diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-06-14 12:39:06 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-06-14 21:08:17 +0200 |
commit | 41bf4139cab36984cff514bfdd6b1b13576746a3 (patch) | |
tree | f976deb977ad2b7bc372b1193fde8984a3842bd8 /svgio | |
parent | b6474249caa697513affdbcb02c7a69fda8203be (diff) |
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 <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio')
-rw-r--r-- | svgio/inc/svgfecolormatrixnode.hxx | 6 | ||||
-rw-r--r-- | svgio/inc/svgtoken.hxx | 1 | ||||
-rw-r--r-- | svgio/qa/cppunit/SvgImportTest.cxx | 21 | ||||
-rw-r--r-- | svgio/qa/cppunit/data/filterSaturate.svg | 11 | ||||
-rw-r--r-- | svgio/source/svgreader/svgfecolormatrixnode.cxx | 29 | ||||
-rw-r--r-- | svgio/source/svgreader/svgtoken.cxx | 2 |
6 files changed, 61 insertions, 9 deletions
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<int>(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<int>(aSequenceTdf132246.getLength())); + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/filterLuminanceToAlpha.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(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 @@ +<svg + width="230" + height="120" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink"> + <filter id="saturate"> + <feColorMatrix type="saturate" values="0.5"/> + </filter> + <circle cx="170" cy="60" r="50" fill="green" filter="url(#saturate)" /> +</svg> + 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<basegfx::BColorModifier_luminance_to_alpha>())); 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<basegfx::BColorModifier_saturate>(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 }, |