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

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Sat May 1 11:46:12 UTC 2021


 svgio/source/svgreader/SvgNumber.cxx |  176 +++++++++++++----------------------
 1 file changed, 70 insertions(+), 106 deletions(-)

New commits:
commit 0acc9af66dd2d35c8335291ff3e72d98e4359bd5
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sat May 1 13:28:35 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sat May 1 13:45:22 2021 +0200

    svgio: refactor SvgNumber::solve and SvgNumber::solveNonPercentage
    
    Change-Id: I9eefe4e6d2edf9891dc20f451230aedd44592732
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114962
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/svgio/source/svgreader/SvgNumber.cxx b/svgio/source/svgreader/SvgNumber.cxx
index 6cfb7acf292a..8254b45b035f 100644
--- a/svgio/source/svgreader/SvgNumber.cxx
+++ b/svgio/source/svgreader/SvgNumber.cxx
@@ -25,134 +25,98 @@ namespace svgio::svgreader
 
 double SvgNumber::solveNonPercentage(const InfoProvider& rInfoProvider) const
 {
-    if(isSet())
+    if (!isSet())
     {
-        switch(meUnit)
-        {
-            case SvgUnit::em:
-            {
-                return mfNumber * rInfoProvider.getCurrentFontSizeInherited();
-            }
-            case SvgUnit::ex:
-            {
-                return mfNumber * rInfoProvider.getCurrentXHeightInherited() * 0.5;
-            }
-            case SvgUnit::px:
-            {
-                return mfNumber;
-            }
-            case SvgUnit::pt:
-            case SvgUnit::pc:
-            case SvgUnit::cm:
-            case SvgUnit::mm:
-            case SvgUnit::in:
-            {
-                double fRetval(mfNumber);
-
-                switch(meUnit)
-                {
-                    case SvgUnit::pt: fRetval *= F_SVG_PIXEL_PER_INCH / 72.0; break;
-                    case SvgUnit::pc: fRetval *= F_SVG_PIXEL_PER_INCH / 6.0; break;
-                    case SvgUnit::cm: fRetval *= F_SVG_PIXEL_PER_INCH / 2.54; break;
-                    case SvgUnit::mm: fRetval *= 0.1 * F_SVG_PIXEL_PER_INCH / 2.54; break;
-                    case SvgUnit::in: fRetval *= F_SVG_PIXEL_PER_INCH; break;
-                    default: break;
-                }
+        assert(false && "SvgNumber not set (!)");
+        return 0.0;
+    }
 
-                return fRetval;
-            }
-            case SvgUnit::none:
-            {
-                SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
-                return mfNumber;
-            }
-            default:
-            {
-                assert(false && "Do not use with percentage!");
-                return 0.0;
-            }
+    switch (meUnit)
+    {
+        case SvgUnit::em:
+            return mfNumber * rInfoProvider.getCurrentFontSizeInherited();
+        case SvgUnit::ex:
+            return mfNumber * rInfoProvider.getCurrentXHeightInherited() * 0.5;
+        case SvgUnit::px:
+            return mfNumber;
+        case SvgUnit::pt:
+            return mfNumber * F_SVG_PIXEL_PER_INCH / 72.0;
+        case SvgUnit::pc:
+            return mfNumber * F_SVG_PIXEL_PER_INCH / 6.0;
+        case SvgUnit::cm:
+            return mfNumber * F_SVG_PIXEL_PER_INCH / 2.54;
+        case SvgUnit::mm:
+            return mfNumber * 0.1 * F_SVG_PIXEL_PER_INCH / 2.54;
+        case SvgUnit::in:
+            return mfNumber * F_SVG_PIXEL_PER_INCH;
+        case SvgUnit::none:
+        {
+            SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
+            return mfNumber;
+        }
+        case SvgUnit::percent:
+        {
+            assert(false && "Do not use with percentage!");
+            break;
         }
     }
 
-    /// not set
-    assert(false && "SvgNumber not set (!)");
     return 0.0;
 }
 
 double SvgNumber::solve(const InfoProvider& rInfoProvider, NumberType aNumberType) const
 {
-    if(isSet())
+    if (!isSet())
     {
-        switch(meUnit)
+        assert(false && "SvgNumber not set (!)");
+        return 0.0;
+    }
+
+    if (meUnit == SvgUnit::percent)
+    {
+        double fRetval(mfNumber * 0.01);
+        basegfx::B2DRange aViewPort = rInfoProvider.getCurrentViewPort();
+
+        if ( aViewPort.isEmpty() )
+        {
+            SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
+            // no viewPort, assume a normal page size (A4)
+            aViewPort = basegfx::B2DRange(
+                0.0,
+                0.0,
+                210.0 * F_SVG_PIXEL_PER_INCH / 2.54,
+                297.0 * F_SVG_PIXEL_PER_INCH / 2.54);
+
+        }
+
+        if ( !aViewPort.isEmpty() )
         {
-            case SvgUnit::px:
+            if (NumberType::xcoordinate == aNumberType)
             {
-                return mfNumber;
+                // it's a x-coordinate, relative to current width (w)
+                fRetval *= aViewPort.getWidth();
             }
-            case SvgUnit::pt:
-            case SvgUnit::pc:
-            case SvgUnit::cm:
-            case SvgUnit::mm:
-            case SvgUnit::in:
-            case SvgUnit::em:
-            case SvgUnit::ex:
-            case SvgUnit::none:
+            else if (NumberType::ycoordinate == aNumberType)
             {
-                return solveNonPercentage( rInfoProvider);
+                // it's a y-coordinate, relative to current height (h)
+                fRetval *= aViewPort.getHeight();
             }
-            case SvgUnit::percent:
+            else // length
             {
-                double fRetval(mfNumber * 0.01);
-                basegfx::B2DRange aViewPort = rInfoProvider.getCurrentViewPort();
+                // it's a length, relative to sqrt(w*w + h*h)/sqrt(2)
+                const double fCurrentWidth(aViewPort.getWidth());
+                const double fCurrentHeight(aViewPort.getHeight());
+                const double fCurrentLength(
+                    sqrt(fCurrentWidth * fCurrentWidth + fCurrentHeight * fCurrentHeight)/sqrt(2.0));
 
-                if ( aViewPort.isEmpty() )
-                {
-                    SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
-                    // no viewPort, assume a normal page size (A4)
-                    aViewPort = basegfx::B2DRange(
-                        0.0,
-                        0.0,
-                        210.0 * F_SVG_PIXEL_PER_INCH / 2.54,
-                        297.0 * F_SVG_PIXEL_PER_INCH / 2.54);
-
-                }
-
-                if ( !aViewPort.isEmpty() )
-                {
-                    if (NumberType::xcoordinate == aNumberType)
-                    {
-                        // it's a x-coordinate, relative to current width (w)
-                        fRetval *= aViewPort.getWidth();
-                    }
-                    else if (NumberType::ycoordinate == aNumberType)
-                    {
-                        // it's a y-coordinate, relative to current height (h)
-                        fRetval *= aViewPort.getHeight();
-                    }
-                    else // length
-                    {
-                        // it's a length, relative to sqrt(w*w + h*h)/sqrt(2)
-                        const double fCurrentWidth(aViewPort.getWidth());
-                        const double fCurrentHeight(aViewPort.getHeight());
-                        const double fCurrentLength(
-                            sqrt(fCurrentWidth * fCurrentWidth + fCurrentHeight * fCurrentHeight)/sqrt(2.0));
-
-                        fRetval *= fCurrentLength;
-                    }
-                }
-
-                return fRetval;
-            }
-            default:
-            {
-                break;
+                fRetval *= fCurrentLength;
             }
         }
+
+        return fRetval;
     }
 
-    /// not set
-    assert(false && "SvgNumber not set (!)");
-    return 0.0;
+    return solveNonPercentage( rInfoProvider);
 }
 
 } // end of namespace svgio::svgreader


More information about the Libreoffice-commits mailing list