29#include "oowriterimport.h"
32#include <tdeversion.h>
36#include <KoDocumentInfo.h>
37#include <KoDocument.h>
39#include <kgenericfactory.h>
40#include <tdemessagebox.h>
41#include <KoFilterChain.h>
43#include <KoPageLayout.h>
45#include "conversion.h"
49#if ! KDE_IS_VERSION(3,1,90)
50# include <kdebugclasses.h>
53typedef KGenericFactory<OoWriterImport, KoFilter> OoWriterImportFactory;
54K_EXPORT_COMPONENT_FACTORY( liboowriterimport, OoWriterImportFactory(
"kofficefilters" ) )
56OoWriterImport::OoWriterImport( KoFilter *, const
char *, const TQStringList & )
58 m_styleStack( ooNS::style, ooNS::fo ),
59 m_insideOrderedList( false ), m_nextItemIsListItem( false ),
60 m_hasTOC( false ), m_hasHeader( false ), m_hasFooter( false ), m_restartNumbering( -1 ),
61 m_pictureNumber(0), m_zip(NULL)
63 m_styles.setAutoDelete(
true );
64 m_masterPages.setAutoDelete(
true );
65 m_listStyles.setAutoDelete(
true );
68OoWriterImport::~OoWriterImport()
72KoFilter::ConversionStatus OoWriterImport::convert( TQCString
const & from, TQCString
const & to )
74 kdDebug(30518) <<
"Entering Oowriter Import filter: " << from <<
" - " << to << endl;
76 if ( ( from !=
"application/vnd.sun.xml.writer"
77 && from !=
"application/vnd.sun.xml.writer.template"
78 && from !=
"application/vnd.sun.xml.writer.master" )
79 || to !=
"application/x-kword" )
81 kdWarning(30518) <<
"Invalid mimetypes " << from <<
" " << to << endl;
82 return KoFilter::NotImplemented;
85 m_zip=
new KZip(m_chain->inputFile());
87 kdDebug(30518) <<
"Store created" << endl;
89 if ( !m_zip->open(IO_ReadOnly) )
91 kdError(30518) <<
"Couldn't open the requested file "<< m_chain->inputFile() << endl;
92 return KoFilter::FileNotFound;
95 if ( !m_zip->directory() )
97 kdError(30518) <<
"Couldn't read ZIP directory of the requested file "<< m_chain->inputFile() << endl;
98 return KoFilter::FileNotFound;
102 KoFilter::ConversionStatus preStatus = openFile();
105 if ( preStatus == KoFilter::OK )
108 OoUtils::loadThumbnail( thumbnail, m_zip );
111 if ( preStatus != KoFilter::OK )
118 m_currentMasterPage = TQString();
119 TQDomDocument mainDocument;
120 TQDomElement framesetsElem;
121 prepareDocument( mainDocument, framesetsElem );
124 if ( !createStyleMap( m_stylesDoc, mainDocument ) )
125 return KoFilter::UserCancelled;
127 if ( !createStyleMap( m_content, mainDocument ) )
128 return KoFilter::UserCancelled;
131 TQDomElement mainFramesetElement = mainDocument.createElement(
"FRAMESET");
132 mainFramesetElement.setAttribute(
"frameType",1);
133 mainFramesetElement.setAttribute(
"frameInfo",0);
134 mainFramesetElement.setAttribute(
"visible",1);
135 mainFramesetElement.setAttribute(
"name", i18n(
"Main Text Frameset" ) );
136 framesetsElem.appendChild(mainFramesetElement);
138 createInitialFrame( mainFramesetElement, 29, 798, 42, 566,
false, Reconnect );
139 createStyles( mainDocument );
140 createDocumentContent( mainDocument, mainFramesetElement );
141 finishDocumentContent( mainDocument );
146 KoStoreDevice* out = m_chain->storageFile(
"maindoc.xml", KoStore::Write );
148 kdError(30518) <<
"Unable to open output file!" << endl;
149 return KoFilter::StorageCreationError;
153 TQCString cstr = mainDocument.toCString();
154 kdDebug(30518)<<
" maindoc: " << cstr << endl;
156 out->writeBlock( cstr, cstr.length() );
159 TQDomDocument docinfo;
160 createDocumentInfo( docinfo );
163 out = m_chain->storageFile(
"documentinfo.xml", KoStore::Write );
166 TQCString info = docinfo.toCString();
167 kdDebug(30518)<<
" info :"<<info<<endl;
169 out->writeBlock( info , info.length() );
174 if ( ! thumbnail.isNull() )
178 TQImage preview( thumbnail.smoothScale( 256, 256 ).convertDepth(8, TQt::AvoidDither | TQt::DiffuseDither) );
180 if ( !preview.isNull() )
182 out = m_chain->storageFile(
"preview.png", KoStore::Write );
185 preview.save( out,
"PNG" );
190 kdDebug(30518) <<
"######################## OoWriterImport::convert done ####################" << endl;
194void OoWriterImport::createStyles( TQDomDocument& doc )
196 TQDomElement stylesElem = doc.createElement(
"STYLES" );
197 doc.documentElement().appendChild( stylesElem );
199 TQDomNode fixedStyles = KoDom::namedItemNS( m_stylesDoc.documentElement(), ooNS::office,
"styles" );
200 Q_ASSERT( !fixedStyles.isNull() );
202 forEachElement( e, fixedStyles )
204 if ( !e.hasAttributeNS( ooNS::style,
"name" ) )
207 if ( e.attributeNS( ooNS::style,
"family", TQString() ) !=
"paragraph" )
215 TQDomElement styleElem = doc.createElement(
"STYLE");
216 stylesElem.appendChild( styleElem );
218 TQString styleName = kWordStyleName( e.attributeNS( ooNS::style,
"name", TQString() ) );
219 TQDomElement element = doc.createElement(
"NAME");
220 element.setAttribute(
"value", styleName );
221 styleElem.appendChild( element );
224 TQString followingStyle = m_styleStack.attributeNS( ooNS::style,
"next-style-name" );
225 if ( !followingStyle.isEmpty() )
227 TQDomElement element = doc.createElement(
"FOLLOWING" );
228 element.setAttribute(
"name", kWordStyleName( followingStyle ) );
229 styleElem.appendChild( element );
236 bool outline = styleName.startsWith(
"Heading" );
238 styleElem.setAttribute(
"outline",
"true" );
240 writeFormat( doc, styleElem, 1, 0, 0 );
241 writeLayout( doc, styleElem );
245 const int level = styleName.right(1).toInt();
249 listOK = pushListLevelStyle(
"<outline-style>", m_outlineStyle, level );
251 const TQString listStyleName = e.attributeNS( ooNS::style,
"list-style-name", TQString() );
252 listOK = !listStyleName.isEmpty();
254 listOK = pushListLevelStyle( listStyleName, level );
258 const TQDomElement listStyle = m_listStyleStack.currentListStyle();
260 bool ordered = listStyle.localName() ==
"list-level-style-number";
261 writeCounter( doc, styleElem, outline, level, ordered );
262 m_listStyleStack.pop();
265 m_styleStack.clear();
269void OoWriterImport::parseBodyOrSimilar( TQDomDocument &doc,
const TQDomElement& parent, TQDomElement& currentFramesetElement )
271 TQDomElement oldCurrentFrameset = m_currentFrameset;
272 m_currentFrameset = currentFramesetElement;
273 Q_ASSERT( !m_currentFrameset.isNull() );
275 forEachElement( t, parent )
278 const TQString localName = t.localName();
279 const TQString ns = t.namespaceURI();
280 const bool isTextNS = ns == ooNS::text;
283 if ( isTextNS && localName ==
"p" ) {
284 fillStyleStack( t, ooNS::text,
"style-name" );
285 e = parseParagraph( doc, t );
287 else if ( isTextNS && localName ==
"h" )
289 fillStyleStack( t, ooNS::text,
"style-name" );
290 int level = t.attributeNS( ooNS::text,
"level", TQString() ).toInt();
300 if ( !m_nextItemIsListItem )
301 listOK = pushListLevelStyle(
"<outline-style>", m_outlineStyle, level );
302 m_nextItemIsListItem =
true;
303 if ( t.hasAttributeNS( ooNS::text,
"start-value" ) )
305 m_restartNumbering = t.attributeNS( ooNS::text,
"start-value", TQString() ).toInt();
306 e = parseParagraph( doc, t );
308 m_listStyleStack.pop();
310 else if ( isTextNS &&
311 ( localName ==
"unordered-list" || localName ==
"ordered-list" ) )
313 parseList( doc, t, currentFramesetElement );
314 m_styleStack.restore();
317 else if ( isTextNS && localName ==
"section" )
319 kdDebug(30518) <<
"Section found!" << endl;
320 fillStyleStack( t, ooNS::text,
"style-name" );
321 parseBodyOrSimilar( doc, t, currentFramesetElement);
323 else if ( localName ==
"table" && ns == ooNS::table )
325 kdDebug(30518) <<
"Table found!" << endl;
326 parseTable( doc, t, currentFramesetElement );
328 else if ( localName ==
"image" && ns == ooNS::draw )
330 appendPicture( doc, t );
332 else if ( localName ==
"text-box" && ns == ooNS::draw )
334 appendTextBox( doc, t );
336 else if ( isTextNS && localName ==
"variable-decls" )
341 else if ( localName ==
"table-of-content" && ns == ooNS::text )
348 kdWarning(30518) <<
"Unsupported body element '" << localName <<
"'" << endl;
352 currentFramesetElement.appendChild( e );
353 m_styleStack.restore();
355 m_currentFrameset = oldCurrentFrameset;
358void OoWriterImport::createDocumentContent( TQDomDocument &doc, TQDomElement& mainFramesetElement )
360 TQDomElement content = m_content.documentElement();
362 TQDomElement body ( KoDom::namedItemNS( content, ooNS::office,
"body" ) );
365 kdError(30518) <<
"No office:body found!" << endl;
369 parseBodyOrSimilar( doc, body, mainFramesetElement );
372void OoWriterImport::writePageLayout( TQDomDocument& mainDocument,
const TQString& masterPageName )
374 TQDomElement docElement = mainDocument.documentElement();
376 kdDebug(30518) <<
"writePageLayout " << masterPageName << endl;
377 TQDomElement elementPaper = mainDocument.createElement(
"PAPER");
378 KoOrientation orientation;
379 double width, height;
380 KoFormat paperFormat;
381 double marginLeft, marginTop, marginRight, marginBottom;
382 bool hasEvenOddHeader =
false;
383 bool hasEvenOddFooter =
false;
385 TQDomElement* masterPage = m_masterPages[ masterPageName ];
386 Q_ASSERT( masterPage );
387 kdDebug(30518) <<
"page-master-name: " << masterPage->attributeNS( ooNS::style,
"page-master-name", TQString() ) << endl;
388 TQDomElement *style = masterPage ? m_styles[masterPage->attributeNS( ooNS::style,
"page-master-name", TQString() )] : 0;
392 TQDomElement properties( KoDom::namedItemNS( *style, ooNS::style,
"properties" ) );
393 Q_ASSERT( !properties.isNull() );
394 orientation = ( (properties.attributeNS( ooNS::style,
"print-orientation", TQString()) !=
"portrait") ? PG_LANDSCAPE : PG_PORTRAIT );
395 width = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"page-width", TQString()));
396 height = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"page-height", TQString()));
397 kdDebug(30518) <<
"width=" << width <<
" height=" << height << endl;
399 if ( orientation == PG_LANDSCAPE )
400 paperFormat = KoPageFormat::guessFormat( POINT_TO_MM(height), POINT_TO_MM(width) );
402 paperFormat = KoPageFormat::guessFormat( POINT_TO_MM(width), POINT_TO_MM(height) );
404 marginLeft = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"margin-left", TQString()));
405 marginTop = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"margin-top", TQString()));
406 marginRight = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"margin-right", TQString()));
407 marginBottom = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"margin-bottom", TQString()));
409 TQDomElement footnoteSep = KoDom::namedItemNS( properties, ooNS::style,
"footnote-sep" );
410 if ( !footnoteSep.isNull() ) {
414 TQString width = footnoteSep.attributeNS( ooNS::style,
"width", TQString() );
415 elementPaper.setAttribute(
"slFootNoteWidth", KoUnit::parseValue( width ) );
416 TQString pageWidth = footnoteSep.attributeNS( ooNS::style,
"rel-width", TQString() );
417 if ( pageWidth.endsWith(
"%" ) ) {
418 pageWidth.truncate( pageWidth.length() - 1 );
419 elementPaper.setAttribute(
"slFootNoteLenth", pageWidth );
421 elementPaper.setAttribute(
"slFootNotePosition", footnoteSep.attributeNS( ooNS::style,
"adjustment", TQString() ) );
428 TQDomElement headerStyle = KoDom::namedItemNS( *style, ooNS::style,
"header-style" );
429 TQDomElement footerStyle = KoDom::namedItemNS( *style, ooNS::style,
"footer-style" );
430 TQDomElement headerLeftElem = KoDom::namedItemNS( *masterPage, ooNS::style,
"header-left" );
431 if ( !headerLeftElem.isNull() ) {
432 kdDebug(30518) <<
"Found header-left" << endl;
433 hasEvenOddHeader =
true;
434 importHeaderFooter( mainDocument, headerLeftElem, hasEvenOddHeader, headerStyle );
436 TQDomElement headerElem = KoDom::namedItemNS( *masterPage, ooNS::style,
"header" );
437 if ( !headerElem.isNull() ) {
438 kdDebug(30518) <<
"Found header" << endl;
439 importHeaderFooter( mainDocument, headerElem, hasEvenOddHeader, headerStyle );
441 TQDomElement footerLeftElem = KoDom::namedItemNS( *masterPage, ooNS::style,
"footer-left" );
442 if ( !footerLeftElem.isNull() ) {
443 kdDebug(30518) <<
"Found footer-left" << endl;
444 importHeaderFooter( mainDocument, footerLeftElem, hasEvenOddFooter, footerStyle );
446 TQDomElement footerElem = KoDom::namedItemNS( *masterPage, ooNS::style,
"footer" );
447 if ( !footerElem.isNull() ) {
448 kdDebug(30518) <<
"Found footer" << endl;
449 importHeaderFooter( mainDocument, footerElem, hasEvenOddFooter, footerStyle );
455 kdWarning(30518) <<
"NO MASTER PAGE" << endl;
456 orientation=PG_PORTRAIT;
457 paperFormat=PG_DIN_A4;
458 width=MM_TO_POINT(KoPageFormat::width(paperFormat, orientation));
459 height=MM_TO_POINT(KoPageFormat::height(paperFormat, orientation));
461 marginLeft=MM_TO_POINT(10.0);
462 marginRight=MM_TO_POINT(10.0);
463 marginTop=MM_TO_POINT(15.0);
464 marginBottom=MM_TO_POINT(15.0);
467 elementPaper.setAttribute(
"orientation",
int(orientation) );
468 elementPaper.setAttribute(
"width", width);
469 elementPaper.setAttribute(
"height", height);
470 elementPaper.setAttribute(
"format", paperFormat);
471 elementPaper.setAttribute(
"columns",1);
472 elementPaper.setAttribute(
"columnspacing",2);
473 elementPaper.setAttribute(
"hType", hasEvenOddHeader ? 3 : 0);
474 elementPaper.setAttribute(
"fType", hasEvenOddFooter ? 3 : 0);
475 elementPaper.setAttribute(
"spHeadBody",9);
476 elementPaper.setAttribute(
"spFootBody",9);
477 elementPaper.setAttribute(
"zoom",100);
478 docElement.appendChild(elementPaper);
481 TQDomElement element = mainDocument.createElement(
"PAPERBORDERS");
482 element.setAttribute(
"left", marginLeft);
483 element.setAttribute(
"top", marginTop);
484 element.setAttribute(
"right", marginRight);
485 element.setAttribute(
"bottom", marginBottom);
486 elementPaper.appendChild(element);
489void OoWriterImport::prepareDocument( TQDomDocument& mainDocument, TQDomElement& framesetsElem )
491 mainDocument = KoDocument::createDomDocument(
"kword",
"DOC",
"1.2" );
492 TQDomElement docElement = mainDocument.documentElement();
493 docElement.setAttribute(
"editor",
"KWord's OOWriter Import Filter" );
494 docElement.setAttribute(
"mime",
"application/x-kword" );
495 docElement.setAttribute(
"syntaxVersion",
"2" );
497 framesetsElem=mainDocument.createElement(
"FRAMESETS");
498 docElement.appendChild(framesetsElem);
501 TQDomElement varSettings = mainDocument.createElement(
"VARIABLESETTINGS" );
502 docElement.appendChild( varSettings );
503 TQDomNode meta = KoDom::namedItemNS( m_meta, ooNS::office,
"document-meta" );
504 TQDomNode office = KoDom::namedItemNS( meta, ooNS::office,
"meta" );
505 if ( !office.isNull() ) {
506 TQDomElement date = KoDom::namedItemNS( office, ooNS::dc,
"date" );
507 if ( !date.isNull() && !date.text().isEmpty() ) {
509 varSettings.setAttribute(
"modificationDate", date.text() );
511 date = KoDom::namedItemNS( office, ooNS::meta,
"creation-date" );
512 if ( !date.isNull() && !date.text().isEmpty() ) {
513 varSettings.setAttribute(
"creationDate", date.text() );
515 date = KoDom::namedItemNS( office, ooNS::meta,
"print-date" );
516 if ( !date.isNull() && !date.text().isEmpty() ) {
517 varSettings.setAttribute(
"lastPrintingDate", date.text() );
523TQDomElement OoWriterImport::createInitialFrame( TQDomElement& parentFramesetElem,
double left,
double right,
double top,
double bottom,
bool autoExtend, NewFrameBehavior nfb )
525 TQDomElement frameElementOut = parentFramesetElem.ownerDocument().createElement(
"FRAME");
526 frameElementOut.setAttribute(
"left", left );
527 frameElementOut.setAttribute(
"right", right );
528 frameElementOut.setAttribute(
"top", top );
529 frameElementOut.setAttribute(
"bottom", bottom );
530 frameElementOut.setAttribute(
"runaround", 1 );
532 frameElementOut.setAttribute(
"autoCreateNewFrame", autoExtend ? 0 : 1 );
533 frameElementOut.setAttribute(
"newFrameBehavior", nfb );
534 parentFramesetElem.appendChild( frameElementOut );
535 return frameElementOut;
538KoFilter::ConversionStatus OoWriterImport::loadAndParse(
const TQString& filename, TQDomDocument& doc)
540 return OoUtils::loadAndParse( filename, doc, m_zip);
543KoFilter::ConversionStatus OoWriterImport::openFile()
545 KoFilter::ConversionStatus status=loadAndParse(
"content.xml", m_content);
546 if ( status != KoFilter::OK )
548 kdError(30518) <<
"Content.xml could not be parsed correctly! Aborting!" << endl;
562 loadAndParse(
"styles.xml", m_stylesDoc);
563 loadAndParse(
"meta.xml", m_meta);
566 emit sigProgress( 10 );
572void OoWriterImport::createDocumentInfo( TQDomDocument &docinfo )
574 docinfo = KoDocument::createDomDocument(
"document-info" ,
"document-info" ,
"1.1" );
576 OoUtils::createDocumentInfo(m_meta, docinfo);
583bool OoWriterImport::createStyleMap(
const TQDomDocument & styles, TQDomDocument& doc )
585 TQDomElement docElement = styles.documentElement();
586 TQDomNode docStyles = KoDom::namedItemNS( docElement, ooNS::office,
"document-styles" );
588 if ( docElement.hasAttributeNS( ooNS::office,
"version" ) )
591 double d = docElement.attributeNS( ooNS::office,
"version", TQString() ).toDouble( &ok );
595 kdDebug(30518) <<
"OpenWriter version: " << d << endl;
598 TQString message( i18n(
"This document was created with OpenOffice.org version '%1'. This filter was written for version 1.0. Reading this file could cause strange behavior, crashes or incorrect display of the data. Do you want to continue converting the document?") );
599 message = message.arg( docElement.attributeNS( ooNS::office,
"version", TQString() ) );
600 if ( KMessageBox::warningYesNo( 0, message, i18n(
"Unsupported document version" ) ) == KMessageBox::No )
606 TQDomNode fontStyles = KoDom::namedItemNS( docElement, ooNS::office,
"font-decls" );
608 if ( !fontStyles.isNull() )
610 kdDebug(30518) <<
"Starting reading in font-decl..." << endl;
612 insertStyles( fontStyles.toElement(), doc );
615 kdDebug(30518) <<
"No items found" << endl;
617 kdDebug(30518) <<
"Starting reading in office:automatic-styles" << endl;
619 TQDomNode autoStyles = KoDom::namedItemNS( docElement, ooNS::office,
"automatic-styles" );
620 if ( !autoStyles.isNull() )
622 insertStyles( autoStyles.toElement(), doc );
625 kdDebug(30518) <<
"No items found" << endl;
628 kdDebug(30518) <<
"Reading in master styles" << endl;
630 TQDomNode masterStyles = KoDom::namedItemNS( docElement, ooNS::office,
"master-styles" );
632 if ( !masterStyles.isNull() )
636 forEachElement( master, masterStyles )
638 if ( master.localName() ==
"master-page" && master.namespaceURI() == ooNS::style )
640 TQString name = master.attributeNS( ooNS::style,
"name", TQString() );
641 kdDebug(30518) <<
"Master style: '" << name <<
"' loaded " << endl;
642 m_masterPages.insert( name,
new TQDomElement( master ) );
644 kdWarning(30518) <<
"Unknown tag " << master.tagName() <<
" in office:master-styles" << endl;
649 kdDebug(30518) <<
"Starting reading in office:styles" << endl;
651 TQDomNode fixedStyles = KoDom::namedItemNS( docElement, ooNS::office,
"styles" );
653 if ( !fixedStyles.isNull() )
654 insertStyles( fixedStyles.toElement(), doc );
656 kdDebug(30518) <<
"Styles read in." << endl;
662void OoWriterImport::insertStyles(
const TQDomElement& styles, TQDomDocument& doc )
666 forEachElement( e, styles )
668 const TQString localName = e.localName();
669 const TQString ns = e.namespaceURI();
671 const TQString name = e.attributeNS( ooNS::style,
"name", TQString() );
672 if ( ns == ooNS::style && (
674 || localName ==
"page-master"
675 || localName ==
"font-decl" ) )
677 TQDomElement* ep =
new TQDomElement( e );
678 m_styles.insert( name, ep );
679 kdDebug(30518) <<
"Style: '" << name <<
"' loaded " << endl;
680 }
else if ( localName ==
"default-style" && ns == ooNS::style ) {
682 }
else if ( localName ==
"list-style" && ns == ooNS::text ) {
683 TQDomElement* ep =
new TQDomElement( e );
684 m_listStyles.insert( name, ep );
685 kdDebug(30518) <<
"List style: '" << name <<
"' loaded " << endl;
686 }
else if ( localName ==
"outline-style" && ns == ooNS::text ) {
688 }
else if ( localName ==
"footnotes-configuration" && ns == ooNS::text ) {
689 importFootnotesConfiguration( doc, e,
false );
690 }
else if ( localName ==
"endnotes-configuration" && ns == ooNS::text ) {
691 importFootnotesConfiguration( doc, e,
true );
692 }
else if ( localName ==
"linenumbering-configuration" && ns == ooNS::text ) {
694 }
else if ( localName ==
"number-style" && ns == ooNS::number ) {
696 }
else if ( ( localName ==
"date-style"
697 || localName ==
"time-style" ) && ns == ooNS::number ) {
698 importDateTimeStyle( e );
700 kdWarning(30518) <<
"Unknown element " << localName <<
" in styles" << endl;
709void OoWriterImport::importDateTimeStyle(
const TQDomElement& parent )
713 forEachElement( e, parent )
715 const TQString ns = e.namespaceURI();
716 if ( ns != ooNS::number )
718 const TQString localName = e.localName();
719 const TQString numberStyle = e.attributeNS( ooNS::number,
"style", TQString() );
720 const bool shortForm = numberStyle ==
"short" || numberStyle.isEmpty();
721 if ( localName ==
"day" ) {
722 format += shortForm ?
"d" :
"dd";
723 }
else if ( localName ==
"day-of-week" ) {
724 format += shortForm ?
"ddd" :
"dddd";
725 }
else if ( localName ==
"month" ) {
727 if ( e.attributeNS( ooNS::number,
"textual", TQString() ) ==
"true" ) {
728 format += shortForm ?
"MMM" :
"MMMM";
730 format += shortForm ?
"M" :
"MM";
732 }
else if ( localName ==
"year" ) {
733 format += shortForm ?
"yy" :
"yyyy";
734 }
else if ( localName ==
"week-of-year" || localName ==
"quarter") {
736 }
else if ( localName ==
"hours" ) {
737 format += shortForm ?
"h" :
"hh";
738 }
else if ( localName ==
"minutes" ) {
739 format += shortForm ?
"m" :
"mm";
740 }
else if ( localName ==
"seconds" ) {
741 format += shortForm ?
"s" :
"ss";
742 }
else if ( localName ==
"am-pm" ) {
744 }
else if ( localName ==
"text" ) {
757 forEachElement( e, parent )
759 const TQString ns = e.namespaceURI();
760 if ( ns != ooNS::number )
762 TQString localName = e.tagName();
763 const TQString numberStyle = e.attributeNS( ooNS::number,
"style", TQString() );
764 const bool shortForm = numberStyle ==
"short" || numberStyle.isEmpty();
765 if ( localName ==
"day" ) {
766 kdeFormat += shortForm ?
"%e" :
"%d";
767 }
else if ( localName ==
"day-of-week" ) {
768 kdeFormat += shortForm ?
"%a" :
"%A";
769 }
else if ( localName ==
"month" ) {
771 if ( e.attributeNS( ooNS::number,
"textual", TQString() ) ==
"true" ) {
772 kdeFormat += shortForm ?
"%b" :
"%B";
774 kdeFormat += shortForm ?
"%n" :
"%m";
776 }
else if ( localName ==
"year" ) {
777 kdeFormat += shortForm ?
"%y" :
"%Y";
778 }
else if ( localName ==
"week-of-year" || localName ==
"quarter") {
780 }
else if ( localName ==
"hours" ) {
781 kdeFormat += shortForm ?
"%k" :
"%H";
782 }
else if ( localName ==
"minutes" ) {
783 kdeFormat += shortForm ?
"%M" :
"%M";
784 }
else if ( localName ==
"seconds" ) {
785 kdeFormat += shortForm ?
"%S" :
"%S";
786 }
else if ( localName ==
"am-pm" ) {
788 }
else if ( localName ==
"text" ) {
789 kdeFormat += e.text();
794 TQString styleName = parent.attributeNS( ooNS::style,
"name", TQString() );
795 kdDebug(30518) <<
"datetime style: " << styleName <<
" tqt format=" << format << endl;
796 m_dateTimeFormats.insert( styleName, format );
799void OoWriterImport::fillStyleStack(
const TQDomElement&
object,
const char* nsURI,
const TQString& attrName )
803 if (
object.hasAttributeNS( nsURI, attrName ) ) {
804 const TQString styleName =
object.attributeNS( nsURI, attrName, TQString() );
805 const TQDomElement* style = m_styles[styleName];
809 kdWarning(30518) <<
"fillStyleStack: no style named " << styleName <<
" found." << endl;
813void OoWriterImport::addStyles(
const TQDomElement* style )
816 if ( !style )
return;
818 if ( style->hasAttributeNS( ooNS::style,
"parent-style-name" ) ) {
819 const TQString parentStyleName = style->attributeNS( ooNS::style,
"parent-style-name", TQString() );
820 TQDomElement* parentStyle = m_styles[ parentStyleName ];
822 addStyles( parentStyle );
824 kdWarning(30518) <<
"Parent style not found: " << parentStyleName << endl;
826 else if ( !m_defaultStyle.isNull() )
827 m_styleStack.push( m_defaultStyle );
830 m_styleStack.push( *style );
833void OoWriterImport::applyListStyle( TQDomDocument& doc, TQDomElement& layoutElement,
const TQDomElement& paragraph )
836 if ( m_listStyleStack.hasListStyle() && m_nextItemIsListItem ) {
837 bool heading = paragraph.localName() ==
"h";
838 m_nextItemIsListItem =
false;
839 int level = heading ? paragraph.attributeNS( ooNS::text,
"level", TQString() ).toInt() : m_listStyleStack.level();
840 writeCounter( doc, layoutElement, heading, level, m_insideOrderedList );
844void OoWriterImport::writeCounter( TQDomDocument& doc, TQDomElement& layoutElement,
bool heading,
int level,
bool ordered )
846 const TQDomElement listStyle = m_listStyleStack.currentListStyle();
848 TQDomElement counter = doc.createElement(
"COUNTER" );
849 counter.setAttribute(
"numberingtype", heading ? 1 : 0 );
850 counter.setAttribute(
"depth", level - 1 );
855 if ( ordered || heading ) {
856 counter.setAttribute(
"type", Conversion::importCounterType( listStyle.attributeNS( ooNS::style,
"num-format", TQString() ) ) );
857 counter.setAttribute(
"lefttext", listStyle.attributeNS( ooNS::style,
"num-prefix", TQString() ) );
858 counter.setAttribute(
"righttext", listStyle.attributeNS( ooNS::style,
"num-suffix", TQString() ) );
859 TQString dl = listStyle.attributeNS( ooNS::text,
"display-levels", TQString() );
862 counter.setAttribute(
"display-levels", dl );
863 if ( m_restartNumbering != -1 ) {
864 counter.setAttribute(
"start", m_restartNumbering );
865 counter.setAttribute(
"restart",
"true" );
868 counter.setAttribute(
"start", listStyle.attributeNS( ooNS::text,
"start-value", TQString() ) );
872 counter.setAttribute(
"type", 6 );
873 TQString bulletChar = listStyle.attributeNS( ooNS::text,
"bullet-char", TQString() );
874 if ( !bulletChar.isEmpty() ) {
876 counter.setAttribute(
"bullet", bulletChar[0].unicode() );
877 kdDebug(30518) <<
"bullet code " << bulletChar[0].unicode() << endl;
878 TQString fontName = listStyleProperties.attributeNS( ooNS::style,
"font-name", TQString() );
879 counter.setAttribute(
"bulletfont", fontName );
882 switch( bulletChar[0].unicode() ) {
884 counter.setAttribute(
"type", 10 );
887 counter.setAttribute(
"type", 10 );
890 counter.setAttribute(
"type", 10 );
893 counter.setAttribute(
"type", 9 );
897 counter.setAttribute(
"bullet", 206 );
898 counter.setAttribute(
"bulletfont",
"symbol" );
901 counter.setAttribute(
"bullet", 212 );
902 counter.setAttribute(
"bulletfont",
"symbol" );
905 counter.setAttribute(
"bullet", 246 );
906 counter.setAttribute(
"bulletfont",
"symbol" );
909 counter.setAttribute(
"type", 8 );
913 counter.setAttribute(
"type", 10 );
917 layoutElement.appendChild(counter);
920static TQDomElement findListLevelStyle( TQDomElement& fullListStyle,
int level )
922 TQDomElement listLevelItem;
923 forEachElement( listLevelItem, fullListStyle )
925 if ( listLevelItem.attributeNS( ooNS::text,
"level", TQString() ).toInt() == level )
926 return listLevelItem;
928 return TQDomElement();
931bool OoWriterImport::pushListLevelStyle(
const TQString& listStyleName,
int level )
933 TQDomElement* fullListStyle = m_listStyles[listStyleName];
934 if ( !fullListStyle ) {
935 kdWarning(30518) <<
"List style " << listStyleName <<
" not found!" << endl;
939 return pushListLevelStyle( listStyleName, *fullListStyle, level );
942bool OoWriterImport::pushListLevelStyle(
const TQString& listStyleName,
943 TQDomElement& fullListStyle,
int level )
947 TQDomElement listLevelStyle;
948 while ( i > 0 && listLevelStyle.isNull() ) {
949 listLevelStyle = findListLevelStyle( fullListStyle, i );
952 if ( listLevelStyle.isNull() ) {
953 kdWarning(30518) <<
"List level style for level " << level <<
" in list style " << listStyleName <<
" not found!" << endl;
956 kdDebug(30518) <<
"Pushing list-level-style from list-style " << listStyleName <<
" level " << level << endl;
957 m_listStyleStack.push( listLevelStyle );
961void OoWriterImport::parseList( TQDomDocument& doc,
const TQDomElement& list, TQDomElement& currentFramesetElement )
965 m_insideOrderedList = ( list.localName() ==
"ordered-list" );
966 TQString oldListStyleName = m_currentListStyleName;
967 if ( list.hasAttributeNS( ooNS::text,
"style-name" ) )
968 m_currentListStyleName = list.attributeNS( ooNS::text,
"style-name", TQString() );
969 bool listOK = !m_currentListStyleName.isEmpty();
970 const int level = m_listStyleStack.level() + 1;
973 listOK = pushListLevelStyle( m_currentListStyleName, level );
976 TQDomElement listItem;
977 forEachElement( listItem, list )
980 m_nextItemIsListItem = ( listItem.localName() !=
"list-header" );
981 m_restartNumbering = -1;
982 if ( listItem.hasAttributeNS( ooNS::text,
"start-value" ) )
983 m_restartNumbering = listItem.attributeNS( ooNS::text,
"start-value", TQString() ).toInt();
985 parseBodyOrSimilar( doc, listItem, currentFramesetElement );
986 m_restartNumbering = -1;
989 m_listStyleStack.pop();
990 m_currentListStyleName = oldListStyleName;
993static int numberOfParagraphs(
const TQDomElement& frameset )
995 const TQDomNodeList children = frameset.childNodes();
996 const TQString paragStr =
"PARAGRAPH";
998 for (
unsigned int i = 0 ; i < children.length() ; ++i ) {
999 if ( children.item( i ).toElement().tagName() == paragStr )
1005void OoWriterImport::parseSpanOrSimilar( TQDomDocument& doc,
const TQDomElement& parent,
1006 TQDomElement& outputParagraph, TQDomElement& outputFormats, TQString& paragraphText, uint& pos)
1010 for( TQDomNode node ( parent.firstChild() ); !node.isNull(); node = node.nextSibling() )
1012 TQDomElement ts ( node.toElement() );
1014 const TQString localName( ts.localName() );
1015 const TQString ns = ts.namespaceURI();
1016 const bool isTextNS = ns == ooNS::text;
1017 TQDomText t ( node.toText() );
1019 bool shouldWriteFormat=
false;
1022 if ( isTextNS && localName ==
"span" )
1024 m_styleStack.save();
1025 fillStyleStack( ts, ooNS::text,
"style-name" );
1026 parseSpanOrSimilar( doc, ts, outputParagraph, outputFormats, paragraphText, pos);
1027 m_styleStack.restore();
1029 else if ( isTextNS && localName ==
"s" )
1031 textData = OoUtils::expandWhitespace(ts);
1032 shouldWriteFormat=
true;
1034 else if ( isTextNS && localName ==
"tab-stop" )
1040 shouldWriteFormat=
true;
1042 else if ( isTextNS && localName ==
"line-break" )
1045 shouldWriteFormat=
true;
1047 else if ( isTextNS &&
1048 ( localName ==
"footnote" || localName ==
"endnote" ) )
1051 importFootnote( doc, ts, outputFormats, pos, localName );
1053 else if ( localName ==
"image" && ns == ooNS::draw )
1056 TQString frameName = appendPicture(doc, ts);
1057 anchorFrameset( doc, outputFormats, pos, frameName );
1059 else if ( localName ==
"text-box" && ns == ooNS::draw )
1062 TQString frameName = appendTextBox(doc, ts);
1063 anchorFrameset( doc, outputFormats, pos, frameName );
1065 else if ( isTextNS && localName ==
"a" )
1067 m_styleStack.save();
1068 TQString href( ts.attributeNS( ooNS::xlink,
"href", TQString()) );
1069 if ( href.startsWith(
"#") )
1073 parseSpanOrSimilar( doc, ts, outputParagraph, outputFormats, paragraphText, pos);
1079 TQDomElement fakeParagraph, fakeFormats;
1082 parseSpanOrSimilar( doc, ts, fakeParagraph, fakeFormats, text, fakePos);
1084 TQDomElement linkElement (doc.createElement(
"LINK"));
1085 linkElement.setAttribute(
"hrefName",ts.attributeNS( ooNS::xlink,
"href", TQString()));
1086 linkElement.setAttribute(
"linkName",text);
1087 appendKWordVariable(doc, outputFormats, ts, pos,
"STRING", 9, linkElement);
1089 m_styleStack.restore();
1091 else if ( isTextNS &&
1092 (localName ==
"date"
1093 || localName ==
"print-time"
1094 || localName ==
"print-date"
1095 || localName ==
"creation-time"
1096 || localName ==
"creation-date"
1097 || localName ==
"modification-time"
1098 || localName ==
"modification-date"
1099 || localName ==
"time"
1100 || localName ==
"page-number"
1101 || localName ==
"chapter"
1102 || localName ==
"file-name"
1103 || localName ==
"author-name"
1104 || localName ==
"author-initials"
1105 || localName ==
"subject"
1106 || localName ==
"title"
1107 || localName ==
"description"
1108 || localName ==
"variable-set"
1109 || localName ==
"page-variable-get"
1110 || localName ==
"user-defined"
1111 || localName.startsWith(
"sender-")
1116 appendField(doc, outputFormats, ts, pos);
1118 else if ( isTextNS && localName ==
"bookmark" )
1122 Q_ASSERT( !m_currentFrameset.isNull() );
1123 appendBookmark( doc, numberOfParagraphs( m_currentFrameset ),
1124 pos, ts.attributeNS( ooNS::text,
"name", TQString() ) );
1126 else if ( isTextNS && localName ==
"bookmark-start" ) {
1127 m_bookmarkStarts.insert( ts.attributeNS( ooNS::text,
"name", TQString() ),
1128 BookmarkStart( m_currentFrameset.attribute(
"name" ),
1129 numberOfParagraphs( m_currentFrameset ),
1132 else if ( isTextNS && localName ==
"bookmark-end" ) {
1133 TQString bkName = ts.attributeNS( ooNS::text,
"name", TQString() );
1134 BookmarkStartsMap::iterator it = m_bookmarkStarts.find( bkName );
1135 if ( it == m_bookmarkStarts.end() ) {
1137 appendBookmark( doc, numberOfParagraphs( m_currentFrameset ),
1138 pos, ts.attributeNS( ooNS::text,
"name", TQString() ) );
1140 if ( (*it).frameSetName != m_currentFrameset.attribute(
"name" ) ) {
1142 kdWarning(30518) <<
"Cross-frameset bookmark! Not supported." << endl;
1144 appendBookmark( doc, (*it).paragId, (*it).pos,
1145 numberOfParagraphs( m_currentFrameset ), pos, it.key() );
1147 m_bookmarkStarts.remove( it );
1150 else if ( t.isNull() )
1152 kdWarning(30518) <<
"Ignoring tag " << ts.tagName() << endl;
1157 textData = t.data();
1158 shouldWriteFormat=
true;
1161 paragraphText += textData;
1162 const uint length = textData.length();
1164 if (shouldWriteFormat)
1166 writeFormat( doc, outputFormats, 1 , pos, length );
1173TQDomElement OoWriterImport::parseParagraph( TQDomDocument& doc,
const TQDomElement& paragraph )
1175 TQDomElement p = doc.createElement(
"PARAGRAPH" );
1177 TQDomElement formats = doc.createElement(
"FORMATS" );
1179 TQString paragraphText;
1183 parseSpanOrSimilar( doc, paragraph, p, formats, paragraphText, pos);
1185 TQDomElement text = doc.createElement(
"TEXT" );
1186 text.appendChild( doc.createTextNode( paragraphText ) );
1187 text.setAttribute(
"xml:space",
"preserve" );
1188 p.appendChild( text );
1191 p.appendChild( formats );
1192 TQDomElement layoutElement = doc.createElement(
"LAYOUT" );
1193 p.appendChild( layoutElement );
1196 TQString styleName = m_styleStack.userStyleName(
"paragraph");
1197 if ( !styleName.isEmpty() )
1199 TQDomElement nameElement = doc.createElement(
"NAME");
1200 nameElement.setAttribute(
"value", kWordStyleName(styleName) );
1201 layoutElement.appendChild(nameElement);
1204 writeLayout( doc, layoutElement );
1205 writeFormat( doc, layoutElement, 1, 0, 0 );
1207 applyListStyle( doc, layoutElement, paragraph );
1209 TQDomElement* paragraphStyle = m_styles[paragraph.attributeNS( ooNS::text,
"style-name", TQString() )];
1210 TQString masterPageName = paragraphStyle ? paragraphStyle->attributeNS( ooNS::style,
"master-page-name", TQString() ) : TQString();
1211 if ( masterPageName.isEmpty() )
1212 masterPageName =
"Standard";
1213 if ( masterPageName != m_currentMasterPage )
1218 if ( m_currentMasterPage.isEmpty() ) {
1219 m_currentMasterPage = masterPageName;
1220 writePageLayout( doc, masterPageName );
1224 m_currentMasterPage = masterPageName;
1225 TQDomElement pageBreakElem = layoutElement.namedItem(
"PAGEBREAKING" ).toElement();
1226 if ( !pageBreakElem.isNull() ) {
1227 pageBreakElem = doc.createElement(
"PAGEBREAKING" );
1228 layoutElement.appendChild( pageBreakElem );
1230 pageBreakElem.setAttribute(
"hardFrameBreak",
"true" );
1238void OoWriterImport::writeFormat( TQDomDocument& doc, TQDomElement& formats,
int id,
int pos,
int length )
1241 TQDomElement format( doc.createElement(
"FORMAT" ) );
1242 format.setAttribute(
"id",
id );
1243 format.setAttribute(
"pos", pos );
1244 format.setAttribute(
"len", length );
1256 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"color" ) ) {
1257 TQColor color( m_styleStack.attributeNS( ooNS::fo,
"color" ) );
1258 TQDomElement colorElem( doc.createElement(
"COLOR" ) );
1259 colorElem.setAttribute(
"red", color.red() );
1260 colorElem.setAttribute(
"blue", color.blue() );
1261 colorElem.setAttribute(
"green", color.green() );
1262 format.appendChild( colorElem );
1264 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-family" )
1265 || m_styleStack.hasAttributeNS( ooNS::style,
"font-name") )
1268 TQString fontName = m_styleStack.attributeNS( ooNS::fo,
"font-family" ).remove(
"'" );
1269 if (fontName.isEmpty())
1273 fontName = m_styleStack.attributeNS( ooNS::style,
"font-name" ).remove(
"'" );
1277 if ( fontName ==
"Thorndale" )
1278 fontName =
"Times New Roman";
1280 fontName.remove(TQRegExp(
"\\sCE$"));
1282 TQDomElement fontElem( doc.createElement(
"FONT" ) );
1283 fontElem.setAttribute(
"name", fontName );
1284 format.appendChild( fontElem );
1286 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-size" ) ) {
1287 double pointSize = m_styleStack.fontSize();
1289 TQDomElement fontSize( doc.createElement(
"SIZE" ) );
1290 fontSize.setAttribute(
"value", tqRound(pointSize) );
1291 format.appendChild( fontSize );
1293 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-weight" ) ) {
1294 TQDomElement weightElem( doc.createElement(
"WEIGHT" ) );
1295 TQString fontWeight = m_styleStack.attributeNS( ooNS::fo,
"font-weight" );
1296 int boldness = fontWeight.toInt();
1297 if ( fontWeight ==
"bold" )
1299 else if ( boldness == 0 )
1301 weightElem.setAttribute(
"value", boldness );
1302 format.appendChild( weightElem );
1305 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-style" ) )
1306 if ( m_styleStack.attributeNS( ooNS::fo,
"font-style" ) ==
"italic" ||
1307 m_styleStack.attributeNS( ooNS::fo,
"font-style" ) ==
"oblique" )
1309 TQDomElement italic = doc.createElement(
"ITALIC" );
1310 italic.setAttribute(
"value", 1 );
1311 format.appendChild( italic );
1314 bool wordByWord = (m_styleStack.hasAttributeNS( ooNS::fo,
"score-spaces"))
1315 && (m_styleStack.attributeNS( ooNS::fo,
"score-spaces") ==
"false");
1316 if( m_styleStack.hasAttributeNS( ooNS::style,
"text-crossing-out" ))
1318 TQString strikeOutType = m_styleStack.attributeNS( ooNS::style,
"text-crossing-out" );
1319 TQDomElement strikeOut = doc.createElement(
"STRIKEOUT" );
1320 if( strikeOutType ==
"double-line")
1322 strikeOut.setAttribute(
"value",
"double");
1323 strikeOut.setAttribute(
"styleline",
"solid");
1325 else if( strikeOutType ==
"single-line")
1327 strikeOut.setAttribute(
"value",
"single");
1328 strikeOut.setAttribute(
"styleline",
"solid");
1330 else if( strikeOutType ==
"thick-line")
1332 strikeOut.setAttribute(
"value",
"single-bold");
1333 strikeOut.setAttribute(
"styleline",
"solid");
1336 strikeOut.setAttribute(
"wordbyword", 1);
1339 format.appendChild( strikeOut );
1341 if( m_styleStack.hasAttributeNS( ooNS::style,
"text-position"))
1343 TQDomElement vertAlign = doc.createElement(
"VERTALIGN" );
1344 TQString text_position = m_styleStack.attributeNS( ooNS::style,
"text-position");
1346 TQString relativetextsize;
1347 OoUtils::importTextPosition( text_position, value, relativetextsize );
1348 vertAlign.setAttribute(
"value", value );
1349 if ( !relativetextsize.isEmpty() )
1350 vertAlign.setAttribute(
"relativetextsize", relativetextsize );
1351 format.appendChild( vertAlign );
1353 if ( m_styleStack.hasAttributeNS( ooNS::style,
"text-underline" ) )
1357 OoUtils::importUnderline( m_styleStack.attributeNS( ooNS::style,
"text-underline" ),
1358 underline, styleline );
1359 TQDomElement underLineElem = doc.createElement(
"UNDERLINE" );
1360 underLineElem.setAttribute(
"value", underline );
1361 underLineElem.setAttribute(
"styleline", styleline );
1363 TQString underLineColor = m_styleStack.attributeNS( ooNS::style,
"text-underline-color" );
1364 if ( !underLineColor.isEmpty() && underLineColor !=
"font-color" )
1365 underLineElem.setAttribute(
"underlinecolor", underLineColor);
1367 underLineElem.setAttribute(
"wordbyword", 1);
1368 format.appendChild( underLineElem );
1371 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-variant" )
1372 || m_styleStack.hasAttributeNS( ooNS::fo,
"text-transform" ) )
1374 TQDomElement fontAttrib( doc.createElement(
"FONTATTRIBUTE" ) );
1375 bool smallCaps = m_styleStack.attributeNS( ooNS::fo,
"font-variant" ) ==
"small-caps";
1378 fontAttrib.setAttribute(
"value",
"smallcaps" );
1383 fontAttrib.setAttribute(
"value", m_styleStack.attributeNS( ooNS::fo,
"text-transform" ) );
1385 format.appendChild( fontAttrib );
1388 if (m_styleStack.hasAttributeNS( ooNS::fo,
"language"))
1390 TQDomElement lang = doc.createElement(
"LANGUAGE");
1391 TQString tmp = m_styleStack.attributeNS( ooNS::fo,
"language");
1393 lang.setAttribute(
"value",
"en_US");
1395 lang.setAttribute(
"value", tmp);
1396 format.appendChild(lang);
1399 if (m_styleStack.hasAttributeNS( ooNS::style,
"text-background-color"))
1401 TQDomElement bgCol = doc.createElement(
"TEXTBACKGROUNDCOLOR");
1402 TQColor tmp = m_styleStack.attributeNS( ooNS::style,
"text-background-color");
1403 if (tmp !=
"transparent")
1405 bgCol.setAttribute(
"red", tmp.red());
1406 bgCol.setAttribute(
"green", tmp.green());
1407 bgCol.setAttribute(
"blue", tmp.blue());
1408 format.appendChild(bgCol);
1412 if (m_styleStack.hasAttributeNS( ooNS::fo,
"text-shadow"))
1414 TQDomElement shadow = doc.createElement(
"SHADOW");
1415 TQString css = m_styleStack.attributeNS( ooNS::fo,
"text-shadow");
1417 TQStringList tokens = TQStringList::split(
' ', css);
1418 if ( !tokens.isEmpty() ) {
1419 TQColor col( tokens.first() );
1420 if ( !col.isValid() && tokens.count() > 1 ) {
1421 col.setNamedColor( tokens.last() );
1423 if ( !col.isValid() )
1426 shadow.setAttribute(
"text-shadow", css);
1427 format.appendChild(shadow);
1453 if ( format.hasChildNodes() || !length )
1454 formats.appendChild( format );
1457void OoWriterImport::writeLayout( TQDomDocument& doc, TQDomElement& layoutElement )
1459 Q_ASSERT( layoutElement.ownerDocument() == doc );
1462 TQDomElement flowElement = doc.createElement(
"FLOW");
1470 if ( m_styleStack.attributeNS( ooNS::style,
"text-auto-align" ) ==
"true" )
1471 flowElement.setAttribute(
"align",
"auto" );
1474 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"text-align" ) )
1475 flowElement.setAttribute(
"align", Conversion::importAlignment( m_styleStack.attributeNS( ooNS::fo,
"text-align" ) ) );
1477 flowElement.setAttribute(
"align",
"auto" );
1479 layoutElement.appendChild( flowElement );
1481 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"writing-mode" ) )
1484 TQString writingMode = m_styleStack.attributeNS( ooNS::fo,
"writing-mode" );
1485 flowElement.setAttribute(
"dir", writingMode==
"rl-tb" || writingMode==
"rl" ?
"R" :
"L" );
1489 OoUtils::importIndents( layoutElement, m_styleStack );
1492 OoUtils::importTopBottomMargin( layoutElement, m_styleStack );
1495 OoUtils::importLineSpacing( layoutElement, m_styleStack );
1498 OoUtils::importTabulators( layoutElement, m_styleStack );
1501 OoUtils::importBorders( layoutElement, m_styleStack );
1504 if( m_styleStack.hasAttributeNS( ooNS::fo,
"break-before") ||
1505 m_styleStack.hasAttributeNS( ooNS::fo,
"break-after") ||
1506 m_styleStack.hasAttributeNS( ooNS::style,
"break-inside") ||
1507 m_styleStack.hasAttributeNS( ooNS::style,
"keep-with-next") ||
1508 m_styleStack.hasAttributeNS( ooNS::fo,
"keep-with-next") )
1510 TQDomElement pageBreak = doc.createElement(
"PAGEBREAKING" );
1511 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"break-before") ) {
1512 bool breakBefore = m_styleStack.attributeNS( ooNS::fo,
"break-before" ) !=
"auto";
1514 pageBreak.setAttribute(
"hardFrameBreak", breakBefore ?
"true" :
"false");
1516 else if ( m_styleStack.hasAttributeNS( ooNS::fo,
"break-after") ) {
1517 bool breakAfter = m_styleStack.attributeNS( ooNS::fo,
"break-after" ) !=
"auto";
1519 pageBreak.setAttribute(
"hardFrameBreakAfter", breakAfter ?
"true" :
"false");
1522 if ( m_styleStack.hasAttributeNS( ooNS::style,
"break-inside" ) ) {
1523 bool breakInside = m_styleStack.attributeNS( ooNS::style,
"break-inside" ) ==
"true";
1524 pageBreak.setAttribute(
"linesTogether", breakInside ?
"false" :
"true");
1526 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"keep-with-next" ) ) {
1528 TQString val = m_styleStack.attributeNS( ooNS::fo,
"keep-with-next" );
1529 pageBreak.setAttribute(
"keepWithNext", ( val ==
"true" || val ==
"always" ) ?
"true" :
"false");
1531 layoutElement.appendChild( pageBreak );
1574void OoWriterImport::importFrame( TQDomElement& frameElementOut,
const TQDomElement&
object,
bool isText )
1577 if (
object.hasAttributeNS( ooNS::svg,
"width" ) ) {
1579 width = KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"width", TQString() ) );
1580 }
else if (
object.hasAttributeNS( ooNS::fo,
"min-width" ) ) {
1582 width = KoUnit::parseValue(
object.attributeNS( ooNS::fo,
"min-width", TQString() ) );
1584 kdWarning(30518) <<
"Error in text-box: neither width nor min-width specified!" << endl;
1586 double height = 100;
1587 bool hasMinHeight =
false;
1588 if (
object.hasAttributeNS( ooNS::svg,
"height" ) ) {
1590 height = KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"height", TQString() ) );
1591 }
else if (
object.hasAttributeNS( ooNS::fo,
"min-height" ) ) {
1592 height = KoUnit::parseValue(
object.attributeNS( ooNS::fo,
"min-height", TQString() ) );
1593 hasMinHeight =
true;
1595 kdWarning(30518) <<
"Error in text-box: neither height nor min-height specified!" << endl;
1610 KoRect frameRect( KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"x", TQString() ) ),
1611 KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"y", TQString() ) ),
1614 frameElementOut.setAttribute(
"left", frameRect.left() );
1615 frameElementOut.setAttribute(
"right", frameRect.right() );
1616 frameElementOut.setAttribute(
"top", frameRect.top() );
1617 frameElementOut.setAttribute(
"bottom", frameRect.bottom() );
1619 frameElementOut.setAttribute(
"min-height", height );
1620 frameElementOut.setAttribute(
"z-index",
object.attributeNS( ooNS::draw,
"z-index", TQString() ) );
1621 TQPair<int, TQString> attribs = Conversion::importWrapping( m_styleStack.attributeNS( ooNS::style,
"wrap" ) );
1622 frameElementOut.setAttribute(
"runaround", attribs.first );
1623 if ( !attribs.second.isEmpty() )
1624 frameElementOut.setAttribute(
"runaroundSide", attribs.second );
1630 int overflowBehavior;
1631 if ( m_styleStack.hasAttributeNS( ooNS::style,
"overflow-behavior" ) ) {
1632 overflowBehavior = Conversion::importOverflowBehavior( m_styleStack.attributeNS( ooNS::style,
"overflow-behavior" ) );
1635 overflowBehavior = hasMinHeight ? 0 : 2 ;
1638 frameElementOut.setAttribute(
"autoCreateNewFrame", overflowBehavior);
1643 importCommonFrameProperties( frameElementOut );
1646void OoWriterImport::importCommonFrameProperties( TQDomElement& frameElementOut )
1649 double paddingLeft = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding",
"left" ) );
1650 double paddingRight = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding",
"right" ) );
1651 double paddingTop = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding",
"top" ) );
1652 double paddingBottom = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding",
"bottom" ) );
1654 if ( paddingLeft != 0 )
1655 frameElementOut.setAttribute(
"bleftpt", paddingLeft );
1656 if ( paddingRight != 0 )
1657 frameElementOut.setAttribute(
"brightpt", paddingRight );
1658 if ( paddingTop != 0 )
1659 frameElementOut.setAttribute(
"btoppt", paddingTop );
1660 if ( paddingBottom != 0 )
1661 frameElementOut.setAttribute(
"bbottompt", paddingBottom );
1664 bool transparent =
false;
1666 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"background-color" ) ) {
1667 TQString color = m_styleStack.attributeNS( ooNS::fo,
"background-color" );
1668 if ( color ==
"transparent" )
1671 bgColor.setNamedColor( color );
1674 frameElementOut.setAttribute(
"bkStyle", 0 );
1675 else if ( bgColor.isValid() ) {
1678 frameElementOut.setAttribute(
"bkStyle", 1 );
1679 frameElementOut.setAttribute(
"bkRed", bgColor.red() );
1680 frameElementOut.setAttribute(
"bkBlue", bgColor.blue() );
1681 frameElementOut.setAttribute(
"bkGreen", bgColor.green() );
1691 if (OoUtils::parseBorder(m_styleStack.attributeNS( ooNS::fo,
"border",
"left"), &width, &style, &color)) {
1692 frameElementOut.setAttribute(
"lWidth", width );
1693 if ( color.isValid() ) {
1694 frameElementOut.setAttribute(
"lRed", color.red() );
1695 frameElementOut.setAttribute(
"lBlue", color.blue() );
1696 frameElementOut.setAttribute(
"lGreen", color.green() );
1698 frameElementOut.setAttribute(
"lStyle", style );
1700 if (OoUtils::parseBorder(m_styleStack.attributeNS( ooNS::fo,
"border",
"right"), &width, &style, &color)) {
1701 frameElementOut.setAttribute(
"rWidth", width );
1702 if ( color.isValid() ) {
1703 frameElementOut.setAttribute(
"rRed", color.red() );
1704 frameElementOut.setAttribute(
"rBlue", color.blue() );
1705 frameElementOut.setAttribute(
"rGreen", color.green() );
1707 frameElementOut.setAttribute(
"rStyle", style );
1709 if (OoUtils::parseBorder(m_styleStack.attributeNS( ooNS::fo,
"border",
"top"), &width, &style, &color)) {
1710 frameElementOut.setAttribute(
"tWidth", width );
1711 if ( color.isValid() ) {
1712 frameElementOut.setAttribute(
"tRed", color.red() );
1713 frameElementOut.setAttribute(
"tBlue", color.blue() );
1714 frameElementOut.setAttribute(
"tGreen", color.green() );
1716 frameElementOut.setAttribute(
"tStyle", style );
1718 if (OoUtils::parseBorder(m_styleStack.attributeNS( ooNS::fo,
"border",
"bottom"), &width, &style, &color)) {
1719 frameElementOut.setAttribute(
"bWidth", width );
1720 if ( color.isValid() ) {
1721 frameElementOut.setAttribute(
"bRed", color.red() );
1722 frameElementOut.setAttribute(
"bBlue", color.blue() );
1723 frameElementOut.setAttribute(
"bGreen", color.green() );
1725 frameElementOut.setAttribute(
"bStyle", style );
1731TQString OoWriterImport::appendTextBox(TQDomDocument& doc,
const TQDomElement&
object)
1733 const TQString frameName (
object.attributeNS( ooNS::draw,
"name", TQString()) );
1734 kdDebug(30518) <<
"appendTextBox " << frameName << endl;
1735 m_styleStack.save();
1736 fillStyleStack(
object, ooNS::draw,
"style-name" );
1739 TQDomElement framesetElement(doc.createElement(
"FRAMESET"));
1740 framesetElement.setAttribute(
"frameType",1);
1741 framesetElement.setAttribute(
"frameInfo",0);
1742 framesetElement.setAttribute(
"visible",1);
1743 framesetElement.setAttribute(
"name",frameName);
1744 TQDomElement framesetsPluralElement (doc.documentElement().namedItem(
"FRAMESETS").toElement());
1745 framesetsPluralElement.appendChild(framesetElement);
1747 TQDomElement frameElementOut(doc.createElement(
"FRAME"));
1748 framesetElement.appendChild(frameElementOut);
1749 importFrame( frameElementOut,
object,
true );
1753 m_styleStack.restore();
1756 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"text-style-name" ) )
1757 addStyles( m_styles[m_styleStack.attributeNS( ooNS::draw,
"text-style-name" )] );
1760 parseBodyOrSimilar( doc,
object, framesetElement );
1766void OoWriterImport::importFootnote( TQDomDocument& doc,
const TQDomElement&
object, TQDomElement& formats, uint pos,
const TQString& localName )
1768 const TQString frameName(
object.attributeNS( ooNS::text,
"id", TQString()) );
1769 TQDomElement citationElem = KoDom::namedItemNS(
object, ooNS::text, (localName+
"-citation").latin1() ).toElement();
1771 bool endnote = localName ==
"endnote";
1773 TQString label = citationElem.attributeNS( ooNS::text,
"label", TQString() );
1774 bool autoNumbered = label.isEmpty();
1777 TQDomElement footnoteElem = doc.createElement(
"FOOTNOTE" );
1779 footnoteElem.setAttribute(
"value", 1 );
1781 footnoteElem.setAttribute(
"value", label );
1782 footnoteElem.setAttribute(
"notetype", endnote ?
"endnote" :
"footnote" );
1783 footnoteElem.setAttribute(
"numberingtype", autoNumbered ?
"auto" :
"manual" );
1784 footnoteElem.setAttribute(
"frameset", frameName );
1786 appendKWordVariable( doc, formats, citationElem, pos,
"STRI", 11 , footnoteElem );
1789 TQDomElement framesetElement( doc.createElement(
"FRAMESET") );
1790 framesetElement.setAttribute(
"frameType", 1 );
1791 framesetElement.setAttribute(
"frameInfo", 7 );
1792 framesetElement.setAttribute(
"name" , frameName );
1793 TQDomElement framesetsPluralElement (doc.documentElement().namedItem(
"FRAMESETS").toElement());
1794 framesetsPluralElement.appendChild(framesetElement);
1795 createInitialFrame( framesetElement, 29, 798, 567, 567+41,
true, NoFollowup );
1799 TQDomElement bodyElem = KoDom::namedItemNS(
object, ooNS::text, (localName+
"-body").latin1() ).toElement();
1800 parseBodyOrSimilar( doc, bodyElem, framesetElement );
1803TQString OoWriterImport::appendPicture(TQDomDocument& doc,
const TQDomElement&
object)
1805 const TQString frameName (
object.attributeNS( ooNS::draw,
"name", TQString()) );
1806 const TQString href (
object.attributeNS( ooNS::xlink,
"href", TQString()) );
1808 kdDebug(30518) <<
"Picture: " << frameName <<
" " << href <<
" (in OoWriterImport::appendPicture)" << endl;
1813 TQString strExtension;
1814 const int result=href.findRev(
".");
1817 strExtension=href.mid(result+1);
1819 TQString filename(href.mid(1));
1820 KoPictureKey key(filename, TQDateTime::currentDateTime(TQt::UTC));
1821 picture.setKey(key);
1826 const KArchiveEntry* entry = m_zip->directory()->entry( filename );
1829 kdWarning(30518) <<
"Picture " << filename <<
" not found!" << endl;
1832 if (entry->isDirectory())
1834 kdWarning(30518) <<
"Picture " << filename <<
" is a directory!" << endl;
1837 const KZipFileEntry* f =
static_cast<const KZipFileEntry *
>(entry);
1838 TQIODevice* io=f->device();
1839 kdDebug(30518) <<
"Picture " << filename <<
" has size " << f->size() << endl;
1843 kdWarning(30518) <<
"No TQIODevice for picture " << frameName <<
" " << href << endl;
1846 if (!picture.load(io,strExtension))
1847 kdWarning(30518) <<
"Cannot load picture: " << frameName <<
" " << href << endl;
1853 picture.setKeyAndDownloadPicture(url, 0);
1856 kdDebug(30518) <<
"Picture ready! Key: " << picture.getKey().toString() <<
" Size:" << picture.getOriginalSize() << endl;
1858 TQString strStoreName;
1859 strStoreName=
"pictures/picture";
1860 strStoreName+=TQString::number(++m_pictureNumber);
1862 strStoreName+=picture.getExtension();
1864 kdDebug(30518) <<
"Storage name: " << strStoreName << endl;
1866 KoStoreDevice* out = m_chain->storageFile( strStoreName , KoStore::Write );
1869 if (!out->open(IO_WriteOnly))
1871 kdWarning(30518) <<
"Cannot open for saving picture: " << frameName <<
" " << href << endl;
1874 if (!picture.save(out))
1875 kdWarning(30518) <<
"Cannot save picture: " << frameName <<
" " << href << endl;
1880 kdWarning(30518) <<
"Cannot store picture: " << frameName <<
" " << href << endl;
1886 TQDomElement docElement( doc.documentElement() );
1888 TQDomElement framesetsPluralElement ( docElement.namedItem(
"FRAMESETS").toElement() );
1890 TQDomElement framesetElement=doc.createElement(
"FRAMESET");
1891 framesetElement.setAttribute(
"frameType",2);
1892 framesetElement.setAttribute(
"frameInfo",0);
1893 framesetElement.setAttribute(
"visible",1);
1894 framesetElement.setAttribute(
"name",frameName);
1895 framesetsPluralElement.appendChild(framesetElement);
1897 TQDomElement frameElementOut=doc.createElement(
"FRAME");
1898 framesetElement.appendChild(frameElementOut);
1900 m_styleStack.save();
1901 fillStyleStack(
object, ooNS::draw,
"style-name" );
1902 importFrame( frameElementOut,
object,
false );
1903 m_styleStack.restore();
1905 TQDomElement element=doc.createElement(
"PICTURE");
1906 element.setAttribute(
"keepAspectRatio",
"true");
1907 framesetElement.setAttribute(
"frameType",2);
1908 framesetElement.appendChild(element);
1910 TQDomElement singleKey ( doc.createElement(
"KEY") );
1911 picture.getKey().saveAttributes(singleKey);
1912 element.appendChild(singleKey);
1914 TQDomElement picturesPluralElement ( docElement.namedItem(
"PICTURES").toElement() );
1915 if (picturesPluralElement.isNull())
1918 picturesPluralElement = doc.createElement(
"PICTURES");
1919 docElement.appendChild(picturesPluralElement);
1922 TQDomElement pluralKey ( doc.createElement(
"KEY") );
1923 picture.getKey().saveAttributes(pluralKey);
1924 pluralKey.setAttribute(
"name",strStoreName);
1925 picturesPluralElement.appendChild(pluralKey);
1929void OoWriterImport::anchorFrameset( TQDomDocument& doc, TQDomElement& formats, uint pos,
const TQString& frameSetName )
1931 TQDomElement formatElementOut=doc.createElement(
"FORMAT");
1932 formatElementOut.setAttribute(
"id",6);
1933 formatElementOut.setAttribute(
"pos",pos);
1934 formatElementOut.setAttribute(
"len",1);
1935 formats.appendChild(formatElementOut);
1937 TQDomElement anchor=doc.createElement(
"ANCHOR");
1939 anchor.setAttribute(
"type",
"frameset");
1940 anchor.setAttribute(
"instance",frameSetName);
1941 formatElementOut.appendChild(anchor);
1944void OoWriterImport::appendField(TQDomDocument& doc, TQDomElement& outputFormats, TQDomElement&
object, uint pos)
1948 const TQString localName (
object.localName());
1952 if ( localName.endsWith(
"date" ) || localName.endsWith(
"time" ) )
1954 TQString dataStyleName =
object.attributeNS( ooNS::style,
"data-style-name", TQString() );
1955 TQString dateFormat =
"locale";
1956 DataFormatsMap::const_iterator it = m_dateTimeFormats.find( dataStyleName );
1957 if ( it != m_dateTimeFormats.end() )
1960 if ( localName ==
"date" )
1964 TQDateTime dt(TQDate::fromString(
object.attributeNS( ooNS::text,
"date-value", TQString()), TQt::ISODate));
1966 bool fixed = (
object.hasAttributeNS( ooNS::text,
"fixed") &&
object.attributeNS( ooNS::text,
"fixed", TQString())==
"true");
1969 dt = TQDateTime::currentDateTime();
1972 const TQDate date(dt.date());
1973 const TQTime time(dt.time());
1977 TQDomElement dateElement ( doc.createElement(
"DATE") );
1978 dateElement.setAttribute(
"fix", fixed ? 1 : 0);
1979 dateElement.setAttribute(
"subtype", subtype);
1980 dateElement.setAttribute(
"day", date.day());
1981 dateElement.setAttribute(
"month", date.month());
1982 dateElement.setAttribute(
"year", date.year());
1983 dateElement.setAttribute(
"hour", time.hour());
1984 dateElement.setAttribute(
"minute", time.minute());
1985 dateElement.setAttribute(
"second", time.second());
1986 if (
object.hasAttributeNS( ooNS::text,
"date-adjust"))
1987 dateElement.setAttribute(
"correct",
object.attributeNS( ooNS::text,
"date-adjust", TQString()));
1988 appendKWordVariable(doc, outputFormats,
object, pos,
"DATE" + dateFormat, 0, dateElement);
1990 else if (localName ==
"time")
1993 TQDateTime dt(TQDateTime::fromString(
object.attributeNS( ooNS::text,
"time-value", TQString()), TQt::ISODate));
1995 bool fixed = (
object.hasAttributeNS( ooNS::text,
"fixed") &&
object.attributeNS( ooNS::text,
"fixed", TQString())==
"true");
1997 if (!dt.isValid()) {
1998 dt = TQDateTime::currentDateTime();
2002 const TQTime time(dt.time());
2003 TQDomElement timeElement (doc.createElement(
"TIME") );
2004 timeElement.setAttribute(
"fix", fixed ? 1 : 0);
2005 timeElement.setAttribute(
"hour", time.hour());
2006 timeElement.setAttribute(
"minute", time.minute());
2007 timeElement.setAttribute(
"second", time.second());
2010 appendKWordVariable(doc, outputFormats,
object, pos,
"TIME" + dateFormat, 2, timeElement);
2013 else if ( localName ==
"print-time"
2014 || localName ==
"print-date"
2015 || localName ==
"creation-time"
2016 || localName ==
"creation-date"
2017 || localName ==
"modification-time"
2018 || localName ==
"modification-date" )
2020 if ( localName.startsWith(
"print" ) )
2022 else if ( localName.startsWith(
"creation" ) )
2024 else if ( localName.startsWith(
"modification" ) )
2028 TQDomElement dateElement ( doc.createElement(
"DATE") );
2029 dateElement.setAttribute(
"subtype", subtype);
2030 if (
object.hasAttributeNS( ooNS::text,
"date-adjust"))
2031 dateElement.setAttribute(
"correct",
object.attributeNS( ooNS::text,
"date-adjust", TQString()));
2032 appendKWordVariable(doc, outputFormats,
object, pos,
"DATE" + dateFormat, 0, dateElement);
2035 else if (localName ==
"page-number")
2039 if (
object.hasAttributeNS( ooNS::text,
"select-page"))
2041 const TQString select =
object.attributeNS( ooNS::text,
"select-page", TQString());
2043 if (select ==
"previous")
2045 else if (select ==
"next")
2049 TQDomElement pgnumElement ( doc.createElement(
"PGNUM") );
2050 pgnumElement.setAttribute(
"subtype", subtype);
2051 pgnumElement.setAttribute(
"value",
object.text());
2052 appendKWordVariable(doc, outputFormats,
object, pos,
"NUMBER", 4, pgnumElement);
2054 else if (localName ==
"chapter")
2056 const TQString display =
object.attributeNS( ooNS::text,
"display", TQString() );
2058 TQDomElement pgnumElement ( doc.createElement(
"PGNUM") );
2059 pgnumElement.setAttribute(
"subtype", 2);
2060 pgnumElement.setAttribute(
"value",
object.text());
2061 appendKWordVariable(doc, outputFormats,
object, pos,
"STRING", 4, pgnumElement);
2063 else if (localName ==
"file-name")
2067 if (
object.hasAttributeNS( ooNS::text,
"display"))
2069 const TQString display =
object.attributeNS( ooNS::text,
"display", TQString());
2071 if (display ==
"path")
2073 else if (display ==
"name")
2075 else if (display ==
"name-and-extension")
2081 TQDomElement fieldElement ( doc.createElement(
"FIELD") );
2082 fieldElement.setAttribute(
"subtype", subtype);
2083 fieldElement.setAttribute(
"value",
object.text());
2084 appendKWordVariable(doc, outputFormats,
object, pos,
"STRING", 8, fieldElement);
2086 else if (localName ==
"author-name"
2087 || localName ==
"author-initials"
2088 || localName ==
"subject"
2089 || localName ==
"title"
2090 || localName ==
"description"
2095 if (localName ==
"author-initials")
2097 else if ( localName ==
"subject" )
2099 else if ( localName ==
"title" )
2101 else if ( localName ==
"description" )
2104 TQDomElement authorElem = doc.createElement(
"FIELD");
2105 authorElem.setAttribute(
"subtype", subtype);
2106 authorElem.setAttribute(
"value",
object.text());
2107 appendKWordVariable(doc, outputFormats,
object, pos,
"STRING", 8, authorElem);
2109 else if ( localName.startsWith(
"sender-" ) )
2112 const TQCString afterText( localName.latin1() + 5 );
2113 if ( afterText ==
"sender-company" )
2115 else if ( afterText ==
"sender-firstname" )
2117 else if ( afterText ==
"sender-lastname" )
2119 else if ( afterText ==
"sender-initials" )
2121 else if ( afterText ==
"sender-street" )
2123 else if ( afterText ==
"sender-country" )
2125 else if ( afterText ==
"sender-postal-code" )
2127 else if ( afterText ==
"sender-city" )
2129 else if ( afterText ==
"sender-title" )
2131 else if ( afterText ==
"sender-position" )
2133 else if ( afterText ==
"sender-phone-private" )
2135 else if ( afterText ==
"sender-phone-work" )
2137 else if ( afterText ==
"sender-fax" )
2139 else if ( afterText ==
"sender-email" )
2141 if ( subtype != -1 )
2143 TQDomElement fieldElem = doc.createElement(
"FIELD");
2144 fieldElem.setAttribute(
"subtype", subtype);
2145 fieldElem.setAttribute(
"value",
object.text());
2146 appendKWordVariable(doc, outputFormats,
object, pos,
"STRING", 8, fieldElem);
2149 else if ( localName ==
"variable-set"
2150 || localName ==
"user-defined" )
2156 TQDomElement customElem = doc.createElement(
"CUSTOM" );
2157 customElem.setAttribute(
"name",
object.attributeNS( ooNS::text,
"name", TQString() ) );
2158 customElem.setAttribute(
"value",
object.text() );
2159 appendKWordVariable(doc, outputFormats,
object, pos,
"STRING", 6, customElem);
2163 kdWarning(30518) <<
"Unsupported field " << localName << endl;
2168void OoWriterImport::appendKWordVariable(TQDomDocument& doc, TQDomElement& formats,
const TQDomElement&
object, uint pos,
2169 const TQString& key,
int type, TQDomElement& child)
2171 TQDomElement variableElement ( doc.createElement(
"VARIABLE") );
2173 TQDomElement typeElement ( doc.createElement(
"TYPE") );
2174 typeElement.setAttribute(
"key",key);
2175 typeElement.setAttribute(
"type",type);
2176 typeElement.setAttribute(
"text",
object.text());
2177 variableElement.appendChild(typeElement);
2179 variableElement.appendChild(child);
2181 TQDomElement formatElement ( doc.createElement(
"FORMAT") );
2182 formatElement.setAttribute(
"id",4);
2183 formatElement.setAttribute(
"pos",pos);
2184 formatElement.setAttribute(
"len",1);
2186 formatElement.appendChild(variableElement);
2188 formats.appendChild(formatElement);
2191void OoWriterImport::parseTable( TQDomDocument &doc,
const TQDomElement& parent, TQDomElement& currentFramesetElement )
2193 TQString tableName ( parent.attributeNS( ooNS::table,
"name", TQString()) );
2194 kdDebug(30518) <<
"Found table " << tableName << endl;
2197 TQDomElement paragraphElementOut (doc.createElement(
"PARAGRAPH"));
2198 currentFramesetElement.appendChild(paragraphElementOut);
2200 TQDomElement textElementOut(doc.createElement(
"TEXT"));
2201 textElementOut.appendChild(doc.createTextNode(
"#"));
2202 paragraphElementOut.appendChild(textElementOut);
2204 TQDomElement formatsPluralElementOut(doc.createElement(
"FORMATS"));
2205 paragraphElementOut.appendChild(formatsPluralElementOut);
2207 TQDomElement elementFormat(doc.createElement(
"FORMAT"));
2208 elementFormat.setAttribute(
"id",6);
2209 elementFormat.setAttribute(
"pos",0);
2210 elementFormat.setAttribute(
"len",1);
2211 formatsPluralElementOut.appendChild(elementFormat);
2215 TQDomElement elementAnchor(doc.createElement(
"ANCHOR"));
2216 elementAnchor.setAttribute(
"type",
"frameset");
2217 elementAnchor.setAttribute(
"instance",tableName);
2218 elementFormat.appendChild(elementAnchor);
2222 TQMemArray<double> columnLefts(4);
2223 uint maxColumns=columnLefts.size() - 1;
2228 forEachElement( elem, parent )
2230 if ( elem.localName() ==
"table-column" && elem.namespaceURI() == ooNS::table )
2232 uint repeat = elem.attributeNS( ooNS::table,
"number-columns-repeated",
"1").toUInt();
2235 const TQString styleName ( elem.attributeNS( ooNS::table,
"style-name", TQString()) );
2236 kdDebug(30518) <<
"Column " << col <<
" style " << styleName << endl;
2237 const TQDomElement* style=m_styles.find(styleName);
2241 const TQDomElement elemProps( KoDom::namedItemNS( *style, ooNS::style,
"properties") );
2242 if (elemProps.isNull())
2244 kdWarning(30518) <<
"Could not find table column style properties!" << endl;
2246 const TQString strWidth ( elemProps.attributeNS( ooNS::style,
"column-width", TQString()) );
2247 kdDebug(30518) <<
"- raw style width " << strWidth << endl;
2248 width = KoUnit::parseValue( strWidth );
2251 kdWarning(30518) <<
"Could not find table column style!" << endl;
2255 kdWarning(30518) <<
"Table column width ridiculous, assuming 1 inch!" << endl;
2259 kdDebug(30518) <<
"- style width " << width << endl;
2261 for (uint j=0; j<repeat; j++)
2264 if (col>=maxColumns)
2268 columnLefts.resize(maxColumns+1, TQGArray::SpeedOptim);
2270 columnLefts.at(col) = width + columnLefts.at(col-1);
2271 kdDebug(30518) <<
"Cell column " << col-1 <<
" left " << columnLefts.at(col-1) <<
" right " << columnLefts.at(col) << endl;
2278 parseInsideOfTable(doc, parent, currentFramesetElement, tableName, columnLefts, row, column);
2281void OoWriterImport::parseInsideOfTable( TQDomDocument &doc,
const TQDomElement& parent, TQDomElement& currentFramesetElement,
2282 const TQString& tableName,
const TQMemArray<double> & columnLefts, uint& row, uint& column )
2284 kdDebug(30518) <<
"parseInsideOfTable: columnLefts.size()=" << columnLefts.size() << endl;
2285 TQDomElement framesetsPluralElement (doc.documentElement().namedItem(
"FRAMESETS").toElement());
2286 if (framesetsPluralElement.isNull())
2288 kdError(30518) <<
"Cannot find KWord's <FRAMESETS>! Cannot process table!" << endl;
2293 forEachElement( e, parent )
2295 m_styleStack.save();
2296 const TQString localName = e.localName();
2297 const TQString ns = e.namespaceURI();
2298 if ( ns != ooNS::table ) {
2299 kdWarning(30518) <<
"Skipping element " << e.tagName() <<
" (in OoWriterImport::parseInsideOfTable)" << endl;
2303 if ( localName ==
"table-cell" )
2305 const TQString frameName(i18n(
"Frameset name",
"Table %3, row %1, column %2")
2306 .arg(row).arg(column).arg(tableName));
2307 kdDebug(30518) <<
"Trying to create " << frameName << endl;
2310 TQDomElement framesetElement(doc.createElement(
"FRAMESET"));
2311 framesetElement.setAttribute(
"frameType",1);
2312 framesetElement.setAttribute(
"frameInfo",0);
2313 framesetElement.setAttribute(
"visible",1);
2314 framesetElement.setAttribute(
"name",frameName);
2315 framesetElement.setAttribute(
"row",row);
2316 framesetElement.setAttribute(
"col",column);
2317 int rowSpan = e.attributeNS( ooNS::table,
"number-rows-spanned", TQString() ).toInt();
2318 framesetElement.setAttribute(
"rows",rowSpan == 0 ? 1 : rowSpan);
2319 int colSpan = e.attributeNS( ooNS::table,
"number-columns-spanned", TQString() ).toInt();
2320 framesetElement.setAttribute(
"cols",colSpan == 0 ? 1 : colSpan);
2321 framesetElement.setAttribute(
"grpMgr",tableName);
2322 framesetsPluralElement.appendChild(framesetElement);
2324 TQDomElement frameElementOut(doc.createElement(
"FRAME"));
2325 frameElementOut.setAttribute(
"left",columnLefts.at(column));
2326 frameElementOut.setAttribute(
"right",columnLefts.at(column+1));
2327 frameElementOut.setAttribute(
"top", 0);
2328 frameElementOut.setAttribute(
"bottom", 0);
2329 frameElementOut.setAttribute(
"runaround",1);
2330 frameElementOut.setAttribute(
"autoCreateNewFrame",0);
2333 m_styleStack.save();
2334 fillStyleStack( e, ooNS::table,
"style-name" );
2335 importCommonFrameProperties(frameElementOut);
2336 m_styleStack.restore();
2338 framesetElement.appendChild(frameElementOut);
2340 parseBodyOrSimilar( doc, e, framesetElement );
2343 else if ( localName ==
"covered-table-cell" )
2347 else if ( localName ==
"table-row" )
2350 parseInsideOfTable( doc, e, currentFramesetElement, tableName, columnLefts, row, column);
2353 else if ( localName ==
"table-header-rows" )
2355 parseInsideOfTable( doc, e, currentFramesetElement, tableName, columnLefts, row, column);
2357 else if ( localName ==
"table-column" )
2364 kdWarning(30518) <<
"Skipping element " << localName <<
" (in OoWriterImport::parseInsideOfTable)" << endl;
2367 m_styleStack.restore();
2371void OoWriterImport::appendBookmark( TQDomDocument& doc,
int paragId,
int pos,
const TQString& name )
2373 appendBookmark( doc, paragId, pos, paragId, pos, name );
2376void OoWriterImport::appendBookmark( TQDomDocument& doc,
int paragId,
int pos,
int endParagId,
int endPos,
const TQString& name )
2378 Q_ASSERT( !m_currentFrameset.isNull() );
2379 const TQString frameSetName = m_currentFrameset.attribute(
"name" );
2380 Q_ASSERT( !frameSetName.isEmpty() );
2381 TQDomElement bookmarks = doc.documentElement().namedItem(
"BOOKMARKS" ).toElement();
2382 if ( bookmarks.isNull() ) {
2383 bookmarks = doc.createElement(
"BOOKMARKS" );
2384 doc.documentElement().appendChild( bookmarks );
2386 TQDomElement bkItem = doc.createElement(
"BOOKMARKITEM" );
2387 bkItem.setAttribute(
"name", name );
2388 bkItem.setAttribute(
"frameset", frameSetName );
2389 bkItem.setAttribute(
"startparag", paragId );
2390 bkItem.setAttribute(
"cursorIndexStart", pos );
2391 bkItem.setAttribute(
"endparag", endParagId );
2392 bkItem.setAttribute(
"cursorIndexEnd", endPos );
2393 bookmarks.appendChild( bkItem );
2397void OoWriterImport::importFootnotesConfiguration( TQDomDocument& doc,
const TQDomElement& elem,
bool endnote )
2399 TQDomElement docElement( doc.documentElement() );
2401 TQString elemName = endnote ?
"ENDNOTESETTING" :
"FOOTNOTESETTING";
2402 Q_ASSERT( docElement.namedItem( elemName ).isNull() );
2403 TQDomElement settings = doc.createElement( elemName );
2404 docElement.appendChild( settings );
2410 if ( elem.hasAttributeNS( ooNS::text,
"start-value" ) ) {
2411 int startValue = elem.attributeNS( ooNS::text,
"start-value", TQString() ).toInt();
2412 settings.setAttribute(
"start", startValue );
2415 settings.setAttribute(
"type", Conversion::importCounterType( elem.attributeNS( ooNS::style,
"num-format", TQString() ) ) );
2416 settings.setAttribute(
"lefttext", elem.attributeNS( ooNS::style,
"num-prefix", TQString() ) );
2417 settings.setAttribute(
"righttext", elem.attributeNS( ooNS::style,
"num-suffix", TQString() ) );
2420void OoWriterImport::appendTOC( TQDomDocument& doc,
const TQDomElement& toc )
2431 TQDomElement tocIndexBody = KoDom::namedItemNS( toc, ooNS::text,
"index-body" );
2433 forEachElement( t, tocIndexBody )
2435 m_styleStack.save();
2436 const TQString localName = t.localName();
2438 bool isTextNS = e.namespaceURI() == ooNS::text;
2439 if ( isTextNS && localName ==
"index-title" ) {
2440 parseBodyOrSimilar( doc, t, m_currentFrameset );
2441 }
else if ( isTextNS && localName ==
"p" ) {
2442 fillStyleStack( t, ooNS::text,
"style-name" );
2443 e = parseParagraph( doc, t );
2446 m_currentFrameset.appendChild( e );
2447 m_styleStack.restore();
2457void OoWriterImport::finishDocumentContent( TQDomDocument& mainDocument )
2459 TQDomElement attributes = mainDocument.createElement(
"ATTRIBUTES" );
2460 TQDomElement docElement = mainDocument.documentElement();
2461 docElement.appendChild( attributes );
2462 attributes.setAttribute(
"hasTOC", m_hasTOC ? 1 : 0 );
2463 attributes.setAttribute(
"hasHeader", m_hasHeader );
2464 attributes.setAttribute(
"hasFooter", m_hasFooter );
2470 TQDomElement paperElement = docElement.namedItem(
"PAPER").toElement();
2471 Q_ASSERT ( !paperElement.isNull() );
2472 if ( !paperElement.isNull() )
2480TQString OoWriterImport::kWordStyleName(
const TQString& ooStyleName )
2482 if ( ooStyleName.startsWith(
"Contents " ) ) {
2483 TQString s( ooStyleName );
2484 return s.replace( 0, 9, TQString(
"Contents Head ") );
2491void OoWriterImport::importHeaderFooter( TQDomDocument& doc,
const TQDomElement& headerFooter,
bool hasEvenOdd, TQDomElement& style )
2493 const TQString localName = headerFooter.localName();
2494 TQDomElement framesetElement = doc.createElement(
"FRAMESET");
2495 TQDomElement framesetsPluralElement (doc.documentElement().namedItem(
"FRAMESETS").toElement());
2496 framesetElement.setAttribute(
"frameType", 1 );
2497 framesetElement.setAttribute(
"frameInfo", Conversion::headerTypeToFrameInfo( localName, hasEvenOdd ) );
2498 framesetElement.setAttribute(
"name", Conversion::headerTypeToFramesetName( localName, hasEvenOdd ) );
2499 framesetsPluralElement.appendChild(framesetElement);
2501 bool isHeader = localName.startsWith(
"header" );
2506 TQDomElement frameElementOut = createInitialFrame( framesetElement, 29, 798, isHeader?0:567, isHeader?41:567+41, true, Copy );
2507 if ( !style.isNull() )
2508 m_styleStack.push( style );
2509 importCommonFrameProperties( frameElementOut );
2510 if ( !style.isNull() )
2513 parseBodyOrSimilar( doc, headerFooter, framesetElement );
2516#include "oowriterimport.moc"