summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2012-01-13 13:55:11 +0100
committerFridrich Štrba <fridrich.strba@bluewin.ch>2012-01-13 13:55:11 +0100
commit08d9a5ad6fbdddefc6ea51ab06750d38e33dac50 (patch)
tree9268d94bcb51f6b0ba0ce7d12979f795cde51899
parent4d4e4e44fe790bce9e7fab4ee4aedc7b41a1a360 (diff)
Simplify the API a bit
Since the way LO handles flips is counterintuitive, use properties from custom shapes "draw:mirror-horizontal" and "draw:mirror-vertical" instead of negative heights and widths. This makes libvisio/libwpg API more intuitive.
-rw-r--r--src/lib/VSDSVGGenerator.cpp43
-rw-r--r--src/lib/VSDXContentCollector.cpp31
2 files changed, 20 insertions, 54 deletions
diff --git a/src/lib/VSDSVGGenerator.cpp b/src/lib/VSDSVGGenerator.cpp
index 58a5a73..de832ff 100644
--- a/src/lib/VSDSVGGenerator.cpp
+++ b/src/lib/VSDSVGGenerator.cpp
@@ -435,52 +435,31 @@ void libvisio::VSDSVGGenerator::drawGraphicObject(const ::WPXPropertyList &propL
m_outputSink << "<svg:image ";
if (propList["svg:x"] && propList["svg:y"] && propList["svg:width"] && propList["svg:height"])
{
- 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 mirror = (m_style["style:mirror"] && m_style["style:mirror"]->getStr() == "horizontal" ? true : false);
- bool flipX = false;
- bool flipY = false;
- if (width < 0.0)
- {
- width = -width;
- x = x - width;
- flipX = true;
- }
- if (height < 0.0)
- {
- height = -height;
- y = y - height;
- flipY = true;
- }
-
- if (mirror)
- flipX = !flipX;
-
- if (flipX)
- x = -(x + width);
- if (flipY)
- y = -(y + height);
+ 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=\"";
- // rotation is around the center of the objects bounding box
+ 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();
+ double angle(propList["libwpg:rotate"]->getDouble());
while (angle > 180.0)
angle -= 360.0;
while (angle < -180.0)
angle += 360.0;
- m_outputSink << " translate(" << doubleToString((flipX ? -1 : 1)*72*xmiddle) << ", " << doubleToString ((flipY ? -1 : 1)*72*ymiddle) << ") ";
m_outputSink << " rotate(" << doubleToString(angle) << ") ";
- m_outputSink << " translate(" << doubleToString((flipX ? 1 : -1)*72*xmiddle) << ", " << doubleToString ((flipY ? 1 : -1)*72*ymiddle) << ") ";
}
- m_outputSink << " scale(" << (flipX ? "-1" : "1") << ", " << (flipY ? "-1" : "1") << ") ";
+ m_outputSink << " translate(" << doubleToString(-72*xmiddle) << ", " << doubleToString (-72*ymiddle) << ") ";
m_outputSink << "\" ";
}
m_outputSink << "xlink:href=\"data:" << propList["libwpg:mime-type"]->getStr().cstr() << ";base64,";
diff --git a/src/lib/VSDXContentCollector.cpp b/src/lib/VSDXContentCollector.cpp
index 0c3c45a..2851d3f 100644
--- a/src/lib/VSDXContentCollector.cpp
+++ b/src/lib/VSDXContentCollector.cpp
@@ -812,31 +812,18 @@ void libvisio::VSDXContentCollector::_flushCurrentForeignData()
break;
}
-
WPXPropertyList styleProps(m_styleProps);
+ m_currentForeignProps.insert("svg:x", m_scale*(xmiddle - (m_foreignWidth / 2.0)));
+ m_currentForeignProps.insert("svg:width", m_scale*m_foreignWidth);
+ m_currentForeignProps.insert("svg:y", m_scale*(ymiddle - (m_foreignHeight / 2.0)));
+ m_currentForeignProps.insert("svg:height", m_scale*m_foreignHeight);
+
+ if (flipX)
+ m_currentForeignProps.insert("draw:mirror-horizontal", true);
if (flipY)
- {
- m_currentForeignProps.insert("svg:x", m_scale*(xmiddle + (m_foreignWidth / 2.0)));
- m_currentForeignProps.insert("svg:width", -m_scale*m_foreignWidth);
- m_currentForeignProps.insert("svg:y", m_scale*(ymiddle + (m_foreignHeight / 2.0)));
- m_currentForeignProps.insert("svg:height", -m_scale*m_foreignHeight);
- if (flipX)
- styleProps.insert("style:mirror", "none");
- else
- styleProps.insert("style:mirror", "horizontal");
- }
- else
- {
- m_currentForeignProps.insert("svg:x", m_scale*(xmiddle - (m_foreignWidth / 2.0)));
- m_currentForeignProps.insert("svg:width", m_scale*m_foreignWidth);
- m_currentForeignProps.insert("svg:y", m_scale*(ymiddle - (m_foreignHeight / 2.0)));
- m_currentForeignProps.insert("svg:height", m_scale*m_foreignHeight);
- if (flipX)
- styleProps.insert("style:mirror", "horizontal");
- else
- styleProps.insert("style:mirror", "none");
- }
+ m_currentForeignProps.insert("draw:mirror-vertical", true);
+
if (angle != 0.0)
m_currentForeignProps.insert("libwpg:rotate", angle * 180 / M_PI, WPX_GENERIC);