sc/source/core/data/column2.cxx |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

New commits:
commit f91a411340ae204ce1e6997f22e0352a4c6a8355
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Thu May 23 15:09:52 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu May 23 19:46:32 2024 +0200

    reduce cost of calc column height calculation
    
    avoid calling GetTextWidth unless we really need to
    
    Change-Id: Ibb0f378e632fa3fce68b4819028630759baf4eb5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167988
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index c4ac17ffe358..e62ac56a1e14 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -307,9 +307,10 @@ tools::Long ScColumn::GetNeededSize(
         {
             //  SetFont is moved up
 
-            Size aSize( pDev->GetTextWidth( aValStr ), pDev->GetTextHeight() );
+            Size aSize;
             if ( eOrient != SvxCellOrientation::Standard )
             {
+                aSize = Size( pDev->GetTextWidth( aValStr ), 
pDev->GetTextHeight() );
                 tools::Long nTemp = aSize.Width();
                 aSize.setWidth( aSize.Height() );
                 aSize.setHeight( nTemp );
@@ -318,6 +319,7 @@ tools::Long ScColumn::GetNeededSize(
             {
                 //TODO: take different X/Y scaling into consideration
 
+                aSize = Size( pDev->GetTextWidth( aValStr ), 
pDev->GetTextHeight() );
                 double nRealOrient = toRadians(nRotate);
                 double nCosAbs = fabs( cos( nRealOrient ) );
                 double nSinAbs = fabs( sin( nRealOrient ) );
@@ -347,8 +349,13 @@ tools::Long ScColumn::GetNeededSize(
                 }
 
                 aSize = Size( nWidth, nHeight );
+                nValue = bWidth ? aSize.Width() : aSize.Height();
             }
-            nValue = bWidth ? aSize.Width() : aSize.Height();
+            else if (bBreak && !bWidth)
+                aSize = Size( pDev->GetTextWidth( aValStr ), 
pDev->GetTextHeight() );
+            else
+                // in the common case (height), avoid calling the expensive 
GetTextWidth
+                nValue = bWidth ? pDev->GetTextWidth( aValStr ) : 
pDev->GetTextHeight();
 
             if ( bAddMargin )
             {

Reply via email to