KWEFKWordLeader.cpp
1/*
2 This file is part of the KDE project
3 Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE <goutte@kde.org>
4 Copyright (c) 2001 IABG mbH. All rights reserved.
5 Contact: Wolf-Michael Bolle <Bolle@IABG.de>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21*/
22
23/*
24 Part of this code comes from the old file:
25 /home/kde/koffice/filters/kword/ascii/asciiexport.cpp
26
27 The old file was copyrighted by
28 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
29 Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved.
30 Contact: Wolf-Michael Bolle <Wolf-Michael.Bolle@GMX.de>
31
32 The old file was licensed under the terms of the GNU Library General Public
33 License version 2.
34*/
35
36#include <tqfile.h>
37#include <tqdom.h>
38
39#include <kdebug.h>
40#include <tdelocale.h>
41#include <tdemessagebox.h>
42
43#include <KoGlobal.h>
44#include <KoStore.h>
45
46#include "KWEFStructures.h"
47#include "TagProcessing.h"
48#include "ProcessDocument.h"
49#include "KWEFBaseWorker.h"
50#include "KWEFKWordLeader.h"
51
52KWEFKWordLeader::KWEFKWordLeader(void)
53 : m_syntaxVersion(-1), m_oldSyntax(false), m_worker(NULL), m_chain(NULL), m_hType(0), m_fType(0)
54{
55}
56
57KWEFKWordLeader::KWEFKWordLeader(KWEFBaseWorker* newWorker)
58 : m_syntaxVersion(-1), m_oldSyntax(false), m_worker(newWorker), m_chain(NULL)
59{
60 if (newWorker) newWorker->registerKWordLeader(this);
61}
62
63KWEFKWordLeader::~KWEFKWordLeader(void)
64{
65}
66
67static FrameAnchor *findAnchor ( const KoPictureKey& key,
68 TQValueList<ParaData>& paraList )
69{
70 kdDebug(30508) << "findAnchor " << key.toString() << endl;
71 TQValueList<ParaData>::Iterator paraIt;
72
73 for ( paraIt = paraList.begin (); paraIt != paraList.end (); ++paraIt )
74 {
75 ValueListFormatData::Iterator formattingIt;
76
77 for ( formattingIt = (*paraIt).formattingList.begin ();
78 formattingIt != (*paraIt).formattingList.end ();
79 formattingIt++ )
80 {
81 if ( (*formattingIt).id == 6 &&
82 (*formattingIt).frameAnchor.key == key )
83 {
84 kdDebug(30508) << "Found anchor " << (*formattingIt).frameAnchor.key.toString() << endl;
85 return &(*formattingIt).frameAnchor;
86 }
87 }
88 }
89
90 kdWarning(30508) << "findAnchor returning NULL!" << endl;
91 return NULL;
92}
93
94static void ProcessHardBrkTag ( TQDomNode myNode, void* tagData, KWEFKWordLeader* )
95{
96 // <HARDBRK>
97 bool* flag = (bool*) tagData;
98 TQValueList<AttrProcessing> attrProcessingList;
99 attrProcessingList << AttrProcessing ( "frame", *flag );
100 ProcessAttributes (myNode, attrProcessingList);
101 if (*flag)
102 kdDebug(30508) << "<HARDBRK frame=\"1\"> found" << endl;
103}
104
105static void InsertBookmarkFormatData (const int pos, const TQString& name, const bool start,
106 ValueListFormatData &paraFormatDataList)
107{
108 ValueListFormatData::Iterator paraFormatDataIt;
109
110 FormatData book( start ? 1001 : 1002 , pos, 0 );
111 book.variable.m_text = name;
112
113 for (paraFormatDataIt = paraFormatDataList.begin ();
114 paraFormatDataIt != paraFormatDataList.end ();
115 paraFormatDataIt++)
116 {
117 if ( pos <= (*paraFormatDataIt).pos )
118 {
119 paraFormatDataList.insert ( paraFormatDataIt, book );
120 return;
121
122 }
123 if ( ( pos > (*paraFormatDataIt).pos ) && ( pos < (*paraFormatDataIt).pos + (*paraFormatDataIt).len ) )
124 {
125 // Somewhere in the middle, we have to split the FormatData
126 FormatData split ( *paraFormatDataIt );
127 //const int oldlen = (*paraFormatDataIt).len;
128 split.len = pos - (*paraFormatDataIt).pos;
129 (*paraFormatDataIt).len -= split.len;
130 (*paraFormatDataIt).pos = pos;
131 paraFormatDataList.insert ( paraFormatDataIt, split );
132 paraFormatDataList.insert ( paraFormatDataIt, book );
133 return;
134 }
135 }
136
137 // Still here? So we need to put the bookmark here:
138 paraFormatDataList.append ( book );
139}
140
141
142void KWEFKWordLeader::createBookmarkFormatData( ParaData& paraData )
143{
144 const int paraCount = m_paraCountMap[ m_currentFramesetName ];
145
146 TQValueList<Bookmark>::ConstIterator it;
147 for (it = m_bookmarkList.begin(); it != m_bookmarkList.end(); ++it )
148 {
149 if ( (*(it)).m_frameset != m_currentFramesetName )
150 {
151 continue;
152 }
153 // As we always insert before, make first endings, then startings (problem is zero-length bookmark)
154 if ( (*(it)).m_endparag == paraCount )
155 {
156 kdDebug(30508) << "Paragraph: " << paraCount << " end: " << (*(it)).m_name << endl;
157 InsertBookmarkFormatData( (*(it)).m_cursorIndexEnd, (*(it)).m_name, false, paraData.formattingList);
158
159 }
160 if ( (*(it)).m_startparag == paraCount )
161 {
162 kdDebug(30508) << "Paragraph: " << paraCount << " begin: " << (*(it)).m_name << endl;
163 InsertBookmarkFormatData( (*(it)).m_cursorIndexStart, (*(it)).m_name, true, paraData.formattingList);
164 }
165 }
166}
167
168static void ProcessParagraphTag ( TQDomNode myNode,
169 void *tagData,
170 KWEFKWordLeader *leader )
171{
172#if 0
173 kdDebug (30508) << "ProcessParagraphTag () - Begin" << endl;
174#endif
175
176 TQValueList<ParaData> *paraList = (TQValueList<ParaData> *) tagData;
177
178 AllowNoAttributes (myNode);
179
180 // We need to adjust the paragraph number (0 if first)
181 TQMap<TQString,int>::Iterator it = leader->m_paraCountMap.find( leader->m_currentFramesetName );
182 if ( it == leader->m_paraCountMap.end() )
183 leader->m_paraCountMap.insert( leader->m_currentFramesetName, 0 );
184 else
185 ++(*it);
186
187 ParaData paraData;
188
189 TQValueList<TagProcessing> tagProcessingList;
190 tagProcessingList << TagProcessing ( "TEXT", ProcessTextTag, &paraData.text )
191 << TagProcessing ( "FORMATS", ProcessFormatsTag, &paraData.formattingList )
192 << TagProcessing ( "LAYOUT", ProcessLayoutTag, &paraData.layout );
193
194 if ( leader->m_oldSyntax )
195 {
196 tagProcessingList.append( TagProcessing( "HARDBRK", ProcessHardBrkTag, &paraData.layout.pageBreakBefore ) );
197 }
198 ProcessSubtags (myNode, tagProcessingList, leader);
199
200 leader->createBookmarkFormatData( paraData );
201 CreateMissingFormatData (paraData.text, paraData.formattingList);
202
203 // TODO/FIXME: why !paraData.text.isEmpty()
204 if ( paraData.formattingList.isEmpty () && !paraData.text.isEmpty () )
205 {
206 if ( paraData.layout.formatData.id == 1 )
207 {
208 paraData.formattingList << paraData.layout.formatData;
209 }
210 else
211 {
212 kdWarning (30508) << "No useful FORMAT tag found for text in PARAGRAPH" << endl;
213 }
214 }
215
216
217 *paraList << paraData;
218
219#if 0
220 kdDebug (30508) << "ProcessParagraphTag () - End " << paraText << endl;
221#endif
222}
223
224
225static void ProcessFrameTag ( TQDomNode myNode, void *tagData,
226 KWEFKWordLeader *leader )
227{
228 FrameAnchor* frameAnchor= (FrameAnchor*) tagData;
229
230 int lRed=0, lBlue=0, lGreen=0;
231 int rRed=0, rBlue=0, rGreen=0;
232 int tRed=0, tBlue=0, tGreen=0;
233 int bRed=0, bBlue=0, bGreen=0;
234 int bkRed=255, bkBlue=255, bkGreen=255;
235
236 frameAnchor->frame.lWidth=0.0;
237 frameAnchor->frame.rWidth=0.0;
238 frameAnchor->frame.tWidth=0.0;
239 frameAnchor->frame.bWidth=0.0;
240
241 TQValueList<AttrProcessing> attrProcessingList;
242 attrProcessingList
243 << AttrProcessing ( "right", frameAnchor->frame.right )
244 << AttrProcessing ( "left", frameAnchor->frame.left )
245 << AttrProcessing ( "top", frameAnchor->frame.top )
246 << AttrProcessing ( "bottom", frameAnchor->frame.bottom )
247
248 << AttrProcessing ( "min-height", frameAnchor->frame.minHeight )
249
250 << AttrProcessing ( "runaround", frameAnchor->frame.runaround )
251 << AttrProcessing ( "runaroundSide", frameAnchor->frame.runaroundSide )
252 << AttrProcessing ( "runaroundGap", frameAnchor->frame.runaroundGap )
253
254 << AttrProcessing ( "autoCreateNewFrame", frameAnchor->frame.autoCreateNewFrame )
255 << AttrProcessing ( "newFrameBehavior", frameAnchor->frame.newFrameBehavior )
256 << AttrProcessing ( "newFrameBehaviour", frameAnchor->frame.newFrameBehavior ) // Depreciated name
257
258 << AttrProcessing ( "copy", frameAnchor->frame.copy )
259 << AttrProcessing ( "sheetSide", frameAnchor->frame.sheetSide )
260
261 << AttrProcessing ( "lWidth", frameAnchor->frame.lWidth )
262 << AttrProcessing ( "rWidth", frameAnchor->frame.rWidth )
263 << AttrProcessing ( "tWidth", frameAnchor->frame.tWidth )
264 << AttrProcessing ( "bWidth", frameAnchor->frame.bWidth )
265
266 << AttrProcessing ( "lRed", lRed )
267 << AttrProcessing ( "lGreen", lGreen )
268 << AttrProcessing ( "lBlue", lBlue )
269
270 << AttrProcessing ( "rRed", rRed )
271 << AttrProcessing ( "rGreen", rGreen )
272 << AttrProcessing ( "rBlue", rBlue )
273
274 << AttrProcessing ( "tRed", tRed )
275 << AttrProcessing ( "tGreen", tGreen )
276 << AttrProcessing ( "tBlue", tBlue )
277
278 << AttrProcessing ( "bRed", bRed )
279 << AttrProcessing ( "bGreen", bGreen )
280 << AttrProcessing ( "bBlue", bBlue )
281
282 << AttrProcessing ( "lStyle", frameAnchor->frame.lStyle )
283 << AttrProcessing ( "rStyle", frameAnchor->frame.rStyle )
284 << AttrProcessing ( "tStyle", frameAnchor->frame.tStyle )
285 << AttrProcessing ( "bStyle", frameAnchor->frame.bStyle )
286
287 << AttrProcessing ( "bkRed", bkRed )
288 << AttrProcessing ( "bkGreen", bkGreen )
289 << AttrProcessing ( "bkBlue", bkBlue )
290
291 << AttrProcessing ( "bkStyle", frameAnchor->frame.bkStyle )
292
293 << AttrProcessing ( "bleftpt", frameAnchor->frame.bleftpt )
294 << AttrProcessing ( "brightpt", frameAnchor->frame.brightpt )
295 << AttrProcessing ( "btoppt", frameAnchor->frame.btoppt )
296 << AttrProcessing ( "bbottompt", frameAnchor->frame.bbottompt )
297 ;
298
299 if ( leader->m_oldSyntax )
300 {
301 attrProcessingList
302 << AttrProcessing ( "bleftmm" )
303 << AttrProcessing ( "bleftinch" )
304 << AttrProcessing ( "brightmm" )
305 << AttrProcessing ( "brightinch" )
306 << AttrProcessing ( "btopmm" )
307 << AttrProcessing ( "btopinch" )
308 << AttrProcessing ( "bbottommm" )
309 << AttrProcessing ( "bbottominch" )
310 ;
311 }
312
313 ProcessAttributes (myNode, attrProcessingList);
314
315 frameAnchor->frame.lColor.setRgb( lRed, lGreen, lBlue );
316 frameAnchor->frame.rColor.setRgb( rRed, rGreen, rBlue );
317 frameAnchor->frame.tColor.setRgb( tRed, tGreen, tBlue );
318 frameAnchor->frame.bColor.setRgb( bRed, bGreen, bBlue );
319 frameAnchor->frame.bkColor.setRgb( bkRed, bkGreen, bkBlue );
320
321 AllowNoSubtags (myNode, leader);
322}
323
324static void ProcessPictureAnchor( TQDomNode myNode, KWEFKWordLeader *leader, FrameAnchor* frameAnchor, const int frameType )
325{
326 frameAnchor->type = frameType;
327
328 TQValueList<TagProcessing> tagProcessingList;
329 tagProcessingList
330 << TagProcessing ( "FRAME", ProcessFrameTag, frameAnchor )
331 << TagProcessing ( "PICTURE", ProcessImageTag, &frameAnchor->picture.key )
332 << TagProcessing ( "IMAGE", ProcessImageTag, &frameAnchor->picture.key )
333 << TagProcessing ( "CLIPART", ProcessImageTag, &frameAnchor->picture.key )
334 ;
335 ProcessSubtags (myNode, tagProcessingList, leader);
336
337 kdDebug (30508) << "FRAMESET PICTURE KEY " << frameAnchor->picture.key.toString() << endl;
338
339 frameAnchor->key = frameAnchor->picture.key;
340}
341
342static void ProcessTableAnchor( TQDomNode myNode, KWEFKWordLeader *leader, FrameAnchor* frameAnchor,
343 const int col, const int row, const int cols, const int rows )
344{
345 frameAnchor->type = 6; // Table
346
347 TQValueList<ParaData> cellParaList;
348 TQValueList<TagProcessing> tagProcessingList;
349 tagProcessingList << TagProcessing ( "FRAME", ProcessFrameTag, frameAnchor )
350 << TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &cellParaList );
351 ProcessSubtags (myNode, tagProcessingList, leader);
352
353 frameAnchor->table.addCell (col, row, cols, rows, cellParaList, frameAnchor->frame);
354}
355
356static void ProcessFramesetTag ( TQDomNode myNode,
357 void *tagData,
358 KWEFKWordLeader *leader )
359{
360#if 0
361 kdDebug (30508) << "ProcessFramesetTag () - Begin" << endl;
362#endif
363
364 TQValueList<ParaData> *paraList = (TQValueList<ParaData> *) tagData;
365
366 int frameType = -1;
367 int frameInfo = -1;
368 int col = -1;
369 int row = -1;
370 int cols = -1;
371 int rows = -1;
372 TQString grpMgr;
373
374 const TQString oldName ( leader->m_currentFramesetName );
375
376 TQValueList<AttrProcessing> attrProcessingList;
377 attrProcessingList << AttrProcessing ( "name", leader->m_currentFramesetName )
378 << AttrProcessing ( "frameType", frameType )
379 << AttrProcessing ( "frameInfo", frameInfo )
380 << AttrProcessing ( "removable" )
381 << AttrProcessing ( "visible" )
382 << AttrProcessing ( "grpMgr", grpMgr )
383 << AttrProcessing ( "row", row )
384 << AttrProcessing ( "col", col )
385 << AttrProcessing ( "rows", rows )
386 << AttrProcessing ( "cols", cols )
387 << AttrProcessing ( "protectSize" )
388 ;
389 ProcessAttributes (myNode, attrProcessingList);
390
391 switch ( frameType )
392 {
393 case 1:
394 if ( grpMgr.isEmpty () )
395 {
396 // As we do not support anything else than normal text, process only normal text.
397 // TODO: Treat the other types of frames (frameType)
398 if (frameInfo==0)
399 {
400 // Normal Text
401 kdDebug(30508) << "Processing Frameset: " << leader->m_currentFramesetName << endl;
402 TQValueList<TagProcessing> tagProcessingList;
403 tagProcessingList.append(TagProcessing ( "FRAME" ));
404 tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, paraList ));
405 ProcessSubtags (myNode, tagProcessingList, leader);
406 }
407 else if (frameInfo==1)
408 {
409 // header for first page
410 HeaderData header;
411 header.page = HeaderData::PAGE_FIRST;
412 TQValueList<TagProcessing> tagProcessingList;
413 tagProcessingList.append(TagProcessing ( "FRAME" ));
414 tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &header.para ));
415
416 ProcessSubtags (myNode, tagProcessingList, leader);
417 leader->doHeader( header );
418 }
419 else if (frameInfo==2)
420 {
421 // header for even page
422 HeaderData header;
423 header.page = HeaderData::PAGE_EVEN;
424 TQValueList<TagProcessing> tagProcessingList;
425 tagProcessingList.append(TagProcessing ( "FRAME" ));
426 tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &header.para ));
427 ProcessSubtags (myNode, tagProcessingList, leader);
428 leader->doHeader( header );
429 }
430 else if (frameInfo==3)
431 {
432 // header for odd page (or all page, if hType=0)
433 HeaderData header;
434 header.page = (leader->headerType() != 0 ) ? HeaderData::PAGE_ODD : HeaderData::PAGE_ALL;
435 TQValueList<TagProcessing> tagProcessingList;
436 tagProcessingList.append(TagProcessing ( "FRAME" ));
437 tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &header.para ));
438 ProcessSubtags (myNode, tagProcessingList, leader);
439 leader->doHeader( header );
440 }
441 else if (frameInfo==4)
442 {
443 // footer for first page
444 FooterData footer;
445 footer.page = FooterData::PAGE_FIRST;
446 TQValueList<TagProcessing> tagProcessingList;
447 tagProcessingList.append(TagProcessing ( "FRAME" ));
448 tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footer.para ));
449 ProcessSubtags (myNode, tagProcessingList, leader);
450 leader->doFooter( footer );
451 }
452 else if (frameInfo==5)
453 {
454 // footer for even page
455 FooterData footer;
456 footer.page = FooterData::PAGE_EVEN;
457 TQValueList<TagProcessing> tagProcessingList;
458 tagProcessingList.append(TagProcessing ( "FRAME" ));
459 tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footer.para ));
460 ProcessSubtags (myNode, tagProcessingList, leader);
461 leader->doFooter( footer );
462 }
463 else if (frameInfo==6)
464 {
465 // footer for odd page (or all page, if fType=0)
466 FooterData footer;
467 footer.page = (leader->footerType() != 0) ? FooterData::PAGE_ODD : FooterData::PAGE_ALL;
468 TQValueList<TagProcessing> tagProcessingList;
469 tagProcessingList.append(TagProcessing ( "FRAME" ));
470 tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footer.para ));
471 ProcessSubtags (myNode, tagProcessingList, leader);
472 leader->doFooter( footer );
473 }
474 }
475 else
476 {
477 if ( col != -1 && row != -1 )
478 {
479 if ( cols > 0 && rows > 0 )
480 {
481#if 0
482 kdDebug (30508) << "DEBUG - FRAMESET: table " << name << " col, row = "
483 << col << ", " << row << ", Mgr = "<< grpMgr << endl;
484#endif
485 FrameAnchor *frameAnchor = findAnchor (grpMgr, *paraList);
486 if ( frameAnchor )
487 {
488 ProcessTableAnchor( myNode, leader, frameAnchor, col, row, cols, rows );
489 }
490 else
491 {
492 bool found = false;
493 KoPictureKey key( grpMgr );
494 TQValueList<FrameAnchor>::Iterator it;
495 for ( it = leader->m_nonInlinedTableAnchors.begin(); it != leader->m_nonInlinedTableAnchors.end(); ++it )
496 {
497 if ( (*it).key == key )
498 {
499 kdDebug(30508) << "Found pseudo-anchor for table: " << (*it).key.toString() << endl;
500 found = true;
501 break;
502 }
503 }
504
505 if ( found )
506 {
507 ProcessTableAnchor( myNode, leader, &(*it), col, row, cols, rows );
508 }
509 else
510 {
511 kdWarning(30508) << "Table anchor not found: " << grpMgr << endl;
512 FrameAnchor anchor;
513 ProcessTableAnchor( myNode, leader, &anchor, col, row, cols, rows );
514 anchor.key = key; // Needed, so that the pseudo-anchor can be found again
515 leader->m_nonInlinedTableAnchors << anchor;
516 leader->m_unanchoredFramesets.append( grpMgr );
517 }
518 }
519 }
520 else
521 {
522 kdWarning (30508) << "Unexpected value for one of, or all FRAMESET attribute cols, rows: "
523 << cols << ", " << rows << "!" << endl;
524 AllowNoSubtags (myNode, leader);
525 }
526 }
527 else
528 {
529 kdWarning (30508) << "Unset value for one of, or all FRAMESET attributes col, row: "
530 << col << ", " << row << "!" << endl;
531 AllowNoSubtags (myNode, leader);
532 leader->m_unanchoredFramesets.append( leader->m_currentFramesetName );
533 }
534 }
535 break;
536
537 case 2: // PICTURE
538 case 5: // CLIPART: deprecated (up to KOffice 1.2 Beta 2)
539 {
540#if 0
541 kdDebug (30508) << "DEBUG: FRAMESET name of picture is " << name << endl;
542#endif
543
544 FrameAnchor *frameAnchor = findAnchor ( leader->m_currentFramesetName, *paraList );
545
546 if ( frameAnchor )
547 {
548 ProcessPictureAnchor( myNode, leader, frameAnchor, frameType );
549 }
550 else
551 {
552 // ### TODO: non-inlined picture?
553 // No anchor found, so the picture is not inlined
554 kdDebug (30508) << "ProcessFramesetTag: Couldn't find anchor " << leader->m_currentFramesetName << endl;
555 FrameAnchor anchor;
556 ProcessPictureAnchor( myNode, leader, &anchor, frameType );
557 leader->m_nonInlinedPictureAnchors << anchor;
558 leader->m_unanchoredFramesets.append( leader->m_currentFramesetName ); // DEBUG
559 }
560
561 break;
562 }
563
564 case 4: // KFormula
565 {
566 kdWarning(30508) << "KFormula frameset not supported yet!" << endl; // ### TODO
567 break;
568 }
569 default:
570 kdWarning (30508) << "Unexpected frametype " << frameType << " (in ProcessFramesetTag)" << endl;
571 }
572
573 leader->m_currentFramesetName = oldName;
574
575#if 0
576 kdDebug (30508) << "ProcessFramesetTag () - End" << endl;
577#endif
578}
579
580
581static void ProcessFramesetsTag ( TQDomNode myNode,
582 void *tagData,
583 KWEFKWordLeader *leader )
584{
585 AllowNoAttributes (myNode);
586 TQValueList<TagProcessing> tagProcessingList;
587 tagProcessingList << TagProcessing ( "FRAMESET", ProcessFramesetTag, tagData );
588 ProcessSubtags (myNode, tagProcessingList, leader);
589}
590
591
592static void ProcessStyleTag (TQDomNode myNode, void *, KWEFKWordLeader *leader )
593{
594 LayoutData layout;
595
596 ProcessLayoutTag (myNode, &layout, leader);
597
598 leader->doFullDefineStyle (layout);
599}
600
601
602static void ProcessStylesPluralTag (TQDomNode myNode, void *, KWEFKWordLeader *leader )
603{
604 AllowNoAttributes (myNode);
605
606 leader->doOpenStyles ();
607
608 TQValueList<TagProcessing> tagProcessingList;
609 tagProcessingList << TagProcessing ( "STYLE", ProcessStyleTag, leader );
610 ProcessSubtags (myNode, tagProcessingList, leader);
611
612 leader->doCloseStyles ();
613}
614
615
616static void ProcessPaperBordersTag (TQDomNode myNode, void*, KWEFKWordLeader* leader)
617{
618
619 double left = 0.0;
620 double right = 0.0;
621 double top = 0.0;
622 double bottom = 0.0;
623
624 TQValueList<AttrProcessing> attrProcessingList;
625 if ( leader->m_oldSyntax )
626 {
627 attrProcessingList
628 << AttrProcessing ( "ptLeft", left )
629 << AttrProcessing ( "ptRight", right )
630 << AttrProcessing ( "ptTop", top )
631 << AttrProcessing ( "ptBottom", bottom )
632 << AttrProcessing ( "mmLeft" )
633 << AttrProcessing ( "mmRight" )
634 << AttrProcessing ( "mmTop" )
635 << AttrProcessing ( "mmBottom" )
636 << AttrProcessing ( "inchLeft" )
637 << AttrProcessing ( "inchRight" )
638 << AttrProcessing ( "inchTop" )
639 << AttrProcessing ( "inchBottom" )
640 ;
641 }
642 else
643 {
644 attrProcessingList
645 << AttrProcessing ( "left", left )
646 << AttrProcessing ( "right", right )
647 << AttrProcessing ( "top", top )
648 << AttrProcessing ( "bottom", bottom )
649 ;
650 }
651 ProcessAttributes (myNode, attrProcessingList);
652
653 leader->doFullPaperBorders(top, left, bottom, right);
654
655 AllowNoSubtags (myNode, leader);
656}
657
658static void ProcessPaperTag (TQDomNode myNode, void *, KWEFKWordLeader *leader)
659{
660
661 int format = -1;
662 int orientation = -1;
663 double width = -1.0;
664 double height = -1.0;
665 int hType = -1;
666 int fType = -1;
667 int columns = 1;
668 double columnspacing = 36.0; // Half-inch
669 int numPages = -1;
670
671 TQValueList<AttrProcessing> attrProcessingList;
672 attrProcessingList << AttrProcessing ( "format", format )
673 << AttrProcessing ( "width", width )
674 << AttrProcessing ( "height", height )
675 << AttrProcessing ( "orientation", orientation )
676 << AttrProcessing ( "columns", columns )
677 << AttrProcessing ( "columnspacing", columnspacing )
678 << AttrProcessing ( "pages", numPages )
679 << AttrProcessing ( "hType", hType )
680 << AttrProcessing ( "fType", fType )
681 << AttrProcessing ( "spHeadBody" )
682 << AttrProcessing ( "spFootBody" )
683 << AttrProcessing ( "spFootNoteBody" )
684 << AttrProcessing ( "slFootNotePosition" )
685 << AttrProcessing ( "slFootNoteLength" )
686 << AttrProcessing ( "slFootNoteWidth" )
687 << AttrProcessing ( "slFootNoteType" );
688
689 if ( leader->m_oldSyntax )
690 {
691 // ### TODO: in syntax 1 hType and fType have other values!
692 attrProcessingList
693 << AttrProcessing ( "ptWidth", width )
694 << AttrProcessing ( "ptHeight", height )
695 << AttrProcessing ( "ptColumnspc", columnspacing )
696 << AttrProcessing ( "mmWidth" )
697 << AttrProcessing ( "mmHeight" )
698 << AttrProcessing ( "mmColumnspc" )
699 << AttrProcessing ( "inchWidth" )
700 << AttrProcessing ( "inchHeight" )
701 << AttrProcessing ( "inchColumnspc" )
702 ;
703 }
704
705 ProcessAttributes (myNode, attrProcessingList);
706
707 leader->setHeaderType( hType );
708 leader->setFooterType( fType );
709
710 leader->doPageInfo ( hType, fType );
711 leader->doFullPaperFormat (format, width, height, orientation);
712 leader->doFullPaperFormatOther( columns, columnspacing, numPages );
713
714 TQValueList<TagProcessing> tagProcessingList;
715 tagProcessingList
716 << TagProcessing ( "PAPERBORDERS", ProcessPaperBordersTag, NULL )
717 ;
718
719 ProcessSubtags (myNode, tagProcessingList, leader);
720}
721
722static void ProcessVariableSettingsTag (TQDomNode myNode, void *, KWEFKWordLeader *leader)
723{
725 TQString print, creation, modification; // Dates (in ISO 8601 format)
726 int creationYear = -1;
727 int creationMonth = -1;
728 int creationDay = -1;
729 int modificationYear = -1;
730 int modificationMonth = -1;
731 int modificationDay = -1;
732
733 TQValueList<AttrProcessing> attrProcessingList;
734 attrProcessingList << AttrProcessing ( "startingPageNumber", vs.startingPageNumber )
735 << AttrProcessing ( "displaylink", vs.displaylink )
736 << AttrProcessing ( "underlinelink", vs.underlinelink )
737 << AttrProcessing ( "displaycomment", vs.displaycomment )
738 << AttrProcessing ( "displayfieldcode", vs.displayfieldcode )
739 ;
740
741
742 // The following 3 attributes are from syntax 3 but at least the RTF import filter generate them with syntax 2.
743 attrProcessingList
744 << AttrProcessing ( "lastPrintingDate", print )
745 << AttrProcessing ( "creationDate", creation )
746 << AttrProcessing ( "modificationDate", modification );
747 ;
748
749 // Some files have the creation and modification date not in one attribute but in an attribute for each the year, the month, the day
750 // ( e.g. syntax 2 file kofficetests/documents/export/kword/text/all.kwd )
751 attrProcessingList
752 << AttrProcessing( "modifyFileYear", modificationYear )
753 << AttrProcessing( "modifyFileMonth", modificationMonth )
754 << AttrProcessing( "modifyFileDay", modificationDay )
755 << AttrProcessing( "createFileYear", creationYear )
756 << AttrProcessing( "createFileMonth", creationMonth )
757 << AttrProcessing( "createFileDay", creationDay )
758 ;
759
760 ProcessAttributes (myNode, attrProcessingList);
761
762 if ( creation.isEmpty() )
763 {
764 if ( ( creationYear >= 1970 ) && TQDate::isValid( creationYear, creationMonth, creationDay ) )
765 {
766 vs.creationTime = TQDateTime( TQDate( creationYear, creationMonth, creationDay ) );
767 }
768 }
769 else
770 vs.creationTime=TQDateTime::fromString(creation, TQt::ISODate);
771 //kdDebug(30508) << "Creation time: " << vs.creationTime.toString( TQt::ISODate ) << endl;
772
773 if ( modification.isEmpty() )
774 {
775 if ( ( modificationYear >= 1970 ) && TQDate::isValid( modificationYear, modificationMonth, modificationDay ) )
776 {
777 vs.modificationTime = TQDateTime( TQDate( modificationYear, modificationMonth, modificationDay ) );
778 }
779 }
780 else
781 vs.modificationTime=TQDateTime::fromString(modification, TQt::ISODate);
782 //kdDebug(30508) << "Modification time: " << vs.modificationTime.toString( TQt::ISODate ) << endl;
783
784 if (!print.isEmpty())
785 vs.printTime=TQDateTime::fromString(print, TQt::ISODate);
786 //kdDebug(30508) << "Print time: " << vs.printTime.toString( TQt::ISODate ) << endl;
787
788 leader->doVariableSettings (vs);
789}
790
791static void ProcessSpellCheckIgnoreWordTag (TQDomNode myNode, void *, KWEFKWordLeader *leader )
792{
793 TQString ignoreword;
794
795 TQValueList<AttrProcessing> attrProcessingList;
796 attrProcessingList
797 << AttrProcessing ( "word", ignoreword )
798 ;
799 ProcessAttributes (myNode, attrProcessingList);
800
801 leader->doFullSpellCheckIgnoreWord (ignoreword);
802
803 AllowNoSubtags (myNode, leader);
804}
805
806
807static void ProcessSpellCheckIgnoreListTag (TQDomNode myNode, void *, KWEFKWordLeader *leader )
808{
809 AllowNoAttributes (myNode);
810
811 leader->doOpenSpellCheckIgnoreList ();
812
813 TQValueList<TagProcessing> tagProcessingList;
814 tagProcessingList << TagProcessing ( "SPELLCHECKIGNOREWORD", ProcessSpellCheckIgnoreWordTag, leader );
815 ProcessSubtags (myNode, tagProcessingList, leader);
816
817 leader->doCloseSpellCheckIgnoreList ();
818}
819
820
821static void ProcessPixmapsKeyTag ( TQDomNode myNode,
822 void *tagData,
823 KWEFKWordLeader *leader )
824{
825 TQValueList<ParaData> *paraList = (TQValueList<ParaData> *) tagData;
826
827 KoPictureKey key;
828
829 // Let KoPictureKey do most of the loading
830 key.loadAttributes(myNode.toElement());
831 const TQString name(myNode.toElement().attribute("name"));
832
833 kdDebug(30508) << "search anchors: " << key.toString() << endl;
834 bool found = false;
835
836 // NOTE: we must always search in both inlined and non-inlined pictures. A picture can be used in both ways and a few times in each!
837
838 // Process inlined pictures
839 TQValueList<ParaData>::Iterator paraIt;
840
841 for ( paraIt = paraList->begin(); paraIt != paraList->end(); ++paraIt )
842 {
843 ValueListFormatData::Iterator formattingIt;
844 for ( formattingIt = (*paraIt).formattingList.begin();
845 formattingIt != (*paraIt).formattingList.end();
846 formattingIt++ )
847 {
848 if ( ( ( (*formattingIt).id == 6 ) || ( (*formattingIt).id == 2 ) )
849 && (*formattingIt).frameAnchor.key == key )
850 {
851 kdDebug(30508) << "Found anchor for inlined picture: " << (*formattingIt).frameAnchor.key.toString() << endl;
852 (*formattingIt).frameAnchor.picture.koStoreName = name;
853 found = true;
854 }
855 }
856 }
857 // Process non-inline pictures
858 TQValueList<FrameAnchor>::Iterator it;
859 for ( it = leader->m_nonInlinedPictureAnchors.begin(); it != leader->m_nonInlinedPictureAnchors.end(); ++it )
860 {
861 if ( (*it).key == key )
862 {
863 kdDebug(30508) << "Found pseudo-anchor for non-inlined picture: " << (*it).key.toString() << endl;
864 (*it).picture.koStoreName = name;
865 found = true;
866 }
867 }
868
869 if ( !found )
870 {
871 kdWarning (30508) << "Could not find any anchor for picture " << key.toString() << endl;
872 }
873
874 AllowNoSubtags (myNode, leader);
875}
876
877
878static void ProcessPixmapsTag ( TQDomNode myNode,
879 void *tagData,
880 KWEFKWordLeader *leader )
881{
882 AllowNoAttributes (myNode);
883
884 TQValueList<TagProcessing> tagProcessingList;
885 tagProcessingList << TagProcessing ( "KEY", ProcessPixmapsKeyTag, tagData );
886 ProcessSubtags (myNode, tagProcessingList, leader);
887}
888
889
890static void FreeCellParaLists ( TQValueList<ParaData> &paraList )
891{
892 TQValueList<ParaData>::Iterator paraIt;
893
894 for ( paraIt = paraList.begin (); paraIt != paraList.end (); ++paraIt )
895 {
896 ValueListFormatData::Iterator formattingIt;
897
898 for ( formattingIt = (*paraIt).formattingList.begin ();
899 formattingIt != (*paraIt).formattingList.end ();
900 formattingIt++ )
901 {
902 if ( (*formattingIt).id == 6 && (*formattingIt).frameAnchor.type == 6 )
903 {
904 TQValueList<TableCell>::Iterator cellIt;
905
906 for ( cellIt = (*formattingIt).frameAnchor.table.cellList.begin ();
907 cellIt != (*formattingIt).frameAnchor.table.cellList.end ();
908 cellIt++ )
909 {
910 FreeCellParaLists ( *(*cellIt).paraList ); // recursion is great
911 delete (*cellIt).paraList;
912 }
913 }
914 }
915 }
916}
917
918// like ProcessFramesetTag, but only handle footnotes
919static void ProcessFootnoteFramesetTag ( TQDomNode myNode, void *tagData, KWEFKWordLeader *leader )
920{
921 TQString frameName;
922 int frameType = -1, frameInfo = -1;
923 bool visible = false;
924
925 TQValueList<AttrProcessing> attrProcessingList;
926 attrProcessingList
927 << AttrProcessing ( "name", frameName )
928 << AttrProcessing ( "frameType", frameType )
929 << AttrProcessing ( "frameInfo", frameInfo )
930 << AttrProcessing ( "removable" )
931 << AttrProcessing ( "visible", visible )
932 << AttrProcessing ( "grpMgr" )
933 << AttrProcessing ( "row" )
934 << AttrProcessing ( "col" )
935 << AttrProcessing ( "rows" )
936 << AttrProcessing ( "cols" )
937 << AttrProcessing ( "protectSize" )
938 ;
939 ProcessAttributes (myNode, attrProcessingList);
940
941 // for footnote frame, frameType is 1 and frameInfo is 7
942 if( ( frameType == 1 ) && ( frameInfo == 7 ) )
943 {
944 FootnoteData footnote;
945 footnote.frameName = frameName;
946 TQValueList<TagProcessing> tagProcessingList;
947 tagProcessingList.append(TagProcessing ( "FRAME" ));
948 tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footnote.para ));
949 ProcessSubtags (myNode, tagProcessingList, leader);
950 leader->footnoteList.append( footnote );
951 }
952}
953
954// like ProcessFramesetsTag, but only handle footnotes
955static void ProcessFootnoteFramesetsTag ( TQDomNode myNode, void *tagData, KWEFKWordLeader *leader )
956{
957 AllowNoAttributes (myNode);
958
959 TQValueList<TagProcessing> tagProcessingList;
960 tagProcessingList << TagProcessing ( "FRAMESET", ProcessFootnoteFramesetTag, tagData );
961 ProcessSubtags (myNode, tagProcessingList, leader);
962}
963
964static void ProcessBookmarkItemTag ( TQDomNode myNode, void* tag, KWEFKWordLeader *leader )
965{
966 TQValueList<Bookmark> * bookmarkList = static_cast< TQValueList<Bookmark> * > ( tag );
967
968 Bookmark bookmark;
969
970 TQValueList<AttrProcessing> attrProcessingList;
971 attrProcessingList
972 << AttrProcessing ( "name", bookmark.m_name )
973 << AttrProcessing ( "cursorIndexStart", bookmark.m_cursorIndexStart )
974 << AttrProcessing ( "cursorIndexEnd", bookmark.m_cursorIndexEnd )
975 << AttrProcessing ( "frameset", bookmark.m_frameset )
976 << AttrProcessing ( "startparag", bookmark.m_startparag )
977 << AttrProcessing ( "endparag", bookmark.m_endparag )
978 ;
979
980 ProcessAttributes (myNode, attrProcessingList);
981
982 AllowNoSubtags( myNode, leader );
983
984 // ### TODO: some verifications
985
986 kdDebug(30508) << "Bookmark: " << bookmark.m_name << " in frameset " << bookmark.m_frameset << endl;
987
988 bookmarkList->append( bookmark );
989}
990
991static void ProcessBookmarksTag ( TQDomNode myNode, void* tag, KWEFKWordLeader *leader )
992{
993 AllowNoAttributes (myNode);
994
995 TQValueList<TagProcessing> tagProcessingList;
996 tagProcessingList << TagProcessing ( "BOOKMARKITEM", ProcessBookmarkItemTag, tag );
997 ProcessSubtags (myNode, tagProcessingList, leader);
998}
999
1000void ProcessDocTag ( TQDomNode myNode,
1001 void* /*tagData*/, KWEFKWordLeader* leader )
1002{
1003 //kdDebug (30508) << "Entering ProcessDocTag" << endl;
1004
1005 TQString editor, author;
1006
1007 TQValueList<AttrProcessing> attrProcessingList;
1008
1009 attrProcessingList
1010 << AttrProcessing ( "xmlns" )
1011 << AttrProcessing ( "editor", editor )
1012 << AttrProcessing ( "mime" )
1013 << AttrProcessing ( "syntaxVersion", leader->m_syntaxVersion )
1014 << AttrProcessing ( "author", author )
1015 << AttrProcessing ( "email" )
1016 ;
1017
1018 ProcessAttributes( myNode, attrProcessingList );
1019
1020 kdDebug(30508) << "Document written by " << editor << endl;
1021 kdDebug(30508) << "Document of syntax version " << leader->m_syntaxVersion << endl;
1022
1023 if ( leader->m_syntaxVersion == 1 )
1024 {
1025 leader->m_oldSyntax = true; // Syntax 1 is old syntax
1026 }
1027 else if ( leader->m_syntaxVersion == -1 )
1028 {
1029 // We do not know the version, but it still might be an old syntax.
1030 // However such old documents have still an author attribute, so check its value
1031 if ( author == "Reginald Stadlbauer and Torben Weis" )
1032 {
1033 kdDebug(30508) << "No syntax version but author attribute matches => assuming old syntax" << endl;
1034 leader->m_oldSyntax = true;
1035 }
1036 else
1037 {
1038 kdWarning(30508) << "No syntax version found, author attribute does not match => assuming new syntax" << endl;
1039 }
1040 }
1041
1042 leader->doOpenHead();
1043
1044 // At first, process <SPELLCHECKIGNORELIST>, even if mostly it will not be needed
1045 TQDomNode nodeIgnoreList=myNode.namedItem("SPELLCHECKIGNORELIST");
1046 if ( nodeIgnoreList.isNull () )
1047 kdDebug (30508) << "No <SPELLCHECKIGNORELIST>" << endl; // Most files will not have it!
1048 else
1049 ProcessSpellCheckIgnoreListTag (nodeIgnoreList, NULL, leader);
1050
1051 // Process <PAPER> now, even if mostly the output will need to be delayed.
1052 TQDomNode nodePaper=myNode.namedItem("PAPER");
1053 if ( nodePaper.isNull () )
1054 kdWarning (30508) << "No <PAPER>" << endl;
1055 else
1056 ProcessPaperTag (nodePaper, NULL, leader);
1057
1058 // Process <VARIABLESETTINGS>
1059 TQDomNode nodeVariableSettings=myNode.namedItem("VARIABLESETTINGS");
1060 if ( nodeVariableSettings.isNull () )
1061 kdWarning (30508) << "No <VARIABLESETTINGS>" << endl;
1062 else
1063 ProcessVariableSettingsTag (nodeVariableSettings, NULL, leader);
1064
1065 // Then we process the styles
1066 TQDomNode nodeStyles=myNode.namedItem("STYLES");
1067 if ( nodeStyles.isNull () )
1068 kdWarning (30508) << "No <STYLES>" << endl;
1069 else
1070 ProcessStylesPluralTag (nodeStyles, NULL, leader);
1071
1072 // Process framesets, but only to find and extract footnotes (also endnotes)
1073 TQValueList<FootnoteData> footnotes;
1074 TQDomNode nodeFramesets=myNode.namedItem("FRAMESETS");
1075 if ( !nodeFramesets.isNull() )
1076 ProcessFootnoteFramesetsTag(nodeFramesets, &footnotes, leader );
1077
1078 // Process all framesets and pictures
1079 TQValueList<TagProcessing> tagProcessingList;
1080 TQValueList<ParaData> paraList;
1081
1082 tagProcessingList
1083 << TagProcessing ( "PAPER" ) // Already done
1084 << TagProcessing ( "ATTRIBUTES" )
1085 << TagProcessing ( "FRAMESETS", ProcessFramesetsTag, &paraList )
1086 << TagProcessing ( "STYLES" ) // Already done
1087 << TagProcessing ( "PICTURES", ProcessPixmapsTag, &paraList )
1088 << TagProcessing ( "PIXMAPS", ProcessPixmapsTag, &paraList )
1089 << TagProcessing ( "CLIPARTS", ProcessPixmapsTag, &paraList )
1090 << TagProcessing ( "EMBEDDED" )
1091 << TagProcessing ( "BOOKMARKS", ProcessBookmarksTag, &leader->m_bookmarkList )
1092 ;
1093
1094 // TODO: why are the followings used by KWord 1.2 but are not in its DTD?
1095 tagProcessingList << TagProcessing ( "SERIALL" );
1096 tagProcessingList << TagProcessing ( "FOOTNOTEMGR" );
1097
1098 ProcessSubtags (myNode, tagProcessingList, leader);
1099
1100 leader->doCloseHead();
1101 leader->doDeclareNonInlinedFramesets( leader->m_nonInlinedPictureAnchors, leader->m_nonInlinedTableAnchors );
1102 leader->doOpenBody();
1103
1104 leader->doFullDocument (paraList);
1105
1106 kdDebug(30508) << "Unachored Framesets : START" << endl;
1107 TQStringList::ConstIterator it;
1108 for ( it = leader->m_unanchoredFramesets.begin(); it != leader->m_unanchoredFramesets.end(); ++it )
1109 {
1110 kdDebug(30508) << (*it) << endl;
1111 }
1112 kdDebug(30508) << "Unachored Framesets : END" << endl;
1113
1114 FreeCellParaLists (paraList);
1115
1116 leader->doCloseBody();
1117
1118 //kdDebug (30508) << "Exiting ProcessDocTag" << endl;
1119}
1120
1121
1122void KWEFKWordLeader::setWorker ( KWEFBaseWorker *newWorker )
1123{
1124 m_worker = newWorker;
1125
1126 if (newWorker)
1127 newWorker->registerKWordLeader(this);
1128}
1129
1130
1131KWEFBaseWorker *KWEFKWordLeader::getWorker(void) const
1132{
1133 return m_worker;
1134}
1135
1136
1137// Short simple definition for methods with void parameter
1138#define DO_VOID_DEFINITION(string) \
1139 bool KWEFKWordLeader::string() \
1140 {\
1141 if (m_worker) \
1142 return m_worker->string(); \
1143 return false; \
1144 }
1145
1146
1147bool KWEFKWordLeader::doOpenFile ( const TQString &filenameOut, const TQString &to )
1148{
1149 if ( m_worker )
1150 return m_worker->doOpenFile (filenameOut, to);
1151
1152 // As it would be the first method to be called, warn if worker is NULL
1153 kdError (30508) << "No Worker! (in KWEFKWordLeader::doOpenFile)" << endl;
1154
1155 return false;
1156}
1157
1158
1159DO_VOID_DEFINITION (doCloseFile)
1160DO_VOID_DEFINITION (doAbortFile)
1161DO_VOID_DEFINITION (doOpenDocument)
1162DO_VOID_DEFINITION (doCloseDocument)
1163DO_VOID_DEFINITION (doOpenStyles)
1164DO_VOID_DEFINITION (doCloseStyles)
1165DO_VOID_DEFINITION (doOpenHead)
1166DO_VOID_DEFINITION (doCloseHead)
1167DO_VOID_DEFINITION (doOpenBody)
1168DO_VOID_DEFINITION (doCloseBody)
1169DO_VOID_DEFINITION (doOpenSpellCheckIgnoreList)
1170DO_VOID_DEFINITION (doCloseSpellCheckIgnoreList)
1171
1172bool KWEFKWordLeader::doFullDocumentInfo (const KWEFDocumentInfo &docInfo)
1173{
1174 if ( m_worker )
1175 return m_worker->doFullDocumentInfo (docInfo);
1176
1177 return false;
1178}
1179
1180
1181bool KWEFKWordLeader::doVariableSettings (const VariableSettingsData &varSettings)
1182{
1183 if ( m_worker )
1184 return m_worker->doVariableSettings (varSettings);
1185
1186 return false;
1187}
1188
1189
1190bool KWEFKWordLeader::doFullDocument (const TQValueList<ParaData> &paraList)
1191{
1192 if ( m_worker )
1193 return m_worker->doFullDocument (paraList);
1194
1195 return false;
1196}
1197
1198bool KWEFKWordLeader::doPageInfo ( const int headerType, const int footerType )
1199{
1200 if ( m_worker )
1201 return m_worker->doPageInfo ( headerType, footerType );
1202
1203 return false;
1204}
1205
1206bool KWEFKWordLeader::doFullPaperFormat ( const int format, const double width, const double height, const int orientation )
1207{
1208 if ( m_worker )
1209 return m_worker->doFullPaperFormat (format, width, height, orientation);
1210
1211 return false;
1212}
1213
1214bool KWEFKWordLeader::doFullPaperBorders (const double top, const double left, const double bottom, const double right)
1215{
1216 if ( m_worker )
1217 return m_worker->doFullPaperBorders (top, left, bottom, right);
1218
1219 return false;
1220}
1221
1222bool KWEFKWordLeader::doFullPaperFormatOther ( const int columns, const double columnspacing, const int numPages )
1223{
1224 if ( m_worker )
1225 return m_worker->doFullPaperFormatOther ( columns, columnspacing, numPages );
1226
1227 return false;
1228}
1229
1230bool KWEFKWordLeader::doFullDefineStyle ( LayoutData &layout )
1231{
1232 if ( m_worker )
1233 return m_worker->doFullDefineStyle (layout);
1234
1235 return false;
1236}
1237
1238bool KWEFKWordLeader::doFullSpellCheckIgnoreWord (const TQString& ignoreword)
1239{
1240 if ( m_worker )
1241 return m_worker->doFullSpellCheckIgnoreWord (ignoreword);
1242
1243 return false;
1244}
1245
1246bool KWEFKWordLeader::doHeader ( const HeaderData& header )
1247{
1248 if ( m_worker )
1249 return m_worker->doHeader (header);
1250
1251 return false;
1252}
1253
1254bool KWEFKWordLeader::doFooter ( const FooterData& footer )
1255{
1256 if ( m_worker )
1257 return m_worker->doFooter (footer);
1258
1259 return false;
1260}
1261
1262bool KWEFKWordLeader::doDeclareNonInlinedFramesets( TQValueList<FrameAnchor>& pictureAnchors, TQValueList<FrameAnchor>& tableAnchors )
1263{
1264 if ( m_worker )
1265 return m_worker->doDeclareNonInlinedFramesets( pictureAnchors, tableAnchors );
1266
1267 return false;
1268}
1269
1270static bool ParseFile ( TQIODevice* subFile, TQDomDocument& doc)
1271{
1272 TQString errorMsg;
1273 int errorLine;
1274 int errorColumn;
1275
1276 if ( !doc.setContent (subFile, &errorMsg, &errorLine, &errorColumn) )
1277 {
1278 kdError (30508) << "Parsing Error! Aborting! (in ParseFile)" << endl
1279 << " Line: " << errorLine << " Column: " << errorColumn << endl
1280 << " Message: " << errorMsg << endl;
1281 // ### TODO: the error is in which sub-file?
1282 KMessageBox::error( 0L, i18n("An error has occurred while parsing the KWord file.\nAt line: %1, column %2\nError message: %3")
1283 .arg( errorLine ).arg( errorColumn ).arg(i18n( "TQXml", errorMsg.utf8() ) ),
1284 i18n("KWord Export Filter Library"), 0 );
1285 return false;
1286 }
1287 return true;
1288}
1289
1290static bool ProcessStoreFile ( TQIODevice* subFile,
1291 void (*processor) (TQDomNode, void *, KWEFKWordLeader *),
1292 KWEFKWordLeader* leader)
1293{
1294 if (!subFile)
1295 {
1296 kdWarning(30508) << "Could not get a device for the document!" << endl;
1297 }
1298 else if ( subFile->open ( IO_ReadOnly ) )
1299 {
1300 kdDebug (30508) << "Processing Document..." << endl;
1301 TQDomDocument doc;
1302 if (!ParseFile(subFile, doc))
1303 {
1304 subFile->close();
1305 return false;
1306 }
1307 // We must close the subFile before processing,
1308 // as the processing could open other sub files.
1309 // However, it would crash if two sub files are opened together
1310 subFile->close();
1311
1312 TQDomNode docNode = doc.documentElement();
1313 processor (docNode, NULL, leader);
1314 return true;
1315 }
1316 else
1317 {
1318 // Note: we do not worry too much if we cannot open the document info!
1319 kdWarning (30508) << "Unable to open document!" << endl;
1320 }
1321 return false;
1322}
1323
1324TQIODevice* KWEFKWordLeader::getSubFileDevice(const TQString& fileName)
1325{
1326 KoStoreDevice* subFile;
1327
1328 subFile=m_chain->storageFile(fileName,KoStore::Read);
1329
1330 if (!subFile)
1331 {
1332 kdError(30508) << "Could not get a device for sub-file: " << fileName << endl;
1333 return NULL;
1334 }
1335 return subFile;
1336}
1337
1338
1339bool KWEFKWordLeader::loadSubFile(const TQString& fileName, TQByteArray& array)
1340{
1341 KoStoreDevice* subFile;
1342
1343 subFile=m_chain->storageFile(fileName,KoStore::Read);
1344
1345 if (!subFile)
1346 {
1347 kdError(30508) << "Could not get a device for sub-file: " << fileName << endl;
1348 return false;
1349 }
1350 else if ( subFile->open ( IO_ReadOnly ) )
1351 {
1352 array = subFile->readAll();
1353 subFile->close ();
1354 }
1355 else
1356 {
1357 kdError(30508) << "Unable to open " << fileName << " sub-file" << endl;
1358 return false;
1359 }
1360
1361 return true;
1362}
1363
1364KoFilter::ConversionStatus KWEFKWordLeader::convert( KoFilterChain* chain,
1365 const TQCString& from, const TQCString& to)
1366{
1367 if ( from != "application/x-kword" )
1368 {
1369 return KoFilter::NotImplemented;
1370 }
1371
1372 if (!chain)
1373 {
1374 kdError(30508) << "'Chain' is NULL! Internal error of the filter system?" << endl;
1375 return KoFilter::StupidError;
1376 }
1377
1378 m_chain=chain;
1379
1380 if ( !doOpenFile (chain->outputFile(),to) )
1381 {
1382 kdError (30508) << "Worker could not open export file! Aborting!" << endl;
1383 return KoFilter::StupidError;
1384 }
1385
1386 if ( !doOpenDocument () )
1387 {
1388 kdError (30508) << "Worker could not open document! Aborting!" << endl;
1389 doAbortFile ();
1390 return KoFilter::StupidError;
1391 }
1392
1393 KoStoreDevice* subFile;
1394
1395 subFile=chain->storageFile("documentinfo.xml",KoStore::Read);
1396 kdDebug (30508) << "Processing documentinfo.xml..." << endl;
1397 // Do not care if we cannot open the document info.
1398 ProcessStoreFile (subFile, ProcessDocumentInfoTag, this);
1399
1400 subFile=chain->storageFile("root",KoStore::Read);
1401 kdDebug (30508) << "Processing root..." << endl;
1402 if (!ProcessStoreFile (subFile, ProcessDocTag, this))
1403 {
1404 kdWarning(30508) << "Opening root has failed. Trying raw XML file!" << endl;
1405
1406 const TQString filename( chain->inputFile() );
1407 if (filename.isEmpty() )
1408 {
1409 kdError(30508) << "Could not open document as raw XML! Aborting!" << endl;
1410 doAbortFile();
1411 return KoFilter::StupidError;
1412 }
1413 else
1414 {
1415 TQFile file( filename );
1416 if ( ! ProcessStoreFile( &file, ProcessDocTag, this ) )
1417 {
1418 kdError(30508) << "Could not process document! Aborting!" << endl;
1419 doAbortFile();
1420 return KoFilter::StupidError;
1421 }
1422 }
1423 }
1424
1425 doCloseDocument ();
1426
1427 doCloseFile ();
1428
1429 return KoFilter::OK;
1430}
The class AttrProcessing and the two functions ProcessAttributes () and AllowNoSubtags () allow for e...
This is basically <FRAMESET> tag.
KoPictureKey key
Picture key.
Base worker of the libexport system.
Paragraph layout.
void addCell(int c, int r, int _cols, int _rows, TQValueList< ParaData > &p, FrameData &frameData)
The class TagProcessing and the two functions ProcessSubtags () and AllowNoSubtags () allow for easin...
see <VARIABLESETTINGS> in the KWord DTD
data for <FRAMESET> which holds footnotes