[Libreoffice-commits] .: Branch 'libreoffice-3-5' - 2 commits - writerperfect/source

Fridrich Strba fridrich at kemper.freedesktop.org
Fri Jan 13 07:36:56 PST 2012


 writerperfect/source/filter/OdgGenerator.cxx |   64 +++++++++++++++++++++++----
 1 file changed, 55 insertions(+), 9 deletions(-)

New commits:
commit 932de5293bb250b4f85e99b9f84f8b4243e0604e
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Fri Jan 13 16:23:54 2012 +0100

    Implement flips and rotations of raster images in the OdgGenerator.cxx
    
    Signed-off-by: Fridrich Å trba <fridrich.strba at bluewin.ch>

diff --git a/writerperfect/source/filter/OdgGenerator.cxx b/writerperfect/source/filter/OdgGenerator.cxx
index 0f085e9..5681ed5 100644
--- a/writerperfect/source/filter/OdgGenerator.cxx
+++ b/writerperfect/source/filter/OdgGenerator.cxx
@@ -948,13 +948,13 @@ void OdgGenerator::drawPath(const WPXPropertyListVector &path)
 
 void OdgGenerator::drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData &binaryData)
 {
-    WPXPropertyList framePropList(propList);
-
-    if (!framePropList["libwpg:mime-type"] || framePropList["libwpg:mime-type"]->getStr().len() <= 0)
+    if (!propList["libwpg:mime-type"] || propList["libwpg:mime-type"]->getStr().len() <= 0)
+        return;
+    if (!propList["svg:x"] || !propList["svg:y"] || !propList["svg:width"] || !propList["svg:height"])
         return;
 
-    bool flipX(framePropList["draw:mirror-horizontal"] && framePropList["draw:mirror-horizontal"]->getInt());
-    bool flipY(framePropList["draw:mirror-vertical"] && framePropList["draw:mirror-vertical"]->getInt());
+    bool flipX(propList["draw:mirror-horizontal"] && propList["draw:mirror-horizontal"]->getInt());
+    bool flipY(propList["draw:mirror-vertical"] && propList["draw:mirror-vertical"]->getInt());
     if ((flipX && !flipY) || (!flipX && flipY))
         mpImpl->mxStyle.insert("style:mirror", "horizontal");
     else
@@ -962,39 +962,61 @@ void OdgGenerator::drawGraphicObject(const ::WPXPropertyList &propList, const ::
 
     mpImpl->_writeGraphicsStyle();
 
+    double x = propList["svg:x"]->getDouble();
+    double y = propList["svg:y"]->getDouble();
+    double height = propList["svg:height"]->getDouble();
+    double width = propList["svg:width"]->getDouble();
+
     if (flipY)
     {
-        double x = framePropList["svg:x"]->getDouble();
-        double y = framePropList["svg:y"]->getDouble();
-        double height = framePropList["svg:height"]->getDouble();
-        double width = framePropList["svg:width"]->getDouble();
         x += width;
         y += height;
         width *= -1.0;
         height *= -1.0;
-        framePropList.insert("svg:x", x);
-        framePropList.insert("svg:y", y);
-        framePropList.insert("svg:height", height);
-        framePropList.insert("svg:width", width);
     }
 
+    double angle(propList["libwpg:rotate"] ? - M_PI * propList["libwpg:rotate"]->getDouble() / 180.0 : 0.0);
+    if (angle != 0.0)
+    {
+        double deltax((width*cos(angle)+height*sin(angle)-width)/2.0);
+        double deltay((-width*sin(angle)+height*cos(angle)-height)/2.0);
+        x -= deltax;
+        y -= deltay;
+    }
+
+    WPXPropertyList framePropList;
+
+    framePropList.insert("svg:x", x);
+    framePropList.insert("svg:y", y);
+    framePropList.insert("svg:height", height);
+    framePropList.insert("svg:width", width);
+
     TagOpenElement *pDrawFrameElement = new TagOpenElement("draw:frame");
 
     WPXString sValue;
     sValue.sprintf("gr%i", mpImpl->miGraphicsStyleIndex-1);
     pDrawFrameElement->addAttribute("draw:style-name", sValue);
 
-    if (framePropList["svg:x"])
+    pDrawFrameElement->addAttribute("svg:height", framePropList["svg:height"]->getStr());
+    pDrawFrameElement->addAttribute("svg:width", framePropList["svg:width"]->getStr());
+
+    if (angle != 0.0)
+    {
+        framePropList.insert("libwpg:rotate", angle, WPX_GENERIC);
+        sValue.sprintf("rotate (%s) translate(%s, %s)",
+                       framePropList["libwpg:rotate"]->getStr().cstr(),
+                       framePropList["svg:x"]->getStr().cstr(),
+                       framePropList["svg:y"]->getStr().cstr());
+        pDrawFrameElement->addAttribute("draw:transform", sValue);
+    }
+    else
+    {
         pDrawFrameElement->addAttribute("svg:x", framePropList["svg:x"]->getStr());
-    if (framePropList["svg:y"])
         pDrawFrameElement->addAttribute("svg:y", framePropList["svg:y"]->getStr());
-    if (framePropList["svg:height"])
-        pDrawFrameElement->addAttribute("svg:height", framePropList["svg:height"]->getStr());
-    if (framePropList["svg:width"])
-        pDrawFrameElement->addAttribute("svg:width", framePropList["svg:width"]->getStr());
+    }
     mpImpl->mBodyElements.push_back(pDrawFrameElement);
 
-    if (framePropList["libwpg:mime-type"]->getStr() == "object/ole")
+    if (propList["libwpg:mime-type"]->getStr() == "object/ole")
         mpImpl->mBodyElements.push_back(new TagOpenElement("draw:object-ole"));
     else
         mpImpl->mBodyElements.push_back(new TagOpenElement("draw:image"));
@@ -1006,7 +1028,7 @@ void OdgGenerator::drawGraphicObject(const ::WPXPropertyList &propList, const ::
 
     mpImpl->mBodyElements.push_back(new TagCloseElement("office:binary-data"));
 
-    if (framePropList["libwpg:mime-type"]->getStr() == "object/ole")
+    if (propList["libwpg:mime-type"]->getStr() == "object/ole")
         mpImpl->mBodyElements.push_back(new TagCloseElement("draw:object-ole"));
     else
         mpImpl->mBodyElements.push_back(new TagCloseElement("draw:image"));
commit 36a2c47f6160681df9137416e0cda72c90b13147
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Fri Jan 13 14:26:03 2012 +0100

    Adapt to the more intuitive libvisio/libwpg API
    
    Signed-off-by: Fridrich Å trba <fridrich.strba at bluewin.ch>

diff --git a/writerperfect/source/filter/OdgGenerator.cxx b/writerperfect/source/filter/OdgGenerator.cxx
index fbafb02..0f085e9 100644
--- a/writerperfect/source/filter/OdgGenerator.cxx
+++ b/writerperfect/source/filter/OdgGenerator.cxx
@@ -948,29 +948,53 @@ void OdgGenerator::drawPath(const WPXPropertyListVector &path)
 
 void OdgGenerator::drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData &binaryData)
 {
-    if (!propList["libwpg:mime-type"] || propList["libwpg:mime-type"]->getStr().len() <= 0)
+    WPXPropertyList framePropList(propList);
+
+    if (!framePropList["libwpg:mime-type"] || framePropList["libwpg:mime-type"]->getStr().len() <= 0)
         return;
 
+    bool flipX(framePropList["draw:mirror-horizontal"] && framePropList["draw:mirror-horizontal"]->getInt());
+    bool flipY(framePropList["draw:mirror-vertical"] && framePropList["draw:mirror-vertical"]->getInt());
+    if ((flipX && !flipY) || (!flipX && flipY))
+        mpImpl->mxStyle.insert("style:mirror", "horizontal");
+    else
+        mpImpl->mxStyle.insert("style:mirror", "none");
+
     mpImpl->_writeGraphicsStyle();
 
-    TagOpenElement *pDrawFrameElement = new TagOpenElement("draw:frame");
+    if (flipY)
+    {
+        double x = framePropList["svg:x"]->getDouble();
+        double y = framePropList["svg:y"]->getDouble();
+        double height = framePropList["svg:height"]->getDouble();
+        double width = framePropList["svg:width"]->getDouble();
+        x += width;
+        y += height;
+        width *= -1.0;
+        height *= -1.0;
+        framePropList.insert("svg:x", x);
+        framePropList.insert("svg:y", y);
+        framePropList.insert("svg:height", height);
+        framePropList.insert("svg:width", width);
+    }
 
+    TagOpenElement *pDrawFrameElement = new TagOpenElement("draw:frame");
 
     WPXString sValue;
     sValue.sprintf("gr%i", mpImpl->miGraphicsStyleIndex-1);
     pDrawFrameElement->addAttribute("draw:style-name", sValue);
 
-    if (propList["svg:x"])
-        pDrawFrameElement->addAttribute("svg:x", propList["svg:x"]->getStr());
-    if (propList["svg:y"])
-        pDrawFrameElement->addAttribute("svg:y", propList["svg:y"]->getStr());
-    if (propList["svg:height"])
-        pDrawFrameElement->addAttribute("svg:height", propList["svg:height"]->getStr());
-    if (propList["svg:width"])
-        pDrawFrameElement->addAttribute("svg:width", propList["svg:width"]->getStr());
+    if (framePropList["svg:x"])
+        pDrawFrameElement->addAttribute("svg:x", framePropList["svg:x"]->getStr());
+    if (framePropList["svg:y"])
+        pDrawFrameElement->addAttribute("svg:y", framePropList["svg:y"]->getStr());
+    if (framePropList["svg:height"])
+        pDrawFrameElement->addAttribute("svg:height", framePropList["svg:height"]->getStr());
+    if (framePropList["svg:width"])
+        pDrawFrameElement->addAttribute("svg:width", framePropList["svg:width"]->getStr());
     mpImpl->mBodyElements.push_back(pDrawFrameElement);
 
-    if (propList["libwpg:mime-type"]->getStr() == "object/ole")
+    if (framePropList["libwpg:mime-type"]->getStr() == "object/ole")
         mpImpl->mBodyElements.push_back(new TagOpenElement("draw:object-ole"));
     else
         mpImpl->mBodyElements.push_back(new TagOpenElement("draw:image"));
@@ -982,7 +1006,7 @@ void OdgGenerator::drawGraphicObject(const ::WPXPropertyList &propList, const ::
 
     mpImpl->mBodyElements.push_back(new TagCloseElement("office:binary-data"));
 
-    if (propList["libwpg:mime-type"]->getStr() == "object/ole")
+    if (framePropList["libwpg:mime-type"]->getStr() == "object/ole")
         mpImpl->mBodyElements.push_back(new TagCloseElement("draw:object-ole"));
     else
         mpImpl->mBodyElements.push_back(new TagCloseElement("draw:image"));


More information about the Libreoffice-commits mailing list