~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to filters/kspread/latex/export/formula.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** A program to convert the XML rendered by KWord into LATEX.
 
3
**
 
4
** Copyright (C) 2000 Robert JACOLIN
 
5
**
 
6
** This library is free software; you can redistribute it and/or
 
7
** modify it under the terms of the GNU Library General Public
 
8
** License as published by the Free Software Foundation; either
 
9
** version 2 of the License, or (at your option) any later version.
 
10
**
 
11
** This library is distributed in the hope that it will be useful,
 
12
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
** Library General Public License for more details.
 
15
**
 
16
** To receive a copy of the GNU Library General Public License, write to the
 
17
** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
** Boston, MA  02111-1307, USA.
 
19
**
 
20
*/
 
21
 
 
22
#include <stdlib.h>             /* for atoi function */
 
23
#include <kdebug.h>             /* for kdDebug() stream */
 
24
#include <qptrstack.h>          /* for getFormula() */
 
25
#include <qdom.h>
 
26
#include "formula.h"
 
27
#include <kapplication.h>
 
28
 
 
29
#include <kformuladocument.h>
 
30
#include <kformulamimesource.h>
 
31
 
 
32
/*******************************************/
 
33
/* Constructor                             */
 
34
/*******************************************/
 
35
Formula::Formula()
 
36
{
 
37
        _left              = 0;
 
38
        _right             = 0;
 
39
        _top               = 0;
 
40
        _bottom            = 0;
 
41
        _runaround         = TA_NONE;
 
42
        _runaroundGap      = 0;
 
43
        _autoCreate        = TC_EXTEND;
 
44
        _newFrameBehaviour = TF_RECONNECT;
 
45
 
 
46
}
 
47
 
 
48
/*******************************************/
 
49
/* analyse                                 */
 
50
/*******************************************/
 
51
void Formula::analyse(const QDomNode balise)
 
52
{
 
53
 
 
54
        /* MARKUP TYPE : FRAMESET INFO = TEXTE, ENTETE CONNUE */
 
55
 
 
56
        /* Parameters Analyse */
 
57
        Element::analyse(balise);
 
58
 
 
59
        kdDebug() << "FRAME ANALYSE (Formula)" << endl;
 
60
 
 
61
        /* Chlidren markups Analyse */
 
62
        for(int index= 0; index < getNbChild(balise); index++)
 
63
        {
 
64
                if(getChildName(balise, index).compare("FRAME")== 0)
 
65
                {
 
66
                        analyseParamFrame(balise);
 
67
                }
 
68
                else if(getChildName(balise, index).compare("FORMULA")== 0)
 
69
                {
 
70
                        getFormula(getChild(getChild(balise, "FORMULA"), "FORMULA"), 0);
 
71
                        kdDebug() << _formula << endl;
 
72
                }
 
73
 
 
74
        }
 
75
        kdDebug() << "END OF A FRAME" << endl;
 
76
}
 
77
 
 
78
/*******************************************/
 
79
/* getFormula                              */
 
80
/*******************************************/
 
81
/* Get back the xml markup tree.           */
 
82
/*******************************************/
 
83
void Formula::getFormula(QDomNode p, int indent)
 
84
{
 
85
/*      while( p.)
 
86
        {*/
 
87
                switch( p.nodeType() )
 
88
                {
 
89
                        case QDomNode::TextNode:
 
90
                                _formula = _formula + QString(p.toText().data()) + " ";
 
91
                                break;
 
92
                /*      case TT_Space:
 
93
                                _formula = _formula + p->zText;
 
94
                                //printf("%*s\"%s\"\n", indent, "", p->zText);
 
95
                                break;
 
96
                        case TT_EOL:
 
97
                                _formula = _formula + "\n";
 
98
                                //printf("%*s\n", indent, "");
 
99
                                break;*/
 
100
                        case QDomNode::ElementNode:
 
101
                                _formula = _formula + "<" + p.nodeName();
 
102
                                QDomNamedNodeMap attr = p.attributes();
 
103
                                for(unsigned int index = 0; index < attr.length(); index++)
 
104
                                { // The attributes
 
105
                                        _formula = _formula + " " + attr.item(index).nodeName();
 
106
                                        _formula = _formula + "=\"" + attr.item(index).nodeValue() + "\"";
 
107
                                }
 
108
                                if(p.childNodes().length() == 0)
 
109
                                        _formula = _formula + "/>\n";
 
110
                                else
 
111
                                {
 
112
                                        _formula = _formula + ">\n";
 
113
                                        QDomNodeList child = p.childNodes();
 
114
                                        for(unsigned int index = 0; index < child.length(); index++)
 
115
                                        {
 
116
                                                getFormula(child.item(index), indent+3); // The child elements
 
117
                                        }
 
118
                                        _formula = _formula + "</" + p.nodeName() + ">\n";
 
119
                                }
 
120
                                break;
 
121
                        /*default:
 
122
                                kdError() << "Can't happen" << endl;
 
123
                                break;*/
 
124
                }
 
125
        /*      p = p.nextSibling();
 
126
        }*/
 
127
}
 
128
 
 
129
/*******************************************/
 
130
/* analyseParamFrame                       */
 
131
/*******************************************/
 
132
void Formula::analyseParamFrame(const QDomNode balise)
 
133
{
 
134
        /*<FRAME left="28" top="42" right="566" bottom="798" runaround="1" />*/
 
135
 
 
136
        _left = getAttr(balise, "left").toInt();
 
137
        _top = getAttr(balise, "top").toInt();
 
138
        _right = getAttr(balise, "right").toInt();
 
139
        _bottom = getAttr(balise, "bottom").toInt();
 
140
        setRunAround(getAttr(balise, "runaround").toInt());
 
141
        setAroundGap(getAttr(balise, "runaroundGap").toInt());
 
142
        setAutoCreate(getAttr(balise, "autoCreateNewFrame").toInt());
 
143
        setNewFrame(getAttr(balise, "newFrameBehaviour").toInt());
 
144
        setSheetSide(getAttr(balise, "sheetside").toInt());
 
145
}
 
146
 
 
147
/*******************************************/
 
148
/* generate                                */
 
149
/*******************************************/
 
150
void Formula::generate(QTextStream &out)
 
151
{
 
152
        kdDebug() << "FORMULA GENERATION" << endl;
 
153
        QDomDocument doc;
 
154
        doc.setContent(_formula);
 
155
 
 
156
        // a new KFormula::Document for every formula is not the best idea.
 
157
        // better to have only one such beast for the whole document.
 
158
        KFormula::Document formulaDoc( kapp->sessionConfig() );
 
159
 
 
160
        KFormula::Container* formula = new KFormula::Container( &formulaDoc );
 
161
        if ( !formula->load( doc ) ) {
 
162
                kdError() << "Failed." << endl;
 
163
        }
 
164
 
 
165
        out << "$" << formula->texString() << "$";
 
166
        delete formula;
 
167
}
 
168