kspread/latex/export/formula.cpp
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., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19**
20*/
21
22#include <stdlib.h> /* for atoi function */
23#include <kdebug.h> /* for kdDebug() stream */
24#include <tqptrstack.h> /* for getFormula() */
25#include <tqdom.h>
26#include "formula.h"
27#include <tdeapplication.h>
28
29#include <kformuladocument.h>
30#include <kformulamimesource.h>
31
32/*******************************************/
33/* Constructor */
34/*******************************************/
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/*******************************************/
51void Formula::analyse(const TQDomNode balise)
52{
53
54 /* MARKUP TYPE : FRAMESET INFO = TEXTE, ENTETE CONNUE */
55
56 /* Parameters Analyse */
57 Element::analyse(balise);
58
59 kdDebug(30522) << "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(30522) << _formula << endl;
72 }
73
74 }
75 kdDebug(30522) << "END OF A FRAME" << endl;
76}
77
78/*******************************************/
79/* getFormula */
80/*******************************************/
81/* Get back the xml markup tree. */
82/*******************************************/
83void Formula::getFormula(TQDomNode p, int indent)
84{
85/* while( p.)
86 {*/
87 switch( p.nodeType() )
88 {
89 case TQDomNode::TextNode:
90 _formula = _formula + TQString(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 TQDomNode::ElementNode:
101 _formula = _formula + "<" + p.nodeName();
102 TQDomNamedNodeMap 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 TQDomNodeList 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(30522) << "Can't happen" << endl;
123 break;*/
124 }
125 /* p = p.nextSibling();
126 }*/
127}
128
129/*******************************************/
130/* analyseParamFrame */
131/*******************************************/
132void Formula::analyseParamFrame(const TQDomNode 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/*******************************************/
150void Formula::generate(TQTextStream &out)
151{
152 kdDebug(30522) << "FORMULA GENERATION" << endl;
153 TQDomDocument 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(30522) << "Failed." << endl;
163 }
164
165 out << "$" << formula->texString() << "$";
166 delete formula;
167}
168
virtual void analyse(const TQDomNode)
Helpfull functions.
void generate(TQTextStream &)
Write the formula in a file.
void setRunAround(const int a)
Modifiers.
void analyse(const TQDomNode)
Helpfull functions.