[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice
From:       Thomas Zander <zander () kde ! org>
Date:       2010-04-23 18:21:17
Message-ID: 20100423182117.050ECAC8B0 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1118034 by zander:

Save the clipping of a shape.

This is a bit tricky to verify since OOo is, ehm, odd...
First it only actually recognizes the clip option if the parent style
is "Graphics". Thats a literal name, it doesn't matter if the style is
defined or not.
In OOo the unit system used for the clip is not in document units, not
sure what it expects.

 M  +9 -5      kword/part/KWOdfWriter.cpp  
 M  +29 -2     libs/flake/KoShape.cpp  


--- trunk/koffice/kword/part/KWOdfWriter.cpp #1118033:1118034
@@ -23,11 +23,8 @@
 
 #include "KWOdfWriter.h"
 #include "KWDocument.h"
-#include <rdf/KoDocumentRdfBase.h>
 #include "KWPage.h"
 
-#include <ktemporaryfile.h>
-
 #include "frames/KWTextFrameSet.h"
 #include "frames/KWTextFrame.h"
 #include <KoXmlWriter.h>
@@ -44,10 +41,12 @@
 #include <KoTextSharedSavingData.h>
 
 #include <KoStoreDevice.h>
+#include <rdf/KoDocumentRdfBase.h>
 
 #include <QBuffer>
 #include <QTextCursor>
 #include <KDebug>
+#include <ktemporaryfile.h>
 
 QByteArray KWOdfWriter::serializeHeaderFooter(KoEmbeddedDocumentSaver \
&embeddedSaver, KoGenStyles &mainStyles, KoGenChanges  &changes, KWTextFrameSet *fs)  \
{ @@ -241,8 +240,13 @@
         //  3) frames that are not anchored but freely positioned somewhere on the \
page.  //     in ODF terms those frames are page-anchored.
 
-        if (fs->frameCount() == 1 && fs->frames().first()->shape()->parent())
-            continue; // is a frame that is anchored to text, don't save those here.
+        if (fs->frameCount() == 1) {
+            KoShape *shape = fs->frames().first()->shape();
+            // may be a frame that is anchored to text, don't save those here.
+            // but first check since clipped shapes look similar, but are not \
anchored to text +            if (shape->parent() && \
!shape->parent()->childClipped(shape)) +                continue;
+        }
 
         KWTextFrameSet *tfs = dynamic_cast<KWTextFrameSet*>(fs);
         if (tfs) {
--- trunk/koffice/libs/flake/KoShape.cpp #1118033:1118034
@@ -1,6 +1,6 @@
 /* This file is part of the KDE project
    Copyright (C) 2006 Casper Boemann Rasmussen <cbr@boemann.dk>
-   Copyright (C) 2006-2009 Thomas Zander <zander@kde.org>
+   Copyright (C) 2006-2010 Thomas Zander <zander@kde.org>
    Copyright (C) 2006-2010 Thorsten Zachmann <zachmann@kde.org>
    Copyright (C) 2007-2009 Jan Hambrecht <jaham@gmx.net>
 
@@ -947,6 +947,23 @@
         style.addProperty(it.key(), it.value());
     }
 
+    if (parent() && parent()->childClipped(this)) {
+        /*
+         * In KOffice clipping is done using a parent shape which can be rotated, \
sheared etc +         * and even non-square.  So the ODF interoperability version we \
write here is really +         * just a very simple version of that...
+         */
+        qreal top = -position().y();
+        qreal left = -position().x();
+        qreal right = parent()->size().width() - size().width() - left;
+        qreal bottom = parent()->size().height() - size().height() - top;
+
+        style.addProperty("fo:clip", QString("rect(%1pt, %2pt, %3pt, %4pt)")
+                .arg(top, 10, 'f').arg(right, 10, 'f')
+                .arg(bottom, 10, 'f').arg(left, 10, 'f'));
+
+    }
+
     return context.mainStyles().insert(style, \
context.isSet(KoShapeSavingContext::PresentationShape) ? "pr" : "gr");  }
 
@@ -1282,7 +1299,17 @@
     }
 
     if (attributes & OdfSize) {
-        const QSizeF s(size());
+        QSizeF s(size());
+        if (parent() && parent()->childClipped(this)) { // being clipped shrinks our \
visible size +            // clipping in ODF is done using a combination of visual \
size and content cliprect. +            // A picture of 10cm x 10cm displayed in a \
box of 2cm x 4cm will be scaled (out +            // of proportion in this case).  If \
we then add a fo:clip like; +            // fo:clip="rect(2cm, 3cm, 4cm, 5cm)" (top, \
right, bottom, left) +            // our original 10x10 is clipped to 2cm x 4cm  and \
*then* fitted in that box. +
+            // TODO do this properly by subtracting rects
+            s = parent()->size();
+        }
         context.xmlWriter().addAttributePt("svg:width", s.width());
         context.xmlWriter().addAttributePt("svg:height", s.height());
     }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic