[Libreoffice-commits] core.git: basegfx/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Aug 14 14:18:05 UTC 2018


 basegfx/source/inc/stringconversiontools.hxx |    6 --
 basegfx/source/polygon/b2dsvgpolypolygon.cxx |   79 +++++++++------------------
 2 files changed, 27 insertions(+), 58 deletions(-)

New commits:
commit 576b53468a15b2952dbdf9612f8a87d54b16680a
Author:     Mark Hung <marklh9 at gmail.com>
AuthorDate: Fri Aug 10 17:55:50 2018 +0800
Commit:     Mark Hung <marklh9 at gmail.com>
CommitDate: Tue Aug 14 16:17:43 2018 +0200

    tdf#118825 refactor basegfx::utils::exportToSvgD with putCommandChar.
    
    Move similar code fragments to a new function called putCommandChar.
    
    Change-Id: I7cd0beaab29110d89c3a206d6929e5154c755c4c
    Reviewed-on: https://gerrit.libreoffice.org/58846
    Tested-by: Jenkins
    Reviewed-by: Mark Hung <marklh9 at gmail.com>

diff --git a/basegfx/source/inc/stringconversiontools.hxx b/basegfx/source/inc/stringconversiontools.hxx
index 77489cf00260..27ae7310d2f9 100644
--- a/basegfx/source/inc/stringconversiontools.hxx
+++ b/basegfx/source/inc/stringconversiontools.hxx
@@ -63,12 +63,6 @@ namespace basegfx
                                     double          fOldValue,
                                     bool            bUseRelativeCoordinates);
 
-        inline sal_Unicode getCommand(sal_Char cUpperCaseCommand,
-                                      sal_Char cLowerCaseCommand,
-                                      bool     bUseRelativeCoordinates)
-        {
-            return bUseRelativeCoordinates ? cLowerCaseCommand : cUpperCaseCommand;
-        }
     } // namespace internal
 } // namespace basegfx
 
diff --git a/basegfx/source/polygon/b2dsvgpolypolygon.cxx b/basegfx/source/polygon/b2dsvgpolypolygon.cxx
index 2de0daf1e82f..049354621975 100644
--- a/basegfx/source/polygon/b2dsvgpolypolygon.cxx
+++ b/basegfx/source/polygon/b2dsvgpolypolygon.cxx
@@ -26,8 +26,25 @@
 #include <rtl/ustring.hxx>
 #include <sal/log.hxx>
 #include <rtl/math.hxx>
+#include <rtl/character.hxx>
 #include <stringconversiontools.hxx>
 
+namespace
+{
+
+void putCommandChar(OUStringBuffer& rBuffer,sal_Unicode& rLastSVGCommand, sal_Unicode aChar, bool bToLower)
+{
+    const sal_Unicode aCommand = bToLower ? rtl::toAsciiLowerCase(aChar) : aChar;
+
+    if (rLastSVGCommand != aCommand)
+    {
+        rBuffer.append(aCommand);
+        rLastSVGCommand = aCommand;
+    }
+}
+
+}
+
 namespace basegfx
 {
     namespace utils
@@ -723,10 +740,10 @@ namespace basegfx
                     }
 
                     // Write 'moveto' and the 1st coordinates, set aLastSVGCommand to 'lineto'
-                    aResult.append(basegfx::internal::getCommand('M', 'm', bUseRelativeCoordinatesForFirstPoint));
+                    putCommandChar(aResult, aLastSVGCommand, 'M', bUseRelativeCoordinatesForFirstPoint);
                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeStart.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinatesForFirstPoint);
                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeStart.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinatesForFirstPoint);
-                    aLastSVGCommand =  basegfx::internal::getCommand('L', 'l', bUseRelativeCoordinatesForFirstPoint);
+                    aLastSVGCommand =  bUseRelativeCoordinatesForFirstPoint ? 'l' : 'L';
                     aCurrentSVGPosition = aEdgeStart;
 
                     for(sal_uInt32 nIndex(0); nIndex < nEdgeCount; nIndex++)
@@ -780,32 +797,20 @@ namespace basegfx
                                 // approximately equal, export as quadratic bezier
                                 if(bSymmetricAtEdgeStart)
                                 {
-                                    const sal_Unicode aCommand(basegfx::internal::getCommand('T', 't', bUseRelativeCoordinates));
-
-                                    if(aLastSVGCommand != aCommand)
-                                    {
-                                        aResult.append(aCommand);
-                                    }
+                                    putCommandChar(aResult, aLastSVGCommand, 'T', bUseRelativeCoordinates);
 
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates);
-                                    aLastSVGCommand = aCommand;
                                     aCurrentSVGPosition = aEdgeEnd;
                                 }
                                 else
                                 {
-                                    const sal_Unicode aCommand(basegfx::internal::getCommand('Q', 'q', bUseRelativeCoordinates));
-
-                                    if(aLastSVGCommand != aCommand)
-                                    {
-                                        aResult.append(aCommand);
-                                    }
+                                    putCommandChar(aResult, aLastSVGCommand, 'Q', bUseRelativeCoordinates);
 
                                     basegfx::internal::putNumberCharWithSpace(aResult, aLeft.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aLeft.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates);
-                                    aLastSVGCommand = aCommand;
                                     aCurrentSVGPosition = aEdgeEnd;
                                 }
                             }
@@ -814,28 +819,17 @@ namespace basegfx
                                 // export as cubic bezier
                                 if(bSymmetricAtEdgeStart)
                                 {
-                                    const sal_Unicode aCommand(basegfx::internal::getCommand('S', 's', bUseRelativeCoordinates));
-
-                                    if(aLastSVGCommand != aCommand)
-                                    {
-                                        aResult.append(aCommand);
-                                    }
+                                    putCommandChar(aResult, aLastSVGCommand, 'S', bUseRelativeCoordinates);
 
                                     basegfx::internal::putNumberCharWithSpace(aResult, aControlEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aControlEdgeEnd.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates);
-                                    aLastSVGCommand = aCommand;
                                     aCurrentSVGPosition = aEdgeEnd;
                                 }
                                 else
                                 {
-                                    const sal_Unicode aCommand(basegfx::internal::getCommand('C', 'c', bUseRelativeCoordinates));
-
-                                    if(aLastSVGCommand != aCommand)
-                                    {
-                                        aResult.append(aCommand);
-                                    }
+                                    putCommandChar(aResult, aLastSVGCommand, 'C', bUseRelativeCoordinates);
 
                                     basegfx::internal::putNumberCharWithSpace(aResult, aControlEdgeStart.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aControlEdgeStart.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates);
@@ -843,7 +837,6 @@ namespace basegfx
                                     basegfx::internal::putNumberCharWithSpace(aResult, aControlEdgeEnd.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates);
-                                    aLastSVGCommand = aCommand;
                                     aCurrentSVGPosition = aEdgeEnd;
                                 }
                             }
@@ -868,13 +861,7 @@ namespace basegfx
                                 else if(bXEqual)
                                 {
                                     // export as vertical line
-                                    const sal_Unicode aCommand(basegfx::internal::getCommand('V', 'v', bUseRelativeCoordinates));
-
-                                    if(aLastSVGCommand != aCommand)
-                                    {
-                                        aResult.append(aCommand);
-                                        aLastSVGCommand = aCommand;
-                                    }
+                                    putCommandChar(aResult, aLastSVGCommand, 'V', bUseRelativeCoordinates);
 
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates);
                                     aCurrentSVGPosition = aEdgeEnd;
@@ -882,13 +869,7 @@ namespace basegfx
                                 else if(bYEqual)
                                 {
                                     // export as horizontal line
-                                    const sal_Unicode aCommand(basegfx::internal::getCommand('H', 'h', bUseRelativeCoordinates));
-
-                                    if(aLastSVGCommand != aCommand)
-                                    {
-                                        aResult.append(aCommand);
-                                        aLastSVGCommand = aCommand;
-                                    }
+                                    putCommandChar(aResult, aLastSVGCommand, 'H', bUseRelativeCoordinates);
 
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates);
                                     aCurrentSVGPosition = aEdgeEnd;
@@ -896,13 +877,7 @@ namespace basegfx
                                 else
                                 {
                                     // export as line
-                                    const sal_Unicode aCommand(basegfx::internal::getCommand('L', 'l', bUseRelativeCoordinates));
-
-                                    if(aLastSVGCommand != aCommand)
-                                    {
-                                        aResult.append(aCommand);
-                                        aLastSVGCommand = aCommand;
-                                    }
+                                    putCommandChar(aResult, aLastSVGCommand, 'L', bUseRelativeCoordinates);
 
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates);
                                     basegfx::internal::putNumberCharWithSpace(aResult, aEdgeEnd.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates);
@@ -918,7 +893,7 @@ namespace basegfx
                     // close path if closed poly (Z and z are equivalent here, but looks nicer when case is matched)
                     if(aPolygon.isClosed())
                     {
-                        aResult.append(basegfx::internal::getCommand('Z', 'z', bUseRelativeCoordinates));
+                        putCommandChar(aResult, aLastSVGCommand, 'Z', bUseRelativeCoordinates);
                     }
 
                     if(!bHandleRelativeNextPointCompatible)


More information about the Libreoffice-commits mailing list