svgio/inc/svgnode.hxx                         |    3 +
 svgio/qa/cppunit/SvgImportTest.cxx            |   46 ++++++++++++++++----------
 svgio/qa/cppunit/data/tdf155814.svg           |   25 ++++++++++++++
 svgio/source/svgreader/svgstyleattributes.cxx |   42 +++++++++++++++--------
 svgio/source/svgreader/svgusenode.cxx         |   18 ++++------
 5 files changed, 93 insertions(+), 41 deletions(-)

New commits:
commit b0c2e580a1c5b055295d303ebb9c9e905ab4890c
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Jun 20 18:15:08 2023 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jun 20 20:52: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 <xiscofa...@libreoffice.org>

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 d9a0bf3cef86..189a1879799a 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -2866,7 +2866,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();
 
@@ -2904,14 +2906,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();
@@ -2939,14 +2946,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);
+                }
             }
         }
 

Reply via email to