21#include "ooimpressimport.h"
26#include <tqdatetime.h>
27#include <tqfileinfo.h>
34#include <KoDocumentInfo.h>
35#include <KoDocument.h>
37#include <kgenericfactory.h>
38#include <KoFilterChain.h>
42#include <KoOasisSettings.h>
44typedef KGenericFactory<OoImpressImport, KoFilter> OoImpressImportFactory;
45K_EXPORT_COMPONENT_FACTORY( libooimpressimport, OoImpressImportFactory(
"kofficefilters" ) )
48OoImpressImport::OoImpressImport( KoFilter *, const
char *, const TQStringList & )
53 m_styleStack( ooNS::style, ooNS::fo )
55 m_styles.setAutoDelete(
true );
56 m_listStyles.setAutoDelete(
true );
59OoImpressImport::~OoImpressImport()
61 TQDictIterator<animationList> it( m_animations );
62 for( ; it.current(); ++it )
64 delete it.current()->element;
69KoFilter::ConversionStatus OoImpressImport::convert( TQCString
const & from, TQCString
const & to )
71 kdDebug(30518) <<
"Entering Ooimpress Import filter: " << from <<
" - " << to << endl;
73 if ( (from !=
"application/vnd.sun.xml.impress" && from !=
"application/vnd.sun.xml.impress.template" )
74 || to !=
"application/x-kpresenter" )
76 kdWarning(30518) <<
"Invalid mimetypes " << from <<
" " << to << endl;
77 return KoFilter::NotImplemented;
80 m_zip =
new KZip( m_chain->inputFile() );
82 if ( !m_zip->open( IO_ReadOnly ) )
84 kdError(30518) <<
"Couldn't open the requested file "<< m_chain->inputFile() << endl;
86 return KoFilter::FileNotFound;
89 KoFilter::ConversionStatus preStatus = openFile();
91 if ( preStatus != KoFilter::OK )
98 TQDomDocument docinfo;
99 createDocumentInfo( docinfo );
102 KoStoreDevice* out = m_chain->storageFile(
"documentinfo.xml", KoStore::Write );
105 TQCString info = docinfo.toCString();
108 out->writeBlock( info , info.length() );
111 TQDomDocument doccontent;
112 createDocumentContent( doccontent );
115 out = m_chain->storageFile(
"maindoc.xml", KoStore::Write );
118 TQCString content = doccontent.toCString();
119 kdDebug(30518) <<
" content :" << content << endl;
120 out->writeBlock( content , content.length() );
126 kdDebug(30518) <<
"######################## OoImpressImport::convert done ####################" << endl;
131KoFilter::ConversionStatus OoImpressImport::openFile()
133 KoFilter::ConversionStatus status = loadAndParse(
"content.xml", m_content );
134 if ( status != KoFilter::OK )
136 kdError(30518) <<
"Content.xml could not be parsed correctly! Aborting!" << endl;
141 TQDomDocument styles;
142 loadAndParse(
"styles.xml", styles );
143 loadAndParse(
"meta.xml", m_meta );
144 loadAndParse(
"settings.xml", m_settings );
146 emit sigProgress( 10 );
147 createStyleMap( styles );
152KoFilter::ConversionStatus OoImpressImport::loadAndParse(
const TQString& filename, TQDomDocument& doc)
154 return OoUtils::loadAndParse( filename, doc, m_zip);
158void OoImpressImport::createDocumentInfo( TQDomDocument &docinfo )
160 docinfo = KoDocument::createDomDocument(
"document-info" ,
"document-info" ,
"1.1" );
162 OoUtils::createDocumentInfo(m_meta, docinfo);
166void OoImpressImport::createDocumentContent( TQDomDocument &doccontent )
168 TQDomDocument doc = KoDocument::createDomDocument(
"kpresenter",
"DOC",
"1.2" );
169 TQDomElement docElement = doc.documentElement();
170 docElement.setAttribute(
"editor",
"KPresenter" );
171 docElement.setAttribute(
"mime",
"application/x-kpresenter" );
172 docElement.setAttribute(
"syntaxVersion",
"2" );
174 TQDomElement content = m_content.documentElement();
177 TQDomNode automaticStyles = KoDom::namedItemNS( content, ooNS::office,
"automatic-styles" );
178 if ( !automaticStyles.isNull() )
179 insertStyles( automaticStyles.toElement() );
181 TQDomNode body = KoDom::namedItemNS( content, ooNS::office,
"body" );
185 TQDomElement customSlideShow = doc.createElement(
"CUSTOMSLIDESHOWCONFIG" );
188 TQDomElement settings = KoDom::namedItemNS( body, ooNS::presentation,
"settings");
189 if (!settings.isNull())
191 if (settings.attributeNS( ooNS::presentation,
"endless", TQString())==
"true")
193 TQDomElement infElem = doc.createElement(
"INFINITLOOP");
194 infElem.setAttribute(
"value", 1);
195 docElement.appendChild(infElem);
198 if (settings.attributeNS( ooNS::presentation,
"show-end-of-presentation-slide", TQString())==
"true")
200 TQDomElement infElem = doc.createElement(
"SHOWENDOFPRESENTATIONSLIDE");
201 infElem.setAttribute(
"value", 1);
202 docElement.appendChild(infElem);
205 if (settings.attributeNS( ooNS::presentation,
"force-manual", TQString())==
"true")
207 TQDomElement manualElem = doc.createElement(
"MANUALSWITCH");
208 manualElem.setAttribute(
"value", 1);
209 docElement.appendChild(manualElem);
211 if ( settings.hasAttributeNS( ooNS::presentation,
"show") )
213 TQDomElement defaultPage = doc.createElement(
"DEFAULTCUSTOMSLIDESHOWNAME");
214 defaultPage.setAttribute(
"name", settings.attributeNS( ooNS::presentation,
"show", TQString()) );
215 docElement.appendChild(defaultPage);
219 TQDomElement presentationShow;
220 forEachElement( presentationShow, settings )
222 if ( presentationShow.localName()==
"show" && presentationShow.namespaceURI() == ooNS::presentation )
224 if ( presentationShow.hasAttributeNS( ooNS::presentation,
"pages") &&
225 presentationShow.hasAttributeNS( ooNS::presentation,
"name"))
227 TQDomElement slide=doc.createElement(
"CUSTOMSLIDESHOW");
228 slide.setAttribute(
"pages", presentationShow.attributeNS( ooNS::presentation,
"pages", TQString() ));
229 slide.setAttribute(
"name", presentationShow.attributeNS( ooNS::presentation,
"name", TQString() ));
230 customSlideShow.appendChild( slide );
236 TQDomElement drawPage = KoDom::namedItemNS( body, ooNS::draw,
"page" );
237 if ( drawPage.isNull() )
240 TQDomElement objectElement = doc.createElement(
"OBJECTS" );
241 TQDomElement pictureElement = doc.createElement(
"PICTURES" );
242 TQDomElement pageTitleElement = doc.createElement(
"PAGETITLES" );
243 TQDomElement pageNoteElement = doc.createElement(
"PAGENOTES" );
244 TQDomElement backgroundElement = doc.createElement(
"BACKGROUND" );
245 TQDomElement soundElement = doc.createElement(
"SOUNDS" );
246 TQDomElement selSlideElement = doc.createElement(
"SELSLIDES" );
247 TQDomElement helpLineElement = doc.createElement(
"HELPLINES" );
248 TQDomElement attributeElement = doc.createElement(
"ATTRIBUTES" );
249 TQDomElement *master = m_styles[drawPage.attributeNS( ooNS::draw,
"master-page-name", TQString() )];
251 appendObject(*master, doc, soundElement,pictureElement,pageNoteElement,objectElement, 0,
true);
253 TQDomElement *style = m_styles[master->attributeNS( ooNS::style,
"page-master-name", TQString() )];
254 TQDomElement properties = KoDom::namedItemNS( *style, ooNS::style,
"properties" );
256 TQDomElement *backgroundStyle = m_stylesPresentation[ master->attributeNS( ooNS::draw,
"style-name", TQString() ).isEmpty() ?
"Standard-background" : master->attributeNS( ooNS::draw,
"style-name", TQString() ) ];
260 TQDomElement paperElement = doc.createElement(
"PAPER" );
261 if ( properties.isNull() )
263 paperElement.setAttribute(
"ptWidth", CM_TO_POINT(28) );
264 paperElement.setAttribute(
"ptHeight", CM_TO_POINT(21) );
265 paperElement.setAttribute(
"unit", 0 );
266 paperElement.setAttribute(
"format", 5 );
267 paperElement.setAttribute(
"tabStopValue", 42.5198 );
268 paperElement.setAttribute(
"orientation", 0 );
271 TQDomElement paperBorderElement = doc.createElement(
"PAPERBORDERS" );
272 paperBorderElement.setAttribute(
"ptRight", 0 );
273 paperBorderElement.setAttribute(
"ptBottom", 0 );
274 paperBorderElement.setAttribute(
"ptLeft", 0 );
275 paperBorderElement.setAttribute(
"ptTop", 0 );
276 paperElement.appendChild( paperBorderElement );
280 paperElement.setAttribute(
"ptWidth", KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"page-width", TQString() ) ) );
281 paperElement.setAttribute(
"ptHeight", KoUnit::parseValue(properties.attributeNS( ooNS::fo,
"page-height", TQString() ) ) );
289 if (properties.attributeNS( ooNS::style,
"print-orientation", TQString())==
"portrait")
290 paperElement.setAttribute(
"orientation", 0);
291 else if (properties.attributeNS( ooNS::style,
"print-orientation", TQString())==
"landscape")
292 paperElement.setAttribute(
"orientation", 1);
296 pageHeight = properties.attributeNS( ooNS::fo,
"page-height", TQString() ).remove(
"cm" ).toDouble();
298 TQDomElement paperBorderElement = doc.createElement(
"PAPERBORDERS" );
299 paperBorderElement.setAttribute(
"ptRight", KoUnit::parseValue( properties.attributeNS( ooNS::fo,
"margin-right", TQString() ) ) );
300 paperBorderElement.setAttribute(
"ptBottom", KoUnit::parseValue( properties.attributeNS( ooNS::fo,
"margin-bottom", TQString() ) ) );
301 paperBorderElement.setAttribute(
"ptLeft", KoUnit::parseValue( properties.attributeNS( ooNS::fo,
"margin-left", TQString() ) ) );
302 paperBorderElement.setAttribute(
"ptTop", KoUnit::parseValue( properties.attributeNS( ooNS::fo,
"margin-top", TQString() ) ) );
303 paperElement.appendChild( paperBorderElement );
308 forEachElement( drawPage, body )
310 if ( drawPage.localName()==
"page" && drawPage.namespaceURI() == ooNS::draw && drawPage.hasAttributeNS( ooNS::draw,
"id" ))
312 m_styleStack.clear();
313 fillStyleStack( drawPage );
315 int pagePos = drawPage.attributeNS( ooNS::draw,
"id", TQString() ).toInt() - 1;
317 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"fill" )
318 || m_styleStack.hasAttributeNS( ooNS::presentation,
"transition-style" ))
320 appendBackgroundPage( doc, backgroundElement,pictureElement, soundElement );
322 else if ( !m_styleStack.hasAttributeNS( ooNS::draw,
"fill" ) && backgroundStyle)
325 m_styleStack.push( *backgroundStyle );
326 appendBackgroundPage( doc, backgroundElement,pictureElement, soundElement );
327 m_styleStack.restore();
328 kdDebug(30518)<<
" load standard bacground \n";
330 if ( m_styleStack.hasAttributeNS( ooNS::presentation,
"visibility" ) )
332 TQString str = m_styleStack.attributeNS( ooNS::presentation,
"visibility" );
333 TQDomElement slide = doc.createElement(
"SLIDE");
334 slide.setAttribute(
"nr", pagePos );
335 slide.setAttribute(
"show", ( ( str==
"hidden" ) ?
"0" :
"1" ));
336 selSlideElement.appendChild( slide );
339 kdDebug(30518)<<
"m_styleStack.hasAttribute( presentation:visibility ) :"<<str<<
" position page "<<pagePos<<endl;
342 TQDomElement titleElement = doc.createElement(
"Title" );
343 titleElement.setAttribute(
"title", drawPage.attributeNS( ooNS::draw,
"name", TQString() ) );
344 pageTitleElement.appendChild( titleElement );
348 double offset = CM_TO_POINT( ( drawPage.attributeNS( ooNS::draw,
"id", TQString() ).toInt() - 1 ) * pageHeight ) + 1;
351 createPresentationAnimation(KoDom::namedItemNS( drawPage, ooNS::presentation,
"animations") );
354 appendObject(drawPage, doc, soundElement,pictureElement,pageNoteElement,objectElement, offset);
357 m_styleStack.restore();
361 docElement.appendChild( paperElement );
362 docElement.appendChild( backgroundElement );
363 if ( parseSettings( doc, helpLineElement, attributeElement ) )
364 docElement.appendChild( helpLineElement );
365 docElement.appendChild( attributeElement );
366 docElement.appendChild( pageTitleElement );
367 docElement.appendChild( pageNoteElement );
368 docElement.appendChild( objectElement );
369 docElement.appendChild( selSlideElement );
370 docElement.appendChild( customSlideShow );
371 docElement.appendChild( soundElement );
372 docElement.appendChild( pictureElement );
374 doccontent.appendChild( doc );
377bool OoImpressImport::parseSettings( TQDomDocument &doc, TQDomElement &helpLineElement, TQDomElement &attributeElement )
379 bool foundElement =
false;
380 KoOasisSettings settings( m_settings, ooNS::office, ooNS::config );
381 KoOasisSettings::Items viewSettings = settings.itemSet(
"view-settings" );
383 KoOasisSettings::IndexedMap viewMap = viewSettings.indexedMap(
"Views" );
384 KoOasisSettings::Items firstView = viewMap.entry( 0 );
388 if ( !firstView.isNull() )
390 TQString str = firstView.parseConfigItemString(
"SnapLinesDrawing" );
391 if ( !str.isEmpty() )
393 parseHelpLine( doc, helpLineElement, str );
395 helpLineElement.setAttribute(
"show",
true );
399 int gridX = firstView.parseConfigItemInt(
"GridFineWidth" );
400 int gridY = firstView.parseConfigItemInt(
"GridFineHeight" );
401 bool snapToGrid = firstView.parseConfigItemBool(
"IsSnapToGrid" );
402 int selectedPage = firstView.parseConfigItemInt(
"SelectedPage" );
404 attributeElement.setAttribute(
"activePage", selectedPage );
405 attributeElement.setAttribute(
"gridx", MM_TO_POINT( gridX / 100.0 ) );
406 attributeElement.setAttribute(
"gridy", MM_TO_POINT( gridY / 100.0 ) );
407 attributeElement.setAttribute(
"snaptogrid", (
int)snapToGrid );
415void OoImpressImport::parseHelpLine( TQDomDocument &doc,TQDomElement &helpLineElement,
const TQString &text )
418 int newPos = text.length()-1;
419 for (
int pos = text.length()-1; pos >=0;--pos )
421 if ( text[pos]==
'P' )
425 str = text.mid( pos+1, ( newPos-pos ) );
426 TQDomElement point=doc.createElement(
"HelpPoint");
429 TQStringList listVal = TQStringList::split(
",", str );
430 int posX = ( listVal[0].toInt()/100 );
431 int posY = ( listVal[1].toInt()/100 );
432 point.setAttribute(
"posX", MM_TO_POINT( posX ));
433 point.setAttribute(
"posY", MM_TO_POINT( posY ));
435 helpLineElement.appendChild( point );
438 else if ( text[pos]==
'V' )
440 TQDomElement lines=doc.createElement(
"Vertical");
442 str = text.mid( pos+1, ( newPos-pos ) );
444 int posX = ( str.toInt()/100 );
445 lines.setAttribute(
"value", MM_TO_POINT( posX ) );
446 helpLineElement.appendChild( lines );
451 else if ( text[pos]==
'H' )
454 TQDomElement lines=doc.createElement(
"Horizontal");
455 str = text.mid( pos+1, ( newPos-pos ) );
457 int posY = ( str.toInt()/100 );
458 lines.setAttribute(
"value", MM_TO_POINT( posY ) );
459 helpLineElement.appendChild( lines );
465void OoImpressImport::appendObject(TQDomNode & drawPage, TQDomDocument & doc, TQDomElement & soundElement, TQDomElement & pictureElement, TQDomElement & pageNoteElement, TQDomElement &objectElement,
double offset,
bool sticky)
468 forEachElement( o, drawPage )
470 const TQString localName = o.localName();
471 const TQString ns = o.namespaceURI();
472 const TQString drawID = o.attributeNS( ooNS::draw,
"id", TQString());
476 if ( localName ==
"text-box" && ns == ooNS::draw )
478 fillStyleStack( o, sticky );
479 e = doc.createElement(
"OBJECT" );
480 e.setAttribute(
"type", 4 );
482 e.setAttribute(
"sticky",
"1" );
483 append2DGeometry( doc, e, o, (
int)offset );
484 appendName(doc, e, o);
486 appendBrush( doc, e );
487 appendRounding( doc, e, o );
488 appendShadow( doc, e );
489 appendObjectEffect(doc, e, o, soundElement);
490 e.appendChild( parseTextBox( doc, o ) );
492 else if ( localName ==
"rect" && ns == ooNS::draw )
494 fillStyleStack( o, sticky );
495 e = doc.createElement(
"OBJECT" );
496 e.setAttribute(
"type", 2 );
498 e.setAttribute(
"sticky",
"1" );
499 append2DGeometry( doc, e, o, (
int)offset );
500 appendName(doc, e, o);
502 appendBrush( doc, e );
503 appendRounding( doc, e, o );
504 appendShadow( doc, e );
506 appendObjectEffect(doc, e, o, soundElement);
508 else if ( ( localName ==
"circle" || localName ==
"ellipse" ) && ns == ooNS::draw )
510 fillStyleStack( o, sticky );
511 e = doc.createElement(
"OBJECT" );
513 e.setAttribute(
"sticky",
"1" );
514 append2DGeometry( doc, e, o, (
int)offset );
515 appendName(doc, e, o);
517 appendShadow( doc, e );
518 appendLineEnds( doc, e );
519 appendObjectEffect(doc, e, o, soundElement);
521 if ( o.hasAttributeNS( ooNS::draw,
"kind" ) )
523 e.setAttribute(
"type", 8 );
524 appendPie( doc, e, o );
525 TQDomElement type = doc.createElement(
"PIETYPE" );
527 TQString kind = o.attributeNS( ooNS::draw,
"kind", TQString() );
528 if ( kind ==
"section" )
530 appendBrush( doc, e );
531 type.setAttribute(
"value", 0 );
533 else if ( kind ==
"cut" )
535 appendBrush( doc, e );
536 type.setAttribute(
"value", 2 );
538 else if ( kind ==
"arc" )
541 type.setAttribute(
"value", 1 );
543 e.appendChild( type );
547 e.setAttribute(
"type", 3 );
548 appendBrush( doc, e );
551 else if ( localName ==
"line" && ns == ooNS::draw )
553 fillStyleStack( o, sticky );
554 e = doc.createElement(
"OBJECT" );
555 e.setAttribute(
"type", 1 );
557 e.setAttribute(
"sticky",
"1" );
558 bool orderEndStartLine = appendLineGeometry( doc, e, o, (
int)offset );
559 appendName(doc, e, o);
561 appendBrush( doc, e );
562 appendShadow( doc, e );
563 appendLineEnds( doc, e, orderEndStartLine );
564 appendObjectEffect(doc, e, o, soundElement);
566 else if ( localName==
"polyline" && ns == ooNS::draw ) {
567 fillStyleStack(o, sticky);
568 e = doc.createElement(
"OBJECT");
569 e.setAttribute(
"type", 12);
571 e.setAttribute(
"sticky",
"1" );
572 append2DGeometry(doc, e, o, (
int)offset);
573 appendName(doc, e, o);
574 appendPoints(doc, e, o);
577 appendLineEnds(doc, e);
579 appendObjectEffect(doc, e, o, soundElement);
581 else if ( localName==
"polygon" && ns == ooNS::draw ) {
582 fillStyleStack(o, sticky);
583 e = doc.createElement(
"OBJECT");
584 e.setAttribute(
"type", 16);
586 e.setAttribute(
"sticky",
"1" );
587 append2DGeometry(doc, e, o, (
int)offset);
588 appendName(doc, e, o);
589 appendPoints(doc, e, o);
594 appendObjectEffect(doc, e, o, soundElement);
596 else if ( localName ==
"image" && ns == ooNS::draw )
598 fillStyleStack( o, sticky );
599 e = doc.createElement(
"OBJECT" );
600 e.setAttribute(
"type", 0 );
602 e.setAttribute(
"sticky",
"1" );
603 append2DGeometry( doc, e, o, (
int)offset );
604 appendName(doc, e, o);
605 appendImage( doc, e, pictureElement, o );
606 appendObjectEffect(doc, e, o, soundElement);
608 else if ( localName ==
"object" && ns == ooNS::draw )
612 else if ( localName ==
"g" && ns == ooNS::draw )
616 else if ( localName ==
"path" && ns == ooNS::draw )
620 else if ( localName ==
"notes" && ns == ooNS::presentation )
622 TQDomNode textBox = KoDom::namedItemNS( o, ooNS::draw,
"text-box" );
623 if ( !textBox.isNull() )
627 forEachElement( t, textBox )
631 note += t.text() +
"\n";
633 TQDomElement notesElement = doc.createElement(
"Note" );
634 notesElement.setAttribute(
"note", note );
635 pageNoteElement.appendChild( notesElement );
640 kdDebug(30518) <<
"Unsupported object '" << localName <<
"'" << endl;
641 m_styleStack.restore();
645 objectElement.appendChild( e );
646 m_styleStack.restore();
650void OoImpressImport::appendBackgroundPage( TQDomDocument &doc, TQDomElement &backgroundElement, TQDomElement & pictureElement, TQDomElement &soundElement)
652 TQDomElement bgPage = doc.createElement(
"PAGE" );
655 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"fill" ) )
657 const TQString fill = m_styleStack.attributeNS( ooNS::draw,
"fill" );
658 if ( fill ==
"solid" )
660 TQDomElement backColor1 = doc.createElement(
"BACKCOLOR1" );
661 backColor1.setAttribute(
"color", m_styleStack.attributeNS( ooNS::draw,
"fill-color" ) );
662 bgPage.appendChild( backColor1 );
664 TQDomElement bcType = doc.createElement(
"BCTYPE" );
665 bcType.setAttribute(
"value", 0 );
666 bgPage.appendChild( bcType );
668 TQDomElement backType = doc.createElement(
"BACKTYPE" );
669 backType.setAttribute(
"value", 0 );
670 bgPage.appendChild( backType );
672 else if ( fill ==
"gradient" )
674 TQString style = m_styleStack.attributeNS( ooNS::draw,
"fill-gradient-name" );
675 TQDomElement* draw = m_draws[style];
676 appendBackgroundGradient( doc, bgPage, *draw );
678 else if ( fill ==
"bitmap" )
680 TQString style = m_styleStack.attributeNS( ooNS::draw,
"fill-image-name" );
681 TQDomElement* draw = m_draws[style];
682 appendBackgroundImage( doc, bgPage, pictureElement, *draw );
684 TQDomElement backView = doc.createElement(
"BACKVIEW" );
685 if ( m_styleStack.hasAttributeNS( ooNS::style,
"repeat" ) )
687 TQString repeat = m_styleStack.attributeNS( ooNS::style,
"repeat" );
688 if ( repeat ==
"stretch" )
689 backView.setAttribute(
"value", 0 );
690 else if ( repeat ==
"no-repeat" )
691 backView.setAttribute(
"value", 1 );
693 backView.setAttribute(
"value", 2 );
696 backView.setAttribute(
"value", 2 );
697 bgPage.appendChild( backView );
699 TQDomElement backType = doc.createElement(
"BACKTYPE" );
700 backType.setAttribute(
"value", 1 );
701 bgPage.appendChild( backType );
705 if ( m_styleStack.hasAttributeNS( ooNS::presentation,
"duration" ) )
707 TQString str = m_styleStack.attributeNS( ooNS::presentation,
"duration");
708 kdDebug(30518)<<
"styleStack.hasAttribute(presentation:duration ) :"<<str<<endl;
710 int hour( str.mid( 2, 2 ).toInt() );
711 int minute( str.mid( 5, 2 ).toInt() );
712 int second( str.mid( 8, 2 ).toInt() );
713 int pageTimer = second + minute*60 + hour*60*60;
714 TQDomElement pgEffect = doc.createElement(
"PGTIMER");
715 pgEffect.setAttribute(
"timer", pageTimer );
716 bgPage.appendChild(pgEffect);
719 if (m_styleStack.hasAttributeNS( ooNS::presentation,
"transition-style"))
721 TQDomElement pgEffect = doc.createElement(
"PGEFFECT");
723 const TQString effect = m_styleStack.attributeNS( ooNS::presentation,
"transition-style");
727 if (effect==
"vertical-stripes" || effect==
"vertical-lines")
729 else if (effect==
"horizontal-stripes" || effect==
"horizontal-lines")
731 else if (effect==
"spiralin-left" || effect==
"spiralin-right"
732 || effect==
"spiralout-left" || effect==
"spiralout-right")
734 else if (effect==
"fade-from-upperleft")
736 else if (effect==
"fade-from-upperright")
738 else if (effect==
"fade-from-lowerleft")
740 else if (effect==
"fade-from-lowerright")
742 else if (effect==
"fade-from-top")
744 else if (effect==
"fade-from-bottom")
746 else if (effect==
"fade-from-left")
748 else if (effect==
"fade-from-right")
750 else if (effect==
"fade-to-center")
752 else if (effect==
"fade-from-center")
754 else if (effect==
"open-vertical")
756 else if (effect==
"open-horizontal")
758 else if (effect==
"close-vertical")
760 else if (effect==
"close-horizontal")
762 else if (effect==
"dissolve")
764 else if (effect==
"horizontal-checkerboard")
766 else if (effect==
"vertical-checkerboard")
768 else if (effect==
"roll-from-left")
770 else if (effect==
"roll-from-right")
772 else if (effect==
"roll-from-bottom")
774 else if (effect==
"roll-from-top")
776 else if (effect==
"random")
781 pgEffect.setAttribute(
"value", pef);
782 bgPage.appendChild(pgEffect);
786 if (m_styleStack.hasChildNodeNS( ooNS::presentation,
"sound"))
788 TQString soundUrl = storeSound(m_styleStack.childNodeNS( ooNS::presentation,
"sound"),
791 if (!soundUrl.isNull())
793 TQDomElement pseElem = doc.createElement(
"PGSOUNDEFFECT");
794 pseElem.setAttribute(
"soundEffect", 1);
795 pseElem.setAttribute(
"soundFileName", soundUrl);
797 bgPage.appendChild(pseElem);
801 backgroundElement.appendChild(bgPage);
804void OoImpressImport::appendName(TQDomDocument& doc, TQDomElement& e,
const TQDomElement&
object)
806 if(
object.hasAttributeNS( ooNS::draw,
"name" ))
808 TQDomElement name = doc.createElement(
"OBJECTNAME" );
809 name.setAttribute(
"objectName",
object.attributeNS( ooNS::draw,
"name", TQString() ));
810 e.appendChild( name );
814void OoImpressImport::append2DGeometry( TQDomDocument& doc, TQDomElement& e,
const TQDomElement&
object,
int offset )
816 TQDomElement orig = doc.createElement(
"ORIG" );
817 orig.setAttribute(
"x", KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"x", TQString() ) ) );
818 orig.setAttribute(
"y", KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"y", TQString() ) ) + offset );
819 e.appendChild( orig );
821 TQDomElement size = doc.createElement(
"SIZE" );
822 size.setAttribute(
"width", KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"width", TQString() ) ) );
823 size.setAttribute(
"height", KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"height", TQString() ) ) );
824 e.appendChild( size );
825 if(
object.hasAttributeNS( ooNS::draw,
"transform" ))
827 kdDebug(30518)<<
" object transform \n";
829 TQString transform =
object.attributeNS( ooNS::draw,
"transform", TQString() );
830 if( transform.contains(
"rotate ("))
833 transform = transform.remove(
"rotate (" );
834 transform = transform.left(transform.find(
")"));
837 double radian = transform.toDouble(&ok);
840 TQDomElement angle = doc.createElement(
"ANGLE" );
842 angle.setAttribute(
"value", (-1 * ((radian*180)/M_PI)));
844 e.appendChild( angle );
851bool OoImpressImport::appendLineGeometry( TQDomDocument& doc, TQDomElement& e,
const TQDomElement&
object,
int offset )
853 double x1 = KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"x1", TQString() ) );
854 double y1 = KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"y1", TQString() ) );
855 double x2 = KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"x2", TQString() ) );
856 double y2 = KoUnit::parseValue(
object.attributeNS( ooNS::svg,
"y2", TQString() ) );
858 double x = TQMIN( x1, x2 );
859 double y = TQMIN( y1, y2 );
861 TQDomElement orig = doc.createElement(
"ORIG" );
862 orig.setAttribute(
"x", x );
863 orig.setAttribute(
"y", y + offset );
864 e.appendChild( orig );
866 TQDomElement size = doc.createElement(
"SIZE" );
867 size.setAttribute(
"width", fabs( x1 - x2 ) );
868 size.setAttribute(
"height", fabs( y1 - y2 ) );
869 e.appendChild( size );
871 TQDomElement linetype = doc.createElement(
"LINETYPE" );
872 if ( ( x1 < x2 && y1 < y2 ) || ( x1 > x2 && y1 > y2 ) )
873 linetype.setAttribute(
"value", 2 );
875 linetype.setAttribute(
"value", 3 );
877 e.appendChild( linetype );
881void OoImpressImport::appendPen( TQDomDocument& doc, TQDomElement& e )
883 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"stroke" ))
885 TQDomElement pen = doc.createElement(
"PEN" );
886 if ( m_styleStack.attributeNS( ooNS::draw,
"stroke" ) ==
"none" )
887 pen.setAttribute(
"style", 0 );
888 else if ( m_styleStack.attributeNS( ooNS::draw,
"stroke" ) ==
"solid" )
889 pen.setAttribute(
"style", 1 );
890 else if ( m_styleStack.attributeNS( ooNS::draw,
"stroke" ) ==
"dash" )
892 TQString style = m_styleStack.attributeNS( ooNS::draw,
"stroke-dash" );
893 if ( style ==
"Ultrafine Dashed" || style ==
"Fine Dashed" ||
894 style ==
"Fine Dashed (var)" || style ==
"Dashed (var)" )
895 pen.setAttribute(
"style", 2 );
896 else if ( style ==
"Fine Dotted" || style ==
"Ultrafine Dotted (var)" ||
897 style ==
"Line with Fine Dots" )
898 pen.setAttribute(
"style", 3 );
899 else if ( style ==
"3 Dashes 3 Dots (var)" || style ==
"Ultrafine 2 Dots 3 Dashes" )
900 pen.setAttribute(
"style", 4 );
901 else if ( style ==
"2 Dots 1 Dash" )
902 pen.setAttribute(
"style", 5 );
905 if ( m_styleStack.hasAttributeNS( ooNS::svg,
"stroke-width" ) )
906 pen.setAttribute(
"width", (
int) KoUnit::parseValue( m_styleStack.attributeNS( ooNS::svg,
"stroke-width" ) ) );
907 if ( m_styleStack.hasAttributeNS( ooNS::svg,
"stroke-color" ) )
908 pen.setAttribute(
"color", m_styleStack.attributeNS( ooNS::svg,
"stroke-color" ) );
909 e.appendChild( pen );
913void OoImpressImport::appendBrush( TQDomDocument& doc, TQDomElement& e )
915 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"fill" ) )
917 const TQString fill = m_styleStack.attributeNS( ooNS::draw,
"fill" );
919 if ( fill ==
"solid" )
921 TQDomElement brush = doc.createElement(
"BRUSH" );
922 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"transparency" ) )
924 TQString transparency = m_styleStack.attributeNS( ooNS::draw,
"transparency" );
925 transparency = transparency.remove(
'%' );
926 int value = transparency.toInt();
927 if ( value >= 94 && value <= 99 )
929 brush.setAttribute(
"style", 2 );
931 else if ( value>=64 && value <= 93 )
933 brush.setAttribute(
"style", 3 );
935 else if ( value>=51 && value <= 63 )
937 brush.setAttribute(
"style", 4 );
939 else if ( value>=38 && value <= 50 )
941 brush.setAttribute(
"style", 5 );
943 else if ( value>=13 && value <= 37 )
945 brush.setAttribute(
"style", 6 );
947 else if ( value>=7 && value <= 12 )
949 brush.setAttribute(
"style", 7 );
951 else if ( value>=1 && value <= 6 )
953 brush.setAttribute(
"style", 8 );
957 brush.setAttribute(
"style", 1 );
958 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"fill-color" ) )
959 brush.setAttribute(
"color", m_styleStack.attributeNS( ooNS::draw,
"fill-color" ) );
960 e.appendChild( brush );
962 else if ( fill ==
"hatch" )
964 TQDomElement brush = doc.createElement(
"BRUSH" );
965 TQString style = m_styleStack.attributeNS( ooNS::draw,
"fill-hatch-name" );
966 TQDomElement* draw = m_draws[style];
969 if( draw->hasAttributeNS( ooNS::draw,
"color" ) )
970 brush.setAttribute(
"color", draw->attributeNS( ooNS::draw,
"color", TQString() ) );
972 if( draw->hasAttributeNS( ooNS::draw,
"rotation" ))
974 angle = (draw->attributeNS( ooNS::draw,
"rotation", TQString() ).toInt())/10;
975 kdDebug(30518)<<
"angle :"<<angle<<endl;
977 if( draw->hasAttributeNS( ooNS::draw,
"style" ))
979 TQString styleHash = draw->attributeNS( ooNS::draw,
"style", TQString() );
980 if( styleHash ==
"single")
986 brush.setAttribute(
"style", 9 );
990 brush.setAttribute(
"style", 12 );
994 brush.setAttribute(
"style", 10 );
998 brush.setAttribute(
"style", 13 );
1002 kdDebug(30518)<<
" draw:rotation 'angle' : "<<angle<<endl;
1006 else if( styleHash ==
"double")
1014 brush.setAttribute(
"style", 11 );
1020 brush.setAttribute(
"style",14 );
1024 kdDebug(30518)<<
" draw:rotation 'angle' : "<<angle<<endl;
1029 else if( styleHash ==
"triple")
1031 kdDebug(30518)<<
" it is not implemented :( \n";
1036 e.appendChild( brush );
1038 else if ( fill ==
"gradient" )
1043 TQDomElement brush = doc.createElement(
"BRUSH" );
1044 brush.setAttribute(
"style", 1 );
1045 e.appendChild( brush );
1047 TQDomElement gradient = doc.createElement(
"GRADIENT" );
1048 TQString style = m_styleStack.attributeNS( ooNS::draw,
"fill-gradient-name" );
1050 TQDomElement* draw = m_draws[style];
1053 gradient.setAttribute(
"color1", draw->attributeNS( ooNS::draw,
"start-color", TQString() ) );
1054 gradient.setAttribute(
"color2", draw->attributeNS( ooNS::draw,
"end-color", TQString() ) );
1056 TQString type = draw->attributeNS( ooNS::draw,
"style", TQString() );
1058 if ( type ==
"linear" )
1060 int angle = draw->attributeNS( ooNS::draw,
"angle", TQString() ).toInt() / 10;
1063 angle = abs( angle );
1064 angle -= ( (int) ( angle / 360 ) ) * 360;
1068 int lower, upper, nearAngle = 0;
1069 for ( lower = 0, upper = 45; upper < 360; lower += 45, upper += 45 )
1071 if ( upper >= angle )
1073 int distanceToUpper = abs( angle - upper );
1074 int distanceToLower = abs( angle - lower );
1075 nearAngle = distanceToUpper > distanceToLower ? lower : upper;
1079 kdDebug(30518)<<
"nearAngle :"<<nearAngle<<endl;
1081 if ( nearAngle == 0 || nearAngle == 180 )
1082 gradient.setAttribute(
"type", 1 );
1083 else if ( nearAngle == 90 || nearAngle == 270 )
1084 gradient.setAttribute(
"type", 2 );
1085 else if ( nearAngle == 45 || nearAngle == 225 )
1086 gradient.setAttribute(
"type", 3 );
1087 else if ( nearAngle == 135 || nearAngle == 315 )
1088 gradient.setAttribute(
"type", 4 );
1090 else if ( type ==
"radial" || type ==
"ellipsoid" )
1091 gradient.setAttribute(
"type", 5 );
1092 else if ( type ==
"square" || type ==
"rectangular" )
1093 gradient.setAttribute(
"type", 6 );
1094 else if ( type ==
"axial" )
1095 gradient.setAttribute(
"type", 7 );
1100 if ( draw->hasAttributeNS( ooNS::draw,
"cx" ) )
1101 x = draw->attributeNS( ooNS::draw,
"cx", TQString() ).remove(
'%' ).toInt();
1105 if ( draw->hasAttributeNS( ooNS::draw,
"cy" ) )
1106 y = draw->attributeNS( ooNS::draw,
"cy", TQString() ).remove(
'%' ).toInt();
1110 if ( x == 50 && y == 50 )
1112 gradient.setAttribute(
"unbalanced", 0 );
1113 gradient.setAttribute(
"xfactor", 100 );
1114 gradient.setAttribute(
"yfactor", 100 );
1118 gradient.setAttribute(
"unbalanced", 1 );
1120 gradient.setAttribute(
"xfactor", 4 * x - 200 );
1121 gradient.setAttribute(
"yfactor", 4 * y - 200 );
1124 e.appendChild( gradient );
1126 TQDomElement fillType = doc.createElement(
"FILLTYPE" );
1127 fillType.setAttribute(
"value", 1 );
1128 e.appendChild( fillType );
1133void OoImpressImport::appendPie( TQDomDocument& doc, TQDomElement& e,
const TQDomElement&
object )
1135 TQDomElement angle = doc.createElement(
"PIEANGLE" );
1136 int start = (int) (
object.attributeNS( ooNS::draw,
"start-angle", TQString() ).toDouble() );
1137 angle.setAttribute(
"value", start * 16 );
1138 e.appendChild( angle );
1140 TQDomElement length = doc.createElement(
"PIELENGTH" );
1141 int end = (int) (
object.attributeNS( ooNS::draw,
"end-angle", TQString() ).toDouble() );
1143 length.setAttribute(
"value", ( 360 - start + end ) * 16 );
1145 length.setAttribute(
"value", ( end - start ) * 16 );
1146 e.appendChild( length );
1149void OoImpressImport::appendImage( TQDomDocument& doc, TQDomElement& e, TQDomElement& p,
1150 const TQDomElement&
object )
1152 TQString fileName = storeImage(
object );
1155 TQTime time = TQTime::currentTime();
1156 TQDate date = TQDate::currentDate();
1158 TQDomElement image = doc.createElement(
"KEY" );
1159 image.setAttribute(
"msec", time.msec() );
1160 image.setAttribute(
"second", time.second() );
1161 image.setAttribute(
"minute", time.minute() );
1162 image.setAttribute(
"hour", time.hour() );
1163 image.setAttribute(
"day", date.day() );
1164 image.setAttribute(
"month", date.month() );
1165 image.setAttribute(
"year", date.year() );
1166 image.setAttribute(
"filename", fileName );
1167 e.appendChild( image );
1169 TQDomElement settings = doc.createElement(
"PICTURESETTINGS" );
1170 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"color-mode" ) && ( m_styleStack.attributeNS( ooNS::draw,
"color-mode" )==
"greyscale" ) )
1171 settings.setAttribute(
"grayscal", 1 );
1173 settings.setAttribute(
"grayscal", 0 );
1175 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"luminance" ) )
1177 TQString str( m_styleStack.attributeNS( ooNS::draw,
"luminance" ) );
1178 str = str.remove(
'%' );
1179 settings.setAttribute(
"bright", str );
1182 settings.setAttribute(
"bright", 0 );
1184 settings.setAttribute(
"mirrorType", 0 );
1185 settings.setAttribute(
"swapRGB", 0 );
1186 settings.setAttribute(
"depth", 0 );
1187 e.appendChild( settings );
1189 TQDomElement effects = doc.createElement(
"EFFECTS" );
1190 bool hasEffect =
false;
1191 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"contrast" ) )
1193 TQString str( m_styleStack.attributeNS( ooNS::draw,
"contrast" ) );
1194 str = str.remove(
'%' );
1195 int val = str.toInt();
1196 val = ( int )( 255.0 *val/100.0 );
1197 effects.setAttribute(
"type",
"5" );
1198 effects.setAttribute(
"param1", TQString::number( val ) );
1202 e.appendChild( effects );
1204 TQDomElement key = image.cloneNode().toElement();
1205 key.setAttribute(
"name",
"pictures/" + fileName );
1206 p.appendChild( key );
1209void OoImpressImport::appendBackgroundImage( TQDomDocument& doc, TQDomElement& e,
1210 TQDomElement& p,
const TQDomElement&
object )
1212 TQString fileName = storeImage(
object );
1215 TQTime time = TQTime::currentTime();
1216 TQDate date = TQDate::currentDate();
1218 TQDomElement image = doc.createElement(
"BACKPICTUREKEY" );
1219 image.setAttribute(
"msec", time.msec() );
1220 image.setAttribute(
"second", time.second() );
1221 image.setAttribute(
"minute", time.minute() );
1222 image.setAttribute(
"hour", time.hour() );
1223 image.setAttribute(
"day", date.day() );
1224 image.setAttribute(
"month", date.month() );
1225 image.setAttribute(
"year", date.year() );
1226 image.setAttribute(
"filename", fileName );
1227 e.appendChild( image );
1229 TQDomElement key = image.cloneNode().toElement();
1230 key.setTagName(
"KEY" );
1231 key.setAttribute(
"name",
"pictures/" + fileName );
1232 p.appendChild( key );
1235void OoImpressImport::appendBackgroundGradient( TQDomDocument& doc, TQDomElement& e,
1236 const TQDomElement&
object )
1238 TQDomElement backColor1 = doc.createElement(
"BACKCOLOR1" );
1239 backColor1.setAttribute(
"color",
object.attributeNS( ooNS::draw,
"start-color", TQString() ) );
1240 e.appendChild( backColor1 );
1242 TQDomElement backColor2 = doc.createElement(
"BACKCOLOR2" );
1243 backColor2.setAttribute(
"color",
object.attributeNS( ooNS::draw,
"end-color", TQString() ) );
1244 e.appendChild( backColor2 );
1246 TQDomElement backType = doc.createElement(
"BACKTYPE" );
1247 backType.setAttribute(
"value", 0 );
1248 e.appendChild( backType );
1250 TQDomElement bcType = doc.createElement(
"BCTYPE" );
1251 TQString type =
object.attributeNS( ooNS::draw,
"style", TQString() );
1252 if ( type ==
"linear" )
1254 int angle =
object.attributeNS( ooNS::draw,
"angle", TQString() ).toInt() / 10;
1257 angle = abs( angle );
1258 angle -= ( (int) ( angle / 360 ) ) * 360;
1262 int lower, upper, nearAngle = 0;
1263 for ( lower = 0, upper = 45; upper < 360; lower += 45, upper += 45 )
1265 if ( upper >= angle )
1267 int distanceToUpper = abs( angle - upper );
1268 int distanceToLower = abs( angle - lower );
1269 nearAngle = distanceToUpper > distanceToLower ? lower : upper;
1275 if ( nearAngle == 0 || nearAngle == 180 )
1276 bcType.setAttribute(
"value", 1 );
1277 else if ( nearAngle == 90 || nearAngle == 270 )
1278 bcType.setAttribute(
"value", 2 );
1279 else if ( nearAngle == 45 || nearAngle == 225 )
1280 bcType.setAttribute(
"value", 3 );
1281 else if ( nearAngle == 135 || nearAngle == 315 )
1282 bcType.setAttribute(
"value", 4 );
1284 else if ( type ==
"radial" || type ==
"ellipsoid" )
1285 bcType.setAttribute(
"value", 5 );
1286 else if ( type ==
"square" || type ==
"rectangular" )
1287 bcType.setAttribute(
"value", 6 );
1288 else if ( type ==
"axial" )
1289 bcType.setAttribute(
"value", 7 );
1291 e.appendChild( bcType );
1293 TQDomElement bGradient = doc.createElement(
"BGRADIENT" );
1298 if (
object.hasAttributeNS( ooNS::draw,
"cx" ) )
1299 x =
object.attributeNS( ooNS::draw,
"cx", TQString() ).remove(
'%' ).toInt();
1303 if (
object.hasAttributeNS( ooNS::draw,
"cy" ) )
1304 y =
object.attributeNS( ooNS::draw,
"cy", TQString() ).remove(
'%' ).toInt();
1308 if ( x == 50 && y == 50 )
1310 bGradient.setAttribute(
"unbalanced", 0 );
1311 bGradient.setAttribute(
"xfactor", 100 );
1312 bGradient.setAttribute(
"yfactor", 100 );
1316 bGradient.setAttribute(
"unbalanced", 1 );
1318 bGradient.setAttribute(
"xfactor", 4 * x - 200 );
1319 bGradient.setAttribute(
"yfactor", 4 * y - 200 );
1322 e.appendChild( bGradient );
1325void OoImpressImport::appendRounding( TQDomDocument& doc, TQDomElement& e,
const TQDomElement&
object )
1327 if (
object.hasAttributeNS( ooNS::draw,
"corner-radius" ) )
1330 TQDomElement rounding = doc.createElement(
"RNDS" );
1331 int corner =
static_cast<int>(KoUnit::parseValue(
object.attributeNS( ooNS::draw,
"corner-radius", TQString())));
1332 rounding.setAttribute(
"x", corner );
1333 rounding.setAttribute(
"y", corner );
1334 e.appendChild( rounding );
1338void OoImpressImport::appendShadow( TQDomDocument& doc, TQDomElement& e )
1346 if ( !e.hasAttribute(
"type" ) ||
1347 ( e.hasAttribute(
"type" ) && e.attribute(
"type" ) ==
"4" ) )
1349 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"text-shadow" ) &&
1350 m_styleStack.attributeNS( ooNS::fo,
"text-shadow" ) !=
"none" )
1353 TQDomElement shadow = doc.createElement(
"SHADOW" );
1354 TQString distance = m_styleStack.attributeNS( ooNS::fo,
"text-shadow" );
1355 distance.truncate( distance.find(
' ' ) );
1356 shadow.setAttribute(
"distance", KoUnit::parseValue( distance ) );
1357 shadow.setAttribute(
"direction", 5 );
1358 shadow.setAttribute(
"color",
"#a0a0a0" );
1359 e.appendChild( shadow );
1362 else if ( m_styleStack.hasAttributeNS( ooNS::draw,
"shadow" ) &&
1363 m_styleStack.attributeNS( ooNS::draw,
"shadow" ) ==
"visible" )
1366 TQDomElement shadow = doc.createElement(
"SHADOW" );
1367 double x = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::draw,
"shadow-offset-x" ) );
1368 double y = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::draw,
"shadow-offset-y" ) );
1370 if ( x < 0 && y < 0 )
1372 shadow.setAttribute(
"direction", 1 );
1373 shadow.setAttribute(
"distance", (
int) fabs ( x ) );
1375 else if ( x == 0 && y < 0 )
1377 shadow.setAttribute(
"direction", 2 );
1378 shadow.setAttribute(
"distance", (
int) fabs ( y ) );
1380 else if ( x > 0 && y < 0 )
1382 shadow.setAttribute(
"direction", 3 );
1383 shadow.setAttribute(
"distance", (
int) fabs ( x ) );
1385 else if ( x > 0 && y == 0 )
1387 shadow.setAttribute(
"direction", 4 );
1388 shadow.setAttribute(
"distance", (
int) fabs ( x ) );
1390 else if ( x > 0 && y > 0 )
1392 shadow.setAttribute(
"direction", 5 );
1393 shadow.setAttribute(
"distance", (
int) fabs ( x ) );
1395 else if ( x == 0 && y > 0 )
1397 shadow.setAttribute(
"direction", 6 );
1398 shadow.setAttribute(
"distance", (
int) fabs ( y ) );
1400 else if ( x < 0 && y > 0 )
1402 shadow.setAttribute(
"direction", 7 );
1403 shadow.setAttribute(
"distance", (
int) fabs ( x ) );
1405 else if ( x < 0 && y == 0 )
1407 shadow.setAttribute(
"direction", 8 );
1408 shadow.setAttribute(
"distance", (
int) fabs ( x ) );
1411 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"shadow-color" ) )
1412 shadow.setAttribute(
"color", m_styleStack.attributeNS( ooNS::draw,
"shadow-color" ) );
1414 e.appendChild( shadow );
1416 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"size-protect" ) || m_styleStack.hasAttributeNS( ooNS::draw,
"move-protect" ) )
1418 bool b = ( m_styleStack.attributeNS( ooNS::draw,
"size-protect" ) ==
"true" ) || ( m_styleStack.attributeNS( ooNS::draw,
"move-protect" ) ==
"true" );
1421 TQDomElement protect = doc.createElement(
"PROTECT" );
1422 protect.setAttribute(
"state" , b);
1423 e.appendChild(protect);
1428void OoImpressImport::appendLineEnds( TQDomDocument& doc, TQDomElement& e,
bool orderEndStartLine)
1430 const char* attr = orderEndStartLine ?
"marker-start" :
"marker-end";
1431 if ( m_styleStack.hasAttributeNS( ooNS::draw, attr ) )
1433 TQDomElement lineBegin = doc.createElement(
"LINEBEGIN" );
1434 TQString type = m_styleStack.attributeNS( ooNS::draw, attr );
1435 if ( type ==
"Arrow" || type ==
"Small Arrow" || type ==
"Rounded short Arrow" ||
1436 type ==
"Symmetric Arrow" || type ==
"Rounded large Arrow" || type ==
"Arrow concave" )
1437 lineBegin.setAttribute(
"value", 1 );
1438 else if ( type ==
"Square" )
1439 lineBegin.setAttribute(
"value", 2 );
1440 else if ( type ==
"Circle" || type ==
"Square 45" )
1441 lineBegin.setAttribute(
"value", 3 );
1442 else if ( type ==
"Line Arrow" )
1443 lineBegin.setAttribute(
"value", 4 );
1444 else if ( type ==
"Dimension Lines" )
1445 lineBegin.setAttribute(
"value", 5 );
1446 else if ( type ==
"Double Arrow" )
1447 lineBegin.setAttribute(
"value", 6 );
1448 e.appendChild( lineBegin );
1450 attr = orderEndStartLine ?
"marker-end" :
"marker-start";
1451 if ( m_styleStack.hasAttributeNS( ooNS::draw, attr ) )
1453 TQDomElement lineEnd = doc.createElement(
"LINEEND" );
1454 TQString type = m_styleStack.attributeNS( ooNS::draw, attr );
1455 if ( type ==
"Arrow" || type ==
"Small Arrow" || type ==
"Rounded short Arrow" ||
1456 type ==
"Symmetric Arrow" || type ==
"Rounded large Arrow" || type ==
"Arrow concave" )
1457 lineEnd.setAttribute(
"value", 1 );
1458 else if ( type ==
"Square" )
1459 lineEnd.setAttribute(
"value", 2 );
1460 else if ( type ==
"Circle" || type ==
"Square 45" )
1461 lineEnd.setAttribute(
"value", 3 );
1462 else if ( type ==
"Line Arrow" )
1463 lineEnd.setAttribute(
"value", 4 );
1464 else if ( type ==
"Dimension Lines" )
1465 lineEnd.setAttribute(
"value", 5 );
1466 else if ( type ==
"Double Arrow" )
1467 lineEnd.setAttribute(
"value", 6 );
1468 e.appendChild( lineEnd );
1472void OoImpressImport::appendTextObjectMargin( TQDomDocument& , TQDomElement& e )
1474 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"padding" ) )
1476 double tmpValue = KoUnit::parseValue(m_styleStack.attributeNS( ooNS::fo,
"padding" ) );
1477 e.setAttribute(
"btoppt", tmpValue );
1478 e.setAttribute(
"bbottompt", tmpValue );
1479 e.setAttribute(
"bleftpt", tmpValue );
1480 e.setAttribute(
"brightpt", tmpValue );
1484 if( m_styleStack.hasAttributeNS( ooNS::fo,
"padding-top" ) )
1485 e.setAttribute(
"btoppt", KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding-top" ) ) );
1486 if( m_styleStack.hasAttributeNS( ooNS::fo,
"padding-bottom" ) )
1487 e.setAttribute(
"bbottompt", KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding-bottom" ) ) );
1488 if( m_styleStack.hasAttributeNS( ooNS::fo,
"padding-left" ) )
1489 e.setAttribute(
"bleftpt", KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding-left" ) ) );
1490 if( m_styleStack.hasAttributeNS( ooNS::fo,
"padding-right" ) )
1491 e.setAttribute(
"brightpt", KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo,
"padding-right" ) ) );
1495TQDomElement OoImpressImport::parseTextBox( TQDomDocument& doc,
const TQDomElement& textBox )
1497 TQDomElement textObjectElement = doc.createElement(
"TEXTOBJ" );
1498 appendTextObjectMargin( doc, textObjectElement );
1501 if ( m_styleStack.hasAttributeNS( ooNS::draw,
"textarea-vertical-align" ) )
1503 TQString alignment = m_styleStack.attributeNS( ooNS::draw,
"textarea-vertical-align" );
1504 if ( alignment ==
"top" )
1505 textObjectElement.setAttribute(
"verticalAlign",
"top" );
1506 else if ( alignment ==
"middle" )
1507 textObjectElement.setAttribute(
"verticalAlign",
"center" );
1508 else if ( alignment ==
"bottom" )
1509 textObjectElement.setAttribute(
"verticalAlign",
"bottom" );
1511 textObjectElement.setAttribute(
"verticalValue", 0.0);
1514 parseParagraphs( doc, textObjectElement, textBox );
1516 return textObjectElement;
1519void OoImpressImport::parseParagraphs( TQDomDocument& doc, TQDomElement& textObjectElement,
const TQDomElement& parent )
1522 forEachElement( t, parent )
1524 m_styleStack.save();
1525 const TQString localName = t.localName();
1526 const TQString ns = t.namespaceURI();
1527 const bool isTextNS = ns == ooNS::text;
1530 if ( isTextNS && localName ==
"p" )
1531 e = parseParagraph( doc, t );
1532 else if ( isTextNS && localName ==
"h" )
1534 e = parseParagraph( doc, t );
1536 else if ( isTextNS && ( localName ==
"unordered-list" || localName ==
"ordered-list" ) )
1538 parseList( doc, textObjectElement, t );
1539 m_styleStack.restore();
1545 kdDebug(30518) <<
"Unsupported texttype '" << localName <<
"'" << endl;
1549 textObjectElement.appendChild( e );
1550 m_styleStack.restore();
1554void OoImpressImport::applyListStyle( TQDomElement& paragraph )
1557 if ( m_listStyleStack.hasListStyle() && m_nextItemIsListItem ) {
1560 m_nextItemIsListItem =
false;
1564 TQDomElement counter = paragraph.ownerDocument().createElement(
"COUNTER" );
1565 counter.setAttribute(
"numberingtype", 0 );
1566 counter.setAttribute(
"depth", 0 );
1568 if ( m_insideOrderedList )
1569 counter.setAttribute(
"type", 1 );
1571 counter.setAttribute(
"type", 10 );
1572 paragraph.appendChild( counter );
1576static TQDomElement findListLevelStyle( TQDomElement& fullListStyle,
int level )
1578 TQDomElement listLevelItem;
1579 forEachElement( listLevelItem, fullListStyle )
1581 if ( listLevelItem.attributeNS( ooNS::text,
"level", TQString() ).toInt() == level )
1582 return listLevelItem;
1584 return TQDomElement();
1587bool OoImpressImport::pushListLevelStyle(
const TQString& listStyleName,
int level )
1589 TQDomElement* fullListStyle = m_listStyles[listStyleName];
1590 if ( !fullListStyle ) {
1591 kdWarning(30518) <<
"List style " << listStyleName <<
" not found!" << endl;
1595 return pushListLevelStyle( listStyleName, *fullListStyle, level );
1598bool OoImpressImport::pushListLevelStyle(
const TQString& listStyleName,
1599 TQDomElement& fullListStyle,
int level )
1603 TQDomElement listLevelStyle;
1604 while ( i > 0 && listLevelStyle.isNull() ) {
1605 listLevelStyle = findListLevelStyle( fullListStyle, i );
1608 if ( listLevelStyle.isNull() ) {
1609 kdWarning(30518) <<
"List level style for level " << level <<
" in list style " << listStyleName <<
" not found!" << endl;
1612 kdDebug(30518) <<
"Pushing list-level-style from list-style " << listStyleName <<
" level " << level << endl;
1613 m_listStyleStack.push( listLevelStyle );
1617void OoImpressImport::parseList( TQDomDocument& doc, TQDomElement& textObjectElement,
const TQDomElement& list )
1621 m_insideOrderedList = ( list.localName() ==
"ordered-list" );
1622 TQString oldListStyleName = m_currentListStyleName;
1623 if ( list.hasAttributeNS( ooNS::text,
"style-name" ) )
1624 m_currentListStyleName = list.attributeNS( ooNS::text,
"style-name", TQString() );
1625 bool listOK = !m_currentListStyleName.isEmpty();
1626 const int level = m_listStyleStack.level() + 1;
1629 listOK = pushListLevelStyle( m_currentListStyleName, level );
1632 TQDomElement listItem;
1633 forEachElement( listItem, list )
1636 m_nextItemIsListItem = ( listItem.localName() !=
"list-header" );
1637 m_restartNumbering = -1;
1638 if ( listItem.hasAttributeNS( ooNS::text,
"start-value" ) )
1639 m_restartNumbering = listItem.attributeNS( ooNS::text,
"start-value", TQString() ).toInt();
1641 parseParagraphs( doc, textObjectElement, listItem );
1642 m_restartNumbering = -1;
1645 m_listStyleStack.pop();
1646 m_currentListStyleName = oldListStyleName;
1649TQDomElement OoImpressImport::parseParagraph( TQDomDocument& doc,
const TQDomElement& paragraph )
1651 TQDomElement p = doc.createElement(
"P" );
1654 fillStyleStack( paragraph );
1657 TQString styleName = m_styleStack.userStyleName(
"paragraph");
1658 if ( !styleName.isEmpty() )
1660 TQDomElement nameElem = doc.createElement(
"NAME");
1661 nameElem.setAttribute(
"value", styleName);
1662 p.appendChild(nameElem);
1666 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"text-align" ) )
1668 TQString align = m_styleStack.attributeNS( ooNS::fo,
"text-align" );
1669 if ( align ==
"center" )
1670 p.setAttribute(
"align", 4 );
1671 else if ( align ==
"justify" )
1672 p.setAttribute(
"align", 8 );
1673 else if ( align ==
"start" )
1674 p.setAttribute(
"align", 0 );
1675 else if ( align ==
"end" )
1676 p.setAttribute(
"align", 2 );
1679 p.setAttribute(
"align", 0 );
1683 OoUtils::importTopBottomMargin( p, m_styleStack );
1686 OoUtils::importIndents( p, m_styleStack );
1689 OoUtils::importLineSpacing( p, m_styleStack );
1692 OoUtils::importTabulators( p, m_styleStack );
1695 OoUtils::importBorders( p, m_styleStack );
1697 applyListStyle( p );
1701 m_styleStack.save();
1703 parseSpanOrSimilar( doc, paragraph, p, pos);
1704 m_styleStack.restore();
1709void OoImpressImport::parseSpanOrSimilar( TQDomDocument& doc,
const TQDomElement& parent,
1710 TQDomElement& outputParagraph, uint& pos)
1714 for( TQDomNode node = parent.firstChild(); !node.isNull(); node = node.nextSibling() )
1716 TQDomElement ts = node.toElement();
1718 const TQString localName( ts.localName() );
1719 const TQString ns = ts.namespaceURI();
1720 const bool isTextNS = ns == ooNS::text;
1721 TQDomText t = node.toText();
1724 if ( isTextNS && localName ==
"span" )
1726 m_styleStack.save();
1727 fillStyleStack( ts );
1728 parseSpanOrSimilar( doc, ts, outputParagraph, pos);
1729 m_styleStack.restore();
1731 else if ( isTextNS && localName ==
"s" )
1733 textData = OoUtils::expandWhitespace(ts);
1735 else if ( isTextNS && localName ==
"tab-stop" )
1742 else if ( isTextNS && localName ==
"line-break" )
1746 else if ( localName ==
"image" && ns == ooNS::draw )
1751 else if ( isTextNS && localName ==
"a" )
1753 m_styleStack.save();
1754 TQString href( ts.attributeNS( ooNS::xlink,
"href", TQString()) );
1755 if ( href.startsWith(
"#") )
1759 parseSpanOrSimilar( doc, ts, outputParagraph, pos);
1766 TQDomElement fakeParagraph, fakeFormats;
1769 parseSpanOrSimilar( doc, ts, fakeParagraph, fakeFormats, text, fakePos);
1771 TQDomElement linkElement (doc.createElement(
"LINK"));
1772 linkElement.setAttribute(
"hrefName",ts.attributeNS( ooNS::xlink,
"href", TQString()));
1773 linkElement.setAttribute(
"linkName",text);
1774 appendVariable(doc, ts, pos,
"STRING", 9, text, linkElement);
1777 m_styleStack.restore();
1779 else if ( isTextNS &&
1780 (localName ==
"date"
1781 || localName ==
"time"
1782 || localName ==
"page-number"
1783 || localName ==
"file-name"
1784 || localName ==
"author-name"
1785 || localName ==
"author-initials" ) )
1788 appendField(doc, outputParagraph, ts, pos);
1790 else if ( t.isNull() )
1792 kdWarning(30518) <<
"Ignoring tag " << ts.tagName() << endl;
1796 textData = t.data();
1798 pos += textData.length();
1800 TQDomElement text = saveHelper(textData, doc);
1802 kdDebug(30518) << k_funcinfo <<
"Para text is: " << textData << endl;
1804 if (m_styleStack.hasAttributeNS( ooNS::fo,
"language" )) {
1805 TQString lang = m_styleStack.attributeNS( ooNS::fo,
"language" );
1807 text.setAttribute(
"language",
"en_US");
1809 text.setAttribute(
"language", lang);
1813 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"color" ) ) {
1814 kdDebug(30518) <<
"color=" << m_styleStack.attributeNS( ooNS::fo,
"color" ) << endl;
1815 text.setAttribute(
"color", m_styleStack.attributeNS( ooNS::fo,
"color" ) );
1817 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-family" )
1818 || m_styleStack.hasAttributeNS( ooNS::style,
"font-name") )
1822 if ( m_styleStack.attributeNS( ooNS::fo,
"font-family" ) ==
"Thorndale" )
1823 text.setAttribute(
"family",
"Times New Roman" );
1824 else if ( m_styleStack.attributeNS( ooNS::fo,
"font-family" ) ==
"Albany" )
1825 text.setAttribute(
"family",
"Arial" );
1827 text.setAttribute(
"family", m_styleStack.attributeNS( ooNS::fo,
"font-family" ).remove(
"'" ) );
1829 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-size" ) )
1831 double pointSize = m_styleStack.fontSize();
1832 text.setAttribute(
"pointSize", tqRound(pointSize) );
1834 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-weight" ) )
1835 if ( m_styleStack.attributeNS( ooNS::fo,
"font-weight" ) ==
"bold" )
1836 text.setAttribute(
"bold", 1 );
1837 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-style" ) )
1838 if ( m_styleStack.attributeNS( ooNS::fo,
"font-style" ) ==
"italic" )
1839 text.setAttribute(
"italic", 1 );
1841 if ( m_styleStack.hasAttributeNS( ooNS::style,
"text-position" ) )
1843 TQString text_position = m_styleStack.attributeNS( ooNS::style,
"text-position");
1845 TQString relativetextsize;
1846 OoUtils::importTextPosition( text_position, value, relativetextsize );
1847 text.setAttribute(
"VERTALIGN", value );
1848 if ( !relativetextsize.isEmpty() )
1849 text.setAttribute(
"relativetextsize", relativetextsize );
1852 bool wordByWord = (m_styleStack.hasAttributeNS( ooNS::fo,
"score-spaces"))
1853 && (m_styleStack.attributeNS( ooNS::fo,
"score-spaces") ==
"false");
1856 if ( m_styleStack.hasAttributeNS( ooNS::style,
"text-crossing-out")
1857 && m_styleStack.attributeNS( ooNS::style,
"text-crossing-out") !=
"none")
1859 TQString strikeOutType = m_styleStack.attributeNS( ooNS::style,
"text-crossing-out" );
1860 if ( strikeOutType ==
"double-line" )
1862 text.setAttribute(
"strikeOut",
"double" );
1863 text.setAttribute(
"strikeoutstyleline",
"solid" );
1865 else if ( strikeOutType ==
"thick-line" )
1867 text.setAttribute(
"strikeOut",
"single-bold" );
1868 text.setAttribute(
"strikeoutstyleline",
"solid" );
1872 text.setAttribute(
"strikeOut",
"single" );
1873 text.setAttribute(
"strikeoutstyleline",
"solid" );
1877 text.setAttribute(
"wordbyword", 1);
1881 if ( m_styleStack.hasAttributeNS( ooNS::style,
"text-underline" ) )
1885 OoUtils::importUnderline( m_styleStack.attributeNS( ooNS::style,
"text-underline" ),
1886 underline, styleline );
1887 TQString underLineColor = m_styleStack.attributeNS( ooNS::style,
"text-underline-color" );
1889 text.setAttribute(
"value", underline );
1890 text.setAttribute(
"styleline", styleline );
1892 if ( !underLineColor.isEmpty() && underLineColor !=
"font-color" )
1893 text.setAttribute(
"underlinecolor", underLineColor);
1895 text.setAttribute(
"wordbyword", 1);
1899 if ( m_styleStack.hasAttributeNS( ooNS::fo,
"font-variant" )
1900 || m_styleStack.hasAttributeNS( ooNS::fo,
"text-transform" ) )
1902 TQDomElement fontAttrib( doc.createElement(
"FONTATTRIBUTE" ) );
1903 bool smallCaps = m_styleStack.attributeNS( ooNS::fo,
"font-variant" ) ==
"small-caps";
1906 text.setAttribute(
"fontattribute",
"smallcaps" );
1911 text.setAttribute(
"fontattribute", m_styleStack.attributeNS( ooNS::fo,
"text-transform" ) );
1916 if (m_styleStack.hasAttributeNS( ooNS::fo,
"background-color" ))
1918 TQString bgColor = m_styleStack.attributeNS( ooNS::fo,
"background-color");
1919 if (bgColor !=
"transparent")
1920 text.setAttribute(
"textbackcolor", bgColor);
1923 appendShadow( doc, outputParagraph );
1924 outputParagraph.appendChild( text );
1928void OoImpressImport::createStyleMap( TQDomDocument &docstyles )
1930 TQDomElement styles = docstyles.documentElement();
1931 if ( styles.isNull() )
1934 TQDomNode fixedStyles = KoDom::namedItemNS( styles, ooNS::office,
"styles" );
1935 if ( !fixedStyles.isNull() )
1937 insertDraws( fixedStyles.toElement() );
1938 insertStyles( fixedStyles.toElement() );
1939 insertStylesPresentation( fixedStyles.toElement() );
1942 TQDomNode automaticStyles = KoDom::namedItemNS( styles, ooNS::office,
"automatic-styles" );
1943 if ( !automaticStyles.isNull() )
1945 insertStyles( automaticStyles.toElement() );
1946 insertStylesPresentation( automaticStyles.toElement() );
1948 TQDomNode masterStyles = KoDom::namedItemNS( styles, ooNS::office,
"master-styles" );
1949 if ( !masterStyles.isNull() )
1950 insertStyles( masterStyles.toElement() );
1953void OoImpressImport::insertDraws(
const TQDomElement& styles )
1956 forEachElement( e, styles )
1958 if ( !e.hasAttributeNS( ooNS::draw,
"name" ) )
1961 TQString name = e.attributeNS( ooNS::draw,
"name", TQString() );
1962 m_draws.insert( name,
new TQDomElement( e ) );
1966void OoImpressImport::insertStyles(
const TQDomElement& styles )
1969 forEachElement( e, styles )
1971 const TQString localName = e.localName();
1972 const TQString ns = e.namespaceURI();
1973 if ( !e.hasAttributeNS( ooNS::style,
"name" ) )
1976 const TQString name = e.attributeNS( ooNS::style,
"name", TQString() );
1977 if ( localName ==
"list-style" && ns == ooNS::text ) {
1978 TQDomElement* ep =
new TQDomElement( e );
1979 m_listStyles.insert( name, ep );
1980 kdDebug(30518) <<
"List style: '" << name <<
"' loaded " << endl;
1984 m_styles.insert( name,
new TQDomElement( e ) );
1985 kdDebug(30518) <<
"Style: '" << name <<
"' loaded " << endl;
1990void OoImpressImport::insertStylesPresentation(
const TQDomElement& styles )
1993 forEachElement( e, styles )
1995 if ( !e.hasAttributeNS( ooNS::style,
"name" ) )
1998 TQString name = e.attributeNS( ooNS::style,
"name", TQString() );
1999 m_stylesPresentation.insert( name,
new TQDomElement( e ) );
2004void OoImpressImport::fillStyleStack(
const TQDomElement&
object,
bool sticky )
2007 if (
object.hasAttributeNS( ooNS::presentation,
"style-name" ) )
2009 kdDebug(30518)<<
" presentation:style-name **************************** :"<<
object.attributeNS( ooNS::presentation,
"style-name", TQString() )<<endl;
2011 addStyles( m_stylesPresentation[
object.attributeNS( ooNS::presentation,
"style-name", TQString() )] );
2013 addStyles( m_styles[
object.attributeNS( ooNS::presentation,
"style-name", TQString() )] );
2015 if (
object.hasAttributeNS( ooNS::draw,
"style-name" ) )
2016 addStyles( m_styles[
object.attributeNS( ooNS::draw,
"style-name", TQString() )] );
2018 if (
object.hasAttributeNS( ooNS::draw,
"text-style-name" ) )
2019 addStyles( m_styles[
object.attributeNS( ooNS::draw,
"text-style-name", TQString() )] );
2021 if (
object.hasAttributeNS( ooNS::text,
"style-name" ) ) {
2022 TQString styleName =
object.attributeNS( ooNS::text,
"style-name", TQString() );
2024 addStyles( m_styles[styleName] );
2028void OoImpressImport::addStyles(
const TQDomElement* style )
2030 kdDebug(30518)<<
" addStyle :" << style->attributeNS( ooNS::style,
"name", TQString() ) <<endl;
2032 if ( style->hasAttributeNS( ooNS::style,
"parent-style-name" ) )
2035 addStyles( m_styles[style->attributeNS( ooNS::style,
"parent-style-name", TQString() )] );
2038 m_styleStack.push( *style );
2041TQString OoImpressImport::storeImage(
const TQDomElement&
object )
2044 TQString url =
object.attributeNS( ooNS::xlink,
"href", TQString() ).remove(
'#' );
2045 KArchiveFile* file = (KArchiveFile*) m_zip->directory()->entry( url );
2047 TQString extension = url.mid( url.find(
'.' ) );
2048 TQString fileName = TQString(
"picture%1" ).arg( m_numPicture++ ) + extension;
2049 KoStoreDevice* out = m_chain->storageFile(
"pictures/" + fileName, KoStore::Write );
2053 TQByteArray buffer = file->data();
2054 out->writeBlock( buffer.data(), buffer.size() );
2060TQString OoImpressImport::storeSound(
const TQDomElement &
object, TQDomElement & p, TQDomDocument & doc)
2062 TQFileInfo fi(m_chain->inputFile());
2063 TQDir::setCurrent(fi.dirPath(
true));
2064 fi.setFile(
object.attributeNS( ooNS::xlink,
"href", TQString()));
2065 TQString url = fi.absFilePath();
2073 TQString extension = url.mid( url.find(
'.' ) );
2074 TQString fileName = TQString(
"sound%1" ).arg( m_numSound++ ) + extension;
2075 fileName =
"sounds/" + fileName;
2076 KoStoreDevice* out = m_chain->storageFile( fileName, KoStore::Write );
2080 if (!file.open(IO_ReadOnly))
2083 TQByteArray data(8*1024);
2086 for (
int block = 0; ( block = file.readBlock(data.data(), data.size()) ) > 0;
2088 out->writeBlock(data.data(), data.size());
2090 Q_ASSERT(total == fi.size());
2097 TQDomElement key = doc.createElement(
"FILE");
2098 key.setAttribute(
"name", fileName);
2099 key.setAttribute(
"filename", url);
2105TQDomElement OoImpressImport::saveHelper(
const TQString &tmpText, TQDomDocument &doc)
2107 TQDomElement element=doc.createElement(
"TEXT");
2109 if(tmpText.stripWhiteSpace().isEmpty())
2111 element.setAttribute(
"whitespace", tmpText.length());
2113 element.appendChild(doc.createTextNode(tmpText));
2117void OoImpressImport::appendPoints(TQDomDocument& doc, TQDomElement& e,
const TQDomElement&
object)
2119 TQDomElement ptsElem = doc.createElement(
"POINTS");
2121 TQStringList ptList = TQStringList::split(
' ',
object.attributeNS( ooNS::draw,
"points", TQString()));
2123 TQString pt_x, pt_y;
2124 double tmp_x, tmp_y;
2125 for (TQStringList::Iterator it = ptList.begin(); it != ptList.end(); ++it)
2127 TQDomElement point = doc.createElement(
"Point");
2129 tmp_x = (*it).section(
',',0,0).toInt() / 100;
2130 tmp_y = (*it).section(
',',1,1).toInt() / 100;
2138 point.setAttribute(
"point_x", KoUnit::parseValue(pt_x));
2139 point.setAttribute(
"point_y", KoUnit::parseValue(pt_y));
2140 ptsElem.appendChild(point);
2143 e.appendChild(ptsElem);
2146void OoImpressImport::appendField(TQDomDocument& doc, TQDomElement& e,
const TQDomElement&
object, uint pos)
2148 const TQString tag =
object.localName();
2149 const TQString ns =
object.namespaceURI();
2150 const bool isTextNS = ns == ooNS::text;
2152 TQDomElement custom = doc.createElement(
"CUSTOM");
2153 custom.setAttribute(
"pos", pos);
2154 TQDomElement variable = doc.createElement(
"VARIABLE");
2156 if (isTextNS && tag ==
"date")
2158 TQDateTime dt(TQDate::fromString(
object.attributeNS( ooNS::text,
"date-value", TQString()), TQt::ISODate));
2160 bool fixed = (
object.hasAttributeNS( ooNS::text,
"fixed") &&
object.attributeNS( ooNS::text,
"fixed", TQString())==
"true");
2162 if (!dt.isValid()) {
2163 dt = TQDateTime::currentDateTime();
2167 TQDomElement typeElem = doc.createElement(
"TYPE");
2168 typeElem.setAttribute(
"key",
"DATE0locale");
2169 typeElem.setAttribute(
"type", 0);
2170 typeElem.setAttribute(
"text",
object.text());
2172 variable.appendChild(typeElem);
2174 const TQDate date(dt.date());
2175 const TQTime time(dt.time());
2176 TQDomElement dateElement = doc.createElement(
"DATE");
2177 dateElement.setAttribute(
"subtype", fixed ? 0 : 1);
2178 dateElement.setAttribute(
"fix", fixed ? 1 : 0);
2179 dateElement.setAttribute(
"day", date.day());
2180 dateElement.setAttribute(
"month", date.month());
2181 dateElement.setAttribute(
"year", date.year());
2182 dateElement.setAttribute(
"hour", time.hour());
2183 dateElement.setAttribute(
"minute", time.minute());
2184 dateElement.setAttribute(
"second", time.second());
2185 if (
object.hasAttributeNS( ooNS::text,
"date-adjust"))
2186 dateElement.setAttribute(
"correct",
object.attributeNS( ooNS::text,
"date-adjust", TQString()));
2188 variable.appendChild(dateElement);
2190 else if (isTextNS && tag ==
"time")
2193 TQDateTime dt(TQDateTime::fromString(
object.attributeNS( ooNS::text,
"time-value", TQString()), TQt::ISODate));
2195 bool fixed = (
object.hasAttributeNS( ooNS::text,
"fixed") &&
object.attributeNS( ooNS::text,
"fixed", TQString())==
"true");
2197 if (!dt.isValid()) {
2198 dt = TQDateTime::currentDateTime();
2202 TQDomElement typeElem = doc.createElement(
"TYPE");
2203 typeElem.setAttribute(
"key",
"TIMElocale");
2204 typeElem.setAttribute(
"type", 2);
2205 typeElem.setAttribute(
"text",
object.text());
2207 variable.appendChild(typeElem);
2209 const TQTime time(dt.time());
2210 TQDomElement timeElement = doc.createElement(
"TIME");
2211 timeElement.setAttribute(
"subtype", fixed ? 0 : 1);
2212 timeElement.setAttribute(
"fix", fixed ? 1 : 0);
2213 timeElement.setAttribute(
"hour", time.hour());
2214 timeElement.setAttribute(
"minute", time.minute());
2215 timeElement.setAttribute(
"second", time.second());
2219 variable.appendChild(timeElement);
2221 else if (isTextNS && tag ==
"page-number")
2223 TQDomElement typeElem = doc.createElement(
"TYPE");
2224 typeElem.setAttribute(
"key",
"NUMBER");
2225 typeElem.setAttribute(
"type", 4);
2226 typeElem.setAttribute(
"text",
object.text());
2228 variable.appendChild(typeElem);
2230 TQDomElement pgNumElem = doc.createElement(
"PGNUM");
2234 if (
object.hasAttributeNS( ooNS::text,
"select-page"))
2236 const TQString select =
object.attributeNS( ooNS::text,
"select-page", TQString());
2238 if (select ==
"previous")
2240 else if (select ==
"next")
2246 pgNumElem.setAttribute(
"subtype", subtype);
2247 pgNumElem.setAttribute(
"value",
object.text());
2249 variable.appendChild(pgNumElem);
2251 else if (isTextNS && tag ==
"file-name")
2253 TQDomElement typeElem = doc.createElement(
"TYPE");
2254 typeElem.setAttribute(
"key",
"STRING");
2255 typeElem.setAttribute(
"type", 8);
2256 typeElem.setAttribute(
"text",
object.text());
2258 variable.appendChild(typeElem);
2262 if (
object.hasAttributeNS( ooNS::text,
"display"))
2264 const TQString display =
object.attributeNS( ooNS::text,
"display", TQString());
2266 if (display ==
"path")
2268 else if (display ==
"name")
2270 else if (display ==
"name-and-extension")
2276 TQDomElement fileNameElem = doc.createElement(
"FIELD");
2277 fileNameElem.setAttribute(
"subtype", subtype);
2278 fileNameElem.setAttribute(
"value",
object.text());
2280 variable.appendChild(fileNameElem);
2282 else if (isTextNS && tag ==
"author-name"
2283 || isTextNS && tag ==
"author-initials")
2285 TQDomElement typeElem = doc.createElement(
"TYPE");
2286 typeElem.setAttribute(
"key",
"STRING");
2287 typeElem.setAttribute(
"type", 8);
2288 typeElem.setAttribute(
"text",
object.text());
2290 variable.appendChild(typeElem);
2294 if (isTextNS && tag ==
"author-initials")
2297 TQDomElement authorElem = doc.createElement(
"FIELD");
2298 authorElem.setAttribute(
"subtype", subtype);
2299 authorElem.setAttribute(
"value",
object.text());
2301 variable.appendChild(authorElem);
2304 custom.appendChild(variable);
2305 e.appendChild(custom);
2308void OoImpressImport::createPresentationAnimation(
const TQDomElement& element)
2312 forEachElement( e, element )
2314 const TQString localName = e.localName();
2315 const TQString ns = e.namespaceURI();
2316 if ( ns == ooNS::presentation && localName ==
"show-shape" && e.hasAttributeNS( ooNS::draw,
"shape-id" ) )
2318 TQString name = e.attributeNS( ooNS::draw,
"shape-id", TQString() );
2320 animationList *lst =
new animationList;
2321 TQDomElement* ep =
new TQDomElement( e );
2324 m_animations.insert( name, lst );
2330TQDomElement OoImpressImport::findAnimationByObjectID(
const TQString &
id,
int & order)
2332 kdDebug(30518)<<
"TQDomElement OoImpressImport::findAnimationByObjectID(const TQString & id) :"<<
id<<endl;
2333 if (m_animations.isEmpty() )
2334 return TQDomElement();
2336 animationList *animation = m_animations[id];
2339 return TQDomElement();
2340 for (TQDomNode node = *( animation->element ); !node.isNull(); node = node.nextSibling())
2342 TQDomElement e = node.toElement();
2343 order = animation->order;
2344 kdDebug(30518)<<
"e.tagName() :"<<e.tagName()<<
" e.attribute(draw:shape-id) :"<<e.attributeNS( ooNS::draw,
"shape-id", TQString())<<endl;
2345 if (e.tagName()==
"presentation:show-shape" && e.attributeNS( ooNS::draw,
"shape-id", TQString())==
id)
2349 return TQDomElement();
2353void OoImpressImport::appendObjectEffect(TQDomDocument& doc, TQDomElement& e,
const TQDomElement&
object,
2354 TQDomElement& sound)
2357 TQDomElement origEffect = findAnimationByObjectID(
object.attributeNS( ooNS::draw,
"id", TQString()), order).toElement();
2359 if (origEffect.isNull())
2362 TQString effect = origEffect.attributeNS( ooNS::presentation,
"effect", TQString());
2363 TQString dir = origEffect.attributeNS( ooNS::presentation,
"direction", TQString());
2364 TQString speed = origEffect.attributeNS( ooNS::presentation,
"speed", TQString());
2365 kdDebug(30518)<<
"speed :"<<speed<<endl;
2372 if (dir==
"from-right")
2374 else if (dir==
"from-left")
2376 else if (dir==
"from-top")
2378 else if (dir==
"from-bottom")
2383 else if (effect==
"move")
2385 if (dir==
"from-right")
2387 else if (dir==
"from-left")
2389 else if (dir==
"from-top")
2391 else if (dir==
"from-bottom")
2393 else if (dir==
"from-upper-right")
2395 else if (dir==
"from-lower-right")
2397 else if (dir==
"from-upper-left")
2399 else if (dir==
"from-lower-left")
2407 TQDomElement effElem = doc.createElement(
"EFFECTS");
2408 effElem.setAttribute(
"effect", effVal);
2409 e.appendChild(effElem);
2411 TQDomElement presNum = doc.createElement(
"PRESNUM" );
2412 presNum.setAttribute(
"value", order);
2413 e.appendChild( presNum );
2416 TQDomElement origSoundEff = KoDom::namedItemNS( origEffect, ooNS::presentation,
"sound");
2417 if (!origSoundEff.isNull())
2419 TQString soundUrl = storeSound(origSoundEff, sound, doc);
2421 if (!soundUrl.isNull())
2423 TQDomElement pseElem = doc.createElement(
"APPEARSOUNDEFFECT");
2424 pseElem.setAttribute(
"appearSoundEffect", 1);
2425 pseElem.setAttribute(
"appearSoundFileName", soundUrl);
2427 e.appendChild(pseElem);
2432#include "ooimpressimport.moc"