29#include "oowriterimport.h"
34#include <KoDocumentInfo.h>
35#include <KoDocument.h>
37#include <kgenericfactory.h>
38#include <tdemessagebox.h>
39#include <KoFilterChain.h>
41#include <KoPageLayout.h>
43#include "conversion.h"
47typedef KGenericFactory<OoWriterImport, KoFilter> OoWriterImportFactory;
48K_EXPORT_COMPONENT_FACTORY( liboowriterimport, OoWriterImportFactory(
"kofficefilters" ) )
50OoWriterImport::OoWriterImport( KoFilter *, const
char *, const TQStringList & )
52 m_styleStack( ooNS::style, ooNS::fo ),
53 m_insideOrderedList( false ), m_nextItemIsListItem( false ),
54 m_hasTOC( false ), m_hasHeader( false ), m_hasFooter( false ), m_restartNumbering( -1 ),
55 m_pictureNumber(0), m_zip(NULL)
57 m_styles.setAutoDelete(
true );
58 m_masterPages.setAutoDelete(
true );
59 m_listStyles.setAutoDelete(
true );
62OoWriterImport::~OoWriterImport()
66KoFilter::ConversionStatus OoWriterImport::convert( TQCString
const & from, TQCString
const & to )
68 kdDebug(30518) <<
"Entering Oowriter Import filter: " << from <<
" - " << to << endl;
70 if ( ( from !=
"application/vnd.sun.xml.writer"
71 && from !=
"application/vnd.sun.xml.writer.template"
72 && from !=
"application/vnd.sun.xml.writer.master" )
73 || to !=
"application/x-kword" )
75 kdWarning(30518) <<
"Invalid mimetypes " << from <<
" " << to << endl;
76 return KoFilter::NotImplemented;
79 m_zip=
new KZip(m_chain->inputFile());
81 kdDebug(30518) <<
"Store created" << endl;
83 if ( !m_zip->open(IO_ReadOnly) )
85 kdError(30518) <<
"Couldn't open the requested file "<< m_chain->inputFile() << endl;
86 return KoFilter::FileNotFound;
89 if ( !m_zip->directory() )
91 kdError(30518) <<
"Couldn't read ZIP directory of the requested file "<< m_chain->inputFile() << endl;
92 return KoFilter::FileNotFound;
96 KoFilter::ConversionStatus preStatus = openFile();
99 if ( preStatus == KoFilter::OK )
102 OoUtils::loadThumbnail( thumbnail, m_zip );
105 if ( preStatus != KoFilter::OK )
112 m_currentMasterPage = TQString();
113 TQDomDocument mainDocument;
114 TQDomElement framesetsElem;
115 prepareDocument( mainDocument, framesetsElem );
118 if ( !createStyleMap( m_stylesDoc, mainDocument ) )
119 return KoFilter::UserCancelled;
121 if ( !createStyleMap( m_content, mainDocument ) )
122 return KoFilter::UserCancelled;
125 TQDomElement mainFramesetElement = mainDocument.createElement(
"FRAMESET");
126 mainFramesetElement.setAttribute(
"frameType",1);
127 mainFramesetElement.setAttribute(
"frameInfo",0);
128 mainFramesetElement.setAttribute(
"visible",1);
129 mainFramesetElement.setAttribute(
"name", i18n(
"Main Text Frameset" ) );
130 framesetsElem.appendChild(mainFramesetElement);
132 createInitialFrame( mainFramesetElement, 29, 798, 42, 566,
false, Reconnect );
133 createStyles( mainDocument );
134 createDocumentContent( mainDocument, mainFramesetElement );
135 finishDocumentContent( mainDocument );
140 KoStoreDevice* out = m_chain->storageFile(
"maindoc.xml", KoStore::Write );
142 kdError(30518) <<
"Unable to open output file!" << endl;
143 return KoFilter::StorageCreationError;
147 TQCString cstr = mainDocument.toCString();
148 kdDebug(30518)<<
" maindoc: " << cstr << endl;
150 out->writeBlock( cstr, cstr.length() );
153 TQDomDocument docinfo;
154 createDocumentInfo( docinfo );
157 out = m_chain->storageFile(
"documentinfo.xml", KoStore::Write );
160 TQCString info = docinfo.toCString();
161 kdDebug(30518)<<
" info :"<<info<<endl;
163 out->writeBlock( info , info.length() );
168 if ( ! thumbnail.isNull() )
172 TQImage preview( thumbnail.smoothScale( 256, 256 ).convertDepth(8, TQt::AvoidDither | TQt::DiffuseDither) );
174 if ( !preview.isNull() )
176 out = m_chain->storageFile(
"preview.png", KoStore::Write );
179 preview.save( out,
"PNG" );
184 kdDebug(30518) <<
"######################## OoWriterImport::convert done ####################" << endl;
188void OoWriterImport::createStyles( TQDomDocument& doc )
190 TQDomElement stylesElem = doc.createElement(
"STYLES" );
191 doc.documentElement().appendChild( stylesElem );
193 TQDomNode fixedStyles = KoDom::namedItemNS( m_stylesDoc.documentElement(), ooNS::office,
"styles" );
194 Q_ASSERT( !fixedStyles.isNull() );
196 forEachElement( e, fixedStyles )
198 if ( !e.hasAttributeNS( ooNS::style,
"name" ) )
201 if ( e.attributeNS( ooNS::style,
"family", TQString() ) !=
"paragraph" )
209 TQDomElement styleElem = doc.createElement(
"STYLE");
210 stylesElem.appendChild( styleElem );
212 TQString styleName = kWordStyleName( e.attributeNS( ooNS::style,
"name", TQString() ) );
213 TQDomElement element = doc.createElement(
"NAME");
214 element.setAttribute(
"value", styleName );
215 styleElem.appendChild( element );
218 TQString followingStyle = m_styleStack.attributeNS( ooNS::style,
"next-style-name" );
219 if ( !followingStyle.isEmpty() )
221 TQDomElement element = doc.createElement(
"FOLLOWING" );
222 element.setAttribute(
"name", kWordStyleName( followingStyle ) );
223 styleElem.appendChild( element );
230 bool outline = styleName.startsWith(
"Heading" );
232 styleElem.setAttribute(
"outline",
"true" );
234 writeFormat( doc, styleElem, 1, 0, 0 );
235 writeLayout( doc, styleElem );
239 const int level = styleName.right(1).toInt();
243 listOK = pushListLevelStyle(
"<outline-style>", m_outlineStyle, level );
245 const TQString listStyleName = e.attributeNS( ooNS::style,
"list-style-name", TQString() );
246 listOK = !listStyleName.isEmpty();
248 listOK = pushListLevelStyle( listStyleName, level );
252 const TQDomElement listStyle = m_listStyleStack.currentListStyle();
254 bool ordered = listStyle.localName() ==
"list-level-style-number";
255 writeCounter( doc, styleElem, outline, level, ordered );
256 m_listStyleStack.pop();
259 m_styleStack.clear();
263void OoWriterImport::parseBodyOrSimilar( TQDomDocument &doc,
const TQDomElement& parent, TQDomElement& currentFramesetElement )
265 TQDomElement oldCurrentFrameset = m_currentFrameset;
266 m_currentFrameset = currentFramesetElement;
267 Q_ASSERT( !m_currentFrameset.isNull() );
269 forEachElement( t, parent )
272 const TQString localName = t.localName();
273 const TQString ns = t.namespaceURI();
274 const bool isTextNS = ns == ooNS::text;
277 if ( isTextNS && localName ==
"p" ) {
278 fillStyleStack( t, ooNS::text,
"style-name" );
279 e = parseParagraph( doc, t );
281 else if ( isTextNS && localName ==
"h" )
283 fillStyleStack( t, ooNS::text,
"style-name" );
284 int level = t.attributeNS( ooNS::text,
"level", TQString() ).toInt();
294 if ( !m_nextItemIsListItem )
295 listOK = pushListLevelStyle(
"<outline-style>", m_outlineStyle, level );
296 m_nextItemIsListItem =
true;
297 if ( t.hasAttributeNS( ooNS::text,
"start-value" ) )
299 m_restartNumbering = t.attributeNS( ooNS::text,
"start-value", TQString() ).toInt();
300 e = parseParagraph( doc, t );
302 m_listStyleStack.pop();
304 else if ( isTextNS &&
305 ( localName ==
"unordered-list" || localName ==
"ordered-list" ) )
307 parseList( doc, t, currentFramesetElement );
308 m_styleStack.restore();
311 else if ( isTextNS && localName ==
"section" )
313 kdDebug(30518) <<
"Section found!" << endl;
314 fillStyleStack( t, ooNS::text,
"style-name" );
315 parseBodyOrSimilar( doc, t, currentFramesetElement);
317 else if ( localName ==
"table" && ns == ooNS::table )
319 kdDebug(30518) <<
"Table found!" << endl;
320 parseTable( doc, t, currentFramesetElement );
322 else if ( localName ==
"image" && ns == ooNS::draw )
324 appendPicture( doc, t );
326 else if ( localName ==
"text-box" && ns == ooNS::draw )
328 appendTextBox( doc, t );
330 else if ( isTextNS && localName ==
"variable-decls" )
335 else if ( localName ==
"table-of-content" && ns == ooNS::text )
342 kdWarning(30518) <<
"Unsupported body element '" << localName <<
"'" << endl;
346 currentFramesetElement.appendChild( e );
347 m_styleStack.restore();
349 m_currentFrameset = oldCurrentFrameset;
352void OoWriterImport::createDocumentContent( TQDomDocument &doc, TQDomElement& mainFramesetElement )
354 TQDomElement content = m_content.documentElement();
356 TQDomElement body ( KoDom::namedItemNS( content, ooNS::office,
"body" ) );
359 kdError(30518) <<
"No office:body found!" << endl;
363 parseBodyOrSimilar( doc, body, mainFramesetElement );
366void OoWriterImport::writePageLayout( TQDomDocument& mainDocument,
const TQString& masterPageName )
368 TQDomElement docElement = mainDocument.documentElement();
370 kdDebug(30518) <<
"writePageLayout " << masterPageName << endl;
371 TQDomElement elementPaper = mainDocument.createElement(
"PAPER");
372 KoOrientation orientation;
373 double width, height;
374 KoFormat paperFormat;
375 double marginLeft, marginTop, marginRight, marginBottom;
376 bool hasEvenOddHeader =
false;
377 bool hasEvenOddFooter =
false;
379 TQDomElement* masterPage = m_masterPages[ masterPageName ];
380 Q_ASSERT( masterPage );
381 kdDebug(30518) <<
"page-master-name: " << masterPage->attributeNS( ooNS::style,
"page-master-name", TQString() ) << endl;
382 TQDomElement *style = masterPage ? m_styles[masterPage->attributeNS( ooNS::style,
"page-master-name", TQString() )] : 0;
386 TQDomElement properties( KoDom::namedItemNS( *style, ooNS::style,
"properties" ) );
387 Q_ASSERT( !properties.isNull() );
388 orientation = ( (properties.attributeNS( ooNS::style,
"print-orientation", TQString()) !=
"portrait") ? PG_LANDSCAPE : PG_PORTRAIT );
389 width = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"page-width", TQString()));
390 height = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"page-height", TQString()));
391 kdDebug(30518) <<
"width=" << width <<
" height=" << height << endl;
393 if ( orientation == PG_LANDSCAPE )
394 paperFormat = KoPageFormat::guessFormat( POINT_TO_MM(height), POINT_TO_MM(width) );
396 paperFormat = KoPageFormat::guessFormat( POINT_TO_MM(width), POINT_TO_MM(height) );
398 marginLeft = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"margin-left", TQString()));
399 marginTop = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"margin-top", TQString()));
400 marginRight = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"margin-right", TQString()));
401 marginBottom = KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"margin-bottom", TQString()));
403 TQDomElement footnoteSep = KoDom::namedItemNS( properties, ooNS::style,
"footnote-sep" );
404 if ( !footnoteSep.isNull() ) {
408 TQString width = footnoteSep.attributeNS( ooNS::style,
"width", TQString() );
409 elementPaper.setAttribute(
"slFootNoteWidth", KoUnit::parseValue( width ) );
410 TQString pageWidth = footnoteSep.attributeNS( ooNS::style,
"rel-width", TQString() );
411 if ( pageWidth.endsWith(
"%" ) ) {
412 pageWidth.truncate( pageWidth.length() - 1 );
413 elementPaper.setAttribute(
"slFootNoteLenth", pageWidth );
415 elementPaper.setAttribute(
"slFootNotePosition", footnoteSep.attributeNS( ooNS::style,
"adjustment", TQString() ) );
422 TQDomElement headerStyle = KoDom::namedItemNS( *style, ooNS::style,
"header-style" );
423 TQDomElement footerStyle = KoDom::namedItemNS( *style, ooNS::style,
"footer-style" );
424 TQDomElement headerLeftElem = KoDom::namedItemNS( *masterPage, ooNS::style,
"header-left" );
425 if ( !headerLeftElem.isNull() ) {
426 kdDebug(30518) <<
"Found header-left" << endl;
427 hasEvenOddHeader =
true;
428 importHeaderFooter( mainDocument, headerLeftElem, hasEvenOddHeader, headerStyle );
430 TQDomElement headerElem = KoDom::namedItemNS( *masterPage, ooNS::style,
"header" );
431 if ( !headerElem.isNull() ) {
432 kdDebug(30518) <<
"Found header" << endl;
433 importHeaderFooter( mainDocument, headerElem, hasEvenOddHeader, headerStyle );
435 TQDomElement footerLeftElem = KoDom::namedItemNS( *masterPage, ooNS::style,
"footer-left" );
436 if ( !footerLeftElem.isNull() ) {
437 kdDebug(30518) <<
"Found footer-left" << endl;
438 importHeaderFooter( mainDocument, footerLeftElem, hasEvenOddFooter, footerStyle );
440 TQDomElement footerElem = KoDom::namedItemNS( *masterPage, ooNS::style,
"footer" );
441 if ( !footerElem.isNull() ) {
442 kdDebug(30518) <<
"Found footer" << endl;
443 importHeaderFooter( mainDocument, footerElem, hasEvenOddFooter, footerStyle );
449 kdWarning(30518) <<
"NO MASTER PAGE" << endl;
450 orientation=PG_PORTRAIT;
451 paperFormat=PG_DIN_A4;
452 width=MM_TO_POINT(KoPageFormat::width(paperFormat, orientation));
453 height=MM_TO_POINT(KoPageFormat::height(paperFormat, orientation));
455 marginLeft=MM_TO_POINT(10.0);
456 marginRight=MM_TO_POINT(10.0);
457 marginTop=MM_TO_POINT(15.0);
458 marginBottom=MM_TO_POINT(15.0);
461 elementPaper.setAttribute(
"orientation",
int(orientation) );
462 elementPaper.setAttribute(
"width", width);
463 elementPaper.setAttribute(
"height", height);
464 elementPaper.setAttribute(
"format", paperFormat);
465 elementPaper.setAttribute(
"columns",1);
466 elementPaper.setAttribute(
"columnspacing",2);
467 elementPaper.setAttribute(
"hType", hasEvenOddHeader ? 3 : 0);
468 elementPaper.setAttribute(
"fType", hasEvenOddFooter ? 3 : 0);
469 elementPaper.setAttribute(
"spHeadBody",9);
470 elementPaper.setAttribute(
"spFootBody",9);
471 elementPaper.setAttribute(
"zoom",100);
472 docElement.appendChild(elementPaper);
475 TQDomElement element = mainDocument.createElement(
"PAPERBORDERS");
476 element.setAttribute(
"left", marginLeft);
477 element.setAttribute(
"top", marginTop);
478 element.setAttribute(
"right", marginRight);
479 element.setAttribute(
"bottom", marginBottom);
480 elementPaper.appendChild(element);
483void OoWriterImport::prepareDocument( TQDomDocument& mainDocument, TQDomElement& framesetsElem )
485 mainDocument = KoDocument::createDomDocument(
"kword",
"DOC",
"1.2" );
486 TQDomElement docElement = mainDocument.documentElement();
487 docElement.setAttribute(
"editor",
"KWord's OOWriter Import Filter" );
488 docElement.setAttribute(
"mime",
"application/x-kword" );
489 docElement.setAttribute(
"syntaxVersion",
"2" );
491 framesetsElem=mainDocument.createElement(
"FRAMESETS");
492 docElement.appendChild(framesetsElem);
495 TQDomElement varSettings = mainDocument.createElement(
"VARIABLESETTINGS" );
496 docElement.appendChild( varSettings );
497 TQDomNode meta = KoDom::namedItemNS( m_meta, ooNS::office,
"document-meta" );
498 TQDomNode office = KoDom::namedItemNS( meta, ooNS::office,
"meta" );
499 if ( !office.isNull() ) {
500 TQDomElement date = KoDom::namedItemNS( office, ooNS::dc,
"date" );
501 if ( !date.isNull() && !date.text().isEmpty() ) {
503 varSettings.setAttribute(
"modificationDate", date.text() );
505 date = KoDom::namedItemNS( office, ooNS::meta,
"creation-date" );
506 if ( !date.isNull() && !date.text().isEmpty() ) {
507 varSettings.setAttribute(
"creationDate", date.text() );
509 date = KoDom::namedItemNS( office, ooNS::meta,
"print-date" );
510 if ( !date.isNull() && !date.text().isEmpty() ) {
511 varSettings.setAttribute(
"lastPrintingDate", date.text() );
517TQDomElement OoWriterImport::createInitialFrame( TQDomElement& parentFramesetElem,
double left,
double right,
double top,
double bottom,
bool autoExtend, NewFrameBehavior nfb )
519 TQDomElement frameElementOut = parentFramesetElem.ownerDocument().createElement(
"FRAME");
520 frameElementOut.setAttribute(
"left", left );
521 frameElementOut.setAttribute(
"right", right );
522 frameElementOut.setAttribute(
"top", top );
523 frameElementOut.setAttribute(
"bottom", bottom );
524 frameElementOut.setAttribute(
"runaround", 1 );
526 frameElementOut.setAttribute(
"autoCreateNewFrame", autoExtend ? 0 : 1 );
527 frameElementOut.setAttribute(
"newFrameBehavior", nfb );
528 parentFramesetElem.appendChild( frameElementOut );
529 return frameElementOut;
532KoFilter::ConversionStatus OoWriterImport::loadAndParse(
const TQString& filename, TQDomDocument& doc)
534 return OoUtils::loadAndParse( filename, doc, m_zip);
537KoFilter::ConversionStatus OoWriterImport::openFile()
539 KoFilter::ConversionStatus status=loadAndParse(
"content.xml", m_content);
540 if ( status != KoFilter::OK )
542 kdError(30518) <<
"Content.xml could not be parsed correctly! Aborting!" << endl;
556 loadAndParse(
"styles.xml", m_stylesDoc);
557 loadAndParse(
"meta.xml", m_meta);
560 emit sigProgress( 10 );
566void OoWriterImport::createDocumentInfo( TQDomDocument &docinfo )
568 docinfo = KoDocument::createDomDocument(
"document-info" ,
"document-info" ,
"1.1" );
570 OoUtils::createDocumentInfo(m_meta, docinfo);
577bool OoWriterImport::createStyleMap(
const TQDomDocument & styles, TQDomDocument& doc )
579 TQDomElement docElement = styles.documentElement();
580 TQDomNode docStyles = KoDom::namedItemNS( docElement, ooNS::office,
"document-styles" );
582 if ( docElement.hasAttributeNS( ooNS::office,
"version" ) )
585 double d = docElement.attributeNS( ooNS::office,
"version", TQString() ).toDouble( &ok );
589 kdDebug(30518) <<
"OpenWriter version: " << d << endl;
592 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?") );
593 message = message.arg( docElement.attributeNS( ooNS::office,
"version", TQString() ) );
594 if ( KMessageBox::warningYesNo( 0, message, i18n(
"Unsupported document version" ) ) == KMessageBox::No )
600 TQDomNode fontStyles = KoDom::namedItemNS( docElement, ooNS::office,
"font-decls" );
602 if ( !fontStyles.isNull() )
604 kdDebug(30518) <<
"Starting reading in font-decl..." << endl;
606 insertStyles( fontStyles.toElement(), doc );
609 kdDebug(30518) <<
"No items found" << endl;
611 kdDebug(30518) <<
"Starting reading in office:automatic-styles" << endl;
613 TQDomNode autoStyles = KoDom::namedItemNS( docElement, ooNS::office,
"automatic-styles" );
614 if ( !autoStyles.isNull() )
616 insertStyles( autoStyles.toElement(), doc );
619 kdDebug(30518) <<
"No items found" << endl;
622 kdDebug(30518) <<
"Reading in master styles" << endl;
624 TQDomNode masterStyles = KoDom::namedItemNS( docElement, ooNS::office,
"master-styles" );
626 if ( !masterStyles.isNull() )
630 forEachElement( master, masterStyles )
632 if ( master.localName() ==
"master-page" && master.namespaceURI() == ooNS::style )
634 TQString name = master.attributeNS( ooNS::style,
"name", TQString() );
635 kdDebug(30518) <<
"Master style: '" << name <<
"' loaded " << endl;
636 m_masterPages.insert( name,
new TQDomElement( master ) );
638 kdWarning(30518) <<
"Unknown tag " << master.tagName() <<
" in office:master-styles" << endl;
643 kdDebug(30518) <<
"Starting reading in office:styles" << endl;
645 TQDomNode fixedStyles = KoDom::namedItemNS( docElement, ooNS::office,
"styles" );
647 if ( !fixedStyles.isNull() )
648 insertStyles( fixedStyles.toElement(), doc );
650 kdDebug(30518) <<
"Styles read in." << endl;
656void OoWriterImport::insertStyles(
const TQDomElement& styles, TQDomDocument& doc )
660 forEachElement( e, styles )
662 const TQString localName = e.localName();
663 const TQString ns = e.namespaceURI();
665 const TQString name = e.attributeNS( ooNS::style,
"name", TQString() );
666 if ( ns == ooNS::style && (
668 || localName ==
"page-master"
669 || localName ==
"font-decl" ) )
671 TQDomElement* ep =
new TQDomElement( e );
672 m_styles.insert( name, ep );
673 kdDebug(30518) <<
"Style: '" << name <<
"' loaded " << endl;
674 }
else if ( localName ==
"default-style" && ns == ooNS::style ) {
676 }
else if ( localName ==
"list-style" && ns == ooNS::text ) {
677 TQDomElement* ep =
new TQDomElement( e );
678 m_listStyles.insert( name, ep );
679 kdDebug(30518) <<
"List style: '" << name <<
"' loaded " << endl;
680 }
else if ( localName ==
"outline-style" && ns == ooNS::text ) {
682 }
else if ( localName ==
"footnotes-configuration" && ns == ooNS::text ) {
683 importFootnotesConfiguration( doc, e,
false );
684 }
else if ( localName ==
"endnotes-configuration" && ns == ooNS::text ) {
685 importFootnotesConfiguration( doc, e,
true );
686 }
else if ( localName ==
"linenumbering-configuration" && ns == ooNS::text ) {
688 }
else if ( localName ==
"number-style" && ns == ooNS::number ) {
690 }
else if ( ( localName ==
"date-style"
691 || localName ==
"time-style" ) && ns == ooNS::number ) {
692 importDateTimeStyle( e );
694 kdWarning(30518) <<
"Unknown element " << localName <<
" in styles" << endl;
703void OoWriterImport::importDateTimeStyle(
const TQDomElement& parent )
707 forEachElement( e, parent )
709 const TQString ns = e.namespaceURI();
710 if ( ns != ooNS::number )
712 const TQString localName = e.localName();
713 const TQString numberStyle = e.attributeNS( ooNS::number,
"style", TQString() );
714 const bool shortForm = numberStyle ==
"short" || numberStyle.isEmpty();
715 if ( localName ==
"day" ) {
716 format += shortForm ?
"d" :
"dd";
717 }
else if ( localName ==
"day-of-week" ) {
718 format += shortForm ?
"ddd" :
"dddd";
719 }
else if ( localName ==
"month" ) {
721 if ( e.attributeNS( ooNS::number,
"textual", TQString() ) ==
"true" ) {
722 format += shortForm ?
"MMM" :
"MMMM";
724 format += shortForm ?
"M" :
"MM";
726 }
else if ( localName ==
"year" ) {
727 format += shortForm ?
"yy" :
"yyyy";
728 }
else if ( localName ==
"week-of-year" || localName ==
"quarter") {
730 }
else if ( localName ==
"hours" ) {
731 format += shortForm ?
"h" :
"hh";
732 }
else if ( localName ==
"minutes" ) {
733 format += shortForm ?
"m" :
"mm";
734 }
else if ( localName ==
"seconds" ) {
735 format += shortForm ?
"s" :
"ss";
736 }
else if ( localName ==
"am-pm" ) {
738 }
else if ( localName ==
"text" ) {
751 forEachElement( e, parent )
753 const TQString ns = e.namespaceURI();
754 if ( ns != ooNS::number )
756 TQString localName = e.tagName();
757 const TQString numberStyle = e.attributeNS( ooNS::number,
"style", TQString() );
758 const bool shortForm = numberStyle ==
"short" || numberStyle.isEmpty();
759 if ( localName ==
"day" ) {
760 kdeFormat += shortForm ?
"%e" :
"%d";
761 }
else if ( localName ==
"day-of-week" ) {
762 kdeFormat += shortForm ?
"%a" :
"%A";
763 }
else if ( localName ==
"month" ) {
765 if ( e.attributeNS( ooNS::number,
"textual", TQString() ) ==
"true" ) {
766 kdeFormat += shortForm ?
"%b" :
"%B";
768 kdeFormat += shortForm ?
"%n" :
"%m";
770 }
else if ( localName ==
"year" ) {
771 kdeFormat += shortForm ?
"%y" :
"%Y";
772 }
else if ( localName ==
"week-of-year" || localName ==
"quarter") {
774 }
else if ( localName ==
"hours" ) {
775 kdeFormat += shortForm ?
"%k" :
"%H";
776 }
else if ( localName ==
"minutes" ) {
777 kdeFormat += shortForm ?
"%M" :
"%M";
778 }
else if ( localName ==
"seconds" ) {
779 kdeFormat += shortForm ?
"%S" :
"%S";
780 }
else if ( localName ==
"am-pm" ) {
782 }
else if ( localName ==
"text" ) {
783 kdeFormat += e.text();
788 TQString styleName = parent.attributeNS( ooNS::style,
"name", TQString() );
789 kdDebug(30518) <<
"datetime style: " << styleName <<
" tqt format=" << format << endl;
790 m_dateTimeFormats.insert( styleName, format );
793void OoWriterImport::fillStyleStack(
const TQDomElement&
object,
const char* nsURI,
const TQString& attrName )
797 if (
object.hasAttributeNS( nsURI, attrName ) ) {
798 const TQString styleName =
object.attributeNS( nsURI, attrName, TQString() );
799 const TQDomElement* style = m_styles[styleName];
803 kdWarning(30518) <<
"fillStyleStack: no style named " << styleName <<
" found." << endl;
807void OoWriterImport::addStyles(
const TQDomElement* style )
810 if ( !style )
return;
812 if ( style->hasAttributeNS( ooNS::style,
"parent-style-name" ) ) {
813 const TQString parentStyleName = style->attributeNS( ooNS::style,
"parent-style-name", TQString() );
814 TQDomElement* parentStyle = m_styles[ parentStyleName ];
816 addStyles( parentStyle );
818 kdWarning(30518) <<
"Parent style not found: " << parentStyleName << endl;
820 else if ( !m_defaultStyle.isNull() )
821 m_styleStack.push( m_defaultStyle );
824 m_styleStack.push( *style );
827void OoWriterImport::applyListStyle( TQDomDocument& doc, TQDomElement& layoutElement,
const TQDomElement& paragraph )
830 if ( m_listStyleStack.hasListStyle() && m_nextItemIsListItem ) {
831 bool heading = paragraph.localName() ==
"h";
832 m_nextItemIsListItem =
false;
833 int level = heading ? paragraph.attributeNS( ooNS::text,
"level", TQString() ).toInt() : m_listStyleStack.level();
834 writeCounter( doc, layoutElement, heading, level, m_insideOrderedList );
838void OoWriterImport::writeCounter( TQDomDocument& doc, TQDomElement& layoutElement,
bool heading,
int level,
bool ordered )
840 const TQDomElement listStyle = m_listStyleStack.currentListStyle();
842 TQDomElement counter = doc.createElement(
"COUNTER" );
843 counter.setAttribute(
"numberingtype", heading ? 1 : 0 );
844 counter.setAttribute(
"depth", level - 1 );
849 if ( ordered || heading ) {
850 counter.setAttribute(
"type", Conversion::importCounterType( listStyle.attributeNS( ooNS::style,
"num-format", TQString() ) ) );
851 counter.setAttribute(
"lefttext", listStyle.attributeNS( ooNS::style,
"num-prefix", TQString() ) );
852 counter.setAttribute(
"righttext", listStyle.attributeNS( ooNS::style,
"num-suffix", TQString() ) );
853 TQString dl = listStyle.attributeNS( ooNS::text,
"display-levels", TQString() );
856 counter.setAttribute(
"display-levels", dl );
857 if ( m_restartNumbering != -1 ) {
858 counter.setAttribute(
"start", m_restartNumbering );
859 counter.setAttribute(
"restart",
"true" );
862 counter.setAttribute(
"start", listStyle.attributeNS( ooNS::text,
"start-value", TQString() ) );
866 counter.setAttribute(
"type", 6 );
867 TQString bulletChar = listStyle.attributeNS( ooNS::text,
"bullet-char", TQString() );
868 if ( !bulletChar.isEmpty() ) {
870 counter.setAttribute(
"bullet", bulletChar[0].unicode() );
871 kdDebug(30518) <<
"bullet code " << bulletChar[0].unicode() << endl;
872 TQString fontName = listStyleProperties.attributeNS( ooNS::style,
"font-name", TQString() );
873 counter.setAttribute(
"bulletfont", fontName );
876 switch( bulletChar[0].unicode() ) {
878 counter.setAttribute(
"type", 10 );
881 counter.setAttribute(
"type", 10 );
884 counter.setAttribute(
"type", 10 );
887 counter.setAttribute(
"type", 9 );
891 counter.setAttribute(
"bullet", 206 );
892 counter.setAttribute(
"bulletfont",
"symbol" );
895 counter.setAttribute(
"bullet", 212 );
896 counter.setAttribute(
"bulletfont",
"symbol" );
899 counter.setAttribute(
"bullet", 246 );
900 counter.setAttribute(
"bulletfont",
"symbol" );
903 counter.setAttribute(
"type", 8 );
907 counter.setAttribute(
"type", 10 );
911 layoutElement.appendChild(counter);
914static TQDomElement findListLevelStyle( TQDomElement& fullListStyle,
int level )
916 TQDomElement listLevelItem;
917 forEachElement( listLevelItem, fullListStyle )
919 if ( listLevelItem.attributeNS( ooNS::text,
"level", TQString() ).toInt() == level )
920 return listLevelItem;
922 return TQDomElement();
925bool OoWriterImport::pushListLevelStyle(
const TQString& listStyleName,
int level )
927 TQDomElement* fullListStyle = m_listStyles[listStyleName];
928 if ( !fullListStyle ) {
929 kdWarning(30518) <<
"List style " << listStyleName <<
" not found!" << endl;
933 return pushListLevelStyle( listStyleName, *fullListStyle, level );
936bool OoWriterImport::pushListLevelStyle(
const TQString& listStyleName,
937 TQDomElement& fullListStyle,
int level )
941 TQDomElement listLevelStyle;
942 while ( i > 0 && listLevelStyle.isNull() ) {
943 listLevelStyle = findListLevelStyle( fullListStyle, i );
946 if ( listLevelStyle.isNull() ) {
947 kdWarning(30518) <<
"List level style for level " << level <<
" in list style " << listStyleName <<
" not found!" << endl;
950 kdDebug(30518) <<
"Pushing list-level-style from list-style " << listStyleName <<
" level " << level << endl;
951 m_listStyleStack.push( listLevelStyle );
955void OoWriterImport::parseList( TQDomDocument& doc,
const TQDomElement& list, TQDomElement& currentFramesetElement )
959 m_insideOrderedList = ( list.localName() ==
"ordered-list" );
960 TQString oldListStyleName = m_currentListStyleName;
961 if ( list.hasAttributeNS( ooNS::text,
"style-name" ) )
962 m_currentListStyleName = list.attributeNS( ooNS::text,
"style-name", TQString() );
963 bool listOK = !m_currentListStyleName.isEmpty();
964 const int level = m_listStyleStack.level() + 1;
967 listOK = pushListLevelStyle( m_currentListStyleName, level );
970 TQDomElement listItem;
971 forEachElement( listItem, list )
974 m_nextItemIsListItem = ( listItem.localName() !=
"list-header" );
975 m_restartNumbering = -1;
976 if ( listItem.hasAttributeNS( ooNS::text,
"start-value" ) )
977 m_restartNumbering = listItem.attributeNS( ooNS::text,
"start-value", TQString() ).toInt();
979 parseBodyOrSimilar( doc, listItem, currentFramesetElement );
980 m_restartNumbering = -1;
983 m_listStyleStack.pop();
984 m_currentListStyleName = oldListStyleName;
987static int numberOfParagraphs(
const TQDomElement& frameset )
989 const TQDomNodeList children = frameset.childNodes();
990 const TQString paragStr =
"PARAGRAPH";
992 for (
unsigned int i = 0 ; i < children.length() ; ++i ) {
993 if ( children.item( i ).toElement().tagName() == paragStr )
999void OoWriterImport::parseSpanOrSimilar( TQDomDocument& doc,
const TQDomElement& parent,
1000 TQDomElement& outputParagraph, TQDomElement& outputFormats, TQString& paragraphText, uint& pos)
1004 for( TQDomNode node ( parent.firstChild() ); !node.isNull(); node = node.nextSibling() )
1006 TQDomElement ts ( node.toElement() );
1008 const TQString localName( ts.localName() );
1009 const TQString ns = ts.namespaceURI();
1010 const bool isTextNS = ns == ooNS::text;
1011 TQDomText t ( node.toText() );
1013 bool shouldWriteFormat=
false;
1016 if ( isTextNS && localName ==
"span" )
1018 m_styleStack.save();
1019 fillStyleStack( ts, ooNS::text,
"style-name" );
1020 parseSpanOrSimilar( doc, ts, outputParagraph, outputFormats, paragraphText, pos);
1021 m_styleStack.restore();
1023 else if ( isTextNS && localName ==
"s" )
1025 textData = OoUtils::expandWhitespace(ts);
1026 shouldWriteFormat=
true;
1028 else if ( isTextNS && localName ==
"tab-stop" )
1034 shouldWriteFormat=
true;
1036 else if ( isTextNS && localName ==
"line-break" )
1039 shouldWriteFormat=
true;
1041 else if ( isTextNS &&
1042 ( localName ==
"footnote" || localName ==
"endnote" ) )
1045 importFootnote( doc, ts, outputFormats, pos, localName );
1047 else if ( localName ==
"image" && ns == ooNS::draw )
1050 TQString frameName = appendPicture(doc, ts);
1051 anchorFrameset( doc, outputFormats, pos, frameName );
1053 else if ( localName ==
"text-box" && ns == ooNS::draw )
1056 TQString frameName = appendTextBox(doc, ts);
1057 anchorFrameset( doc, outputFormats, pos, frameName );
1059 else if ( isTextNS && localName ==
"a" )
1061 m_styleStack.save();
1062 TQString href( ts.attributeNS( ooNS::xlink,
"href", TQString()) );
1063 if ( href.startsWith(
"#") )
1067 parseSpanOrSimilar( doc, ts, outputParagraph, outputFormats, paragraphText, pos);
1073 TQDomElement fakeParagraph, fakeFormats;
1076 parseSpanOrSimilar( doc, ts, fakeParagraph, fakeFormats, text, fakePos);
1078 TQDomElement linkElement (doc.createElement(
"LINK"));
1079 linkElement.setAttribute(
"hrefName",ts.attributeNS( ooNS::xlink,
"href", TQString()));
1080 linkElement.setAttribute(
"linkName",text);
1081 appendKWordVariable(doc, outputFormats, ts, pos,
"STRING", 9, linkElement);
1083 m_styleStack.restore();
1085 else if ( isTextNS &&
1086 (localName ==
"date"
1087 || localName ==
"print-time"
1088 || localName ==
"print-date"
1089 || localName ==
"creation-time"
1090 || localName ==
"creation-date"
1091 || localName ==
"modification-time"
1092 || localName ==
"modification-date"
1093 || localName ==
"time"
1094 || localName ==
"page-number"
1095 || localName ==
"chapter"
1096 || localName ==
"file-name"
1097 || localName ==
"author-name"
1098 || localName ==
"author-initials"
1099 || localName ==
"subject"
1100 || localName ==
"title"
1101 || localName ==
"description"
1102 || localName ==
"variable-set"
1103 || localName ==
"page-variable-get"
1104 || localName ==
"user-defined"
1105 || localName.startsWith(
"sender-")
1110 appendField(doc, outputFormats, ts, pos);
1112 else if ( isTextNS && localName ==
"bookmark" )
1116 Q_ASSERT( !m_currentFrameset.isNull() );
1117 appendBookmark( doc, numberOfParagraphs( m_currentFrameset ),
1118 pos, ts.attributeNS( ooNS::text,
"name", TQString() ) );
1120 else if ( isTextNS && localName ==
"bookmark-start" ) {
1121 m_bookmarkStarts.insert( ts.attributeNS( ooNS::text,
"name", TQString() ),
1122 BookmarkStart( m_currentFrameset.attribute(
"name" ),
1123 numberOfParagraphs( m_currentFrameset ),
1126 else if ( isTextNS && localName ==
"bookmark-end" ) {
1127 TQString bkName = ts.attributeNS( ooNS::text,
"name", TQString() );
1128 BookmarkStartsMap::iterator it = m_bookmarkStarts.find( bkName );
1129 if ( it == m_bookmarkStarts.end() ) {
1131 appendBookmark( doc, numberOfParagraphs( m_currentFrameset ),
1132 pos, ts.attributeNS( ooNS::text,
"name", TQString() ) );
1134 if ( (*it).frameSetName != m_currentFrameset.attribute(
"name" ) ) {
1136 kdWarning(30518) <<
"Cross-frameset bookmark! Not supported." << endl;
1138 appendBookmark( doc, (*it).paragId, (*it).pos,
1139 numberOfParagraphs( m_currentFrameset ), pos, it.key() );
1141 m_bookmarkStarts.remove( it );
1144 else if ( t.isNull() )
1146 kdWarning(30518) <<
"Ignoring tag " << ts.tagName() << endl;
1151 textData = t.data();
1152 shouldWriteFormat=
true;
1155 paragraphText += textData;
1156 const uint length = textData.length();
1158 if (shouldWriteFormat)
1160 writeFormat( doc, outputFormats, 1 , pos, length );
1167TQDomElement OoWriterImport::parseParagraph( TQDomDocument& doc,
const TQDomElement& paragraph )
1169 TQDomElement p = doc.createElement(
"PARAGRAPH" );
1171 TQDomElement formats = doc.createElement(
"FORMATS" );
1173 TQString paragraphText;
1177 parseSpanOrSimilar( doc, paragraph, p, formats, paragraphText, pos);
1179 TQDomElement text = doc.createElement(
"TEXT" );
1180 text.appendChild( doc.createTextNode( paragraphText ) );
1181 text.setAttribute(
"xml:space",
"preserve" );
1182 p.appendChild( text );
1185 p.appendChild( formats );
1186 TQDomElement layoutElement = doc.createElement(
"LAYOUT" );
1187 p.appendChild( layoutElement );
1190 TQString styleName = m_styleStack.userStyleName(
"paragraph");
1191 if ( !styleName.isEmpty() )
1193 TQDomElement nameElement = doc.createElement(
"NAME");
1194 nameElement.setAttribute(
"value", kWordStyleName(styleName) );
1195 layoutElement.appendChild(nameElement);
1198 writeLayout( doc, layoutElement );
1199 writeFormat( doc, layoutElement, 1, 0, 0 );
1201 applyListStyle( doc, layoutElement, paragraph );
1203 TQDomElement* paragraphStyle = m_styles[paragraph.attributeNS( ooNS::text,
"style-name", TQString() )];
1204 TQString masterPageName = paragraphStyle ? paragraphStyle->attributeNS( ooNS::style,
"master-page-name", TQString() ) : TQString();
1205 if ( masterPageName.isEmpty() )
1206 masterPageName =
"Standard";
1207 if ( masterPageName != m_currentMasterPage )
1212 if ( m_currentMasterPage.isEmpty() ) {
1213 m_currentMasterPage = masterPageName;
1214 writePageLayout( doc, masterPageName );
1218 m_currentMasterPage = masterPageName;
1219 TQDomElement pageBreakElem = layoutElement.namedItem(
"PAGEBREAKING" ).toElement();
1220 if ( !pageBreakElem.isNull() ) {
1221 pageBreakElem = doc.createElement(
"PAGEBREAKING" );
1222 layoutElement.appendChild( pageBreakElem );
1224 pageBreakElem.setAttribute(
"hardFrameBreak",
"true" );
1232void OoWriterImport::writeFormat( TQDomDocument& doc, TQDomElement& formats,
int id,
int pos,
int length )
1235 TQDomElement format( doc.createElement(
"FORMAT" ) );
1236 format.setAttribute(
"id",
id );
1237 format.setAttribute(
"pos", pos );
1238 format.setAttribute(
"len", length );
1250 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"color" ) ) {
1251 TQColor color( m_styleStack.attributeNS( ooNS::fo,
"color" ) );
1252 TQDomElement colorElem( doc.createElement(
"COLOR" ) );
1253 colorElem.setAttribute(
"red", color.red() );
1254 colorElem.setAttribute(
"blue", color.blue() );
1255 colorElem.setAttribute(
"green", color.green() );
1256 format.appendChild( colorElem );
1258 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-family" )
1259 || m_styleStack.hasAttributeNS( ooNS::style,
"font-name") )
1262 TQString fontName = m_styleStack.attributeNS( ooNS::fo,
"font-family" ).remove(
"'" );
1263 if (fontName.isEmpty())
1267 fontName = m_styleStack.attributeNS( ooNS::style,
"font-name" ).remove(
"'" );
1271 if ( fontName ==
"Thorndale" )
1272 fontName =
"Times New Roman";
1274 fontName.remove(TQRegExp(
"\\sCE$"));
1276 TQDomElement fontElem( doc.createElement(
"FONT" ) );
1277 fontElem.setAttribute(
"name", fontName );
1278 format.appendChild( fontElem );
1280 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-size" ) ) {
1281 double pointSize = m_styleStack.fontSize();
1283 TQDomElement fontSize( doc.createElement(
"SIZE" ) );
1284 fontSize.setAttribute(
"value", tqRound(pointSize) );
1285 format.appendChild( fontSize );
1287 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-weight" ) ) {
1288 TQDomElement weightElem( doc.createElement(
"WEIGHT" ) );
1289 TQString fontWeight = m_styleStack.attributeNS( ooNS::fo,
"font-weight" );
1290 int boldness = fontWeight.toInt();
1291 if ( fontWeight ==
"bold" )
1293 else if ( boldness == 0 )
1295 weightElem.setAttribute(
"value", boldness );
1296 format.appendChild( weightElem );
1299 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-style" ) )
1300 if ( m_styleStack.attributeNS( ooNS::fo,
"font-style" ) ==
"italic" ||
1301 m_styleStack.attributeNS( ooNS::fo,
"font-style" ) ==
"oblique" )
1303 TQDomElement italic = doc.createElement(
"ITALIC" );
1304 italic.setAttribute(
"value", 1 );
1305 format.appendChild( italic );
1308 bool wordByWord = (m_styleStack.hasAttributeNS( ooNS::fo,
"score-spaces"))
1309 && (m_styleStack.attributeNS( ooNS::fo,
"score-spaces") ==
"false");
1310 if( m_styleStack.hasAttributeNS( ooNS::style,
"text-crossing-out" ))
1312 TQString strikeOutType = m_styleStack.attributeNS( ooNS::style,
"text-crossing-out" );
1313 TQDomElement strikeOut = doc.createElement(
"STRIKEOUT" );
1314 if( strikeOutType ==
"double-line")
1316 strikeOut.setAttribute(
"value",
"double");
1317 strikeOut.setAttribute(
"styleline",
"solid");
1319 else if( strikeOutType ==
"single-line")
1321 strikeOut.setAttribute(
"value",
"single");
1322 strikeOut.setAttribute(
"styleline",
"solid");
1324 else if( strikeOutType ==
"thick-line")
1326 strikeOut.setAttribute(
"value",
"single-bold");
1327 strikeOut.setAttribute(
"styleline",
"solid");
1330 strikeOut.setAttribute(
"wordbyword", 1);
1333 format.appendChild( strikeOut );
1335 if( m_styleStack.hasAttributeNS( ooNS::style,
"text-position"))
1337 TQDomElement vertAlign = doc.createElement(
"VERTALIGN" );
1338 TQString text_position = m_styleStack.attributeNS( ooNS::style,
"text-position");
1340 TQString relativetextsize;
1341 OoUtils::importTextPosition( text_position, value, relativetextsize );
1342 vertAlign.setAttribute(
"value", value );
1343 if ( !relativetextsize.isEmpty() )
1344 vertAlign.setAttribute(
"relativetextsize", relativetextsize );
1345 format.appendChild( vertAlign );
1347 if ( m_styleStack.hasAttributeNS( ooNS::style,
"text-underline" ) )
1351 OoUtils::importUnderline( m_styleStack.attributeNS( ooNS::style,
"text-underline" ),
1352 underline, styleline );
1353 TQDomElement underLineElem = doc.createElement(
"UNDERLINE" );
1354 underLineElem.setAttribute(
"value", underline );
1355 underLineElem.setAttribute(
"styleline", styleline );
1357 TQString underLineColor = m_styleStack.attributeNS( ooNS::style,
"text-underline-color" );
1358 if ( !underLineColor.isEmpty() && underLineColor !=
"font-color" )
1359 underLineElem.setAttribute(
"underlinecolor", underLineColor);
1361 underLineElem.setAttribute(
"wordbyword", 1);
1362 format.appendChild( underLineElem );
1365 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-variant" )
1366 || m_styleStack.hasAttributeNS( ooNS::fo,
"text-transform" ) )
1368 TQDomElement fontAttrib( doc.createElement(
"FONTATTRIBUTE" ) );
1369 bool smallCaps = m_styleStack.attributeNS( ooNS::fo,
"font-variant" ) ==
"small-caps";
1372 fontAttrib.setAttribute(
"value",
"smallcaps" );
1377 fontAttrib.setAttribute(
"value", m_styleStack.attributeNS( ooNS::fo,
"text-transform" ) );
1379 format.appendChild( fontAttrib );
1382 if (m_styleStack.hasAttributeNS( ooNS::fo,
"language"))
1384 TQDomElement lang = doc.createElement(
"LANGUAGE");
1385 TQString tmp = m_styleStack.attributeNS( ooNS::fo,
"language");
1387 lang.setAttribute(
"value",
"en_US");
1389 lang.setAttribute(
"value", tmp);
1390 format.appendChild(lang);
1393 if (m_styleStack.hasAttributeNS( ooNS::style,
"text-background-color"))
1395 TQDomElement bgCol = doc.createElement(
"TEXTBACKGROUNDCOLOR");
1396 TQColor tmp = m_styleStack.attributeNS( ooNS::style,
"text-background-color");
1397 if (tmp !=
"transparent")
1399 bgCol.setAttribute(
"red", tmp.red());
1400 bgCol.setAttribute(
"green", tmp.green());
1401 bgCol.setAttribute(
"blue", tmp.blue());
1402 format.appendChild(bgCol);
1406 if (m_styleStack.hasAttributeNS( ooNS::fo,
"text-shadow"))
1408 TQDomElement shadow = doc.createElement(
"SHADOW");
1409 TQString css = m_styleStack.attributeNS( ooNS::fo,
"text-shadow");
1411 TQStringList tokens = TQStringList::split(
' ', css);
1412 if ( !tokens.isEmpty() ) {
1413 TQColor col( tokens.first() );
1414 if ( !col.isValid() && tokens.count() > 1 ) {
1415 col.setNamedColor( tokens.last() );
1417 if ( !col.isValid() )
1420 shadow.setAttribute(
"text-shadow", css);
1421 format.appendChild(shadow);
1447 if ( format.hasChildNodes() || !length )
1448 formats.appendChild( format );
1451void OoWriterImport::writeLayout( TQDomDocument& doc, TQDomElement& layoutElement )
1453 Q_ASSERT( layoutElement.ownerDocument() == doc );
1456 TQDomElement flowElement = doc.createElement(
"FLOW");
1464 if ( m_styleStack.attributeNS( ooNS::style,
"text-auto-align" ) ==
"true" )
1465 flowElement.setAttribute(
"align",
"auto" );
1468 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"text-align" ) )
1469 flowElement.setAttribute(
"align", Conversion::importAlignment( m_styleStack.attributeNS( ooNS::fo,
"text-align" ) ) );
1471 flowElement.setAttribute(
"align",
"auto" );
1473 layoutElement.appendChild( flowElement );
1475 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"writing-mode" ) )
1478 TQString writingMode = m_styleStack.attributeNS( ooNS::fo,
"writing-mode" );
1479 flowElement.setAttribute(
"dir", writingMode==
"rl-tb" || writingMode==
"rl" ?
"R" :
"L" );
1483 OoUtils::importIndents( layoutElement, m_styleStack );
1486 OoUtils::importTopBottomMargin( layoutElement, m_styleStack );
1489 OoUtils::importLineSpacing( layoutElement, m_styleStack );
1492 OoUtils::importTabulators( layoutElement, m_styleStack );
1495 OoUtils::importBorders( layoutElement, m_styleStack );
1498 if( m_styleStack.hasAttributeNS( ooNS::fo,
"break-before") ||
1499 m_styleStack.hasAttributeNS( ooNS::fo,
"break-after") ||
1500 m_styleStack.hasAttributeNS( ooNS::style,
"break-inside") ||
1501 m_styleStack.hasAttributeNS( ooNS::style,
"keep-with-next") ||
1502 m_styleStack.hasAttributeNS( ooNS::fo,
"keep-with-next") )
1504 TQDomElement pageBreak = doc.createElement(
"PAGEBREAKING" );
1505 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"break-before") ) {
1506 bool breakBefore = m_styleStack.attributeNS( ooNS::fo,
"break-before" ) !=
"auto";
1508 pageBreak.setAttribute(
"hardFrameBreak", breakBefore ?
"true" :
"false");
1510 else if ( m_styleStack.hasAttributeNS( ooNS::fo,
"break-after") ) {
1511 bool breakAfter = m_styleStack.attributeNS( ooNS::fo,
"break-after" ) !=
"auto";
1513 pageBreak.setAttribute(
"hardFrameBreakAfter", breakAfter ?
"true" :
"false");
1516 if ( m_styleStack.hasAttributeNS( ooNS::style,
"break-inside" ) ) {
1517 bool breakInside = m_styleStack.attributeNS( ooNS::style,
"break-inside" ) ==
"true";
1518 pageBreak.setAttribute(
"linesTogether", breakInside ?
"false" :
"true");
1520 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"keep-with-next" ) ) {
1522 TQString val = m_styleStack.attributeNS( ooNS::fo,
"keep-with-next" );
1523 pageBreak.setAttribute(
"keepWithNext", ( val ==
"true" || val ==
"always" ) ?
"true" :
"false");
1525 layoutElement.appendChild( pageBreak );
1568void OoWriterImport::importFrame( TQDomElement& frameElementOut,
const TQDomElement&
object,
bool isText )
1571 if (
object.hasAttributeNS( ooNS::svg,
"width" ) ) {
1573 width = KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"width", TQString() ) );
1574 }
else if (
object.hasAttributeNS( ooNS::fo,
"min-width" ) ) {
1576 width = KoUnit::parseValue(
object.attributeNS( ooNS::fo,
"min-width", TQString() ) );
1578 kdWarning(30518) <<
"Error in text-box: neither width nor min-width specified!" << endl;
1580 double height = 100;
1581 bool hasMinHeight =
false;
1582 if (
object.hasAttributeNS( ooNS::svg,
"height" ) ) {
1584 height = KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"height", TQString() ) );
1585 }
else if (
object.hasAttributeNS( ooNS::fo,
"min-height" ) ) {
1586 height = KoUnit::parseValue(
object.attributeNS( ooNS::fo,
"min-height", TQString() ) );
1587 hasMinHeight =
true;
1589 kdWarning(30518) <<
"Error in text-box: neither height nor min-height specified!" << endl;
1604 KoRect frameRect( KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"x", TQString() ) ),
1605 KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"y", TQString() ) ),
1608 frameElementOut.setAttribute(
"left", frameRect.left() );
1609 frameElementOut.setAttribute(
"right", frameRect.right() );
1610 frameElementOut.setAttribute(
"top", frameRect.top() );
1611 frameElementOut.setAttribute(
"bottom", frameRect.bottom() );
1613 frameElementOut.setAttribute(
"min-height", height );
1614 frameElementOut.setAttribute(
"z-index",
object.attributeNS( ooNS::draw,
"z-index", TQString() ) );
1615 TQPair<int, TQString> attribs = Conversion::importWrapping( m_styleStack.attributeNS( ooNS::style,
"wrap" ) );
1616 frameElementOut.setAttribute(
"runaround", attribs.first );
1617 if ( !attribs.second.isEmpty() )
1618 frameElementOut.setAttribute(
"runaroundSide", attribs.second );
1624 int overflowBehavior;
1625 if ( m_styleStack.hasAttributeNS( ooNS::style,
"overflow-behavior" ) ) {
1626 overflowBehavior = Conversion::importOverflowBehavior( m_styleStack.attributeNS( ooNS::style,
"overflow-behavior" ) );
1629 overflowBehavior = hasMinHeight ? 0 : 2 ;
1632 frameElementOut.setAttribute(
"autoCreateNewFrame", overflowBehavior);
1637 importCommonFrameProperties( frameElementOut );
1640void OoWriterImport::importCommonFrameProperties( TQDomElement& frameElementOut )
1643 double paddingLeft = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding",
"left" ) );
1644 double paddingRight = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding",
"right" ) );
1645 double paddingTop = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding",
"top" ) );
1646 double paddingBottom = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding",
"bottom" ) );
1648 if ( paddingLeft != 0 )
1649 frameElementOut.setAttribute(
"bleftpt", paddingLeft );
1650 if ( paddingRight != 0 )
1651 frameElementOut.setAttribute(
"brightpt", paddingRight );
1652 if ( paddingTop != 0 )
1653 frameElementOut.setAttribute(
"btoppt", paddingTop );
1654 if ( paddingBottom != 0 )
1655 frameElementOut.setAttribute(
"bbottompt", paddingBottom );
1658 bool transparent =
false;
1660 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"background-color" ) ) {
1661 TQString color = m_styleStack.attributeNS( ooNS::fo,
"background-color" );
1662 if ( color ==
"transparent" )
1665 bgColor.setNamedColor( color );
1668 frameElementOut.setAttribute(
"bkStyle", 0 );
1669 else if ( bgColor.isValid() ) {
1672 frameElementOut.setAttribute(
"bkStyle", 1 );
1673 frameElementOut.setAttribute(
"bkRed", bgColor.red() );
1674 frameElementOut.setAttribute(
"bkBlue", bgColor.blue() );
1675 frameElementOut.setAttribute(
"bkGreen", bgColor.green() );
1685 if (OoUtils::parseBorder(m_styleStack.attributeNS( ooNS::fo,
"border",
"left"), &width, &style, &color)) {
1686 frameElementOut.setAttribute(
"lWidth", width );
1687 if ( color.isValid() ) {
1688 frameElementOut.setAttribute(
"lRed", color.red() );
1689 frameElementOut.setAttribute(
"lBlue", color.blue() );
1690 frameElementOut.setAttribute(
"lGreen", color.green() );
1692 frameElementOut.setAttribute(
"lStyle", style );
1694 if (OoUtils::parseBorder(m_styleStack.attributeNS( ooNS::fo,
"border",
"right"), &width, &style, &color)) {
1695 frameElementOut.setAttribute(
"rWidth", width );
1696 if ( color.isValid() ) {
1697 frameElementOut.setAttribute(
"rRed", color.red() );
1698 frameElementOut.setAttribute(
"rBlue", color.blue() );
1699 frameElementOut.setAttribute(
"rGreen", color.green() );
1701 frameElementOut.setAttribute(
"rStyle", style );
1703 if (OoUtils::parseBorder(m_styleStack.attributeNS( ooNS::fo,
"border",
"top"), &width, &style, &color)) {
1704 frameElementOut.setAttribute(
"tWidth", width );
1705 if ( color.isValid() ) {
1706 frameElementOut.setAttribute(
"tRed", color.red() );
1707 frameElementOut.setAttribute(
"tBlue", color.blue() );
1708 frameElementOut.setAttribute(
"tGreen", color.green() );
1710 frameElementOut.setAttribute(
"tStyle", style );
1712 if (OoUtils::parseBorder(m_styleStack.attributeNS( ooNS::fo,
"border",
"bottom"), &width, &style, &color)) {
1713 frameElementOut.setAttribute(
"bWidth", width );
1714 if ( color.isValid() ) {
1715 frameElementOut.setAttribute(
"bRed", color.red() );
1716 frameElementOut.setAttribute(
"bBlue", color.blue() );
1717 frameElementOut.setAttribute(
"bGreen", color.green() );
1719 frameElementOut.setAttribute(
"bStyle", style );
1725TQString OoWriterImport::appendTextBox(TQDomDocument& doc,
const TQDomElement&
object)
1727 const TQString frameName (
object.attributeNS( ooNS::draw,
"name", TQString()) );
1728 kdDebug(30518) <<
"appendTextBox " << frameName << endl;
1729 m_styleStack.save();
1730 fillStyleStack(
object, ooNS::draw,
"style-name" );
1733 TQDomElement framesetElement(doc.createElement(
"FRAMESET"));
1734 framesetElement.setAttribute(
"frameType",1);
1735 framesetElement.setAttribute(
"frameInfo",0);
1736 framesetElement.setAttribute(
"visible",1);
1737 framesetElement.setAttribute(
"name",frameName);
1738 TQDomElement framesetsPluralElement (doc.documentElement().namedItem(
"FRAMESETS").toElement());
1739 framesetsPluralElement.appendChild(framesetElement);
1741 TQDomElement frameElementOut(doc.createElement(
"FRAME"));
1742 framesetElement.appendChild(frameElementOut);
1743 importFrame( frameElementOut,
object,
true );
1747 m_styleStack.restore();
1750 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"text-style-name" ) )
1751 addStyles( m_styles[m_styleStack.attributeNS( ooNS::draw,
"text-style-name" )] );
1754 parseBodyOrSimilar( doc,
object, framesetElement );
1760void OoWriterImport::importFootnote( TQDomDocument& doc,
const TQDomElement&
object, TQDomElement& formats, uint pos,
const TQString& localName )
1762 const TQString frameName(
object.attributeNS( ooNS::text,
"id", TQString()) );
1763 TQDomElement citationElem = KoDom::namedItemNS(
object, ooNS::text, (localName+
"-citation").latin1() ).toElement();
1765 bool endnote = localName ==
"endnote";
1767 TQString label = citationElem.attributeNS( ooNS::text,
"label", TQString() );
1768 bool autoNumbered = label.isEmpty();
1771 TQDomElement footnoteElem = doc.createElement(
"FOOTNOTE" );
1773 footnoteElem.setAttribute(
"value", 1 );
1775 footnoteElem.setAttribute(
"value", label );
1776 footnoteElem.setAttribute(
"notetype", endnote ?
"endnote" :
"footnote" );
1777 footnoteElem.setAttribute(
"numberingtype", autoNumbered ?
"auto" :
"manual" );
1778 footnoteElem.setAttribute(
"frameset", frameName );
1780 appendKWordVariable( doc, formats, citationElem, pos,
"STRI", 11 , footnoteElem );
1783 TQDomElement framesetElement( doc.createElement(
"FRAMESET") );
1784 framesetElement.setAttribute(
"frameType", 1 );
1785 framesetElement.setAttribute(
"frameInfo", 7 );
1786 framesetElement.setAttribute(
"name" , frameName );
1787 TQDomElement framesetsPluralElement (doc.documentElement().namedItem(
"FRAMESETS").toElement());
1788 framesetsPluralElement.appendChild(framesetElement);
1789 createInitialFrame( framesetElement, 29, 798, 567, 567+41,
true, NoFollowup );
1793 TQDomElement bodyElem = KoDom::namedItemNS(
object, ooNS::text, (localName+
"-body").latin1() ).toElement();
1794 parseBodyOrSimilar( doc, bodyElem, framesetElement );
1797TQString OoWriterImport::appendPicture(TQDomDocument& doc,
const TQDomElement&
object)
1799 const TQString frameName (
object.attributeNS( ooNS::draw,
"name", TQString()) );
1800 const TQString href (
object.attributeNS( ooNS::xlink,
"href", TQString()) );
1802 kdDebug(30518) <<
"Picture: " << frameName <<
" " << href <<
" (in OoWriterImport::appendPicture)" << endl;
1807 TQString strExtension;
1808 const int result=href.findRev(
".");
1811 strExtension=href.mid(result+1);
1813 TQString filename(href.mid(1));
1814 KoPictureKey key(filename, TQDateTime::currentDateTime(TQt::UTC));
1815 picture.setKey(key);
1820 const KArchiveEntry* entry = m_zip->directory()->entry( filename );
1823 kdWarning(30518) <<
"Picture " << filename <<
" not found!" << endl;
1826 if (entry->isDirectory())
1828 kdWarning(30518) <<
"Picture " << filename <<
" is a directory!" << endl;
1831 const KZipFileEntry* f =
static_cast<const KZipFileEntry *
>(entry);
1832 TQIODevice* io=f->device();
1833 kdDebug(30518) <<
"Picture " << filename <<
" has size " << f->size() << endl;
1837 kdWarning(30518) <<
"No TQIODevice for picture " << frameName <<
" " << href << endl;
1840 if (!picture.load(io,strExtension))
1841 kdWarning(30518) <<
"Cannot load picture: " << frameName <<
" " << href << endl;
1847 picture.setKeyAndDownloadPicture(url, 0);
1850 kdDebug(30518) <<
"Picture ready! Key: " << picture.getKey().toString() <<
" Size:" << picture.getOriginalSize() << endl;
1852 TQString strStoreName;
1853 strStoreName=
"pictures/picture";
1854 strStoreName+=TQString::number(++m_pictureNumber);
1856 strStoreName+=picture.getExtension();
1858 kdDebug(30518) <<
"Storage name: " << strStoreName << endl;
1860 KoStoreDevice* out = m_chain->storageFile( strStoreName , KoStore::Write );
1863 if (!out->open(IO_WriteOnly))
1865 kdWarning(30518) <<
"Cannot open for saving picture: " << frameName <<
" " << href << endl;
1868 if (!picture.save(out))
1869 kdWarning(30518) <<
"Cannot save picture: " << frameName <<
" " << href << endl;
1874 kdWarning(30518) <<
"Cannot store picture: " << frameName <<
" " << href << endl;
1880 TQDomElement docElement( doc.documentElement() );
1882 TQDomElement framesetsPluralElement ( docElement.namedItem(
"FRAMESETS").toElement() );
1884 TQDomElement framesetElement=doc.createElement(
"FRAMESET");
1885 framesetElement.setAttribute(
"frameType",2);
1886 framesetElement.setAttribute(
"frameInfo",0);
1887 framesetElement.setAttribute(
"visible",1);
1888 framesetElement.setAttribute(
"name",frameName);
1889 framesetsPluralElement.appendChild(framesetElement);
1891 TQDomElement frameElementOut=doc.createElement(
"FRAME");
1892 framesetElement.appendChild(frameElementOut);
1894 m_styleStack.save();
1895 fillStyleStack(
object, ooNS::draw,
"style-name" );
1896 importFrame( frameElementOut,
object,
false );
1897 m_styleStack.restore();
1899 TQDomElement element=doc.createElement(
"PICTURE");
1900 element.setAttribute(
"keepAspectRatio",
"true");
1901 framesetElement.setAttribute(
"frameType",2);
1902 framesetElement.appendChild(element);
1904 TQDomElement singleKey ( doc.createElement(
"KEY") );
1905 picture.getKey().saveAttributes(singleKey);
1906 element.appendChild(singleKey);
1908 TQDomElement picturesPluralElement ( docElement.namedItem(
"PICTURES").toElement() );
1909 if (picturesPluralElement.isNull())
1912 picturesPluralElement = doc.createElement(
"PICTURES");
1913 docElement.appendChild(picturesPluralElement);
1916 TQDomElement pluralKey ( doc.createElement(
"KEY") );
1917 picture.getKey().saveAttributes(pluralKey);
1918 pluralKey.setAttribute(
"name",strStoreName);
1919 picturesPluralElement.appendChild(pluralKey);
1923void OoWriterImport::anchorFrameset( TQDomDocument& doc, TQDomElement& formats, uint pos,
const TQString& frameSetName )
1925 TQDomElement formatElementOut=doc.createElement(
"FORMAT");
1926 formatElementOut.setAttribute(
"id",6);
1927 formatElementOut.setAttribute(
"pos",pos);
1928 formatElementOut.setAttribute(
"len",1);
1929 formats.appendChild(formatElementOut);
1931 TQDomElement anchor=doc.createElement(
"ANCHOR");
1933 anchor.setAttribute(
"type",
"frameset");
1934 anchor.setAttribute(
"instance",frameSetName);
1935 formatElementOut.appendChild(anchor);
1938void OoWriterImport::appendField(TQDomDocument& doc, TQDomElement& outputFormats, TQDomElement&
object, uint pos)
1942 const TQString localName (
object.localName());
1946 if ( localName.endsWith(
"date" ) || localName.endsWith(
"time" ) )
1948 TQString dataStyleName =
object.attributeNS( ooNS::style,
"data-style-name", TQString() );
1949 TQString dateFormat =
"locale";
1950 DataFormatsMap::const_iterator it = m_dateTimeFormats.find( dataStyleName );
1951 if ( it != m_dateTimeFormats.end() )
1954 if ( localName ==
"date" )
1958 TQDateTime dt(TQDate::fromString(
object.attributeNS( ooNS::text,
"date-value", TQString()), TQt::ISODate));
1960 bool fixed = (
object.hasAttributeNS( ooNS::text,
"fixed") &&
object.attributeNS( ooNS::text,
"fixed", TQString())==
"true");
1963 dt = TQDateTime::currentDateTime();
1966 const TQDate date(dt.date());
1967 const TQTime time(dt.time());
1971 TQDomElement dateElement ( doc.createElement(
"DATE") );
1972 dateElement.setAttribute(
"fix", fixed ? 1 : 0);
1973 dateElement.setAttribute(
"subtype", subtype);
1974 dateElement.setAttribute(
"day", date.day());
1975 dateElement.setAttribute(
"month", date.month());
1976 dateElement.setAttribute(
"year", date.year());
1977 dateElement.setAttribute(
"hour", time.hour());
1978 dateElement.setAttribute(
"minute", time.minute());
1979 dateElement.setAttribute(
"second", time.second());
1980 if (
object.hasAttributeNS( ooNS::text,
"date-adjust"))
1981 dateElement.setAttribute(
"correct",
object.attributeNS( ooNS::text,
"date-adjust", TQString()));
1982 appendKWordVariable(doc, outputFormats,
object, pos,
"DATE" + dateFormat, 0, dateElement);
1984 else if (localName ==
"time")
1987 TQDateTime dt(TQDateTime::fromString(
object.attributeNS( ooNS::text,
"time-value", TQString()), TQt::ISODate));
1989 bool fixed = (
object.hasAttributeNS( ooNS::text,
"fixed") &&
object.attributeNS( ooNS::text,
"fixed", TQString())==
"true");
1991 if (!dt.isValid()) {
1992 dt = TQDateTime::currentDateTime();
1996 const TQTime time(dt.time());
1997 TQDomElement timeElement (doc.createElement(
"TIME") );
1998 timeElement.setAttribute(
"fix", fixed ? 1 : 0);
1999 timeElement.setAttribute(
"hour", time.hour());
2000 timeElement.setAttribute(
"minute", time.minute());
2001 timeElement.setAttribute(
"second", time.second());
2004 appendKWordVariable(doc, outputFormats,
object, pos,
"TIME" + dateFormat, 2, timeElement);
2007 else if ( localName ==
"print-time"
2008 || localName ==
"print-date"
2009 || localName ==
"creation-time"
2010 || localName ==
"creation-date"
2011 || localName ==
"modification-time"
2012 || localName ==
"modification-date" )
2014 if ( localName.startsWith(
"print" ) )
2016 else if ( localName.startsWith(
"creation" ) )
2018 else if ( localName.startsWith(
"modification" ) )
2022 TQDomElement dateElement ( doc.createElement(
"DATE") );
2023 dateElement.setAttribute(
"subtype", subtype);
2024 if (
object.hasAttributeNS( ooNS::text,
"date-adjust"))
2025 dateElement.setAttribute(
"correct",
object.attributeNS( ooNS::text,
"date-adjust", TQString()));
2026 appendKWordVariable(doc, outputFormats,
object, pos,
"DATE" + dateFormat, 0, dateElement);
2029 else if (localName ==
"page-number")
2033 if (
object.hasAttributeNS( ooNS::text,
"select-page"))
2035 const TQString select =
object.attributeNS( ooNS::text,
"select-page", TQString());
2037 if (select ==
"previous")
2039 else if (select ==
"next")
2043 TQDomElement pgnumElement ( doc.createElement(
"PGNUM") );
2044 pgnumElement.setAttribute(
"subtype", subtype);
2045 pgnumElement.setAttribute(
"value",
object.text());
2046 appendKWordVariable(doc, outputFormats,
object, pos,
"NUMBER", 4, pgnumElement);
2048 else if (localName ==
"chapter")
2050 const TQString display =
object.attributeNS( ooNS::text,
"display", TQString() );
2052 TQDomElement pgnumElement ( doc.createElement(
"PGNUM") );
2053 pgnumElement.setAttribute(
"subtype", 2);
2054 pgnumElement.setAttribute(
"value",
object.text());
2055 appendKWordVariable(doc, outputFormats,
object, pos,
"STRING", 4, pgnumElement);
2057 else if (localName ==
"file-name")
2061 if (
object.hasAttributeNS( ooNS::text,
"display"))
2063 const TQString display =
object.attributeNS( ooNS::text,
"display", TQString());
2065 if (display ==
"path")
2067 else if (display ==
"name")
2069 else if (display ==
"name-and-extension")
2075 TQDomElement fieldElement ( doc.createElement(
"FIELD") );
2076 fieldElement.setAttribute(
"subtype", subtype);
2077 fieldElement.setAttribute(
"value",
object.text());
2078 appendKWordVariable(doc, outputFormats,
object, pos,
"STRING", 8, fieldElement);
2080 else if (localName ==
"author-name"
2081 || localName ==
"author-initials"
2082 || localName ==
"subject"
2083 || localName ==
"title"
2084 || localName ==
"description"
2089 if (localName ==
"author-initials")
2091 else if ( localName ==
"subject" )
2093 else if ( localName ==
"title" )
2095 else if ( localName ==
"description" )
2098 TQDomElement authorElem = doc.createElement(
"FIELD");
2099 authorElem.setAttribute(
"subtype", subtype);
2100 authorElem.setAttribute(
"value",
object.text());
2101 appendKWordVariable(doc, outputFormats,
object, pos,
"STRING", 8, authorElem);
2103 else if ( localName.startsWith(
"sender-" ) )
2106 const TQCString afterText( localName.latin1() + 5 );
2107 if ( afterText ==
"sender-company" )
2109 else if ( afterText ==
"sender-firstname" )
2111 else if ( afterText ==
"sender-lastname" )
2113 else if ( afterText ==
"sender-initials" )
2115 else if ( afterText ==
"sender-street" )
2117 else if ( afterText ==
"sender-country" )
2119 else if ( afterText ==
"sender-postal-code" )
2121 else if ( afterText ==
"sender-city" )
2123 else if ( afterText ==
"sender-title" )
2125 else if ( afterText ==
"sender-position" )
2127 else if ( afterText ==
"sender-phone-private" )
2129 else if ( afterText ==
"sender-phone-work" )
2131 else if ( afterText ==
"sender-fax" )
2133 else if ( afterText ==
"sender-email" )
2135 if ( subtype != -1 )
2137 TQDomElement fieldElem = doc.createElement(
"FIELD");
2138 fieldElem.setAttribute(
"subtype", subtype);
2139 fieldElem.setAttribute(
"value",
object.text());
2140 appendKWordVariable(doc, outputFormats,
object, pos,
"STRING", 8, fieldElem);
2143 else if ( localName ==
"variable-set"
2144 || localName ==
"user-defined" )
2150 TQDomElement customElem = doc.createElement(
"CUSTOM" );
2151 customElem.setAttribute(
"name",
object.attributeNS( ooNS::text,
"name", TQString() ) );
2152 customElem.setAttribute(
"value",
object.text() );
2153 appendKWordVariable(doc, outputFormats,
object, pos,
"STRING", 6, customElem);
2157 kdWarning(30518) <<
"Unsupported field " << localName << endl;
2162void OoWriterImport::appendKWordVariable(TQDomDocument& doc, TQDomElement& formats,
const TQDomElement&
object, uint pos,
2163 const TQString& key,
int type, TQDomElement& child)
2165 TQDomElement variableElement ( doc.createElement(
"VARIABLE") );
2167 TQDomElement typeElement ( doc.createElement(
"TYPE") );
2168 typeElement.setAttribute(
"key",key);
2169 typeElement.setAttribute(
"type",type);
2170 typeElement.setAttribute(
"text",
object.text());
2171 variableElement.appendChild(typeElement);
2173 variableElement.appendChild(child);
2175 TQDomElement formatElement ( doc.createElement(
"FORMAT") );
2176 formatElement.setAttribute(
"id",4);
2177 formatElement.setAttribute(
"pos",pos);
2178 formatElement.setAttribute(
"len",1);
2180 formatElement.appendChild(variableElement);
2182 formats.appendChild(formatElement);
2185void OoWriterImport::parseTable( TQDomDocument &doc,
const TQDomElement& parent, TQDomElement& currentFramesetElement )
2187 TQString tableName ( parent.attributeNS( ooNS::table,
"name", TQString()) );
2188 kdDebug(30518) <<
"Found table " << tableName << endl;
2191 TQDomElement paragraphElementOut (doc.createElement(
"PARAGRAPH"));
2192 currentFramesetElement.appendChild(paragraphElementOut);
2194 TQDomElement textElementOut(doc.createElement(
"TEXT"));
2195 textElementOut.appendChild(doc.createTextNode(
"#"));
2196 paragraphElementOut.appendChild(textElementOut);
2198 TQDomElement formatsPluralElementOut(doc.createElement(
"FORMATS"));
2199 paragraphElementOut.appendChild(formatsPluralElementOut);
2201 TQDomElement elementFormat(doc.createElement(
"FORMAT"));
2202 elementFormat.setAttribute(
"id",6);
2203 elementFormat.setAttribute(
"pos",0);
2204 elementFormat.setAttribute(
"len",1);
2205 formatsPluralElementOut.appendChild(elementFormat);
2209 TQDomElement elementAnchor(doc.createElement(
"ANCHOR"));
2210 elementAnchor.setAttribute(
"type",
"frameset");
2211 elementAnchor.setAttribute(
"instance",tableName);
2212 elementFormat.appendChild(elementAnchor);
2216 TQMemArray<double> columnLefts(4);
2217 uint maxColumns=columnLefts.size() - 1;
2222 forEachElement( elem, parent )
2224 if ( elem.localName() ==
"table-column" && elem.namespaceURI() == ooNS::table )
2226 uint repeat = elem.attributeNS( ooNS::table,
"number-columns-repeated",
"1").toUInt();
2229 const TQString styleName ( elem.attributeNS( ooNS::table,
"style-name", TQString()) );
2230 kdDebug(30518) <<
"Column " << col <<
" style " << styleName << endl;
2231 const TQDomElement* style=m_styles.find(styleName);
2235 const TQDomElement elemProps( KoDom::namedItemNS( *style, ooNS::style,
"properties") );
2236 if (elemProps.isNull())
2238 kdWarning(30518) <<
"Could not find table column style properties!" << endl;
2240 const TQString strWidth ( elemProps.attributeNS( ooNS::style,
"column-width", TQString()) );
2241 kdDebug(30518) <<
"- raw style width " << strWidth << endl;
2242 width = KoUnit::parseValue( strWidth );
2245 kdWarning(30518) <<
"Could not find table column style!" << endl;
2249 kdWarning(30518) <<
"Table column width ridiculous, assuming 1 inch!" << endl;
2253 kdDebug(30518) <<
"- style width " << width << endl;
2255 for (uint j=0; j<repeat; j++)
2258 if (col>=maxColumns)
2262 columnLefts.resize(maxColumns+1, TQGArray::SpeedOptim);
2264 columnLefts.at(col) = width + columnLefts.at(col-1);
2265 kdDebug(30518) <<
"Cell column " << col-1 <<
" left " << columnLefts.at(col-1) <<
" right " << columnLefts.at(col) << endl;
2272 parseInsideOfTable(doc, parent, currentFramesetElement, tableName, columnLefts, row, column);
2275void OoWriterImport::parseInsideOfTable( TQDomDocument &doc,
const TQDomElement& parent, TQDomElement& currentFramesetElement,
2276 const TQString& tableName,
const TQMemArray<double> & columnLefts, uint& row, uint& column )
2278 kdDebug(30518) <<
"parseInsideOfTable: columnLefts.size()=" << columnLefts.size() << endl;
2279 TQDomElement framesetsPluralElement (doc.documentElement().namedItem(
"FRAMESETS").toElement());
2280 if (framesetsPluralElement.isNull())
2282 kdError(30518) <<
"Cannot find KWord's <FRAMESETS>! Cannot process table!" << endl;
2287 forEachElement( e, parent )
2289 m_styleStack.save();
2290 const TQString localName = e.localName();
2291 const TQString ns = e.namespaceURI();
2292 if ( ns != ooNS::table ) {
2293 kdWarning(30518) <<
"Skipping element " << e.tagName() <<
" (in OoWriterImport::parseInsideOfTable)" << endl;
2297 if ( localName ==
"table-cell" )
2299 const TQString frameName(i18n(
"Frameset name",
"Table %3, row %1, column %2")
2300 .arg(row).arg(column).arg(tableName));
2301 kdDebug(30518) <<
"Trying to create " << frameName << endl;
2304 TQDomElement framesetElement(doc.createElement(
"FRAMESET"));
2305 framesetElement.setAttribute(
"frameType",1);
2306 framesetElement.setAttribute(
"frameInfo",0);
2307 framesetElement.setAttribute(
"visible",1);
2308 framesetElement.setAttribute(
"name",frameName);
2309 framesetElement.setAttribute(
"row",row);
2310 framesetElement.setAttribute(
"col",column);
2311 int rowSpan = e.attributeNS( ooNS::table,
"number-rows-spanned", TQString() ).toInt();
2312 framesetElement.setAttribute(
"rows",rowSpan == 0 ? 1 : rowSpan);
2313 int colSpan = e.attributeNS( ooNS::table,
"number-columns-spanned", TQString() ).toInt();
2314 framesetElement.setAttribute(
"cols",colSpan == 0 ? 1 : colSpan);
2315 framesetElement.setAttribute(
"grpMgr",tableName);
2316 framesetsPluralElement.appendChild(framesetElement);
2318 TQDomElement frameElementOut(doc.createElement(
"FRAME"));
2319 frameElementOut.setAttribute(
"left",columnLefts.at(column));
2320 frameElementOut.setAttribute(
"right",columnLefts.at(column+1));
2321 frameElementOut.setAttribute(
"top", 0);
2322 frameElementOut.setAttribute(
"bottom", 0);
2323 frameElementOut.setAttribute(
"runaround",1);
2324 frameElementOut.setAttribute(
"autoCreateNewFrame",0);
2327 m_styleStack.save();
2328 fillStyleStack( e, ooNS::table,
"style-name" );
2329 importCommonFrameProperties(frameElementOut);
2330 m_styleStack.restore();
2332 framesetElement.appendChild(frameElementOut);
2334 parseBodyOrSimilar( doc, e, framesetElement );
2337 else if ( localName ==
"covered-table-cell" )
2341 else if ( localName ==
"table-row" )
2344 parseInsideOfTable( doc, e, currentFramesetElement, tableName, columnLefts, row, column);
2347 else if ( localName ==
"table-header-rows" )
2349 parseInsideOfTable( doc, e, currentFramesetElement, tableName, columnLefts, row, column);
2351 else if ( localName ==
"table-column" )
2358 kdWarning(30518) <<
"Skipping element " << localName <<
" (in OoWriterImport::parseInsideOfTable)" << endl;
2361 m_styleStack.restore();
2365void OoWriterImport::appendBookmark( TQDomDocument& doc,
int paragId,
int pos,
const TQString& name )
2367 appendBookmark( doc, paragId, pos, paragId, pos, name );
2370void OoWriterImport::appendBookmark( TQDomDocument& doc,
int paragId,
int pos,
int endParagId,
int endPos,
const TQString& name )
2372 Q_ASSERT( !m_currentFrameset.isNull() );
2373 const TQString frameSetName = m_currentFrameset.attribute(
"name" );
2374 Q_ASSERT( !frameSetName.isEmpty() );
2375 TQDomElement bookmarks = doc.documentElement().namedItem(
"BOOKMARKS" ).toElement();
2376 if ( bookmarks.isNull() ) {
2377 bookmarks = doc.createElement(
"BOOKMARKS" );
2378 doc.documentElement().appendChild( bookmarks );
2380 TQDomElement bkItem = doc.createElement(
"BOOKMARKITEM" );
2381 bkItem.setAttribute(
"name", name );
2382 bkItem.setAttribute(
"frameset", frameSetName );
2383 bkItem.setAttribute(
"startparag", paragId );
2384 bkItem.setAttribute(
"cursorIndexStart", pos );
2385 bkItem.setAttribute(
"endparag", endParagId );
2386 bkItem.setAttribute(
"cursorIndexEnd", endPos );
2387 bookmarks.appendChild( bkItem );
2391void OoWriterImport::importFootnotesConfiguration( TQDomDocument& doc,
const TQDomElement& elem,
bool endnote )
2393 TQDomElement docElement( doc.documentElement() );
2395 TQString elemName = endnote ?
"ENDNOTESETTING" :
"FOOTNOTESETTING";
2396 Q_ASSERT( docElement.namedItem( elemName ).isNull() );
2397 TQDomElement settings = doc.createElement( elemName );
2398 docElement.appendChild( settings );
2404 if ( elem.hasAttributeNS( ooNS::text,
"start-value" ) ) {
2405 int startValue = elem.attributeNS( ooNS::text,
"start-value", TQString() ).toInt();
2406 settings.setAttribute(
"start", startValue );
2409 settings.setAttribute(
"type", Conversion::importCounterType( elem.attributeNS( ooNS::style,
"num-format", TQString() ) ) );
2410 settings.setAttribute(
"lefttext", elem.attributeNS( ooNS::style,
"num-prefix", TQString() ) );
2411 settings.setAttribute(
"righttext", elem.attributeNS( ooNS::style,
"num-suffix", TQString() ) );
2414void OoWriterImport::appendTOC( TQDomDocument& doc,
const TQDomElement& toc )
2425 TQDomElement tocIndexBody = KoDom::namedItemNS( toc, ooNS::text,
"index-body" );
2427 forEachElement( t, tocIndexBody )
2429 m_styleStack.save();
2430 const TQString localName = t.localName();
2432 bool isTextNS = e.namespaceURI() == ooNS::text;
2433 if ( isTextNS && localName ==
"index-title" ) {
2434 parseBodyOrSimilar( doc, t, m_currentFrameset );
2435 }
else if ( isTextNS && localName ==
"p" ) {
2436 fillStyleStack( t, ooNS::text,
"style-name" );
2437 e = parseParagraph( doc, t );
2440 m_currentFrameset.appendChild( e );
2441 m_styleStack.restore();
2451void OoWriterImport::finishDocumentContent( TQDomDocument& mainDocument )
2453 TQDomElement attributes = mainDocument.createElement(
"ATTRIBUTES" );
2454 TQDomElement docElement = mainDocument.documentElement();
2455 docElement.appendChild( attributes );
2456 attributes.setAttribute(
"hasTOC", m_hasTOC ? 1 : 0 );
2457 attributes.setAttribute(
"hasHeader", m_hasHeader );
2458 attributes.setAttribute(
"hasFooter", m_hasFooter );
2464 TQDomElement paperElement = docElement.namedItem(
"PAPER").toElement();
2465 Q_ASSERT ( !paperElement.isNull() );
2466 if ( !paperElement.isNull() )
2474TQString OoWriterImport::kWordStyleName(
const TQString& ooStyleName )
2476 if ( ooStyleName.startsWith(
"Contents " ) ) {
2477 TQString s( ooStyleName );
2478 return s.replace( 0, 9, TQString(
"Contents Head ") );
2485void OoWriterImport::importHeaderFooter( TQDomDocument& doc,
const TQDomElement& headerFooter,
bool hasEvenOdd, TQDomElement& style )
2487 const TQString localName = headerFooter.localName();
2488 TQDomElement framesetElement = doc.createElement(
"FRAMESET");
2489 TQDomElement framesetsPluralElement (doc.documentElement().namedItem(
"FRAMESETS").toElement());
2490 framesetElement.setAttribute(
"frameType", 1 );
2491 framesetElement.setAttribute(
"frameInfo", Conversion::headerTypeToFrameInfo( localName, hasEvenOdd ) );
2492 framesetElement.setAttribute(
"name", Conversion::headerTypeToFramesetName( localName, hasEvenOdd ) );
2493 framesetsPluralElement.appendChild(framesetElement);
2495 bool isHeader = localName.startsWith(
"header" );
2500 TQDomElement frameElementOut = createInitialFrame( framesetElement, 29, 798, isHeader?0:567, isHeader?41:567+41,
true, Copy );
2501 if ( !style.isNull() )
2502 m_styleStack.push( style );
2503 importCommonFrameProperties( frameElementOut );
2504 if ( !style.isNull() )
2507 parseBodyOrSimilar( doc, headerFooter, framesetElement );
2510#include "oowriterimport.moc"