diff options
author | Xisco Fauli <anistenis@gmail.com> | 2016-03-26 16:23:23 +0100 |
---|---|---|
committer | Xisco Faulí <anistenis@gmail.com> | 2016-03-26 16:20:47 +0000 |
commit | c2d130425cc876cceb96cc7e47636426a9e48fa8 (patch) | |
tree | d5de2a66b56872410c23c539b3720f919e8c9b4d | |
parent | ae5bf728937a9233a5090adca94c2ffc106ea8b6 (diff) |
SVGIO: Shapes within a clippath element might inherit...
... fill, stroke, stroke-width and others attributes from
parent element, like use element
Change-Id: I911bc50409428e81135b81e6dfc82acd1c21d113
Reviewed-on: https://gerrit.libreoffice.org/23527
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Xisco Faulí <anistenis@gmail.com>
-rw-r--r-- | svgio/qa/cppunit/SvgImportTest.cxx | 20 | ||||
-rw-r--r-- | svgio/qa/cppunit/data/ClipPathAndParentStyle.svg | 10 | ||||
-rw-r--r-- | svgio/source/svgreader/svgstyleattributes.cxx | 62 |
3 files changed, 92 insertions, 0 deletions
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index feea8179f4d9..c4b681bd242d 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -53,6 +53,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools void testRGBColor(); void testRGBAColor(); void testTdf97936(); + void testClipPathAndParentStyle(); Primitive2DSequence parseSvg(const char* aSource); @@ -76,6 +77,7 @@ public: CPPUNIT_TEST(testRGBColor); CPPUNIT_TEST(testRGBAColor); CPPUNIT_TEST(testTdf97936); + CPPUNIT_TEST(testClipPathAndParentStyle); CPPUNIT_TEST_SUITE_END(); }; @@ -403,6 +405,24 @@ void Test::testTdf97936() assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "maxx", "60"); assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "maxy", "100"); } + +void Test::testClipPathAndParentStyle() +{ + //Check that fill color, stroke color and stroke-width are inherited from use element + //when the element is within a clipPath element + Primitive2DSequence aSequenceClipPathAndParentStyle = parseSvg("/svgio/qa/cppunit/data/ClipPathAndParentStyle.svg"); + CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceClipPathAndParentStyle.getLength()); + + Primitive2dXmlDump dumper; + xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceClipPathAndParentStyle)); + + CPPUNIT_ASSERT (pDocument); + + assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#ff0000"); + assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "color", "#000000"); + assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "width", "5"); + +} CPPUNIT_TEST_SUITE_REGISTRATION(Test); } diff --git a/svgio/qa/cppunit/data/ClipPathAndParentStyle.svg b/svgio/qa/cppunit/data/ClipPathAndParentStyle.svg new file mode 100644 index 000000000000..d85a95995c0a --- /dev/null +++ b/svgio/qa/cppunit/data/ClipPathAndParentStyle.svg @@ -0,0 +1,10 @@ +<svg version="1.1" baseProfile="basic" id="svg-root" + width="100%" height="100%" viewBox="0 0 480 360" + xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> + <clipPath> + <circle id="c1" cx="100" cy="100" r="50"/> + </clipPath> + + <use xlink:href="#c1" style="fill:red" stroke-width="5px" stroke="black"/> + +</svg> diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index b60d84b4077b..6b768f000408 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -1956,6 +1956,13 @@ namespace svgio { if(mbIsClipPathContent) { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if(pSvgStyleAttributes) + { + return pSvgStyleAttributes->getFill(); + } + static basegfx::BColor aBlack(0.0, 0.0, 0.0); return &aBlack; } @@ -1999,6 +2006,13 @@ namespace svgio { if(mbIsClipPathContent) { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if(pSvgStyleAttributes) + { + return pSvgStyleAttributes->getStroke(); + } + return nullptr; } else if(maStroke.isSet()) @@ -2041,6 +2055,13 @@ namespace svgio { if(mbIsClipPathContent) { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if(pSvgStyleAttributes) + { + return pSvgStyleAttributes->getSvgGradientNodeFill(); + } + return nullptr; } else if(mpSvgGradientNodeFill) @@ -2064,6 +2085,13 @@ namespace svgio { if(mbIsClipPathContent) { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if(pSvgStyleAttributes) + { + return pSvgStyleAttributes->getSvgGradientNodeStroke(); + } + return nullptr; } else if(mpSvgGradientNodeStroke) @@ -2087,6 +2115,13 @@ namespace svgio { if(mbIsClipPathContent) { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if(pSvgStyleAttributes) + { + return pSvgStyleAttributes->getSvgPatternNodeFill(); + } + return nullptr; } else if(mpSvgPatternNodeFill) @@ -2110,6 +2145,13 @@ namespace svgio { if(mbIsClipPathContent) { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if(pSvgStyleAttributes) + { + return pSvgStyleAttributes->getSvgPatternNodeStroke(); + } + return nullptr; } else if(mpSvgPatternNodeStroke) @@ -2133,6 +2175,13 @@ namespace svgio { if(mbIsClipPathContent) { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if(pSvgStyleAttributes) + { + return pSvgStyleAttributes->getStrokeWidth(); + } + return SvgNumber(0.0); } else if(maStrokeWidth.isSet()) @@ -2166,6 +2215,13 @@ namespace svgio { if(mbIsClipPathContent) { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if(pSvgStyleAttributes) + { + return pSvgStyleAttributes->getFillOpacity(); + } + return SvgNumber(1.0); } else if(maFillOpacity.isSet()) @@ -2188,6 +2244,12 @@ namespace svgio { if(mbIsClipPathContent) { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if(pSvgStyleAttributes) + { + return pSvgStyleAttributes->getOpacity(); + } return SvgNumber(1.0); } else if(maOpacity.isSet()) |