summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2024-07-11 14:22:58 +0200
committerAron Budea <aron.budea@collabora.com>2024-07-12 16:51:07 +0200
commitf568b2346c06a82768452fdfb0b3fe9597f8151a (patch)
treee1d20a83a0d0fe330d1b635323946b86f747da6c /svgio
parent66aaa3850f3a3141f19c398a2efc85fde7969092 (diff)
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/+/170350 Tested-by: Jenkins Reviewed-by: Aron Budea <aron.budea@collabora.com>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx13
-rw-r--r--svgio/qa/cppunit/data/tdf161985.svg14
-rw-r--r--svgio/source/svgreader/svgstyleattributes.cxx37
3 files changed, 53 insertions, 11 deletions
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 485142240871..5fe78f8b58d0 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