Kaydet (Commit) b6a62f07 authored tarafından Xisco Fauli's avatar Xisco Fauli Kaydeden (comit) Xisco Faulí

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/22131Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJochen Nitschke <j.nitschke+logerrit@ok.de>
Reviewed-by: 's avatarXisco Faulí <anistenis@gmail.com>
üst 54e3ea8a
...@@ -45,6 +45,8 @@ class Test : public test::BootstrapFixture, public XmlTestTools ...@@ -45,6 +45,8 @@ class Test : public test::BootstrapFixture, public XmlTestTools
void testTdf45771(); void testTdf45771();
void testTdf85770(); void testTdf85770();
void testTdf79163(); void testTdf79163();
void testTdf97542_1();
void testTdf97542_2();
Primitive2DSequence parseSvg(const char* aSource); Primitive2DSequence parseSvg(const char* aSource);
...@@ -60,6 +62,8 @@ public: ...@@ -60,6 +62,8 @@ public:
CPPUNIT_TEST(testTdf45771); CPPUNIT_TEST(testTdf45771);
CPPUNIT_TEST(testTdf85770); CPPUNIT_TEST(testTdf85770);
CPPUNIT_TEST(testTdf79163); CPPUNIT_TEST(testTdf79163);
CPPUNIT_TEST(testTdf97542_1);
CPPUNIT_TEST(testTdf97542_2);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
...@@ -237,6 +241,34 @@ void Test::testTdf79163() ...@@ -237,6 +241,34 @@ void Test::testTdf79163()
assertXPath(pDocument, "/primitive2D/transform/mask/unifiedtransparence", "transparence", "0"); 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); CPPUNIT_TEST_SUITE_REGISTRATION(Test);
} }
......
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
...@@ -263,6 +263,9 @@ namespace svgio ...@@ -263,6 +263,9 @@ namespace svgio
// dismantle to geometry and add needed primitives // dismantle to geometry and add needed primitives
const basegfx::BColor* pFill = getFill(); const basegfx::BColor* pFill = getFill();
const SvgGradientNode* pFillGradient = getSvgGradientNodeFill(); const SvgGradientNode* pFillGradient = getSvgGradientNodeFill();
const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
const SvgGradientNode* pParentFillGradient =
pSvgStyleAttributes ? pSvgStyleAttributes->getSvgGradientNodeFill() : nullptr;
const SvgPatternNode* pFillPattern = getSvgPatternNodeFill(); const SvgPatternNode* pFillPattern = getSvgPatternNodeFill();
const basegfx::BColor* pStroke = getStroke(); const basegfx::BColor* pStroke = getStroke();
const SvgGradientNode* pStrokeGradient = getSvgGradientNodeStroke(); const SvgGradientNode* pStrokeGradient = getSvgGradientNodeStroke();
...@@ -303,20 +306,20 @@ namespace svgio ...@@ -303,20 +306,20 @@ namespace svgio
const bool bStrokeUsed(pStroke || pStrokeGradient || pStrokePattern); 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 // add fill. Use geometry even for simple color fill when stroke
// is used, else text rendering and the geometry-based stroke will // is used, else text rendering and the geometry-based stroke will
// normally not really match optically due to diverse system text // normally not really match optically due to diverse system text
// renderers // renderers
if(aMergedArea.count() && (pFillGradient || pFillPattern || bStrokeUsed)) else if(aMergedArea.count() && (pFillGradient || pFillPattern || bStrokeUsed))
{ {
// create text fill content based on geometry // create text fill content based on geometry
add_fill(aMergedArea, rTarget, aMergedArea.getB2DRange()); add_fill(aMergedArea, rTarget, aMergedArea.getB2DRange());
} }
else if(pFill)
{
// add the already prepared primitives for single color fill
rTarget.append(rSource);
}
// add stroke // add stroke
if(aMergedArea.count() && bStrokeUsed) if(aMergedArea.count() && bStrokeUsed)
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include <drawinglayer/primitive2d/textprimitive2d.hxx> #include <drawinglayer/primitive2d/textprimitive2d.hxx>
#include <drawinglayer/primitive2d/maskprimitive2d.hxx> #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
#include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx> #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
#include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
#include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
#include <drawinglayer/attribute/lineattribute.hxx> #include <drawinglayer/attribute/lineattribute.hxx>
...@@ -180,8 +182,8 @@ void Primitive2dXmlDump::decomposeAndWrite( ...@@ -180,8 +182,8 @@ void Primitive2dXmlDump::decomposeAndWrite(
{ {
rWriter.attribute("height", aScale.getY()); rWriter.attribute("height", aScale.getY());
} }
rWriter.attribute("text", pTextSimplePortionPrimitive2D->getText()); rWriter.attribute("text", pTextSimplePortionPrimitive2D->getText());
rWriter.attribute("fontcolor", convertColorToString(pTextSimplePortionPrimitive2D->getFontColor()));
rWriter.endElement(); rWriter.endElement();
} }
break; break;
...@@ -207,6 +209,30 @@ void Primitive2dXmlDump::decomposeAndWrite( ...@@ -207,6 +209,30 @@ void Primitive2dXmlDump::decomposeAndWrite(
} }
break; 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: default:
{ {
rWriter.element(OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8)); rWriter.element(OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment