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

Armin Le Grand alg at apache.org
Mon Oct 13 09:32:09 PDT 2014


 svgio/inc/svgio/svgreader/svgtools.hxx        |    4 ++
 svgio/source/svgreader/svgdocumenthandler.cxx |   11 +++++
 svgio/source/svgreader/svgtools.cxx           |   51 ++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 1 deletion(-)

New commits:
commit c18591107d9c856b15fa884eaed354d021ec4262
Author: Armin Le Grand <alg at apache.org>
Date:   Fri Oct 10 15:52:52 2014 +0000

    Resolves: #i125325# added code to handle block comments...
    
    in Css style definitions
    
    (cherry picked from commit 7b071b828a5f602cc30c17ddd871a75426a53faf)
    
    Conflicts:
    	svgio/source/svgreader/svgtools.cxx
    
    Change-Id: I094228ea398686c5b39f5f279a964a2df7b00368

diff --git a/svgio/inc/svgio/svgreader/svgtools.hxx b/svgio/inc/svgio/svgreader/svgtools.hxx
index 555a075..a2f1940 100644
--- a/svgio/inc/svgio/svgreader/svgtools.hxx
+++ b/svgio/inc/svgio/svgreader/svgtools.hxx
@@ -224,6 +224,10 @@ namespace svgio
         OUString whiteSpaceHandlingDefault(const OUString& rCandidate);
         OUString whiteSpaceHandlingPreserve(const OUString& rCandidate);
 
+        // #125325# removes block comment of the general form '/* ... */', returns
+        // an adapted string or the original if no comments included
+        OUString removeBlockComments(const OUString& rCandidate);
+
     } // end of namespace svgreader
 } // end of namespace svgio
 
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx
index 1cb1a54..d816f54 100644
--- a/svgio/source/svgreader/svgdocumenthandler.cxx
+++ b/svgio/source/svgreader/svgdocumenthandler.cxx
@@ -519,7 +519,16 @@ namespace svgio
                     if(maCssContents.size())
                     {
                         // need to interpret css styles and remember them as StyleSheets
-                        pCssStyle->addCssStyleSheet(*(maCssContents.end() - 1));
+                        // #125325# Caution! the Css content may contain block comments
+                        // (see http://www.w3.org/wiki/CSS_basics#CSS_comments). These need
+                        // to be removed first
+                        const OUString aCommentFreeSource(removeBlockComments(*(maCssContents.end() - 1)));
+
+                        if(aCommentFreeSource.getLength())
+                        {
+                            pCssStyle->addCssStyleSheet(aCommentFreeSource);
+                        }
+
                         maCssContents.pop_back();
                     }
                     else
diff --git a/svgio/source/svgreader/svgtools.cxx b/svgio/source/svgreader/svgtools.cxx
index f3faa47..a4d594a 100644
--- a/svgio/source/svgreader/svgtools.cxx
+++ b/svgio/source/svgreader/svgtools.cxx
@@ -1513,6 +1513,57 @@ namespace svgio
             return rCandidate;
         }
 
+        // #i125325#
+        OUString removeBlockComments(const OUString& rCandidate)
+        {
+            const sal_Int32 nLen(rCandidate.getLength());
+
+            if(nLen)
+            {
+                sal_Int32 nPos(0);
+                OUStringBuffer aBuffer;
+                bool bChanged(false);
+                sal_Int32 nInsideComment(0);
+                const sal_Unicode aCommentSlash('/');
+                const sal_Unicode aCommentStar('*');
+
+                while(nPos < nLen)
+                {
+                    const sal_Unicode aChar(rCandidate[nPos]);
+                    const bool bStart(aCommentSlash == aChar && nPos + 1 < nLen && aCommentStar == rCandidate[nPos + 1]);
+                    const bool bEnd(aCommentStar == aChar && nPos + 1 < nLen && aCommentSlash == rCandidate[nPos + 1]);
+
+                    if(bStart)
+                    {
+                        nPos += 2;
+                        nInsideComment++;
+                        bChanged = true;
+                    }
+                    else if(bEnd)
+                    {
+                        nPos += 2;
+                        nInsideComment--;
+                    }
+                    else
+                    {
+                        if(!nInsideComment)
+                        {
+                            aBuffer.append(aChar);
+                        }
+
+                        nPos++;
+                    }
+                }
+
+                if(bChanged)
+                {
+                    return aBuffer.makeStringAndClear();
+                }
+            }
+
+            return rCandidate;
+        }
+
         OUString consolidateContiguosSpace(const OUString& rCandidate)
         {
             const sal_Int32 nLen(rCandidate.getLength());


More information about the Libreoffice-commits mailing list