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 de722a935c4a6fbde1e09da79840cca63fdafac1
Author:     Xisco Fauli <[email protected]>
AuthorDate: Thu Jul 7 12:33:12 2022 +0200
Commit:     Adolfo Jayme Barrientos <[email protected]>
CommitDate: Fri Jul 8 05:13:46 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 <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 8da687a2843a2cc9e5db3c82204260bde783a76c)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136863
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136882
    Reviewed-by: Adolfo Jayme Barrientos <[email protected]>

diff --git a/svgio/inc/svgtools.hxx b/svgio/inc/svgtools.hxx
index 550c33d88fac..7b532cd35b15 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(const OUString& 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 c563e7b296fd..49ac541c4424 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();
@@ -92,6 +93,7 @@ public:
     CPPUNIT_TEST(testRGBAColor);
     CPPUNIT_TEST(testNoneColor);
     CPPUNIT_TEST(testTdf97936);
+    CPPUNIT_TEST(testTdf149893);
     CPPUNIT_TEST(testClipPathAndParentStyle);
     CPPUNIT_TEST(testClipPathAndStyle);
     CPPUNIT_TEST(testi125329);
@@ -516,6 +518,22 @@ void Test::testTdf97936()
     assertXPath(pDocument, 
"/primitive2D/transform/polypolygoncolor[2]/polypolygon", "maxy", "100");
 }
 
+void Test::testTdf149893()
+{
+    Primitive2DSequence aSequence = 
parseSvg(u"/svgio/qa/cppunit/data/tdf149893.svg");
+    CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
+
+    drawinglayer::Primitive2dXmlDump dumper;
+    xmlDocUniquePtr pDocument = 
dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequence));
+
+    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 21ef7cebf5cf..df200e40f428 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 928dfbe5caa9..cb2f1abce77d 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;
                         }
@@ -1084,13 +1078,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;

Reply via email to