diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2011-07-14 15:41:47 +0200 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2011-07-14 15:42:24 +0200 |
commit | 5844fa8dc25e035961ad7281149f14c91bc82b2d (patch) | |
tree | 5c49a1d9c5ff1f197a276ce512847bba32549814 /writerperfect | |
parent | 9daf5608e41b9d6d5896752bafe0525507a8c688 (diff) |
Trying to use the svg:fill-rule in ODG
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/source/filter/OdgGenerator.cxx | 120 |
1 files changed, 42 insertions, 78 deletions
diff --git a/writerperfect/source/filter/OdgGenerator.cxx b/writerperfect/source/filter/OdgGenerator.cxx index 5edb71ab4e4f..30d3e7a2a5de 100644 --- a/writerperfect/source/filter/OdgGenerator.cxx +++ b/writerperfect/source/filter/OdgGenerator.cxx @@ -100,7 +100,7 @@ static void getEllipticalArcBBox(double x1, double y1, // now compute bounding box of the whole ellipse - // Parametrick equation of an ellipse: + // Parametric equation of an ellipse: // x(theta) = cx + rx*cos(theta)*cos(phi) - ry*sin(theta)*sin(phi) // y(theta) = cy + rx*cos(theta)*sin(phi) + ry*sin(theta)*cos(phi) @@ -753,9 +753,7 @@ void OdgGeneratorPrivate::_drawPath(const WPXPropertyListVector& path) // accurate but that should be enough for this purpose bool isFirstPoint = true; - std::vector<double> px, py, qx, qy; - int boundingBoxIndex = 0; - px.push_back(0.0); py.push_back(0.0); qx.push_back(0.0); qy.push_back(0.0); + double px = 0.0, py = 0.0, qx = 0.0, qy = 0.0; double lastX = 0.0; double lastY = 0.0; @@ -763,40 +761,31 @@ void OdgGeneratorPrivate::_drawPath(const WPXPropertyListVector& path) { if (!path[k]["svg:x"] || !path[k]["svg:y"]) continue; - - if(path[k]["libwpg:path-action"]->getStr() == "M" && !isFirstPoint) - { - px.push_back(0.0); - py.push_back(0.0); - qx.push_back(0.0); - qy.push_back(0.0); - boundingBoxIndex++; - isFirstPoint = true; - } - if (isFirstPoint) { - px[boundingBoxIndex] = path[k]["svg:x"]->getDouble(); - py[boundingBoxIndex] = path[k]["svg:y"]->getDouble(); - qx[boundingBoxIndex] = px[boundingBoxIndex]; - qy[boundingBoxIndex] = py[boundingBoxIndex]; + px = path[k]["svg:x"]->getDouble(); + py = path[k]["svg:y"]->getDouble(); + qx = px; + qy = py; + lastX = px; + lastY = py; isFirstPoint = false; } - px[boundingBoxIndex] = (px[boundingBoxIndex] > path[k]["svg:x"]->getDouble()) ? path[k]["svg:x"]->getDouble() : px[boundingBoxIndex]; - py[boundingBoxIndex] = (py[boundingBoxIndex] > path[k]["svg:y"]->getDouble()) ? path[k]["svg:y"]->getDouble() : py[boundingBoxIndex]; - qx[boundingBoxIndex] = (qx[boundingBoxIndex] < path[k]["svg:x"]->getDouble()) ? path[k]["svg:x"]->getDouble() : qx[boundingBoxIndex]; - qy[boundingBoxIndex] = (qy[boundingBoxIndex] < path[k]["svg:y"]->getDouble()) ? path[k]["svg:y"]->getDouble() : qy[boundingBoxIndex]; + px = (px > path[k]["svg:x"]->getDouble()) ? path[k]["svg:x"]->getDouble() : px; + py = (py > path[k]["svg:y"]->getDouble()) ? path[k]["svg:y"]->getDouble() : py; + qx = (qx < path[k]["svg:x"]->getDouble()) ? path[k]["svg:x"]->getDouble() : qx; + qy = (qy < path[k]["svg:y"]->getDouble()) ? path[k]["svg:y"]->getDouble() : qy; if(path[k]["libwpg:path-action"]->getStr() == "C") { - px[boundingBoxIndex] = (px[boundingBoxIndex] > path[k]["svg:x1"]->getDouble()) ? path[k]["svg:x1"]->getDouble() : px[boundingBoxIndex]; - py[boundingBoxIndex] = (py[boundingBoxIndex] > path[k]["svg:y1"]->getDouble()) ? path[k]["svg:y1"]->getDouble() : py[boundingBoxIndex]; - qx[boundingBoxIndex] = (qx[boundingBoxIndex] < path[k]["svg:x1"]->getDouble()) ? path[k]["svg:x1"]->getDouble() : qx[boundingBoxIndex]; - qy[boundingBoxIndex] = (qy[boundingBoxIndex] < path[k]["svg:y1"]->getDouble()) ? path[k]["svg:y1"]->getDouble() : qy[boundingBoxIndex]; - px[boundingBoxIndex] = (px[boundingBoxIndex] > path[k]["svg:x2"]->getDouble()) ? path[k]["svg:x2"]->getDouble() : px[boundingBoxIndex]; - py[boundingBoxIndex] = (py[boundingBoxIndex] > path[k]["svg:y2"]->getDouble()) ? path[k]["svg:y2"]->getDouble() : py[boundingBoxIndex]; - qx[boundingBoxIndex] = (qx[boundingBoxIndex] < path[k]["svg:x2"]->getDouble()) ? path[k]["svg:x2"]->getDouble() : qx[boundingBoxIndex]; - qy[boundingBoxIndex] = (qy[boundingBoxIndex] < path[k]["svg:y2"]->getDouble()) ? path[k]["svg:y2"]->getDouble() : qy[boundingBoxIndex]; + px = (px > path[k]["svg:x1"]->getDouble()) ? path[k]["svg:x1"]->getDouble() : px; + py = (py > path[k]["svg:y1"]->getDouble()) ? path[k]["svg:y1"]->getDouble() : py; + qx = (qx < path[k]["svg:x1"]->getDouble()) ? path[k]["svg:x1"]->getDouble() : qx; + qy = (qy < path[k]["svg:y1"]->getDouble()) ? path[k]["svg:y1"]->getDouble() : qy; + px = (px > path[k]["svg:x2"]->getDouble()) ? path[k]["svg:x2"]->getDouble() : px; + py = (py > path[k]["svg:y2"]->getDouble()) ? path[k]["svg:y2"]->getDouble() : py; + qx = (qx < path[k]["svg:x2"]->getDouble()) ? path[k]["svg:x2"]->getDouble() : qx; + qy = (qy < path[k]["svg:y2"]->getDouble()) ? path[k]["svg:y2"]->getDouble() : qy; } if(path[k]["libwpg:path-action"]->getStr() == "A") { @@ -808,10 +797,10 @@ void OdgGeneratorPrivate::_drawPath(const WPXPropertyListVector& path) path[k]["libwpg:sweep"] ? path[k]["libwpg:sweep"]->getInt() : 1, path[k]["svg:x"]->getDouble(), path[k]["svg:y"]->getDouble(), xmin, ymin, xmax, ymax); - px[boundingBoxIndex] = (px[boundingBoxIndex] > xmin ? xmin : px[boundingBoxIndex]); - py[boundingBoxIndex] = (py[boundingBoxIndex] > ymin ? ymin : py[boundingBoxIndex]); - qx[boundingBoxIndex] = (qx[boundingBoxIndex] < xmax ? xmax : qx[boundingBoxIndex]); - qy[boundingBoxIndex] = (qy[boundingBoxIndex] < ymax ? ymax : qy[boundingBoxIndex]); + px = (px > xmin ? xmin : px); + py = (py > ymin ? ymin : py); + qx = (qx < xmax ? xmax : qx); + qy = (qy < ymax ? ymax : qy); } lastX = path[k]["svg:x"]->getDouble(); lastY = path[k]["svg:y"]->getDouble(); @@ -819,91 +808,63 @@ void OdgGeneratorPrivate::_drawPath(const WPXPropertyListVector& path) WPXString sValue; - boundingBoxIndex = 0; _writeGraphicsStyle(); TagOpenElement *pDrawPathElement = new TagOpenElement("draw:path"); sValue.sprintf("gr%i", miGraphicsStyleIndex-1); pDrawPathElement->addAttribute("draw:style-name", sValue); pDrawPathElement->addAttribute("draw:text-style-name", "P1"); pDrawPathElement->addAttribute("draw:layer", "layout"); - sValue = doubleToString(px[boundingBoxIndex]); sValue.append("in"); + sValue = doubleToString(px); sValue.append("in"); pDrawPathElement->addAttribute("svg:x", sValue); - sValue = doubleToString(py[boundingBoxIndex]); sValue.append("in"); + sValue = doubleToString(py); sValue.append("in"); pDrawPathElement->addAttribute("svg:y", sValue); - sValue = doubleToString((qx[boundingBoxIndex] - px[boundingBoxIndex])); sValue.append("in"); + sValue = doubleToString((qx - px)); sValue.append("in"); pDrawPathElement->addAttribute("svg:width", sValue); - sValue = doubleToString((qy[boundingBoxIndex] - py[boundingBoxIndex])); sValue.append("in"); + sValue = doubleToString((qy - py)); sValue.append("in"); pDrawPathElement->addAttribute("svg:height", sValue); - sValue.sprintf("%i %i %i %i", 0, 0, (unsigned)(2540*(qx[boundingBoxIndex] - px[boundingBoxIndex])), (unsigned)(2540*(qy[boundingBoxIndex] - py[boundingBoxIndex]))); + sValue.sprintf("%i %i %i %i", 0, 0, (unsigned)(2540*(qx - px)), (unsigned)(2540*(qy - py))); pDrawPathElement->addAttribute("svg:viewBox", sValue); sValue.clear(); - isFirstPoint = true; for(unsigned i = 0; i < path.count(); i++) { WPXString sElement; if (path[i]["libwpg:path-action"]->getStr() == "M") { - if (!isFirstPoint) - { - pDrawPathElement->addAttribute("svg:d", sValue); - mBodyElements.push_back(pDrawPathElement); - mBodyElements.push_back(new TagCloseElement("draw:path")); - boundingBoxIndex++; - pDrawPathElement = new TagOpenElement("draw:path"); - sValue.sprintf("gr%i", miGraphicsStyleIndex-1); - pDrawPathElement->addAttribute("draw:style-name", sValue); - pDrawPathElement->addAttribute("draw:text-style-name", "P1"); - pDrawPathElement->addAttribute("draw:layer", "layout"); - sValue = doubleToString(px[boundingBoxIndex]); sValue.append("in"); - pDrawPathElement->addAttribute("svg:x", sValue); - sValue = doubleToString(py[boundingBoxIndex]); sValue.append("in"); - pDrawPathElement->addAttribute("svg:y", sValue); - sValue = doubleToString((qx[boundingBoxIndex] - px[boundingBoxIndex])); sValue.append("in"); - pDrawPathElement->addAttribute("svg:width", sValue); - sValue = doubleToString((qy[boundingBoxIndex] - py[boundingBoxIndex])); sValue.append("in"); - pDrawPathElement->addAttribute("svg:height", sValue); - sValue.sprintf("%i %i %i %i", 0, 0, (unsigned)(2540*(qx[boundingBoxIndex] - px[boundingBoxIndex])), (unsigned)(2540*(qy[boundingBoxIndex] - py[boundingBoxIndex]))); - pDrawPathElement->addAttribute("svg:viewBox", sValue); - sValue.clear(); - } - // 2540 is 2.54*1000, 2.54 in = 1 inch - sElement.sprintf("M%i %i", (unsigned)((path[i]["svg:x"]->getDouble()-px[boundingBoxIndex])*2540), - (unsigned)((path[i]["svg:y"]->getDouble()-py[boundingBoxIndex])*2540)); + sElement.sprintf("M%i %i", (unsigned)((path[i]["svg:x"]->getDouble()-px)*2540), + (unsigned)((path[i]["svg:y"]->getDouble()-py)*2540)); sValue.append(sElement); } else if (path[i]["libwpg:path-action"]->getStr() == "L") { - sElement.sprintf("L%i %i", (unsigned)((path[i]["svg:x"]->getDouble()-px[boundingBoxIndex])*2540), - (unsigned)((path[i]["svg:y"]->getDouble()-py[boundingBoxIndex])*2540)); + sElement.sprintf("L%i %i", (unsigned)((path[i]["svg:x"]->getDouble()-px)*2540), + (unsigned)((path[i]["svg:y"]->getDouble()-py)*2540)); sValue.append(sElement); } else if (path[i]["libwpg:path-action"]->getStr() == "C") { - sElement.sprintf("C%i %i %i %i %i %i", (unsigned)((path[i]["svg:x1"]->getDouble()-px[boundingBoxIndex])*2540), - (int)((path[i]["svg:y1"]->getDouble()-py[boundingBoxIndex])*2540), (unsigned)((path[i]["svg:x2"]->getDouble()-px[boundingBoxIndex])*2540), - (int)((path[i]["svg:y2"]->getDouble()-py[boundingBoxIndex])*2540), (unsigned)((path[i]["svg:x"]->getDouble()-px[boundingBoxIndex])*2540), - (unsigned)((path[i]["svg:y"]->getDouble()-py[boundingBoxIndex])*2540)); + sElement.sprintf("C%i %i %i %i %i %i", (unsigned)((path[i]["svg:x1"]->getDouble()-px)*2540), + (unsigned)((path[i]["svg:y1"]->getDouble()-py)*2540), (unsigned)((path[i]["svg:x2"]->getDouble()-px)*2540), + (unsigned)((path[i]["svg:y2"]->getDouble()-py)*2540), (unsigned)((path[i]["svg:x"]->getDouble()-px)*2540), + (unsigned)((path[i]["svg:y"]->getDouble()-py)*2540)); sValue.append(sElement); } else if (path[i]["libwpg:path-action"]->getStr() == "A") { sElement.sprintf("A%i %i %i %i %i %i %i", (unsigned)((path[i]["svg:rx"]->getDouble())*2540), - (int)((path[i]["svg:ry"]->getDouble())*2540), (path[i]["libwpg:rotate"] ? path[i]["libwpg:rotate"]->getInt() : 0), + (unsigned)((path[i]["svg:ry"]->getDouble())*2540), (path[i]["libwpg:rotate"] ? path[i]["libwpg:rotate"]->getInt() : 0), (path[i]["libwpg:large-arc"] ? path[i]["libwpg:large-arc"]->getInt() : 1), (path[i]["libwpg:sweep"] ? path[i]["libwpg:sweep"]->getInt() : 1), - (unsigned)((path[i]["svg:x"]->getDouble()-px[boundingBoxIndex])*2540), (unsigned)((path[i]["svg:y"]->getDouble()-py[boundingBoxIndex])*2540)); + (unsigned)((path[i]["svg:x"]->getDouble()-px)*2540), (unsigned)((path[i]["svg:y"]->getDouble()-py)*2540)); sValue.append(sElement); } else if (path[i]["libwpg:path-action"]->getStr() == "Z") sValue.append(" Z"); - isFirstPoint = false; } pDrawPathElement->addAttribute("svg:d", sValue); mBodyElements.push_back(pDrawPathElement); mBodyElements.push_back(new TagCloseElement("draw:path")); - } void OdgGenerator::drawPath(const WPXPropertyListVector& path) @@ -1086,6 +1047,9 @@ void OdgGeneratorPrivate::_writeGraphicsStyle() if(mxStyle["draw:fill"] && mxStyle["draw:fill"]->getStr() == "none") pStyleGraphicsPropertiesElement->addAttribute("draw:fill", "none"); + else + if (mxStyle["svg:fill-rule"]) + pStyleGraphicsPropertiesElement->addAttribute("svg:fill-rule", mxStyle["svg:fill-rule"]->getStr()); if(mxStyle["draw:fill"] && mxStyle["draw:fill"]->getStr() == "solid") { |