svx/source/customshapes/EnhancedCustomShapeFontWork.cxx |   67 ++++++++--------
 1 file changed, 36 insertions(+), 31 deletions(-)

New commits:
commit 03b5c306044c8a41e58b99ef7f648f81ee4a9533
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Sat Jun 18 21:13:47 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sun Jun 19 13:25:12 2022 +0200

    factor out body as UpdateScalingMode
    
    Change-Id: Ib65856e4573bbd0a4ac08aac9ef6e26b86678f46
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136092
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx 
b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
index 0043b69cd646..a08e03f146eb 100644
--- a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
+++ b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
@@ -153,6 +153,41 @@ static double GetLength( const tools::Polygon& rPolygon )
     return fLength;
 }
 
+static void UpdateScalingMode(FWData& rFWData, const tools::PolyPolygon& 
rOutline2d,
+                bool bSingleLineMode,
+                VirtualDevice* pVirDev, double& rScalingFactor)
+{
+    sal_uInt16 i = 0;
+    bool bScalingFactorDefined = false; // New calculation for each font size
+    for( const auto& rTextArea : rFWData.vTextAreas )
+    {
+        // calculating the width of the corresponding 2d text area
+        double fWidth = GetLength( rOutline2d.GetObject( i++ ) );
+        if ( !bSingleLineMode )
+        {
+            fWidth += GetLength( rOutline2d.GetObject( i++ ) );
+            fWidth /= 2.0;
+        }
+
+        for( const auto& rParagraph : rTextArea.vParagraphs )
+        {
+            double fTextWidth = pVirDev->GetTextWidth( rParagraph.aString );
+            if ( fTextWidth > 0.0 )
+            {
+                double fScale = fWidth / fTextWidth;
+                if ( !bScalingFactorDefined )
+                {
+                    rScalingFactor = fScale;
+                    bScalingFactorDefined = true;
+                }
+                else if (fScale < rScalingFactor)
+                {
+                    rScalingFactor = fScale;
+                }
+            }
+        }
+    }
+}
 
 /* CalculateHorizontalScalingFactor returns the horizontal scaling factor for
 the whole text object, so that each text will match its corresponding 2d 
Outline */
@@ -164,7 +199,6 @@ static void CalculateHorizontalScalingFactor(
     double fScalingFactor = 1.0;
     rFWData.fVerticalTextScaling = 1.0;
 
-    sal_uInt16 i = 0;
     bool bSingleLineMode = false;
     sal_uInt16 nOutlinesCount2d = rOutline2d.Count();
 
@@ -205,36 +239,7 @@ static void CalculateHorizontalScalingFactor(
     // FitTextOutlinesToShapeOutlines()
     do
     {
-        i = 0;
-        bool bScalingFactorDefined = false; // New calculation for each font 
size
-        for( const auto& rTextArea : rFWData.vTextAreas )
-        {
-            // calculating the width of the corresponding 2d text area
-            double fWidth = GetLength( rOutline2d.GetObject( i++ ) );
-            if ( !bSingleLineMode )
-            {
-                fWidth += GetLength( rOutline2d.GetObject( i++ ) );
-                fWidth /= 2.0;
-            }
-
-            for( const auto& rParagraph : rTextArea.vParagraphs )
-            {
-                double fTextWidth = pVirDev->GetTextWidth( rParagraph.aString 
);
-                if ( fTextWidth > 0.0 )
-                {
-                    double fScale = fWidth / fTextWidth;
-                    if ( !bScalingFactorDefined )
-                    {
-                        fScalingFactor = fScale;
-                        bScalingFactorDefined = true;
-                    }
-                    else if (fScale < fScalingFactor)
-                    {
-                        fScalingFactor = fScale;
-                    }
-                }
-            }
-        }
+        UpdateScalingMode(rFWData, rOutline2d, bSingleLineMode, pVirDev, 
fScalingFactor);
 
         if (fScalingFactor < 1.0)
         {

Reply via email to