[Libreoffice-commits] core.git: svgio/qa svgio/source test/source

Xisco Fauli anistenis at gmail.com
Thu Feb 11 17:17:29 UTC 2016


 svgio/qa/cppunit/SvgImportTest.cxx            |   32 ++++++++++++++++++++++++++
 svgio/qa/cppunit/data/tdf97542_1.svg          |   15 ++++++++++++
 svgio/qa/cppunit/data/tdf97542_2.svg          |   15 ++++++++++++
 svgio/source/svgreader/svgstyleattributes.cxx |   15 +++++++-----
 test/source/primitive2dxmldump.cxx            |   28 +++++++++++++++++++++-
 5 files changed, 98 insertions(+), 7 deletions(-)

New commits:
commit b6a62f07557fe4ae0931e0f3e0f306d2f69b116b
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Fri Feb 5 00:25:58 2016 +0100

    tdf#97542: SVGIO: First check the current fill attribute
    
    Differenciate when gradient is defined in the text element or in its parents
    
    Add unit tests
    
    Change-Id: I85b09f72fbb1a3c8d2fa7350b4396b5bf924277f
    Reviewed-on: https://gerrit.libreoffice.org/22131
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Jochen Nitschke <j.nitschke+logerrit at ok.de>
    Reviewed-by: Xisco FaulĂ­ <anistenis at gmail.com>

diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index 50a7ef7..9214223 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -45,6 +45,8 @@ class Test : public test::BootstrapFixture, public XmlTestTools
     void testTdf45771();
     void testTdf85770();
     void testTdf79163();
+    void testTdf97542_1();
+    void testTdf97542_2();
 
     Primitive2DSequence parseSvg(const char* aSource);
 
@@ -60,6 +62,8 @@ public:
     CPPUNIT_TEST(testTdf45771);
     CPPUNIT_TEST(testTdf85770);
     CPPUNIT_TEST(testTdf79163);
+    CPPUNIT_TEST(testTdf97542_1);
+    CPPUNIT_TEST(testTdf97542_2);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -237,6 +241,34 @@ void Test::testTdf79163()
     assertXPath(pDocument, "/primitive2D/transform/mask/unifiedtransparence", "transparence", "0");
 }
 
+void Test::testTdf97542_1()
+{
+    Primitive2DSequence aSequenceTdf97542_1 = parseSvg("/svgio/qa/cppunit/data/tdf97542_1.svg");
+    CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf97542_1.getLength());
+
+    Primitive2dXmlDump dumper;
+    xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf97542_1));
+
+    CPPUNIT_ASSERT (pDocument);
+
+    assertXPath(pDocument, "/primitive2D/transform/objectinfo/textsimpleportion", "fontcolor", "#ffff00");
+}
+
+void Test::testTdf97542_2()
+{
+    Primitive2DSequence aSequenceTdf97542_2 = parseSvg("/svgio/qa/cppunit/data/tdf97542_2.svg");
+    CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf97542_2.getLength());
+
+    Primitive2dXmlDump dumper;
+    xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf97542_2));
+
+    CPPUNIT_ASSERT (pDocument);
+
+    assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "x", "1");
+    assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "y", "1");
+    assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "radius", "3");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 }
diff --git a/svgio/qa/cppunit/data/tdf97542_1.svg b/svgio/qa/cppunit/data/tdf97542_1.svg
new file mode 100644
index 0000000..328bd97
--- /dev/null
+++ b/svgio/qa/cppunit/data/tdf97542_1.svg
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<svg width="200" height="50" xmlns="http://www.w3.org/2000/svg">
+ <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
+ <defs>
+  <radialGradient id="svg_2" cx="0.5" cy="0.5" r="0.5">
+   <stop offset="0" stop-color="#ff0000"/>
+   <stop offset="1" stop-color="#000000"/>
+  </radialGradient>
+ </defs>
+ <g fill="url(#svg_2)" >
+  <title>Layer 1</title>
+  <rect id="svg_1" height="50" width="200" y="0" x="0"/>
+  <text x="50" y="40" id="svg_12" font-size="48" font-family="serif" fill="#ffff00">Text</text>
+ </g>
+</svg>
diff --git a/svgio/qa/cppunit/data/tdf97542_2.svg b/svgio/qa/cppunit/data/tdf97542_2.svg
new file mode 100644
index 0000000..03cee96
--- /dev/null
+++ b/svgio/qa/cppunit/data/tdf97542_2.svg
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<svg width="200" height="50" xmlns="http://www.w3.org/2000/svg">
+ <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
+ <defs>
+  <radialGradient id="svg_2" cx="1" cy="1" r="3">
+   <stop offset="0" stop-color="#ff0000"/>
+   <stop offset="1" stop-color="#000000"/>
+  </radialGradient>
+ </defs>
+ <g fill="#ffff00">
+  <title>Layer 1</title>
+  <rect id="svg_1" height="50" width="200" y="0" x="0" />
+  <text x="50" y="40" id="svg_12" font-size="48" font-family="serif" fill="url(#svg_2)">Text</text>
+ </g>
+</svg>
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index 2ae8a06..1f592e7 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -263,6 +263,9 @@ namespace svgio
                 // dismantle to geometry and add needed primitives
                 const basegfx::BColor* pFill = getFill();
                 const SvgGradientNode* pFillGradient = getSvgGradientNodeFill();
+                const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
+                const SvgGradientNode* pParentFillGradient =
+                    pSvgStyleAttributes ? pSvgStyleAttributes->getSvgGradientNodeFill() : nullptr;
                 const SvgPatternNode* pFillPattern = getSvgPatternNodeFill();
                 const basegfx::BColor* pStroke = getStroke();
                 const SvgGradientNode* pStrokeGradient = getSvgGradientNodeStroke();
@@ -303,20 +306,20 @@ namespace svgio
 
                 const bool bStrokeUsed(pStroke || pStrokeGradient || pStrokePattern);
 
+                if(pFill && (!pFillGradient || pParentFillGradient))
+                {
+                    // add the already prepared primitives for single color fill
+                    rTarget.append(rSource);
+                }
                 // add fill. Use geometry even for simple color fill when stroke
                 // is used, else text rendering and the geometry-based stroke will
                 // normally not really match optically due to diverse system text
                 // renderers
-                if(aMergedArea.count() && (pFillGradient || pFillPattern || bStrokeUsed))
+                else if(aMergedArea.count() && (pFillGradient || pFillPattern || bStrokeUsed))
                 {
                     // create text fill content based on geometry
                     add_fill(aMergedArea, rTarget, aMergedArea.getB2DRange());
                 }
-                else if(pFill)
-                {
-                    // add the already prepared primitives for single color fill
-                    rTarget.append(rSource);
-                }
 
                 // add stroke
                 if(aMergedArea.count() && bStrokeUsed)
diff --git a/test/source/primitive2dxmldump.cxx b/test/source/primitive2dxmldump.cxx
index 84cef39..dd1546f 100644
--- a/test/source/primitive2dxmldump.cxx
+++ b/test/source/primitive2dxmldump.cxx
@@ -24,6 +24,8 @@
 #include <drawinglayer/primitive2d/textprimitive2d.hxx>
 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
+#include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
+#include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
 
 #include <drawinglayer/attribute/lineattribute.hxx>
 
@@ -180,8 +182,8 @@ void Primitive2dXmlDump::decomposeAndWrite(
                 {
                     rWriter.attribute("height", aScale.getY());
                 }
-
                 rWriter.attribute("text", pTextSimplePortionPrimitive2D->getText());
+                rWriter.attribute("fontcolor", convertColorToString(pTextSimplePortionPrimitive2D->getFontColor()));
                 rWriter.endElement();
             }
             break;
@@ -207,6 +209,30 @@ void Primitive2dXmlDump::decomposeAndWrite(
             }
             break;
 
+            case PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D:
+            {
+                const ObjectInfoPrimitive2D* pObjectInfoPrimitive2D = dynamic_cast<const ObjectInfoPrimitive2D*>(pBasePrimitive);
+                rWriter.startElement("objectinfo");
+
+                decomposeAndWrite(pObjectInfoPrimitive2D->getChildren(), rWriter);
+                rWriter.endElement();
+            }
+            break;
+
+            case PRIMITIVE2D_ID_SVGRADIALGRADIENTPRIMITIVE2D:
+            {
+                const SvgRadialGradientPrimitive2D* pSvgRadialGradientPrimitive2D = dynamic_cast<const SvgRadialGradientPrimitive2D*>(pBasePrimitive);
+                rWriter.startElement("svgradialgradient");
+                basegfx::B2DPoint aFocusAttribute = pSvgRadialGradientPrimitive2D->getFocal();
+
+                rWriter.attribute("radius", pSvgRadialGradientPrimitive2D->getRadius());
+                rWriter.attribute("x", aFocusAttribute.getX());
+                rWriter.attribute("y", aFocusAttribute.getY());
+
+                rWriter.endElement();
+            }
+            break;
+
             default:
             {
                 rWriter.element(OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8));


More information about the Libreoffice-commits mailing list