textFrame.cpp
1/*
2** A program to convert the XML rendered by KWord into LATEX.
3**
4** Copyright (C) 2000, 2001, 2002 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 "textFrame.h"
25
26/*******************************************/
27/* Constructor */
28/*******************************************/
30{
31 _left = 0;
32 _right = 0;
33 _top = 0;
34 _bottom = 0;
35 _runaround = TA_NONE;
36 _runaroundGap = 0;
37 _autoCreate = TC_EXTEND;
38 _newFrameBehaviour = TF_RECONNECT;
39 _sheetSide = TS_ANYSIDE;
40 //_footnotes = 0;
41
42 setType(ST_TEXT);
43}
44
45/*******************************************/
46/* searchFootnote */
47/*******************************************/
48/*Para* TextFrame::searchFootnote(const TQString name)
49{
50 for(Para* current = _footnotes.first(); current!= 0; current = _footnotes.next())
51 {
52 TQString* string = current->getName();
53 kdDebug(30522) << *string << endl;
54 if(*string == name)
55 return current;
56 //iter.next();
57 }
58 return 0;
59}*/
60
61/*******************************************/
62/* analyse */
63/*******************************************/
64void TextFrame::analyse(const TQDomNode balise)
65{
66 /* MARKUP TYPE : FRAMESET INFO = TEXTE, ENTETE CONNUE */
67
68 /* Parameters Analyse */
69 Element::analyse(balise);
70
71 kdDebug(30522) << "FRAME ANALYSE (TextFrame)" << endl;
72
73 /* Chlidren markups Analyse */
74 analyseParamFrame(getChild(balise, "FRAME"));
75
76 for(int index = 0; index < getNbChild(balise); index++)
77 {
78 if(getChildName(balise, index).compare("PARAGRAPH")== 0)
79 {
80 // 1. Create a paragraph :
81 Para *prg = new Para(this);
82 // 2. Add the informations :
83 prg->analyse(getChild(balise, index));
84 if(prg->getInfo() == EP_FOOTNOTE)
85 {
86 // 3. add this parag. in the footnote list
87 //if(_footnotes == 0)
88 // _footnotes = new ListPara;
89 //_footnotes.append(prg);
90 }
91 else
92 {
93 // 3. add this parag. in the text list
94 _parags.append(prg);
95 }
96 kdDebug(30522) << "PARA ADDED" << endl;
97 }
98
99 }
100 kdDebug(30522) << "END OF A FRAME ANALYSE" << endl;
101}
102
103/*******************************************/
104/* analyseParamFrame */
105/*******************************************/
106void TextFrame::analyseParamFrame(const TQDomNode balise)
107{
108 /*<FRAME left="28" top="42" right="566" bottom="798" runaround="1" />*/
109 setLeft(getAttr(balise, "left").toDouble());
110 setTop(getAttr(balise, "top").toDouble());
111 setRight(getAttr(balise, "right").toDouble());
112 setBottom(getAttr(balise, "bottom").toDouble());
113 setRunAround(getAttr(balise, "runaround").toInt());
114 setAroundGap(getAttr(balise, "runaroundGap").toInt());
115 setAutoCreate(getAttr(balise, "autoCreateNewFrame").toInt());
116 setNewFrame(getAttr(balise, "newFrameBehaviour").toInt());
117 setSheetSide(getAttr(balise, "sheetSide").toInt());
118 if(getAttr(balise, "lWidth").toInt() > 0)
119 {
120 setLeftWidth(getAttr(balise, "lWidth").toInt());
122 }
123 if(getAttr(balise, "rWidth").toInt() > 0)
124 {
125 setRightWidth(getAttr(balise, "rWidth").toInt());
126 useRightBorder();
127 }
128 if(getAttr(balise, "tWidth").toInt() > 0)
129 {
130 setTopWidth(getAttr(balise, "tWidth").toInt());
131 useTopBorder();
132 }
133 if(getAttr(balise, "bWidth").toInt() > 0)
134 {
135 setBottomWidth(getAttr(balise, "bWidth").toInt());
136 useBottomBorder();
137 }
138 setLeftRed(getAttr(balise, "lRed").toInt());
139 setLeftGreen(getAttr(balise, "lGreen").toInt());
140 setLeftBlue(getAttr(balise, "lBlue").toInt());
141
142 setRightRed(getAttr(balise, "rRed").toInt());
143 setRightGreen(getAttr(balise, "rGreen").toInt());
144 setRightBlue(getAttr(balise, "rBlue").toInt());
145
146 setTopRed(getAttr(balise, "tRed").toInt());
147 setTopGreen(getAttr(balise, "tGreen").toInt());
148 setTopBlue(getAttr(balise, "tBlue").toInt());
149
150 setBottomRed(getAttr(balise, "bRed").toInt());
151 setBottomGreen(getAttr(balise, "bGreen").toInt());
152 setBottomBlue(getAttr(balise, "bBlue").toInt());
153
154 setLeftStyle(getAttr(balise, "lStyle").toInt());
155 setRightStyle(getAttr(balise, "rStyle").toInt());
156 setTopStyle(getAttr(balise, "tStyle").toInt());
157 setBottomStyle(getAttr(balise, "bStyle").toInt());
158 setBkRed(getAttr(balise, "bkred").toInt());
159 setBkGreen(getAttr(balise, "bkgreen").toInt());
160 setBkBlue(getAttr(balise, "bkblue").toInt());
161/*
162 setLeftWidth(getAttr(balise, "bleftpt").toDouble());
163 setLeftWidth(getAttr(balise, "brightpt").toDouble());
164 setLeftWidth(getAttr(balise, "bktoppt").toDouble());
165 setLeftWidth(getAttr(balise, "bkbottompt").toDouble());
166*/
167}
168
169/*******************************************/
170/* generate */
171/*******************************************/
172void TextFrame::generate(TQTextStream &out)
173{
174 Para * lastPara = 0;
175
176 kdDebug(30522) << "TEXT GENERATION" << endl;
177 kdDebug(30522) << "NB PARA " << _parags.count() << endl;
178
179 if(getSection() == SS_TABLE || getSection() == SS_HEADERS ||
180 getSection() == SS_FOOTERS)
181 {
182 Config::instance()->writeIndent(out);
183 out << "\\begin{minipage}{";
184 out << (getRight() - getLeft()) << "pt}" << endl;
185 }
186 _lastEnv = ENV_NONE;
187 _lastTypeEnum = TL_NONE;
188
189 Para* currentPara = _parags.first();
190 while( currentPara != 0)
191 {
192 //indent();
193 if((!currentPara->isChapter() && _lastTypeEnum == TL_NONE &&
194 _lastEnv != getNextEnv(_parags, _parags.at()) &&
195 currentPara->notEmpty()) ||
196 _lastEnv != getNextEnv(_parags, _parags.at()) )
197 {
198 currentPara->generateBeginEnv(out);
199 _lastEnv = currentPara->getEnv();
200 }
201
202 /* List management */
203 if(isBeginEnum(lastPara, currentPara))
204 {
205 currentPara->openList(out);
206 _lastTypeEnum = currentPara->getCounterType();
207 }
208 /* paragraph generation */
209 currentPara->generate(out);
210
211 lastPara = currentPara;
212 currentPara = _parags.next();
213
214 /* list management */
215 if(isCloseEnum(lastPara, currentPara))
216 {
217 lastPara->closeList(out, currentPara);
218 _lastTypeEnum = TL_NONE;
219 }
220 /* layout management (left, center, justify, right) */
221 if((!lastPara->isChapter() && _lastEnv != getNextEnv(_parags, _parags.at()) &&
222 lastPara->notEmpty()) ||
223 _lastEnv != getNextEnv(_parags, _parags.at()))
224 {
225 lastPara->generateEndEnv(out);
226 out << endl;
227 }
228 if(getSection() != SS_HEADERS && getSection() != SS_FOOTERS)
229 out << endl;
230 }
231
232 if(getSection() == SS_TABLE || getSection() == SS_HEADERS ||
233 getSection() == SS_FOOTERS)
234 {
235 Config::instance()->desindent();
236 Config::instance()->writeIndent(out);
237 out << "\\end{minipage}" << endl;
238 }
239}
240
241EEnv TextFrame::getNextEnv(TQPtrList<Para> liste, const int pos)
242{
243 if ( pos < 0 )
244 return ENV_NONE;
245 Para* index = 0;
246
247 for(index = liste.at(pos); index != 0 && index->isChapter(); index = liste.next())
248 {}
249
250 if(index != 0)
251 {
252 return index->getEnv();
253 }
254 else
255 return ENV_NONE;
256}
257
258/* next is the paragraph which will be generated, just after */
259bool TextFrame::isBeginEnum(Para* previous, Para* next)
260{
261 /* If it's a list : */
262 /* - go in a new list */
263 /* - change depth (a list in a list) */
264 /* - or two lists nearby (but with the same depth) */
265 kdDebug(30522) << "---------------------------------" << endl;
266 kdDebug(30522) << getSection() << " = " << SS_HEADERS << endl;
267 if(next->isList() && getSection() != SS_FOOTNOTES &&
268 getSection() != SS_HEADERS && getSection() != SS_FOOTERS)
269 {
270 if(previous == 0 || !previous->isList() ||
271 (previous->isList() && (
272 (previous->getCounterDepth() < next->getCounterDepth()) ||
273 (previous->getCounterType() != next->getCounterType() &&
274 previous->getCounterDepth() == next->getCounterDepth()))
275 ))
276 return true;
277 }
278 return false;
279}
280
281/* next is the paragraph which will be generated in the next loop */
282bool TextFrame::isCloseEnum(Para* previous, Para* next)
283{
284 if(previous->isList() && getSection() != SS_FOOTNOTES &&
285 getSection() != SS_HEADERS && getSection() != SS_FOOTERS)
286 {
287 if(next == 0 || !next->isList() ||
288 (next->isList() && next->getCounterDepth() < previous->getCounterDepth()) ||
289 (next->isList() && next->getCounterType() != previous->getCounterType() &&
290 next->getCounterDepth() == previous->getCounterDepth()) ||
291 previous->getFrameType() == SS_TABLE)
292 return true;
293 }
294 return false;
295}
void useLeftBorder()
Modifiors.
Definition border.h:141
void setType(SType t)
Modifiors.
SSect getSection() const
Accessors.
virtual void analyse(const TQDomNode)
Helpfull functions.
bool isChapter() const
Accessors.
Definition layout.h:102
This class hold a real paragraph.
Definition para.h:59
void analyse(const TQDomNode)
Modifiers.
Definition para.cpp:129
SSect getFrameType() const
Definition para.cpp:69
void openList(TQTextStream &)
Write the markup to begin a list.
Definition para.cpp:476
void generateBeginEnv(TQTextStream &)
If the paragraph has a different environment, change it.
Definition para.cpp:447
EP_INFO getInfo() const
Definition para.h:114
void generate(TQTextStream &)
Write the paragraph in a file.
Definition para.cpp:359
void generateEndEnv(TQTextStream &)
If the next paragraph has a different environment, close it.
Definition para.cpp:545
void closeList(TQTextStream &, Para *)
Write the markup to close a list.
Definition para.cpp:584
void analyse(const TQDomNode)
Get informations from a markup tree.
Definition textFrame.cpp:64
void generate(TQTextStream &)
Write the text in a file.
TextFrame()
Constructors.
Definition textFrame.cpp:29
void setLeft(const double l)
Modifiors.
Definition textFrame.h:102
double getLeft() const
Accessors.
Definition textFrame.h:85