svgio/inc/svgnode.hxx | 3 + svgio/qa/cppunit/SvgImportTest.cxx | 60 ++++++++++++----------- svgio/qa/cppunit/data/filterFeColorMatrix.svg | 60 +++++++++++++++++++++++ svgio/qa/cppunit/data/filterLuminanceToAlpha.svg | 11 ---- svgio/qa/cppunit/data/filterSaturate.svg | 11 ---- svgio/qa/cppunit/data/tdf155814.svg | 25 +++++++++ svgio/source/svgreader/svgstyleattributes.cxx | 42 ++++++++++------ svgio/source/svgreader/svgusenode.cxx | 18 +++--- 8 files changed, 155 insertions(+), 75 deletions(-)
New commits: commit 05291e38d53e8be76b690586cff0cf4f067e918f Author: Xisco Fauli <[email protected]> AuthorDate: Tue Jun 20 18:15:08 2023 +0200 Commit: Xisco Fauli <[email protected]> CommitDate: Tue Jun 20 23:13:13 2023 +0200 tdf#155814: only check parent style when it has a local css style This also fixes the problem for filters and mask, since they are call from add_postProcess Adapt some tests to the new xml output. Visually nothing has changed Change-Id: I65d2491409019f4cd0b1113a9a7931fc602c57b5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153355 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]> Signed-off-by: Xisco Fauli <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153364 diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx index 4bdbd3046d75..f2eb0fcb1b6e 100644 --- a/svgio/inc/svgnode.hxx +++ b/svgio/inc/svgnode.hxx @@ -180,6 +180,9 @@ namespace svgio::svgreader /// alternative parent void setAlternativeParent(const SvgNode* pAlternativeParent = nullptr) { mpAlternativeParent = pAlternativeParent; } + + /// Check if there is a local css style + bool hasLocalCssStyle() { return static_cast<bool>(mpLocalCssStyle); } }; class Visitor diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index cb7fc790c375..87c99ba72509 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -163,10 +163,10 @@ CPPUNIT_TEST_FIXTURE(Test, testFeColorMatrix) CPPUNIT_ASSERT (pDocument); - //assertXPath(pDocument, "/primitive2D/transform/mask/transform[1]/modifiedColor", "modifier", "matrix"); - assertXPath(pDocument, "/primitive2D/transform/mask/transform[2]/modifiedColor", "modifier", "saturate"); - //assertXPath(pDocument, "/primitive2D/transform/mask/transform[3]/modifiedColor", "modifier", "hueRotate"); - assertXPath(pDocument, "/primitive2D/transform/mask/transform[4]/modifiedColor", "modifier", "luminance_to_alpha"); + //assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor", "modifier", "matrix"); + assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor[1]", "modifier", "saturate"); + //assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor", "modifier", "hueRotate"); + assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor[2]", "modifier", "luminance_to_alpha"); } CPPUNIT_TEST_FIXTURE(Test, testFilterFeGaussianBlur) @@ -717,10 +717,24 @@ CPPUNIT_TEST_FIXTURE(Test, testClipPathAndParentStyle) 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"); + assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor", "color", "#ff0000"); + assertXPath(pDocument, "/primitive2D/transform/transform/polypolygonstroke/line", "color", "#000000"); + assertXPath(pDocument, "/primitive2D/transform/transform/polypolygonstroke/line", "width", "5"); + +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf155814) +{ + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf155814.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength())); + + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence)); + CPPUNIT_ASSERT (pDocument); + + assertXPath(pDocument, "/primitive2D/transform/mask/mask/transform/unifiedtransparence", "transparence", "50"); + assertXPath(pDocument, "/primitive2D/transform/mask/mask/transform/unifiedtransparence/polypolygoncolor", "color", "#0000ff"); } CPPUNIT_TEST_FIXTURE(Test, testClipPathAndStyle) @@ -735,9 +749,9 @@ CPPUNIT_TEST_FIXTURE(Test, testClipPathAndStyle) CPPUNIT_ASSERT (pDocument); - assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#ccccff"); - assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "color", "#0000cc"); - assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "width", "2"); + assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor", "color", "#ccccff"); + assertXPath(pDocument, "/primitive2D/transform/transform/polypolygonstroke/line", "color", "#0000cc"); + assertXPath(pDocument, "/primitive2D/transform/transform/polypolygonstroke/line", "width", "2"); } @@ -915,10 +929,10 @@ CPPUNIT_TEST_FIXTURE(Test, testMaskText) CPPUNIT_ASSERT (pDocument); assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor", "color", "#000000"); - assertXPath(pDocument, "/primitive2D/transform/transform/textsimpleportion", "fontcolor", "#ffffff"); - assertXPath(pDocument, "/primitive2D/transform/transform/textsimpleportion", "text", "Black White"); - assertXPath(pDocument, "/primitive2D/transform/transform/textsimpleportion", "height", "26"); - assertXPath(pDocument, "/primitive2D/transform/transform/textsimpleportion", "familyname", "Times New Roman"); + assertXPath(pDocument, "/primitive2D/transform/transform/transform/textsimpleportion", "fontcolor", "#ffffff"); + assertXPath(pDocument, "/primitive2D/transform/transform/transform/textsimpleportion", "text", "Black White"); + assertXPath(pDocument, "/primitive2D/transform/transform/transform/textsimpleportion", "height", "26"); + assertXPath(pDocument, "/primitive2D/transform/transform/transform/textsimpleportion", "familyname", "Times New Roman"); } CPPUNIT_TEST_FIXTURE(Test, testTdf99994) @@ -1096,12 +1110,12 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf155733) CPPUNIT_ASSERT (pDocument); - assertXPath(pDocument, "/primitive2D/transform/transform[1]/softedge", "radius", "5"); + assertXPath(pDocument, "/primitive2D/transform/softedge", "radius", "5"); // Without the fix in place, the softedge would have been applied to the second element // - Expected: 1 // - Actual : 0 - assertXPath(pDocument, "/primitive2D/transform/transform[2]/unifiedtransparence", "transparence", "50"); + assertXPath(pDocument, "/primitive2D/transform/transform/unifiedtransparence", "transparence", "50"); } CPPUNIT_TEST_FIXTURE(Test, testTdf97663) diff --git a/svgio/qa/cppunit/data/tdf155814.svg b/svgio/qa/cppunit/data/tdf155814.svg new file mode 100644 index 000000000000..5ac2e8297379 --- /dev/null +++ b/svgio/qa/cppunit/data/tdf155814.svg @@ -0,0 +1,25 @@ +<svg + width="100%" + height="100%" + viewBox="0 0 150 500" + preserveAspectRatio="xMidYMid meet" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink"> + <!-- ref --> + <defs> + <g id="circles"> + <circle cx="30" cy="30" r="20" fill="blue" fill-opacity="0.5" /> + </g> + </defs> + <clipPath id="myClip"> + <!-- + Everything outside the circle will be + clipped and therefore invisible. + --> + <circle r="35" /> + </clipPath> + + <use xlink:href="#circles" transform="translate(0 50)" clip-path="url(#myClip)" /> + <use xlink:href="#circles" transform="translate(0 100)" /> +</svg> + diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index 092f84787dff..9e8c47d76f7e 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -2867,7 +2867,9 @@ namespace svgio::svgreader return maClipPathXLink; } - if(getCssStyleParent()) + // This is called from add_postProcess so only check the parent style + // if it has a local css style, because it's the first in the stack + if(mrOwner.hasLocalCssStyle()) { const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); @@ -2905,14 +2907,19 @@ namespace svgio::svgreader return maFilterXLink; } - const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); - - if (pSvgStyleAttributes && maResolvingParent[32] < nStyleDepthLimit) + // This is called from add_postProcess so only check the parent style + // if it has a local css style, because it's the first in the stack + if(mrOwner.hasLocalCssStyle()) { - ++maResolvingParent[32]; - auto ret = pSvgStyleAttributes->getFilterXLink(); - --maResolvingParent[32]; - return ret; + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if (pSvgStyleAttributes && maResolvingParent[32] < nStyleDepthLimit) + { + ++maResolvingParent[32]; + auto ret = pSvgStyleAttributes->getFilterXLink(); + --maResolvingParent[32]; + return ret; + } } return OUString(); @@ -2940,14 +2947,19 @@ namespace svgio::svgreader return maMaskXLink; } - const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); - - if (pSvgStyleAttributes && maResolvingParent[25] < nStyleDepthLimit) + // This is called from add_postProcess so only check the parent style + // if it has a local css style, because it's the first in the stack + if(mrOwner.hasLocalCssStyle()) { - ++maResolvingParent[25]; - auto ret = pSvgStyleAttributes->getMaskXLink(); - --maResolvingParent[25]; - return ret; + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if (pSvgStyleAttributes && maResolvingParent[25] < nStyleDepthLimit) + { + ++maResolvingParent[25]; + auto ret = pSvgStyleAttributes->getMaskXLink(); + --maResolvingParent[25]; + return ret; + } } return OUString(); diff --git a/svgio/source/svgreader/svgusenode.cxx b/svgio/source/svgreader/svgusenode.cxx index 66f9d1a551a0..185dc4f919a0 100644 --- a/svgio/source/svgreader/svgusenode.cxx +++ b/svgio/source/svgreader/svgusenode.cxx @@ -163,18 +163,16 @@ namespace svgio::svgreader aTransform = *getTransform() * aTransform; } - if(!aTransform.isIdentity()) - { - const drawinglayer::primitive2d::Primitive2DReference xRef( - new drawinglayer::primitive2d::TransformPrimitive2D( - aTransform, - std::move(aNewTarget))); + const SvgStyleAttributes* pStyle = getSvgStyleAttributes(); - rTarget.push_back(xRef); - } - else + if(pStyle) { - rTarget.append(aNewTarget); + const double fOpacity(pStyle->getOpacity().getNumber()); + + if(fOpacity > 0.0 && Display::None != getDisplay()) + { + pStyle->add_postProcess(rTarget, std::move(aNewTarget), aTransform, false); + } } } commit f2f4bf495aba09d53edf7028f79db46bf7c6f2dc Author: Xisco Fauli <[email protected]> AuthorDate: Fri Jun 16 15:57:14 2023 +0200 Commit: Xisco Fauli <[email protected]> CommitDate: Tue Jun 20 23:13:04 2023 +0200 tdf#155735: unify unittest Change-Id: I8de80f869715d4476e62f526e0bb161de8274977 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153181 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]> Signed-off-by: Xisco Fauli <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153363 diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index 018daa03578c..cb7fc790c375 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -153,9 +153,9 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf155819) assertXPath(pDocument, "/primitive2D/transform/transform", 4); } -CPPUNIT_TEST_FIXTURE(Test, testFilterSaturate) +CPPUNIT_TEST_FIXTURE(Test, testFeColorMatrix) { - Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/filterSaturate.svg"); + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/filterFeColorMatrix.svg"); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength())); drawinglayer::Primitive2dXmlDump dumper; @@ -163,20 +163,10 @@ CPPUNIT_TEST_FIXTURE(Test, testFilterSaturate) CPPUNIT_ASSERT (pDocument); - assertXPath(pDocument, "/primitive2D/transform/modifiedColor", "modifier", "saturate"); -} - -CPPUNIT_TEST_FIXTURE(Test, testFilterLuminanceToAlpha) -{ - Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/filterLuminanceToAlpha.svg"); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength())); - - drawinglayer::Primitive2dXmlDump dumper; - xmlDocUniquePtr pDocument = dumper.dumpAndParse(aSequence); - - CPPUNIT_ASSERT (pDocument); - - assertXPath(pDocument, "/primitive2D/transform/modifiedColor", "modifier", "luminance_to_alpha"); + //assertXPath(pDocument, "/primitive2D/transform/mask/transform[1]/modifiedColor", "modifier", "matrix"); + assertXPath(pDocument, "/primitive2D/transform/mask/transform[2]/modifiedColor", "modifier", "saturate"); + //assertXPath(pDocument, "/primitive2D/transform/mask/transform[3]/modifiedColor", "modifier", "hueRotate"); + assertXPath(pDocument, "/primitive2D/transform/mask/transform[4]/modifiedColor", "modifier", "luminance_to_alpha"); } CPPUNIT_TEST_FIXTURE(Test, testFilterFeGaussianBlur) diff --git a/svgio/qa/cppunit/data/filterFeColorMatrix.svg b/svgio/qa/cppunit/data/filterFeColorMatrix.svg new file mode 100644 index 000000000000..07d5559ed1b6 --- /dev/null +++ b/svgio/qa/cppunit/data/filterFeColorMatrix.svg @@ -0,0 +1,60 @@ +<svg + width="100%" + height="100%" + viewBox="0 0 150 500" + preserveAspectRatio="xMidYMid meet" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink"> + <!-- ref --> + <defs> + <g id="circles"> + <circle cx="30" cy="30" r="20" fill="blue" fill-opacity="0.5" /> + </g> + </defs> + <use href="#circles" /> + <text x="70" y="50">Reference</text> + + <!-- Combine RGB into green matrix --> + <filter id="colorMeGreen"> + <feColorMatrix + in="SourceGraphic" + type="matrix" + values="0 0 0 0 0 + 1 1 1 1 0 + 0 0 0 0 0 + 0 0 0 1 0" /> + </filter> + <use + href="#circles" + transform="translate(0 70)" + filter="url(#colorMeGreen)" /> + <text x="70" y="120">rgbToGreen</text> + + <!-- saturate --> + <filter id="colorMeSaturate"> + <feColorMatrix in="SourceGraphic" type="saturate" values="0.2" /> + </filter> + <use + href="#circles" + transform="translate(0 140)" + filter="url(#colorMeSaturate)" /> + <text x="70" y="190">saturate</text> + + <!-- hueRotate --> + <filter id="colorMeHueRotate"> + <feColorMatrix in="SourceGraphic" type="hueRotate" values="180" /> + </filter> + <use + href="#circles" + transform="translate(0 210)" + filter="url(#colorMeHueRotate)" /> + <text x="70" y="260">hueRotate</text> + + <!-- luminanceToAlpha --> + <filter id="colorMeLTA"> + <feColorMatrix in="SourceGraphic" type="luminanceToAlpha" /> + </filter> + <use href="#circles" transform="translate(0 280)" filter="url(#colorMeLTA)" /> + <text x="70" y="330">luminanceToAlpha</text> +</svg> + diff --git a/svgio/qa/cppunit/data/filterLuminanceToAlpha.svg b/svgio/qa/cppunit/data/filterLuminanceToAlpha.svg deleted file mode 100644 index 854fad125446..000000000000 --- a/svgio/qa/cppunit/data/filterLuminanceToAlpha.svg +++ /dev/null @@ -1,11 +0,0 @@ -<svg - width="230" - height="120" - xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink"> - <filter id="luminanceToAlpha"> - <feColorMatrix type="luminanceToAlpha"/> - </filter> - <circle cx="170" cy="60" r="50" fill="green" filter="url(#luminanceToAlpha)" /> -</svg> - diff --git a/svgio/qa/cppunit/data/filterSaturate.svg b/svgio/qa/cppunit/data/filterSaturate.svg deleted file mode 100644 index 3fc1ab89f538..000000000000 --- a/svgio/qa/cppunit/data/filterSaturate.svg +++ /dev/null @@ -1,11 +0,0 @@ -<svg - width="230" - height="120" - xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink"> - <filter id="saturate"> - <feColorMatrix type="saturate" values="0.5"/> - </filter> - <circle cx="170" cy="60" r="50" fill="green" filter="url(#saturate)" /> -</svg> -
