summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-06-19 13:18:42 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-06-19 15:32:49 +0200
commitd47b37eea9779e3c354e6c19a7211a306965b7ef (patch)
tree9dea50e5dd37d49352027f2363052057684f6308 /svgio
parent99d01ff26fe69ccc66f49b3ddd43b258c3687f2c (diff)
tdf#97717: do not call add_postProcess from g element
Otherwise, it will be called twice, from g and from its children Change-Id: I88535a7caab6a7711f917b3f383cd79b3b9fbd2d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153260 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx19
-rw-r--r--svgio/qa/cppunit/data/tdf97717.svg11
-rw-r--r--svgio/source/svgreader/svggnode.cxx38
3 files changed, 47 insertions, 21 deletions
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index ba267f5443a5..c9ec752d882a 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -302,6 +302,25 @@ CPPUNIT_TEST_FIXTURE(Test, testFontsizeRelative)
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "familyname", "serif");
}
+CPPUNIT_TEST_FIXTURE(Test, testTdf97717)
+{
+ //Check when font-size uses relative units (em,ex) and it's based on its parent's font-size
+ Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf97717.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/unifiedtransparence[1]", "transparence", "50");
+ // Without the fix in place, this test would have failed here since the patch
+ // would have contained two unifiedtransparence
+ assertXPath(pDocument, "/primitive2D/transform/unifiedtransparence[1]/polypolygoncolor", "color", "#ccccff");
+ assertXPath(pDocument, "/primitive2D/transform/unifiedtransparence[2]", "transparence", "50");
+ assertXPath(pDocument, "/primitive2D/transform/unifiedtransparence[2]/polypolygoncolor", "color", "#ccccff");
+}
+
CPPUNIT_TEST_FIXTURE(Test, testMarkerOrient)
{
Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/MarkerOrient.svg");
diff --git a/svgio/qa/cppunit/data/tdf97717.svg b/svgio/qa/cppunit/data/tdf97717.svg
new file mode 100644
index 000000000000..c354e4416827
--- /dev/null
+++ b/svgio/qa/cppunit/data/tdf97717.svg
@@ -0,0 +1,11 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-0 0 300 300">
+
+ <g opacity="0.5">
+ <rect x="0" y="0" height="50" width="50"
+ style="fill: #ccccff">
+ </rect>
+ </g>
+ <rect x="60" y="0" height="50" width="50"
+ style="fill: #ccccff" opacity="0.5">
+ </rect>
+</svg>
diff --git a/svgio/source/svgreader/svggnode.cxx b/svgio/source/svgreader/svggnode.cxx
index aca500af60ab..f49e737daafa 100644
--- a/svgio/source/svgreader/svggnode.cxx
+++ b/svgio/source/svgreader/svggnode.cxx
@@ -19,6 +19,7 @@
#include <svggnode.hxx>
#include <osl/diagnose.h>
+#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
namespace svgio::svgreader
{
@@ -85,31 +86,26 @@ namespace svgio::svgreader
void SvgGNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const
{
- if(SVGToken::Defs == getType())
- {
- // #i125258# no decompose needed for defs element, call parent for SVGTokenDefs
- SvgNode::decomposeSvgNode(rTarget, bReferenced);
- }
- else
- {
- // #i125258# for SVGTokenG decompose children
- const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
+ SvgNode::decomposeSvgNode(rTarget, bReferenced);
- if(pStyle)
+ // if g element has transform, apply it
+ if(SVGToken::G == getType())
+ {
+ if(getTransform())
{
- const double fOpacity(pStyle->getOpacity().getNumber());
-
- if(fOpacity > 0.0 && Display::None != getDisplay())
- {
- drawinglayer::primitive2d::Primitive2DContainer aContent;
+ drawinglayer::primitive2d::Primitive2DContainer aSource(std::move(rTarget));
+ // create embedding group element with transformation
+ const drawinglayer::primitive2d::Primitive2DReference xRef(
+ new drawinglayer::primitive2d::TransformPrimitive2D(
+ *getTransform(),
+ std::move(aSource)));
- // decompose children
- SvgNode::decomposeSvgNode(aContent, bReferenced);
+ aSource = drawinglayer::primitive2d::Primitive2DContainer { xRef };
- if(!aContent.empty())
- {
- pStyle->add_postProcess(rTarget, std::move(aContent), getTransform());
- }
+ if(!aSource.empty())
+ {
+ // append to current target
+ rTarget.append(aSource);
}
}
}