filters

kword/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 switch( p.nodeType() )
86 {
87 case TQDomNode::TextNode:
88 _formula = _formula + TQString(p.toText().data()) + " ";
89 break;
90 /* case TT_Space:
91 _formula = _formula + p->zText;
92 //printf("%*s\"%s\"\n", indent, "", p->zText);
93 break;
94 case TT_EOL:
95 _formula = _formula + "\n";
96 //printf("%*s\n", indent, "");
97 break;*/
98 case TQDomNode::ElementNode:
99 _formula = _formula + "<" + p.nodeName();
100 TQDomNamedNodeMap attr = p.attributes();
101 for(unsigned int index = 0; index < attr.length(); index++)
102 { // The attributes
103 _formula = _formula + " " + attr.item(index).nodeName();
104 _formula = _formula + "=\"" + attr.item(index).nodeValue() + "\"";
105 }
106 if(p.childNodes().length() == 0)
107 _formula = _formula + "/>\n";
108 else
109 {
110 _formula = _formula + ">\n";
111 TQDomNodeList child = p.childNodes();
112 for(unsigned int index = 0; index < child.length(); index++)
113 {
114 getFormula(child.item(index), indent + 3); // The child elements
115 }
116 _formula = _formula + "</" + p.nodeName() + ">\n";
117 }
118 break;
119 /*case TQDomNode::AttributeNode:
120 case TQDomNode::CDATASectionNode:
121 case TQDomNode::EntityReferenceNode:
122 case TQDomNode::EntityNode:
123 case TQDomNode::ProcessingInstructionNode:
124 case TQDomNode::CommentNode:
125 case TQDomNode::DocumentNode:
126 case TQDomNode::DocumentTypeNode:
127 case TQDomNode::DocumentFragmentNode:
128 case TQDomNode::NotationNode:
129 case TQDomNode::BaseNode:
130 case TQDomNode::CharacterDataNode:
131 break;*/
132 //default:
133 //kdError(30522) << "Can't happen" << endl;
134 //break;
135
136 }
137}
138
139/*******************************************/
140/* analyseParamFrame */
141/*******************************************/
142void Formula::analyseParamFrame(const TQDomNode balise)
143{
144 /*<FRAME left="28" top="42" right="566" bottom="798" runaround="1" />*/
145
146 _left = getAttr(balise, "left").toInt();
147 _top = getAttr(balise, "top").toInt();
148 _right = getAttr(balise, "right").toInt();
149 _bottom = getAttr(balise, "bottom").toInt();
150 setRunAround(getAttr(balise, "runaround").toInt());
151 setAroundGap(getAttr(balise, "runaroundGap").toInt());
152 setAutoCreate(getAttr(balise, "autoCreateNewFrame").toInt());
153 setNewFrame(getAttr(balise, "newFrameBehaviour").toInt());
154 setSheetSide(getAttr(balise, "sheetside").toInt());
155}
156
157/*******************************************/
158/* generate */
159/*******************************************/
160void Formula::generate(TQTextStream &out)
161{
162 kdDebug(30522) << "FORMULA GENERATION" << endl;
163 TQDomDocument doc;
164 doc.setContent(_formula);
165
166 // a new KFormula::Document for every formula is not the best idea.
167 // better to have only one such beast for the whole document.
168 KFormula::DocumentWrapper* wrapper = new KFormula::DocumentWrapper( kapp->config(), 0 );
169 KFormula::Document* formulaDoc = new KFormula::Document;
170 wrapper->document( formulaDoc );
171
172 KFormula::Container* formula = formulaDoc->createFormula();
173 if ( !formula->load( doc.documentElement () ) ) {
174 kdError(30522) << "Failed." << endl;
175 }
176
177 out << "$" << formula->texString() << "$";
178 delete formula;
179
180 delete wrapper;
181}
182
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.