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

Xisco Fauli anistenis at gmail.com
Sat Feb 13 13:39:03 UTC 2016


 svgio/inc/svgio/svgreader/svgtools.hxx        |    4 +-
 svgio/qa/cppunit/SvgImportTest.cxx            |   32 ++++++++++++++++
 svgio/qa/cppunit/data/RGBAColor.svg           |    4 ++
 svgio/qa/cppunit/data/RGBColor.svg            |    4 ++
 svgio/source/svgreader/svgstyleattributes.cxx |   28 ++++++++++++--
 svgio/source/svgreader/svgtools.cxx           |   50 +++++++++++++++++++++-----
 6 files changed, 107 insertions(+), 15 deletions(-)

New commits:
commit 3c8b880c5edc1dcbf0f481c558c6093513df6b45
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Fri Feb 12 01:36:58 2016 +0100

    SVGIO: tdf#97659: Add support for RGBA
    
    Change-Id: Icbf3796cdc95f91d298a5ca52d44931b3985eac6
    Reviewed-on: https://gerrit.libreoffice.org/22303
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/svgio/inc/svgio/svgreader/svgtools.hxx b/svgio/inc/svgio/svgreader/svgtools.hxx
index 27b687f..a9dba7f 100644
--- a/svgio/inc/svgio/svgreader/svgtools.hxx
+++ b/svgio/inc/svgio/svgreader/svgtools.hxx
@@ -201,12 +201,12 @@ namespace svgio
         bool readAngle(const OUString& rCandidate, sal_Int32& nPos, double& fAngle, const sal_Int32 nLen);
         sal_Int32 read_hex(const sal_Unicode& rChar);
         bool match_colorKeyword(basegfx::BColor& rColor, const OUString& rName, bool bCaseIndependent);
-        bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, bool bCaseIndependent);
+        bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, bool bCaseIndependent, SvgNumber& rOpacity);
         basegfx::B2DRange readViewBox(const OUString& rCandidate, InfoProvider& rInfoProvider);
         basegfx::B2DHomMatrix readTransform(const OUString& rCandidate, InfoProvider& 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);
+        bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, OUString& rURL, bool bCaseIndependent, SvgNumber& rOpacity);
 
         bool readSvgNumberVector(const OUString& rCandidate, SvgNumberVector& rSvgNumberVector);
         ::std::vector< double > solveSvgNumberVector(const SvgNumberVector& rInput, const InfoProvider& rInfoProvider, NumberType aNumberType = length);
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index 182c4fe..2030598 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -48,6 +48,8 @@ class Test : public test::BootstrapFixture, public XmlTestTools
     void testTdf97542_1();
     void testTdf97542_2();
     void testTdf97543();
+    void testRGBColor();
+    void testRGBAColor();
 
     Primitive2DSequence parseSvg(const char* aSource);
 
@@ -66,6 +68,8 @@ public:
     CPPUNIT_TEST(testTdf97542_1);
     CPPUNIT_TEST(testTdf97542_2);
     CPPUNIT_TEST(testTdf97543);
+    CPPUNIT_TEST(testRGBColor);
+    CPPUNIT_TEST(testRGBAColor);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -232,6 +236,7 @@ void Test::testTdf85770()
 
 void Test::testTdf79163()
 {
+    //Check Opacity
     Primitive2DSequence aSequenceTdf79163 = parseSvg("/svgio/qa/cppunit/data/tdf79163.svg");
     CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf79163.getLength());
 
@@ -284,6 +289,33 @@ void Test::testTdf97543()
 
     assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#00cc00");
 }
+
+void Test::testRGBColor()
+{
+    Primitive2DSequence aSequenceRGBColor = parseSvg("/svgio/qa/cppunit/data/RGBColor.svg");
+    CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceRGBColor.getLength());
+
+    Primitive2dXmlDump dumper;
+    xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceRGBColor));
+
+    CPPUNIT_ASSERT (pDocument);
+
+    assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#646464");
+}
+
+void Test::testRGBAColor()
+{
+    Primitive2DSequence aSequenceRGBAColor = parseSvg("/svgio/qa/cppunit/data/RGBAColor.svg");
+    CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceRGBAColor.getLength());
+
+    Primitive2dXmlDump dumper;
+    xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceRGBAColor));
+
+    CPPUNIT_ASSERT (pDocument);
+
+    assertXPath(pDocument, "/primitive2D/transform/unifiedtransparence", "transparence", "0");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 }
diff --git a/svgio/qa/cppunit/data/RGBAColor.svg b/svgio/qa/cppunit/data/RGBAColor.svg
new file mode 100644
index 0000000..ddd7a3c
--- /dev/null
+++ b/svgio/qa/cppunit/data/RGBAColor.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<svg width="120" height="120" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+   <rect x="10" y="10" width="100" height="100" rx="10" ry="10" fill="rgba(20,10,100,0.5)" visibility="inherit" />
+</svg>
diff --git a/svgio/qa/cppunit/data/RGBColor.svg b/svgio/qa/cppunit/data/RGBColor.svg
new file mode 100644
index 0000000..ad60d5b
--- /dev/null
+++ b/svgio/qa/cppunit/data/RGBColor.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<svg width="120" height="120" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+   <rect x="10" y="10" width="100" height="100" rx="10" ry="10" fill="rgb(100,100,100)" visibility="inherit" />
+</svg>
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index 1f592e7..698f7e8 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -1258,10 +1258,15 @@ namespace svgio
                 {
                     SvgPaint aSvgPaint;
                     OUString aURL;
+                    SvgNumber aOpacity;
 
-                    if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent))
+                    if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity))
                     {
                         setFill(aSvgPaint);
+                        if(aOpacity.isSet())
+                        {
+                            setOpacity(SvgNumber(basegfx::clamp(aOpacity.getNumber(), 0.0, 1.0)));
+                        }
                     }
                     else if(!aURL.isEmpty())
                     {
@@ -1310,10 +1315,15 @@ namespace svgio
                 {
                     SvgPaint aSvgPaint;
                     OUString aURL;
+                    SvgNumber aOpacity;
 
-                    if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent))
+                    if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity))
                     {
                         setStroke(aSvgPaint);
+                        if(aOpacity.isSet())
+                        {
+                            setOpacity(SvgNumber(basegfx::clamp(aOpacity.getNumber(), 0.0, 1.0)));
+                        }
                     }
                     else if(!aURL.isEmpty())
                     {
@@ -1448,10 +1458,15 @@ namespace svgio
                 {
                     SvgPaint aSvgPaint;
                     OUString aURL;
+                    SvgNumber aOpacity;
 
-                    if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent))
+                    if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity))
                     {
                         setStopColor(aSvgPaint);
+                        if(aOpacity.isSet())
+                        {
+                            setOpacity(SvgNumber(basegfx::clamp(aOpacity.getNumber(), 0.0, 1.0)));
+                        }
                     }
                     break;
                 }
@@ -1767,10 +1782,15 @@ namespace svgio
                 {
                     SvgPaint aSvgPaint;
                     OUString aURL;
+                    SvgNumber aOpacity;
 
-                    if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent))
+                    if(readSvgPaint(aContent, aSvgPaint, aURL, bCaseIndependent, aOpacity))
                     {
                         setColor(aSvgPaint);
+                        if(aOpacity.isSet())
+                        {
+                            setOpacity(SvgNumber(basegfx::clamp(aOpacity.getNumber(), 0.0, 1.0)));
+                        }
                     }
                     break;
                 }
diff --git a/svgio/source/svgreader/svgtools.cxx b/svgio/source/svgreader/svgtools.cxx
index ff74d63..a4e4233 100644
--- a/svgio/source/svgreader/svgtools.cxx
+++ b/svgio/source/svgreader/svgtools.cxx
@@ -814,7 +814,7 @@ namespace svgio
             }
         }
 
-        bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, bool bCaseIndependent)
+        bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, bool bCaseIndependent, SvgNumber& rOpacity)
         {
             const sal_Int32 nLen(rCandidate.getLength());
 
@@ -866,8 +866,17 @@ namespace svgio
 
                     if(rCandidate.matchIgnoreAsciiCase(aStrRgb, 0))
                     {
-                        // rgb definition
+                        // rgb/rgba definition
                         sal_Int32 nPos(strlen(aStrRgb));
+                        bool bIsRGBA = false;
+
+                        if('a' == rCandidate[nPos])
+                        {
+                            //Delete the 'a' from 'rbga'
+                            skip_char(rCandidate, 'a', nPos, nPos + 1);
+                            bIsRGBA = true;
+                        }
+
                         skip_char(rCandidate, ' ', '(', nPos, nLen);
                         double fR(0.0);
 
@@ -901,17 +910,39 @@ namespace svgio
 
                                     if(readNumber(rCandidate, nPos, fB, nLen))
                                     {
-                                        const double fFac(bIsPercent ? 0.01 : fFactor);
-
-                                        rColor.setRed(fR * fFac);
-                                        rColor.setGreen(fG * fFac);
-                                        rColor.setBlue(fB * fFac);
+                                        double fA(1.0);
 
                                         if(bIsPercent)
                                         {
                                             skip_char(rCandidate, '%', nPos, nLen);
                                         }
 
+                                        skip_char(rCandidate, ' ', ',', nPos, nLen);
+
+                                        if(readNumber(rCandidate, nPos, fA, nLen))
+                                        {
+                                            if(bIsRGBA)
+                                            {
+                                                const double fFac(bIsPercent ? 0.01 : 1);
+                                                rOpacity = SvgNumber(fA * fFac);
+
+                                                if(bIsPercent)
+                                                {
+                                                    skip_char(rCandidate, '%', nPos, nLen);
+                                                }
+                                            }
+                                            else
+                                            {
+                                                return false;
+                                            }
+                                        }
+
+                                        const double fFac(bIsPercent ? 0.01 : fFactor);
+
+                                        rColor.setRed(fR * fFac);
+                                        rColor.setGreen(fG * fFac);
+                                        rColor.setBlue(fB * fFac);
+
                                         skip_char(rCandidate, ' ', ')', nPos, nLen);
                                         return true;
                                     }
@@ -1207,13 +1238,14 @@ namespace svgio
             return false;
         }
 
-        bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, OUString& rURL, bool bCaseIndependent)
+        bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint,
+            OUString& rURL, bool bCaseIndependent, SvgNumber& rOpacity)
         {
             if( !rCandidate.isEmpty() )
             {
                 basegfx::BColor aColor;
 
-                if(read_color(rCandidate, aColor, bCaseIndependent))
+                if(read_color(rCandidate, aColor, bCaseIndependent, rOpacity))
                 {
                     rSvgPaint = SvgPaint(aColor, true, true);
                     return true;


More information about the Libreoffice-commits mailing list