~ubuntu-branches/ubuntu/breezy/koffice/breezy-security

« back to all changes in this revision

Viewing changes to filters/kpresenter/ooimpress/ooimpressimport.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-10-11 14:49:50 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051011144950-lwpngbifzp8nk0ds
Tags: 1:1.4.1-0ubuntu7
* SECURITY UPDATE: fix heap based buffer overflow in the RTF importer of KWord
* Opening specially crafted RTF files in KWord can cause
  execution of abitrary code.
* Add kubuntu_01_rtfimport_heap_overflow.diff
* References:
  CAN-2005-2971
  CESA-2005-005
  http://www.koffice.org/security/advisory-20051011-1.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include <koFilterChain.h>
40
40
#include <koGlobal.h>
41
41
#include <ooutils.h>
 
42
#include <kodom.h>
 
43
#include <koOasisSettings.h>
42
44
 
43
45
typedef KGenericFactory<OoImpressImport, KoFilter> OoImpressImportFactory;
44
 
K_EXPORT_COMPONENT_FACTORY( libooimpressimport, OoImpressImportFactory( "ooimpressimport" ) )
 
46
K_EXPORT_COMPONENT_FACTORY( libooimpressimport, OoImpressImportFactory( "kofficefilters" ) )
45
47
 
46
48
 
47
49
OoImpressImport::OoImpressImport( KoFilter *, const char *, const QStringList & )
48
50
    : KoFilter(),
49
51
      m_numPicture( 1 ),
50
52
      m_numSound(1),
51
 
      m_styles( 23, true )
 
53
      m_styles( 23, true ),
 
54
      m_styleStack( ooNS::style, ooNS::fo )
52
55
{
53
56
    m_styles.setAutoDelete( true );
 
57
    m_listStyles.setAutoDelete( true );
54
58
}
55
59
 
56
60
OoImpressImport::~OoImpressImport()
57
61
{
 
62
    QDictIterator<animationList> it( m_animations ); // See QDictIterator
 
63
    for( ; it.current(); ++it )
 
64
    {
 
65
        delete it.current()->element;
 
66
    }
 
67
    m_animations.clear();
58
68
}
59
69
 
60
70
KoFilter::ConversionStatus OoImpressImport::convert( QCString const & from, QCString const & to )
61
71
{
62
72
    kdDebug(30518) << "Entering Ooimpress Import filter: " << from << " - " << to << endl;
63
73
 
64
 
    if ( from != "application/vnd.sun.xml.impress" || to != "application/x-kpresenter" )
 
74
    if ( (from != "application/vnd.sun.xml.impress" && from != "application/vnd.sun.xml.impress.template" )
 
75
                            || to != "application/x-kpresenter" )
65
76
    {
66
77
        kdWarning(30518) << "Invalid mimetypes " << from << " " << to << endl;
67
78
        return KoFilter::NotImplemented;
106
117
    if( out )
107
118
    {
108
119
        QCString content = doccontent.toCString();
109
 
        //kdDebug(30518) << " content :" << content << endl;
 
120
        kdDebug(30518) << " content :" << content << endl;
110
121
        out->writeBlock( content , content.length() );
111
122
    }
112
123
 
141
152
 
142
153
KoFilter::ConversionStatus OoImpressImport::loadAndParse(const QString& filename, QDomDocument& doc)
143
154
{
144
 
    kdDebug(30518) << "Trying to open " << filename << endl;
145
 
 
146
 
    if (!m_zip)
147
 
    {
148
 
        kdError(30518) << "No ZIP file!" << endl;
149
 
        return KoFilter::CreationError; // Should not happen
150
 
    }
151
 
 
152
 
    const KArchiveEntry* entry = m_zip->directory()->entry( filename );
153
 
    if (!entry)
154
 
    {
155
 
        kdWarning(30518) << "Entry " << filename << " not found!" << endl;
156
 
        return KoFilter::FileNotFound;
157
 
    }
158
 
    if (entry->isDirectory())
159
 
    {
160
 
        kdWarning(30518) << "Entry " << filename << " is a directory!" << endl;
161
 
        return KoFilter::WrongFormat;
162
 
    }
163
 
    const KZipFileEntry* f = static_cast<const KZipFileEntry *>(entry);
164
 
    QIODevice* io=f->device();
165
 
    kdDebug(30518) << "Entry " << filename << " has size " << f->size() << endl;
166
 
 
167
 
    // Error variables for QDomDocument::setContent
168
 
    QString errorMsg;
169
 
    int errorLine, errorColumn;
170
 
    if ( !doc.setContent( io, &errorMsg, &errorLine, &errorColumn ) )
171
 
    {
172
 
        kdError(30518) << "Parsing error in " << filename << "! Aborting!" << endl
173
 
            << " In line: " << errorLine << ", column: " << errorColumn << endl
174
 
            << " Error message: " << errorMsg << endl;
175
 
        delete io;
176
 
        return KoFilter::ParsingError;
177
 
    }
178
 
    delete io;
179
 
 
180
 
    kdDebug(30518) << "File " << filename << " loaded and parsed!" << endl;
181
 
 
182
 
    return KoFilter::OK;
 
155
    return OoUtils::loadAndParse( filename, doc, m_zip);
183
156
}
184
157
 
185
158
// Very related to OoWriterImport::createDocumentInfo
186
159
void OoImpressImport::createDocumentInfo( QDomDocument &docinfo )
187
160
{
188
 
    docinfo.appendChild( docinfo.createProcessingInstruction( "xml","version=\"1.0\" encoding=\"UTF-8\"" ) );
189
 
    QDomDocument doc = KoDocument::createDomDocument( "document-info" /*DTD name*/, "document-info" /*tag name*/, "1.1" );
190
 
 
191
 
    QDomNode meta   = m_meta.namedItem( "office:document-meta" );
192
 
    QDomNode office = meta.namedItem( "office:meta" );
193
 
 
194
 
    if ( office.isNull() )
195
 
        return;
196
 
    QDomElement elementDocInfo  = doc.documentElement();
197
 
 
198
 
    QDomElement e = office.namedItem( "dc:creator" ).toElement();
199
 
    if ( !e.isNull() && !e.text().isEmpty() )
200
 
    {
201
 
        QDomElement author = doc.createElement( "author" );
202
 
        QDomElement t = doc.createElement( "full-name" );
203
 
        author.appendChild( t );
204
 
        t.appendChild( doc.createTextNode( e.text() ) );
205
 
        elementDocInfo.appendChild( author);
206
 
    }
207
 
 
208
 
    e = office.namedItem( "dc:title" ).toElement();
209
 
    if ( !e.isNull() && !e.text().isEmpty() )
210
 
    {
211
 
        QDomElement about = doc.createElement( "about" );
212
 
        QDomElement title = doc.createElement( "title" );
213
 
        about.appendChild( title );
214
 
        title.appendChild( doc.createTextNode( e.text() ) );
215
 
        elementDocInfo.appendChild( about );
216
 
    }
217
 
#if 0
218
 
    e = office.namedItem( "dc:description" ).toElement();
219
 
    if ( !e.isNull() && !e.text().isEmpty() )
220
 
    {
221
 
 
222
 
    }
223
 
#endif
224
 
    docinfo.appendChild(doc);
225
 
 
 
161
    docinfo = KoDocument::createDomDocument( "document-info" /*DTD name*/, "document-info" /*tag name*/, "1.1" );
 
162
 
 
163
    OoUtils::createDocumentInfo(m_meta, docinfo);
226
164
    //kdDebug(30518) << " meta-info :" << m_meta.toCString() << endl;
227
165
}
228
166
 
237
175
    QDomElement content = m_content.documentElement();
238
176
 
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() );
243
181
 
244
 
    QDomNode body = content.namedItem( "office:body" );
 
182
    QDomNode body = KoDom::namedItemNS( content, ooNS::office, "body" );
245
183
    if ( body.isNull() )
246
184
        return;
247
185
 
 
186
    QDomElement customSlideShow = doc.createElement( "CUSTOMSLIDESHOWCONFIG" );
 
187
 
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())
251
191
    {
252
 
        if (settings.attribute("presentation:endless")=="true")
 
192
        if (settings.attributeNS( ooNS::presentation, "endless", QString::null)=="true")
253
193
        {
254
194
            QDomElement infElem = doc.createElement("INFINITLOOP");
255
195
            infElem.setAttribute("value", 1);
256
196
            docElement.appendChild(infElem);
257
197
        }
258
198
 
259
 
        if (settings.attribute("presentation:force-manual")=="true")
 
199
        if (settings.attributeNS( ooNS::presentation, "force-manual", QString::null)=="true")
260
200
        {
261
201
            QDomElement manualElem = doc.createElement("MANUALSWITCH");
262
202
            manualElem.setAttribute("value", 1);
263
203
            docElement.appendChild(manualElem);
264
204
        }
 
205
        if ( settings.hasAttributeNS( ooNS::presentation, "show") )
 
206
        {
 
207
            QDomElement defaultPage = doc.createElement("DEFAULTCUSTOMSLIDESHOWNAME");
 
208
            defaultPage.setAttribute("name", settings.attributeNS( ooNS::presentation, "show", QString::null) );
 
209
            docElement.appendChild(defaultPage);
 
210
        }
265
211
    }
266
212
 
 
213
    QDomElement presentationShow;
 
214
    forEachElement( presentationShow, settings )
 
215
    {
 
216
        if ( presentationShow.localName()=="show" && presentationShow.namespaceURI() == ooNS::presentation )
 
217
        {
 
218
            if ( presentationShow.hasAttributeNS( ooNS::presentation, "pages")  &&
 
219
                 presentationShow.hasAttributeNS( ooNS::presentation, "name"))
 
220
            {
 
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 );
 
225
            }
 
226
        }
 
227
    }
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.
271
232
        return;
272
233
 
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"];
278
 
 
 
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 )];
 
244
 
 
245
    appendObject(*master, doc, soundElement,pictureElement,pageNoteElement,objectElement, 0, true);
 
246
 
 
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 ) ];
 
251
 
 
252
    //kdDebug(30518)<<" backgroundStyle :"<<backgroundStyle<<endl;
279
253
    double pageHeight;
280
254
    QDomElement paperElement = doc.createElement( "PAPER" );
281
255
    if ( properties.isNull() )
297
271
    }
298
272
    else
299
273
    {
300
 
        paperElement.setAttribute( "ptWidth", KoUnit::parseValue(properties.attribute( "fo:page-width" ) ) );
301
 
        paperElement.setAttribute( "ptHeight", KoUnit::parseValue(properties.attribute( "fo:page-height" ) ) );
 
274
        paperElement.setAttribute( "ptWidth", KoUnit::parseValue(properties.attributeNS( ooNS::fo, "page-width", QString::null ) ) );
 
275
        paperElement.setAttribute( "ptHeight", KoUnit::parseValue(properties.attributeNS( ooNS::fo, "page-height", QString::null ) ) );
302
276
//         paperElement.setAttribute( "unit", 0 );
303
277
//         paperElement.setAttribute( "format", 5 );
304
278
//         paperElement.setAttribute( "tabStopValue", 42.5198 );
306
280
        // Keep pageHeight in cm to avoid rounding-errors that would
307
281
        // get multiplied with every new slide.
308
282
 
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);
313
287
 
314
 
        pageHeight = properties.attribute( "fo:page-height" ).remove( "cm" ).toDouble();
 
288
 
 
289
 
 
290
        pageHeight = properties.attributeNS( ooNS::fo, "page-height", QString::null ).remove( "cm" ).toDouble();
315
291
 
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 );
322
298
    }
323
299
 
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" );
330
300
 
331
301
    // parse all pages
332
 
    for ( drawPage = body.firstChild(); !drawPage.isNull(); drawPage = drawPage.nextSibling() )
 
302
    forEachElement( drawPage, body )
333
303
    {
334
 
        dp = drawPage.toElement();
335
 
        m_styleStack.clear(); // remove all styles
336
 
        fillStyleStack( dp );
337
 
        m_styleStack.save();
338
 
 
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" ))
342
 
        {
343
 
            appendBackgroundPage( doc, backgroundElement,pictureElement, soundElement );
344
 
        }
345
 
        else if ( !m_styleStack.hasAttribute( "draw:fill" ) && backgroundStyle)
346
 
        {
347
 
            m_styleStack.save();
348
 
            m_styleStack.push( *backgroundStyle );
349
 
            appendBackgroundPage( doc, backgroundElement,pictureElement, soundElement );
350
 
            m_styleStack.restore();
351
 
            kdDebug()<<" load standard bacground \n";
352
 
        }
353
 
 
354
 
        // set the pagetitle
355
 
        QDomElement titleElement = doc.createElement( "Title" );
356
 
        titleElement.setAttribute( "title", dp.attribute( "draw:name" ) );
357
 
        pageTitleElement.appendChild( titleElement );
358
 
 
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;
362
 
 
363
 
        // animations (object effects)
364
 
        m_animations = drawPage.namedItem("presentation:animations").toElement();
365
 
 
366
 
        // parse all objects
367
 
        for ( QDomNode object = drawPage.firstChild(); !object.isNull(); object = object.nextSibling() )
368
 
        {
369
 
            QDomElement o = object.toElement();
370
 
            QString name = o.tagName();
371
 
            QString drawID = o.attribute("draw:id");
372
 
            m_styleStack.save();
373
 
 
374
 
            QDomElement e;
375
 
            if ( name == "draw:text-box" ) // textbox
376
 
            {
377
 
                fillStyleStack( o );
378
 
                e = doc.createElement( "OBJECT" );
379
 
                e.setAttribute( "type", 4 );
380
 
                append2DGeometry( doc, e, o, (int)offset );
381
 
                appendName(doc, e, o);
382
 
                appendPen( doc, e );
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 ) );
388
 
            }
389
 
            else if ( name == "draw:rect" ) // rectangle
390
 
            {
391
 
                fillStyleStack( o );
392
 
                e = doc.createElement( "OBJECT" );
393
 
                e.setAttribute( "type", 2 );
394
 
                append2DGeometry( doc, e, o, (int)offset );
395
 
                appendName(doc, e, o);
396
 
                appendPen( doc, e );
397
 
                appendBrush( doc, e );
398
 
                appendRounding( doc, e, o );
399
 
                appendShadow( doc, e );
400
 
                appendObjectEffect(doc, e, o, soundElement);
401
 
            }
402
 
            else if ( name == "draw:circle" || name == "draw:ellipse" )
403
 
            {
404
 
                fillStyleStack( o );
405
 
                e = doc.createElement( "OBJECT" );
406
 
                append2DGeometry( doc, e, o, (int)offset );
407
 
                appendName(doc, e, o);
408
 
                appendPen( doc, e );
409
 
                appendShadow( doc, e );
410
 
                appendObjectEffect(doc, e, o, soundElement);
411
 
 
412
 
                if ( o.hasAttribute( "draw:kind" ) ) // pie, chord or arc
413
 
                {
414
 
                    e.setAttribute( "type", 8 );
415
 
                    appendPie( doc, e, o );
416
 
                    QDomElement type = doc.createElement( "PIETYPE" );
417
 
 
418
 
                    QString kind = o.attribute( "draw:kind" );
419
 
                    if ( kind == "section" )
420
 
                    {
421
 
                        appendBrush( doc, e );
422
 
                        type.setAttribute( "value", 0 );
423
 
                    }
424
 
                    else if ( kind == "cut" )
425
 
                    {
426
 
                        appendBrush( doc, e );
427
 
                        type.setAttribute( "value", 2 );
428
 
                    }
429
 
                    else if ( kind == "arc" )
430
 
                    {
431
 
                        // arc has no brush
432
 
                        type.setAttribute( "value", 1 );
433
 
                    }
434
 
                    e.appendChild( type );
435
 
                }
436
 
                else  // circle or ellipse
437
 
                {
438
 
                    e.setAttribute( "type", 3 );
439
 
                    appendBrush( doc, e );
440
 
                }
441
 
            }
442
 
            else if ( name == "draw:line" ) // line
443
 
            {
444
 
                fillStyleStack( o );
445
 
                e = doc.createElement( "OBJECT" );
446
 
                e.setAttribute( "type", 1 );
447
 
                bool orderEndStartLine = appendLineGeometry( doc, e, o, (int)offset );
448
 
                appendName(doc, e, o);
449
 
                appendPen( doc, e );
450
 
                appendBrush( doc, e );
451
 
                appendShadow( doc, e );
452
 
                appendLineEnds( doc, e, orderEndStartLine );
453
 
                appendObjectEffect(doc, e, o, soundElement);
454
 
            }
455
 
            else if (name=="draw:polyline") { // polyline
456
 
                fillStyleStack(o);
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);
462
 
                appendPen(doc, e);
463
 
                appendBrush(doc, e);
464
 
                appendLineEnds(doc, e);
465
 
                //appendShadow(doc, e);
466
 
                appendObjectEffect(doc, e, o, soundElement);
467
 
            }
468
 
            else if (name=="draw:polygon") { // polygon
469
 
                fillStyleStack(o);
470
 
                e = doc.createElement("OBJECT");
471
 
                e.setAttribute("type", 16);
472
 
                append2DGeometry(doc, e, o, (int)offset);
473
 
                appendPoints(doc, e, o);
474
 
                appendPen(doc, e);
475
 
                appendBrush(doc, e);
476
 
                //appendLineEnds(doc, e);
477
 
                //appendShadow(doc, e);
478
 
                appendObjectEffect(doc, e, o, soundElement);
479
 
            }
480
 
            else if ( name == "draw:image" ) // image
481
 
            {
482
 
                fillStyleStack( o );
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);
489
 
            }
490
 
            else if ( name == "presentation:notes" ) // notes
491
 
            {
492
 
                QDomNode textBox = o.namedItem( "draw:text-box" );
493
 
                if ( !textBox.isNull() )
494
 
                {
495
 
                    QString note;
496
 
                    for ( QDomNode text = textBox.firstChild(); !text.isNull(); text = text.nextSibling() )
497
 
                    {
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";
502
 
                    }
503
 
                    QDomElement notesElement = doc.createElement( "Note" );
504
 
                    notesElement.setAttribute( "note", note );
505
 
                    pageNoteElement.appendChild( notesElement );
506
 
                }
507
 
            }
508
 
            else
509
 
            {
510
 
                kdDebug(30518) << "Unsupported object '" << name << "'" << endl;
 
304
        if ( drawPage.localName()=="page" && drawPage.namespaceURI() == ooNS::draw && drawPage.hasAttributeNS( ooNS::draw, "id" ))
 
305
        {
 
306
            m_styleStack.clear(); // remove all styles
 
307
            fillStyleStack( drawPage );
 
308
            m_styleStack.save();
 
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" ))
 
313
            {
 
314
                appendBackgroundPage( doc, backgroundElement,pictureElement, soundElement );
 
315
            }
 
316
            else if ( !m_styleStack.hasAttributeNS( ooNS::draw, "fill" ) && backgroundStyle)
 
317
            {
 
318
                m_styleStack.save();
 
319
                m_styleStack.push( *backgroundStyle );
 
320
                appendBackgroundPage( doc, backgroundElement,pictureElement, soundElement );
511
321
                m_styleStack.restore();
512
 
                continue;
513
 
            }
514
 
 
515
 
            objectElement.appendChild( e );
 
322
                kdDebug(30518)<<" load standard bacground \n";
 
323
            }
 
324
            if ( m_styleStack.hasAttributeNS( ooNS::presentation, "visibility" ) )
 
325
            {
 
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 );
 
331
 
 
332
                //todo add support
 
333
                kdDebug(30518)<<"m_styleStack.hasAttribute( presentation:visibility ) :"<<str<<" position page "<<pagePos<<endl;
 
334
            }
 
335
            // set the pagetitle
 
336
            QDomElement titleElement = doc.createElement( "Title" );
 
337
            titleElement.setAttribute( "title", drawPage.attributeNS( ooNS::draw, "name", QString::null ) );
 
338
            pageTitleElement.appendChild( titleElement );
 
339
 
 
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;
 
343
 
 
344
            // animations (object effects)
 
345
            createPresentationAnimation(KoDom::namedItemNS( drawPage, ooNS::presentation, "animations") );
 
346
 
 
347
            // parse all objects
 
348
            appendObject(drawPage, doc, soundElement,pictureElement,pageNoteElement,objectElement, offset);
 
349
 
 
350
            //m_animations.clear();
516
351
            m_styleStack.restore();
517
352
        }
518
 
 
519
 
        m_animations.clear();
520
 
        m_styleStack.restore();
521
353
    }
522
354
 
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 );
530
367
 
531
368
    doccontent.appendChild( doc );
532
369
}
533
370
 
 
371
bool OoImpressImport::parseSettings( QDomDocument &doc, QDomElement &helpLineElement, QDomElement &attributeElement )
 
372
{
 
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
 
381
 
 
382
    if ( !firstView.isNull() )
 
383
    {
 
384
        QString str = firstView.parseConfigItemString( "SnapLinesDrawing" );
 
385
        if ( !str.isEmpty() )
 
386
        {
 
387
            parseHelpLine( doc, helpLineElement, str );
 
388
            //display it by default
 
389
            helpLineElement.setAttribute( "show", true );
 
390
            foundElement = true;
 
391
        }
 
392
 
 
393
        int gridX = firstView.parseConfigItemInt( "GridFineWidth" );
 
394
        int gridY = firstView.parseConfigItemInt( "GridFineHeight" );
 
395
        bool snapToGrid = firstView.parseConfigItemBool( "IsSnapToGrid" );
 
396
        int selectedPage = firstView.parseConfigItemInt( "SelectedPage" );
 
397
 
 
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 );
 
402
 
 
403
    }
 
404
 
 
405
    //kdDebug(30518)<<" gridX :"<<gridX<<" gridY :"<<gridY<<" snapToGrid :"<<snapToGrid<<" selectedPage :"<<selectedPage<<endl;
 
406
    return foundElement;
 
407
}
 
408
 
 
409
void OoImpressImport::parseHelpLine( QDomDocument &doc,QDomElement &helpLineElement, const QString &text )
 
410
{
 
411
    QString str;
 
412
    int newPos = text.length()-1; //start to element = 1
 
413
    for ( int pos = text.length()-1; pos >=0;--pos )
 
414
    {
 
415
        if ( text[pos]=='P' )
 
416
        {
 
417
 
 
418
            //point
 
419
            str = text.mid( pos+1, ( newPos-pos ) );
 
420
            QDomElement point=doc.createElement("HelpPoint");
 
421
 
 
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 ));
 
428
 
 
429
            helpLineElement.appendChild( point );
 
430
            newPos = pos-1;
 
431
        }
 
432
        else if ( text[pos]=='V' )
 
433
        {
 
434
            QDomElement lines=doc.createElement("Vertical");
 
435
            //vertical element
 
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 );
 
441
 
 
442
            newPos = ( pos-1 );
 
443
 
 
444
        }
 
445
        else if ( text[pos]=='H' )
 
446
        {
 
447
            //horizontal element
 
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 );
 
454
            newPos = pos-1;
 
455
        }
 
456
    }
 
457
}
 
458
 
 
459
void OoImpressImport::appendObject(QDomNode & drawPage,  QDomDocument & doc,  QDomElement & soundElement, QDomElement & pictureElement, QDomElement & pageNoteElement, QDomElement &objectElement, double offset, bool sticky)
 
460
{
 
461
    QDomElement o;
 
462
    forEachElement( o, drawPage )
 
463
    {
 
464
        const QString localName = o.localName();
 
465
        const QString ns = o.namespaceURI();
 
466
        const QString drawID = o.attributeNS( ooNS::draw, "id", QString::null);
 
467
        m_styleStack.save();
 
468
 
 
469
        QDomElement e;
 
470
        if ( localName == "text-box" && ns == ooNS::draw ) // textbox
 
471
        {
 
472
            fillStyleStack( o, sticky );
 
473
            e = doc.createElement( "OBJECT" );
 
474
            e.setAttribute( "type", 4 );
 
475
            if ( sticky )
 
476
                e.setAttribute( "sticky", "1" );
 
477
            append2DGeometry( doc, e, o, (int)offset );
 
478
            appendName(doc, e, o);
 
479
            appendPen( doc, e );
 
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 ) );
 
485
        }
 
486
        else if ( localName == "rect" && ns == ooNS::draw ) // rectangle
 
487
        {
 
488
            fillStyleStack( o, sticky );
 
489
            e = doc.createElement( "OBJECT" );
 
490
            e.setAttribute( "type", 2 );
 
491
            if ( sticky )
 
492
                e.setAttribute( "sticky", "1" );
 
493
            append2DGeometry( doc, e, o, (int)offset );
 
494
            appendName(doc, e, o);
 
495
            appendPen( doc, e );
 
496
            appendBrush( doc, e );
 
497
            appendRounding( doc, e, o );
 
498
            appendShadow( doc, e );
 
499
 
 
500
            appendObjectEffect(doc, e, o, soundElement);
 
501
        }
 
502
        else if ( ( localName == "circle" || localName == "ellipse" ) && ns == ooNS::draw )
 
503
        {
 
504
            fillStyleStack( o, sticky );
 
505
            e = doc.createElement( "OBJECT" );
 
506
            if ( sticky )
 
507
                e.setAttribute( "sticky", "1" );
 
508
            append2DGeometry( doc, e, o, (int)offset );
 
509
            appendName(doc, e, o);
 
510
            appendPen( doc, e );
 
511
            appendShadow( doc, e );
 
512
            appendLineEnds( doc, e );
 
513
            appendObjectEffect(doc, e, o, soundElement);
 
514
 
 
515
            if ( o.hasAttributeNS( ooNS::draw, "kind" ) ) // pie, chord or arc
 
516
            {
 
517
                e.setAttribute( "type", 8 );
 
518
                appendPie( doc, e, o );
 
519
                QDomElement type = doc.createElement( "PIETYPE" );
 
520
 
 
521
                QString kind = o.attributeNS( ooNS::draw, "kind", QString::null );
 
522
                if ( kind == "section" )
 
523
                {
 
524
                    appendBrush( doc, e );
 
525
                    type.setAttribute( "value", 0 );
 
526
                }
 
527
                else if ( kind == "cut" )
 
528
                {
 
529
                    appendBrush( doc, e );
 
530
                    type.setAttribute( "value", 2 );
 
531
                }
 
532
                else if ( kind == "arc" )
 
533
                {
 
534
                    // arc has no brush
 
535
                    type.setAttribute( "value", 1 );
 
536
                }
 
537
                e.appendChild( type );
 
538
            }
 
539
            else  // circle or ellipse
 
540
            {
 
541
                e.setAttribute( "type", 3 );
 
542
                appendBrush( doc, e );
 
543
            }
 
544
        }
 
545
        else if ( localName == "line" && ns == ooNS::draw ) // line
 
546
        {
 
547
            fillStyleStack( o, sticky );
 
548
            e = doc.createElement( "OBJECT" );
 
549
            e.setAttribute( "type", 1 );
 
550
            if ( sticky )
 
551
                e.setAttribute( "sticky", "1" );
 
552
            bool orderEndStartLine = appendLineGeometry( doc, e, o, (int)offset );
 
553
            appendName(doc, e, o);
 
554
            appendPen( doc, e );
 
555
            appendBrush( doc, e );
 
556
            appendShadow( doc, e );
 
557
            appendLineEnds( doc, e, orderEndStartLine );
 
558
            appendObjectEffect(doc, e, o, soundElement);
 
559
        }
 
560
        else if ( localName=="polyline" && ns == ooNS::draw ) { // polyline
 
561
            fillStyleStack(o, sticky);
 
562
            e = doc.createElement("OBJECT");
 
563
            e.setAttribute("type", 12);
 
564
            if ( sticky )
 
565
                e.setAttribute( "sticky", "1" );
 
566
            append2DGeometry(doc, e, o, (int)offset);
 
567
            appendName(doc, e, o);
 
568
            appendPoints(doc, e, o);
 
569
            appendPen(doc, e);
 
570
            appendBrush(doc, e);
 
571
            appendLineEnds(doc, e);
 
572
            //appendShadow(doc, e);
 
573
            appendObjectEffect(doc, e, o, soundElement);
 
574
        }
 
575
        else if ( localName=="polygon" && ns == ooNS::draw ) { // polygon
 
576
            fillStyleStack(o, sticky);
 
577
            e = doc.createElement("OBJECT");
 
578
            e.setAttribute("type", 16);
 
579
            if ( sticky )
 
580
                e.setAttribute( "sticky", "1" );
 
581
            append2DGeometry(doc, e, o, (int)offset);
 
582
            appendName(doc, e, o);
 
583
            appendPoints(doc, e, o);
 
584
            appendPen(doc, e);
 
585
            appendBrush(doc, e);
 
586
            //appendLineEnds(doc, e);
 
587
            //appendShadow(doc, e);
 
588
            appendObjectEffect(doc, e, o, soundElement);
 
589
        }
 
590
        else if ( localName == "image" && ns == ooNS::draw ) // image
 
591
        {
 
592
            fillStyleStack( o, sticky );
 
593
            e = doc.createElement( "OBJECT" );
 
594
            e.setAttribute( "type", 0 );
 
595
            if ( sticky )
 
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);
 
601
        }
 
602
        else if ( localName == "object" && ns == ooNS::draw )
 
603
        {
 
604
            //todo add part object
 
605
        }
 
606
        else if ( localName == "g" && ns == ooNS::draw )
 
607
        {
 
608
            //todo add group object
 
609
        }
 
610
        else if ( localName == "path" && ns == ooNS::draw )
 
611
        {
 
612
            //todo add path object (freehand/cubic/quadricbeziercurve
 
613
        }
 
614
        else if ( localName == "notes" && ns == ooNS::presentation ) // notes
 
615
        {
 
616
            QDomNode textBox = KoDom::namedItemNS( o, ooNS::draw, "text-box" );
 
617
            if ( !textBox.isNull() )
 
618
            {
 
619
                QString note;
 
620
                QDomElement t;
 
621
                forEachElement( t, textBox )
 
622
                {
 
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";
 
626
                }
 
627
                QDomElement notesElement = doc.createElement( "Note" );
 
628
                notesElement.setAttribute( "note", note );
 
629
                pageNoteElement.appendChild( notesElement );
 
630
            }
 
631
        }
 
632
        else
 
633
        {
 
634
            kdDebug(30518) << "Unsupported object '" << localName << "'" << endl;
 
635
            m_styleStack.restore();
 
636
            continue;
 
637
        }
 
638
 
 
639
        objectElement.appendChild( e );
 
640
        m_styleStack.restore();
 
641
    }
 
642
}
 
643
 
534
644
void OoImpressImport::appendBackgroundPage( QDomDocument &doc, QDomElement &backgroundElement, QDomElement & pictureElement,  QDomElement &soundElement)
535
645
{
536
646
    QDomElement bgPage = doc.createElement( "PAGE" );
537
647
 
538
648
    // background
539
 
    if ( m_styleStack.hasAttribute( "draw:fill" ) )
 
649
    if ( m_styleStack.hasAttributeNS( ooNS::draw, "fill" ) )
540
650
    {
541
 
        const QString fill = m_styleStack.attribute( "draw:fill" );
 
651
        const QString fill = m_styleStack.attributeNS( ooNS::draw, "fill" );
542
652
        if ( fill == "solid" )
543
653
        {
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 );
547
657
 
548
658
            QDomElement bcType = doc.createElement( "BCTYPE" );
555
665
        }
556
666
        else if ( fill == "gradient" )
557
667
        {
558
 
            QString style = m_styleStack.attribute( "draw:fill-gradient-name" );
 
668
            QString style = m_styleStack.attributeNS( ooNS::draw, "fill-gradient-name" );
559
669
            QDomElement* draw = m_draws[style];
560
670
            appendBackgroundGradient( doc, bgPage, *draw );
561
671
        }
562
672
        else if ( fill == "bitmap" )
563
673
        {
564
 
            QString style = m_styleStack.attribute( "draw:fill-image-name" );
 
674
            QString style = m_styleStack.attributeNS( ooNS::draw, "fill-image-name" );
565
675
            QDomElement* draw = m_draws[style];
566
676
            appendBackgroundImage( doc, bgPage, pictureElement, *draw );
567
677
 
568
678
            QDomElement backView = doc.createElement( "BACKVIEW" );
569
 
            if ( m_styleStack.hasAttribute( "style:repeat" ) )
 
679
            if ( m_styleStack.hasAttributeNS( ooNS::style, "repeat" ) )
570
680
            {
571
 
                QString repeat = m_styleStack.attribute( "style:repeat" );
 
681
                QString repeat = m_styleStack.attributeNS( ooNS::style, "repeat" );
572
682
                if ( repeat == "stretch" )
573
683
                    backView.setAttribute( "value", 0 ); // zoomed
574
684
                else if ( repeat == "no-repeat" )
586
696
        }
587
697
    }
588
698
 
 
699
    if ( m_styleStack.hasAttributeNS( ooNS::presentation, "duration" ) )
 
700
    {
 
701
        QString str = m_styleStack.attributeNS( ooNS::presentation, "duration");
 
702
        kdDebug(30518)<<"styleStack.hasAttribute(presentation:duration ) :"<<str<<endl;
 
703
        //convert date duration
 
704
            int hour( str.mid( 2, 2 ).toInt() );
 
705
            int minute( str.mid( 5, 2 ).toInt() );
 
706
            int second( str.mid( 8, 2 ).toInt() );
 
707
        int pageTimer = second + minute*60 + hour*60*60;
 
708
        QDomElement pgEffect = doc.createElement("PGTIMER");
 
709
        pgEffect.setAttribute( "timer", pageTimer );
 
710
        bgPage.appendChild(pgEffect);
 
711
    }
589
712
    // slide transition
590
 
    if (m_styleStack.hasAttribute("presentation:transition-style"))
 
713
    if (m_styleStack.hasAttributeNS( ooNS::presentation, "transition-style"))
591
714
    {
592
715
        QDomElement pgEffect = doc.createElement("PGEFFECT");
593
716
 
594
 
        const QString effect = m_styleStack.attribute("presentation:transition-style");
 
717
        const QString effect = m_styleStack.attributeNS( ooNS::presentation, "transition-style");
595
718
        //kdDebug(30518) << "Transition name: " << effect << endl;
596
719
        int pef;
597
720
 
644
767
            pef=22;
645
768
        else if (effect=="roll-from-top") // PEF_UNCOVER_DOWN
646
769
            pef=20;
 
770
        else if (effect=="random") // PEF_RANDOM
 
771
            pef=-1;
647
772
        else         // we choose a random transition instead of the unsupported ones ;)
648
773
            pef=-1;
649
774
 
652
777
    }
653
778
 
654
779
    // slide transition sound
655
 
    if (m_styleStack.hasChildNode("presentation:sound"))
 
780
    if (m_styleStack.hasChildNodeNS( ooNS::presentation, "sound"))
656
781
    {
657
 
        QString soundUrl = storeSound(m_styleStack.childNode("presentation:sound").toElement(),
 
782
        QString soundUrl = storeSound(m_styleStack.childNodeNS( ooNS::presentation, "sound"),
658
783
                                      soundElement, doc);
659
784
 
660
785
        if (!soundUrl.isNull())
672
797
 
673
798
void OoImpressImport::appendName(QDomDocument& doc, QDomElement& e, const QDomElement& object)
674
799
{
675
 
    if( object.hasAttribute( "draw:name" ))
 
800
    if( object.hasAttributeNS( ooNS::draw, "name" ))
676
801
        {
677
802
            QDomElement name = doc.createElement( "OBJECTNAME" );
678
 
            name.setAttribute( "objectName", object.attribute( "draw:name" ));
 
803
            name.setAttribute( "objectName", object.attributeNS( ooNS::draw, "name", QString::null ));
679
804
            e.appendChild( name );
680
805
        }
681
806
}
682
807
 
683
 
 
684
808
void OoImpressImport::append2DGeometry( QDomDocument& doc, QDomElement& e, const QDomElement& object, int offset )
685
809
{
686
810
    QDomElement orig = doc.createElement( "ORIG" );
687
 
    orig.setAttribute( "x", KoUnit::parseValue( object.attribute( "svg:x" ) ) );
688
 
    orig.setAttribute( "y", KoUnit::parseValue( object.attribute( "svg:y" ) ) + offset );
 
811
    orig.setAttribute( "x", KoUnit::parseValue( object.attributeNS( ooNS::svg, "x", QString::null ) ) );
 
812
    orig.setAttribute( "y", KoUnit::parseValue( object.attributeNS( ooNS::svg, "y", QString::null ) ) + offset );
689
813
    e.appendChild( orig );
690
814
 
691
815
    QDomElement size = doc.createElement( "SIZE" );
692
 
    size.setAttribute( "width", KoUnit::parseValue( object.attribute( "svg:width" ) ) );
693
 
    size.setAttribute( "height", KoUnit::parseValue( object.attribute( "svg:height" ) ) );
 
816
    size.setAttribute( "width", KoUnit::parseValue( object.attributeNS( ooNS::svg, "width", QString::null ) ) );
 
817
    size.setAttribute( "height", KoUnit::parseValue( object.attributeNS( ooNS::svg, "height", QString::null ) ) );
694
818
    e.appendChild( size );
695
 
    if( object.hasAttribute( "draw:transform" ))
 
819
    if( object.hasAttributeNS( ooNS::draw, "transform" ))
696
820
        {
697
 
            QString transform = object.attribute( "draw:transform" );
 
821
            kdDebug(30518)<<" object transform \n";
 
822
            //todo parse it
 
823
            QString transform = object.attributeNS( ooNS::draw, "transform", QString::null );
698
824
            if( transform.contains("rotate ("))
699
825
                {
 
826
                    //kdDebug(30518)<<" rotate object \n";
700
827
                    transform = transform.remove("rotate (" );
701
828
                    transform = transform.left(transform.find(")"));
 
829
                    //kdDebug(30518)<<" transform :"<<transform<<endl;
702
830
                    bool ok;
703
831
                    double radian = transform.toDouble(&ok);
704
832
                    if( ok )
711
839
                        }
712
840
                }
713
841
        }
714
 
 
715
842
}
716
843
 
717
844
//return true if (x1 < x2) necessary to load correctly start-line and end-line
718
845
bool OoImpressImport::appendLineGeometry( QDomDocument& doc, QDomElement& e, const QDomElement& object, int offset )
719
846
{
720
 
    double x1 = KoUnit::parseValue( object.attribute( "svg:x1" ) );
721
 
    double y1 = KoUnit::parseValue( object.attribute( "svg:y1" ) );
722
 
    double x2 = KoUnit::parseValue( object.attribute( "svg:x2" ) );
723
 
    double y2 = KoUnit::parseValue( object.attribute( "svg:y2" ) );
 
847
    double x1 = KoUnit::parseValue( object.attributeNS( ooNS::svg, "x1", QString::null ) );
 
848
    double y1 = KoUnit::parseValue( object.attributeNS( ooNS::svg, "y1", QString::null ) );
 
849
    double x2 = KoUnit::parseValue( object.attributeNS( ooNS::svg, "x2", QString::null ) );
 
850
    double y2 = KoUnit::parseValue( object.attributeNS( ooNS::svg, "y2", QString::null ) );
724
851
 
725
852
    double x = QMIN( x1, x2 );
726
853
    double y = QMIN( y1, y2 );
747
874
 
748
875
void OoImpressImport::appendPen( QDomDocument& doc, QDomElement& e )
749
876
{
750
 
    if ( m_styleStack.hasAttribute( "draw:stroke" ))
 
877
    if ( m_styleStack.hasAttributeNS( ooNS::draw, "stroke" ))
751
878
    {
752
879
        QDomElement pen = doc.createElement( "PEN" );
753
 
        if ( m_styleStack.attribute( "draw:stroke" ) == "none" )
 
880
        if ( m_styleStack.attributeNS( ooNS::draw, "stroke" ) == "none" )
754
881
            pen.setAttribute( "style", 0 );
755
 
        else if ( m_styleStack.attribute( "draw:stroke" ) == "solid" )
 
882
        else if ( m_styleStack.attributeNS( ooNS::draw, "stroke" ) == "solid" )
756
883
            pen.setAttribute( "style", 1 );
757
 
        else if ( m_styleStack.attribute( "draw:stroke" ) == "dash" )
 
884
        else if ( m_styleStack.attributeNS( ooNS::draw, "stroke" ) == "dash" )
758
885
        {
759
 
            QString style = m_styleStack.attribute( "draw:stroke-dash" );
 
886
            QString style = m_styleStack.attributeNS( ooNS::draw, "stroke-dash" );
760
887
            if ( style == "Ultrafine Dashed" || style == "Fine Dashed" ||
761
888
                 style == "Fine Dashed (var)" || style == "Dashed (var)" )
762
889
                pen.setAttribute( "style", 2 );
769
896
                pen.setAttribute( "style", 5 );
770
897
        }
771
898
 
772
 
        if ( m_styleStack.hasAttribute( "svg:stroke-width" ) )
773
 
            pen.setAttribute( "width", (int) KoUnit::parseValue( m_styleStack.attribute( "svg:stroke-width" ) ) );
774
 
        if ( m_styleStack.hasAttribute( "svg:stroke-color" ) )
775
 
            pen.setAttribute( "color", m_styleStack.attribute( "svg:stroke-color" ) );
 
899
        if ( m_styleStack.hasAttributeNS( ooNS::svg, "stroke-width" ) )
 
900
            pen.setAttribute( "width", (int) KoUnit::parseValue( m_styleStack.attributeNS( ooNS::svg, "stroke-width" ) ) );
 
901
        if ( m_styleStack.hasAttributeNS( ooNS::svg, "stroke-color" ) )
 
902
            pen.setAttribute( "color", m_styleStack.attributeNS( ooNS::svg, "stroke-color" ) );
776
903
        e.appendChild( pen );
777
904
    }
778
905
}
779
906
 
780
907
void OoImpressImport::appendBrush( QDomDocument& doc, QDomElement& e )
781
908
{
782
 
    if ( m_styleStack.hasAttribute( "draw:fill" ) )
 
909
    if ( m_styleStack.hasAttributeNS( ooNS::draw, "fill" ) )
783
910
    {
784
 
        const QString fill = m_styleStack.attribute( "draw:fill" );
785
 
 
786
 
        if ( fill == "solid" )
 
911
        const QString fill = m_styleStack.attributeNS( ooNS::draw, "fill" );
 
912
        //kdDebug(30518)<<"void OoImpressImport::appendBrush( QDomDocument& doc, QDomElement& e ) :"<<fill<<endl;
 
913
        if (  fill == "solid"  )
787
914
        {
788
915
            QDomElement brush = doc.createElement( "BRUSH" );
789
 
            brush.setAttribute( "style", 1 );
790
 
            if ( m_styleStack.hasAttribute( "draw:fill-color" ) )
791
 
                brush.setAttribute( "color", m_styleStack.attribute( "draw:fill-color" ) );
 
916
            if ( m_styleStack.hasAttributeNS( ooNS::draw, "transparency" ) )
 
917
            {
 
918
                QString transparency = m_styleStack.attributeNS( ooNS::draw, "transparency" );
 
919
                transparency = transparency.remove( '%' );
 
920
                int value = transparency.toInt();
 
921
                if ( value >= 94 && value <= 99 )
 
922
                {
 
923
                    brush.setAttribute( "style", 2 );
 
924
                }
 
925
                else if ( value>=64 && value <= 93 )
 
926
                {
 
927
                    brush.setAttribute( "style", 3 );
 
928
                }
 
929
                else if ( value>=51 && value <= 63 )
 
930
                {
 
931
                    brush.setAttribute( "style", 4 );
 
932
                }
 
933
                else if ( value>=38 && value <= 50 )
 
934
                {
 
935
                    brush.setAttribute( "style", 5 );
 
936
                }
 
937
                else if ( value>=13 && value <= 37 )
 
938
                {
 
939
                    brush.setAttribute( "style", 6 );
 
940
                }
 
941
                else if ( value>=7 && value <= 12 )
 
942
                {
 
943
                    brush.setAttribute( "style", 7 );
 
944
                }
 
945
                else if ( value>=1 && value <= 6 )
 
946
                {
 
947
                    brush.setAttribute( "style", 8 );
 
948
                }
 
949
            }
 
950
            else
 
951
                brush.setAttribute( "style", 1 );
 
952
            if ( m_styleStack.hasAttributeNS( ooNS::draw, "fill-color" ) )
 
953
                brush.setAttribute( "color", m_styleStack.attributeNS( ooNS::draw, "fill-color" ) );
792
954
            e.appendChild( brush );
793
955
        }
794
956
        else if ( fill == "hatch" )
795
957
        {
796
958
            QDomElement brush = doc.createElement( "BRUSH" );
797
 
            QString style = m_styleStack.attribute( "draw:fill-hatch-name" );
 
959
            QString style = m_styleStack.attributeNS( ooNS::draw, "fill-hatch-name" );
798
960
            QDomElement* draw = m_draws[style];
799
961
            if ( draw )
800
962
                {
801
 
                    if( draw->hasAttribute( "draw:color" ) )
802
 
                        brush.setAttribute( "color", draw->attribute( "draw:color" ) );
 
963
                    if( draw->hasAttributeNS( ooNS::draw, "color" ) )
 
964
                        brush.setAttribute( "color", draw->attributeNS( ooNS::draw, "color", QString::null ) );
803
965
                    int angle = 0;
804
 
                    if( draw->hasAttribute( "draw:rotation" ))
 
966
                    if( draw->hasAttributeNS( ooNS::draw, "rotation" ))
805
967
                        {
806
 
                            angle = (draw->attribute( "draw:rotation" ).toInt())/10;
807
 
                            kdDebug()<<"angle :"<<angle<<endl;
 
968
                            angle = (draw->attributeNS( ooNS::draw, "rotation", QString::null ).toInt())/10;
 
969
                            kdDebug(30518)<<"angle :"<<angle<<endl;
808
970
                        }
809
 
                    if( draw->hasAttribute( "draw:style" ))
 
971
                    if( draw->hasAttributeNS( ooNS::draw, "style" ))
810
972
                        {
811
 
                            QString styleHash = draw->attribute( "draw:style" );
 
973
                            QString styleHash = draw->attributeNS( ooNS::draw, "style", QString::null );
812
974
                            if( styleHash == "single")
813
975
                                {
814
976
                                    switch( angle )
831
993
                                            break;
832
994
                                        default:
833
995
                                            //todo fixme when we will have a kopaint
834
 
                                            kdDebug()<<" draw:rotation 'angle' : "<<angle<<endl;
 
996
                                            kdDebug(30518)<<" draw:rotation 'angle' : "<<angle<<endl;
835
997
                                            break;
836
998
                                        }
837
999
                                }
853
1015
                                            break;
854
1016
                                        default:
855
1017
                                            //todo fixme when we will have a kopaint
856
 
                                            kdDebug()<<" draw:rotation 'angle' : "<<angle<<endl;
 
1018
                                            kdDebug(30518)<<" draw:rotation 'angle' : "<<angle<<endl;
857
1019
                                            break;
858
1020
                                        }
859
1021
 
860
1022
                                }
861
1023
                            else if( styleHash == "triple")
862
1024
                                {
863
 
                                    kdDebug()<<" it is not implemented :( \n";
 
1025
                                    kdDebug(30518)<<" it is not implemented :( \n";
864
1026
                                }
865
1027
 
866
1028
                        }
867
1029
                }
868
1030
            e.appendChild( brush );
869
 
 
870
1031
        }
871
1032
        else if ( fill == "gradient" )
872
1033
        {
878
1039
            e.appendChild( brush );
879
1040
 
880
1041
            QDomElement gradient = doc.createElement( "GRADIENT" );
881
 
            QString style = m_styleStack.attribute( "draw:fill-gradient-name" );
 
1042
            QString style = m_styleStack.attributeNS( ooNS::draw, "fill-gradient-name" );
882
1043
 
883
1044
            QDomElement* draw = m_draws[style];
884
1045
            if ( draw )
885
1046
            {
886
 
                gradient.setAttribute( "color1", draw->attribute( "draw:start-color" ) );
887
 
                gradient.setAttribute( "color2", draw->attribute( "draw:end-color" ) );
 
1047
                gradient.setAttribute( "color1", draw->attributeNS( ooNS::draw, "start-color", QString::null ) );
 
1048
                gradient.setAttribute( "color2", draw->attributeNS( ooNS::draw, "end-color", QString::null ) );
888
1049
 
889
 
                QString type = draw->attribute( "draw:style" );
 
1050
                QString type = draw->attributeNS( ooNS::draw, "style", QString::null );
 
1051
                //kdDebug(30518)<<" type !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :"<<type<<endl;
890
1052
                if ( type == "linear" )
891
1053
                {
892
 
                    int angle = draw->attribute( "draw:angle" ).toInt() / 10;
 
1054
                    int angle = draw->attributeNS( ooNS::draw, "angle", QString::null ).toInt() / 10;
893
1055
 
894
1056
                    // make sure the angle is between 0 and 359
895
1057
                    angle = abs( angle );
908
1070
                            break;
909
1071
                        }
910
1072
                    }
911
 
 
 
1073
                    kdDebug(30518)<<"nearAngle :"<<nearAngle<<endl;
912
1074
                    // nearAngle should now be one of: 0, 45, 90, 135, 180...
913
1075
                    if ( nearAngle == 0 || nearAngle == 180 )
914
1076
                        gradient.setAttribute( "type", 1 ); // horizontal
929
1091
                // Hard to map between x- and y-center settings of ooimpress
930
1092
                // and (un-)balanced settings of kpresenter. Let's try it.
931
1093
                int x, y;
932
 
                if ( draw->hasAttribute( "draw:cx" ) )
933
 
                    x = draw->attribute( "draw:cx" ).remove( '%' ).toInt();
 
1094
                if ( draw->hasAttributeNS( ooNS::draw, "cx" ) )
 
1095
                    x = draw->attributeNS( ooNS::draw, "cx", QString::null ).remove( '%' ).toInt();
934
1096
                else
935
1097
                    x = 50;
936
1098
 
937
 
                if ( draw->hasAttribute( "draw:cy" ) )
938
 
                    y = draw->attribute( "draw:cy" ).remove( '%' ).toInt();
 
1099
                if ( draw->hasAttributeNS( ooNS::draw, "cy" ) )
 
1100
                    y = draw->attributeNS( ooNS::draw, "cy", QString::null ).remove( '%' ).toInt();
939
1101
                else
940
1102
                    y = 50;
941
1103
 
965
1127
void OoImpressImport::appendPie( QDomDocument& doc, QDomElement& e, const QDomElement& object )
966
1128
{
967
1129
    QDomElement angle = doc.createElement( "PIEANGLE" );
968
 
    int start = (int) ( object.attribute( "draw:start-angle" ).toDouble() );
 
1130
    int start = (int) ( object.attributeNS( ooNS::draw, "start-angle", QString::null ).toDouble() );
969
1131
    angle.setAttribute( "value",  start * 16 );
970
1132
    e.appendChild( angle );
971
1133
 
972
1134
    QDomElement length = doc.createElement( "PIELENGTH" );
973
 
    int end = (int) ( object.attribute( "draw:end-angle" ).toDouble() );
 
1135
    int end = (int) ( object.attributeNS( ooNS::draw, "end-angle", QString::null ).toDouble() );
974
1136
    if ( end < start )
975
1137
        length.setAttribute( "value",  ( 360 - start + end ) * 16 );
976
1138
    else
999
1161
    e.appendChild( image );
1000
1162
 
1001
1163
    QDomElement settings = doc.createElement( "PICTURESETTINGS" );
1002
 
    settings.setAttribute( "grayscal", 0 );
1003
 
    settings.setAttribute( "bright", 0 );
 
1164
    if ( m_styleStack.hasAttributeNS( ooNS::draw, "color-mode" ) &&  ( m_styleStack.attributeNS( ooNS::draw, "color-mode" )=="greyscale" ) )
 
1165
        settings.setAttribute( "grayscal", 1 );
 
1166
    else
 
1167
        settings.setAttribute( "grayscal", 0 );
 
1168
 
 
1169
    if ( m_styleStack.hasAttributeNS( ooNS::draw, "luminance" ) )
 
1170
    {
 
1171
        QString str( m_styleStack.attributeNS( ooNS::draw, "luminance" ) );
 
1172
        str = str.remove( '%' );
 
1173
        settings.setAttribute( "bright", str );
 
1174
    }
 
1175
    else
 
1176
        settings.setAttribute( "bright", 0 );
 
1177
 
1004
1178
    settings.setAttribute( "mirrorType", 0 );
1005
1179
    settings.setAttribute( "swapRGB", 0 );
1006
1180
    settings.setAttribute( "depth", 0 );
1007
1181
    e.appendChild( settings );
1008
1182
 
 
1183
    QDomElement effects = doc.createElement( "EFFECTS" );
 
1184
    bool hasEffect = false;
 
1185
    if ( m_styleStack.hasAttributeNS( ooNS::draw, "contrast" ) )
 
1186
    {
 
1187
        QString str( m_styleStack.attributeNS( ooNS::draw, "contrast" ) );
 
1188
        str = str.remove( '%' );
 
1189
        int val = str.toInt();
 
1190
        val = ( int )( 255.0 *val/100.0 );
 
1191
        effects.setAttribute( "type", "5" );
 
1192
        effects.setAttribute( "param1", QString::number( val ) );
 
1193
        hasEffect = true;
 
1194
    }
 
1195
    if ( hasEffect )
 
1196
        e.appendChild( effects );
 
1197
 
1009
1198
    QDomElement key = image.cloneNode().toElement();
1010
1199
    key.setAttribute( "name", "pictures/" + fileName );
1011
1200
    p.appendChild( key );
1041
1230
                                                const QDomElement& object )
1042
1231
{
1043
1232
    QDomElement backColor1 = doc.createElement( "BACKCOLOR1" );
1044
 
    backColor1.setAttribute( "color", object.attribute( "draw:start-color" ) );
 
1233
    backColor1.setAttribute( "color", object.attributeNS( ooNS::draw, "start-color", QString::null ) );
1045
1234
    e.appendChild( backColor1 );
1046
1235
 
1047
1236
    QDomElement backColor2 = doc.createElement( "BACKCOLOR2" );
1048
 
    backColor2.setAttribute( "color", object.attribute( "draw:end-color" ) );
 
1237
    backColor2.setAttribute( "color", object.attributeNS( ooNS::draw, "end-color", QString::null ) );
1049
1238
    e.appendChild( backColor2 );
1050
1239
 
1051
1240
    QDomElement backType = doc.createElement( "BACKTYPE" );
1053
1242
    e.appendChild( backType );
1054
1243
 
1055
1244
    QDomElement bcType = doc.createElement( "BCTYPE" );
1056
 
    QString type = object.attribute( "draw:style" );
 
1245
    QString type = object.attributeNS( ooNS::draw, "style", QString::null );
1057
1246
    if ( type == "linear" )
1058
1247
    {
1059
 
        int angle = object.attribute( "draw:angle" ).toInt() / 10;
 
1248
        int angle = object.attributeNS( ooNS::draw, "angle", QString::null ).toInt() / 10;
1060
1249
 
1061
1250
        // make sure the angle is between 0 and 359
1062
1251
        angle = abs( angle );
1100
1289
    // Hard to map between x- and y-center settings of ooimpress
1101
1290
    // and (un-)balanced settings of kpresenter. Let's try it.
1102
1291
    int x, y;
1103
 
    if ( object.hasAttribute( "draw:cx" ) )
1104
 
        x = object.attribute( "draw:cx" ).remove( '%' ).toInt();
 
1292
    if ( object.hasAttributeNS( ooNS::draw, "cx" ) )
 
1293
        x = object.attributeNS( ooNS::draw, "cx", QString::null ).remove( '%' ).toInt();
1105
1294
    else
1106
1295
        x = 50;
1107
1296
 
1108
 
    if ( object.hasAttribute( "draw:cy" ) )
1109
 
        y = object.attribute( "draw:cy" ).remove( '%' ).toInt();
 
1297
    if ( object.hasAttributeNS( ooNS::draw, "cy" ) )
 
1298
        y = object.attributeNS( ooNS::draw, "cy", QString::null ).remove( '%' ).toInt();
1110
1299
    else
1111
1300
        y = 50;
1112
1301
 
1129
1318
 
1130
1319
void OoImpressImport::appendRounding( QDomDocument& doc, QDomElement& e, const QDomElement& object )
1131
1320
{
1132
 
    if ( object.hasAttribute( "draw:corner-radius" ) )
 
1321
    if ( object.hasAttributeNS( ooNS::draw, "corner-radius" ) )
1133
1322
    {
1134
1323
        // kpresenter uses percent, ooimpress uses cm ... hmm?
1135
1324
        QDomElement rounding = doc.createElement( "RNDS" );
1136
 
        int corner = static_cast<int>(KoUnit::parseValue(object.attribute("draw:corner-radius")));
 
1325
        int corner = static_cast<int>(KoUnit::parseValue(object.attributeNS( ooNS::draw, "corner-radius", QString::null)));
1137
1326
        rounding.setAttribute( "x", corner );
1138
1327
        rounding.setAttribute( "y", corner );
1139
1328
        e.appendChild( rounding );
1151
1340
    if ( !e.hasAttribute( "type" ) ||
1152
1341
         ( e.hasAttribute( "type" ) && e.attribute( "type" ) == "4" ) )
1153
1342
    {
1154
 
        if ( m_styleStack.hasAttribute( "fo:text-shadow" ) &&
1155
 
             m_styleStack.attribute( "fo:text-shadow" ) != "none" )
 
1343
        if ( m_styleStack.hasAttributeNS( ooNS::fo, "text-shadow" ) &&
 
1344
             m_styleStack.attributeNS( ooNS::fo, "text-shadow" ) != "none" )
1156
1345
        {
1157
1346
            // use the shadow attribute to indicate a text-shadow
1158
1347
            QDomElement shadow = doc.createElement( "SHADOW" );
1159
 
            QString distance = m_styleStack.attribute( "fo:text-shadow" );
 
1348
            QString distance = m_styleStack.attributeNS( ooNS::fo, "text-shadow" );
1160
1349
            distance.truncate( distance.find( ' ' ) );
1161
1350
            shadow.setAttribute( "distance", KoUnit::parseValue( distance ) );
1162
1351
            shadow.setAttribute( "direction", 5 );
1164
1353
            e.appendChild( shadow );
1165
1354
        }
1166
1355
    }
1167
 
    else if ( m_styleStack.hasAttribute( "draw:shadow" ) &&
1168
 
              m_styleStack.attribute( "draw:shadow" ) == "visible" )
 
1356
    else if ( m_styleStack.hasAttributeNS( ooNS::draw, "shadow" ) &&
 
1357
              m_styleStack.attributeNS( ooNS::draw, "shadow" ) == "visible" )
1169
1358
    {
1170
1359
        // use the shadow attribute to indicate an object-shadow
1171
1360
        QDomElement shadow = doc.createElement( "SHADOW" );
1172
 
        double x = KoUnit::parseValue( m_styleStack.attribute( "draw:shadow-offset-x" ) );
1173
 
        double y = KoUnit::parseValue( m_styleStack.attribute( "draw:shadow-offset-y" ) );
 
1361
        double x = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::draw, "shadow-offset-x" ) );
 
1362
        double y = KoUnit::parseValue( m_styleStack.attributeNS( ooNS::draw, "shadow-offset-y" ) );
1174
1363
 
1175
1364
        if ( x < 0 && y < 0 )
1176
1365
        {
1213
1402
            shadow.setAttribute( "distance", (int) fabs ( x ) );
1214
1403
        }
1215
1404
 
1216
 
        if ( m_styleStack.hasAttribute ( "draw:shadow-color" ) )
1217
 
            shadow.setAttribute( "color", m_styleStack.attribute( "draw:shadow-color" ) );
 
1405
        if ( m_styleStack.hasAttributeNS( ooNS::draw, "shadow-color" ) )
 
1406
            shadow.setAttribute( "color", m_styleStack.attributeNS( ooNS::draw, "shadow-color" ) );
1218
1407
 
1219
1408
        e.appendChild( shadow );
1220
1409
    }
1221
 
    if ( m_styleStack.hasAttribute( "draw:size-protect" ) || m_styleStack.hasAttribute("draw:move-protect" ) )
 
1410
    if ( m_styleStack.hasAttributeNS( ooNS::draw, "size-protect" ) || m_styleStack.hasAttributeNS( ooNS::draw, "move-protect" ) )
1222
1411
    {
1223
 
        bool b = ( m_styleStack.attribute("draw:size-protect" ) == "true" ) || ( m_styleStack.attribute("draw:move-protect" ) == "true" );
 
1412
        bool b = ( m_styleStack.attributeNS( ooNS::draw, "size-protect" ) == "true" ) || ( m_styleStack.attributeNS( ooNS::draw, "move-protect" ) == "true" );
1224
1413
        if ( b )
1225
1414
        {
1226
1415
            QDomElement protect  = doc.createElement( "PROTECT" );
1230
1419
    }
1231
1420
}
1232
1421
 
1233
 
void OoImpressImport::appendLineEnds( QDomDocument& doc, QDomElement& e, bool orderEndStartLine )
 
1422
void OoImpressImport::appendLineEnds( QDomDocument& doc, QDomElement& e, bool orderEndStartLine)
1234
1423
{
1235
 
    QString attr = orderEndStartLine ? "draw:marker-start" : "draw:marker-end";
1236
 
    if ( m_styleStack.hasAttribute( attr ) )
 
1424
    const char* attr = orderEndStartLine ? "marker-start" : "marker-end";
 
1425
    if ( m_styleStack.hasAttributeNS( ooNS::draw, attr ) )
1237
1426
    {
1238
1427
        QDomElement lineBegin = doc.createElement( "LINEBEGIN" );
1239
 
        QString type = m_styleStack.attribute( attr );
 
1428
        QString type = m_styleStack.attributeNS( ooNS::draw, attr );
1240
1429
        if ( type == "Arrow" || type == "Small Arrow" || type == "Rounded short Arrow" ||
1241
1430
             type == "Symmetric Arrow" || type == "Rounded large Arrow" || type == "Arrow concave" )
1242
1431
            lineBegin.setAttribute( "value", 1 );
1252
1441
            lineBegin.setAttribute( "value", 6 );
1253
1442
        e.appendChild( lineBegin );
1254
1443
    }
1255
 
    attr = orderEndStartLine ? "draw:marker-end" : "draw:marker-start";
1256
 
    if ( m_styleStack.hasAttribute( attr ) )
 
1444
    attr = orderEndStartLine ? "marker-end" : "marker-start";
 
1445
    if ( m_styleStack.hasAttributeNS( ooNS::draw, attr ) )
1257
1446
    {
1258
1447
        QDomElement lineEnd = doc.createElement( "LINEEND" );
1259
 
        QString type = m_styleStack.attribute( attr );
 
1448
        QString type = m_styleStack.attributeNS( ooNS::draw, attr );
1260
1449
        if ( type == "Arrow" || type == "Small Arrow" || type == "Rounded short Arrow" ||
1261
1450
             type == "Symmetric Arrow" || type == "Rounded large Arrow" || type == "Arrow concave" )
1262
1451
            lineEnd.setAttribute( "value", 1 );
1276
1465
 
1277
1466
void OoImpressImport::appendTextObjectMargin( QDomDocument& /*doc*/, QDomElement& e )
1278
1467
{
1279
 
    if( m_styleStack.hasAttribute( "fo:padding-top" ) )
1280
 
        e.setAttribute( "btoppt", KoUnit::parseValue( m_styleStack.attribute( "fo:padding-top" ) ) );
1281
 
    if( m_styleStack.hasAttribute( "fo:padding-bottom" ) )
1282
 
        e.setAttribute( "bbottompt", KoUnit::parseValue( m_styleStack.attribute( "fo:padding-bottom" ) ) );
1283
 
    if( m_styleStack.hasAttribute( "fo:padding-left" ) )
1284
 
        e.setAttribute( "bleftpt", KoUnit::parseValue( m_styleStack.attribute( "fo:padding-left" ) ) );
1285
 
    if( m_styleStack.hasAttribute( "fo:padding-right" ) )
1286
 
        e.setAttribute( "brightpt", KoUnit::parseValue( m_styleStack.attribute( "fo:padding-right" ) ) );
 
1468
    if ( m_styleStack.hasAttributeNS( ooNS::fo, "padding" ) )
 
1469
    {
 
1470
        double tmpValue = KoUnit::parseValue(m_styleStack.attributeNS( ooNS::fo, "padding" ) );
 
1471
        e.setAttribute( "btoppt", tmpValue );
 
1472
        e.setAttribute( "bbottompt", tmpValue );
 
1473
        e.setAttribute( "bleftpt", tmpValue );
 
1474
        e.setAttribute( "brightpt", tmpValue );
 
1475
    }
 
1476
    else
 
1477
    {
 
1478
        if( m_styleStack.hasAttributeNS( ooNS::fo, "padding-top" ) )
 
1479
            e.setAttribute( "btoppt", KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo, "padding-top" ) ) );
 
1480
        if( m_styleStack.hasAttributeNS( ooNS::fo, "padding-bottom" ) )
 
1481
            e.setAttribute( "bbottompt", KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo, "padding-bottom" ) ) );
 
1482
        if( m_styleStack.hasAttributeNS( ooNS::fo, "padding-left" ) )
 
1483
            e.setAttribute( "bleftpt", KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo, "padding-left" ) ) );
 
1484
        if( m_styleStack.hasAttributeNS( ooNS::fo, "padding-right" ) )
 
1485
            e.setAttribute( "brightpt", KoUnit::parseValue( m_styleStack.attributeNS( ooNS::fo, "padding-right" ) ) );
 
1486
    }
1287
1487
}
1288
1488
 
1289
 
 
1290
1489
QDomElement OoImpressImport::parseTextBox( QDomDocument& doc, const QDomElement& textBox )
1291
1490
{
1292
1491
    QDomElement textObjectElement = doc.createElement( "TEXTOBJ" );
1293
1492
    appendTextObjectMargin( doc, textObjectElement );
1294
1493
 
1295
1494
    // vertical alignment
1296
 
    if ( m_styleStack.hasAttribute( "draw:textarea-vertical-align" ) )
 
1495
    if ( m_styleStack.hasAttributeNS( ooNS::draw, "textarea-vertical-align" ) )
1297
1496
    {
1298
 
        QString alignment = m_styleStack.attribute( "draw:textarea-vertical-align" );
 
1497
        QString alignment = m_styleStack.attributeNS( ooNS::draw, "textarea-vertical-align" );
1299
1498
        if ( alignment == "top" )
1300
1499
            textObjectElement.setAttribute( "verticalAlign", "top" );
1301
1500
        else if ( alignment == "middle" )
1306
1505
        textObjectElement.setAttribute("verticalValue", 0.0);
1307
1506
    }
1308
1507
 
1309
 
    for ( QDomNode text = textBox.firstChild(); !text.isNull(); text = text.nextSibling() )
 
1508
    parseParagraphs( doc, textObjectElement, textBox );
 
1509
 
 
1510
    return textObjectElement;
 
1511
}
 
1512
 
 
1513
void OoImpressImport::parseParagraphs( QDomDocument& doc, QDomElement& textObjectElement, const QDomElement& parent )
 
1514
{
 
1515
    QDomElement t;
 
1516
    forEachElement( t, parent )
1310
1517
    {
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;
1313
1522
 
1314
1523
        QDomElement e;
1315
 
        if ( name == "text:p" ) // text paragraph
1316
 
            e = parseParagraph( doc, t );
1317
 
        else if ( name == "text:h" ) // heading - can this happen in ooimpress?
1318
 
        {
1319
 
            e = parseParagraph( doc, t );
1320
 
        }
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?
 
1527
        {
 
1528
            e = parseParagraph( doc, t );
 
1529
        }
 
1530
        else if ( isTextNS && ( localName == "unordered-list" || localName == "ordered-list" ) )
 
1531
        {
 
1532
            parseList( doc, textObjectElement, t );
 
1533
            m_styleStack.restore();
 
1534
            continue;
 
1535
        }
1323
1536
        // TODO text:sequence-decls
1324
1537
        else
1325
1538
        {
1326
 
            kdDebug(30518) << "Unsupported texttype '" << name << "'" << endl;
1327
 
            continue;
1328
 
        }
1329
 
 
1330
 
        textObjectElement.appendChild( e );
1331
 
    }
1332
 
 
1333
 
    return textObjectElement;
1334
 
}
1335
 
 
1336
 
QDomElement OoImpressImport::parseList( QDomDocument& doc, const QDomElement& list )
1337
 
{
1338
 
    //kdDebug(30518) << k_funcinfo << "parsing list"<< endl;
1339
 
 
1340
 
    bool isOrdered;
1341
 
    if ( list.tagName() == "text:ordered-list" )
1342
 
        isOrdered = true;
1343
 
    else
1344
 
        isOrdered = false;
1345
 
 
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.
1348
 
    QDomElement e;
1349
 
    for ( QDomNode n = list.firstChild(); !n.isNull(); n = n.firstChild() )
1350
 
    {
1351
 
        e = n.toElement();
1352
 
        QString name = e.tagName();
1353
 
        if ( name == "text:unordered-list" )
1354
 
        {
1355
 
            isOrdered = false;
1356
 
            // parse the list-properties
1357
 
            fillStyleStack( e );
1358
 
        }
1359
 
        else if ( name == "text:ordered-list" )
1360
 
        {
1361
 
            isOrdered = true;
1362
 
            // parse the list-properties
1363
 
            fillStyleStack( e );
1364
 
        }
1365
 
        if ( name == "text:p" )
1366
 
            break;
1367
 
    }
1368
 
    // ### Where are the sibling paragraphs of 'e' parsed?
1369
 
 
1370
 
    QDomElement p = parseParagraph( doc, e );
1371
 
 
1372
 
    QDomElement counter = doc.createElement( "COUNTER" );
1373
 
    counter.setAttribute( "numberingtype", 0 );
1374
 
    counter.setAttribute( "depth", 0 );
1375
 
 
1376
 
    if ( isOrdered )
1377
 
        counter.setAttribute( "type", 1 );
1378
 
    else
1379
 
        counter.setAttribute( "type", 10 );
1380
 
 
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
1383
 
    // every item!
1384
 
    p.insertBefore( counter, QDomNode() );
1385
 
 
1386
 
    return p;
 
1539
            kdDebug(30518) << "Unsupported texttype '" << localName << "'" << endl;
 
1540
        }
 
1541
 
 
1542
        if ( !e.isNull() )
 
1543
            textObjectElement.appendChild( e );
 
1544
        m_styleStack.restore(); // remove the styles added by the paragraph or list
 
1545
    }
 
1546
}
 
1547
 
 
1548
void OoImpressImport::applyListStyle( QDomElement& paragraph )
 
1549
{
 
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();
 
1557
 
 
1558
        QDomElement counter = paragraph.ownerDocument().createElement( "COUNTER" );
 
1559
        counter.setAttribute( "numberingtype", 0 );
 
1560
        counter.setAttribute( "depth", 0 );
 
1561
 
 
1562
        if ( m_insideOrderedList )
 
1563
            counter.setAttribute( "type", 1 );
 
1564
        else
 
1565
            counter.setAttribute( "type", 10 ); // a disc bullet
 
1566
        paragraph.appendChild( counter );
 
1567
    }
 
1568
}
 
1569
 
 
1570
static QDomElement findListLevelStyle( QDomElement& fullListStyle, int level )
 
1571
{
 
1572
    QDomElement listLevelItem;
 
1573
    forEachElement( listLevelItem, fullListStyle )
 
1574
    {
 
1575
       if ( listLevelItem.attributeNS( ooNS::text, "level", QString::null ).toInt() == level )
 
1576
           return listLevelItem;
 
1577
    }
 
1578
    return QDomElement();
 
1579
}
 
1580
 
 
1581
bool OoImpressImport::pushListLevelStyle( const QString& listStyleName, int level )
 
1582
{
 
1583
    QDomElement* fullListStyle = m_listStyles[listStyleName];
 
1584
    if ( !fullListStyle ) {
 
1585
        kdWarning(30518) << "List style " << listStyleName << " not found!" << endl;
 
1586
        return false;
 
1587
    }
 
1588
    else
 
1589
        return pushListLevelStyle( listStyleName, *fullListStyle, level );
 
1590
}
 
1591
 
 
1592
bool OoImpressImport::pushListLevelStyle( const QString& listStyleName, // for debug only
 
1593
                                          QDomElement& fullListStyle, int level )
 
1594
{
 
1595
    // Find applicable list-level-style for level
 
1596
    int i = level;
 
1597
    QDomElement listLevelStyle;
 
1598
    while ( i > 0 && listLevelStyle.isNull() ) {
 
1599
        listLevelStyle = findListLevelStyle( fullListStyle, i );
 
1600
        --i;
 
1601
    }
 
1602
    if ( listLevelStyle.isNull() ) {
 
1603
        kdWarning(30518) << "List level style for level " << level << " in list style " << listStyleName << " not found!" << endl;
 
1604
        return false;
 
1605
    }
 
1606
    kdDebug(30518) << "Pushing list-level-style from list-style " << listStyleName << " level " << level << endl;
 
1607
    m_listStyleStack.push( listLevelStyle );
 
1608
    return true;
 
1609
}
 
1610
 
 
1611
void OoImpressImport::parseList( QDomDocument& doc, QDomElement& textObjectElement, const QDomElement& list )
 
1612
{
 
1613
    //kdDebug(30518) << k_funcinfo << "parseList"<< endl;
 
1614
 
 
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;
 
1622
    if ( listOK )
 
1623
        listOK = pushListLevelStyle( m_currentListStyleName, level );
 
1624
 
 
1625
    // Iterate over list items
 
1626
    QDomElement listItem;
 
1627
    forEachElement( listItem, list )
 
1628
    {
 
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;
 
1637
    }
 
1638
    if ( listOK )
 
1639
        m_listStyleStack.pop();
 
1640
    m_currentListStyleName = oldListStyleName;
1387
1641
}
1388
1642
 
1389
1643
QDomElement OoImpressImport::parseParagraph( QDomDocument& doc, const QDomElement& paragraph )
1403
1657
    }
1404
1658
 
1405
1659
    // Paragraph alignment
1406
 
    if ( m_styleStack.hasAttribute( "fo:text-align" ) )
 
1660
    if ( m_styleStack.hasAttributeNS( ooNS::fo, "text-align" ) )
1407
1661
    {
1408
 
        QString align = m_styleStack.attribute( "fo:text-align" );
 
1662
        QString align = m_styleStack.attributeNS( ooNS::fo, "text-align" );
1409
1663
        if ( align == "center" )
1410
1664
            p.setAttribute( "align", 4 );
1411
1665
        else if ( align == "justify" )
1434
1688
    // Borders
1435
1689
    OoUtils::importBorders( p, m_styleStack );
1436
1690
 
 
1691
    applyListStyle( p );
 
1692
 
1437
1693
    uint pos = 0;
1438
1694
 
1439
1695
    m_styleStack.save();
1447
1703
void OoImpressImport::parseSpanOrSimilar( QDomDocument& doc, const QDomElement& parent,
1448
1704
    QDomElement& outputParagraph, uint& pos)
1449
1705
{
1450
 
    // parse every child node of the parent
 
1706
    // Parse every child node of the parent
 
1707
    // Can't use forEachElement here since we also care about text nodes
1451
1708
    for( QDomNode node = parent.firstChild(); !node.isNull(); node = node.nextSibling() )
1452
1709
    {
1453
1710
        QDomElement ts = node.toElement();
1454
1711
        QString textData;
1455
 
        QString tagName = ts.tagName();
 
1712
        const QString localName( ts.localName() );
 
1713
        const QString ns = ts.namespaceURI();
 
1714
        const bool isTextNS = ns == ooNS::text;
1456
1715
        QDomText t = node.toText();
1457
1716
 
1458
1717
        // Try to keep the order of the tag names by probability of happening
1459
 
        if ( tagName == "text:span" )
 
1718
        if ( isTextNS && localName == "span" ) // text:span
1460
1719
        {
1461
1720
            m_styleStack.save();
1462
1721
            fillStyleStack( ts );
1463
1722
            parseSpanOrSimilar( doc, ts, outputParagraph, pos);
1464
1723
            m_styleStack.restore();
1465
1724
        }
1466
 
        else if (tagName == "text:s")
 
1725
        else if ( isTextNS && localName == "s" ) // text:s
1467
1726
        {
1468
1727
            textData = OoUtils::expandWhitespace(ts);
1469
1728
        }
1470
 
        else if ( tagName == "text:tab-stop" )
 
1729
        else if ( isTextNS && localName == "tab-stop" ) // text:tab-stop
1471
1730
        {
1472
1731
            // KPresenter currently uses \t.
1473
1732
            // Known bug: a line with only \t\t\t\t isn't loaded - XML (QDom) strips out whitespace.
1474
1733
            // One more good reason to switch to <text:tab-stop> instead...
1475
1734
            textData = '\t';
1476
1735
        }
1477
 
        else if ( tagName == "text:line-break" )
 
1736
        else if ( isTextNS && localName == "line-break" )
1478
1737
        {
1479
1738
            textData = '\n';
1480
1739
        }
1481
 
        else if ( tagName == "draw:image" )
 
1740
        else if ( localName == "image" && ns == ooNS::draw )
1482
1741
        {
1483
1742
            textData = '#'; // anchor placeholder
1484
1743
            // TODO
1485
1744
        }
1486
 
        else if ( tagName == "text:a" )
 
1745
        else if ( isTextNS && localName == "a" )
1487
1746
        {
1488
1747
            m_styleStack.save();
1489
 
            QString href( ts.attribute("xlink:href") );
 
1748
            QString href( ts.attributeNS( ooNS::xlink, "href", QString::null) );
1490
1749
            if ( href.startsWith("#") )
1491
1750
            {
1492
1751
                // We have a reference to a bookmark (### TODO)
1504
1763
                parseSpanOrSimilar( doc, ts, fakeParagraph, fakeFormats, text, fakePos);
1505
1764
                textData = '#'; // hyperlink placeholder
1506
1765
                QDomElement linkElement (doc.createElement("LINK"));
1507
 
                linkElement.setAttribute("hrefName",ts.attribute("xlink:href"));
 
1766
                linkElement.setAttribute("hrefName",ts.attributeNS( ooNS::xlink, "href", QString::null));
1508
1767
                linkElement.setAttribute("linkName",text);
1509
1768
                appendVariable(doc, ts, pos, "STRING", 9, text, linkElement);
1510
1769
#endif
1511
1770
            }
1512
1771
            m_styleStack.restore();
1513
1772
        }
1514
 
        else if (tagName == "text:date" // fields
1515
 
                 || tagName == "text:time"
1516
 
                 || tagName == "text:page-number"
1517
 
                 || tagName == "text:file-name"
1518
 
                 || tagName == "text:author-name"
1519
 
                 || tagName == "text:author-initials")
 
1773
        else if ( isTextNS &&
 
1774
                  (localName == "date" // fields
 
1775
                 || localName == "time"
 
1776
                 || localName == "page-number"
 
1777
                 || localName == "file-name"
 
1778
                 || localName == "author-name"
 
1779
                 || localName == "author-initials" ) )
1520
1780
        {
1521
1781
            textData = "#";     // field placeholder
1522
1782
            appendField(doc, outputParagraph, ts, pos);
1533
1793
 
1534
1794
        QDomElement text = saveHelper(textData, doc);
1535
1795
 
1536
 
        //kdDebug(30518) << k_funcinfo << "Para text is: " << paragraph.text() << endl;
 
1796
        kdDebug(30518) << k_funcinfo << "Para text is: " << textData << endl;
1537
1797
 
1538
 
        if (m_styleStack.hasAttribute("fo:language")) {
1539
 
            QString lang = m_styleStack.attribute("fo:language");
 
1798
        if (m_styleStack.hasAttributeNS( ooNS::fo, "language" )) {
 
1799
            QString lang = m_styleStack.attributeNS( ooNS::fo, "language" );
1540
1800
            if (lang=="en")
1541
1801
                text.setAttribute("language", "en_US");
1542
1802
            else
1544
1804
        }
1545
1805
 
1546
1806
        // parse the text-properties
1547
 
        if ( m_styleStack.hasAttribute( "fo:color" ) )
1548
 
            text.setAttribute( "color", m_styleStack.attribute( "fo:color" ) );
1549
 
        if ( m_styleStack.hasAttribute( "fo:font-family" ) )
 
1807
        if ( m_styleStack.hasAttributeNS( ooNS::fo, "color" ) ) {
 
1808
            kdDebug(30518) << "color=" << m_styleStack.attributeNS( ooNS::fo, "color" ) << endl;
 
1809
            text.setAttribute( "color", m_styleStack.attributeNS( ooNS::fo, "color" ) );
 
1810
        }
 
1811
        if ( m_styleStack.hasAttributeNS( ooNS::fo, "font-family" )  // 3.10.9
 
1812
             || m_styleStack.hasAttributeNS( ooNS::style, "font-name") )//3.10.8
1550
1813
        {
1551
1814
            // 'Thorndale/Albany' are not known outside OpenOffice so we substitute them
1552
1815
            // with 'Times New Roman/Arial' that look nearly the same.
1553
 
            if ( m_styleStack.attribute( "fo:font-family" ) == "Thorndale" )
 
1816
            if ( m_styleStack.attributeNS( ooNS::fo, "font-family" ) == "Thorndale" )
1554
1817
                text.setAttribute( "family", "Times New Roman" );
1555
 
            else if ( m_styleStack.attribute( "fo:font-family" ) == "Albany" )
 
1818
            else if ( m_styleStack.attributeNS( ooNS::fo, "font-family" ) == "Albany" )
1556
1819
                text.setAttribute( "family", "Arial" );
1557
1820
            else
1558
 
                text.setAttribute( "family", m_styleStack.attribute( "fo:font-family" ).remove( "'" ) );
 
1821
                text.setAttribute( "family", m_styleStack.attributeNS( ooNS::fo, "font-family" ).remove( "'" ) );
1559
1822
        }
1560
 
        if ( m_styleStack.hasAttribute( "fo:font-size" ) )
 
1823
        if ( m_styleStack.hasAttributeNS( ooNS::fo, "font-size" ) )
1561
1824
        {
1562
1825
            double pointSize = m_styleStack.fontSize();
1563
1826
            text.setAttribute( "pointSize", qRound(pointSize) ); // KPresenter uses toInt()!
1564
1827
        }
1565
 
        if ( m_styleStack.hasAttribute( "fo:font-weight" ) ) // 3.10.24
1566
 
            if ( m_styleStack.attribute( "fo:font-weight" ) == "bold" )
 
1828
        if ( m_styleStack.hasAttributeNS( ooNS::fo, "font-weight" ) ) // 3.10.24
 
1829
            if ( m_styleStack.attributeNS( ooNS::fo, "font-weight" ) == "bold" )
1567
1830
                text.setAttribute( "bold", 1 );
1568
 
        if ( m_styleStack.hasAttribute( "fo:font-style" ) )
1569
 
            if ( m_styleStack.attribute( "fo:font-style" ) == "italic" )
 
1831
        if ( m_styleStack.hasAttributeNS( ooNS::fo, "font-style" ) )
 
1832
            if ( m_styleStack.attributeNS( ooNS::fo, "font-style" ) == "italic" )
1570
1833
                text.setAttribute( "italic", 1 );
1571
1834
 
1572
 
        if ( m_styleStack.hasAttribute( "style:text-position" ) ) // 3.10.17
 
1835
        if ( m_styleStack.hasAttributeNS( ooNS::style, "text-position" ) ) // 3.10.17
1573
1836
        {
1574
 
            QString text_position = m_styleStack.attribute("style:text-position");
 
1837
            QString text_position = m_styleStack.attributeNS( ooNS::style, "text-position");
1575
1838
            QString value;
1576
1839
            QString relativetextsize;
1577
1840
            OoUtils::importTextPosition( text_position, value, relativetextsize );
1580
1843
                text.setAttribute( "relativetextsize", relativetextsize );
1581
1844
        }
1582
1845
 
1583
 
        bool wordByWord = (m_styleStack.hasAttribute("fo:score-spaces"))
1584
 
                          && (m_styleStack.attribute("fo:score-spaces") == "false");
 
1846
        bool wordByWord = (m_styleStack.hasAttributeNS( ooNS::fo, "score-spaces"))// 3.10.25
 
1847
                          && (m_styleStack.attributeNS( ooNS::fo, "score-spaces") == "false");
1585
1848
 
1586
1849
        // strikeout
1587
 
        if ( m_styleStack.hasAttribute("style:text-crossing-out")
1588
 
             && m_styleStack.attribute("style:text-crossing-out") != "none")
 
1850
        if ( m_styleStack.hasAttributeNS( ooNS::style, "text-crossing-out")// 3.10.6
 
1851
             && m_styleStack.attributeNS( ooNS::style, "text-crossing-out") != "none")
1589
1852
        {
1590
 
            QString strikeOutType = m_styleStack.attribute( "style:text-crossing-out" );
 
1853
            QString strikeOutType = m_styleStack.attributeNS( ooNS::style, "text-crossing-out" );
1591
1854
            if ( strikeOutType =="double-line" )
1592
1855
            {
1593
1856
                text.setAttribute( "strikeOut", "double" );
1609
1872
        }
1610
1873
 
1611
1874
        // underlining
1612
 
        if ( m_styleStack.hasAttribute( "style:text-underline" ) )
 
1875
        if ( m_styleStack.hasAttributeNS( ooNS::style, "text-underline" ) ) // 3.10.22
1613
1876
        {
1614
 
            QString underType = m_styleStack.attribute( "style:text-underline" );
1615
 
            QString underLineColor = m_styleStack.attribute( "style:text-underline-color" );
1616
 
            if ( underType == "single" )
1617
 
            {
1618
 
                text.setAttribute( "underline", 1 );
1619
 
                text.setAttribute( "underlinestyleline", "solid" );
1620
 
                text.setAttribute( "underlinecolor", underLineColor );
1621
 
            }
1622
 
            else if ( underType == "double" )
1623
 
            {
1624
 
                text.setAttribute( "underline", "double" );
1625
 
                text.setAttribute( "underlinestyleline", "solid" );
1626
 
                text.setAttribute( "underlinecolor", underLineColor );
1627
 
            }
1628
 
            else if ( underType == "bold" )
1629
 
            {
1630
 
                text.setAttribute( "underline", "single-bold" );
1631
 
                text.setAttribute( "underlinestyleline", "solid" );
1632
 
                text.setAttribute( "underlinecolor", underLineColor );
1633
 
            }
1634
 
            else if ( underType == "wave" )
1635
 
            {
1636
 
                text.setAttribute( "underline", "wave" );
1637
 
                text.setAttribute( "underlinestyleline", "solid" );
1638
 
                text.setAttribute( "underlinecolor", underLineColor );
1639
 
            }
1640
 
            else if ( underType == "dotted" )
1641
 
            {
1642
 
                text.setAttribute( "underline", 1 );
1643
 
                text.setAttribute( "underlinestyleline", "dot" );
1644
 
                text.setAttribute( "underlinecolor", underLineColor );
1645
 
 
1646
 
            }
1647
 
            else if ( underType == "dash" )
1648
 
            {
1649
 
                text.setAttribute( "underline", 1 );
1650
 
                text.setAttribute( "underlinestyleline", "dash" );
1651
 
                text.setAttribute( "underlinecolor", underLineColor );
1652
 
            }
1653
 
            else if ( underType == "dot-dash" )
1654
 
            {
1655
 
                text.setAttribute( "underline", 1 );
1656
 
                text.setAttribute( "underlinestyleline", "dash" );
1657
 
                text.setAttribute( "underlinecolor", underLineColor );
1658
 
            }
1659
 
            else if ( underType == "bold-dotted" )
1660
 
            {
1661
 
                text.setAttribute( "underline", "single-bold" );
1662
 
                text.setAttribute( "underlinestyleline", "dot" );
1663
 
                text.setAttribute( "underlinecolor", underLineColor );
1664
 
            }
1665
 
 
1666
 
            if (wordByWord)
 
1877
            QString underline;
 
1878
            QString styleline;
 
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
 
1882
 
 
1883
            text.setAttribute( "value", underline );
 
1884
            text.setAttribute( "styleline", styleline );
 
1885
 
 
1886
            if ( !underLineColor.isEmpty() && underLineColor != "font-color" )
 
1887
                text.setAttribute("underlinecolor", underLineColor);
 
1888
            if ( wordByWord )
1667
1889
                text.setAttribute("wordbyword", 1);
1668
1890
        }
1669
 
 
 
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
 
1895
        {
 
1896
            QDomElement fontAttrib( doc.createElement( "FONTATTRIBUTE" ) );
 
1897
            bool smallCaps = m_styleStack.attributeNS( ooNS::fo, "font-variant" ) == "small-caps";
 
1898
            if ( smallCaps )
 
1899
            {
 
1900
                text.setAttribute( "fontattribute", "smallcaps" );
 
1901
            } else
 
1902
            {
 
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" ) );
 
1906
            }
 
1907
        }
 
1908
#endif
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" ))
1672
1911
        {
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);
1676
1915
        }
1686
1925
    if ( styles.isNull() )
1687
1926
        return;
1688
1927
 
1689
 
    QDomNode fixedStyles = styles.namedItem( "office:styles" );
 
1928
    QDomNode fixedStyles = KoDom::namedItemNS( styles, ooNS::office, "styles" );
1690
1929
    if ( !fixedStyles.isNull() )
1691
1930
    {
1692
1931
        insertDraws( fixedStyles.toElement() );
1693
1932
        insertStyles( fixedStyles.toElement() );
 
1933
        insertStylesPresentation( fixedStyles.toElement() );
1694
1934
    }
1695
1935
 
1696
 
    QDomNode automaticStyles = styles.namedItem( "office:automatic-styles" );
 
1936
    QDomNode automaticStyles = KoDom::namedItemNS( styles, ooNS::office, "automatic-styles" );
1697
1937
    if ( !automaticStyles.isNull() )
 
1938
    {
1698
1939
        insertStyles( automaticStyles.toElement() );
1699
 
 
1700
 
    QDomNode masterStyles = styles.namedItem( "office:master-styles" );
 
1940
        insertStylesPresentation( automaticStyles.toElement() );
 
1941
    }
 
1942
    QDomNode masterStyles = KoDom::namedItemNS( styles, ooNS::office, "master-styles" );
1701
1943
    if ( !masterStyles.isNull() )
1702
1944
        insertStyles( masterStyles.toElement() );
1703
1945
}
1704
1946
 
1705
1947
void OoImpressImport::insertDraws( const QDomElement& styles )
1706
1948
{
1707
 
    for ( QDomNode n = styles.firstChild(); !n.isNull(); n = n.nextSibling() )
 
1949
    QDomElement e;
 
1950
    forEachElement( e, styles )
1708
1951
    {
1709
 
        QDomElement e = n.toElement();
1710
 
 
1711
 
        if ( !e.hasAttribute( "draw:name" ) )
 
1952
        if ( !e.hasAttributeNS( ooNS::draw, "name" ) )
1712
1953
            continue;
1713
1954
 
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 ) );
1716
1957
    }
1717
1958
}
1718
1959
 
1719
1960
void OoImpressImport::insertStyles( const QDomElement& styles )
1720
1961
{
1721
 
    for ( QDomNode n = styles.firstChild(); !n.isNull(); n = n.nextSibling() )
1722
 
    {
1723
 
        QDomElement e = n.toElement();
1724
 
 
1725
 
        if ( !e.hasAttribute( "style:name" ) )
1726
 
            continue;
1727
 
 
1728
 
        QString name = e.attribute( "style:name" );
1729
 
        m_styles.insert( name, new QDomElement( e ) );
 
1962
    QDomElement e;
 
1963
    forEachElement( e, styles )
 
1964
    {
 
1965
        const QString localName = e.localName();
 
1966
        const QString ns = e.namespaceURI();
 
1967
        if ( !e.hasAttributeNS( ooNS::style, "name" ) )
 
1968
            continue;
 
1969
 
 
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;
 
1975
        }
 
1976
        else
 
1977
        {
 
1978
            m_styles.insert( name, new QDomElement( e ) );
 
1979
            kdDebug(30518) << "Style: '" << name << "' loaded " << endl;
 
1980
        }
 
1981
    }
 
1982
}
 
1983
 
 
1984
void OoImpressImport::insertStylesPresentation( const QDomElement& styles )
 
1985
{
 
1986
    QDomElement e;
 
1987
    forEachElement( e, styles )
 
1988
    {
 
1989
        if ( !e.hasAttributeNS( ooNS::style, "name" ) )
 
1990
            continue;
 
1991
 
 
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;
1731
1995
    }
1732
1996
}
1733
1997
 
1734
 
void OoImpressImport::fillStyleStack( const QDomElement& object )
 
1998
void OoImpressImport::fillStyleStack( const QDomElement& object, bool sticky )
1735
1999
{
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" )] );
1739
 
 
1740
 
    if ( object.hasAttribute( "draw:style-name" ) )
1741
 
        addStyles( m_styles[object.attribute( "draw:style-name" )] );
1742
 
 
1743
 
    if ( object.hasAttribute( "draw:text-style-name" ) )
1744
 
        addStyles( m_styles[object.attribute( "draw:text-style-name" )] );
1745
 
 
1746
 
    if ( object.hasAttribute( "text:style-name" ) )
1747
 
        addStyles( m_styles[object.attribute( "text:style-name" )] );
 
2001
    if ( object.hasAttributeNS( ooNS::presentation, "style-name" ) )
 
2002
    {
 
2003
        kdDebug(30518)<<" presentation:style-name **************************** :"<<object.attributeNS( ooNS::presentation, "style-name", QString::null )<<endl;
 
2004
        if ( sticky )
 
2005
            addStyles( m_stylesPresentation[object.attributeNS( ooNS::presentation, "style-name", QString::null )] );
 
2006
        else
 
2007
            addStyles( m_styles[object.attributeNS( ooNS::presentation, "style-name", QString::null )] );
 
2008
    }
 
2009
    if ( object.hasAttributeNS( ooNS::draw, "style-name" ) )
 
2010
        addStyles( m_styles[object.attributeNS( ooNS::draw, "style-name", QString::null )] );
 
2011
 
 
2012
    if ( object.hasAttributeNS( ooNS::draw, "text-style-name" ) )
 
2013
        addStyles( m_styles[object.attributeNS( ooNS::draw, "text-style-name", QString::null )] );
 
2014
 
 
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] );
 
2019
    }
1748
2020
}
1749
2021
 
1750
2022
void OoImpressImport::addStyles( const QDomElement* style )
1751
2023
{
 
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" )] );
1755
 
 
 
2026
    if ( style->hasAttributeNS( ooNS::style, "parent-style-name" ) )
 
2027
    {
 
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 )] );
 
2030
    }
 
2031
    //kdDebug(30518)<<" void OoImpressImport::addStyles( const QDomElement* style ) :"<<style<<endl;
1756
2032
    m_styleStack.push( *style );
1757
2033
}
1758
2034
 
1759
2035
QString OoImpressImport::storeImage( const QDomElement& object )
1760
2036
{
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 );
1764
2040
 
1765
2041
    QString extension = url.mid( url.find( '.' ) );
1779
2055
{
1780
2056
    QFileInfo fi(m_chain->inputFile()); // handle relative URLs
1781
2057
    QDir::setCurrent(fi.dirPath(true));
1782
 
    fi.setFile(object.attribute("xlink:href"));
 
2058
    fi.setFile(object.attributeNS( ooNS::xlink, "href", QString::null));
1783
2059
    QString url = fi.absFilePath();
1784
2060
 
1785
2061
    //kdDebug(30518) << "Sound URL: " << url << endl;
1836
2112
{
1837
2113
    QDomElement ptsElem = doc.createElement("POINTS");
1838
2114
 
1839
 
    QStringList ptList = QStringList::split(' ', object.attribute("draw:points"));
 
2115
    QStringList ptList = QStringList::split(' ', object.attributeNS( ooNS::draw, "points", QString::null));
1840
2116
 
1841
2117
    QString pt_x, pt_y;
1842
2118
    double tmp_x, tmp_y;
1863
2139
 
1864
2140
void OoImpressImport::appendField(QDomDocument& doc, QDomElement& e, const QDomElement& object, uint pos)
1865
2141
{
1866
 
    const QString tag = object.tagName();
 
2142
    const QString tag = object.localName();
 
2143
    const QString ns = object.namespaceURI();
 
2144
    const bool isTextNS = ns == ooNS::text;
1867
2145
 
1868
2146
    QDomElement custom = doc.createElement("CUSTOM");
1869
2147
    custom.setAttribute("pos", pos);
1870
2148
    QDomElement variable = doc.createElement("VARIABLE");
1871
2149
 
1872
 
    if (tag == "text:date")
 
2150
    if (isTextNS && tag == "date")
1873
2151
    {
1874
 
        QDateTime dt(QDate::fromString(object.attribute("text:date-value"), Qt::ISODate));
 
2152
        QDateTime dt(QDate::fromString(object.attributeNS( ooNS::text, "date-value", QString::null), Qt::ISODate));
1875
2153
 
1876
 
        bool fixed = (object.hasAttribute("text:fixed") && object.attribute("text:fixed")=="true");
 
2154
        bool fixed = (object.hasAttributeNS( ooNS::text, "fixed") && object.attributeNS( ooNS::text, "fixed", QString::null)=="true");
1877
2155
 
1878
2156
        if (!dt.isValid()) {
1879
2157
            dt = QDateTime::currentDateTime(); // OOo docs say so :)
1898
2176
        dateElement.setAttribute("hour", time.hour());
1899
2177
        dateElement.setAttribute("minute", time.minute());
1900
2178
        dateElement.setAttribute("second", time.second());
1901
 
        if (object.hasAttribute("text:date-adjust"))
1902
 
            dateElement.setAttribute("correct", object.attribute("text:date-adjust"));
 
2179
        if (object.hasAttributeNS( ooNS::text, "date-adjust"))
 
2180
            dateElement.setAttribute("correct", object.attributeNS( ooNS::text, "date-adjust", QString::null));
1903
2181
 
1904
2182
        variable.appendChild(dateElement);
1905
2183
    }
1906
 
    else if (tag == "text:time")
 
2184
    else if (isTextNS && tag == "time")
1907
2185
    {
1908
2186
        // Use QDateTime to work around a possible problem of QTime::FromString in Qt 3.2.2
1909
 
        QDateTime dt(QDateTime::fromString(object.attribute("text:time-value"), Qt::ISODate));
 
2187
        QDateTime dt(QDateTime::fromString(object.attributeNS( ooNS::text, "time-value", QString::null), Qt::ISODate));
1910
2188
 
1911
 
        bool fixed = (object.hasAttribute("text:fixed") && object.attribute("text:fixed")=="true");
 
2189
        bool fixed = (object.hasAttributeNS( ooNS::text, "fixed") && object.attributeNS( ooNS::text, "fixed", QString::null)=="true");
1912
2190
 
1913
2191
        if (!dt.isValid()) {
1914
2192
            dt = QDateTime::currentDateTime(); // OOo docs say so :)
1929
2207
        timeElement.setAttribute("hour", time.hour());
1930
2208
        timeElement.setAttribute("minute", time.minute());
1931
2209
        timeElement.setAttribute("second", time.second());
1932
 
        /*if (object.hasAttribute("text:time-adjust"))
1933
 
          timeElem.setAttribute("correct", object.attribute("text:time-adjust"));*/ // ### TODO
 
2210
        /*if (object.hasAttributeNS( ooNS::text, "time-adjust"))
 
2211
          timeElem.setAttribute("correct", object.attributeNS( ooNS::text, "time-adjust", QString::null));*/ // ### TODO
1934
2212
 
1935
2213
        variable.appendChild(timeElement);
1936
2214
    }
1937
 
    else if (tag == "text:page-number")
 
2215
    else if (isTextNS && tag == "page-number")
1938
2216
    {
1939
2217
        QDomElement typeElem = doc.createElement("TYPE");
1940
2218
        typeElem.setAttribute("key", "NUMBER");
1947
2225
 
1948
2226
        int subtype = 0;        // VST_PGNUM_CURRENT
1949
2227
 
1950
 
        if (object.hasAttribute("text:select-page"))
 
2228
        if (object.hasAttributeNS( ooNS::text, "select-page"))
1951
2229
        {
1952
 
            const QString select = object.attribute("text:select-page");
 
2230
            const QString select = object.attributeNS( ooNS::text, "select-page", QString::null);
1953
2231
 
1954
2232
            if (select == "previous")
1955
2233
                subtype = 3;    // VST_PGNUM_PREVIOUS
1964
2242
 
1965
2243
        variable.appendChild(pgNumElem);
1966
2244
    }
1967
 
    else if (tag == "text:file-name")
 
2245
    else if (isTextNS && tag == "file-name")
1968
2246
    {
1969
2247
        QDomElement typeElem = doc.createElement("TYPE");
1970
2248
        typeElem.setAttribute("key", "STRING");
1975
2253
 
1976
2254
        int subtype = 5;
1977
2255
 
1978
 
        if (object.hasAttribute("text:display"))
 
2256
        if (object.hasAttributeNS( ooNS::text, "display"))
1979
2257
        {
1980
 
            const QString display = object.attribute("text:display");
 
2258
            const QString display = object.attributeNS( ooNS::text, "display", QString::null);
1981
2259
 
1982
2260
            if (display == "path")
1983
2261
                subtype = 1;    // VST_DIRECTORYNAME
1995
2273
 
1996
2274
        variable.appendChild(fileNameElem);
1997
2275
    }
1998
 
    else if (tag == "text:author-name"
1999
 
             || tag == "text:author-initials")
 
2276
    else if (isTextNS && tag == "author-name"
 
2277
             || isTextNS && tag == "author-initials")
2000
2278
    {
2001
2279
        QDomElement typeElem = doc.createElement("TYPE");
2002
2280
        typeElem.setAttribute("key", "STRING");
2007
2285
 
2008
2286
        int subtype = 2;        // VST_AUTHORNAME
2009
2287
 
2010
 
        if (tag == "text:author-initials")
 
2288
        if (isTextNS && tag == "author-initials")
2011
2289
            subtype = 16;       // VST_INITIAL
2012
2290
 
2013
2291
        QDomElement authorElem = doc.createElement("FIELD");
2021
2299
    e.appendChild(custom);
2022
2300
}
2023
2301
 
2024
 
QDomNode OoImpressImport::findAnimationByObjectID(const QString & id)
2025
 
{
2026
 
    if (m_animations.isNull() || !m_animations.hasChildNodes())
2027
 
        return QDomNode();
2028
 
 
2029
 
    for (QDomNode node = m_animations.firstChild(); !node.isNull(); node = node.nextSibling())
 
2302
void OoImpressImport::createPresentationAnimation(const QDomElement& element)
 
2303
{
 
2304
    int order = 0;
 
2305
    QDomElement e;
 
2306
    forEachElement( e, element )
 
2307
    {
 
2308
        const QString localName = e.localName();
 
2309
        const QString ns = e.namespaceURI();
 
2310
        if ( ns == ooNS::presentation && localName == "show-shape" && e.hasAttributeNS( ooNS::draw, "shape-id" ) )
 
2311
        {
 
2312
            QString name = e.attributeNS( ooNS::draw, "shape-id", QString::null );
 
2313
            //kdDebug(30518)<<" insert animation style : name :"<<name<<endl;
 
2314
            animationList *lst = new animationList;
 
2315
            QDomElement* ep = new QDomElement( e );
 
2316
            lst->element = ep;
 
2317
            lst->order = order;
 
2318
            m_animations.insert( name, lst );
 
2319
            ++order;
 
2320
        }
 
2321
    }
 
2322
}
 
2323
 
 
2324
QDomElement OoImpressImport::findAnimationByObjectID(const QString & id,  int & order)
 
2325
{
 
2326
    //kdDebug(30518)<<"QDomElement OoImpressImport::findAnimationByObjectID(const QString & id) :"<<id<<endl;
 
2327
    if (m_animations.isEmpty() )
 
2328
        return QDomElement();
 
2329
 
 
2330
    animationList *animation = m_animations[id];
 
2331
    //kdDebug(30518)<<"QDomElement *animation = m_animations[id]; :"<<animation<<endl;
 
2332
    if ( !animation )
 
2333
        return QDomElement();
 
2334
    for (QDomNode node = *( animation->element ); !node.isNull(); node = node.nextSibling())
2030
2335
    {
2031
2336
        QDomElement e = node.toElement();
2032
 
        if (e.tagName()=="presentation:show-shape" && e.attribute("draw:shape-id")==id)
2033
 
            return node;
 
2337
        order = animation->order;
 
2338
        //kdDebug(30518)<<"e.tagName() :"<<e.tagName()<<" e.attribute(draw:shape-id) :"<<e.attributeNS( ooNS::draw, "shape-id", QString::null)<<endl;
 
2339
        if (e.tagName()=="presentation:show-shape" && e.attributeNS( ooNS::draw, "shape-id", QString::null)==id)
 
2340
                return e;
2034
2341
    }
2035
2342
 
2036
 
    return QDomNode();
 
2343
    return QDomElement();
2037
2344
}
2038
2345
 
 
2346
 
2039
2347
void OoImpressImport::appendObjectEffect(QDomDocument& doc, QDomElement& e, const QDomElement& object,
2040
2348
                                         QDomElement& sound)
2041
2349
{
2042
 
    QDomElement origEffect = findAnimationByObjectID(object.attribute("draw:id")).toElement();
 
2350
    int order = 0;
 
2351
    QDomElement origEffect = findAnimationByObjectID(object.attributeNS( ooNS::draw, "id", QString::null), order).toElement();
2043
2352
 
2044
2353
    if (origEffect.isNull())
2045
2354
        return;
2046
2355
 
2047
 
    QString effect = origEffect.attribute("presentation:effect");
2048
 
    QString dir = origEffect.attribute("presentation:direction");
 
2356
    QString effect = origEffect.attributeNS( ooNS::presentation, "effect", QString::null);
 
2357
    QString dir = origEffect.attributeNS( ooNS::presentation, "direction", QString::null);
 
2358
    QString speed = origEffect.attributeNS( ooNS::presentation, "speed", QString::null);
 
2359
    kdDebug(30518)<<"speed :"<<speed<<endl;
 
2360
    //todo implement speed value.
 
2361
 
2049
2362
    int effVal=0;
2050
 
 
 
2363
    //kdDebug(30518)<<" effect :"<<effect<<" dir :"<<dir<<endl;
2051
2364
    if (effect=="fade")
2052
2365
    {
2053
2366
        if (dir=="from-right")
2089
2402
    effElem.setAttribute("effect", effVal);
2090
2403
    e.appendChild(effElem);
2091
2404
 
 
2405
    QDomElement presNum = doc.createElement( "PRESNUM" );
 
2406
    presNum.setAttribute("value", order);
 
2407
    e.appendChild( presNum );
 
2408
 
2092
2409
    // sound effect
2093
 
    QDomElement origSoundEff = origEffect.namedItem("presentation:sound").toElement();
 
2410
    QDomElement origSoundEff = KoDom::namedItemNS( origEffect, ooNS::presentation, "sound");
2094
2411
    if (!origSoundEff.isNull())
2095
2412
    {
2096
2413
        QString soundUrl = storeSound(origSoundEff, sound, doc);