25#include <docbookexport.h>
26#include <docbookexport.moc>
28#include <kgenericfactory.h>
32#include <KoFilterChain.h>
33#include <KWEFStructures.h>
35#include <KWEFKWordLeader.h>
36#include <ProcessDocument.h>
37#include <KWEFBaseWorker.h>
39typedef KGenericFactory<DocBookExport, KoFilter> DocBookExportFactory;
40K_EXPORT_COMPONENT_FACTORY( libdocbookexport, DocBookExportFactory(
"kofficefilters" ) )
42DocBookExport::DocBookExport ( KoFilter *,
44 const TQStringList & ) : KoFilter ()
49#define INSERT_TABLE_IN_PARA 1
50#define TABLES_WITH_TITLES 0
62 bool alphabeticalList;
69 DocBookWorker (
void) {}
71 bool doOpenDocument (
void );
72 bool doCloseDocument (
void );
74 bool doOpenFile (
const TQString &,
const TQString & );
75 bool doCloseFile (
void );
80 bool doFullDocumentInfo (
const KWEFDocumentInfo & );
82 bool doFullDocument (
const TQValueList<ParaData> ¶List );
85 void ProcessPictureData (
const Picture &picture );
87 void ProcessTableData (
const Table &table );
89 void ProcessParagraphData (
const ParaData ¶,
92 void CloseItemizedList (
void );
93 void CloseEnumeratedList (
void );
94 void CloseAlphabeticalList (
void );
95 void CloseLists (
void );
97 void CloseHead4 (
void );
98 void CloseHead3 (
void );
99 void CloseHead2 (
void );
100 void CloseHead1AndArticle (
void );
102 void OpenArticleUnlessHead1 (
void );
107 TQString exportFileName;
115void DocBookWorker::ProcessPictureData (
const Picture &picture )
117 TQByteArray byteArray;
119 if ( loadSubFile ( picture.koStoreName,byteArray ) )
121 TQFileInfo fileInfo (exportFileName);
122 TQDir dir ( fileInfo.dirPath () );
123 TQString subDirName = fileInfo.fileName () +
".d";
125 if ( !dir.exists (subDirName) )
127 dir.mkdir (subDirName);
132 if ( !dir.exists (
"pictures") )
134 dir.mkdir (
"pictures");
137 TQString pictureFileName = dir.filePath (picture.koStoreName);
139 TQFile pictureFile (pictureFileName);
141 if ( pictureFile.open (IO_WriteOnly) )
143 pictureFile.writeBlock ( byteArray, byteArray.size () );
145 TQString pictureText;
147#if TABLES_WITH_TITLES
148 pictureText +=
"<FIGURE>\n";
151 pictureText +=
" <TITLE>" + picture.name +
"</TITLE>\n";
153 pictureText +=
" <TITLE></TITLE>\n";
156 pictureText +=
"<INFORMALFIGURE>\n";
158 pictureText +=
" <MEDIAOBJECT>\n";
159 pictureText +=
" <IMAGEOBJECT>\n";
160 pictureText +=
" <IMAGEDATA FILEREF=\"" + pictureFileName +
"\">\n";
161 pictureText +=
" </IMAGEOBJECT>\n";
162 pictureText +=
" </MEDIAOBJECT>\n";
163#if TABLES_WITH_TITLES
164 pictureText +=
"</FIGURE>\n";
166 pictureText +=
"</INFORMALFIGURE>\n";
169 outputText += pictureText;
173 kdError (30507) <<
"Unable to open picture file " << pictureFileName <<
"!" << endl;
175 pictureFile.close ();
180 kdError (30507) <<
"Unable to open KoStore file " << picture.koStoreName <<
"!" << endl;
188void DocBookWorker::ProcessTableData (
const Table &table )
191 kdError (30507) <<
"DEBUG: ProcessTableData ()" << endl;
196#if TABLES_WITH_TITLES
197 tableText +=
"<TABLE>\n";
200 tableText +=
" <TITLE>" + table.name +
"</TITLE>\n";
202 tableText +=
" <TITLE></TITLE>\n";
205 tableText +=
"<INFORMALTABLE>\n";
208 tableText +=
" <TGROUP COLS=\"" + TQString::number (table.cols) +
"\">\n";
209 tableText +=
" <TBODY>\n";
213 TQValueList<TableCell>::ConstIterator cellIt;
215 for ( cellIt = table.cellList.begin ();
216 cellIt != table.cellList.end ();
219 if ( (*cellIt).row != currentRow )
221 if ( currentRow >= 0 )
223 tableText +=
" </ROW>\n";
226 currentRow = (*cellIt).row;
228 tableText +=
" <ROW>\n";
235 doFullDocument ( *(*cellIt).paraList );
237 tableText +=
" <ENTRY>" + outputText.remove (
'\n' ) +
"</ENTRY>\n";
242 if ( currentRow >= 0 )
244 tableText +=
" </ROW>\n";
247 tableText +=
" </TBODY>\n";
248 tableText +=
" </TGROUP>\n";
250#if TABLES_WITH_TITLES
251 tableText +=
"</TABLE>\n";
253 tableText +=
"</INFORMALTABLE>\n";
256 outputText += tableText;
259 kdError (30507) <<
"DEBUG: ProcessTableData (): " << tableText << endl;
268void DocBookWorker::ProcessParagraphData (
const ParaData ¶,
271#if !INSERT_TABLE_IN_PARA
272 TQValueList<AnchoredInsert> tmpAnchoredInsertList;
275 outputText +=
"<" + tag +
">";
277 if ( para.text.length () > 0 )
279 ValueListFormatData::ConstIterator formattingIt;
281 for ( formattingIt = para.formattingList.begin ();
282 formattingIt != para.formattingList.end ();
285 switch ( (*formattingIt).id )
290 bool fixedFont =
false;
292 if ( (*formattingIt).text.fontName ==
"courier" ||
293 (*formattingIt).text.fontName ==
"Courier" ||
294 (*formattingIt).text.fontName ==
"Courier New" )
299 if ( (*formattingIt).text.italic && !para.layout.formatData.text.italic )
301 outputText +=
"<EMPHASIS>";
304 if ( (*formattingIt).text.weight > para.layout.formatData.text.weight )
306 outputText +=
"<EMPHASIS ROLE=bold>";
311 outputText +=
"<LITERAL>";
314 outputText += EscapeXmlText (para.text.mid ( (*formattingIt).pos, (*formattingIt).len ));
318 outputText +=
"</LITERAL>";
321 if ( (*formattingIt).text.weight > para.layout.formatData.text.weight )
323 outputText +=
"</EMPHASIS>";
326 if ( (*formattingIt).text.italic && !para.layout.formatData.text.italic )
328 outputText +=
"</EMPHASIS>";
334 if (9 == (*formattingIt).variable.m_type)
337 outputText +=
"<ULINK URL=\"";
338 outputText += EscapeXmlText ( (*formattingIt).variable.getHrefName(),
true,
true );
340 outputText += EscapeXmlText ( (*formattingIt).variable.getLinkName() );
341 outputText +=
"</ULINK>";
345 outputText += EscapeXmlText ( (*formattingIt).variable.m_text );
351 kdError (30507) <<
"Processing anchor " << (*formattingIt).frameAnchor.name << endl;
354#if INSERT_TABLE_IN_PARA
355 outputText +=
"</" + tag +
">\n";
358 anchoredInsertList.prepend ( AnchoredInsert ( (*formattingIt).frameAnchor.name,
359 outputText.length () ) );
362 switch ( (*formattingIt).frameAnchor.type )
365 ProcessPictureData ( (*formattingIt).frameAnchor.picture );
369 ProcessTableData ( (*formattingIt).frameAnchor.table );
373 kdError (30507) <<
"Unhandled anchor type "
374 << (*formattingIt).frameAnchor.type <<
"!" << endl;
377 tmpAnchoredInsertList << AnchoredInsert ( (*formattingIt).frameAnchor.name, 0 );
380 outputText +=
"<" + tag +
">";
385 kdError (30507) <<
"Unhandled format id "
386 << (*formattingIt).id <<
"!" << endl;
391 outputText +=
"</" + tag +
">\n";
393#if !INSERT_TABLE_IN_PARA
394 TQValueList<AnchoredInsert>::Iterator anchoredInsert;
396 for ( anchoredInsert = tmpAnchoredInsertList.begin ();
397 anchoredInsert != tmpAnchoredInsertList.end ();
400 (*anchoredInsert).pos = outputText.length ();
401 anchoredInsertList.prepend (*anchoredInsert);
407void DocBookWorker::CloseItemizedList (
void )
409 if ( docData.bulletList )
411 outputText +=
"</ITEMIZEDLIST> <!-- End of Bullet List -->\n";
412 docData.bulletList =
false;
417void DocBookWorker::CloseEnumeratedList (
void )
419 if ( docData.enumeratedList )
421 outputText +=
"</ORDEREDLIST> <!-- End of Enumerated List -->\n";
422 docData.enumeratedList =
false;
427void DocBookWorker::CloseAlphabeticalList (
void )
429 if ( docData.alphabeticalList )
431 outputText +=
"</ORDEREDLIST> <!-- End of Alphabetical List -->\n";
432 docData.alphabeticalList =
false;
437void DocBookWorker::CloseLists (
void )
439 CloseItemizedList ();
440 CloseEnumeratedList ();
441 CloseAlphabeticalList ();
445void DocBookWorker::CloseHead4 (
void )
451 outputText +=
"</SECTION> <!-- End of Head 4 -->\n";
452 docData.head4 =
false;
457void DocBookWorker::CloseHead3 (
void )
463 outputText +=
"</SECTION> <!-- End of Head 3 -->\n";
464 docData.head3 =
false;
469void DocBookWorker::CloseHead2 (
void )
475 outputText +=
"</SECTION> <!-- End of Head 2 -->\n";
476 docData.head2 =
false;
481void DocBookWorker::CloseHead1AndArticle (
void )
485 if ( docData.article )
487 outputText +=
"</ARTICLE>\n";
488 docData.article =
false;
493 outputText +=
"</CHAPTER> <!-- End of Head 1 -->\n";
494 docData.head1 =
false;
499void DocBookWorker::OpenArticleUnlessHead1 (
void )
501 if ( !docData.head1 && !docData.article )
503 outputText +=
"<ARTICLE> <!-- Begin of Article -->\n";
504 docData.article =
true;
509bool DocBookWorker::doFullDocument (
const TQValueList<ParaData> ¶List )
512 kdError (30507) <<
"doFullDocument () - Begin" << endl;
515 TQValueList<ParaData>::ConstIterator paraIt;
516 TQValueList<ParaData>::ConstIterator end(paraList.end ());
517 for ( paraIt = paraList.begin (); paraIt != end ; ++paraIt )
519 switch ( (*paraIt).layout.counter.numbering )
522 switch ( (*paraIt).layout.counter.style )
524 case CounterData::STYLE_CUSTOMBULLET:
525 case CounterData::STYLE_CIRCLEBULLET:
526 case CounterData::STYLE_SQUAREBULLET:
527 case CounterData::STYLE_DISCBULLET:
528 case CounterData::STYLE_CUSTOM:
529 case CounterData::STYLE_NONE:
530 CloseEnumeratedList ();
531 CloseAlphabeticalList ();
533 OpenArticleUnlessHead1 ();
535 if ( !docData.bulletList )
537 outputText +=
"<ITEMIZEDLIST> <!-- Begin of Bullet List -->\n";
538 docData.bulletList =
true;
541 outputText +=
"<LISTITEM>\n";
542 ProcessParagraphData (*paraIt,
"PARA" );
543 outputText +=
"</LISTITEM>\n";
546 case CounterData::STYLE_NUM:
547 case CounterData::STYLE_ROM_NUM_L:
548 case CounterData::STYLE_ROM_NUM_U:
549 CloseItemizedList ();
550 CloseAlphabeticalList ();
552 OpenArticleUnlessHead1 ();
554 if ( !docData.enumeratedList )
556 outputText +=
"<ORDEREDLIST NUMERATION=\"Arabic\"> <!-- Begin of Enumerated List -->\n";
557 docData.enumeratedList =
true;
560 outputText +=
"<LISTITEM>\n";
561 ProcessParagraphData (*paraIt,
"PARA" );
562 outputText +=
"</LISTITEM>\n";
565 case CounterData::STYLE_ALPHAB_L:
566 case CounterData::STYLE_ALPHAB_U:
567 CloseItemizedList ();
568 CloseEnumeratedList ();
570 OpenArticleUnlessHead1 ();
572 if ( !docData.alphabeticalList )
574 outputText +=
"<ORDEREDLIST NUMERATION=\"Loweralpha\"> <!-- Begin of Alphabetical List -->\n";
575 docData.alphabeticalList =
true;
578 outputText +=
"<LISTITEM>\n";
579 ProcessParagraphData (*paraIt,
"PARA" );
580 outputText +=
"</LISTITEM>\n";
584 kdError (30507) <<
"Unknown counter style " << (*paraIt).layout.counter.style <<
"!" << endl;
586 OpenArticleUnlessHead1 ();
587 ProcessParagraphData (*paraIt,
"PARA" );
593 switch ( (*paraIt).layout.counter.depth )
596 CloseHead1AndArticle ();
598 outputText +=
"<CHAPTER> <!-- Begin of Head 1 -->\n";
599 docData.head1 =
true;
601 ProcessParagraphData (*paraIt,
"TITLE" );
607 outputText +=
"<SECTION> <!-- Begin of Head 2 -->\n";
608 docData.head2 =
true;
610 ProcessParagraphData (*paraIt,
"TITLE" );
616 outputText +=
"<SECTION> <!-- Begin of Head 3 -->\n";
617 docData.head3 =
true;
619 ProcessParagraphData (*paraIt,
"TITLE" );
625 outputText +=
"<SECTION> <!-- Begin of Head 4 -->\n";
626 docData.head4 =
true;
628 ProcessParagraphData (*paraIt,
"TITLE" );
632 kdError (30507) <<
"Unexpected chapter depth " << (*paraIt).layout.counter.depth <<
"!" << endl;
634 OpenArticleUnlessHead1 ();
635 ProcessParagraphData (*paraIt,
"PARA" );
642 OpenArticleUnlessHead1 ();
643 ProcessParagraphData (*paraIt,
"PARA" );
648 kdError (30507) <<
"doFullDocument () - End" << outputText << endl;
654bool DocBookWorker::doOpenDocument (
void )
656 outputText +=
"<!DOCTYPE BOOK PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\">\n";
657 outputText +=
"<BOOK>\n";
665 docData.article =
false;
666 docData.head1 =
false;
667 docData.head2 =
false;
668 docData.head3 =
false;
669 docData.head4 =
false;
670 docData.bulletList =
false;
671 docData.enumeratedList =
false;
672 docData.alphabeticalList =
false;
680 CloseHead1AndArticle ();
686bool DocBookWorker::doCloseDocument (
void )
688 outputText +=
"</BOOK>\n";
694bool DocBookWorker::doOpenFile (
const TQString &filenameOut,
const TQString & )
696 fileOut =
new TQFile(filenameOut);
700 kdError(30507) <<
"No output file! Aborting!" << endl;
704 if ( !fileOut->open (IO_WriteOnly) )
706 kdError(30507) <<
"Unable to open output file!" << endl;
715 exportFileName=filenameOut;
721bool DocBookWorker::doCloseFile (
void )
723 if ( !fileOut )
return true;
727 TQCString cstr = outputText.local8Bit ();
728 fileOut->writeBlock ( cstr, cstr.length () );
743static void ProcessInfoData (
const TQString &tagName,
744 const TQString & tagText,
745 TQString &outputText)
747 if ( tagText.length () )
749 outputText +=
"<" + tagName +
">" + tagText +
"</" + tagName +
">\n";
754bool DocBookWorker::doFullDocumentInfo (
const KWEFDocumentInfo &docInfo )
756 TQString bookInfoText;
757 TQString abstractText;
759 TQString affiliationText;
760 TQString addressText;
762 ProcessInfoData (
"TITLE", docInfo.title, bookInfoText );
763 ProcessInfoData (
"PARA", docInfo.abstract, abstractText );
764 ProcessInfoData (
"SURNAME", docInfo.fullName, authorText );
765 ProcessInfoData (
"JOBTITLE", docInfo.jobTitle, affiliationText );
766 ProcessInfoData (
"ORGNAME", docInfo.company, affiliationText );
767 ProcessInfoData (
"STREET", docInfo.street, addressText );
768 ProcessInfoData (
"CITY", docInfo.city, addressText );
769 ProcessInfoData (
"POSTCODE", docInfo.postalCode, addressText );
770 ProcessInfoData (
"COUNTRY", docInfo.country, addressText );
771 ProcessInfoData (
"EMAIL", docInfo.email, addressText );
772 ProcessInfoData (
"PHONE", docInfo.telephone, addressText );
773 ProcessInfoData (
"FAX", docInfo.fax, addressText );
775 ProcessInfoData (
"ADDRESS", addressText, affiliationText );
776 ProcessInfoData (
"AFFILIATION", affiliationText, authorText );
777 ProcessInfoData (
"ABSTRACT", abstractText, bookInfoText );
778 ProcessInfoData (
"AUTHOR", authorText, bookInfoText );
779 ProcessInfoData (
"BOOKINFO", bookInfoText, outputText );
785KoFilter::ConversionStatus DocBookExport::convert(
const TQCString& from,
const TQCString& to )
788 kdError (30507) <<
"to = " << to <<
", from = " << from << endl;
791 if ( to !=
"text/sgml" && to !=
"text/docbook" || from !=
"application/x-kword" )
793 return KoFilter::NotImplemented;
797 kdError (30507) <<
"let's get on with it" << endl;
800 DocBookWorker worker;
801 KWEFKWordLeader leader (&worker);
802 leader.convert (m_chain, from, to);
805 kdError (30507) <<
"done here" << endl;
@ NUM_LIST
Numbered as a list item.
@ NUM_CHAPTER
Numbered as a heading.
Base worker of the libexport system.
virtual bool doCloseBody(void)
Like HTML's </BODY>.
virtual bool doOpenBody(void)
Like HTML's <BODY>.