svx/source/customshapes/EnhancedCustomShapeFontWork.cxx |   94 ++++------------
 1 file changed, 25 insertions(+), 69 deletions(-)

New commits:
commit 5ad33bf93ca718bc4f33b4e7cf5693d7d6983cc5
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Fri Sep 2 14:06:56 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Fri Sep 2 18:10:10 2022 +0200

    Revert "ofz#48264 Timeout"
    
    This reverts commit d4eee72ea39f02ad8a63a592feb3553771bf9bbe.
    
    and all the related timeout improvement efforts and return to its
    original state, more trouble than its worth
    
    Change-Id: I5c4951ae225fe5e27a1b969cdaade3dd7ba3ce2e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139266
    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 e13e680d7407..c44e63f4bdec 100644
--- a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
+++ b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
@@ -153,41 +153,6 @@ 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 */
@@ -199,6 +164,7 @@ static void CalculateHorizontalScalingFactor(
     double fScalingFactor = 1.0;
     rFWData.fVerticalTextScaling = 1.0;
 
+    sal_uInt16 i = 0;
     bool bSingleLineMode = false;
     sal_uInt16 nOutlinesCount2d = rOutline2d.Count();
 
@@ -207,8 +173,6 @@ static void CalculateHorizontalScalingFactor(
     const SvxFontHeightItem& rFontHeight( rSdrObjCustomShape.GetMergedItem( 
EE_CHAR_FONTHEIGHT ) );
     sal_Int32 nFontSize = rFontHeight.GetHeight();
 
-    SAL_WARN_IF(nFontSize > SAL_MAX_INT16, "svx", 
"CalculateHorizontalScalingFactor suspiciously large font height: " << 
nFontSize);
-
     if (rFWData.bScaleX)
         aFont.SetFontHeight( nFontSize );
     else
@@ -239,47 +203,39 @@ static void CalculateHorizontalScalingFactor(
     // FitTextOutlinesToShapeOutlines()
     do
     {
-        UpdateScalingMode(rFWData, rOutline2d, bSingleLineMode, pVirDev, 
fScalingFactor);
-
-        if (fScalingFactor < 1.0)
+        i = 0;
+        bool bScalingFactorDefined = false; // New calculation for each font 
size
+        for( const auto& rTextArea : rFWData.vTextAreas )
         {
-            // we have a very large font that will require scaling down to a 
very small value.
-            if (nFontSize > 128)
+            // calculating the width of the corresponding 2d text area
+            double fWidth = GetLength( rOutline2d.GetObject( i++ ) );
+            if ( !bSingleLineMode )
             {
-                // see if it will even be possible at the min size
-                sal_Int32 nOrigFontSize = nFontSize;
-                double fOrigScalingFactor = fScalingFactor;
-
-                nFontSize = 2;
-                pVirDev->Push(vcl::PushFlags::FONT);
-                aFont.SetFontHeight(nFontSize);
-                pVirDev->SetFont(aFont);
-                UpdateScalingMode(rFWData, rOutline2d, bSingleLineMode, 
pVirDev, fScalingFactor);
-                pVirDev->Pop();
-
-                const bool bHopeLess = fScalingFactor < 1.0;
-                // if it's hopeless then just continue on with this FontSize 
of 2, otherwise
-                // continue to try smaller sizes
-                if (!bHopeLess)
-                {
-                    nFontSize = nOrigFontSize;
-                    fScalingFactor = fOrigScalingFactor;
+                fWidth += GetLength( rOutline2d.GetObject( i++ ) );
+                fWidth /= 2.0;
+            }
 
-                    // skip directly to a small font size
-                    double nEstimatedFinalFontSize = nFontSize * 
fScalingFactor;
-                    double nOnePercentFontSize = nFontSize / 100.0;
-                    if (nEstimatedFinalFontSize < nOnePercentFontSize)
+            for( const auto& rParagraph : rTextArea.vParagraphs )
+            {
+                double fTextWidth = pVirDev->GetTextWidth( rParagraph.aString 
);
+                if ( fTextWidth > 0.0 )
+                {
+                    double fScale = fWidth / fTextWidth;
+                    if ( !bScalingFactorDefined )
                     {
-                        nFontSize = std::max<int>(16, std::ceil(5 * 
nEstimatedFinalFontSize));
-                        SAL_WARN("svx", "CalculateHorizontalScalingFactor 
skipping direct to: " << nFontSize << " from " << rFontHeight.GetHeight());
+                        fScalingFactor = fScale;
+                        bScalingFactorDefined = true;
                     }
-                    else if (nEstimatedFinalFontSize < nOnePercentFontSize * 
10)
+                    else if (fScale < fScalingFactor)
                     {
-                        nFontSize = std::max<int>(16, std::ceil(2 * 
nEstimatedFinalFontSize));
-                        SAL_WARN("svx", "CalculateHorizontalScalingFactor 
skipping direct to: " << nFontSize << " from " << rFontHeight.GetHeight());
+                        fScalingFactor = fScale;
                     }
                 }
             }
+        }
+
+        if (fScalingFactor < 1.0)
+        {
             nFontSize--;
             aFont.SetFontHeight( nFontSize );
             pVirDev->SetFont( aFont );

Reply via email to