~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to filters/kpresenter/kword/kprkword.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <QColor>
29
29
 
30
30
typedef KGenericFactory<KprKword> KprKwordFactory;
31
 
K_EXPORT_COMPONENT_FACTORY( libkprkword, KprKwordFactory( "kofficefilters" ) )
 
31
K_EXPORT_COMPONENT_FACTORY(libkprkword, KprKwordFactory("kofficefilters"))
32
32
 
33
 
KprKword::KprKword(QObject *parent,const QStringList&) :
34
 
    KoFilter(parent),
35
 
    outdoc( "DOC" )
 
33
KprKword::KprKword(QObject *parent, const QStringList&) :
 
34
        KoFilter(parent),
 
35
        outdoc("DOC")
36
36
{
37
37
}
38
38
 
39
39
// This filter can act as an import filter for KWord and as an export
40
40
// filter for KPresenter (isn't our architecture really nice ? :)
41
41
// This is why we use the file-to-file method, not a QDomDoc one.
42
 
KoFilter::ConversionStatus KprKword::convert( const QByteArray& from, const QByteArray& to )
 
42
KoFilter::ConversionStatus KprKword::convert(const QByteArray& from, const QByteArray& to)
43
43
{
44
 
    if(to!="application/x-kword" || from!="application/x-kpresenter")
 
44
    if (to != "application/x-kword" || from != "application/x-kpresenter")
45
45
        return KoFilter::NotImplemented;
46
46
 
47
 
    KoStoreDevice* inpdev = m_chain->storageFile( "root", KoStore::Read );
48
 
    if ( !inpdev )
49
 
    {
 
47
    KoStoreDevice* inpdev = m_chain->storageFile("root", KoStore::Read);
 
48
    if (!inpdev) {
50
49
        kError(30502) << "Unable to open input stream" << endl;
51
50
        return KoFilter::StorageCreationError;
52
51
    }
53
52
 
54
 
    inpdoc.setContent( inpdev );
55
 
 
56
 
 
57
 
    outdoc.appendChild( outdoc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
58
 
    QDomElement kwdoc = outdoc.createElement( "DOC" );
59
 
    kwdoc.setAttribute( "editor", "KprKword converter" );
60
 
    kwdoc.setAttribute( "mime", "application/x-kword" );
61
 
    kwdoc.setAttribute( "syntaxVersion", 1 );
62
 
    outdoc.appendChild( kwdoc );
63
 
 
64
 
    QDomElement paper = outdoc.createElement( "PAPER" );
65
 
    kwdoc.appendChild( paper );
66
 
    paper.setAttribute( "format", 1 ); // A4. How on earth could I know what the user really wants ? :)
67
 
    paper.setAttribute( "width", 595 );
68
 
    paper.setAttribute( "height", 841 );
69
 
    QDomElement borders = outdoc.createElement( "PAPERBORDERS" );
70
 
    paper.appendChild( borders );
71
 
    borders.setAttribute( "left", 28 );
72
 
    borders.setAttribute( "top", 42 );
73
 
    borders.setAttribute( "right", 28 );
74
 
    borders.setAttribute( "bottom", 42 );
75
 
 
76
 
    QDomElement framesets = outdoc.createElement( "FRAMESETS" );
77
 
    kwdoc.appendChild( framesets );
78
 
 
79
 
    frameset = outdoc.createElement( "FRAMESET" );
80
 
    framesets.appendChild( frameset );
81
 
    frameset.setAttribute( "frameType", 1 ); // text
82
 
    frameset.setAttribute( "frameInfo", 0 ); // body
83
 
    QDomElement frame = outdoc.createElement( "FRAME" );
84
 
    frameset.appendChild( frame );
85
 
    frame.setAttribute( "left", 28 );
86
 
    frame.setAttribute( "top", 42 );
87
 
    frame.setAttribute( "right", 566 );
88
 
    frame.setAttribute( "bottom", 798 );
89
 
    frame.setAttribute( "autoCreateNewFrame", 1 );
90
 
    frame.setAttribute( "newFrameBehaviour", 0 );
 
53
    inpdoc.setContent(inpdev);
 
54
 
 
55
 
 
56
    outdoc.appendChild(outdoc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
 
57
    QDomElement kwdoc = outdoc.createElement("DOC");
 
58
    kwdoc.setAttribute("editor", "KprKword converter");
 
59
    kwdoc.setAttribute("mime", "application/x-kword");
 
60
    kwdoc.setAttribute("syntaxVersion", 1);
 
61
    outdoc.appendChild(kwdoc);
 
62
 
 
63
    QDomElement paper = outdoc.createElement("PAPER");
 
64
    kwdoc.appendChild(paper);
 
65
    paper.setAttribute("format", 1);   // A4. How on earth could I know what the user really wants ? :)
 
66
    paper.setAttribute("width", 595);
 
67
    paper.setAttribute("height", 841);
 
68
    QDomElement borders = outdoc.createElement("PAPERBORDERS");
 
69
    paper.appendChild(borders);
 
70
    borders.setAttribute("left", 28);
 
71
    borders.setAttribute("top", 42);
 
72
    borders.setAttribute("right", 28);
 
73
    borders.setAttribute("bottom", 42);
 
74
 
 
75
    QDomElement framesets = outdoc.createElement("FRAMESETS");
 
76
    kwdoc.appendChild(framesets);
 
77
 
 
78
    frameset = outdoc.createElement("FRAMESET");
 
79
    framesets.appendChild(frameset);
 
80
    frameset.setAttribute("frameType", 1);   // text
 
81
    frameset.setAttribute("frameInfo", 0);   // body
 
82
    QDomElement frame = outdoc.createElement("FRAME");
 
83
    frameset.appendChild(frame);
 
84
    frame.setAttribute("left", 28);
 
85
    frame.setAttribute("top", 42);
 
86
    frame.setAttribute("right", 566);
 
87
    frame.setAttribute("bottom", 798);
 
88
    frame.setAttribute("autoCreateNewFrame", 1);
 
89
    frame.setAttribute("newFrameBehaviour", 0);
91
90
 
92
91
    titleStyleName = i18n("Slide Title");
93
92
 
97
96
 
98
97
    // Create a style for the slide titles
99
98
 
100
 
    QDomElement styles = outdoc.createElement( "STYLES" );
101
 
    kwdoc.appendChild( styles );
102
 
 
103
 
    QDomElement style = outdoc.createElement( "STYLE" );
104
 
    styles.appendChild( style );
105
 
    QDomElement elem = outdoc.createElement( "NAME" );
106
 
    style.appendChild( elem );
107
 
    elem.setAttribute( "value", titleStyleName );
108
 
    elem = outdoc.createElement( "FOLLOWING" );
109
 
    style.appendChild( elem );
110
 
    elem.setAttribute( "name", "Standard" ); // no i18n here!
111
 
 
112
 
    QDomElement counter = outdoc.createElement( "COUNTER" );
113
 
    style.appendChild( counter );
114
 
    counter.setAttribute( "type", 1 ); // numbered
115
 
    counter.setAttribute( "depth", 0 );
116
 
    counter.setAttribute( "start", 1 );
117
 
    counter.setAttribute( "numberingtype", 1 ); // chapter
118
 
    counter.setAttribute( "righttext", "." );
119
 
 
120
 
    QDomElement format = outdoc.createElement( "FORMAT" );
121
 
    style.appendChild( format );
122
 
    QDomElement font = outdoc.createElement( "FONT" );
123
 
    format.appendChild( font );
124
 
    font.setAttribute( "name", titleFont ); // found when reading the first title
125
 
    QDomElement size = outdoc.createElement( "SIZE" );
126
 
    format.appendChild( size );
127
 
    size.setAttribute( "value", 24 );
128
 
    QDomElement bold = outdoc.createElement( "WEIGHT" );
129
 
    format.appendChild( bold );
130
 
    bold.setAttribute( "value", 75 );
 
99
    QDomElement styles = outdoc.createElement("STYLES");
 
100
    kwdoc.appendChild(styles);
 
101
 
 
102
    QDomElement style = outdoc.createElement("STYLE");
 
103
    styles.appendChild(style);
 
104
    QDomElement elem = outdoc.createElement("NAME");
 
105
    style.appendChild(elem);
 
106
    elem.setAttribute("value", titleStyleName);
 
107
    elem = outdoc.createElement("FOLLOWING");
 
108
    style.appendChild(elem);
 
109
    elem.setAttribute("name", "Standard");   // no i18n here!
 
110
 
 
111
    QDomElement counter = outdoc.createElement("COUNTER");
 
112
    style.appendChild(counter);
 
113
    counter.setAttribute("type", 1);   // numbered
 
114
    counter.setAttribute("depth", 0);
 
115
    counter.setAttribute("start", 1);
 
116
    counter.setAttribute("numberingtype", 1);   // chapter
 
117
    counter.setAttribute("righttext", ".");
 
118
 
 
119
    QDomElement format = outdoc.createElement("FORMAT");
 
120
    style.appendChild(format);
 
121
    QDomElement font = outdoc.createElement("FONT");
 
122
    format.appendChild(font);
 
123
    font.setAttribute("name", titleFont);   // found when reading the first title
 
124
    QDomElement size = outdoc.createElement("SIZE");
 
125
    format.appendChild(size);
 
126
    size.setAttribute("value", 24);
 
127
    QDomElement bold = outdoc.createElement("WEIGHT");
 
128
    format.appendChild(bold);
 
129
    bold.setAttribute("value", 75);
131
130
 
132
131
    // Create the standard style
133
 
    style = outdoc.createElement( "STYLE" );
134
 
    styles.appendChild( style );
135
 
    elem = outdoc.createElement( "NAME" );
136
 
    style.appendChild( elem );
137
 
    elem.setAttribute( "value", "Standard" ); // no i18n here!
138
 
    format = outdoc.createElement( "FORMAT" );
139
 
    style.appendChild( format ); // empty format == use defaults
 
132
    style = outdoc.createElement("STYLE");
 
133
    styles.appendChild(style);
 
134
    elem = outdoc.createElement("NAME");
 
135
    style.appendChild(elem);
 
136
    elem.setAttribute("value", "Standard");   // no i18n here!
 
137
    format = outdoc.createElement("FORMAT");
 
138
    style.appendChild(format);   // empty format == use defaults
140
139
 
141
140
    // Write output file
142
141
 
143
 
    KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write );
144
 
    if(!out) {
 
142
    KoStoreDevice* out = m_chain->storageFile("root", KoStore::Write);
 
143
    if (!out) {
145
144
        kError(30502) << "Unable to open output file!" << endl;
146
145
        return KoFilter::StorageCreationError;
147
146
    }
148
147
    QByteArray cstring = outdoc.toByteArray(); // utf-8 already
149
 
    out->write( cstring.data(), cstring.length() );
 
148
    out->write(cstring.data(), cstring.length());
150
149
    out->close();
151
150
    return KoFilter::OK;
152
151
}
153
152
 
154
153
// This class is used to sort the objects by y position
155
 
class KprObject {
156
 
 public:
 
154
class KprObject
 
155
{
 
156
public:
157
157
    double y;
158
158
    QDomElement elem;
159
 
    bool operator < ( const KprObject & c ) const
160
 
    {
 
159
    bool operator < (const KprObject & c) const {
161
160
        return y < c.y;
162
161
    }
163
 
    bool operator == ( const KprObject & c ) const
164
 
    {
 
162
    bool operator == (const KprObject & c) const {
165
163
        return y == c.y;
166
164
    }
167
165
};
169
167
void KprKword::convert()
170
168
{
171
169
    QDomElement docElem = inpdoc.documentElement();
172
 
    QDomElement paper = docElem.namedItem( "PAPER" ).toElement();
173
 
    int ptPageHeight = paper.attribute( "ptHeight" ).toInt();
 
170
    QDomElement paper = docElem.namedItem("PAPER").toElement();
 
171
    int ptPageHeight = paper.attribute("ptHeight").toInt();
174
172
 
175
 
    QDomElement objects = docElem.namedItem( "OBJECTS" ).toElement();
176
 
    if ( objects.isNull() )
 
173
    QDomElement objects = docElem.namedItem("OBJECTS").toElement();
 
174
    if (objects.isNull())
177
175
        return;
178
176
 
179
177
    QList< KprObject > objList;
180
178
    qSort(objList.begin(), list.end());
181
 
    QDomNodeList lst = objects.elementsByTagName( "OBJECT" );
 
179
    QDomNodeList lst = objects.elementsByTagName("OBJECT");
182
180
    uint lstcount = lst.count();
183
 
    for ( uint item = 0 ; item < lstcount ; ++item )
184
 
    {
185
 
        QDomElement object = lst.item( item ).toElement();
186
 
        if ( object.attribute( "type" ).toInt() == 4 ) // we only care about text objs
187
 
        {
188
 
            QDomElement orig = object.namedItem( "ORIG" ).toElement();
189
 
            if ( !orig.isNull() )
190
 
            {
 
181
    for (uint item = 0 ; item < lstcount ; ++item) {
 
182
        QDomElement object = lst.item(item).toElement();
 
183
        if (object.attribute("type").toInt() == 4) {   // we only care about text objs
 
184
            QDomElement orig = object.namedItem("ORIG").toElement();
 
185
            if (!orig.isNull()) {
191
186
                KprObject * obj = new KprObject;
192
 
                obj->y = orig.attribute( "y" ).toDouble();
 
187
                obj->y = orig.attribute("y").toDouble();
193
188
                obj->elem = object;
194
 
                objList.inSort( obj );
 
189
                objList.inSort(obj);
195
190
            }
196
191
        }
197
192
    }
199
194
    int curPage = -1;
200
195
    //kDebug() <<"found" << objList.count() <<" objects";
201
196
    foreach(KprObject* it, objList) {
202
 
    {
 
197
 
203
198
        QDomElement elem = it->elem;
204
199
        // Detect the first object of each page
205
 
        int page = int( it->y / ptPageHeight );
206
 
        bool isTitle = ( page > curPage );
 
200
        int page = int(it->y / ptPageHeight);
 
201
        bool isTitle = (page > curPage);
207
202
        //kDebug() <<"KprKword::convert y=" << it->y <<" ptPageHeight=" << ptPageHeight
208
203
        //          << " isTitle=" << isTitle << endl;
209
204
        curPage = page;
210
205
 
211
 
        QDomElement textObj = elem.namedItem( "TEXTOBJ" ).toElement();
 
206
        QDomElement textObj = elem.namedItem("TEXTOBJ").toElement();
212
207
        if (textObj.isNull())
213
208
            continue;
214
209
        // For each paragraph in this text object...
215
 
        QDomNodeList lst = textObj.elementsByTagName( "P" );
 
210
        QDomNodeList lst = textObj.elementsByTagName("P");
216
211
        uint lstcount = lst.count();
217
 
        for ( uint item = 0; item < lstcount ; ++item )
218
 
        {
219
 
            QDomElement p = lst.item( item ).toElement();
 
212
        for (uint item = 0; item < lstcount ; ++item) {
 
213
            QDomElement p = lst.item(item).toElement();
220
214
 
221
215
            // Create paragraph in KWord doc
222
 
            QDomElement parag = outdoc.createElement( "PARAGRAPH" );
223
 
            frameset.appendChild( parag );
 
216
            QDomElement parag = outdoc.createElement("PARAGRAPH");
 
217
            frameset.appendChild(parag);
224
218
 
225
 
            QDomElement outFormatsElem = outdoc.createElement( "FORMATS" );
 
219
            QDomElement outFormatsElem = outdoc.createElement("FORMATS");
226
220
 
227
221
            QString text;
228
222
            // For each text element in the paragraph...
229
223
            QDomElement textElem = p.firstChild().toElement();
230
224
 
231
 
            QDomElement counter = p.namedItem( "COUNTER" ).toElement();
232
 
            QDomElement indent=p.namedItem("INDENTS").toElement();
233
 
            QDomElement lineSpacing=p.namedItem( "LINESPACING" ).toElement();
234
 
            QDomElement offset=p.namedItem("OFFSETS").toElement();
235
 
            QDomElement leftBorder = p.namedItem( "LEFTBORDER" ).toElement();
236
 
            QDomElement rightBorder = p.namedItem( "RIGHTBORDER" ).toElement();
237
 
            QDomElement topBorder = p.namedItem( "TOPBORDER" ).toElement();
238
 
            QDomElement bottomBorder = p.namedItem( "BOTTOMBORDER" ).toElement();
239
 
 
240
 
            QDomElement shadow=p.namedItem("SHADOW").toElement();
241
 
 
242
 
            for ( ; !textElem.isNull() ; textElem = textElem.nextSibling().toElement() )
243
 
            {
 
225
            QDomElement counter = p.namedItem("COUNTER").toElement();
 
226
            QDomElement indent = p.namedItem("INDENTS").toElement();
 
227
            QDomElement lineSpacing = p.namedItem("LINESPACING").toElement();
 
228
            QDomElement offset = p.namedItem("OFFSETS").toElement();
 
229
            QDomElement leftBorder = p.namedItem("LEFTBORDER").toElement();
 
230
            QDomElement rightBorder = p.namedItem("RIGHTBORDER").toElement();
 
231
            QDomElement topBorder = p.namedItem("TOPBORDER").toElement();
 
232
            QDomElement bottomBorder = p.namedItem("BOTTOMBORDER").toElement();
 
233
 
 
234
            QDomElement shadow = p.namedItem("SHADOW").toElement();
 
235
 
 
236
            for (; !textElem.isNull() ; textElem = textElem.nextSibling().toElement()) {
244
237
                int oldLen = text.length();
245
238
                text += textElem.text();
246
239
                //kDebug() <<"KprKword::convert text now" << text;
247
 
                QDomElement outFormatElem = outdoc.createElement( "FORMAT" );
 
240
                QDomElement outFormatElem = outdoc.createElement("FORMAT");
248
241
 
249
 
                if ( textElem.attribute( "italic" ).toInt() )
250
 
                {
 
242
                if (textElem.attribute("italic").toInt()) {
251
243
                    QDomElement e = outdoc.createElement("ITALIC");
252
 
                    e.setAttribute( "value", 1 );
253
 
                    outFormatElem.appendChild( e );
 
244
                    e.setAttribute("value", 1);
 
245
                    outFormatElem.appendChild(e);
254
246
                }
255
247
                QColor underlineColor;
256
 
                if ( textElem.hasAttribute("underlinecolor" ))
257
 
                {
258
 
                    underlineColor =QColor(textElem.attribute("underlinecolor" ));
 
248
                if (textElem.hasAttribute("underlinecolor")) {
 
249
                    underlineColor = QColor(textElem.attribute("underlinecolor"));
259
250
                }
260
251
                QString underlineStyleLine;
261
 
                if ( textElem.hasAttribute("underlinestyleline"))
262
 
                {
 
252
                if (textElem.hasAttribute("underlinestyleline")) {
263
253
                    underlineStyleLine = textElem.attribute("underlinestyleline");
264
254
                }
265
 
                if ( textElem.hasAttribute("underline" ))
266
 
                {
 
255
                if (textElem.hasAttribute("underline")) {
267
256
                    QDomElement e = outdoc.createElement("UNDERLINE");
268
 
                    QString value = textElem.attribute( "underline" );
269
 
                     if ( value == "double" )
270
 
                     {
271
 
                         e.setAttribute( "value", "double" );
272
 
                     }
273
 
                     else if ( value == "single" )
274
 
                     {
275
 
                         e.setAttribute( "value", "double" );
276
 
                     }
277
 
                     else
278
 
                     {
279
 
                         e.setAttribute( "value", (bool)value.toInt() ? "1" :"0" );
280
 
                     }
281
 
                     if ( underlineColor.isValid())
282
 
                     {
283
 
                         e.setAttribute("underlinecolor", underlineColor.name());
284
 
                     }
285
 
                     if ( !underlineStyleLine.isEmpty() )
286
 
                         e.setAttribute("styleline", underlineStyleLine);
287
 
                     outFormatElem.appendChild( e );
 
257
                    QString value = textElem.attribute("underline");
 
258
                    if (value == "double") {
 
259
                        e.setAttribute("value", "double");
 
260
                    } else if (value == "single") {
 
261
                        e.setAttribute("value", "double");
 
262
                    } else {
 
263
                        e.setAttribute("value", (bool)value.toInt() ? "1" : "0");
 
264
                    }
 
265
                    if (underlineColor.isValid()) {
 
266
                        e.setAttribute("underlinecolor", underlineColor.name());
 
267
                    }
 
268
                    if (!underlineStyleLine.isEmpty())
 
269
                        e.setAttribute("styleline", underlineStyleLine);
 
270
                    outFormatElem.appendChild(e);
288
271
 
289
272
                }
290
273
 
291
274
                QString strikeOutStyleLine;
292
 
                if ( textElem.hasAttribute("strikeoutstyleline"))
293
 
                {
 
275
                if (textElem.hasAttribute("strikeoutstyleline")) {
294
276
                    strikeOutStyleLine = textElem.attribute("strikeoutstyleline");
295
277
                }
296
278
                QString strikeOutValue;
297
 
                if ( textElem.hasAttribute("strikeOut"))
298
 
                {
 
279
                if (textElem.hasAttribute("strikeOut")) {
299
280
                    strikeOutValue = textElem.attribute("strikeOut");
300
281
                }
301
282
 
302
 
                if( !strikeOutValue.isEmpty())
303
 
                {
 
283
                if (!strikeOutValue.isEmpty()) {
304
284
                    QDomElement e = outdoc.createElement("STRIKEOUT");
305
 
                    e.setAttribute( "value", strikeOutValue );
306
 
                    if ( !strikeOutStyleLine.isEmpty())
 
285
                    e.setAttribute("value", strikeOutValue);
 
286
                    if (!strikeOutStyleLine.isEmpty())
307
287
                        e.setAttribute("styleline", strikeOutStyleLine);
308
 
                    outFormatElem.appendChild( e );
 
288
                    outFormatElem.appendChild(e);
309
289
                }
310
290
                /*if ( textElem.attribute( "bold" ).toInt() )
311
291
                {
313
293
                    e.setAttribute( "value", 75 );
314
294
                    outFormatElem.appendChild( e );
315
295
                }*/ // doesn't look good
316
 
                if ( titleFont.isEmpty() && isTitle )
317
 
                    titleFont = textElem.attribute( "family" );
 
296
                if (titleFont.isEmpty() && isTitle)
 
297
                    titleFont = textElem.attribute("family");
318
298
 
319
299
                // Family and point size are voluntarily NOT passed over.
320
 
                if ( !textElem.attribute( "color" ).isEmpty())
321
 
                {
 
300
                if (!textElem.attribute("color").isEmpty()) {
322
301
                    QColor col;
323
 
                    col.setNamedColor(textElem.attribute( "color" ));
 
302
                    col.setNamedColor(textElem.attribute("color"));
324
303
                    QDomElement e = outdoc.createElement("COLOR");
325
 
                    e.setAttribute( "red", col.red() );
326
 
                    e.setAttribute( "green", col.green() );
327
 
                    e.setAttribute( "blue", col.blue() );
328
 
                    outFormatElem.appendChild( e );
 
304
                    e.setAttribute("red", col.red());
 
305
                    e.setAttribute("green", col.green());
 
306
                    e.setAttribute("blue", col.blue());
 
307
                    outFormatElem.appendChild(e);
329
308
                }
330
 
                if ( !textElem.attribute("textbackcolor").isEmpty())
331
 
                {
 
309
                if (!textElem.attribute("textbackcolor").isEmpty()) {
332
310
                    QColor col;
333
 
                    col.setNamedColor(textElem.attribute( "textbackcolor" ));
 
311
                    col.setNamedColor(textElem.attribute("textbackcolor"));
334
312
                    QDomElement e = outdoc.createElement("TEXTBACKGROUNDCOLOR");
335
 
                    e.setAttribute( "red", col.red() );
336
 
                    e.setAttribute( "green", col.green() );
337
 
                    e.setAttribute( "blue", col.blue() );
338
 
                    outFormatElem.appendChild( e );
 
313
                    e.setAttribute("red", col.red());
 
314
                    e.setAttribute("green", col.green());
 
315
                    e.setAttribute("blue", col.blue());
 
316
                    outFormatElem.appendChild(e);
339
317
                }
340
318
 
341
319
                //before VERTICAL align
342
320
                double relative = 0;
343
 
                if( textElem.attribute("relativetextsize").toDouble())
344
 
                {
 
321
                if (textElem.attribute("relativetextsize").toDouble()) {
345
322
                    relative = textElem.attribute("relativetextsize").toDouble();
346
323
                }
347
324
 
348
325
 
349
 
                if( textElem.attribute("VERTALIGN").toInt())
350
 
                {
 
326
                if (textElem.attribute("VERTALIGN").toInt()) {
351
327
                    QDomElement e = outdoc.createElement("VERTALIGN");
352
 
                    e.setAttribute( "value", textElem.attribute("VERTALIGN").toInt() );
353
 
                    if ( relative != 0)
354
 
                        e.setAttribute( "relativetextsize", relative );
355
 
                    outFormatElem.appendChild( e );
 
328
                    e.setAttribute("value", textElem.attribute("VERTALIGN").toInt());
 
329
                    if (relative != 0)
 
330
                        e.setAttribute("relativetextsize", relative);
 
331
                    outFormatElem.appendChild(e);
356
332
                }
357
333
 
358
 
                if( textElem.hasAttribute("shadowtext"))
359
 
                {
 
334
                if (textElem.hasAttribute("shadowtext")) {
360
335
                    QDomElement e = outdoc.createElement("SHADOWTEXT");
361
 
                    e.setAttribute( "value", textElem.attribute("shadowtext").toInt() );
362
 
                    outFormatElem.appendChild( e );
 
336
                    e.setAttribute("value", textElem.attribute("shadowtext").toInt());
 
337
                    outFormatElem.appendChild(e);
363
338
                }
364
339
 
365
 
                if( textElem.hasAttribute("offsetfrombaseline"))
366
 
                {
 
340
                if (textElem.hasAttribute("offsetfrombaseline")) {
367
341
                    QDomElement e = outdoc.createElement("OFFSETFROMBASELINE");
368
 
                    e.setAttribute( "value", textElem.attribute("offsetfrombaseline").toInt() );
369
 
                    outFormatElem.appendChild( e );
 
342
                    e.setAttribute("value", textElem.attribute("offsetfrombaseline").toInt());
 
343
                    outFormatElem.appendChild(e);
370
344
                }
371
345
 
372
 
                if( textElem.hasAttribute("wordbyword"))
373
 
                {
 
346
                if (textElem.hasAttribute("wordbyword")) {
374
347
                    QDomElement e = outdoc.createElement("WORDBYWORD");
375
 
                    e.setAttribute( "value", textElem.attribute("wordbyword").toInt() );
376
 
                    outFormatElem.appendChild( e );
 
348
                    e.setAttribute("value", textElem.attribute("wordbyword").toInt());
 
349
                    outFormatElem.appendChild(e);
377
350
                }
378
351
 
379
 
                if( textElem.hasAttribute("fontattribute"))
380
 
                {
 
352
                if (textElem.hasAttribute("fontattribute")) {
381
353
                    QDomElement e = outdoc.createElement("FONTATTRIBUTE");
382
 
                    e.setAttribute( "value", textElem.attribute("fontattribute") );
383
 
                    outFormatElem.appendChild( e );
 
354
                    e.setAttribute("value", textElem.attribute("fontattribute"));
 
355
                    outFormatElem.appendChild(e);
384
356
                }
385
 
                if( textElem.hasAttribute("language"))
386
 
                {
 
357
                if (textElem.hasAttribute("language")) {
387
358
                    QDomElement e = outdoc.createElement("LANGUAGE");
388
 
                    e.setAttribute( "value", textElem.attribute("language") );
389
 
                    outFormatElem.appendChild( e );
 
359
                    e.setAttribute("value", textElem.attribute("language"));
 
360
                    outFormatElem.appendChild(e);
390
361
                }
391
 
                if ( !outFormatElem.firstChild().isNull() )
392
 
                {
393
 
                    outFormatElem.setAttribute( "id", 1 ); // normal exte
394
 
                    outFormatElem.setAttribute( "pos", oldLen );
395
 
                    outFormatElem.setAttribute( "len", text.length() - oldLen );
396
 
                    outFormatsElem.appendChild( outFormatElem );
 
362
                if (!outFormatElem.firstChild().isNull()) {
 
363
                    outFormatElem.setAttribute("id", 1);   // normal exte
 
364
                    outFormatElem.setAttribute("pos", oldLen);
 
365
                    outFormatElem.setAttribute("len", text.length() - oldLen);
 
366
                    outFormatsElem.appendChild(outFormatElem);
397
367
                }
398
368
 
399
369
            } // end "for each text element"
400
370
 
401
371
            // KPresenter seems to save a trailing space (bug!)
402
372
            int len = text.length();
403
 
            if ( len > 0 && text[ len - 1 ] == ' ' )
404
 
                text.truncate( len - 1 );
405
 
 
406
 
            QDomElement outTextElem = outdoc.createElement( "TEXT" );
407
 
            parag.appendChild( outTextElem );
408
 
            outTextElem.appendChild( outdoc.createTextNode( text ) );
409
 
 
410
 
            if ( !outFormatsElem.firstChild().isNull() ) // Do we have formats to save ?
411
 
                parag.appendChild( outFormatsElem );
412
 
 
413
 
            QDomElement layoutElem = outdoc.createElement( "LAYOUT" );
414
 
            parag.appendChild( layoutElem );
415
 
            QDomElement nameElem = outdoc.createElement( "NAME" );
416
 
            layoutElem.appendChild( nameElem );
417
 
            nameElem.setAttribute( "value", isTitle ? titleStyleName : QString("Standard") );
418
 
            QDomElement align=outdoc.createElement("FLOW");
419
 
            if(p.hasAttribute("align"))
420
 
            {
421
 
                switch(p.attribute( "align" ).toInt())
422
 
                {
 
373
            if (len > 0 && text[ len - 1 ] == ' ')
 
374
                text.truncate(len - 1);
 
375
 
 
376
            QDomElement outTextElem = outdoc.createElement("TEXT");
 
377
            parag.appendChild(outTextElem);
 
378
            outTextElem.appendChild(outdoc.createTextNode(text));
 
379
 
 
380
            if (!outFormatsElem.firstChild().isNull())   // Do we have formats to save ?
 
381
                parag.appendChild(outFormatsElem);
 
382
 
 
383
            QDomElement layoutElem = outdoc.createElement("LAYOUT");
 
384
            parag.appendChild(layoutElem);
 
385
            QDomElement nameElem = outdoc.createElement("NAME");
 
386
            layoutElem.appendChild(nameElem);
 
387
            nameElem.setAttribute("value", isTitle ? titleStyleName : QString("Standard"));
 
388
            QDomElement align = outdoc.createElement("FLOW");
 
389
            if (p.hasAttribute("align")) {
 
390
                switch (p.attribute("align").toInt()) {
423
391
                case 1:
424
 
                    align.setAttribute( "align","left");
 
392
                    align.setAttribute("align", "left");
425
393
                    break;
426
394
                case 2:
427
 
                    align.setAttribute( "align","right");
 
395
                    align.setAttribute("align", "right");
428
396
                    break;
429
397
                case 4:
430
 
                    align.setAttribute( "align","center");
 
398
                    align.setAttribute("align", "center");
431
399
                    break;
432
400
                case 8:
433
 
                    align.setAttribute( "align","justify");
 
401
                    align.setAttribute("align", "justify");
434
402
                    break;
435
403
                }
436
404
            }
437
 
            if(!counter.isNull() )
438
 
                layoutElem.appendChild( counter );
439
 
            if(!indent.isNull())
440
 
                layoutElem.appendChild( indent );
441
 
            if(!lineSpacing.isNull())
442
 
                layoutElem.appendChild( lineSpacing );
443
 
            if(!offset.isNull())
444
 
                layoutElem.appendChild( offset);
445
 
            if(!leftBorder.isNull())
 
405
            if (!counter.isNull())
 
406
                layoutElem.appendChild(counter);
 
407
            if (!indent.isNull())
 
408
                layoutElem.appendChild(indent);
 
409
            if (!lineSpacing.isNull())
 
410
                layoutElem.appendChild(lineSpacing);
 
411
            if (!offset.isNull())
 
412
                layoutElem.appendChild(offset);
 
413
            if (!leftBorder.isNull())
446
414
                layoutElem.appendChild(leftBorder);
447
 
            if(!rightBorder.isNull())
 
415
            if (!rightBorder.isNull())
448
416
                layoutElem.appendChild(rightBorder);
449
 
            if(!topBorder.isNull())
 
417
            if (!topBorder.isNull())
450
418
                layoutElem.appendChild(topBorder);
451
 
            if(!bottomBorder.isNull())
 
419
            if (!bottomBorder.isNull())
452
420
                layoutElem.appendChild(bottomBorder);
453
 
            if(!align.isNull())
 
421
            if (!align.isNull())
454
422
                layoutElem.appendChild(align);
455
 
            if(!shadow.isNull())
 
423
            if (!shadow.isNull())
456
424
                layoutElem.appendChild(shadow);
457
425
            // Only the first parag of the top text object is set to the 'title' style
458
426
            isTitle = false;