[Libreoffice-commits] core.git: sc/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sun Feb 21 14:02:34 UTC 2021


 sc/source/ui/app/transobj.cxx    |    9 +++++----
 sc/source/ui/docshell/docsh2.cxx |    7 +++++--
 sc/source/ui/docshell/docsh3.cxx |    8 ++++----
 3 files changed, 14 insertions(+), 10 deletions(-)

New commits:
commit 6dccc6b54e4bb13f765d494bcdcdd782fa11fe38
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sun Feb 21 12:03:49 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Feb 21 15:01:50 2021 +0100

    Some more unit conversion unification
    
    Change-Id: Id000613426eb5a0159f44419446cad1f3d7f1845
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111282
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx
index b83a085d5c08..ad6e01df42e1 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -23,6 +23,7 @@
 #include <com/sun/star/uno/Sequence.hxx>
 #include <com/sun/star/embed/XTransactedObject.hpp>
 
+#include <o3tl/unit_conversion.hxx>
 #include <osl/diagnose.h>
 #include <unotools/tempfile.hxx>
 #include <unotools/ucbstreamhelper.hxx>
@@ -769,8 +770,8 @@ void ScTransferObj::InitDocShell(bool bLimitToPageSize)
     for (nCol=0; nCol<nStartX; nCol++)
         nPosX += rDestDoc.GetColWidth( nCol, 0 );
     nPosY += rDestDoc.GetRowHeight( 0, nStartY-1, 0 );
-    nPosX = static_cast<tools::Long>( nPosX * HMM_PER_TWIPS );
-    nPosY = static_cast<tools::Long>( nPosY * HMM_PER_TWIPS );
+    nPosX = o3tl::convert(nPosX, o3tl::Length::twip, o3tl::Length::mm100);
+    nPosY = o3tl::convert(nPosY, o3tl::Length::twip, o3tl::Length::mm100);
 
     aPaperSize.setWidth( aPaperSize.Width() * 2 );       // limit OLE object to double of page size
     aPaperSize.setHeight( aPaperSize.Height() * 2 );
@@ -791,8 +792,8 @@ void ScTransferObj::InitDocShell(bool bLimitToPageSize)
             break;
         nSizeY += nAdd;
     }
-    nSizeX = static_cast<tools::Long>( nSizeX * HMM_PER_TWIPS );
-    nSizeY = static_cast<tools::Long>( nSizeY * HMM_PER_TWIPS );
+    nSizeX = o3tl::convert(nSizeX, o3tl::Length::twip, o3tl::Length::mm100);
+    nSizeY = o3tl::convert(nSizeY, o3tl::Length::twip, o3tl::Length::mm100);
 
 //      pDocSh->SetVisAreaSize( Size(nSizeX,nSizeY) );
 
diff --git a/sc/source/ui/docshell/docsh2.cxx b/sc/source/ui/docshell/docsh2.cxx
index 0c8da05362b0..e02b815d2181 100644
--- a/sc/source/ui/docshell/docsh2.cxx
+++ b/sc/source/ui/docshell/docsh2.cxx
@@ -26,6 +26,7 @@
 #include <config_folders.h>
 #include <unotools/configmgr.hxx>
 #include <comphelper/processfactory.hxx>
+#include <o3tl/unit_conversion.hxx>
 
 #include <drwlayer.hxx>
 #include <stlpool.hxx>
@@ -46,8 +47,10 @@ bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
     //  Additional tables are created by the first View, if bIsEmpty is still sal_True
     if( bRet )
     {
-        Size aSize( tools::Long( STD_COL_WIDTH           * HMM_PER_TWIPS * OLE_STD_CELLS_X ),
-                    static_cast<tools::Long>( ScGlobal::nStdRowHeight * HMM_PER_TWIPS * OLE_STD_CELLS_Y ) );
+        Size aSize(
+            o3tl::convert(STD_COL_WIDTH * OLE_STD_CELLS_X, o3tl::Length::twip, o3tl::Length::mm100),
+            o3tl::convert(ScGlobal::nStdRowHeight * OLE_STD_CELLS_Y, o3tl::Length::twip,
+                          o3tl::Length::mm100));
         // Also adjust start here
         SetVisAreaOrSize( tools::Rectangle( Point(), aSize ) );
     }
diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx
index a31d73e5802c..37e1bc773859 100644
--- a/sc/source/ui/docshell/docsh3.cxx
+++ b/sc/source/ui/docshell/docsh3.cxx
@@ -25,6 +25,7 @@
 #include <editeng/flstitem.hxx>
 #include <editeng/paperinf.hxx>
 #include <editeng/sizeitem.hxx>
+#include <o3tl/unit_conversion.hxx>
 #include <officecfg/Office/Common.hxx>
 #include <sal/log.hxx>
 #include <sfx2/viewfrm.hxx>
@@ -367,7 +368,6 @@ void ScDocShell::CalcOutputFactor()
     OUString aTestString(
             "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789");
     tools::Long nPrinterWidth = 0;
-    tools::Long nWindowWidth = 0;
     const ScPatternAttr* pPattern = &m_aDocument.GetPool()->GetDefaultItem(ATTR_PATTERN);
 
     vcl::Font aDefFont;
@@ -386,11 +386,11 @@ void ScDocShell::CalcOutputFactor()
     pVirtWindow->SetMapMode(MapMode(MapUnit::MapPixel));
     pPattern->GetFont(aDefFont, SC_AUTOCOL_BLACK, pVirtWindow);    // font color doesn't matter here
     pVirtWindow->SetFont(aDefFont);
-    nWindowWidth = pVirtWindow->GetTextWidth(aTestString);
-    nWindowWidth = static_cast<tools::Long>( nWindowWidth / ScGlobal::nScreenPPTX * HMM_PER_TWIPS );
+    double nWindowWidth = pVirtWindow->GetTextWidth(aTestString) / ScGlobal::nScreenPPTX;
+    nWindowWidth = o3tl::convert(nWindowWidth, o3tl::Length::twip, o3tl::Length::mm100);
 
     if (nPrinterWidth && nWindowWidth)
-        m_nPrtToScreenFactor = nPrinterWidth / static_cast<double>(nWindowWidth);
+        m_nPrtToScreenFactor = nPrinterWidth / nWindowWidth;
     else
     {
         OSL_FAIL("GetTextSize returns 0 ??");


More information about the Libreoffice-commits mailing list