summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-06-16 11:50:57 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-06-22 17:19:27 +0200
commite121f7b37c48b6d843dfdd1d774d2a40567c46c7 (patch)
treef512af867d5653469713613df0b3b12a718ea40f /svgio
parentcdce0b615a0bd599cd90dfd145d8270287045619 (diff)
tdf#155735: Add support for matrix type
Change-Id: Icc172c5f47731ddcf0beca64c72c2022313e74a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153177 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/inc/svgfecolormatrixnode.hxx3
-rw-r--r--svgio/inc/svgtools.hxx2
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx8
-rw-r--r--svgio/source/svgreader/svgfecolormatrixnode.cxx13
-rw-r--r--svgio/source/svgreader/svgtools.cxx34
5 files changed, 55 insertions, 5 deletions
diff --git a/svgio/inc/svgfecolormatrixnode.hxx b/svgio/inc/svgfecolormatrixnode.hxx
index a63d44715457..78d8b027f653 100644
--- a/svgio/inc/svgfecolormatrixnode.hxx
+++ b/svgio/inc/svgfecolormatrixnode.hxx
@@ -21,7 +21,7 @@
#include "svgnode.hxx"
#include "svgstyleattributes.hxx"
-#include <basegfx/matrix/b2dhommatrix.hxx>
+#include <basegfx/matrix/b3dhommatrix.hxx>
namespace svgio::svgreader
{
@@ -29,6 +29,7 @@ enum class ColorType
{
None,
HueRotate,
+ Matrix,
Saturate,
LuminanceToAlpha
};
diff --git a/svgio/inc/svgtools.hxx b/svgio/inc/svgtools.hxx
index fd9bdd396d9d..1bca409001b6 100644
--- a/svgio/inc/svgtools.hxx
+++ b/svgio/inc/svgtools.hxx
@@ -20,6 +20,7 @@
#pragma once
#include <basegfx/color/bcolor.hxx>
+#include <basegfx/range/b3drange.hxx>
#include <basegfx/range/b2drange.hxx>
#include <basegfx/vector/b2ivector.hxx>
#include <rtl/ustrbuf.hxx>
@@ -109,6 +110,7 @@ namespace svgio::svgreader
bool match_colorKeyword(basegfx::BColor& rColor, const OUString& rName);
bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, SvgNumber& rOpacity);
basegfx::B2DRange readViewBox(std::u16string_view rCandidate, InfoProvider const & rInfoProvider);
+ basegfx::B3DHomMatrix readFilterMatrix(std::u16string_view rCandidate, InfoProvider const & rInfoProvider);
basegfx::B2DHomMatrix readTransform(std::u16string_view rCandidate, InfoProvider const & rInfoProvider);
bool readSingleNumber(std::u16string_view rCandidate, SvgNumber& aNum);
bool readLocalLink(std::u16string_view rCandidate, OUString& rURL);
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index 87beb7742405..df1337090ff3 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -163,10 +163,10 @@ CPPUNIT_TEST_FIXTURE(Test, testFeColorMatrix)
CPPUNIT_ASSERT (pDocument);
- //assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor", "modifier", "matrix");
- assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor[1]", "modifier", "saturate");
- assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor[2]", "modifier", "hueRotate");
- assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor[3]", "modifier", "luminance_to_alpha");
+ assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor[1]", "modifier", "matrix");
+ assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor[2]", "modifier", "saturate");
+ assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor[3]", "modifier", "hueRotate");
+ assertXPath(pDocument, "/primitive2D/transform/mask/modifiedColor[4]", "modifier", "luminance_to_alpha");
}
CPPUNIT_TEST_FIXTURE(Test, testFilterFeGaussianBlur)
diff --git a/svgio/source/svgreader/svgfecolormatrixnode.cxx b/svgio/source/svgreader/svgfecolormatrixnode.cxx
index 42611e48efdd..5f8e03c4318b 100644
--- a/svgio/source/svgreader/svgfecolormatrixnode.cxx
+++ b/svgio/source/svgreader/svgfecolormatrixnode.cxx
@@ -53,6 +53,10 @@ void SvgFeColorMatrixNode::parseAttribute(const OUString& /*rTokenName*/, SVGTok
{
maType = ColorType::HueRotate;
}
+ else if (o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"matrix"))
+ {
+ maType = ColorType::Matrix;
+ }
}
break;
}
@@ -99,6 +103,15 @@ void SvgFeColorMatrixNode::apply(drawinglayer::primitive2d::Primitive2DContainer
basegfx::deg2rad(aNum.getNumber()))));
rTarget = drawinglayer::primitive2d::Primitive2DContainer{ xRef };
}
+ else if (maType == ColorType::Matrix)
+ {
+ basegfx::B3DHomMatrix aMatrix = readFilterMatrix(maValuesContent, *this);
+
+ const drawinglayer::primitive2d::Primitive2DReference xRef(
+ new drawinglayer::primitive2d::ModifiedColorPrimitive2D(
+ std::move(rTarget), std::make_shared<basegfx::BColorModifier_matrix>(aMatrix)));
+ rTarget = drawinglayer::primitive2d::Primitive2DContainer{ xRef };
+ }
}
} // end of namespace svgio::svgreader
diff --git a/svgio/source/svgreader/svgtools.cxx b/svgio/source/svgreader/svgtools.cxx
index af10626af3ad..f885086497c1 100644
--- a/svgio/source/svgreader/svgtools.cxx
+++ b/svgio/source/svgreader/svgtools.cxx
@@ -24,6 +24,7 @@
#include <o3tl/string_view.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <basegfx/matrix/b3dhommatrix.hxx>
#include <svgtoken.hxx>
#include <unordered_map>
@@ -844,6 +845,39 @@ namespace svgio::svgreader
return basegfx::B2DRange();
}
+ basegfx::B3DHomMatrix readFilterMatrix(std::u16string_view rCandidate, InfoProvider const & rInfoProvider)
+ {
+ basegfx::B3DHomMatrix aMatrix;
+ const sal_Int32 nLen(rCandidate.size());
+
+ sal_Int32 nPos(0);
+ skip_char(rCandidate, ' ', ',', nPos, nLen);
+
+ SvgNumber aVal;
+
+ // create a 3x5 matrix using the first 15 values from the list of 20 matrix values.
+ // FIXME: support alpha (the last 5 values)
+ for (sal_uInt16 nRow = 0; nRow < 3; ++nRow)
+ {
+ for (sal_uInt16 nColumn = 0; nColumn < 5; ++nColumn)
+ {
+ // return earlier if there are not enough values
+ if (nPos >= nLen)
+ {
+ return basegfx::B3DHomMatrix();
+ }
+
+ if(readNumberAndUnit(rCandidate, nPos, aVal, nLen))
+ {
+ aMatrix.set(nRow, nColumn, aVal.solve(rInfoProvider));
+ skip_char(rCandidate, ' ', ',', nPos, nLen);
+ }
+ }
+ }
+
+ return aMatrix;
+ }
+
basegfx::B2DHomMatrix readTransform(std::u16string_view rCandidate, InfoProvider const & rInfoProvider)
{
basegfx::B2DHomMatrix aMatrix;