237
175
QDomElement content = m_content.documentElement();
239
177
// content.xml contains some automatic-styles that we need to store
240
QDomNode automaticStyles = content.namedItem( "office:automatic-styles" );
178
QDomNode automaticStyles = KoDom::namedItemNS( content, ooNS::office, "automatic-styles" );
241
179
if ( !automaticStyles.isNull() )
242
180
insertStyles( automaticStyles.toElement() );
244
QDomNode body = content.namedItem( "office:body" );
182
QDomNode body = KoDom::namedItemNS( content, ooNS::office, "body" );
245
183
if ( body.isNull() )
186
QDomElement customSlideShow = doc.createElement( "CUSTOMSLIDESHOWCONFIG" );
248
188
// presentation settings
249
QDomElement settings = body.namedItem("presentation:settings").toElement();
189
QDomElement settings = KoDom::namedItemNS( body, ooNS::presentation, "settings");
250
190
if (!settings.isNull())
252
if (settings.attribute("presentation:endless")=="true")
192
if (settings.attributeNS( ooNS::presentation, "endless", QString::null)=="true")
254
194
QDomElement infElem = doc.createElement("INFINITLOOP");
255
195
infElem.setAttribute("value", 1);
256
196
docElement.appendChild(infElem);
259
if (settings.attribute("presentation:force-manual")=="true")
199
if (settings.attributeNS( ooNS::presentation, "force-manual", QString::null)=="true")
261
201
QDomElement manualElem = doc.createElement("MANUALSWITCH");
262
202
manualElem.setAttribute("value", 1);
263
203
docElement.appendChild(manualElem);
205
if ( settings.hasAttributeNS( ooNS::presentation, "show") )
207
QDomElement defaultPage = doc.createElement("DEFAULTCUSTOMSLIDESHOWNAME");
208
defaultPage.setAttribute("name", settings.attributeNS( ooNS::presentation, "show", QString::null) );
209
docElement.appendChild(defaultPage);
213
QDomElement presentationShow;
214
forEachElement( presentationShow, settings )
216
if ( presentationShow.localName()=="show" && presentationShow.namespaceURI() == ooNS::presentation )
218
if ( presentationShow.hasAttributeNS( ooNS::presentation, "pages") &&
219
presentationShow.hasAttributeNS( ooNS::presentation, "name"))
221
QDomElement slide=doc.createElement("CUSTOMSLIDESHOW");
222
slide.setAttribute( "pages", presentationShow.attributeNS( ooNS::presentation, "pages", QString::null ));
223
slide.setAttribute( "name", presentationShow.attributeNS( ooNS::presentation, "name", QString::null ));
224
customSlideShow.appendChild( slide );
267
228
// it seems that ooimpress has different paper-settings for every slide.
268
229
// we take the settings of the first slide for the whole document.
269
QDomNode drawPage = body.namedItem( "draw:page" );
230
QDomElement drawPage = KoDom::namedItemNS( body, ooNS::draw, "page" );
270
231
if ( drawPage.isNull() ) // no slides? give up.
273
QDomElement dp = drawPage.toElement();
274
QDomElement *master = m_styles[dp.attribute( "draw:master-page-name" )];
275
QDomElement *style = m_styles[master->attribute( "style:page-master-name" )];
276
QDomElement properties = style->namedItem( "style:properties" ).toElement();
277
QDomElement *backgroundStyle = m_styles[ "Standard-background"];
234
QDomElement objectElement = doc.createElement( "OBJECTS" );
235
QDomElement pictureElement = doc.createElement( "PICTURES" );
236
QDomElement pageTitleElement = doc.createElement( "PAGETITLES" );
237
QDomElement pageNoteElement = doc.createElement( "PAGENOTES" );
238
QDomElement backgroundElement = doc.createElement( "BACKGROUND" );
239
QDomElement soundElement = doc.createElement( "SOUNDS" );
240
QDomElement selSlideElement = doc.createElement( "SELSLIDES" );
241
QDomElement helpLineElement = doc.createElement( "HELPLINES" );
242
QDomElement attributeElement = doc.createElement( "ATTRIBUTES" );
243
QDomElement *master = m_styles[drawPage.attributeNS( ooNS::draw, "master-page-name", QString::null )];
245
appendObject(*master, doc, soundElement,pictureElement,pageNoteElement,objectElement, 0, true);
247
QDomElement *style = m_styles[master->attributeNS( ooNS::style, "page-master-name", QString::null )];
248
QDomElement properties = KoDom::namedItemNS( *style, ooNS::style, "properties" );
249
//kdDebug(30518)<<" master->attribute( draw:style-name ) :"<<master->attributeNS( ooNS::draw, "style-name", QString::null )<<endl;
250
QDomElement *backgroundStyle = m_stylesPresentation[ master->attributeNS( ooNS::draw, "style-name", QString::null ).isEmpty() ? "Standard-background" : master->attributeNS( ooNS::draw, "style-name", QString::null ) ];
252
//kdDebug(30518)<<" backgroundStyle :"<<backgroundStyle<<endl;
279
253
double pageHeight;
280
254
QDomElement paperElement = doc.createElement( "PAPER" );
281
255
if ( properties.isNull() )
306
280
// Keep pageHeight in cm to avoid rounding-errors that would
307
281
// get multiplied with every new slide.
309
if (properties.attribute("style:print-orientation")=="portrait")
283
if (properties.attributeNS( ooNS::style, "print-orientation", QString::null)=="portrait")
310
284
paperElement.setAttribute("orientation", 0);
311
else if (properties.attribute("style:print-orientation")=="landscape")
285
else if (properties.attributeNS( ooNS::style, "print-orientation", QString::null)=="landscape")
312
286
paperElement.setAttribute("orientation", 1);
314
pageHeight = properties.attribute( "fo:page-height" ).remove( "cm" ).toDouble();
290
pageHeight = properties.attributeNS( ooNS::fo, "page-height", QString::null ).remove( "cm" ).toDouble();
316
292
QDomElement paperBorderElement = doc.createElement( "PAPERBORDERS" );
317
paperBorderElement.setAttribute( "ptRight", KoUnit::parseValue( properties.attribute( "fo:margin-right" ) ) );
318
paperBorderElement.setAttribute( "ptBottom", KoUnit::parseValue( properties.attribute( "fo:margin-bottom" ) ) );
319
paperBorderElement.setAttribute( "ptLeft", KoUnit::parseValue( properties.attribute( "fo:margin-left" ) ) );
320
paperBorderElement.setAttribute( "ptTop", KoUnit::parseValue( properties.attribute( "fo:margin-top" ) ) );
293
paperBorderElement.setAttribute( "ptRight", KoUnit::parseValue( properties.attributeNS( ooNS::fo, "margin-right", QString::null ) ) );
294
paperBorderElement.setAttribute( "ptBottom", KoUnit::parseValue( properties.attributeNS( ooNS::fo, "margin-bottom", QString::null ) ) );
295
paperBorderElement.setAttribute( "ptLeft", KoUnit::parseValue( properties.attributeNS( ooNS::fo, "margin-left", QString::null ) ) );
296
paperBorderElement.setAttribute( "ptTop", KoUnit::parseValue( properties.attributeNS( ooNS::fo, "margin-top", QString::null ) ) );
321
297
paperElement.appendChild( paperBorderElement );
324
QDomElement objectElement = doc.createElement( "OBJECTS" );
325
QDomElement pictureElement = doc.createElement( "PICTURES" );
326
QDomElement pageTitleElement = doc.createElement( "PAGETITLES" );
327
QDomElement pageNoteElement = doc.createElement( "PAGENOTES" );
328
QDomElement backgroundElement = doc.createElement( "BACKGROUND" );
329
QDomElement soundElement = doc.createElement( "SOUNDS" );
331
301
// parse all pages
332
for ( drawPage = body.firstChild(); !drawPage.isNull(); drawPage = drawPage.nextSibling() )
302
forEachElement( drawPage, body )
334
dp = drawPage.toElement();
335
m_styleStack.clear(); // remove all styles
336
fillStyleStack( dp );
339
// take care of a possible page background or slide transition or sound
340
if ( m_styleStack.hasAttribute( "draw:fill" )
341
|| m_styleStack.hasAttribute( "presentation:transition-style" ))
343
appendBackgroundPage( doc, backgroundElement,pictureElement, soundElement );
345
else if ( !m_styleStack.hasAttribute( "draw:fill" ) && backgroundStyle)
348
m_styleStack.push( *backgroundStyle );
349
appendBackgroundPage( doc, backgroundElement,pictureElement, soundElement );
350
m_styleStack.restore();
351
kdDebug()<<" load standard bacground \n";
355
QDomElement titleElement = doc.createElement( "Title" );
356
titleElement.setAttribute( "title", dp.attribute( "draw:name" ) );
357
pageTitleElement.appendChild( titleElement );
359
// The '+1' is necessary to avoid that objects that start on the first line
360
// of a slide will show up on the last line of the previous slide.
361
double offset = CM_TO_POINT( ( dp.attribute( "draw:id" ).toInt() - 1 ) * pageHeight ) + 1;
363
// animations (object effects)
364
m_animations = drawPage.namedItem("presentation:animations").toElement();
367
for ( QDomNode object = drawPage.firstChild(); !object.isNull(); object = object.nextSibling() )
369
QDomElement o = object.toElement();
370
QString name = o.tagName();
371
QString drawID = o.attribute("draw:id");
375
if ( name == "draw:text-box" ) // textbox
378
e = doc.createElement( "OBJECT" );
379
e.setAttribute( "type", 4 );
380
append2DGeometry( doc, e, o, (int)offset );
381
appendName(doc, e, o);
383
appendBrush( doc, e );
384
appendRounding( doc, e, o );
385
appendShadow( doc, e );
386
appendObjectEffect(doc, e, o, soundElement);
387
e.appendChild( parseTextBox( doc, o ) );
389
else if ( name == "draw:rect" ) // rectangle
392
e = doc.createElement( "OBJECT" );
393
e.setAttribute( "type", 2 );
394
append2DGeometry( doc, e, o, (int)offset );
395
appendName(doc, e, o);
397
appendBrush( doc, e );
398
appendRounding( doc, e, o );
399
appendShadow( doc, e );
400
appendObjectEffect(doc, e, o, soundElement);
402
else if ( name == "draw:circle" || name == "draw:ellipse" )
405
e = doc.createElement( "OBJECT" );
406
append2DGeometry( doc, e, o, (int)offset );
407
appendName(doc, e, o);
409
appendShadow( doc, e );
410
appendObjectEffect(doc, e, o, soundElement);
412
if ( o.hasAttribute( "draw:kind" ) ) // pie, chord or arc
414
e.setAttribute( "type", 8 );
415
appendPie( doc, e, o );
416
QDomElement type = doc.createElement( "PIETYPE" );
418
QString kind = o.attribute( "draw:kind" );
419
if ( kind == "section" )
421
appendBrush( doc, e );
422
type.setAttribute( "value", 0 );
424
else if ( kind == "cut" )
426
appendBrush( doc, e );
427
type.setAttribute( "value", 2 );
429
else if ( kind == "arc" )
432
type.setAttribute( "value", 1 );
434
e.appendChild( type );
436
else // circle or ellipse
438
e.setAttribute( "type", 3 );
439
appendBrush( doc, e );
442
else if ( name == "draw:line" ) // line
445
e = doc.createElement( "OBJECT" );
446
e.setAttribute( "type", 1 );
447
bool orderEndStartLine = appendLineGeometry( doc, e, o, (int)offset );
448
appendName(doc, e, o);
450
appendBrush( doc, e );
451
appendShadow( doc, e );
452
appendLineEnds( doc, e, orderEndStartLine );
453
appendObjectEffect(doc, e, o, soundElement);
455
else if (name=="draw:polyline") { // polyline
457
e = doc.createElement("OBJECT");
458
e.setAttribute("type", 12);
459
append2DGeometry(doc, e, o, (int)offset);
460
appendName(doc, e, o);
461
appendPoints(doc, e, o);
464
appendLineEnds(doc, e);
465
//appendShadow(doc, e);
466
appendObjectEffect(doc, e, o, soundElement);
468
else if (name=="draw:polygon") { // polygon
470
e = doc.createElement("OBJECT");
471
e.setAttribute("type", 16);
472
append2DGeometry(doc, e, o, (int)offset);
473
appendPoints(doc, e, o);
476
//appendLineEnds(doc, e);
477
//appendShadow(doc, e);
478
appendObjectEffect(doc, e, o, soundElement);
480
else if ( name == "draw:image" ) // image
483
e = doc.createElement( "OBJECT" );
484
e.setAttribute( "type", 0 );
485
append2DGeometry( doc, e, o, (int)offset );
486
appendName(doc, e, o);
487
appendImage( doc, e, pictureElement, o );
488
appendObjectEffect(doc, e, o, soundElement);
490
else if ( name == "presentation:notes" ) // notes
492
QDomNode textBox = o.namedItem( "draw:text-box" );
493
if ( !textBox.isNull() )
496
for ( QDomNode text = textBox.firstChild(); !text.isNull(); text = text.nextSibling() )
498
// We don't care about styles as they are not supported in kpresenter.
499
// Only add a linebreak for every child.
500
QDomElement t = text.toElement();
501
note += t.text() + "\n";
503
QDomElement notesElement = doc.createElement( "Note" );
504
notesElement.setAttribute( "note", note );
505
pageNoteElement.appendChild( notesElement );
510
kdDebug(30518) << "Unsupported object '" << name << "'" << endl;
304
if ( drawPage.localName()=="page" && drawPage.namespaceURI() == ooNS::draw && drawPage.hasAttributeNS( ooNS::draw, "id" ))
306
m_styleStack.clear(); // remove all styles
307
fillStyleStack( drawPage );
309
int pagePos = drawPage.attributeNS( ooNS::draw, "id", QString::null ).toInt() - 1;
310
// take care of a possible page background or slide transition or sound
311
if ( m_styleStack.hasAttributeNS( ooNS::draw, "fill" )
312
|| m_styleStack.hasAttributeNS( ooNS::presentation, "transition-style" ))
314
appendBackgroundPage( doc, backgroundElement,pictureElement, soundElement );
316
else if ( !m_styleStack.hasAttributeNS( ooNS::draw, "fill" ) && backgroundStyle)
319
m_styleStack.push( *backgroundStyle );
320
appendBackgroundPage( doc, backgroundElement,pictureElement, soundElement );
511
321
m_styleStack.restore();
515
objectElement.appendChild( e );
322
kdDebug(30518)<<" load standard bacground \n";
324
if ( m_styleStack.hasAttributeNS( ooNS::presentation, "visibility" ) )
326
QString str = m_styleStack.attributeNS( ooNS::presentation, "visibility" );
327
QDomElement slide = doc.createElement("SLIDE");
328
slide.setAttribute( "nr", pagePos );
329
slide.setAttribute( "show", ( ( str=="hidden" ) ? "0" : "1" ));
330
selSlideElement.appendChild( slide );
333
kdDebug(30518)<<"m_styleStack.hasAttribute( presentation:visibility ) :"<<str<<" position page "<<pagePos<<endl;
336
QDomElement titleElement = doc.createElement( "Title" );
337
titleElement.setAttribute( "title", drawPage.attributeNS( ooNS::draw, "name", QString::null ) );
338
pageTitleElement.appendChild( titleElement );
340
// The '+1' is necessary to avoid that objects that start on the first line
341
// of a slide will show up on the last line of the previous slide.
342
double offset = CM_TO_POINT( ( drawPage.attributeNS( ooNS::draw, "id", QString::null ).toInt() - 1 ) * pageHeight ) + 1;
344
// animations (object effects)
345
createPresentationAnimation(KoDom::namedItemNS( drawPage, ooNS::presentation, "animations") );
348
appendObject(drawPage, doc, soundElement,pictureElement,pageNoteElement,objectElement, offset);
350
//m_animations.clear();
516
351
m_styleStack.restore();
519
m_animations.clear();
520
m_styleStack.restore();
523
355
docElement.appendChild( paperElement );
524
356
docElement.appendChild( backgroundElement );
357
if ( parseSettings( doc, helpLineElement, attributeElement ) )
358
docElement.appendChild( helpLineElement );
359
docElement.appendChild( attributeElement );
525
360
docElement.appendChild( pageTitleElement );
526
361
docElement.appendChild( pageNoteElement );
527
362
docElement.appendChild( objectElement );
363
docElement.appendChild( selSlideElement );
364
docElement.appendChild( customSlideShow );
528
365
docElement.appendChild( soundElement );
529
366
docElement.appendChild( pictureElement );
531
368
doccontent.appendChild( doc );
371
bool OoImpressImport::parseSettings( QDomDocument &doc, QDomElement &helpLineElement, QDomElement &attributeElement )
373
bool foundElement = false;
374
KoOasisSettings settings( m_settings, ooNS::office, ooNS::config );
375
KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
376
//setUnit(KoUnit::unit(viewSettings.parseConfigItemString("unit")));
377
KoOasisSettings::IndexedMap viewMap = viewSettings.indexedMap( "Views" );
378
KoOasisSettings::Items firstView = viewMap.entry( 0 );
379
//<config:config-item config:name="SnapLinesDrawing" config:type="string">V7939H1139</config:config-item>
380
//by default show line
382
if ( !firstView.isNull() )
384
QString str = firstView.parseConfigItemString( "SnapLinesDrawing" );
385
if ( !str.isEmpty() )
387
parseHelpLine( doc, helpLineElement, str );
388
//display it by default
389
helpLineElement.setAttribute( "show", true );
393
int gridX = firstView.parseConfigItemInt( "GridFineWidth" );
394
int gridY = firstView.parseConfigItemInt( "GridFineHeight" );
395
bool snapToGrid = firstView.parseConfigItemBool( "IsSnapToGrid" );
396
int selectedPage = firstView.parseConfigItemInt( "SelectedPage" );
398
attributeElement.setAttribute( "activePage", selectedPage );
399
attributeElement.setAttribute( "gridx", MM_TO_POINT( gridX / 100.0 ) );
400
attributeElement.setAttribute( "gridy", MM_TO_POINT( gridY / 100.0 ) );
401
attributeElement.setAttribute( "snaptogrid", (int)snapToGrid );
405
//kdDebug(30518)<<" gridX :"<<gridX<<" gridY :"<<gridY<<" snapToGrid :"<<snapToGrid<<" selectedPage :"<<selectedPage<<endl;
409
void OoImpressImport::parseHelpLine( QDomDocument &doc,QDomElement &helpLineElement, const QString &text )
412
int newPos = text.length()-1; //start to element = 1
413
for ( int pos = text.length()-1; pos >=0;--pos )
415
if ( text[pos]=='P' )
419
str = text.mid( pos+1, ( newPos-pos ) );
420
QDomElement point=doc.createElement("HelpPoint");
422
//kdDebug(30518)<<" point element :"<< str <<endl;
423
QStringList listVal = QStringList::split( ",", str );
424
int posX = ( listVal[0].toInt()/100 );
425
int posY = ( listVal[1].toInt()/100 );
426
point.setAttribute("posX", MM_TO_POINT( posX ));
427
point.setAttribute("posY", MM_TO_POINT( posY ));
429
helpLineElement.appendChild( point );
432
else if ( text[pos]=='V' )
434
QDomElement lines=doc.createElement("Vertical");
436
str = text.mid( pos+1, ( newPos-pos ) );
437
//kdDebug(30518)<<" vertical :"<< str <<endl;
438
int posX = ( str.toInt()/100 );
439
lines.setAttribute( "value", MM_TO_POINT( posX ) );
440
helpLineElement.appendChild( lines );
445
else if ( text[pos]=='H' )
448
QDomElement lines=doc.createElement("Horizontal");
449
str = text.mid( pos+1, ( newPos-pos ) );
450
//kdDebug(30518)<<" horizontal :"<< str <<endl;
451
int posY = ( str.toInt()/100 );
452
lines.setAttribute( "value", MM_TO_POINT( posY ) );
453
helpLineElement.appendChild( lines );
459
void OoImpressImport::appendObject(QDomNode & drawPage, QDomDocument & doc, QDomElement & soundElement, QDomElement & pictureElement, QDomElement & pageNoteElement, QDomElement &objectElement, double offset, bool sticky)
462
forEachElement( o, drawPage )
464
const QString localName = o.localName();
465
const QString ns = o.namespaceURI();
466
const QString drawID = o.attributeNS( ooNS::draw, "id", QString::null);
470
if ( localName == "text-box" && ns == ooNS::draw ) // textbox
472
fillStyleStack( o, sticky );
473
e = doc.createElement( "OBJECT" );
474
e.setAttribute( "type", 4 );
476
e.setAttribute( "sticky", "1" );
477
append2DGeometry( doc, e, o, (int)offset );
478
appendName(doc, e, o);
480
appendBrush( doc, e );
481
appendRounding( doc, e, o );
482
appendShadow( doc, e );
483
appendObjectEffect(doc, e, o, soundElement);
484
e.appendChild( parseTextBox( doc, o ) );
486
else if ( localName == "rect" && ns == ooNS::draw ) // rectangle
488
fillStyleStack( o, sticky );
489
e = doc.createElement( "OBJECT" );
490
e.setAttribute( "type", 2 );
492
e.setAttribute( "sticky", "1" );
493
append2DGeometry( doc, e, o, (int)offset );
494
appendName(doc, e, o);
496
appendBrush( doc, e );
497
appendRounding( doc, e, o );
498
appendShadow( doc, e );
500
appendObjectEffect(doc, e, o, soundElement);
502
else if ( ( localName == "circle" || localName == "ellipse" ) && ns == ooNS::draw )
504
fillStyleStack( o, sticky );
505
e = doc.createElement( "OBJECT" );
507
e.setAttribute( "sticky", "1" );
508
append2DGeometry( doc, e, o, (int)offset );
509
appendName(doc, e, o);
511
appendShadow( doc, e );
512
appendLineEnds( doc, e );
513
appendObjectEffect(doc, e, o, soundElement);
515
if ( o.hasAttributeNS( ooNS::draw, "kind" ) ) // pie, chord or arc
517
e.setAttribute( "type", 8 );
518
appendPie( doc, e, o );
519
QDomElement type = doc.createElement( "PIETYPE" );
521
QString kind = o.attributeNS( ooNS::draw, "kind", QString::null );
522
if ( kind == "section" )
524
appendBrush( doc, e );
525
type.setAttribute( "value", 0 );
527
else if ( kind == "cut" )
529
appendBrush( doc, e );
530
type.setAttribute( "value", 2 );
532
else if ( kind == "arc" )
535
type.setAttribute( "value", 1 );
537
e.appendChild( type );
539
else // circle or ellipse
541
e.setAttribute( "type", 3 );
542
appendBrush( doc, e );
545
else if ( localName == "line" && ns == ooNS::draw ) // line
547
fillStyleStack( o, sticky );
548
e = doc.createElement( "OBJECT" );
549
e.setAttribute( "type", 1 );
551
e.setAttribute( "sticky", "1" );
552
bool orderEndStartLine = appendLineGeometry( doc, e, o, (int)offset );
553
appendName(doc, e, o);
555
appendBrush( doc, e );
556
appendShadow( doc, e );
557
appendLineEnds( doc, e, orderEndStartLine );
558
appendObjectEffect(doc, e, o, soundElement);
560
else if ( localName=="polyline" && ns == ooNS::draw ) { // polyline
561
fillStyleStack(o, sticky);
562
e = doc.createElement("OBJECT");
563
e.setAttribute("type", 12);
565
e.setAttribute( "sticky", "1" );
566
append2DGeometry(doc, e, o, (int)offset);
567
appendName(doc, e, o);
568
appendPoints(doc, e, o);
571
appendLineEnds(doc, e);
572
//appendShadow(doc, e);
573
appendObjectEffect(doc, e, o, soundElement);
575
else if ( localName=="polygon" && ns == ooNS::draw ) { // polygon
576
fillStyleStack(o, sticky);
577
e = doc.createElement("OBJECT");
578
e.setAttribute("type", 16);
580
e.setAttribute( "sticky", "1" );
581
append2DGeometry(doc, e, o, (int)offset);
582
appendName(doc, e, o);
583
appendPoints(doc, e, o);
586
//appendLineEnds(doc, e);
587
//appendShadow(doc, e);
588
appendObjectEffect(doc, e, o, soundElement);
590
else if ( localName == "image" && ns == ooNS::draw ) // image
592
fillStyleStack( o, sticky );
593
e = doc.createElement( "OBJECT" );
594
e.setAttribute( "type", 0 );
596
e.setAttribute( "sticky", "1" );
597
append2DGeometry( doc, e, o, (int)offset );
598
appendName(doc, e, o);
599
appendImage( doc, e, pictureElement, o );
600
appendObjectEffect(doc, e, o, soundElement);
602
else if ( localName == "object" && ns == ooNS::draw )
604
//todo add part object
606
else if ( localName == "g" && ns == ooNS::draw )
608
//todo add group object
610
else if ( localName == "path" && ns == ooNS::draw )
612
//todo add path object (freehand/cubic/quadricbeziercurve
614
else if ( localName == "notes" && ns == ooNS::presentation ) // notes
616
QDomNode textBox = KoDom::namedItemNS( o, ooNS::draw, "text-box" );
617
if ( !textBox.isNull() )
621
forEachElement( t, textBox )
623
// We don't care about styles as they are not supported in kpresenter.
624
// Only add a linebreak for every child.
625
note += t.text() + "\n";
627
QDomElement notesElement = doc.createElement( "Note" );
628
notesElement.setAttribute( "note", note );
629
pageNoteElement.appendChild( notesElement );
634
kdDebug(30518) << "Unsupported object '" << localName << "'" << endl;
635
m_styleStack.restore();
639
objectElement.appendChild( e );
640
m_styleStack.restore();
534
644
void OoImpressImport::appendBackgroundPage( QDomDocument &doc, QDomElement &backgroundElement, QDomElement & pictureElement, QDomElement &soundElement)
536
646
QDomElement bgPage = doc.createElement( "PAGE" );
539
if ( m_styleStack.hasAttribute( "draw:fill" ) )
649
if ( m_styleStack.hasAttributeNS( ooNS::draw, "fill" ) )
541
const QString fill = m_styleStack.attribute( "draw:fill" );
651
const QString fill = m_styleStack.attributeNS( ooNS::draw, "fill" );
542
652
if ( fill == "solid" )
544
654
QDomElement backColor1 = doc.createElement( "BACKCOLOR1" );
545
backColor1.setAttribute( "color", m_styleStack.attribute( "draw:fill-color" ) );
655
backColor1.setAttribute( "color", m_styleStack.attributeNS( ooNS::draw, "fill-color" ) );
546
656
bgPage.appendChild( backColor1 );
548
658
QDomElement bcType = doc.createElement( "BCTYPE" );
1306
1505
textObjectElement.setAttribute("verticalValue", 0.0);
1309
for ( QDomNode text = textBox.firstChild(); !text.isNull(); text = text.nextSibling() )
1508
parseParagraphs( doc, textObjectElement, textBox );
1510
return textObjectElement;
1513
void OoImpressImport::parseParagraphs( QDomDocument& doc, QDomElement& textObjectElement, const QDomElement& parent )
1516
forEachElement( t, parent )
1311
QDomElement t = text.toElement();
1312
QString name = t.tagName();
1518
m_styleStack.save();
1519
const QString localName = t.localName();
1520
const QString ns = t.namespaceURI();
1521
const bool isTextNS = ns == ooNS::text;
1315
if ( name == "text:p" ) // text paragraph
1316
e = parseParagraph( doc, t );
1317
else if ( name == "text:h" ) // heading - can this happen in ooimpress?
1319
e = parseParagraph( doc, t );
1321
else if ( name == "text:unordered-list" || name == "text:ordered-list" ) // listitem
1322
e = parseList( doc, t );
1524
if ( isTextNS && localName == "p" ) // text paragraph
1525
e = parseParagraph( doc, t );
1526
else if ( isTextNS && localName == "h" ) // heading - can this happen in ooimpress?
1528
e = parseParagraph( doc, t );
1530
else if ( isTextNS && ( localName == "unordered-list" || localName == "ordered-list" ) )
1532
parseList( doc, textObjectElement, t );
1533
m_styleStack.restore();
1323
1536
// TODO text:sequence-decls
1326
kdDebug(30518) << "Unsupported texttype '" << name << "'" << endl;
1330
textObjectElement.appendChild( e );
1333
return textObjectElement;
1336
QDomElement OoImpressImport::parseList( QDomDocument& doc, const QDomElement& list )
1338
//kdDebug(30518) << k_funcinfo << "parsing list"<< endl;
1341
if ( list.tagName() == "text:ordered-list" )
1346
// take care of nested lists
1347
// ### DF: I think this doesn't take care of them the right way. We need to save/parse-whole-list/restore.
1349
for ( QDomNode n = list.firstChild(); !n.isNull(); n = n.firstChild() )
1352
QString name = e.tagName();
1353
if ( name == "text:unordered-list" )
1356
// parse the list-properties
1357
fillStyleStack( e );
1359
else if ( name == "text:ordered-list" )
1362
// parse the list-properties
1363
fillStyleStack( e );
1365
if ( name == "text:p" )
1368
// ### Where are the sibling paragraphs of 'e' parsed?
1370
QDomElement p = parseParagraph( doc, e );
1372
QDomElement counter = doc.createElement( "COUNTER" );
1373
counter.setAttribute( "numberingtype", 0 );
1374
counter.setAttribute( "depth", 0 );
1377
counter.setAttribute( "type", 1 );
1379
counter.setAttribute( "type", 10 );
1381
// Don't 'appendChild()'! Text elements have to be the last children of the
1382
// paragraph element otherwise kpresenter will cut off the last character of
1384
p.insertBefore( counter, QDomNode() );
1539
kdDebug(30518) << "Unsupported texttype '" << localName << "'" << endl;
1543
textObjectElement.appendChild( e );
1544
m_styleStack.restore(); // remove the styles added by the paragraph or list
1548
void OoImpressImport::applyListStyle( QDomElement& paragraph )
1550
// Spec: see 3.3.5 p137
1551
if ( m_listStyleStack.hasListStyle() && m_nextItemIsListItem ) {
1552
//const QDomElement listStyle = m_listStyleStack.currentListStyle();
1553
bool heading = paragraph.localName() == "h";
1554
m_nextItemIsListItem = false;
1555
int level = heading ? paragraph.attributeNS( ooNS::text, "level", QString::null ).toInt()
1556
: m_listStyleStack.level();
1558
QDomElement counter = paragraph.ownerDocument().createElement( "COUNTER" );
1559
counter.setAttribute( "numberingtype", 0 );
1560
counter.setAttribute( "depth", 0 );
1562
if ( m_insideOrderedList )
1563
counter.setAttribute( "type", 1 );
1565
counter.setAttribute( "type", 10 ); // a disc bullet
1566
paragraph.appendChild( counter );
1570
static QDomElement findListLevelStyle( QDomElement& fullListStyle, int level )
1572
QDomElement listLevelItem;
1573
forEachElement( listLevelItem, fullListStyle )
1575
if ( listLevelItem.attributeNS( ooNS::text, "level", QString::null ).toInt() == level )
1576
return listLevelItem;
1578
return QDomElement();
1581
bool OoImpressImport::pushListLevelStyle( const QString& listStyleName, int level )
1583
QDomElement* fullListStyle = m_listStyles[listStyleName];
1584
if ( !fullListStyle ) {
1585
kdWarning(30518) << "List style " << listStyleName << " not found!" << endl;
1589
return pushListLevelStyle( listStyleName, *fullListStyle, level );
1592
bool OoImpressImport::pushListLevelStyle( const QString& listStyleName, // for debug only
1593
QDomElement& fullListStyle, int level )
1595
// Find applicable list-level-style for level
1597
QDomElement listLevelStyle;
1598
while ( i > 0 && listLevelStyle.isNull() ) {
1599
listLevelStyle = findListLevelStyle( fullListStyle, i );
1602
if ( listLevelStyle.isNull() ) {
1603
kdWarning(30518) << "List level style for level " << level << " in list style " << listStyleName << " not found!" << endl;
1606
kdDebug(30518) << "Pushing list-level-style from list-style " << listStyleName << " level " << level << endl;
1607
m_listStyleStack.push( listLevelStyle );
1611
void OoImpressImport::parseList( QDomDocument& doc, QDomElement& textObjectElement, const QDomElement& list )
1613
//kdDebug(30518) << k_funcinfo << "parseList"<< endl;
1615
m_insideOrderedList = ( list.localName() == "ordered-list" );
1616
QString oldListStyleName = m_currentListStyleName;
1617
if ( list.hasAttributeNS( ooNS::text, "style-name" ) )
1618
m_currentListStyleName = list.attributeNS( ooNS::text, "style-name", QString::null );
1619
bool listOK = !m_currentListStyleName.isEmpty();
1620
const int level = m_listStyleStack.level() + 1;
1621
//kdDebug(30518) << k_funcinfo << " listOK=" << listOK << " level=" << level << endl;
1623
listOK = pushListLevelStyle( m_currentListStyleName, level );
1625
// Iterate over list items
1626
QDomElement listItem;
1627
forEachElement( listItem, list )
1629
// It's either list-header (normal text on top of list) or list-item
1630
m_nextItemIsListItem = ( listItem.localName() != "list-header" );
1631
m_restartNumbering = -1;
1632
if ( listItem.hasAttributeNS( ooNS::text, "start-value" ) )
1633
m_restartNumbering = listItem.attributeNS( ooNS::text, "start-value", QString::null ).toInt();
1634
// ### Oasis: can be p h or list only.
1635
parseParagraphs( doc, textObjectElement, listItem );
1636
m_restartNumbering = -1;
1639
m_listStyleStack.pop();
1640
m_currentListStyleName = oldListStyleName;
1389
1643
QDomElement OoImpressImport::parseParagraph( QDomDocument& doc, const QDomElement& paragraph )
1612
if ( m_styleStack.hasAttribute( "style:text-underline" ) )
1875
if ( m_styleStack.hasAttributeNS( ooNS::style, "text-underline" ) ) // 3.10.22
1614
QString underType = m_styleStack.attribute( "style:text-underline" );
1615
QString underLineColor = m_styleStack.attribute( "style:text-underline-color" );
1616
if ( underType == "single" )
1618
text.setAttribute( "underline", 1 );
1619
text.setAttribute( "underlinestyleline", "solid" );
1620
text.setAttribute( "underlinecolor", underLineColor );
1622
else if ( underType == "double" )
1624
text.setAttribute( "underline", "double" );
1625
text.setAttribute( "underlinestyleline", "solid" );
1626
text.setAttribute( "underlinecolor", underLineColor );
1628
else if ( underType == "bold" )
1630
text.setAttribute( "underline", "single-bold" );
1631
text.setAttribute( "underlinestyleline", "solid" );
1632
text.setAttribute( "underlinecolor", underLineColor );
1634
else if ( underType == "wave" )
1636
text.setAttribute( "underline", "wave" );
1637
text.setAttribute( "underlinestyleline", "solid" );
1638
text.setAttribute( "underlinecolor", underLineColor );
1640
else if ( underType == "dotted" )
1642
text.setAttribute( "underline", 1 );
1643
text.setAttribute( "underlinestyleline", "dot" );
1644
text.setAttribute( "underlinecolor", underLineColor );
1647
else if ( underType == "dash" )
1649
text.setAttribute( "underline", 1 );
1650
text.setAttribute( "underlinestyleline", "dash" );
1651
text.setAttribute( "underlinecolor", underLineColor );
1653
else if ( underType == "dot-dash" )
1655
text.setAttribute( "underline", 1 );
1656
text.setAttribute( "underlinestyleline", "dash" );
1657
text.setAttribute( "underlinecolor", underLineColor );
1659
else if ( underType == "bold-dotted" )
1661
text.setAttribute( "underline", "single-bold" );
1662
text.setAttribute( "underlinestyleline", "dot" );
1663
text.setAttribute( "underlinecolor", underLineColor );
1879
OoUtils::importUnderline( m_styleStack.attributeNS( ooNS::style, "text-underline" ),
1880
underline, styleline );
1881
QString underLineColor = m_styleStack.attributeNS( ooNS::style, "text-underline-color" );// 3.10.23
1883
text.setAttribute( "value", underline );
1884
text.setAttribute( "styleline", styleline );
1886
if ( !underLineColor.isEmpty() && underLineColor != "font-color" )
1887
text.setAttribute("underlinecolor", underLineColor);
1667
1889
text.setAttribute("wordbyword", 1);
1891
#if 0 // strange ooimpress doesn't implement it
1892
// Small caps, lowercase, uppercase
1893
if ( m_styleStack.hasAttributeNS( ooNS::fo, "font-variant" ) // 3.10.1
1894
|| m_styleStack.hasAttributeNS( ooNS::fo, "text-transform" ) ) // 3.10.2
1896
QDomElement fontAttrib( doc.createElement( "FONTATTRIBUTE" ) );
1897
bool smallCaps = m_styleStack.attributeNS( ooNS::fo, "font-variant" ) == "small-caps";
1900
text.setAttribute( "fontattribute", "smallcaps" );
1903
// Both KWord/KPresenter and OO use "uppercase" and "lowercase".
1904
// TODO in KWord: "capitalize".
1905
text.setAttribute( "fontattribute", m_styleStack.attributeNS( ooNS::fo, "text-transform" ) );
1670
1909
// background color (property of the paragraph in OOo, of the text in kword/kpresenter)
1671
if (m_styleStack.hasAttribute( "fo:background-color" ))
1910
if (m_styleStack.hasAttributeNS( ooNS::fo, "background-color" ))
1673
QString bgColor = m_styleStack.attribute("fo:background-color");
1912
QString bgColor = m_styleStack.attributeNS( ooNS::fo, "background-color");
1674
1913
if (bgColor != "transparent")
1675
1914
text.setAttribute("textbackcolor", bgColor);
1686
1925
if ( styles.isNull() )
1689
QDomNode fixedStyles = styles.namedItem( "office:styles" );
1928
QDomNode fixedStyles = KoDom::namedItemNS( styles, ooNS::office, "styles" );
1690
1929
if ( !fixedStyles.isNull() )
1692
1931
insertDraws( fixedStyles.toElement() );
1693
1932
insertStyles( fixedStyles.toElement() );
1933
insertStylesPresentation( fixedStyles.toElement() );
1696
QDomNode automaticStyles = styles.namedItem( "office:automatic-styles" );
1936
QDomNode automaticStyles = KoDom::namedItemNS( styles, ooNS::office, "automatic-styles" );
1697
1937
if ( !automaticStyles.isNull() )
1698
1939
insertStyles( automaticStyles.toElement() );
1700
QDomNode masterStyles = styles.namedItem( "office:master-styles" );
1940
insertStylesPresentation( automaticStyles.toElement() );
1942
QDomNode masterStyles = KoDom::namedItemNS( styles, ooNS::office, "master-styles" );
1701
1943
if ( !masterStyles.isNull() )
1702
1944
insertStyles( masterStyles.toElement() );
1705
1947
void OoImpressImport::insertDraws( const QDomElement& styles )
1707
for ( QDomNode n = styles.firstChild(); !n.isNull(); n = n.nextSibling() )
1950
forEachElement( e, styles )
1709
QDomElement e = n.toElement();
1711
if ( !e.hasAttribute( "draw:name" ) )
1952
if ( !e.hasAttributeNS( ooNS::draw, "name" ) )
1714
QString name = e.attribute( "draw:name" );
1955
QString name = e.attributeNS( ooNS::draw, "name", QString::null );
1715
1956
m_draws.insert( name, new QDomElement( e ) );
1719
1960
void OoImpressImport::insertStyles( const QDomElement& styles )
1721
for ( QDomNode n = styles.firstChild(); !n.isNull(); n = n.nextSibling() )
1723
QDomElement e = n.toElement();
1725
if ( !e.hasAttribute( "style:name" ) )
1728
QString name = e.attribute( "style:name" );
1729
m_styles.insert( name, new QDomElement( e ) );
1963
forEachElement( e, styles )
1965
const QString localName = e.localName();
1966
const QString ns = e.namespaceURI();
1967
if ( !e.hasAttributeNS( ooNS::style, "name" ) )
1970
const QString name = e.attributeNS( ooNS::style, "name", QString::null );
1971
if ( localName == "list-style" && ns == ooNS::text ) {
1972
QDomElement* ep = new QDomElement( e );
1973
m_listStyles.insert( name, ep );
1974
kdDebug(30518) << "List style: '" << name << "' loaded " << endl;
1978
m_styles.insert( name, new QDomElement( e ) );
1979
kdDebug(30518) << "Style: '" << name << "' loaded " << endl;
1984
void OoImpressImport::insertStylesPresentation( const QDomElement& styles )
1987
forEachElement( e, styles )
1989
if ( !e.hasAttributeNS( ooNS::style, "name" ) )
1992
QString name = e.attributeNS( ooNS::style, "name", QString::null );
1993
m_stylesPresentation.insert( name, new QDomElement( e ) );
1730
1994
//kdDebug(30518) << "Style: '" << name << "' loaded " << endl;
1734
void OoImpressImport::fillStyleStack( const QDomElement& object )
1998
void OoImpressImport::fillStyleStack( const QDomElement& object, bool sticky )
1736
2000
// find all styles associated with an object and push them on the stack
1737
if ( object.hasAttribute( "presentation:style-name" ) )
1738
addStyles( m_styles[object.attribute( "presentation:style-name" )] );
1740
if ( object.hasAttribute( "draw:style-name" ) )
1741
addStyles( m_styles[object.attribute( "draw:style-name" )] );
1743
if ( object.hasAttribute( "draw:text-style-name" ) )
1744
addStyles( m_styles[object.attribute( "draw:text-style-name" )] );
1746
if ( object.hasAttribute( "text:style-name" ) )
1747
addStyles( m_styles[object.attribute( "text:style-name" )] );
2001
if ( object.hasAttributeNS( ooNS::presentation, "style-name" ) )
2003
kdDebug(30518)<<" presentation:style-name **************************** :"<<object.attributeNS( ooNS::presentation, "style-name", QString::null )<<endl;
2005
addStyles( m_stylesPresentation[object.attributeNS( ooNS::presentation, "style-name", QString::null )] );
2007
addStyles( m_styles[object.attributeNS( ooNS::presentation, "style-name", QString::null )] );
2009
if ( object.hasAttributeNS( ooNS::draw, "style-name" ) )
2010
addStyles( m_styles[object.attributeNS( ooNS::draw, "style-name", QString::null )] );
2012
if ( object.hasAttributeNS( ooNS::draw, "text-style-name" ) )
2013
addStyles( m_styles[object.attributeNS( ooNS::draw, "text-style-name", QString::null )] );
2015
if ( object.hasAttributeNS( ooNS::text, "style-name" ) ) {
2016
QString styleName = object.attributeNS( ooNS::text, "style-name", QString::null );
2017
//kdDebug(30518) << "adding style " << styleName << endl;
2018
addStyles( m_styles[styleName] );
1750
2022
void OoImpressImport::addStyles( const QDomElement* style )
2024
kdDebug(30518)<<" addStyle :" << style->attributeNS( ooNS::style, "name", QString::null ) <<endl;
1752
2025
// this function is necessary as parent styles can have parents themself
1753
if ( style->hasAttribute( "style:parent-style-name" ) )
1754
addStyles( m_styles[style->attribute( "style:parent-style-name" )] );
2026
if ( style->hasAttributeNS( ooNS::style, "parent-style-name" ) )
2028
//kdDebug(30518)<<"m_styles[style->attribute( style:parent-style-name )] :"<<m_styles[style->attributeNS( ooNS::style, "parent-style-name", QString::null )]<<endl;
2029
addStyles( m_styles[style->attributeNS( ooNS::style, "parent-style-name", QString::null )] );
2031
//kdDebug(30518)<<" void OoImpressImport::addStyles( const QDomElement* style ) :"<<style<<endl;
1756
2032
m_styleStack.push( *style );
1759
2035
QString OoImpressImport::storeImage( const QDomElement& object )
1761
2037
// store the picture
1762
QString url = object.attribute( "xlink:href" ).remove( '#' );
2038
QString url = object.attributeNS( ooNS::xlink, "href", QString::null ).remove( '#' );
1763
2039
KArchiveFile* file = (KArchiveFile*) m_zip->directory()->entry( url );
1765
2041
QString extension = url.mid( url.find( '.' ) );