include/svx/svdotext.hxx       |    2 
 svx/source/svdraw/svdotext.cxx |   85 ++++++-----------------------------------
 2 files changed, 14 insertions(+), 73 deletions(-)

New commits:
commit dd15364793401e41bae45cdeb410808c9f94fa93
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sat Apr 29 21:33:09 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sun Apr 30 03:19:26 2023 +0200

    adapt the new auto-fitting alg. to work for vertical text
    
    And remove the old auto-fitting algorithm now.
    
    Change-Id: I0bf26d57955018b6d43783d860a0aeae596439b5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151183
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index bf82e4db7c54..d9c0908e505b 100644
--- a/include/svx/svdotext.hxx
+++ b/include/svx/svdotext.hxx
@@ -275,7 +275,7 @@ private:
                                        Fraction&        aFitXCorrection ) 
const;
     void ImpAutoFitText( SdrOutliner& rOutliner ) const;
     void ImpAutoFitText( SdrOutliner& rOutliner, const Size& rShapeSize, bool 
bIsVerticalWriting ) const;
-    void autoFitTextForCompatibility(SdrOutliner& rOutliner, const Size& 
rShapeSize) const;
+    void autoFitTextForCompatibility(SdrOutliner& rOutliner, const Size& 
rShapeSize, bool bIsVerticalWriting) const;
 
     SVX_DLLPRIVATE rtl::Reference<SdrObject> 
ImpConvertContainedTextToSdrPathObjs(bool bToPoly) const;
     SVX_DLLPRIVATE void ImpRegisterLink();
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index 4eab532af59b..f2951787b551 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -1272,78 +1272,10 @@ void SdrTextObj::ImpAutoFitText( SdrOutliner& rOutliner 
) const
 void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, const Size& rTextSize,
                                 bool bIsVerticalWriting) const
 {
-    if (!bIsVerticalWriting)
-    {
-        autoFitTextForCompatibility(rOutliner, rTextSize);
-        return;
-    }
-
-    // EditEngine formatting is unstable enough for
-    // line-breaking text that we need some more samples
-
-    // loop early-exits if we detect an already attained value
-    double nMinStretchX = 0.0;
-    double nMinStretchY = 0.0;
-    std::array<sal_Int32, 10> aOldStretchXVals = {0,0,0,0,0,0,0,0,0,0};
-    rOutliner.setRoundFontSizeToPt(false);
-    for (size_t i = 0; i < aOldStretchXVals.size(); ++i)
-    {
-        const Size aCurrTextSize = rOutliner.CalcTextSizeNTP();
-        double fFactor = 1.0;
-        if (aCurrTextSize.Width() != 0)
-            fFactor = double(rTextSize.Width())/aCurrTextSize.Width();
-
-        // fFactor scales in both x and y directions
-        // - this is fine for bulleted words
-        // - but it scales too much for a long paragraph
-        // - taking sqrt scales long paragraphs the best
-        // - bulleted words will have to go through more iterations
-        fFactor = std::sqrt(fFactor);
-
-        double nCurrStretchX, nCurrStretchY;
-        rOutliner.getGlobalScale(nCurrStretchX, nCurrStretchY, 
o3tl::temporary(double()), o3tl::temporary(double()));
-
-        if (fFactor >= 0.98)
-        {
-            // resulting text area fits into available shape rect -
-            // err on the larger stretching, to optimally fill area
-            nMinStretchX = std::max(nMinStretchX, nCurrStretchX);
-            nMinStretchY = std::max(nMinStretchY, nCurrStretchY);
-        }
-
-        aOldStretchXVals[i] = basegfx::fround(nCurrStretchX * 10.0);
-        if (std::find(aOldStretchXVals.begin(), aOldStretchXVals.begin() + i, 
basegfx::fround(nCurrStretchX * 10.0)) != aOldStretchXVals.begin() + i)
-            break; // same value already attained once; algo is looping, exit
-
-        if (fFactor < 1.0 || nCurrStretchX != 100)
-        {
-            nCurrStretchX = double(basegfx::fround(nCurrStretchX * fFactor * 
100.0)) / 100.00;
-            nCurrStretchY = double(basegfx::fround(nCurrStretchY * fFactor * 
100.0)) / 100.00;
-
-            double nStretchX = std::min(100.0, nCurrStretchX);
-            double nStretchY = std::min(100.0, nCurrStretchY);
-
-            rOutliner.setGlobalScale(nStretchX, nStretchY, nStretchX, 
nStretchY);
-            SAL_INFO("svx", "zoom is " << nCurrStretchX);
-        }
-    }
-
-    const SdrTextFitToSizeTypeItem& rItem = 
GetObjectItem(SDRATTR_TEXT_FITTOSIZE);
-    if (rItem.GetMaxScale() > 0.0)
-    {
-        nMinStretchX = std::min(rItem.GetMaxScale(), nMinStretchX);
-        nMinStretchY = std::min(rItem.GetMaxScale(), nMinStretchY);
-    }
-
-    SAL_INFO("svx", "final zoom is " << nMinStretchX);
-
-    nMinStretchX = std::min(100.0, nMinStretchX);
-    nMinStretchY = std::min(100.0, nMinStretchY);
-
-    rOutliner.setGlobalScale(nMinStretchX, nMinStretchY, nMinStretchX, 
nMinStretchY);
+    autoFitTextForCompatibility(rOutliner, rTextSize, bIsVerticalWriting);
 }
 
-void SdrTextObj::autoFitTextForCompatibility(SdrOutliner& rOutliner, const 
Size& rTextBoxSize) const
+void SdrTextObj::autoFitTextForCompatibility(SdrOutliner& rOutliner, const 
Size& rTextBoxSize, bool bIsVerticalWriting) const
 {
     rOutliner.setRoundFontSizeToPt(true);
 
@@ -1364,7 +1296,12 @@ void 
SdrTextObj::autoFitTextForCompatibility(SdrOutliner& rOutliner, const Size&
 
     tools::Long nExtendTextBoxBy = -50;
     aCurrentTextBoxSize.extendBy(0, nExtendTextBoxBy);
-    double fCurrentFitFactor = double(rTextBoxSize.Height()) / 
aCurrentTextBoxSize.Height();
+    double fCurrentFitFactor = 1.0;
+
+    if (bIsVerticalWriting)
+        fCurrentFitFactor = double(rTextBoxSize.Width()) / 
aCurrentTextBoxSize.Width();
+    else
+        fCurrentFitFactor = double(rTextBoxSize.Height()) / 
aCurrentTextBoxSize.Height();
 
     if (fCurrentFitFactor >= 1.0)
         return;
@@ -1404,7 +1341,11 @@ void 
SdrTextObj::autoFitTextForCompatibility(SdrOutliner& rOutliner, const Size&
 
             aCurrentTextBoxSize = rOutliner.CalcTextSizeNTP();
             aCurrentTextBoxSize.extendBy(0, nExtendTextBoxBy);
-            fCurrentFitFactor = double(rTextBoxSize.Height()) / 
aCurrentTextBoxSize.Height();
+            if (bIsVerticalWriting)
+                fCurrentFitFactor = double(rTextBoxSize.Width()) / 
aCurrentTextBoxSize.Width();
+            else
+                fCurrentFitFactor = double(rTextBoxSize.Height()) / 
aCurrentTextBoxSize.Height();
+
 
             if (fCurrentSpacing == 100.0)
             {

Reply via email to