summaryrefslogtreecommitdiff
path: root/svgio/source
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/source
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/source')
-rw-r--r--svgio/source/svgreader/svgfecolormatrixnode.cxx13
-rw-r--r--svgio/source/svgreader/svgtools.cxx34
2 files changed, 47 insertions, 0 deletions
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;