From 41bf4139cab36984cff514bfdd6b1b13576746a3 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Wed, 14 Jun 2023 12:39:06 +0200 Subject: tdf#155735: Add support for saturate type Add getModifierName to BColorModifier class so when can assert which modifier is being used Change-Id: I2bc2a36470a449df4dc84a8440f232149c1f8278 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153048 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- svgio/inc/svgfecolormatrixnode.hxx | 6 +++-- svgio/inc/svgtoken.hxx | 1 + svgio/qa/cppunit/SvgImportTest.cxx | 21 ++++++++++++++---- svgio/qa/cppunit/data/filterSaturate.svg | 11 ++++++++++ svgio/source/svgreader/svgfecolormatrixnode.cxx | 29 ++++++++++++++++++++++--- svgio/source/svgreader/svgtoken.cxx | 2 ++ 6 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 svgio/qa/cppunit/data/filterSaturate.svg (limited to 'svgio') diff --git a/svgio/inc/svgfecolormatrixnode.hxx b/svgio/inc/svgfecolormatrixnode.hxx index 7436f737b04c..631da8877372 100644 --- a/svgio/inc/svgfecolormatrixnode.hxx +++ b/svgio/inc/svgfecolormatrixnode.hxx @@ -25,16 +25,18 @@ namespace svgio::svgreader { -enum class Type +enum class ColorType { None, + Saturate, LuminanceToAlpha }; class SvgFeColorMatrixNode final : public SvgNode { private: - Type maType; + ColorType maType; + SvgNumber maValues; public: SvgFeColorMatrixNode(SvgDocument& rDocument, SvgNode* pParent); diff --git a/svgio/inc/svgtoken.hxx b/svgio/inc/svgtoken.hxx index 18c1a092c238..a28be73df50a 100644 --- a/svgio/inc/svgtoken.hxx +++ b/svgio/inc/svgtoken.hxx @@ -122,6 +122,7 @@ namespace svgio::svgreader XMaxYMax, Meet, Slice, + Values, // structural elements Defs, diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index 559af49af695..bdfbfcccb911 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -153,17 +153,30 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf155819) assertXPath(pDocument, "/primitive2D/transform/transform", 4); } +CPPUNIT_TEST_FIXTURE(Test, testFilterSaturate) +{ + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/filterSaturate.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast(aSequence.getLength())); + + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(aSequence); + + CPPUNIT_ASSERT (pDocument); + + assertXPath(pDocument, "/primitive2D/transform/modifiedColor", "modifier", "saturate"); +} + CPPUNIT_TEST_FIXTURE(Test, testFilterLuminanceToAlpha) { - Primitive2DSequence aSequenceTdf132246 = parseSvg(u"/svgio/qa/cppunit/data/filterLuminanceToAlpha.svg"); - CPPUNIT_ASSERT_EQUAL(1, static_cast(aSequenceTdf132246.getLength())); + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/filterLuminanceToAlpha.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast(aSequence.getLength())); drawinglayer::Primitive2dXmlDump dumper; - xmlDocUniquePtr pDocument = dumper.dumpAndParse(aSequenceTdf132246); + xmlDocUniquePtr pDocument = dumper.dumpAndParse(aSequence); CPPUNIT_ASSERT (pDocument); - assertXPath(pDocument, "/primitive2D/transform/modifiedColor"); + assertXPath(pDocument, "/primitive2D/transform/modifiedColor", "modifier", "luminance_to_alpha"); } CPPUNIT_TEST_FIXTURE(Test, testFilterFeGaussianBlur) diff --git a/svgio/qa/cppunit/data/filterSaturate.svg b/svgio/qa/cppunit/data/filterSaturate.svg new file mode 100644 index 000000000000..3fc1ab89f538 --- /dev/null +++ b/svgio/qa/cppunit/data/filterSaturate.svg @@ -0,0 +1,11 @@ + + + + + + + diff --git a/svgio/source/svgreader/svgfecolormatrixnode.cxx b/svgio/source/svgreader/svgfecolormatrixnode.cxx index fb53f1d5c503..2a02ddc3c0bd 100644 --- a/svgio/source/svgreader/svgfecolormatrixnode.cxx +++ b/svgio/source/svgreader/svgfecolormatrixnode.cxx @@ -25,7 +25,8 @@ namespace svgio::svgreader { SvgFeColorMatrixNode::SvgFeColorMatrixNode(SvgDocument& rDocument, SvgNode* pParent) : SvgNode(SVGToken::FeColorMatrix, rDocument, pParent) - , maType(Type::None) + , maType(ColorType::None) + , maValues(1.0) { } @@ -43,8 +44,22 @@ void SvgFeColorMatrixNode::parseAttribute(const OUString& /*rTokenName*/, SVGTok { if (o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"luminanceToAlpha")) { - maType = Type::LuminanceToAlpha; + maType = ColorType::LuminanceToAlpha; } + else if (o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"saturate")) + { + maType = ColorType::Saturate; + } + } + break; + } + case SVGToken::Values: + { + SvgNumber aNum; + + if (readSingleNumber(aContent, aNum)) + { + maValues = aNum; } break; } @@ -57,7 +72,7 @@ void SvgFeColorMatrixNode::parseAttribute(const OUString& /*rTokenName*/, SVGTok void SvgFeColorMatrixNode::apply(drawinglayer::primitive2d::Primitive2DContainer& rTarget) const { - if (maType == Type::LuminanceToAlpha) + if (maType == ColorType::LuminanceToAlpha) { const drawinglayer::primitive2d::Primitive2DReference xRef( new drawinglayer::primitive2d::ModifiedColorPrimitive2D( @@ -65,6 +80,14 @@ void SvgFeColorMatrixNode::apply(drawinglayer::primitive2d::Primitive2DContainer std::make_shared())); rTarget = drawinglayer::primitive2d::Primitive2DContainer{ xRef }; } + else if (maType == ColorType::Saturate) + { + const drawinglayer::primitive2d::Primitive2DReference xRef( + new drawinglayer::primitive2d::ModifiedColorPrimitive2D( + std::move(rTarget), + std::make_shared(maValues.getNumber()))); + rTarget = drawinglayer::primitive2d::Primitive2DContainer{ xRef }; + } } } // end of namespace svgio::svgreader diff --git a/svgio/source/svgreader/svgtoken.cxx b/svgio/source/svgreader/svgtoken.cxx index 8228689606bf..09ed13459b2e 100644 --- a/svgio/source/svgreader/svgtoken.cxx +++ b/svgio/source/svgreader/svgtoken.cxx @@ -113,6 +113,7 @@ namespace svgio::svgreader const char aSVGStrXMaxYMax[] = "xMaxYMax"; const char aSVGStrMeet[] = "meet"; const char aSVGStrSlice[] = "slice"; + const char aSVGStrValues[] = "values"; const char aSVGStrDefs[] = "defs"; const char aSVGStrG[] = "g"; @@ -265,6 +266,7 @@ namespace svgio::svgreader { aSVGStrXMaxYMax, SVGToken::XMaxYMax }, { aSVGStrMeet, SVGToken::Meet }, { aSVGStrSlice, SVGToken::Slice }, + { aSVGStrValues, SVGToken::Values }, { aSVGStrDefs, SVGToken::Defs }, { aSVGStrG, SVGToken::G }, -- cgit