[Libreoffice-commits] libcdr.git: 2 commits - src/lib

Fridrich Å trba fridrich.strba at bluewin.ch
Wed Feb 27 00:31:31 PST 2013


 src/lib/CDRParser.cpp       |    4 -
 src/lib/CDRSVGGenerator.cpp |   96 ++++++++++++++++++++++++++++++++++++++------
 src/lib/CDRTransforms.cpp   |    2 
 3 files changed, 86 insertions(+), 16 deletions(-)

New commits:
commit 16aad5b68991bb0ae2874f8a7fa196fab8fe5990
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Wed Feb 27 09:31:05 2013 +0100

    Some improvements in rotation of objects in SVG generator

diff --git a/src/lib/CDRSVGGenerator.cpp b/src/lib/CDRSVGGenerator.cpp
index be717b6..910f0d7 100644
--- a/src/lib/CDRSVGGenerator.cpp
+++ b/src/lib/CDRSVGGenerator.cpp
@@ -368,10 +368,9 @@ void libcdr::CDRSVGGenerator::drawEllipse(const WPXPropertyList &propList)
   m_outputSink << "rx=\"" << doubleToString(72*propList["svg:rx"]->getDouble()) << "\" ry=\"" << doubleToString(72*propList["svg:ry"]->getDouble()) << "\" ";
   writeStyle();
   if (propList["libwpg:rotate"] && propList["libwpg:rotate"]->getDouble() != 0.0)
-    m_outputSink << " transform=\" translate(" << doubleToString(72*propList["svg:cx"]->getDouble()) << ", " << doubleToString(72*propList["svg:cy"]->getDouble())
-                 << ") rotate(" << doubleToString(-propList["libwpg:rotate"]->getDouble())
-                 << ") translate(" << doubleToString(-72*propList["svg:cx"]->getDouble())
-                 << ", " << doubleToString(-72*propList["svg:cy"]->getDouble())
+    m_outputSink << " transform=\" rotate(" << doubleToString(-propList["libwpg:rotate"]->getDouble())
+                 << ", " << doubleToString(72*propList["svg:cy"]->getDouble())
+                 << ", " << doubleToString(72*propList["svg:cy"]->getDouble())
                  << ")\" ";
   m_outputSink << "/>\n";
 }
@@ -459,7 +458,7 @@ void libcdr::CDRSVGGenerator::drawPath(const ::WPXPropertyListVector &path)
       m_outputSink << (propList["libwpg:sweep"] ? propList["libwpg:sweep"]->getInt() : 1) << " ";
       m_outputSink << doubleToString(72*(propList["svg:x"]->getDouble())) << "," << doubleToString(72*(propList["svg:y"]->getDouble()));
     }
-    else if ((i >= path.count()-1 && i > 2) && propList["libwpg:path-action"] && propList["libwpg:path-action"]->getStr() == "Z" )
+    else if (propList["libwpg:path-action"] && propList["libwpg:path-action"]->getStr() == "Z")
     {
       isClosed = true;
       m_outputSink << "\nZ";
@@ -478,8 +477,34 @@ void libcdr::CDRSVGGenerator::drawGraphicObject(const ::WPXPropertyList &propLis
   WPXString base64 = binaryData.getBase64Data();
   m_outputSink << "<svg:image ";
   if (propList["svg:x"] && propList["svg:y"] && propList["svg:width"] && propList["svg:height"])
-    m_outputSink << "x=\"" << doubleToString(72*(propList["svg:x"]->getDouble())) << "\" y=\"" << doubleToString(72*(propList["svg:y"]->getDouble())) << "\" ";
-  m_outputSink << "width=\"" << doubleToString(72*(propList["svg:width"]->getDouble())) << "\" height=\"" << doubleToString(72*(propList["svg:height"]->getDouble())) << "\" ";
+  {
+    double x(propList["svg:x"]->getDouble());
+    double y(propList["svg:y"]->getDouble());
+    double width(propList["svg:width"]->getDouble());
+    double height(propList["svg:height"]->getDouble());
+    bool flipX(propList["draw:mirror-horizontal"] && propList["draw:mirror-horizontal"]->getInt());
+    bool flipY(propList["draw:mirror-vertical"] && propList["draw:mirror-vertical"]->getInt());
+
+    double xmiddle = x + width / 2.0;
+    double ymiddle = y + height / 2.0;
+    m_outputSink << "x=\"" << doubleToString(72*x) << "\" y=\"" << doubleToString(72*y) << "\" ";
+    m_outputSink << "width=\"" << doubleToString(72*width) << "\" height=\"" << doubleToString(72*height) << "\" ";
+    m_outputSink << "transform=\"";
+    m_outputSink << " translate(" << doubleToString(72*xmiddle) << ", " << doubleToString (72*ymiddle) << ") ";
+    m_outputSink << " scale(" << (flipX ? "-1" : "1") << ", " << (flipY ? "-1" : "1") << ") ";
+    // rotation is around the center of the object's bounding box
+    if (propList["libwpg:rotate"])
+    {
+      double angle(propList["libwpg:rotate"]->getDouble());
+      while (angle > 180.0)
+        angle -= 360.0;
+      while (angle < -180.0)
+        angle += 360.0;
+      m_outputSink << " rotate(" << doubleToString(angle) << ") ";
+    }
+    m_outputSink << " translate(" << doubleToString(-72*xmiddle) << ", " << doubleToString (-72*ymiddle) << ") ";
+    m_outputSink << "\" ";
+  }
   m_outputSink << "xlink:href=\"data:" << propList["libwpg:mime-type"]->getStr().cstr() << ";base64,";
   m_outputSink << base64.cstr();
   m_outputSink << "\" />\n";
@@ -487,15 +512,60 @@ void libcdr::CDRSVGGenerator::drawGraphicObject(const ::WPXPropertyList &propLis
 
 void libcdr::CDRSVGGenerator::startTextObject(const ::WPXPropertyList &propList, const ::WPXPropertyListVector & /* path */)
 {
+  double x = 0.0;
+  double y = 0.0;
+  double height = 0.0;
   m_outputSink << "<svg:text ";
   if (propList["svg:x"] && propList["svg:y"])
-    m_outputSink << "x=\"" << doubleToString(72*(propList["svg:x"]->getDouble())) << "\" y=\"" << doubleToString(72*(propList["svg:y"]->getDouble())) << "\"";
+  {
+    x = propList["svg:x"]->getDouble();
+    y = propList["svg:y"]->getDouble();
+  }
+
+  double xmiddle = x;
+  double ymiddle = y;
+
+  if (propList["svg:width"])
+  {
+    double width = propList["svg:width"]->getDouble();
+    xmiddle += width / 2.0;
+  }
+
+  if (propList["svg:height"])
+  {
+    height = propList["svg:height"]->getDouble();
+    ymiddle += height / 2.0;
+  }
+
+  if (propList["draw:textarea-vertical-align"])
+  {
+    if (propList["draw:textarea-vertical-align"]->getStr() == "middle")
+      y = ymiddle;
+    if (propList["draw:textarea-vertical-align"]->getStr() == "bottom")
+    {
+      y += height;
+      if (propList["fo:padding-bottom"])
+        y -= propList["fo:padding-bottom"]->getDouble();
+    }
+  }
+  else
+    y += height;
+
+  if (propList["fo:padding-left"])
+    x += propList["fo:padding-left"]->getDouble();
+
+  m_outputSink << "x=\"" << doubleToString(72*x) << "\" y=\"" << doubleToString(72*y) << "\"";
+
+  // rotation is around the center of the object's bounding box
   if (propList["libwpg:rotate"] && propList["libwpg:rotate"]->getDouble() != 0.0)
-    m_outputSink << " transform=\"translate(" << doubleToString(72*propList["svg:x"]->getDouble()) << ", " << doubleToString(72*propList["svg:y"]->getDouble())
-                 << ") rotate(" << doubleToString(-propList["libwpg:rotate"]->getDouble())
-                 << ") translate(" << doubleToString(-72*propList["svg:x"]->getDouble())
-                 << ", " << doubleToString(-72*propList["svg:y"]->getDouble())
-                 << ")\"";
+  {
+    double angle(propList["libwpg:rotate"]->getDouble());
+    while (angle > 180.0)
+      angle -= 360.0;
+    while (angle < -180.0)
+      angle += 360.0;
+    m_outputSink << " transform=\"rotate(" << doubleToString(angle) << ", " << doubleToString(72*xmiddle) << ", " << doubleToString(72*ymiddle) << ")\" ";
+  }
   m_outputSink << ">\n";
 
 }
commit 3f5713d58d85fb331d73ba01e958c4d3e628e0ee
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Wed Feb 27 08:55:22 2013 +0100

    Some more arc fixes

diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index 8ba5d0b..3e9f6c3 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -1206,10 +1206,10 @@ void libcdr::CDRParser::readEllipse(WPXInputStream *input)
     double x1 = cx + rx*cos(angle2);
     double y1 = cy - ry*sin(angle2);
 
-    bool largeArc = (angle2 - angle1 > M_PI || angle2 - angle1 < -M_PI);
+    bool largeArc = (angle2 - angle1 > M_PI);
 
     m_collector->collectMoveTo(x0, y0);
-    m_collector->collectArcTo(rx, ry, largeArc, true, x1, y1);
+    m_collector->collectArcTo(rx, ry, largeArc, false, x1, y1);
     if (pie)
     {
       m_collector->collectLineTo(cx, cy);
diff --git a/src/lib/CDRTransforms.cpp b/src/lib/CDRTransforms.cpp
index 9a76a21..5451b9b 100644
--- a/src/lib/CDRTransforms.cpp
+++ b/src/lib/CDRTransforms.cpp
@@ -120,7 +120,7 @@ void libcdr::CDRTransform::applyToArc(double &rx, double &ry, double &rotation,
     sweep = !sweep;
   if (v4 < 0)
     sweep = !sweep;
-  
+
 }
 
 double libcdr::CDRTransform::_getScaleX() const


More information about the Libreoffice-commits mailing list