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 8c5f93ee35f0d9ecaa01e3243ae6bfa1bc148df9
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Jul 11 14:22:58 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jul 11 17:09:43 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/+/170376
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Tested-by: Jenkins

diff --git a/svgio/qa/cppunit/SvgImportTest.cxx 
b/svgio/qa/cppunit/SvgImportTest.cxx
index 280cffc5c8a5..0f2478860d9b 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -447,6 +447,19 @@ CPPUNIT_TEST_FIXTURE(Test, testFontsizeRelative)
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"familyname"_ostr, u"DejaVu Serif"_ustr);
 }
 
+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 e1822b52088f..22cd585eef73 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -1181,7 +1181,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))
             {
@@ -1303,7 +1320,7 @@ namespace svgio::svgreader
             maBaselineShift(BaselineShift::Baseline),
             maBaselineShiftNumber(0),
             maDominantBaseline(DominantBaseline::Auto),
-            maResolvingParent(34, 0),
+            maResolvingParent(35, 0),
             mbStrokeDasharraySet(false),
             mbContextFill(false),
             mbContextStroke(false),
@@ -2411,16 +2428,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