25#include <tdetempfile.h>
30#include "fileheader.h"
34#include "pixmapFrame.h"
48 kdDebug(30522) <<
"Document destructor" << endl;
54void Document::analyse(
const TQDomNode balise)
57 kdDebug(30522) << getChildName(balise, 0) << endl;
58 for(
int index= 0; index < getNbChild(balise); index++)
61 kdDebug(30522) <<
"--------------------------------------------------" << endl;
63 kdDebug(30522) << getChildName(balise, index) << endl;
67 kdDebug(30522) <<
"NONE" << endl;
70 kdDebug(30522) <<
"TEXT" << endl;
72 elt->
analyse(getChild(balise, index));
75 kdDebug(30522) <<
"PICTURE" << endl;
76 elt =
new PixmapFrame();
77 elt->
analyse(getChild(balise, index));
80 kdDebug(30522) <<
"PART" << endl;
90 kdDebug(30522) <<
"FORMULA" << endl;
92 elt->
analyse(getChild(balise, index));
95 kdDebug(30522) <<
"HLINE" << endl;
98 kdDebug(30522) <<
"error " << elt->getType() <<
" " << ST_TEXT << endl;
104 kdDebug(30522) <<
"INFO : " << elt->
getSection() << endl;
107 case SS_FOOTERS: kdDebug(30522) <<
" FOOTER" <<endl;
108 _footers.append(elt);
110 case SS_HEADERS: kdDebug(30522) <<
" HEADER" << endl;
111 _headers.append(elt);
116 switch(elt->getType())
120 kdDebug(30522) <<
" BODY" << endl;
123 kdDebug(30522) <<
" PART" <<endl;
127 kdDebug(30522) <<
" FORMULA" <<endl;
128 _formulas.append(elt);
131 kdDebug(30522) <<
" PIXMAP" <<endl;
132 _pixmaps.append(elt);
135 kdError(30522) <<
"Element frame type no supported or type unexpected." << endl;
140 kdDebug(30522) <<
" TABLE" <<endl;
146 FileHeader::instance()->useTable();
149 _footnotes.append(elt);
151 default: kdDebug(30522) <<
"UNKNOWN" << endl;
155 kdDebug(30522) <<
"END OF ANALYSE OF A FRAMESET" << endl;
162void Document::analysePixmaps(
const TQDomNode balise)
165 for(
int index= 0; index < getNbChild(balise); index++)
168 kdDebug(30522) <<
"NEW PIXMAP" << endl;
170 key =
new Key(Key::PIXMAP);
171 key->
analyse(getChild(balise,
"KEY"));
181 SType type = ST_NONE;
182 type = (SType) getAttr(balise,
"frameType").toInt();
189void Document::generate(TQTextStream &out,
bool hasPreambule)
191 kdDebug(30522) <<
"DOC. GENERATION." << endl;
194 generatePreambule(out);
195 kdDebug(30522) <<
"preambule : " << hasPreambule << endl;
198 kdDebug(30522) << endl <<
"body : " << _corps.count() << endl;
202 out <<
"\\begin{document}" << endl;
203 Config::instance()->indent();
206 if( !Config::instance()->getPicturesDir().isEmpty() &&
207 Config::instance()->getPicturesDir() != NULL &&
208 FileHeader::instance()->hasGraphics())
210 out << endl <<
"\\graphicspath{{" << Config::instance()->getPicturesDir() <<
"}}" << endl;
213 if(_corps.getFirst() != 0)
214 _corps.getFirst()->generate(out);
222 out <<
"\\end{document}" << endl;
223 Config::instance()->desindent();
224 if(Config::instance()->getIndentation() != 0)
225 kdError(30522) <<
"Error : indent != 0 at the end ! " << endl;
231void Document::generatePreambule(TQTextStream &out)
237 if(FileHeader::instance()->hasHeader())
239 kdDebug(30522) <<
"header : " << _headers.count() << endl;
242 out <<
"\\renewcommand{\\headrulewidth}{0pt}" << endl;
243 for(header = _headers.first(); header != 0; header = _headers.next())
245 generateTypeHeader(out, header);
250 if(FileHeader::instance()->hasFooter())
252 kdDebug(30522) <<
"footer : " << _footers.count() << endl;
255 out <<
"\\renewcommand{\\footrulewidth}{0pt}" << endl;
256 for(footer = _footers.first(); footer != 0; footer = _footers.next())
258 generateTypeFooter(out, footer);
262 if(FileHeader::instance()->hasHeader() || FileHeader::instance()->hasFooter())
263 out <<
"\\pagestyle{fancy}" << endl;
266 out <<
"\\pagestyle{empty}" << endl;
273void Document::generateTypeHeader(TQTextStream &out,
Element *header)
275 kdDebug(30522) <<
"generate header" << endl;
276 if((FileHeader::instance()->getHeadType() == FileHeader::TH_ALL ||
277 FileHeader::instance()->getHeadType() == FileHeader::TH_FIRST) && header->getInfo() == SI_EVEN)
279 out <<
"\\fancyhead[L]{}" << endl;
280 out <<
"\\fancyhead[C]{";
281 header->generate(out);
283 out <<
"\\fancyhead[R]{}" << endl;
286 switch(header->getInfo())
292 out <<
"\\fancyhead[RO]{}" << endl;
293 out <<
"\\fancyhead[CO]{";
294 header->generate(out);
296 out <<
"\\fancyhead[LO]{}" << endl;
299 out <<
"\\fancyhead[RE]{}" << endl;
300 out <<
"\\fancyhead[CE]{";
301 header->generate(out);
303 out <<
"\\fancyhead[LE]{}" << endl;
307 if(header->getInfo() == SI_FIRST)
309 out <<
"\\fancyhead{";
310 header->generate(out);
312 out <<
"\\thispagestyle{fancy}" << endl;
319void Document::generateTypeFooter(TQTextStream &out,
Element *footer)
321 if(FileHeader::instance()->getFootType() == FileHeader::TH_ALL &&
322 footer->getInfo() == SI_EVEN)
324 out <<
"\\fancyfoot[L]{}" << endl;
325 out <<
"\\fancyfoot[C]{";
326 footer->generate(out);
328 out <<
"\\fancyfoot[R]{}" << endl;
330 else if(FileHeader::instance()->getFootType() == FileHeader::TH_EVODD)
332 switch(footer->getInfo())
338 out <<
"\\fancyfoot[CO]{";
339 footer->generate(out);
343 out <<
"\\fancyfoot[CE]{";
344 footer->generate(out);
349 else if(FileHeader::instance()->getFootType() == FileHeader::TH_FIRST &&
350 footer->getInfo() == SI_FIRST)
352 out <<
"\\fanycfoot{";
353 footer->generate(out);
355 out <<
"\\thispagestyle{fancy}" << endl;
359Element* Document::searchAnchor(TQString anchor)
361 Element *elt = _tables.first();
364 kdDebug(30522) << elt->getGrpMgr() << endl;
365 if(elt->getGrpMgr() == anchor)
367 elt = _tables.next();
369 kdDebug(30522) <<
"No in table, search in formulae list." << endl;
370 elt = _formulas.first();
373 if(elt->getName() == anchor)
375 elt = _formulas.next();
377 kdDebug(30522) <<
"No in table and formulae, search in pictures." << endl;
378 elt = _pixmaps.first();
381 if(elt->getName() == anchor)
383 elt = _pixmaps.next();
389Element* Document::searchFootnote(TQString footnote)
391 Element* elt = _footnotes.first();
394 if(elt->getName() == footnote)
396 elt = _footnotes.next();
402Key* Document::searchKey(TQString keyName)
404 Key* key = _keys.first();
407 kdDebug(30522) <<
"key " << key->getFilename() << endl;
408 if(key->getFilename() == keyName)
418 TQString data = searchKey(key)->getName();
419 kdDebug(30522) <<
"Opening " << data << endl;
420 if(!getStorage()->isOpen())
422 if(!getStorage()->open(data))
424 kdError(30522) <<
"Unable to open " << data << endl;
432 TQFile* tempFile = temp.file();
434 const TQ_LONG buflen = 4096;
435 char buffer[ buflen ];
436 TQ_LONG readBytes = getStorage()->read( buffer, buflen );
438 while ( readBytes > 0 )
440 tempFile->writeBlock( buffer, readBytes );
441 readBytes = getStorage()->read( buffer, buflen );
444 if(!getStorage()->close())
446 kdError(30522) <<
"Unable to close " << data << endl;
449 kdDebug(30522) <<
"temp filename : " << temp.name() << endl;
virtual ~Document()
Destructor.
SType getTypeFrameset(const TQDomNode)
Accessors.
TQString extractData(TQString key)
Save the file in a temp file.
SSect getSection() const
Accessors.
virtual void analyse(const TQDomNode)
Helpfull functions.
This class hold a real paragraph.
void analyse(const TQDomNode)
Helpfull functions.