2
** A program to convert the XML rendered by KWord into LATEX.
4
** Copyright (C) 2000 Robert JACOLIN
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.
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.
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.
22
#include <stdlib.h> /* for atoi function */
23
#include <kdebug.h> /* for kdDebug() stream */
24
#include <qptrstack.h> /* for getFormula() */
27
#include <kapplication.h>
29
#include <kformuladocument.h>
30
#include <kformulamimesource.h>
32
/*******************************************/
34
/*******************************************/
43
_autoCreate = TC_EXTEND;
44
_newFrameBehaviour = TF_RECONNECT;
48
/*******************************************/
50
/*******************************************/
51
void Formula::analyse(const QDomNode balise)
54
/* MARKUP TYPE : FRAMESET INFO = TEXTE, ENTETE CONNUE */
56
/* Parameters Analyse */
57
Element::analyse(balise);
59
kdDebug() << "FRAME ANALYSE (Formula)" << endl;
61
/* Chlidren markups Analyse */
62
for(int index= 0; index < getNbChild(balise); index++)
64
if(getChildName(balise, index).compare("FRAME")== 0)
66
analyseParamFrame(balise);
68
else if(getChildName(balise, index).compare("FORMULA")== 0)
70
getFormula(getChild(getChild(balise, "FORMULA"), "FORMULA"), 0);
71
kdDebug() << _formula << endl;
75
kdDebug() << "END OF A FRAME" << endl;
78
/*******************************************/
80
/*******************************************/
81
/* Get back the xml markup tree. */
82
/*******************************************/
83
void Formula::getFormula(QDomNode p, int indent)
87
switch( p.nodeType() )
89
case QDomNode::TextNode:
90
_formula = _formula + QString(p.toText().data()) + " ";
93
_formula = _formula + p->zText;
94
//printf("%*s\"%s\"\n", indent, "", p->zText);
97
_formula = _formula + "\n";
98
//printf("%*s\n", indent, "");
100
case QDomNode::ElementNode:
101
_formula = _formula + "<" + p.nodeName();
102
QDomNamedNodeMap attr = p.attributes();
103
for(unsigned int index = 0; index < attr.length(); index++)
105
_formula = _formula + " " + attr.item(index).nodeName();
106
_formula = _formula + "=\"" + attr.item(index).nodeValue() + "\"";
108
if(p.childNodes().length() == 0)
109
_formula = _formula + "/>\n";
112
_formula = _formula + ">\n";
113
QDomNodeList child = p.childNodes();
114
for(unsigned int index = 0; index < child.length(); index++)
116
getFormula(child.item(index), indent+3); // The child elements
118
_formula = _formula + "</" + p.nodeName() + ">\n";
122
kdError() << "Can't happen" << endl;
125
/* p = p.nextSibling();
129
/*******************************************/
130
/* analyseParamFrame */
131
/*******************************************/
132
void Formula::analyseParamFrame(const QDomNode balise)
134
/*<FRAME left="28" top="42" right="566" bottom="798" runaround="1" />*/
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());
147
/*******************************************/
149
/*******************************************/
150
void Formula::generate(QTextStream &out)
152
kdDebug() << "FORMULA GENERATION" << endl;
154
doc.setContent(_formula);
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() );
160
KFormula::Container* formula = new KFormula::Container( &formulaDoc );
161
if ( !formula->load( doc ) ) {
162
kdError() << "Failed." << endl;
165
out << "$" << formula->texString() << "$";