svgio/qa/cppunit/SvgImportTest.cxx            |   13 +++++++++
 svgio/qa/cppunit/data/tdf161985.svg           |   14 +++++++++
 svgio/source/svgreader/svgstyleattributes.cxx |   37 ++++++++++++++++++--------
 3 files changed, 53 insertions(+), 11 deletions(-)

New commits:
commit d023ef070990e242df62d6c1951cc953fd60e7db
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Jul 11 14:22:58 2024 +0200
Commit:     Aron Budea <aron.bu...@collabora.com>
CommitDate: Fri Jul 12 16:51:33 2024 +0200

    tdf#161985: getOpacity is also called from other places
    
    Partially revert 56039daae4a436d7ea1b093a02cf0e8ad3bda4a9
    "tdf#149673: only check opacity from parent..." to make
    getOpacity behave as before and move the new behaviour
    of getOpacity inside add_postProcess
    
    Change-Id: If475cddbc4967308fa06adacda621cb3790c6f70
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170351
    Reviewed-by: Aron Budea <aron.bu...@collabora.com>
    Tested-by: Jenkins

diff --git a/svgio/qa/cppunit/SvgImportTest.cxx 
b/svgio/qa/cppunit/SvgImportTest.cxx
index f3d8013bee9e..75742d182f08 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -406,6 +406,19 @@ CPPUNIT_TEST_FIXTURE(Test, testFontsizeRelative)
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"familyname"_ostr, "DejaVu Serif");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf161985)
+{
+    xmlDocUniquePtr pDocument = 
dumpAndParseSvg(u"/svgio/qa/cppunit/data/tdf161985.svg");
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 0
+    // - Actual  : 1
+    assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor"_ostr, 0);
+
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion"_ostr, 1);
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion"_ostr, 
"text"_ostr, u"This is a test file."_ustr);
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf160386)
 {
     xmlDocUniquePtr pDocument = 
dumpAndParseSvg(u"/svgio/qa/cppunit/data/tdf160386.svg");
diff --git a/svgio/qa/cppunit/data/tdf161985.svg 
b/svgio/qa/cppunit/data/tdf161985.svg
new file mode 100644
index 000000000000..781811b15dbf
--- /dev/null
+++ b/svgio/qa/cppunit/data/tdf161985.svg
@@ -0,0 +1,14 @@
+<svg viewBox="0 0 630 550" xmlns="http://www.w3.org/2000/svg";>
+  <style type="text/css">
+     #help { font-size:12px; }
+  </style>
+  <g>
+    <g id="help" opacity="0">
+      <path
+         d="M16 50 c-16 0 -16 -8 -16 -16 v-18 c0 -16 8 -16 16 -16 h300 c16 0 
16 5 16 16 v18 c0 16 -8 16 -16 16 H60 L0 70 L36 50 H16"/>
+    </g>
+    <text>
+        <tspan x="101.0625" y="222.22849">This is a test file.</tspan>
+    </text>
+  </g>
+</svg>
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx 
b/svgio/source/svgreader/svgstyleattributes.cxx
index bb15fbfdc0a3..6c36c306ce24 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -1175,7 +1175,24 @@ namespace svgio::svgreader
             drawinglayer::primitive2d::Primitive2DContainer&& rSource,
             const std::optional<basegfx::B2DHomMatrix>& pTransform) const
         {
-            const double fOpacity(getOpacity().solve(mrOwner));
+            // default is 1
+            double fOpacity(1.0);
+
+            if(maOpacity.isSet())
+            {
+                fOpacity = maOpacity.solve(mrOwner);
+            }
+            else
+            {
+                // if opacity is not set, check the css style
+                if (const SvgStyleAttributes* pSvgStyleAttributes = 
getCssStyleParent())
+                {
+                    if (pSvgStyleAttributes->maOpacity.isSet())
+                    {
+                        fOpacity =  
pSvgStyleAttributes->maOpacity.solve(mrOwner);
+                    }
+                }
+            }
 
             if(basegfx::fTools::equalZero(fOpacity))
             {
@@ -1297,7 +1314,7 @@ namespace svgio::svgreader
             maBaselineShift(BaselineShift::Baseline),
             maBaselineShiftNumber(0),
             maDominantBaseline(DominantBaseline::Auto),
-            maResolvingParent(34, 0),
+            maResolvingParent(35, 0),
             mbStrokeDasharraySet(false),
             mbContextFill(false),
             mbContextStroke(false),
@@ -2405,16 +2422,14 @@ namespace svgio::svgreader
                 return maOpacity;
             }
 
-            // 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();
+            const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-                if (pSvgStyleAttributes && 
pSvgStyleAttributes->maOpacity.isSet())
-                {
-                    return pSvgStyleAttributes->maOpacity;
-                }
+            if (pSvgStyleAttributes && maResolvingParent[34] < 
nStyleDepthLimit)
+            {
+                ++maResolvingParent[34];
+                auto ret = pSvgStyleAttributes->getOpacity();
+                --maResolvingParent[34];
+                return ret;
             }
 
             // default is 1

Reply via email to