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

« back to all changes in this revision

Viewing changes to kword/part/KWOdfWriter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include "KWOdfWriter.h"
25
25
#include "KWDocument.h"
26
 
#include <rdf/KoDocumentRdfBase.h>
27
26
#include "KWPage.h"
28
27
 
29
 
#include <ktemporaryfile.h>
30
 
 
31
28
#include "frames/KWTextFrameSet.h"
32
29
#include "frames/KWTextFrame.h"
33
30
#include <KoXmlWriter.h>
44
41
#include <KoTextSharedSavingData.h>
45
42
 
46
43
#include <KoStoreDevice.h>
 
44
#include <rdf/KoDocumentRdfBase.h>
47
45
 
48
46
#include <QBuffer>
49
47
#include <QTextCursor>
50
48
#include <KDebug>
 
49
#include <ktemporaryfile.h>
51
50
 
52
51
QByteArray KWOdfWriter::serializeHeaderFooter(KoEmbeddedDocumentSaver &embeddedSaver, KoGenStyles &mainStyles, KoGenChanges  &changes, KWTextFrameSet *fs)
53
52
{
76
75
    Q_ASSERT(shapedata);
77
76
 
78
77
    writer.startElement(tag);
79
 
    shapedata->saveOdf(context, 0, -1, m_document->documentRdfBase());
 
78
    shapedata->saveOdf(context, m_document->documentRdfBase());
80
79
    writer.endElement();
81
80
 
82
81
    return content;
241
240
        //  3) frames that are not anchored but freely positioned somewhere on the page.
242
241
        //     in ODF terms those frames are page-anchored.
243
242
 
244
 
        if (fs->frameCount() == 1 && fs->frames().first()->shape()->parent())
245
 
            continue; // is a frame that is anchored to text, don't save those here.
 
243
        if (fs->frameCount() == 1) {
 
244
            KoShape *shape = fs->frames().first()->shape();
 
245
            // may be a frame that is anchored to text, don't save those here.
 
246
            // but first check since clipped shapes look similar, but are not anchored to text
 
247
            if (shape->parent() && !shape->parent()->isClipped(shape))
 
248
                continue;
 
249
        }
246
250
 
247
251
        KWTextFrameSet *tfs = dynamic_cast<KWTextFrameSet*>(fs);
248
252
        if (tfs) {
255
259
            }
256
260
        }
257
261
 
258
 
        KWFrame *lastNonCopyFrame = 0;
259
262
        int counter = 1;
260
263
        QSet<QString> uniqueNames;
261
264
        foreach (KWFrame *frame, fs->frames()) { // make sure all shapes have names.
269
272
        const QList<KWFrame*> frames = fs->frames();
270
273
        for (int i = 0; i < frames.count(); ++i) {
271
274
            KWFrame *frame = frames.at(i);
272
 
            KoShape *shape = frame->shape();
273
 
            // frame properties first
274
 
            shape->setAdditionalStyleAttribute("fo:margin", QString::number(frame->runAroundDistance()) + "pt");
275
 
            shape->setAdditionalStyleAttribute("style:horizontal-pos", "from-left");
276
 
            shape->setAdditionalStyleAttribute("style:horizontal-rel", "page");
277
 
            shape->setAdditionalStyleAttribute("style:vertical-pos", "from-top");
278
 
            shape->setAdditionalStyleAttribute("style:vertical-rel", "page");
279
 
            QString value;
280
 
            switch (frame->textRunAround()) {
281
 
            case KWord::RunAround:
282
 
                switch (frame->runAroundSide()) {
283
 
                case KWord::BiggestRunAroundSide: value = "biggest"; break;
284
 
                case KWord::LeftRunAroundSide: value = "left"; break;
285
 
                case KWord::RightRunAroundSide: value = "right"; break;
286
 
                case KWord::AutoRunAroundSide: value = "dynamic"; break;
287
 
                case KWord::BothRunAroundSide: value = "parallel"; break;
288
 
                }
289
 
                break;
290
 
            case KWord::RunThrough:
291
 
                value = "run-through";
292
 
                break;
293
 
            case KWord::NoRunAround:
294
 
                value = "none";
295
 
                break;
296
 
            }
297
 
            shape->setAdditionalStyleAttribute("style:wrap", value);
298
 
 
299
 
            switch (frame->frameBehavior()) {
300
 
            case KWord::AutoCreateNewFrameBehavior:
301
 
                value = "auto-create-new-frame";
302
 
                break;
303
 
            case KWord::IgnoreContentFrameBehavior:
304
 
                value = "clip";
305
 
                break;
306
 
            case KWord::AutoExtendFrameBehavior:
307
 
                // the third case, AutoExtendFrame is handled by min-height
308
 
                value.clear();
309
 
                KWTextFrame *tf = dynamic_cast<KWTextFrame*>(frame);
310
 
                if (tf && tf->minimumFrameHeight() > 1)
311
 
                    shape->setAdditionalAttribute("fo:min-height", QString::number(tf->minimumFrameHeight()) + "pt");
312
 
                break;
313
 
            }
314
 
            if (!value.isEmpty())
315
 
                shape->setAdditionalStyleAttribute("style:overflow-behavior", value);
316
 
 
317
 
            if (frame->frameBehavior() != KWord::IgnoreContentFrameBehavior) {
318
 
                switch (frame->newFrameBehavior()) {
319
 
                case KWord::ReconnectNewFrame: value = "followup"; break;
320
 
                case KWord::NoFollowupFrame: value.clear(); break; // "none" is the default
321
 
                case KWord::CopyNewFrame: value = "copy"; break;
322
 
                }
323
 
                if (!value.isEmpty()) {
324
 
                    shape->setAdditionalStyleAttribute("koffice:frame-behavior-on-new-page", value);
325
 
                    if (! frame->frameOnBothSheets())
326
 
                        shape->setAdditionalAttribute("koffice:frame-copy-to-facing-pages", "true");
327
 
                }
328
 
            }
329
 
 
330
 
            if (frame->isCopy()) {
331
 
                Q_ASSERT(lastNonCopyFrame);
332
 
                shape->setAdditionalAttribute("draw:copy-of", lastNonCopyFrame->shape()->name());
333
 
            } else {
334
 
                lastNonCopyFrame = frame;
335
 
            }
336
 
 
337
 
            // shape properties
338
 
            KWPage page = m_document->pageManager()->page(shape);
339
 
            const qreal pagePos = page.offsetInDocument();
340
 
 
341
 
            const int effectiveZIndex = shape->zIndex() + m_zIndexOffsets.value(page);
342
 
            shape->setAdditionalAttribute("draw:z-index", QString::number(effectiveZIndex));
343
 
            shape->setAdditionalAttribute("text:anchor-type", "page");
344
 
            shape->setAdditionalAttribute("text:anchor-page-number", QString::number(page.pageNumber()));
345
 
            context.addShapeOffset(shape, QMatrix(1, 0, 0 , 1, 0, -pagePos));
346
 
            shape->saveOdf(context);
347
 
            context.removeShapeOffset(shape);
348
 
            shape->removeAdditionalAttribute("draw:copy-of");
349
 
            shape->removeAdditionalAttribute("draw:z-index");
350
 
            shape->removeAdditionalAttribute("fo:min-height");
351
 
            shape->removeAdditionalAttribute("koffice:frame-copy-to-facing-pages");
352
 
            shape->removeAdditionalAttribute("text:anchor-page-number");
353
 
            shape->removeAdditionalAttribute("text:anchor-page-number");
354
 
            shape->removeAdditionalAttribute("text:anchor-type");
 
275
            KWPage page = m_document->pageManager()->page(frame->shape());
 
276
            frame->saveOdf(context, page, m_zIndexOffsets.value(page));
355
277
        }
356
278
    }
357
279
 
367
289
                    tbf.setProperty(KoParagraphStyle::MasterPageName, m_masterPages.value(style));
368
290
                    cursor.mergeBlockFormat(tbf);
369
291
                }
370
 
                shapeData->saveOdf(context, 0, -1, m_document->documentRdfBase());
 
292
                shapeData->saveOdf(context, m_document->documentRdfBase());
371
293
            }
372
294
        }
373
295
    }
383
305
    tmpChangeFile.close();
384
306
    bodyWriter->addCompleteElement(&tmpChangeFile);
385
307
 
386
 
    bodyWriter->startElement("text:page-sequence");
387
 
    foreach (KWPage page, m_document->pageManager()->pages()) {
388
 
        Q_ASSERT(m_masterPages.contains(page.pageStyle()));
389
 
        bodyWriter->startElement("text:page");
390
 
        bodyWriter->addAttribute("text:master-page-name", m_masterPages.value(page.pageStyle()));
391
 
        bodyWriter->endElement(); // text:page
 
308
    // Do not write out text:page-sequence, if there is a maintTextFrame
 
309
    // The ODF specification does not allow text:page-sequence in office:text
 
310
    // if there is e.g. text:p or text:h there
 
311
    if (!mainTextFrame) {
 
312
        bodyWriter->startElement("text:page-sequence");
 
313
        foreach (KWPage page, m_document->pageManager()->pages()) {
 
314
            Q_ASSERT(m_masterPages.contains(page.pageStyle()));
 
315
            bodyWriter->startElement("text:page");
 
316
            bodyWriter->addAttribute("text:master-page-name",
 
317
                    m_masterPages.value(page.pageStyle()));
 
318
            bodyWriter->endElement(); // text:page
 
319
        }
 
320
        bodyWriter->endElement(); // text:page-sequence
392
321
    }
393
 
    bodyWriter->endElement(); // text:page-sequence
394
322
 
395
323
    delete tmpBodyWriter;
396
324
    tmpBodyWriter = 0;
466
394
{
467
395
    Q_ASSERT(m_zIndexOffsets.isEmpty()); // call this method only once, please.
468
396
    foreach (KWFrameSet *fs, m_document->frameSets()) {
469
 
        if (KWord::isAutoGenerated(dynamic_cast<KWTextFrameSet*>(fs)))
 
397
        if (KWord::isAutoGenerated(fs))
470
398
            continue;
471
399
        foreach (KWFrame *frame, fs->frames()) {
472
400
            addShapeToTree(frame->shape());
490
418
    // add the children of a KoShapeContainer
491
419
    KoShapeContainer *container = dynamic_cast<KoShapeContainer*>(shape);
492
420
    if (container) {
493
 
        foreach(KoShape *containerShape, container->childShapes()) {
 
421
        foreach(KoShape *containerShape, container->shapes()) {
494
422
            addShapeToTree(containerShape);
495
423
        }
496
424
    }