svgio/inc/svgtools.hxx | 6 +++--- svgio/qa/cppunit/SvgImportTest.cxx | 18 ++++++++++++++++++ svgio/qa/cppunit/data/tdf149893.svg | 3 +++ svgio/source/svgreader/svgstyleattributes.cxx | 8 ++++---- svgio/source/svgreader/svgtools.cxx | 18 ++++++------------ 5 files changed, 34 insertions(+), 19 deletions(-)
New commits: commit cded65d05a01ac34af750ddb97f1ffb51f3d638a Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Thu Jul 7 12:33:12 2022 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Jul 7 13:47:51 2022 +0200 tdf#149893: Color names are ASCII case-insensitive See https://www.w3.org/TR/css-color-3/#html4 Change-Id: Ifdf887bad08ab606abef78fa8335bc49507f4a43 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136879 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Tested-by: Jenkins diff --git a/svgio/inc/svgtools.hxx b/svgio/inc/svgtools.hxx index 6ef52ae5bf6c..f5e2e03573e6 100644 --- a/svgio/inc/svgtools.hxx +++ b/svgio/inc/svgtools.hxx @@ -106,13 +106,13 @@ namespace svgio::svgreader bool readNumberAndUnit(std::u16string_view rCandidate, sal_Int32& nPos, SvgNumber& aNum, const sal_Int32 nLen); bool readAngle(std::u16string_view rCandidate, sal_Int32& nPos, double& fAngle, const sal_Int32 nLen); sal_Int32 read_hex(sal_Unicode aChar); - bool match_colorKeyword(basegfx::BColor& rColor, const OUString& rName, bool bCaseIndependent); - bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, bool bCaseIndependent, SvgNumber& rOpacity); + bool match_colorKeyword(basegfx::BColor& rColor, const OUString& rName); + bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, SvgNumber& rOpacity); basegfx::B2DRange readViewBox(const OUString& rCandidate, InfoProvider const & rInfoProvider); basegfx::B2DHomMatrix readTransform(const OUString& rCandidate, InfoProvider const & rInfoProvider); bool readSingleNumber(const OUString& rCandidate, SvgNumber& aNum); bool readLocalUrl(const OUString& rCandidate, OUString& rURL); - bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, OUString& rURL, bool bCaseIndependent, SvgNumber& rOpacity); + bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, OUString& rURL, SvgNumber& rOpacity); bool readSvgNumberVector(const OUString& rCandidate, SvgNumberVector& rSvgNumberVector); ::std::vector< double > solveSvgNumberVector(const SvgNumberVector& rInput, const InfoProvider& rInfoProvider); diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index 5c041ac3b386..b97185f36af7 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -56,6 +56,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools void testRGBAColor(); void testNoneColor(); void testTdf97936(); + void testTdf149893(); void testClipPathAndParentStyle(); void testClipPathAndStyle(); void testi125329(); @@ -94,6 +95,7 @@ public: CPPUNIT_TEST(testRGBAColor); CPPUNIT_TEST(testNoneColor); CPPUNIT_TEST(testTdf97936); + CPPUNIT_TEST(testTdf149893); CPPUNIT_TEST(testClipPathAndParentStyle); CPPUNIT_TEST(testClipPathAndStyle); CPPUNIT_TEST(testi125329); @@ -523,6 +525,22 @@ void Test::testTdf97936() assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]/polypolygon", "maxy", "100"); } +void Test::testTdf149893() +{ + Primitive2DSequence aSequenceClipPathAndParentStyle = parseSvg(u"/svgio/qa/cppunit/data/tdf149893.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceClipPathAndParentStyle.getLength())); + + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequenceClipPathAndParentStyle)); + + CPPUNIT_ASSERT (pDocument); + + // Without the fix in place, this test would have failed with + // - Expected: #008000 + // - Actual : #000000 + assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#008000"); +} + void Test::testClipPathAndParentStyle() { //Check that fill color, stroke color and stroke-width are inherited from use element diff --git a/svgio/qa/cppunit/data/tdf149893.svg b/svgio/qa/cppunit/data/tdf149893.svg new file mode 100644 index 000000000000..05c41eac96af --- /dev/null +++ b/svgio/qa/cppunit/data/tdf149893.svg @@ -0,0 +1,3 @@ +<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"> + <rect x="0" y="0" width="100%" height="100%" fill="GREEN"></rect> +</svg> diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index a2ed97a940ed..5e355ea309da 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -1301,7 +1301,7 @@ namespace svgio::svgreader OUString aURL; SvgNumber aOpacity; - if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity)) + if(readSvgPaint(aContent, aSvgPaint, aURL, aOpacity)) { setFill(aSvgPaint); if(aOpacity.isSet()) @@ -1346,7 +1346,7 @@ namespace svgio::svgreader OUString aURL; SvgNumber aOpacity; - if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity)) + if(readSvgPaint(aContent, aSvgPaint, aURL, aOpacity)) { maStroke = aSvgPaint; if(aOpacity.isSet()) @@ -1475,7 +1475,7 @@ namespace svgio::svgreader OUString aURL; SvgNumber aOpacity; - if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity)) + if(readSvgPaint(aContent, aSvgPaint, aURL, aOpacity)) { maStopColor = aSvgPaint; if(aOpacity.isSet()) @@ -1788,7 +1788,7 @@ namespace svgio::svgreader OUString aURL; SvgNumber aOpacity; - if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity)) + if(readSvgPaint(aContent, aSvgPaint, aURL, aOpacity)) { maColor = aSvgPaint; if(aOpacity.isSet()) diff --git a/svgio/source/svgreader/svgtools.cxx b/svgio/source/svgreader/svgtools.cxx index 4ae287784d8c..7fd541a2a93e 100644 --- a/svgio/source/svgreader/svgtools.cxx +++ b/svgio/source/svgreader/svgtools.cxx @@ -486,7 +486,7 @@ namespace svgio::svgreader } } - bool match_colorKeyword(basegfx::BColor& rColor, const OUString& rName, bool bCaseIndependent) + bool match_colorKeyword(basegfx::BColor& rColor, const OUString& rName) { typedef std::unordered_map< OUString, Color > ColorTokenMapper; typedef std::pair< OUString, Color > ColorTokenValueType; @@ -640,13 +640,7 @@ namespace svgio::svgreader { ColorTokenValueType(OUString("yellowgreen"), Color(154, 205, 50) ) }, }; - ColorTokenMapper::const_iterator aResult(aColorTokenMapperList.find(rName)); - - if(bCaseIndependent && aResult == aColorTokenMapperList.end()) - { - // also try case independent match (e.g. for Css styles) - aResult = aColorTokenMapperList.find(rName.toAsciiLowerCase()); - } + ColorTokenMapper::const_iterator aResult(aColorTokenMapperList.find(rName.toAsciiLowerCase())); if(aResult == aColorTokenMapperList.end()) { @@ -659,7 +653,7 @@ namespace svgio::svgreader } } - bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, bool bCaseIndependent, SvgNumber& rOpacity) + bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, SvgNumber& rOpacity) { const sal_Int32 nLen(rCandidate.getLength()); @@ -798,7 +792,7 @@ namespace svgio::svgreader else { // color keyword - if(match_colorKeyword(rColor, rCandidate, bCaseIndependent)) + if(match_colorKeyword(rColor, rCandidate)) { return true; } @@ -1093,13 +1087,13 @@ namespace svgio::svgreader } bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, - OUString& rURL, bool bCaseIndependent, SvgNumber& rOpacity) + OUString& rURL, SvgNumber& rOpacity) { if( !rCandidate.isEmpty() ) { basegfx::BColor aColor; - if(read_color(rCandidate, aColor, bCaseIndependent, rOpacity)) + if(read_color(rCandidate, aColor, rOpacity)) { rSvgPaint = SvgPaint(aColor, true, true); return true;