From a661f9a2e0a05de1705a8e9d930c148a1416be29 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Fri, 1 Mar 2024 16:42:27 +0100 Subject: [PATCH] tdf#159968: Support overflow:visible in marker element Change-Id: I4ea648cf94a4bb321a78843a9898769a69c5630d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164224 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- svgio/inc/svgstyleattributes.hxx | 12 ++++++ svgio/inc/svgtoken.hxx | 1 + svgio/qa/cppunit/SvgImportTest.cxx | 17 +++++++++ svgio/qa/cppunit/data/tdf159968.svg | 37 ++++++++++++++++++ svgio/source/svgreader/svgstyleattributes.cxx | 38 ++++++++++++++++++- svgio/source/svgreader/svgtoken.cxx | 1 + 6 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 svgio/qa/cppunit/data/tdf159968.svg diff --git a/svgio/inc/svgstyleattributes.hxx b/svgio/inc/svgstyleattributes.hxx index 4516773e83a6..bf921f8b1bb0 100644 --- a/svgio/inc/svgstyleattributes.hxx +++ b/svgio/inc/svgstyleattributes.hxx @@ -170,6 +170,13 @@ namespace svgio::svgreader Central }; + enum class Overflow + { + notset, + hidden, + visible + }; + enum class Visibility { notset, @@ -207,6 +214,7 @@ namespace svgio::svgreader TextAnchor maTextAnchor; SvgPaint maColor; SvgNumber maOpacity; + Overflow maOverflow; Visibility maVisibility; OUString maTitle; OUString maDesc; @@ -410,6 +418,10 @@ namespace svgio::svgreader SvgNumber getOpacity() const; void setOpacity(const SvgNumber& rOpacity) { maOpacity = rOpacity; } + /// Overflow + Overflow getOverflow() const; + void setOverflow(const Overflow aOverflow) { maOverflow = aOverflow; } + /// Visibility Visibility getVisibility() const; void setVisibility(const Visibility aVisibility) { maVisibility = aVisibility; } diff --git a/svgio/inc/svgtoken.hxx b/svgio/inc/svgtoken.hxx index 8ad390f0b4a5..613b75049335 100644 --- a/svgio/inc/svgtoken.hxx +++ b/svgio/inc/svgtoken.hxx @@ -113,6 +113,7 @@ namespace svgio::svgreader Visibility, Title, Desc, + Overflow, // AspectRatio and params PreserveAspectRatio, diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index 99541f0b63b7..708ab7dcc970 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -2013,6 +2013,23 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156271) assertXPath(pDocument, "/primitive2D/transform/mask/textsimpleportion[4]"_ostr, "dx1"_ostr, "23"); } +CPPUNIT_TEST_FIXTURE(Test, testTdf159968) +{ + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf159968.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast(aSequence.getLength())); + + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence)); + + CPPUNIT_ASSERT (pDocument); + + // Check no mask is applied to the marker + assertXPath(pDocument, + "/primitive2D/transform/transform/transform/transform/polypolygoncolor"_ostr, "color"_ostr, "#000000"); + assertXPath(pDocument, + "/primitive2D/transform/transform/transform/transform/polypolygoncolor/polypolygon/polygon/point"_ostr, 5); +} + CPPUNIT_TEST_FIXTURE(Test, testTdf149880) { Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf149880.svg"); diff --git a/svgio/qa/cppunit/data/tdf159968.svg b/svgio/qa/cppunit/data/tdf159968.svg new file mode 100644 index 000000000000..8c13f0864901 --- /dev/null +++ b/svgio/qa/cppunit/data/tdf159968.svg @@ -0,0 +1,37 @@ + + + + + + + + + + + + diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index e2088be449b3..cdebccbd2526 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -850,7 +850,8 @@ namespace svgio::svgreader const basegfx::B2DRange aTargetRange(0.0, 0.0, fTargetWidth, fTargetHeight); const SvgAspectRatio& rRatio = rMarker.getSvgAspectRatio(); - if(rRatio.isSet()) + + if(rRatio.isSet() && Overflow::visible != rMarker.getSvgStyleAttributes()->getOverflow()) { // let mapping be created from SvgAspectRatio rMarkerTransform = rRatio.createMapping(aTargetRange, aPrimitiveRange); @@ -1279,6 +1280,7 @@ namespace svgio::svgreader maTextAlign(TextAlign::notset), maTextDecoration(TextDecoration::notset), maTextAnchor(TextAnchor::notset), + maOverflow(Overflow::notset), maVisibility(Visibility::notset), maFillRule(FillRule::notset), maClipRule(FillRule::notset), @@ -1822,6 +1824,21 @@ namespace svgio::svgreader } break; } + case SVGToken::Overflow: + { + if(!aContent.isEmpty()) + { + if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"visible")) + { + setOverflow(Overflow::visible); + } + else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"hidden")) + { + setOverflow(Overflow::hidden); + } + } + break; + } case SVGToken::Visibility: { if(!aContent.isEmpty()) @@ -2316,6 +2333,25 @@ namespace svgio::svgreader return SvgNumber(1.0); } + Overflow SvgStyleAttributes::getOverflow() const + { + if(Overflow::notset != maOverflow) + { + return maOverflow; + } + + if(mrOwner.hasLocalCssStyle()) + { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + if (pSvgStyleAttributes) + { + return pSvgStyleAttributes->getOverflow(); + } + } + + return Overflow::hidden; + } + Visibility SvgStyleAttributes::getVisibility() const { if(Visibility::notset == maVisibility || Visibility::inherit == maVisibility) diff --git a/svgio/source/svgreader/svgtoken.cxx b/svgio/source/svgreader/svgtoken.cxx index 14c27a396631..2edcd528793e 100644 --- a/svgio/source/svgreader/svgtoken.cxx +++ b/svgio/source/svgreader/svgtoken.cxx @@ -111,6 +111,7 @@ constexpr auto aSVGTokenMap = frozen::make_unordered_map