sc/source/ui/docshell/docfunc.cxx |   24 +++++++++++-------------
 sc/source/ui/inc/docsh.hxx        |    2 +-
 sc/source/ui/inc/viewdata.hxx     |    3 +++
 sc/source/ui/view/tabview3.cxx    |    6 ++++--
 sc/source/ui/view/viewfun3.cxx    |    4 ++--
 sc/source/ui/view/viewfunc.cxx    |   32 +++++++++++++++++++++-----------
 vcl/source/gdi/TypeSerializer.cxx |    2 +-
 7 files changed, 43 insertions(+), 30 deletions(-)

New commits:
commit 9bc2872d5ff9e18c0d5d2b60dbd6670809f2faa5
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Mon Feb 12 15:55:22 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Feb 13 15:09:15 2024 +0100

    pass width hint around as twips and convert to pixel at the end
    
    reuse the device setup and twip calculation that GetOptimalColWidth uses
    and convert to pixel at the end with ViewData::toPixel
    
    Change-Id: Ie24a66dda2e642c23ae63ff915829dd910ee44dd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163259
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    (cherry picked from commit 85db2b8338392525bb138f41a3175203c703bf73)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163284
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/source/ui/docshell/docfunc.cxx 
b/sc/source/ui/docshell/docfunc.cxx
index 2867b8b6df36..37f0f2209848 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -671,24 +671,22 @@ bool ScDocFunc::DeleteContents(
     return true;
 }
 
-tools::Long ScDocShell::GetPixelWidthHint(const ScAddress& rPos)
+tools::Long ScDocShell::GetTwipWidthHint(const ScAddress& rPos)
 {
     ScViewData* pViewData = GetViewData();
     if (!pViewData)
         return -1;
 
     ScSizeDeviceProvider aProv(this);
-    OutputDevice* pDev = aProv.GetDevice();         // has pixel MapMode
-    double nPPTX = aProv.GetPPTX();
-    double nPPTY = aProv.GetPPTY();
+    Fraction aZoomX, aZoomY;
+    double nPPTX, nPPTY;
+    pViewData->setupSizeDeviceProviderForColWidth(aProv, aZoomX, aZoomY, 
nPPTX, nPPTY);
 
     ScDocument& rDoc = GetDocument();
-    Fraction aInvX(pViewData->GetZoomX().GetDenominator(),
-                   pViewData->GetZoomX().GetNumerator());
-    Fraction aInvY(pViewData->GetZoomY().GetDenominator(),
-                   pViewData->GetZoomY().GetNumerator());
-    return rDoc.GetNeededSize(rPos.Col(), rPos.Row(), rPos.Tab(), pDev,
-                              nPPTX, nPPTY, aInvX, aInvY, true /*bWidth*/);
+    tools::Long nWidth = rDoc.GetNeededSize(rPos.Col(), rPos.Row(), 
rPos.Tab(), aProv.GetDevice(),
+                                            nPPTX, nPPTY, aZoomX, aZoomY, true 
/*bWidth*/);
+
+    return (nWidth + 2) / nPPTX; // same as ScColumn::GetOptimalColWidth
 }
 
 bool ScDocFunc::DeleteCell(
@@ -739,7 +737,7 @@ bool ScDocFunc::DeleteCell(
         pDataSpans = sc::DocFuncUtil::getNonEmptyCellSpans(rDoc, rMark, rPos);
     }
 
-    tools::Long nBefore(rDocShell.GetPixelWidthHint(rPos));
+    tools::Long nBefore(rDocShell.GetTwipWidthHint(rPos));
     rDoc.DeleteArea(rPos.Col(), rPos.Row(), rPos.Col(), rPos.Row(), rMark, 
nFlags);
 
     if (bRecord)
@@ -854,9 +852,9 @@ bool ScDocFunc::SetNormalString( bool& o_rbNumFmtSet, const 
ScAddress& rPos, con
         aOldValues.push_back(aOldValue);
     }
 
-    tools::Long nBefore(rDocShell.GetPixelWidthHint(rPos));
+    tools::Long nBefore(rDocShell.GetTwipWidthHint(rPos));
     o_rbNumFmtSet = rDoc.SetString( rPos.Col(), rPos.Row(), rPos.Tab(), rText 
);
-    tools::Long nAfter(rDocShell.GetPixelWidthHint(rPos));
+    tools::Long nAfter(rDocShell.GetTwipWidthHint(rPos));
 
     if (bUndo)
     {
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 2a87da31ee69..1b1f4164db06 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -314,7 +314,7 @@ public:
 
     void            PostEditView( ScEditEngineDefaulter* pEditEngine, const 
ScAddress& rCursorPos );
 
-    tools::Long     GetPixelWidthHint(const ScAddress& rPos);
+    tools::Long     GetTwipWidthHint(const ScAddress& rPos);
 
     void            PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB 
nStartTab,
                             SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, 
PaintPartFlags nPart,
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 72386b2efa17..62231b116813 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -115,6 +115,7 @@ class ScExtDocOptions;
 class ScViewData;
 class ScMarkData;
 class ScGridWindow;
+class ScSizeDeviceProvider;
 
 class ScPositionHelper
 {
@@ -698,6 +699,8 @@ public:
     static void     AddPixelsWhileBackward( tools::Long & rScrY, tools::Long 
nEndPixels,
                                     SCROW & rPosY, SCROW nStartRow, double 
nPPTY,
                                     const ScDocument * pDoc, SCTAB nTabNo );
+
+    void setupSizeDeviceProviderForColWidth(ScSizeDeviceProvider& rProv, 
Fraction& rZoomX, Fraction& rZoomY, double& rPPTX, double &rPPTY);
 };
 
 inline tools::Long ScViewData::ToPixel( sal_uInt16 nTwips, double nFactor )
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index a2a6667b8f27..7a69d5d82af9 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -2390,7 +2390,7 @@ void ScTabView::UpdateFormulas(SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol,
 //  PaintArea - repaint block
 
 void ScTabView::PaintArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, 
SCROW nEndRow,
-                            ScUpdateMode eMode, tools::Long 
nMaxWidthAffectedHint )
+                            ScUpdateMode eMode, tools::Long 
nMaxWidthAffectedHintTwip )
 {
     SCCOL nCol1;
     SCROW nRow1;
@@ -2468,8 +2468,10 @@ void ScTabView::PaintArea( SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol, SCRO
 
         if ( eMode == ScUpdateMode::All )
         {
-            if (nMaxWidthAffectedHint != -1)
+            if (nMaxWidthAffectedHintTwip != -1)
             {
+                tools::Long nMaxWidthAffectedHint = 
ScViewData::ToPixel(nMaxWidthAffectedHintTwip, aViewData.GetPPTX());
+
                 // If we know the max text width affected then just invalidate
                 // the max of the cell width and hint of affected cell width
                 // (where affected with is in terms of max width of optimal 
cell
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 289776006284..30c5e0079ea5 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -1268,7 +1268,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, 
ScDocument* pClipDoc,
     const bool bSingleCellBefore = nStartCol == nEndCol &&
                                    nStartRow == nEndRow &&
                                    nStartTab == nEndTab;
-    tools::Long nBeforeHint(bSingleCellBefore ? 
pDocSh->GetPixelWidthHint(ScAddress(nStartCol, nStartRow, nStartTab)) : -1);
+    tools::Long nBeforeHint(bSingleCellBefore ? 
pDocSh->GetTwipWidthHint(ScAddress(nStartCol, nStartRow, nStartTab)) : -1);
 
     sal_uInt16 nExtFlags = 0;
     pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab,
@@ -1452,7 +1452,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, 
ScDocument* pClipDoc,
                                   nStartTab == nEndTab;
     if (bSingleCellBefore && bSingleCellAfter)
     {
-        tools::Long nAfterHint(pDocSh->GetPixelWidthHint(ScAddress(nStartCol, 
nStartRow, nStartTab)));
+        tools::Long nAfterHint(pDocSh->GetTwipWidthHint(ScAddress(nStartCol, 
nStartRow, nStartTab)));
         nMaxWidthAffectedHint = std::max(nBeforeHint, nAfterHint);
     }
 
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index d551f5af7b29..21c2a9c3d44f 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -308,24 +308,34 @@ void ScViewFunc::DoAutoAttributes( SCCOL nCol, SCROW 
nRow, SCTAB nTab,
 
 //      additional routines
 
+void ScViewData::setupSizeDeviceProviderForColWidth(ScSizeDeviceProvider& 
rProv, Fraction& rZoomX, Fraction& rZoomY, double& rPPTX, double &rPPTY)
+{
+    if (rProv.IsPrinter())
+    {
+        rPPTX = rProv.GetPPTX();
+        rPPTY = rProv.GetPPTY();
+        rZoomX = rZoomY = Fraction(1, 1);
+    }
+    else
+    {
+        rPPTX = GetPPTX();
+        rPPTY = GetPPTY();
+        rZoomX = GetZoomX();
+        rZoomY = GetZoomY();
+    }
+}
+
 sal_uInt16 ScViewFunc::GetOptimalColWidth( SCCOL nCol, SCTAB nTab, bool 
bFormula )
 {
     ScDocShell* pDocSh = GetViewData().GetDocShell();
     ScDocument& rDoc = pDocSh->GetDocument();
     ScMarkData& rMark = GetViewData().GetMarkData();
 
-    double nPPTX = GetViewData().GetPPTX();
-    double nPPTY = GetViewData().GetPPTY();
-    Fraction aZoomX = GetViewData().GetZoomX();
-    Fraction aZoomY = GetViewData().GetZoomY();
-
     ScSizeDeviceProvider aProv(pDocSh);
-    if (aProv.IsPrinter())
-    {
-        nPPTX = aProv.GetPPTX();
-        nPPTY = aProv.GetPPTY();
-        aZoomX = aZoomY = Fraction( 1, 1 );
-    }
+
+    Fraction aZoomX, aZoomY;
+    double nPPTX, nPPTY;
+    GetViewData().setupSizeDeviceProviderForColWidth(aProv, aZoomX, aZoomY, 
nPPTX, nPPTY);
 
     sal_uInt16 nTwips = rDoc.GetOptimalColWidth( nCol, nTab, aProv.GetDevice(),
                                 nPPTX, nPPTY, aZoomX, aZoomY, bFormula, &rMark 
);
commit 1f9d8733aef959641e1b2b081c13e97fd8be09bf
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Feb 13 10:39:04 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Feb 13 15:09:04 2024 +0100

    ofz: scaling by 0 is an error for cairo rendering
    
    which leads to leaks as cairo doesn't do anything one entering
    an error state
    
    Change-Id: I8d0f7bcb9c705bb1c2c63b2bbbccdba788113df8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163295
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/vcl/source/gdi/TypeSerializer.cxx 
b/vcl/source/gdi/TypeSerializer.cxx
index 68e072892183..c4fd54c14dba 100644
--- a/vcl/source/gdi/TypeSerializer.cxx
+++ b/vcl/source/gdi/TypeSerializer.cxx
@@ -439,7 +439,7 @@ static bool UselessScaleForMapMode(const Fraction& rScale)
     // cannot be expressed as an int
     if (rScale.GetNumerator() == std::numeric_limits<sal_Int32>::min())
         return true;
-    if (static_cast<double>(rScale) < 0.0)
+    if (static_cast<double>(rScale) <= 0.0)
         return true;
     return false;
 }

Reply via email to