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>
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index ba267f5..c9ec752 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 0000000..c354e441
--- /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 aca500a..f49e737 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());
                    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)));

                    if(fOpacity > 0.0 && Display::None != getDisplay())
                    aSource = drawinglayer::primitive2d::Primitive2DContainer { xRef };

                    if(!aSource.empty())
                    {
                        drawinglayer::primitive2d::Primitive2DContainer aContent;

                        // decompose children
                        SvgNode::decomposeSvgNode(aContent, bReferenced);

                        if(!aContent.empty())
                        {
                            pStyle->add_postProcess(rTarget, std::move(aContent), getTransform());
                        }
                        // append to current target
                        rTarget.append(aSource);
                    }
                }
            }