Rebased ref, commits from common ancestor:
commit 1d9d36f30061f58a24a8b5815078796623b253f1
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Jun 10 11:16:32 2025 +0200
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Tue Jun 10 11:32:28 2025 +0200

    sw: convert SwTwips to use gfx::Length to store values in EMU
    
    Change-Id: Idcd3da864974738108c5031a46844104780e5885

diff --git a/sw/inc/EnhancedPDFExportHelper.hxx 
b/sw/inc/EnhancedPDFExportHelper.hxx
index 333348c4e5ab..24abd4bcf7a3 100644
--- a/sw/inc/EnhancedPDFExportHelper.hxx
+++ b/sw/inc/EnhancedPDFExportHelper.hxx
@@ -127,7 +127,7 @@ struct lt_TableColumn
 {
     bool operator()( tools::Long nVal1, tools::Long nVal2 ) const
     {
-        return nVal1 + ( MINLAY - 1 ) < nVal2;
+        return nVal1 + ( MINLAY - 1_twip ) < nVal2;
     }
 };
 
diff --git a/sw/inc/SwTwips.hxx b/sw/inc/SwTwips.hxx
new file mode 100644
index 000000000000..a386a1c2baf0
--- /dev/null
+++ b/sw/inc/SwTwips.hxx
@@ -0,0 +1,135 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <basegfx/units/Length.hxx>
+#include <o3tl/concepts.hxx>
+
+class SW_DLLPUBLIC SwTwips
+{
+private:
+    gfx::Length maValue;
+
+public:
+    constexpr SwTwips() = default;
+
+    constexpr SwTwips(tools::Long aInput)
+        : maValue(gfx::Length::from(gfx::LengthUnit::twip, aInput))
+    {
+    }
+
+    constexpr SwTwips(gfx::Length const& rLength)
+        : maValue(rLength)
+    {
+    }
+
+    operator tools::Long() const { return std::lround(maValue.as_twip()); }
+
+    constexpr SwTwips& operator+=(tools::Long const& value)
+    {
+        gfx::Length nLength = gfx::Length::from(gfx::LengthUnit::twip, value);
+        maValue += nLength;
+        return *this;
+    }
+
+    constexpr SwTwips& operator++()
+    {
+        maValue += 1_twip;
+        return *this;
+    }
+
+    constexpr SwTwips& operator-=(tools::Long const& value)
+    {
+        gfx::Length nLength = gfx::Length::from(gfx::LengthUnit::twip, value);
+        maValue -= nLength;
+        return *this;
+    }
+
+    template <typename INPUT> constexpr SwTwips& operator/=(INPUT const& value)
+    {
+        maValue /= value;
+        return *this;
+    }
+
+    template <typename INPUT> constexpr SwTwips& operator*=(INPUT const& value)
+    {
+        maValue *= value;
+        return *this;
+    }
+
+    constexpr SwTwips& operator-()
+    {
+        maValue = -maValue;
+        return *this;
+    }
+
+    constexpr gfx::Length const& data() const { return maValue; }
+};
+
+inline SwTwips operator+(const SwTwips& rA, const SwTwips& rB)
+{
+    SwTwips aNew(rA.data() + rB.data());
+    return aNew;
+}
+
+inline SwTwips operator-(const SwTwips& rA, const SwTwips& rB)
+{
+    SwTwips aNew(rA.data() - rB.data());
+    return aNew;
+}
+
+inline SwTwips operator+(const SwTwips& rA, const gfx::Length& rB)
+{
+    SwTwips aNew(rA.data() + rB);
+    return aNew;
+}
+
+inline SwTwips operator-(const SwTwips& rA, const gfx::Length& rB)
+{
+    SwTwips aNew(rA.data() - rB);
+    return aNew;
+}
+
+inline SwTwips operator+(const SwTwips& rA, const tools::Long& rB)
+{
+    SwTwips aNew(rA.data() + SwTwips(rB).data());
+    return aNew;
+}
+
+inline SwTwips operator-(const SwTwips& rA, const tools::Long& rB)
+{
+    SwTwips aNew(rA.data() - SwTwips(rB).data());
+    return aNew;
+}
+
+inline SwTwips operator+(const tools::Long& rA, const SwTwips& rB)
+{
+    SwTwips aNew(SwTwips(rA).data() + rB.data());
+    return aNew;
+}
+
+inline SwTwips operator-(const tools::Long& rA, const SwTwips& rB)
+{
+    SwTwips aNew(SwTwips(rA).data() - rB.data());
+    return aNew;
+}
+
+namespace std
+{
+template <> struct hash<SwTwips>
+{
+    std::size_t operator()(SwTwips const& rLength) const
+    {
+        return std::hash<sal_Int64>()(rLength.data().data());
+    }
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/inc/swtypes.hxx b/sw/inc/swtypes.hxx
index 88a33b983ec4..a70927e3f76e 100644
--- a/sw/inc/swtypes.hxx
+++ b/sw/inc/swtypes.hxx
@@ -16,8 +16,10 @@
  *   except in compliance with the License. You may obtain a copy of
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
+
 #ifndef INCLUDED_SW_INC_SWTYPES_HXX
 #define INCLUDED_SW_INC_SWTYPES_HXX
+
 #include <rtl/ustring.hxx>
 
 #include <limits.h>
@@ -29,6 +31,7 @@
 #include <i18nlangtag/lang.h>
 #include <vcl/outdev.hxx>
 #include <unotools/resmgr.hxx>
+#include "SwTwips.hxx"
 
 namespace com::sun::star {
     namespace linguistic2{
@@ -48,33 +51,32 @@ class CharClass;
 class CollatorWrapper;
 class LanguageTag;
 
-typedef tools::Long SwTwips;
+//typedef tools::Long SwTwips;
 #define INVALID_TWIPS   LONG_MAX
 #define TWIPS_MAX       (LONG_MAX - 1)
 
 constexpr sal_Int32 COMPLETE_STRING = SAL_MAX_INT32;
 
-constexpr SwTwips cMinHdFtHeight = 56; // ~1mm
+constexpr SwTwips cMinHdFtHeight(1_mm); // ~1mm
 
-#define MINFLY 23   // Minimal size for FlyFrames.
-#define MINLAY 23   // Minimal size for other Frames.
+constexpr SwTwips MINFLY(23_twip);   // Minimal size for FlyFrames.
+constexpr SwTwips MINLAY(23_twip);   // Minimal size for other Frames.
 
 // Default column distance of two text columns corresponds to 0.3 cm.
-constexpr SwTwips DEF_GUTTER_WIDTH = o3tl::toTwips(3, o3tl::Length::mm);
+constexpr SwTwips DEF_GUTTER_WIDTH(3_mm);
 
 // Minimal distance (distance to text) for border attribute
 // in order not to crock up aligned lines.
 // 28 Twips == 0,5mm
-constexpr SwTwips MIN_BORDER_DIST = 28; // ~0.5mm
+constexpr SwTwips MIN_BORDER_DIST(50_hmm); // ~0.5mm
 
 // Minimal document border: 20mm.
-constexpr tools::Long lMinBorderInMm(20);
-constexpr SwTwips lMinBorder = o3tl::toTwips(lMinBorderInMm, o3tl::Length::mm);
+constexpr SwTwips lMinBorder(20_mm);
 
 // Margin left and above document.
 // Half of it is gap between the pages.
 //TODO: Replace with SwViewOption::defDocumentBorder
-constexpr SwTwips DOCUMENTBORDER = 284; // ~5mm
+constexpr SwTwips DOCUMENTBORDER(5_mm); // ~5mm
 
 // For inserting of captions (what and where to insert).
 // It's here because it is not big enough to justify its own hxx
@@ -93,8 +95,8 @@ constexpr sal_uInt8 MAXLEVEL = 10;
 //  (For more levels the values have to be multiplied with the levels+1;
 //  levels 0 ..4!)
 
-constexpr short lBulletIndent = o3tl::toTwips(25, o3tl::Length::in100); // 
0.25 inch
-constexpr short lBulletFirstLineOffset = -lBulletIndent;
+constexpr SwTwips lBulletIndent(0.25_in); // 0.25 inch
+constexpr short 
lBulletFirstLineOffset(std::round(-lBulletIndent.data().as_twip()));
 constexpr sal_uInt16 lNumberIndent = o3tl::toTwips(25, o3tl::Length::in100); 
// 0.25 inch
 constexpr short lNumberFirstLineOffset = -lNumberIndent;
 constexpr short lOutlineMinTextDistance = o3tl::toTwips(15, 
o3tl::Length::in100); // 0.15 inch = 0.38 cm
diff --git a/sw/source/core/doc/docfly.cxx b/sw/source/core/doc/docfly.cxx
index fdd7d866628b..d28488ad93c5 100644
--- a/sw/source/core/doc/docfly.cxx
+++ b/sw/source/core/doc/docfly.cxx
@@ -383,7 +383,7 @@ sal_Int8 SwDoc::SetFlyFrameAnchor( SwFrameFormat& rFormat, 
SfxItemSet& rSet, boo
                 && text::HoriOrientation::NONE == 
pHoriOrientItem->GetHoriOrient()
                 && aOldH.GetPos() == pHoriOrientItem->GetPos())
             {
-                SwTwips nPos = (RndStdIds::FLY_AS_CHAR == nOld) ? 0 : 
aOldH.GetPos();
+                SwTwips nPos = (RndStdIds::FLY_AS_CHAR == nOld) ? SwTwips(0) : 
aOldH.GetPos();
                 nPos += aOldAnchorPos.getX() - aNewAnchorPos.getX();
 
                 assert(aOldH.GetRelationOrient() != 
pHoriOrientItem->GetRelationOrient());
@@ -416,7 +416,7 @@ sal_Int8 SwDoc::SetFlyFrameAnchor( SwFrameFormat& rFormat, 
SfxItemSet& rSet, boo
                 && text::VertOrientation::NONE == 
pVertOrientItem->GetVertOrient()
                 && aOldV.GetPos() == pVertOrientItem->GetPos())
             {
-                SwTwips nPos = (RndStdIds::FLY_AS_CHAR == nOld) ? 0 : 
aOldV.GetPos();
+                SwTwips nPos = (RndStdIds::FLY_AS_CHAR == nOld) ? SwTwips(0) : 
aOldV.GetPos();
                 nPos += aOldAnchorPos.getY() - aNewAnchorPos.getY();
 
                 assert(aOldV.GetRelationOrient() != 
pVertOrientItem->GetRelationOrient());
diff --git a/sw/source/core/doc/htmltbl.cxx b/sw/source/core/doc/htmltbl.cxx
index 1400028ec9da..d957fb3e76df 100644
--- a/sw/source/core/doc/htmltbl.cxx
+++ b/sw/source/core/doc/htmltbl.cxx
@@ -620,11 +620,11 @@ void SwHTMLTableLayout::AutoLayoutPass1()
                 }
 
                 // Respect minimum width for content
-                if( nMinNoAlignCell < MINLAY )
+                if (nMinNoAlignCell < sal_uLong(MINLAY))
                     nMinNoAlignCell = MINLAY;
-                if( nMaxNoAlignCell < MINLAY )
+                if (nMaxNoAlignCell < sal_uLong(MINLAY))
                     nMaxNoAlignCell = MINLAY;
-                if( nAbsMinNoAlignCell < MINLAY )
+                if (nAbsMinNoAlignCell < sal_uLong(MINLAY))
                     nAbsMinNoAlignCell = MINLAY;
 
                 // Respect the border and distance to the content
@@ -1504,7 +1504,7 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 
nAbsAvail, sal_uInt16 nRelAv
     // to the border width.
     // In the last case we probably exported the table ourselves.
     if( m_nRelLeftFill &&
-        ( m_nWidthSet>0 || nAbsLeftFill<MINLAY+m_nInhLeftBorderWidth ||
+        ( m_nWidthSet>0 || nAbsLeftFill < sal_uInt16(MINLAY) + 
m_nInhLeftBorderWidth ||
           (HasColTags() && nAbsLeftFill < 
nAbsLeftSpace+nParentInhAbsLeftSpace+20) ) )
     {
         SwHTMLTableLayoutColumn *pColumn = GetColumn( 0 );
@@ -1514,7 +1514,7 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 
nAbsAvail, sal_uInt16 nRelAv
         m_nInhAbsLeftSpace = nAbsLeftSpace + nParentInhAbsLeftSpace;
     }
     if( m_nRelRightFill &&
-        ( m_nWidthSet>0 || nAbsRightFill<MINLAY+m_nInhRightBorderWidth ||
+        ( m_nWidthSet>0 || nAbsRightFill < sal_uInt16(MINLAY) + 
m_nInhRightBorderWidth ||
           (HasColTags() && nAbsRightFill < 
nAbsRightSpace+nParentInhAbsRightSpace+20) ) )
     {
         SwHTMLTableLayoutColumn *pColumn = GetColumn( m_nCols-1 );
@@ -1621,7 +1621,7 @@ void SwHTMLTableLayout::SetWidths( bool bCallPass2, 
sal_uInt16 nAbsAvail,
     SwTwips nCalcTabWidth = 0;
     for( const SwTableLine *pLine : m_pSwTable->GetTabLines() )
         lcl_ResizeLine( pLine, &nCalcTabWidth );
-    SAL_WARN_IF( std::abs( m_nRelTabWidth-nCalcTabWidth ) >= COLFUZZY, 
"sw.core",
+    SAL_WARN_IF( std::abs(SwTwips(m_nRelTabWidth) - nCalcTabWidth) >= 
COLFUZZY, "sw.core",
                  "Table width is not equal to the row width" );
 
     // Lock the table format when altering it, or else the box formats
diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx
index 5e321bfe2a9b..8424346eb85b 100644
--- a/sw/source/core/doc/tblrwcl.cxx
+++ b/sw/source/core/doc/tblrwcl.cxx
@@ -62,8 +62,8 @@
 
 using namespace com::sun::star;
 
-#define COLFUZZY 20
-#define ROWFUZZY 10
+constexpr SwTwips COLFUZZY(20);
+constexpr SwTwips ROWFUZZY(10);
 
 #ifdef DBG_UTIL
 #define CHECK_TABLE(t) (t).CheckConsistency();
@@ -754,7 +754,7 @@ void DeleteBox_( SwTable& rTable, SwTableBox* pBox, SwUndo* 
pUndo,
             if( bCalcNewSize )
             {
                 SwFormatFrameSize aNew( pBox->GetFrameFormat()->GetFrameSize() 
);
-                aNew.SetWidth( aNew.GetWidth() + nBoxSz );
+                aNew.SetWidth(SwTwips(aNew.GetWidth()) + nBoxSz);
                 if( pShareFormats )
                     pShareFormats->SetSize( *pBox, aNew );
                 else
@@ -2382,16 +2382,16 @@ static bool lcl_SetSelBoxWidth( SwTableLine* pLine, 
CR_SetBoxWidth& rParam,
 
             // Collect all "ContentBoxes"
             bGreaterBox = (TableChgMode::FixedWidthChangeAbs != rParam.nMode)
-                       && ((nDist + (rParam.bLeft ? 0 : nWidth)) >= 
rParam.nSide);
+                       && ((nDist + (rParam.bLeft ? SwTwips(0) : nWidth)) >= 
rParam.nSide);
             if (bGreaterBox
                 || (!rParam.bBigger
-                    && (std::abs(nDist + ((rParam.nMode != 
TableChgMode::FixedWidthChangeAbs && rParam.bLeft) ? 0 : nWidth) - 
rParam.nSide) < COLFUZZY)))
+                    && (std::abs(nDist + ((rParam.nMode != 
TableChgMode::FixedWidthChangeAbs && rParam.bLeft) ? SwTwips(0) : nWidth) - 
rParam.nSide) < COLFUZZY)))
             {
                 SwTwips nLowerDiff;
                 if( bGreaterBox && TableChgMode::FixedWidthChangeProp == 
rParam.nMode )
                 {
                     // The "other Boxes" have been adapted, so change by this 
value
-                    nLowerDiff = (nDist + ( rParam.bLeft ? 0 : nWidth ) ) - 
rParam.nSide;
+                    nLowerDiff = (nDist + ( rParam.bLeft ? SwTwips(0) : nWidth 
) ) - rParam.nSide;
                     nLowerDiff *= rParam.nDiff;
                     nLowerDiff /= rParam.nMaxSize;
                     nLowerDiff = rParam.nDiff - nLowerDiff;
@@ -2418,8 +2418,8 @@ static bool lcl_SetSelBoxWidth( SwTableLine* pLine, 
CR_SetBoxWidth& rParam,
 
             if( nLowerDiff ||
                  (bGreaterBox = !nOldLower && 
TableChgMode::FixedWidthChangeAbs != rParam.nMode &&
-                    ( nDist + ( rParam.bLeft ? 0 : nWidth ) ) >= rParam.nSide) 
||
-                ( std::abs( nDist + ( (rParam.nMode != 
TableChgMode::FixedWidthChangeAbs && rParam.bLeft) ? 0 : nWidth )
+                    ( nDist + ( rParam.bLeft ? SwTwips(0) : nWidth ) ) >= 
rParam.nSide) ||
+                ( std::abs( nDist + ( (rParam.nMode != 
TableChgMode::FixedWidthChangeAbs && rParam.bLeft) ? SwTwips(0) : nWidth )
                             - rParam.nSide ) < COLFUZZY ))
             {
                 // This column contains the Cursor - so decrease/increase
@@ -2430,7 +2430,7 @@ static bool lcl_SetSelBoxWidth( SwTableLine* pLine, 
CR_SetBoxWidth& rParam,
                     if( bGreaterBox && TableChgMode::FixedWidthChangeProp == 
rParam.nMode )
                     {
                         // The "other Boxes" have been adapted, so change by 
this value
-                        nLowerDiff = (nDist + ( rParam.bLeft ? 0 : nWidth ) ) 
- rParam.nSide;
+                        nLowerDiff = (nDist + ( rParam.bLeft ? SwTwips(0) : 
nWidth ) ) - rParam.nSide;
                         nLowerDiff *= rParam.nDiff;
                         nLowerDiff /= rParam.nMaxSize;
                         nLowerDiff = rParam.nDiff - nLowerDiff;
@@ -2630,9 +2630,9 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, 
TableChgWidthHeightType eTyp
     // Only needed for manipulating the width
     const SwTwips nDist = ::lcl_GetDistance( &rCurrentBox, bLeft );
     SwTwips nDistStt = 0;
-    CR_SetBoxWidth aParam( eType, nRelDiff, nDist,
-                            bLeft ? nDist : rSz.GetWidth() - nDist,
-                            
const_cast<SwTableNode*>(rCurrentBox.GetSttNd()->FindTableNode()) );
+    SwTwips nMax = bLeft ? nDist : SwTwips(rSz.GetWidth()) - nDist;
+    CR_SetBoxWidth aParam(eType, nRelDiff, nDist, nMax,
+                            
const_cast<SwTableNode*>(rCurrentBox.GetSttNd()->FindTableNode()));
     bBigger = aParam.bBigger;
 
     FN_lcl_SetBoxWidth fnSelBox, fnOtherBox;
@@ -2653,7 +2653,7 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, 
TableChgWidthHeightType eTyp
                     !rSz.GetWidthPercent() )
                 {
                     // silence -Wsign-compare on Android with the static cast
-                    bRet = rSz.GetWidth() < static_cast<unsigned 
short>(USHRT_MAX) - nRelDiff;
+                    bRet = rSz.GetWidth() < static_cast<sal_uInt16>(USHRT_MAX) 
- sal_uInt16(nRelDiff);
                     bChgLRSpace = bLeft ? rLR.ResolveLeft({}) >= nAbsDiff
                                         : rLR.ResolveRight({}) >= nAbsDiff;
                 }
@@ -2700,7 +2700,7 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, 
TableChgWidthHeightType eTyp
                 {
                     // If the Table does not have any room to grow, we need to 
create some!
                     // silence -Wsign-compare on Android with the static cast
-                    if( aSz.GetWidth() + nRelDiff > static_cast<unsigned 
short>(USHRT_MAX) )
+                    if (SwTwips(aSz.GetWidth()) + nRelDiff > 
static_cast<unsigned short>(USHRT_MAX) )
                     {
                         // Break down to USHRT_MAX / 2
                         CR_SetBoxWidth aTmpPara( 
TableChgWidthHeightType::ColLeft, aSz.GetWidth() / 2,
@@ -2715,16 +2715,16 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, 
TableChgWidthHeightType eTyp
 
                     if( bLeft )
                         aLR.SetLeft(
-                            
SvxIndentValue::twips(sal_uInt16(aLR.ResolveLeft({}) - nAbsDiff)));
+                            SvxIndentValue::twips(SwTwips(aLR.ResolveLeft({})) 
- nAbsDiff));
                     else
                         aLR.SetRight(
-                            
SvxIndentValue::twips(sal_uInt16(aLR.ResolveRight({}) - nAbsDiff)));
+                            
SvxIndentValue::twips(SwTwips(aLR.ResolveRight({})) - nAbsDiff));
                 }
                 else if( bLeft )
-                    
aLR.SetLeft(SvxIndentValue::twips(sal_uInt16(aLR.ResolveLeft({}) + nAbsDiff)));
+                    
aLR.SetLeft(SvxIndentValue::twips(SwTwips(aLR.ResolveLeft({})) + nAbsDiff));
                 else
                     aLR.SetRight(
-                        SvxIndentValue::twips(sal_uInt16(aLR.ResolveRight({}) 
+ nAbsDiff)));
+                        SvxIndentValue::twips(SwTwips(aLR.ResolveRight({})) + 
nAbsDiff));
 
                 if( bChgLRSpace )
                     GetFrameFormat()->SetFormatAttr( aLR );
@@ -2758,9 +2758,9 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, 
TableChgWidthHeightType eTyp
                 }
 
                 if( bBigger )
-                    aSz.SetWidth( aSz.GetWidth() + nRelDiff );
+                    aSz.SetWidth(SwTwips(aSz.GetWidth()) + nRelDiff);
                 else
-                    aSz.SetWidth( aSz.GetWidth() - nRelDiff );
+                    aSz.SetWidth(SwTwips(aSz.GetWidth()) - nRelDiff);
 
                 if (rSz.GetWidthPercent())
                     aSz.SetWidthPercent(static_cast<sal_uInt8>(
@@ -2789,7 +2789,7 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, 
TableChgWidthHeightType eTyp
                 }
             }
         }
-        else if( bLeft ? nDist != 0 : std::abs( rSz.GetWidth() - nDist ) > 
COLFUZZY )
+        else if( bLeft ? nDist != 0 : std::abs(SwTwips(rSz.GetWidth()) - 
nDist) > COLFUZZY )
         {
             bRet = true;
             if( bLeft && TableChgMode::FixedWidthChangeAbs == m_eTableChgMode )
@@ -2867,7 +2867,7 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, 
TableChgWidthHeightType eTyp
             m_eTableChgMode = eOld;
             return bRet;
         }
-        else if( bLeft ? nDist != 0 : (rSz.GetWidth() - nDist) > COLFUZZY )
+        else if( bLeft ? nDist != 0 : (SwTwips(rSz.GetWidth()) - nDist) > 
COLFUZZY )
         {
             if( bLeft && TableChgMode::FixedWidthChangeAbs == m_eTableChgMode )
                 aParam.bBigger = !bBigger;
@@ -2893,8 +2893,7 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, 
TableChgWidthHeightType eTyp
                 if( bLeft )
                     aParam.nMaxSize = aParam.nSide;
                 else
-                    aParam.nMaxSize = pLine->GetUpper()->GetFrameFormat()->
-                                    GetFrameSize().GetWidth() - aParam.nSide;
+                    aParam.nMaxSize = 
SwTwips(pLine->GetUpper()->GetFrameFormat()->GetFrameSize().GetWidth()) - 
aParam.nSide;
             }
 
             // First, see if there is enough room at all
diff --git a/sw/source/core/doc/textboxhelper.cxx 
b/sw/source/core/doc/textboxhelper.cxx
index 0d45170fd621..0eb5f0c82072 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -1139,10 +1139,10 @@ void SwTextBoxHelper::syncFlyFrameAttr(SwFrameFormat& 
rShape, SfxItemSet const&
                     if (!bInlineAnchored)
                     {
                         aVertOrient.SetPos(
-                            (pObj ? pObj->GetRelativePos().getX() : 
aVertOrient.GetPos())
+                            (pObj ? SwTwips(pObj->GetRelativePos().getX()) : 
aVertOrient.GetPos())
                             + aRect.Top());
                         aHoriOrient.SetPos(
-                            (pObj ? pObj->GetRelativePos().getY() : 
aHoriOrient.GetPos())
+                            (pObj ? SwTwips(pObj->GetRelativePos().getY()) : 
aHoriOrient.GetPos())
                             + aRect.Left());
 
                         aTextBoxSet.Put(aVertOrient);
@@ -1397,22 +1397,24 @@ bool 
SwTextBoxHelper::doTextBoxPositioning(SwFrameFormat* pShape, SdrObject* pOb
                 // case 1: The textbox should be in that position where the 
shape is.
                 // case 2: The shape has negative offset so that have to be 
subtracted
                 // case 3: The shape and its parent shape also has negative 
offset, so subtract
-                aNewVOri.SetPos(
-                    ((pObj->GetRelativePos().getY()) > 0
-                         ? (pShape->GetVertOrient().GetPos() > 0
-                                ? pObj->GetRelativePos().getY()
-                                : pObj->GetRelativePos().getY() - 
pShape->GetVertOrient().GetPos())
-                         : (pShape->GetVertOrient().GetPos() > 0
-                                ? 0 // Is this can be a variation?
-                                : pObj->GetRelativePos().getY() - 
pShape->GetVertOrient().GetPos()))
-                    + aRect.Top());
+                aNewVOri.SetPos(((pObj->GetRelativePos().getY()) > 0
+                                     ? (pShape->GetVertOrient().GetPos() > 0
+                                            ? 
SwTwips(pObj->GetRelativePos().getY())
+                                            : 
SwTwips(pObj->GetRelativePos().getY())
+                                                  - 
pShape->GetVertOrient().GetPos())
+                                     : (pShape->GetVertOrient().GetPos() > 0
+                                            ? SwTwips(0) // Is this can be a 
variation?
+                                            : 
SwTwips(pObj->GetRelativePos().getY())
+                                                  - 
pShape->GetVertOrient().GetPos()))
+                                + aRect.Top());
             }
             else
             {
                 // Simple textboxes: vertical position equals to the vertical 
offset of the shape
-                aNewVOri.SetPos(
-                    ((pShape->GetVertOrient().GetPos()) > 0 ? 
pShape->GetVertOrient().GetPos() : 0)
-                    + aRect.Top());
+                aNewVOri.SetPos(((pShape->GetVertOrient().GetPos()) > 0
+                                     ? pShape->GetVertOrient().GetPos()
+                                     : SwTwips(0))
+                                + aRect.Top());
             }
 
             // Special cases when the shape is aligned to the line
@@ -1467,11 +1469,11 @@ bool 
SwTextBoxHelper::doTextBoxPositioning(SwFrameFormat* pShape, SdrObject* pOb
                 aNewHOri.SetHoriOrient(text::HoriOrientation::NONE);
 
             aNewHOri.SetPos(
-                (bIsGroupObj && pObj ? pObj->GetRelativePos().getX() : 
aNewHOri.GetPos())
+                (bIsGroupObj && pObj ? SwTwips(pObj->GetRelativePos().getX()) 
: aNewHOri.GetPos())
                 + aRect.Left());
             SwFormatVertOrient aNewVOri(pShape->GetVertOrient());
             aNewVOri.SetPos(
-                (bIsGroupObj && pObj ? pObj->GetRelativePos().getY() : 
aNewVOri.GetPos())
+                (bIsGroupObj && pObj ? SwTwips(pObj->GetRelativePos().getY()) 
: aNewVOri.GetPos())
                 + aRect.Top());
 
             // Get the distance of the child shape inside its parent
diff --git a/sw/source/core/docnode/ndtbl1.cxx 
b/sw/source/core/docnode/ndtbl1.cxx
index c94d40fb8e5b..e67ae75541dc 100644
--- a/sw/source/core/docnode/ndtbl1.cxx
+++ b/sw/source/core/docnode/ndtbl1.cxx
@@ -1428,9 +1428,9 @@ static sal_uInt16 lcl_CalcCellFit( const SwLayoutFrame 
*pCell )
         // pFrame does not necessarily have to be a SwTextFrame!
         const SwTwips nCalcFitToContent = pFrame->IsTextFrame() ?
                                           
const_cast<SwTextFrame*>(static_cast<const 
SwTextFrame*>(pFrame))->CalcFitToContent() :
-                                          
aRectFnSet.GetWidth(pFrame->getFramePrintArea());
+                                          
SwTwips(aRectFnSet.GetWidth(pFrame->getFramePrintArea()));
 
-        nRet = std::max( nRet, nCalcFitToContent + nAdd );
+        nRet = std::max( nRet, SwTwips(nCalcFitToContent + nAdd));
         pFrame = pFrame->GetNext();
     }
     // Surrounding border as well as left and Right Border also need to be 
respected
@@ -1462,7 +1462,7 @@ static void lcl_CalcSubColValues( std::vector<sal_uInt16> 
&rToFill, const SwTabC
 {
     const sal_uInt16 nWish = bWishValues ?
                     ::lcl_CalcCellFit( pCell ) :
-                    MINLAY + sal_uInt16(pCell->getFrameArea().Width() - 
pCell->getFramePrintArea().Width());
+                    sal_uInt16(MINLAY) + 
sal_uInt16(pCell->getFrameArea().Width() - pCell->getFramePrintArea().Width());
 
     SwRectFnSet aRectFnSet(pTab);
 
@@ -1584,7 +1584,7 @@ static void lcl_CalcColValues( std::vector<sal_uInt16> 
&rToFill, const SwTabCols
                                 nFit = nWish;
                         }
                         else
-                        {   const sal_uInt16 nMin = MINLAY + 
sal_uInt16(pCell->getFrameArea().Width() -
+                        {   const sal_uInt16 nMin = sal_uInt16(MINLAY) + 
sal_uInt16(pCell->getFrameArea().Width() -
                                                                 
pCell->getFramePrintArea().Width());
                             if ( !nFit || nMin < nFit )
                                 nFit = nMin;
diff --git a/sw/source/core/draw/dflyobj.cxx b/sw/source/core/draw/dflyobj.cxx
index d650b135d247..0656e12c1be8 100644
--- a/sw/source/core/draw/dflyobj.cxx
+++ b/sw/source/core/draw/dflyobj.cxx
@@ -1066,9 +1066,9 @@ void SwVirtFlyDrawObj::NbcResize(const Point& rRef, const 
Fraction& xFact, const
             {
                 for ( const auto &rC : rCol.GetColumns() )
                 {
-                    nMin += rC.GetLeft() + rC.GetRight() + MINFLY;
+                    nMin += rC.GetLeft() + rC.GetRight() + tools::Long(MINFLY);
                 }
-                nMin -= MINFLY;
+                nMin -= tools::Long(MINFLY);
             }
             aSz.setWidth( std::max( aSz.Width(), nMin ) );
         }
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 8b5dd3c05224..be149e3213c1 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -1563,11 +1563,11 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, 
sal_uInt16 nDigitLevel )
                         }
                     }
 
-                    sal_Int32 nAbsPos = lBulletIndent;
+                    SwTwips nAbsPos = lBulletIndent;
                     SwTwips nSpaceSteps = nLvl
-                                            ? nLeftTextPos / nLvl
+                                            ? SwTwips(nLeftTextPos / nLvl)
                                             : lBulletIndent;
-                    for( sal_uInt8 n = 0; n < MAXLEVEL; ++n, nAbsPos = nAbsPos 
+ nSpaceSteps )
+                    for (sal_uInt8 n = 0; n < MAXLEVEL; ++n, nAbsPos = nAbsPos 
+ nSpaceSteps)
                     {
                         SwNumFormat aFormat( aRule.Get( n ) );
                         aFormat.SetBulletFont( pBullFnt );
@@ -1576,7 +1576,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 
nDigitLevel )
                         // #i93908# clear suffix for bullet lists
                         aFormat.SetListFormat(u""_ustr, u""_ustr, n);
                         aFormat.SetFirstLineOffset( lBulletFirstLineOffset );
-                        aFormat.SetAbsLSpace( nAbsPos );
+                        aFormat.SetAbsLSpace(sal_Int32(nAbsPos));
                         if( !aFormat.GetCharFormat() )
                             aFormat.SetCharFormat( pCFormat );
                         if( bRTL )
@@ -1681,7 +1681,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 
nDigitLevel )
                         aFormat.SetIncludeUpperLevels( MAXLEVEL );
                         if( bDefStep )
                             aFormat.SetAbsLSpace( nLeftTextPos +
-                                
SwNumRule::GetNumIndent(static_cast<sal_uInt8>(n-nLvl)));
+                                
SwTwips(SwNumRule::GetNumIndent(static_cast<sal_uInt8>(n-nLvl))));
                         else
                             aFormat.SetAbsLSpace( nSpaceSteps * n
                                                 + lNumberIndent );
diff --git a/sw/source/core/frmedt/fews.cxx b/sw/source/core/frmedt/fews.cxx
index 90d93f5a1004..35fd434d8035 100644
--- a/sw/source/core/frmedt/fews.cxx
+++ b/sw/source/core/frmedt/fews.cxx
@@ -1123,7 +1123,7 @@ void SwFEShell::CalcBoundRect( SwRect& _orRect,
 
         const SwTwips nBaseOfstForFly = ( pFrame->IsTextFrame() && pFly ) ?
                                         static_cast<const 
SwTextFrame*>(pFrame)->GetBaseOffsetForFly( !bWrapThrough ) :
-                                         0;
+                                        SwTwips(0);
         if( aRectFnSet.IsVert() || aRectFnSet.IsVertL2R() )
         {
             bVertic = aRectFnSet.IsVert();
@@ -1141,7 +1141,7 @@ void SwFEShell::CalcBoundRect( SwRect& _orRect,
                 case text::RelOrientation::PRINT_AREA:
                 {
                     aPos += aRectFnSet.GetPos(pFrame->getFramePrintArea());
-                    aPos.setY(aPos.getY() + nBaseOfstForFly);
+                    aPos.setY(SwTwips(aPos.getY()) + nBaseOfstForFly);
                     break;
                 }
                 case text::RelOrientation::PAGE_RIGHT:
@@ -1162,7 +1162,7 @@ void SwFEShell::CalcBoundRect( SwRect& _orRect,
                 }
                 case text::RelOrientation::FRAME:
                 {
-                    aPos.setY(aPos.getY() + nBaseOfstForFly);
+                    aPos.setY(SwTwips(aPos.getY()) + nBaseOfstForFly);
                     break;
                 }
                 default: break;
@@ -1195,7 +1195,7 @@ void SwFEShell::CalcBoundRect( SwRect& _orRect,
                 case text::RelOrientation::PRINT_AREA:
                     aPos.setX(pFrame->getFrameArea().Left() + 
pFrame->getFramePrintArea().Left() +
                                pFrame->getFramePrintArea().Width());
-                    aPos.setX(aPos.getX() + nBaseOfstForFly);
+                    aPos.setX(SwTwips(aPos.getX()) + nBaseOfstForFly);
                     break;
 
                 case text::RelOrientation::PAGE_LEFT:
@@ -1213,7 +1213,7 @@ void SwFEShell::CalcBoundRect( SwRect& _orRect,
                     break;
 
                 case text::RelOrientation::FRAME:
-                    aPos.setX(aPos.getX() + nBaseOfstForFly);
+                    aPos.setX(SwTwips(aPos.getX()) + nBaseOfstForFly);
                     break;
                 default: break;
             }
@@ -1228,7 +1228,7 @@ void SwFEShell::CalcBoundRect( SwRect& _orRect,
                     break;
                 case text::RelOrientation::PRINT_AREA:
                     aPos += pFrame->getFramePrintArea().Pos();
-                    aPos.setX(aPos.getX() + nBaseOfstForFly);
+                    aPos.setX(SwTwips(aPos.getX()) + nBaseOfstForFly);
                     break;
                 case text::RelOrientation::PAGE_RIGHT:
                     aPos.setX(pPage->getFrameArea().Left() + 
pPage->getFramePrintArea().Right());
@@ -1241,7 +1241,7 @@ void SwFEShell::CalcBoundRect( SwRect& _orRect,
                     aPos.setX(pPage->getFrameArea().Left());
                     break;
                 case text::RelOrientation::FRAME:
-                    aPos.setX(aPos.getX() + nBaseOfstForFly);
+                    aPos.setX(SwTwips(aPos.getX()) + nBaseOfstForFly);
                     break;
                 default: break;
             }
diff --git a/sw/source/core/inc/txtfly.hxx b/sw/source/core/inc/txtfly.hxx
index 9047e127e7d8..72a974e49338 100644
--- a/sw/source/core/inc/txtfly.hxx
+++ b/sw/source/core/inc/txtfly.hxx
@@ -129,7 +129,7 @@ class SwTextFly
     const SwTextFrame                * m_pMaster;
     std::unique_ptr<SwAnchoredObjList> mpAnchoredObjList;
 
-    tools::Long m_nMinBottom;
+    SwTwips m_nMinBottom;
     tools::Long m_nNextTop;  /// Stores the upper edge of the "next" frame
     SwNodeOffset m_nCurrFrameNodeIndex;
 
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index 19c4be53fd08..d78a7159e8f4 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -306,11 +306,14 @@ bool SwFormatFrameSize::QueryValue( uno::Any& rVal, 
sal_uInt8 nMemberId ) const
             rVal <<= static_cast<sal_Int32>(convertTwipToMm100(GetWidth()));
         break;
         case MID_FRMSIZE_HEIGHT:
+        {
             // #95848# returned size should never be zero.
             // (there was a bug that allowed for setting height to 0.
             // Thus there some documents existing with that not allowed
             // attribute value which may cause problems on import.)
-            rVal <<= static_cast<sal_Int32>(convertTwipToMm100(GetHeight() < 
MINLAY ? MINLAY : GetHeight() ));
+            SwTwips aValue = GetHeight() < MINLAY ? MINLAY : 
SwTwips(GetHeight());
+            rVal <<= sal_Int32(aValue.data().as_hmm());
+        }
         break;
         case MID_FRMSIZE_SIZE_TYPE:
             rVal <<= static_cast<sal_Int16>(GetHeightSizeType());
@@ -1148,7 +1151,7 @@ bool SwFormatCol::QueryValue( uno::Any& rVal, sal_uInt8 
nMemberId ) const
             xCols->setColumnCount(GetNumCols());
             const sal_uInt16 nItemGutterWidth = GetGutterWidth();
             sal_Int32 nAutoDistance = IsOrtho() ? USHRT_MAX == nItemGutterWidth
-                                                      ? DEF_GUTTER_WIDTH
+                                                      ? 
sal_Int32(DEF_GUTTER_WIDTH)
                                                       : 
static_cast<sal_Int32>(nItemGutterWidth)
                                                 : 0;
             nAutoDistance = convertTwipToMm100(nAutoDistance);
@@ -1477,7 +1480,7 @@ bool SwFormatVertOrient::QueryValue( uno::Any& rVal, 
sal_uInt8 nMemberId ) const
                 rVal <<= m_eRelation;
         break;
         case MID_VERTORIENT_POSITION:
-                rVal <<= static_cast<sal_Int32>(convertTwipToMm100(GetPos()));
+                rVal <<= sal_Int32(GetPos().data().as_hmm());
                 break;
         default:
             OSL_ENSURE( false, "unknown MemberId" );
@@ -1587,7 +1590,7 @@ bool SwFormatHoriOrient::QueryValue( uno::Any& rVal, 
sal_uInt8 nMemberId ) const
             rVal <<= m_eRelation;
         break;
         case MID_HORIORIENT_POSITION:
-                rVal <<= static_cast<sal_Int32>(convertTwipToMm100(GetPos()));
+                rVal <<= sal_Int32(GetPos().data().as_hmm());
                 break;
         case MID_HORIORIENT_PAGETOGGLE:
             rVal <<= IsPosToggle();
diff --git a/sw/source/core/layout/calcmove.cxx 
b/sw/source/core/layout/calcmove.cxx
index e05024d7f2b6..0f47343be939 100644
--- a/sw/source/core/layout/calcmove.cxx
+++ b/sw/source/core/layout/calcmove.cxx
@@ -2227,7 +2227,7 @@ bool SwContentFrame::WouldFit_( SwTwips nSpace,
                                  bCommonBorder &&
                                  !static_cast<const 
SwTextFrame*>(this)->IsEmpty() ) ?
                                  nUpper :
-                                 0;
+                                 SwTwips(0);
 
                 nUpper += bCommonBorder ?
                           rAttrs.GetBottomLine( *pFrame ) :
diff --git a/sw/source/core/layout/colfrm.cxx b/sw/source/core/layout/colfrm.cxx
index 9b13a5686a53..26ee2aad2da7 100644
--- a/sw/source/core/layout/colfrm.cxx
+++ b/sw/source/core/layout/colfrm.cxx
@@ -154,7 +154,7 @@ static bool lcl_AddColumns( SwLayoutFrame *pCont, 
sal_uInt16 nCount )
 
     bool bRet;
     SwTwips nMax = pCont->IsPageBodyFrame() ?
-                   pCont->FindPageFrame()->GetMaxFootnoteHeight() : LONG_MAX;
+                   pCont->FindPageFrame()->GetMaxFootnoteHeight() : 
SwTwips(TWIPS_MAX);
     if ( pNeighbourCol )
     {
         bRet = false;
@@ -364,7 +364,7 @@ void SwLayoutFrame::AdjustColumns( const SwFormatCol 
*pAttr, bool bAdjustAttribu
         {
             const SwTwips nWidth = i == (pAttr->GetNumCols() - 1) ?
                                    nAvail :
-                                   pAttr->CalcColWidth( i, sal_uInt16( 
fnRect.GetWidth(getFramePrintArea()) ) );
+                                   SwTwips(pAttr->CalcColWidth(i, 
sal_uInt16(fnRect.GetWidth(getFramePrintArea()))));
 
             const Size aColSz = fnRect.IsVert() ?
                                 Size( getFramePrintArea().Width(), nWidth ) :
diff --git a/sw/source/core/layout/flowfrm.cxx 
b/sw/source/core/layout/flowfrm.cxx
index ead94615e359..973cf5cd0f64 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -652,7 +652,7 @@ bool SwFlowFrame::PasteTree( SwFrame *pStart, SwLayoutFrame 
*pParent, SwFrame *p
         else
             bRet = true;
 
-        nGrowVal = o3tl::saturating_add(nGrowVal, 
aRectFnSet.GetHeight(pFloat->getFrameArea()));
+        nGrowVal = o3tl::saturating_add(nGrowVal, 
SwTwips(aRectFnSet.GetHeight(pFloat->getFrameArea())));
         if ( pFloat->GetNext() )
             pFloat = pFloat->GetNext();
         else
@@ -1654,7 +1654,7 @@ SwTwips SwFlowFrame::CalcUpperSpace( const SwBorderAttrs 
*pAttrs,
             if( rIDSA.get(DocumentSettingId::PARA_SPACE_MAX) )
             {
                 // FIXME: apply bHalfContextualSpacing for better portability?
-                nUpper = bContextualSpacing ? 0 : nPrevLowerSpace + 
pAttrs->GetULSpace().GetUpper();
+                nUpper = bContextualSpacing ? SwTwips(0) : nPrevLowerSpace + 
SwTwips(pAttrs->GetULSpace().GetUpper());
                 SwTwips nAdd = nPrevLineSpacing;
                 // i#11859 - consideration of the line spacing
                 //      for the upper spacing of a text frame
@@ -1885,7 +1885,7 @@ SwTwips 
SwFlowFrame::GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid() cons
             GetUpperSpaceAmountConsideredForPrevFrame() +
             ( m_rThis.GetUpper()->GetFormat()->GetDoc()->IsSquaredPageMode()
               ? GetUpperSpaceAmountConsideredForPageGrid_( CalcUpperSpace( 
nullptr, nullptr, false ) )
-              : 0 );
+              : SwTwips(0) );
     }
 
     return nUpperSpaceAmountConsideredForPrevFrameAndPageGrid;
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index 4b8c953d8ac0..55f002de7f01 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -216,7 +216,7 @@ SwFlyFrame::SwFlyFrame( SwFlyFrameFormat *pFormat, SwFrame* 
pSib, SwFrame *pAnch
     {
         SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
         aFrm.Width( rFrameSize.GetWidth() );
-        aFrm.Height( rFrameSize.GetHeightSizeType() == SwFrameSize::Variable ? 
MINFLY : rFrameSize.GetHeight() );
+        aFrm.Height( rFrameSize.GetHeightSizeType() == SwFrameSize::Variable ? 
MINFLY : SwTwips(rFrameSize.GetHeight()));
     }
 
     // Fixed or variable Height?
@@ -761,8 +761,8 @@ bool SwFlyFrame::FrameSizeChg( const SwFormatFrameSize 
&rFrameSize )
 
             {
                 SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
-                aFrm.Height( aFrm.Height() - nDiffHeight );
-                aFrm.Width ( aFrm.Width()  - nDiffWidth  );
+                aFrm.Height(SwTwips(aFrm.Height()) - nDiffHeight);
+                aFrm.Width(SwTwips(aFrm.Width())  - nDiffWidth);
             }
 
             // #i68520#
@@ -770,8 +770,8 @@ bool SwFlyFrame::FrameSizeChg( const SwFormatFrameSize 
&rFrameSize )
 
             {
                 SwFrameAreaDefinition::FramePrintAreaWriteAccess aPrt(*this);
-                aPrt.Height( aPrt.Height() - nDiffHeight );
-                aPrt.Width ( aPrt.Width()  - nDiffWidth  );
+                aPrt.Height(SwTwips(aPrt.Height()) - nDiffHeight);
+                aPrt.Width(SwTwips(aPrt.Width())  - nDiffWidth);
             }
 
             ChgLowersProp( aOldSz );
@@ -1373,7 +1373,7 @@ void SwFlyFrame::ChgRelPos( const Point &rNewPos )
     SwFrameFormat *pFormat = GetFormat();
     const bool bVert = GetAnchorFrame()->IsVertical();
     const SwTwips nNewY = bVert ? rNewPos.X() : rNewPos.Y();
-    SwTwips nTmpY = nNewY == LONG_MAX ? 0 : nNewY;
+    SwTwips nTmpY = nNewY == LONG_MAX ? SwTwips(0) : nNewY;
     if( bVert )
         nTmpY = -nTmpY;
     SfxItemSetFixed<RES_VERT_ORIENT, RES_HORI_ORIENT> aSet( 
pFormat->GetDoc()->GetAttrPool() );
@@ -1431,7 +1431,7 @@ void SwFlyFrame::ChgRelPos( const Point &rNewPos )
     if ( !IsFlyInContentFrame() )
     {
         const SwTwips nNewX = bVert ? rNewPos.Y() : rNewPos.X();
-        SwTwips nTmpX = nNewX == LONG_MAX ? 0 : nNewX;
+        SwTwips nTmpX = nNewX == LONG_MAX ? SwTwips(0) : nNewX;
         SwFormatHoriOrient aHori( pFormat->GetHoriOrient() );
         // #i34948# - handle also at-page and at-fly anchored
         // Writer fly frames
@@ -1528,7 +1528,7 @@ void SwFlyFrame::Format( vcl::RenderContext* 
/*pRenderContext*/, const SwBorderA
 
             SwTwips nRemaining = CalcContentHeight(pAttrs, nMinHeight, nUL);
             if( IsMinHeight() && (nRemaining + nUL) < nMinHeight )
-                nRemaining = nMinHeight - nUL;
+                nRemaining = SwTwips(nMinHeight) - nUL;
             // Because the Grow/Shrink of the Flys does not directly
             // set the size - only indirectly by triggering a Format()
             // via Invalidate() - the sizes need to be set here.
@@ -1552,7 +1552,7 @@ void SwFlyFrame::Format( vcl::RenderContext* 
/*pRenderContext*/, const SwBorderA
                 // anchor.
                 SwTwips nDeadline = GetFlyAnchorBottom(this, *pAnchor);
                 SwTwips nTop = aRectFnSet.GetTop(getFrameArea());
-                SwTwips nBottom = aRectFnSet.GetTop(getFrameArea()) + 
nRemaining;
+                SwTwips nBottom = SwTwips(aRectFnSet.GetTop(getFrameArea())) + 
nRemaining;
                 if (nBottom > nDeadline)
                 {
                     if (nDeadline > nTop)
@@ -1645,7 +1645,7 @@ void SwFlyFrame::Format( vcl::RenderContext* 
/*pRenderContext*/, const SwBorderA
                 if ( nAutoWidth )
                 {
                     if( SwFrameSize::Minimum == rFrameSz.GetWidthSizeType() )
-                        nNewSize = std::max( nNewSize - nLR, nAutoWidth );
+                        nNewSize = std::max(SwTwips(nNewSize - nLR), 
nAutoWidth);
                     else
                         nNewSize = nAutoWidth;
                 }
@@ -2143,20 +2143,20 @@ void SwFlyFrame::MakeContentPos( const SwBorderAttrs 
&rAttrs )
             if( nAdjust == SDRTEXTVERTADJUST_CENTER )
             {
                 if( aRectFnSet.IsVertL2R() )
-                    aNewContentPos.setX(aNewContentPos.getX() + nDiff/2);
+                    aNewContentPos.setX(SwTwips(aNewContentPos.getX()) + nDiff 
/ 2);
                 else if( aRectFnSet.IsVert() )
-                    aNewContentPos.setX(aNewContentPos.getX() - nDiff/2);
+                    aNewContentPos.setX(SwTwips(aNewContentPos.getX()) - nDiff 
/ 2);
                 else
-                    aNewContentPos.setY(aNewContentPos.getY() + nDiff/2);
+                    aNewContentPos.setY(SwTwips(aNewContentPos.getY()) + nDiff 
/ 2);
             }
             else if( nAdjust == SDRTEXTVERTADJUST_BOTTOM )
             {
                 if( aRectFnSet.IsVertL2R() )
-                    aNewContentPos.setX(aNewContentPos.getX() + nDiff);
+                    aNewContentPos.setX(SwTwips(aNewContentPos.getX()) + 
nDiff);
                 else if( aRectFnSet.IsVert() )
-                    aNewContentPos.setX(aNewContentPos.getX() - nDiff);
+                    aNewContentPos.setX(SwTwips(aNewContentPos.getX()) - 
nDiff);
                 else
-                    aNewContentPos.setY(aNewContentPos.getY() + nDiff);
+                    aNewContentPos.setY(SwTwips(aNewContentPos.getY()) + 
nDiff);
             }
         }
     }
@@ -2299,8 +2299,8 @@ SwTwips SwFlyFrame::Grow_(SwTwips nDist, 
SwResizeLimitReason& reason, bool bTst)
 
     SwRectFnSet aRectFnSet(this);
     SwTwips nSize = aRectFnSet.GetHeight(getFrameArea());
-    if( nSize > 0 && nDist > ( LONG_MAX - nSize ) )
-        nDist = LONG_MAX - nSize;
+    if( nSize > 0 && nDist > (SwTwips(LONG_MAX) - nSize) )
+        nDist = SwTwips(LONG_MAX) - nSize;
 
     if ( nDist <= 0 )
     {
@@ -2451,7 +2451,7 @@ SwTwips SwFlyFrame::Shrink_( SwTwips nDist, bool bTst )
             const SwFormatFrameSize& rFormatSize = GetFormat()->GetFrameSize();
             SwTwips nFormatHeight = aRectFnSet.IsVert() ? 
rFormatSize.GetWidth() : rFormatSize.GetHeight();
 
-            nVal = std::min( nDist, nHeight - nFormatHeight );
+            nVal = std::min(nDist, SwTwips(nHeight - nFormatHeight));
         }
 
         if ( nVal <= 0 )
diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx
index eb34e63caacc..accb1bc3de39 100644
--- a/sw/source/core/layout/flycnt.cxx
+++ b/sw/source/core/layout/flycnt.cxx
@@ -67,11 +67,11 @@ SwTwips lcl_GetTopForObjPos(const SwContentFrame* pCnt, 
const bool bVert, const
         if ( bVertL2R )
             aResult += 
pCnt->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
         else
-            aResult += pCnt->getFrameArea().Width() - 
pCnt->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
+            aResult += SwTwips(pCnt->getFrameArea().Width()) - 
pCnt->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
         return aResult;
     }
     else
-        return pCnt->getFrameArea().Top() + 
pCnt->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
+        return SwTwips(pCnt->getFrameArea().Top()) + 
pCnt->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
 }
 
 }
@@ -662,12 +662,12 @@ static const SwFrame * lcl_CalcDownDist( SwDistance &rRet,
             if( bVert )
             {
                 if ( bVertL2R )
-                    rRet.m_nMain = rPt.X() - nTopForObjPos;
+                    rRet.m_nMain = SwTwips(rPt.X()) - nTopForObjPos;
                 else
                     rRet.m_nMain = nTopForObjPos - rPt.X();
             }
             else
-                rRet.m_nMain = rPt.Y() - nTopForObjPos;
+                rRet.m_nMain = SwTwips(rPt.Y()) - nTopForObjPos;
             return pCnt;
         }
         else if ( rPt.Y() <= pUp->getFrameArea().Top() )
@@ -691,7 +691,7 @@ static const SwFrame * lcl_CalcDownDist( SwDistance &rRet,
                 if( bVert )
                 {
                     if ( bVertL2R )
-                        rRet.m_nMain = rPt.X() - nTopForObjPos;
+                        rRet.m_nMain = SwTwips(rPt.X()) - nTopForObjPos;
                     else
                         rRet.m_nMain = nTopForObjPos - rPt.X();
                 }
@@ -906,7 +906,7 @@ static const SwFrame * lcl_CalcDownDist( SwDistance &rRet,
                 if ( pLay->getFrameArea().Contains( rPt ) )
                 {
                     SwTwips nDiff = pLay->IsVertical() ? ( pLay->IsVertLR() ? 
( rPt.X() - nFrameTop ) : ( nFrameTop - rPt.X() ) )
-                                                       : ( rPt.Y() - nFrameTop 
);
+                                                       : ( SwTwips(rPt.Y()) - 
nFrameTop );
                     if( bSct || pSect )
                         rRet.m_nSub += nDiff;
                     else
@@ -1300,7 +1300,7 @@ void SwFlyAtContentFrame::SetAbsPos( const Point &rNew )
             nY -= pCnt->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
         }
         else
-            nY = rNew.Y() - pCnt->getFrameArea().Top() - 
pCnt->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
+            nY = SwTwips(rNew.Y() - pCnt->getFrameArea().Top()) - 
pCnt->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
     }
     else
     {
@@ -1361,13 +1361,13 @@ void SwFlyAtContentFrame::SetAbsPos( const Point &rNew )
         if( bVert )
         {
             if ( bVertL2R )
-                nY = rNew.X() - nTopForObjPos;
+                nY = SwTwips(rNew.X()) - nTopForObjPos;
             else
                 nY = nTopForObjPos - rNew.X();
         }
         else
         {
-            nY = rNew.Y() - nTopForObjPos;
+            nY = SwTwips(rNew.Y()) - nTopForObjPos;
         }
     }
 
diff --git a/sw/source/core/layout/ftnfrm.cxx b/sw/source/core/layout/ftnfrm.cxx
index 23ed26c972cd..ebf6eff3d472 100644
--- a/sw/source/core/layout/ftnfrm.cxx
+++ b/sw/source/core/layout/ftnfrm.cxx
@@ -270,7 +270,7 @@ SwTwips FootnoteSeparatorHeight(SwDoc& rDoc, 
SwPageFootnoteInfo const& rInf)
     }
 
     // Writer style: calculate from the page style.
-    return rInf.GetTopDist() + rInf.GetBottomDist() + rInf.GetLineWidth();
+    return SwTwips(rInf.GetTopDist()) + SwTwips(rInf.GetBottomDist()) + 
SwTwips(rInf.GetLineWidth());
 }
 
 } // namespace sw
diff --git a/sw/source/core/layout/hffrm.cxx b/sw/source/core/layout/hffrm.cxx
index f773e8393911..e9adec2676ef 100644
--- a/sw/source/core/layout/hffrm.cxx
+++ b/sw/source/core/layout/hffrm.cxx
@@ -166,9 +166,9 @@ void SwHeadFootFrame::FormatPrt(SwTwips & nUL, const 
SwBorderAttrs * pAttrs)
 
         /* calculate real vertical space between frame and print area */
         if (IsHeaderFrame())
-            nUL = pAttrs->CalcTop() + nSpace;
+            nUL = SwTwips(pAttrs->CalcTop()) + nSpace;
         else
-            nUL = pAttrs->CalcBottom() + nSpace;
+            nUL = SwTwips(pAttrs->CalcBottom()) + nSpace;
 
         /* set print area */
         SwTwips nLR = pAttrs->CalcLeft( this ) + pAttrs->CalcRight( this );
@@ -185,13 +185,13 @@ void SwHeadFootFrame::FormatPrt(SwTwips & nUL, const 
SwBorderAttrs * pAttrs)
             aPrt.Top(nSpace);
         }
 
-        aPrt.Width(getFrameArea().Width() - nLR);
+        aPrt.Width(SwTwips(getFrameArea().Width()) - nLR);
 
         SwTwips nNewHeight;
 
         if (nUL < getFrameArea().Height())
         {
-            nNewHeight = getFrameArea().Height() - nUL;
+            nNewHeight = SwTwips(getFrameArea().Height()) - nUL;
         }
         else
         {
@@ -210,8 +210,8 @@ void SwHeadFootFrame::FormatPrt(SwTwips & nUL, const 
SwBorderAttrs * pAttrs)
         // Set sizes - the sizes are given by the surrounding Frame, just
         // subtract the borders.
         SwTwips nLR = pAttrs->CalcLeft( this ) + pAttrs->CalcRight( this );
-        aPrt.Width ( getFrameArea().Width() - nLR );
-        aPrt.Height( getFrameArea().Height()- nUL );
+        aPrt.Width (SwTwips(getFrameArea().Width())  - nLR);
+        aPrt.Height(SwTwips(getFrameArea().Height()) - nUL);
     }
 
     setFramePrintAreaValid(true);
@@ -314,7 +314,7 @@ void SwHeadFootFrame::FormatSize(SwTwips nUL, const 
SwBorderAttrs * pAttrs)
                     nMaxHeight = nOldHeight;
 
                     if( nRemaining <= nMinHeight )
-                        nRemaining = ( nMaxHeight + nMinHeight + 1 ) / 2;
+                        nRemaining = (nMaxHeight + nMinHeight + 1_twip) / 2;
                 }
                 else
                 {
@@ -322,7 +322,7 @@ void SwHeadFootFrame::FormatSize(SwTwips nUL, const 
SwBorderAttrs * pAttrs)
                         nMinHeight = nOldHeight;
 
                     if( nRemaining >= nMaxHeight )
-                        nRemaining = ( nMaxHeight + nMinHeight + 1 ) / 2;
+                        nRemaining = (nMaxHeight + nMinHeight + 1_twip) / 2;
                 }
 
                 nDiff = nRemaining - nOldHeight;
@@ -384,7 +384,7 @@ void SwHeadFootFrame::FormatSize(SwTwips nUL, const 
SwBorderAttrs * pAttrs)
                         aFrm.Bottom( nDeadLine );
 
                         SwFrameAreaDefinition::FramePrintAreaWriteAccess 
aPrt(*this);
-                        aPrt.Height( getFrameArea().Height() - nBorder );
+                        aPrt.Height(SwTwips(getFrameArea().Height()) - nBorder 
);
                     }
                 }
 
@@ -591,8 +591,8 @@ SwTwips SwHeadFootFrame::ShrinkFrame( SwTwips nDist, bool 
bTst, bool bInfo )
 
             /* minimal height of print area */
             SwTwips nMinPrtHeight = nMinHeight
-                - pAttrs->CalcTop()
-                - pAttrs->CalcBottom();
+                - SwTwips(pAttrs->CalcTop())
+                - SwTwips(pAttrs->CalcBottom());
 
             if (nMinPrtHeight < 0)
                 nMinPrtHeight = 0;
diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx
index ec87aa49831c..96719b247d5e 100644
--- a/sw/source/core/layout/layact.cxx
+++ b/sw/source/core/layout/layact.cxx
@@ -1408,7 +1408,7 @@ bool SwLayAction::FormatLayout( OutputDevice 
*pRenderContext, SwLayoutFrame *pLa
 
                     // right
                     aSpaceToNextPage = aPageRect;
-                    aSpaceToNextPage.Right( aSpaceToNextPage.Right() + 
nHalfDocBorder );
+                    aSpaceToNextPage.Right(SwTwips(aSpaceToNextPage.Right()) + 
nHalfDocBorder );
                     aSpaceToNextPage.Left( pLay->getFrameArea().Right() );
                     if(!aSpaceToNextPage.IsEmpty())
                         m_pImp->GetShell().AddPaintRect( aSpaceToNextPage );
diff --git a/sw/source/core/layout/pagechg.cxx 
b/sw/source/core/layout/pagechg.cxx
index 61eb3f325286..96dfc74a193f 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -205,8 +205,9 @@ SwPageFrame::SwPageFrame( SwFrameFormat *pFormat, SwFrame* 
pSib, SwPageDesc *pPg
     }
     else
         m_bHasGrid = false;
-    SetMaxFootnoteHeight( pPgDsc->GetFootnoteInfo().GetHeight() ?
-                     pPgDsc->GetFootnoteInfo().GetHeight() : LONG_MAX );
+    SetMaxFootnoteHeight(
+        pPgDsc->GetFootnoteInfo().GetHeight() ?
+        pPgDsc->GetFootnoteInfo().GetHeight() : SwTwips(TWIPS_MAX));
     mnFrameType = SwFrameType::Page;
     m_bInvalidLayout = m_bInvalidContent = m_bInvalidSpelling = 
m_bInvalidSmartTags = m_bInvalidAutoCmplWrds = m_bInvalidWordCount = true;
     m_bInvalidFlyLayout = m_bInvalidFlyContent = m_bInvalidFlyInCnt = 
m_bFootnotePage = m_bEndNotePage = false;
@@ -1878,7 +1879,8 @@ void SwRootFrame::ImplCalcBrowseWidth()
 
     mbBrowseWidthValid = true;
     SwViewShell *pSh = getRootFrame()->GetCurrShell();
-    mnBrowseWidth = (!comphelper::LibreOfficeKit::isActive() && pSh)? MINLAY + 
2 * pSh->GetOut()-> PixelToLogic( pSh->GetBrowseBorder() ).Width(): 
MIN_BROWSE_WIDTH;
+    mnBrowseWidth = (!comphelper::LibreOfficeKit::isActive() && pSh) ?
+                        MINLAY + 2 * pSh->GetOut()-> PixelToLogic( 
pSh->GetBrowseBorder() ).Width() : SwTwips(MIN_BROWSE_WIDTH);
 
     do
     {
@@ -2394,12 +2396,10 @@ void SwRootFrame::CheckViewLayout( const SwViewOption* 
pViewOpt, const SwRect* p
                 if ( mbBookMode )
                     pFormatPage = &pPageToAdjust->GetFormatPage();
 
-                const SwTwips nCurrentPageWidth = 
pFormatPage->getFrameArea().Width() + (pFormatPage->IsEmptyPage() ? 0 : 
nSidebarWidth);
+                const SwTwips nCurrentPageWidth = 
pFormatPage->getFrameArea().Width() + (pFormatPage->IsEmptyPage() ? SwTwips(0) 
: nSidebarWidth);
                 const Point aOldPagePos = pPageToAdjust->getFrameArea().Pos();
                 const bool bLeftSidebar = pPageToAdjust->SidebarPosition() == 
sw::sidebarwindows::SidebarPosition::LEFT;
-                const SwTwips nLeftPageAddOffset = bLeftSidebar ?
-                                                   nSidebarWidth :
-                                                   0;
+                const SwTwips nLeftPageAddOffset = bLeftSidebar ? 
nSidebarWidth : SwTwips(0);
 
                 Point aNewPagePos( nBorder + nX, nBorder + nSumRowHeight );
                 Point aNewPagePosWithLeftOffset( nBorder + nX + 
nLeftPageAddOffset, nBorder + nSumRowHeight );
diff --git a/sw/source/core/layout/sectfrm.cxx 
b/sw/source/core/layout/sectfrm.cxx
index 12d67f5a6dc8..ff8305314c59 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -3095,9 +3095,9 @@ SwTwips SwSectionFrame::CalcUndersize() const
 
 SwTwips SwSectionFrame::Undersize()
 {
-    const auto nRet = CalcUndersize();
+    const SwTwips nRet = CalcUndersize();
     m_bUndersized = (nRet > 0);
-    return nRet <= 0 ? 0 : nRet;
+    return nRet <= 0 ? SwTwips(0) : nRet;
 }
 
 void SwSectionFrame::CalcFootnoteContent()
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 2c33166f12ec..11f95e9027c5 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -735,7 +735,7 @@ static bool lcl_RecalcSplitLine( SwRowFrame& rLastLine, 
SwRowFrame& rFollowLine,
     // Shrink the table to account for the shrunk last row, as well as lower 
rows
     // that had been moved to follow table in SwTabFrame::Split.
     // It will grow later when last line will recalc its height.
-    rTab.Shrink(nAlreadyFree + nCurLastLineHeight - nRemainingSpaceForLastRow 
+ 1);
+    rTab.Shrink(nAlreadyFree + nCurLastLineHeight - nRemainingSpaceForLastRow 
+ 1_twip);
 
     // Lock this tab frame and its follow
     bool bUnlockMaster = false;
@@ -3745,7 +3745,7 @@ void SwTabFrame::Format( vcl::RenderContext* 
/*pRenderContext*/, const SwBorderA
                         //      otherwise non negative wished right indent is 
hold.
                         nRightSpacing = nRightLine +
                                         ( ( (nWishRight+nLeftOffset) < 0 ) ?
-                                            (nWishRight+nLeftOffset) :
+                                            SwTwips(nWishRight+nLeftOffset) :
                                             std::max( SwTwips(0), nWishRight ) 
);
                     }
                 }
@@ -3776,7 +3776,7 @@ void SwTabFrame::Format( vcl::RenderContext* 
/*pRenderContext*/, const SwBorderA
                         //      otherwise non negative wished left indent is 
hold.
                         nLeftSpacing = nLeftLine +
                                        ( ( (nWishLeft+nRightOffset) < 0 ) ?
-                                           (nWishLeft+nRightOffset) :
+                                           SwTwips(nWishLeft+nRightOffset) :
                                            std::max( SwTwips(0), nWishLeft ) );
                     }
                 }
@@ -3844,7 +3844,7 @@ void SwTabFrame::Format( vcl::RenderContext* 
/*pRenderContext*/, const SwBorderA
                     }
                     // OD 10.03.2003 #i9040# - consider right and left line 
attribute.
                     const SwTwips nWishRight =
-                            nMax - (nLeftSpacing-pAttrs->CalcLeftLine()) - 
nWishedTableWidth;
+                            nMax - (nLeftSpacing - 
SwTwips(pAttrs->CalcLeftLine())) - nWishedTableWidth;
                     nRightSpacing = nRightLine +
                                     ( (nRightOffset > 0) ?
                                       std::max( nWishRight, 
SwTwips(nRightOffset) ) :
@@ -3941,7 +3941,7 @@ SwTwips SwTabFrame::GrowFrame(SwTwips nDist, 
SwResizeLimitReason& reason, bool b
 
             if ( IsRestrictTableGrowth() )
             {
-                nTmp = std::min( tools::Long(nDist), nReal + nTmp );
+                nTmp = std::min(SwTwips(nDist), nReal + nTmp);
                 nDist = nTmp < 0 ? 0 : nTmp;
             }
         }
@@ -4851,7 +4851,7 @@ tools::Long CalcHeightWithFlys( const SwFrame *pFrame )
                                     aRectFnSet.GetTop(pTmp->getFrameArea()),
                                     aRectFnSet.GetTop(pFrame->getFrameArea()) 
);
 
-                            nHeight = std::max( nHeight, 
nDistOfFlyBottomToAnchorTop + nFrameDiff -
+                            nHeight = std::max(SwTwips(nHeight), 
nDistOfFlyBottomToAnchorTop + nFrameDiff -
                                             
aRectFnSet.GetHeight(pFrame->getFrameArea()) );
 
                             // #i56115# The first height calculation
@@ -5450,7 +5450,7 @@ void SwRowFrame::AdjustCells( const SwTwips nHeight, 
const bool bHeight )
                 // Use new height for the current row:
                 nSumRowHeight += pToAdjustRow == this ?
                                  nHeight :
-                                 
aRectFnSet.GetHeight(pToAdjustRow->getFrameArea());
+                                 
SwTwips(aRectFnSet.GetHeight(pToAdjustRow->getFrameArea()));
 
                 if ( nRowSpan-- == 1 )
                     break;
@@ -5597,8 +5597,8 @@ SwTwips SwRowFrame::ShrinkFrame( SwTwips nDist, bool 
bTst, bool bInfo )
         const SwFormatFrameSize &rSz = pMod->GetFrameSize();
         SwTwips nMinHeight = 0;
         if (rSz.GetHeightSizeType() == SwFrameSize::Minimum)
-            nMinHeight = std::max(rSz.GetHeight() - 
lcl_calcHeightOfRowBeforeThisFrame(*this),
-                                  tools::Long(0));
+            nMinHeight = std::max(SwTwips(rSz.GetHeight()) - 
lcl_calcHeightOfRowBeforeThisFrame(*this),
+                                  SwTwips(0));
 
         // Only necessary to calculate minimal row height if height
         // of pRow is at least nMinHeight. Otherwise nMinHeight is the
@@ -5633,7 +5633,7 @@ SwTwips SwRowFrame::ShrinkFrame( SwTwips nDist, bool 
bTst, bool bInfo )
         }
 
         SwLayoutFrame* pFrame = GetUpper();
-        SwTwips nTmp = pFrame ? pFrame->Shrink(nReal, bTst) : 0;
+        SwTwips nTmp = pFrame ? pFrame->Shrink(nReal, bTst) : SwTwips(0);
         if ( !bShrinkAnyway && !GetNext() && nTmp != nReal )
         {
             //The last one gets the leftover in the upper and therefore takes
@@ -6032,7 +6032,7 @@ void SwCellFrame::Format( vcl::RenderContext* 
/*pRenderContext*/, const SwBorder
     // #i26945#
     tools::Long nRemaining = GetTabBox()->getRowSpan() >= 1 ?
                       ::lcl_CalcMinCellHeight( this, 
pTab->IsConsiderObjsForMinCellHeight(), pAttrs ) :
-                      0;
+                      SwTwips(0);
     if ( !isFrameAreaSizeValid() )
     {
         setFrameAreaSizeValid(true);
@@ -6812,7 +6812,7 @@ static SwTwips lcl_CalcHeightOfFirstContentLine( const 
SwRowFrame& rSourceLine )
         pCurrSourceCell = static_cast<const 
SwCellFrame*>(pCurrSourceCell->GetNext());
     }
 
-    return ( LONG_MAX == nHeight ) ? 0 : nHeight;
+    return ( LONG_MAX == nHeight ) ? SwTwips(0) : nHeight;
 }
 
 /// Function to calculate height of first text row
@@ -6921,8 +6921,8 @@ SwTwips SwTabFrame::CalcHeightOfFirstContentLine() const
             SwTwips nMinRowHeight = 0;
             if (rSz.GetHeightSizeType() == SwFrameSize::Minimum)
             {
-                nMinRowHeight = std::max(rSz.GetHeight() - 
lcl_calcHeightOfRowBeforeThisFrame(*pFirstRow),
-                                         tools::Long(0));
+                nMinRowHeight = std::max(SwTwips(rSz.GetHeight()) - 
lcl_calcHeightOfRowBeforeThisFrame(*pFirstRow),
+                                         SwTwips(0));
             }
 
             nTmpHeight += std::max( nHeightOfFirstContentLine, nMinRowHeight );
diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index 09a078467d32..3030c703f49d 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -2304,7 +2304,7 @@ SwTwips SwContentFrame::ShrinkFrame( SwTwips nDist, bool 
bTst, bool bInfo )
             // i#94666 if WIDOW_MAGIC was set as height, nDist is wrong, need
             // to take into account all the frames in the section.
             if (GetUpper()->IsSctFrame()
-                && sw::WIDOW_MAGIC - 20000 - getFrameArea().Top() < nDist)
+                && sw::WIDOW_MAGIC - 20000_twip - getFrameArea().Top() < nDist)
             {
                 SwFrame *pNxt = GetNext();
                 while( pNxt )
@@ -2817,7 +2817,7 @@ SwTwips SwLayoutFrame::GrowFrame(SwTwips nDist, 
SwResizeLimitReason& reason, boo
                             }
                         }
                     }
-                    nGrow = pToGrow ? pToGrow->Grow(nReal, reason, bTst, 
bInfo) : 0;
+                    nGrow = pToGrow ? pToGrow->Grow(nReal, reason, bTst, 
bInfo) : SwTwips(0);
                 }
 
                 if( SwNeighbourAdjust::GrowAdjust == nAdjust && nGrow < nReal )
@@ -2826,7 +2826,7 @@ SwTwips SwLayoutFrame::GrowFrame(SwTwips nDist, 
SwResizeLimitReason& reason, boo
                 if ( IsFootnoteFrame() && (nGrow != nReal) && GetNext() )
                 {
                     //Footnotes can replace their successor.
-                    SwTwips nSpace = bTst ? 0 : -nDist;
+                    SwTwips nSpace = bTst ? SwTwips(0) : -nDist;
                     if (const SwFrame *pFrame = GetUpper()->Lower())
                     {
                         do
@@ -3089,7 +3089,7 @@ SwTwips SwLayoutFrame::ShrinkFrame( SwTwips nDist, bool 
bTst, bool bInfo )
                 }
             }
         }
-        nReal = pToShrink ? pToShrink->Shrink( nShrink, bTst, bInfo ) : 0;
+        nReal = pToShrink ? pToShrink->Shrink( nShrink, bTst, bInfo ) : 
SwTwips(0);
         if( ( SwNeighbourAdjust::GrowAdjust == nAdjust || 
SwNeighbourAdjust::AdjustGrow == nAdjust )
             && nReal < nShrink )
             AdjustNeighbourhood( nReal - nShrink );
@@ -4114,7 +4114,7 @@ void SwLayoutFrame::FormatWidthCols( const SwBorderAttrs 
&rAttrs,
                         if ( nFrameHeight > nMinHeight || nPrtHeight >= 
nMinDiff )
                             nDiff = std::max( nDiff, nMinDiff );
                         else if( nDiff < nMinDiff )
-                            nDiff = nMinDiff - nPrtHeight + 1;
+                            nDiff = nMinDiff - nPrtHeight + 1_twip;
                     }
                     // nMaximum is a size in which the content fit or the
                     // requested value from the environment, therefore we don't
diff --git a/sw/source/core/objectpositioning/anchoredobjectposition.cxx 
b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
index 0e6b702cc6db..57aac07e69f3 100644
--- a/sw/source/core/objectpositioning/anchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
@@ -226,7 +226,8 @@ void SwAnchoredObjectPosition::GetVertAlignmentValues(
             _rVertOrientFrame.IsTextFrame()
             ? static_cast<const SwTextFrame&>(_rVertOrientFrame).
                         GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid()
-            : 0;
+            : SwTwips(0);
+
     switch ( _eRelOrient )
     {
         case text::RelOrientation::FRAME:
@@ -415,7 +416,7 @@ SwTwips SwAnchoredObjectPosition::GetVertRelPos(
         {
             nRelPosY += nAlignAreaHeight
                         - (nObjHeight
-                           + (aRectFnSet.IsVert()
+                           + SwTwips(aRectFnSet.IsVert()
                                   ? (aRectFnSet.IsVertL2R() ? 
_rLRSpacing.ResolveRight({})
                                                             : 
_rLRSpacing.ResolveLeft({}))
                                   : _rULSpacing.GetLower()));
@@ -804,7 +805,7 @@ void SwAnchoredObjectPosition::GetHoriAlignmentValues( 
const SwFrame&  _rHoriOri
             bool bIgnoreFlysAnchoredAtFrame = !bWrapThrough;
             nOffset = _rHoriOrientFrame.IsTextFrame() ?
                    static_cast<const 
SwTextFrame&>(_rHoriOrientFrame).GetBaseOffsetForFly( 
bIgnoreFlysAnchoredAtFrame ) :
-                   0;
+                   SwTwips(0);
             break;
         }
     }
@@ -938,7 +939,7 @@ SwTwips SwAnchoredObjectPosition::CalcRelPosX(
         nRelPosX
             += nWidth
                - (nObjWidth
-                  + (aRectFnSet.IsVert() ? _rULSpacing.GetLower() : 
_rLRSpacing.ResolveRight({})));
+                  + SwTwips(aRectFnSet.IsVert() ? _rULSpacing.GetLower() : 
_rLRSpacing.ResolveRight({})));
     else
         nRelPosX += aRectFnSet.IsVert() ? _rULSpacing.GetUpper() : 
_rLRSpacing.ResolveLeft({});
 
@@ -1053,11 +1054,11 @@ SwTwips 
SwAnchoredObjectPosition::AdjustHoriRelPosForDrawAside(
                 {
                     if ( _eHoriOrient == text::HoriOrientation::LEFT )
                     {
-                        SwTwips nTmp = nOtherBot + 1 + _rULSpacing.GetUpper() -
+                        SwTwips nTmp = nOtherBot + 1_twip + 
SwTwips(_rULSpacing.GetUpper()) -
                                        rAnchorTextFrame.getFrameArea().Top();
                         if ( nTmp > nAdjustedRelPosX &&
                              rAnchorTextFrame.getFrameArea().Top() + nTmp +
-                             aObjBoundRect.Height() + _rULSpacing.GetLower()
+                             aObjBoundRect.Height() + 
SwTwips(_rULSpacing.GetLower())
                              <= pObjPage->getFrameArea().Height() + 
pObjPage->getFrameArea().Top() )
                         {
                             nAdjustedRelPosX = nTmp;
@@ -1065,7 +1066,7 @@ SwTwips 
SwAnchoredObjectPosition::AdjustHoriRelPosForDrawAside(
                     }
                     else if ( _eHoriOrient == text::HoriOrientation::RIGHT )
                     {
-                        SwTwips nTmp = nOtherTop - 1 - _rULSpacing.GetLower() -
+                        SwTwips nTmp = nOtherTop - 1_twip - 
SwTwips(_rULSpacing.GetLower()) -
                                        aObjBoundRect.Height() -
                                        rAnchorTextFrame.getFrameArea().Top();
                         if ( nTmp < nAdjustedRelPosX &&
@@ -1090,7 +1091,7 @@ SwTwips 
SwAnchoredObjectPosition::AdjustHoriRelPosForDrawAside(
                 {
                     if ( _eHoriOrient == text::HoriOrientation::LEFT )
                     {
-                        SwTwips nTmp = nOtherRight + 1 + 
_rLRSpacing.ResolveLeft({})
+                        SwTwips nTmp = nOtherRight + 1_twip + 
SwTwips(_rLRSpacing.ResolveLeft({}))
                                        - 
rAnchorTextFrame.getFrameArea().Left();
                         if (nTmp > nAdjustedRelPosX
                             && rAnchorTextFrame.getFrameArea().Left() + nTmp + 
aObjBoundRect.Width()
@@ -1103,7 +1104,7 @@ SwTwips 
SwAnchoredObjectPosition::AdjustHoriRelPosForDrawAside(
                     }
                     else if ( _eHoriOrient == text::HoriOrientation::RIGHT )
                     {
-                        SwTwips nTmp = nOtherLeft - 1 - 
_rLRSpacing.ResolveRight({})
+                        SwTwips nTmp = nOtherLeft - 1_twip - 
SwTwips(_rLRSpacing.ResolveRight({}))
                                        - aObjBoundRect.Width()
                                        - 
rAnchorTextFrame.getFrameArea().Left();
                         if (nTmp < nAdjustedRelPosX
diff --git a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx 
b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
index 9ffb25400fd7..a0b65524dd95 100644
--- a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
@@ -1307,7 +1307,7 @@ void SwToContentAnchoredObjectPosition::CalcOverlap(const 
SwTextFrame* pAnchorFr
 
         // Already formatted, overlaps: resolve the conflict by shifting 
ourselves down.
         SwTwips nYDiff = pAnchoredObj->GetObjRect().Bottom() - 
GetAnchoredObj().GetObjRect().Top();
-        rRelPos.setY(rRelPos.getY() + nYDiff + 1);
+        rRelPos.setY(rRelPos.getY() + nYDiff + 1_twip);
         GetAnchoredObj().SetObjTop(nTopOfAnch + rRelPos.Y());
 
         // Store our offset that avoids the overlap. If this is a shape of a 
textbox, then the frame
diff --git 
a/sw/source/core/objectpositioning/tolayoutanchoredobjectposition.cxx 
b/sw/source/core/objectpositioning/tolayoutanchoredobjectposition.cxx
index 04d94185d755..87c41418590d 100644
--- a/sw/source/core/objectpositioning/tolayoutanchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/tolayoutanchoredobjectposition.cxx
@@ -175,7 +175,8 @@ void SwToLayoutAnchoredObjectPosition::CalcPosition()
         else if (text::HoriOrientation::RIGHT == eHoriOrient)
             nRelPosX
                 = nWidth
-                  - (nObjWidth + (aRectFnSet.IsVert() ? rUL.GetLower() : 
rLR.ResolveRight({})));
+                  - (nObjWidth + (aRectFnSet.IsVert() ?
+                                    SwTwips(rUL.GetLower()) : 
SwTwips(rLR.ResolveRight({}))));
         else
             nRelPosX = aRectFnSet.IsVert() ? rUL.GetUpper() : 
rLR.ResolveLeft({});
         nRelPosX += nOffset;
diff --git a/sw/source/core/table/swnewtable.cxx 
b/sw/source/core/table/swnewtable.cxx
index 7fa4912f9f42..2e858211ea6e 100644
--- a/sw/source/core/table/swnewtable.cxx
+++ b/sw/source/core/table/swnewtable.cxx
@@ -1372,7 +1372,7 @@ static sal_uInt16 lcl_CalculateSplitLineHeights( 
SwSplitLines &rCurr, SwSplitLin
     }
     for( const auto& rSplit : aBoxes )
     {
-        SwTwips nBase = rSplit.first <= nFirst ? 0 :
+        SwTwips nBase = rSplit.first <= nFirst ? SwTwips(0) :
                         pLines[ rSplit.first - nFirst - 1 ];
         SwTwips nDiff = pLines[ rSplit.second - nFirst ] - nBase;
         for( sal_uInt16 i = 1; i < nCnt; ++i )
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 9789fe9268c1..780d8f959e28 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -1006,7 +1006,7 @@ static void lcl_AdjustWidthsInLine( SwTableLine* pLine, 
ChangeList& rOldNew,
         SwTwips nNewWidth = nWidth - nRest;
         nRest = 0;
         nBorder += nWidth;
-        if( pCurr != rOldNew.end() && nBorder + nColFuzzy >= pCurr->first )
+        if( pCurr != rOldNew.end() && nBorder + SwTwips(nColFuzzy) >= 
pCurr->first )
         {
             nBorder -= nColFuzzy;
             while( pCurr != rOldNew.end() && nBorder > pCurr->first )
@@ -1014,7 +1014,7 @@ static void lcl_AdjustWidthsInLine( SwTableLine* pLine, 
ChangeList& rOldNew,
             if( pCurr != rOldNew.end() )
             {
                 nBorder += nColFuzzy;
-                if( nBorder + nColFuzzy >= pCurr->first )
+                if( nBorder + SwTwips(nColFuzzy) >= pCurr->first )
                 {
                     if( pCurr->second == pCurr->first )
                         nRest = 0;
@@ -1029,8 +1029,8 @@ static void lcl_AdjustWidthsInLine( SwTableLine* pLine, 
ChangeList& rOldNew,
         {
             if( nNewWidth < 0 )
             {
-                nRest += 1 - nNewWidth;
-                nNewWidth = 1;
+                nRest += SwTwips(1_twip) - nNewWidth;
+                nNewWidth = SwTwips(1_twip);
             }
             SwFormatFrameSize aFormatFrameSize( 
pBox->GetFrameFormat()->GetFrameSize() );
             aFormatFrameSize.SetWidth( nNewWidth );
diff --git a/sw/source/core/text/frmcrsr.cxx b/sw/source/core/text/frmcrsr.cxx
index a2545c300abf..047f3de18eef 100644
--- a/sw/source/core/text/frmcrsr.cxx
+++ b/sw/source/core/text/frmcrsr.cxx
@@ -516,7 +516,7 @@ bool SwTextFrame::GetTopOfLine( SwTwips& _onTopOfLine,
 }
 
 // Minimum distance of non-empty lines is a little less than 2 cm
-#define FILL_MIN_DIST 1100
+constexpr SwTwips FILL_MIN_DIST(1100);
 
 struct SwFillData
 {
@@ -1460,7 +1460,7 @@ void SwTextFrame::FillCursorPos( SwFillData& rFill ) const
         if( nDiff > 0 )
         {
             nDiff /= nDist;
-            rFill.Fill().nParaCnt = o3tl::narrowing<sal_uInt16>(nDiff + 1);
+            rFill.Fill().nParaCnt = o3tl::narrowing<sal_uInt16>(nDiff + 
1_twip);
             rFill.nLineWidth = 0;
             rFill.bInner = false;
             rFill.bEmpty = true;
@@ -1478,7 +1478,7 @@ void SwTextFrame::FillCursorPos( SwFillData& rFill ) const
             const SvxRightMarginItem& rRightMargin(pSet->GetRightMargin());
 
             SwRect &rRect = rFill.Fill().aCursor;
-            rRect.Top( rFill.Bottom() + (nDiff+1) * nDist - nLineHeight );
+            rRect.Top( rFill.Bottom() + (nDiff + 1_twip) * nDist - nLineHeight 
);
             if( nFirst && nDiff > -1 )
                 rRect.Top( rRect.Top() + nFirst );
             rRect.Height( nLineHeight );
diff --git a/sw/source/core/text/frmform.cxx b/sw/source/core/text/frmform.cxx
index 17e55bf5ba48..806451fe6072 100644
--- a/sw/source/core/text/frmform.cxx
+++ b/sw/source/core/text/frmform.cxx
@@ -1501,7 +1501,7 @@ bool SwTextFrame::FormatLine( SwTextFormatter &rLine, 
const bool bPrev )
                 rRepaint.Top( nOldTop );
             if( !rLine.IsUnclipped() || nOldBottom > rRepaint.Bottom() )
             {
-                rRepaint.Bottom( nOldBottom - 1 );
+                rRepaint.Bottom(nOldBottom - 1_twip);
                 rLine.SetUnclipped( true );
             }
         }
@@ -1513,7 +1513,7 @@ bool SwTextFrame::FormatLine( SwTextFormatter &rLine, 
const bool bPrev )
                 rRepaint.Top( nTmpTop );
             if( !rLine.IsUnclipped() || nTmpBottom > rRepaint.Bottom() )
             {
-                rRepaint.Bottom( nTmpBottom - 1 );
+                rRepaint.Bottom(nTmpBottom - 1_twip);
                 rLine.SetUnclipped( true );
             }
         }
@@ -1521,7 +1521,7 @@ bool SwTextFrame::FormatLine( SwTextFormatter &rLine, 
const bool bPrev )
         {
             if( !rLine.IsUnclipped() || nBottom > rRepaint.Bottom() )
             {
-                rRepaint.Bottom( nBottom - 1 );
+                rRepaint.Bottom(nBottom - 1_twip);
                 rLine.SetUnclipped( false );
             }
         }
diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx
index d18336432118..6a036ae95679 100644
--- a/sw/source/core/text/guess.cxx
+++ b/sw/source/core/text/guess.cxx
@@ -802,7 +802,7 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, 
SwTextFormatInfo &rInf,
         {
             const TextFrameIndex nHangingLen = m_nBreakPos - m_nCutPos;
             SwPositiveSize aTmpSize = rInf.GetTextSize( &rSI, m_nCutPos, 
nHangingLen );
-            aTmpSize.Width(aTmpSize.Width() + nLeftRightBorderSpace);
+            aTmpSize.Width(aTmpSize.Width() + SwTwips(nLeftRightBorderSpace));
             OSL_ENSURE( !m_pHanging, "A hanging portion is hanging around" );
             m_pHanging.reset( new SwHangingPortion( std::move(aTmpSize) ) );
             m_pHanging->SetLen( nHangingLen );
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index 692be2c2da41..f5e717e1dfba 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -765,7 +765,7 @@ void SwTextPaintInfo::DrawText_( const OUString &rText, 
const SwLinePortion &rPo
         aDrawInf.SetPos( aPoint );
         aDrawInf.SetSize( aSize );
         aDrawInf.SetAscent( rPor.GetAscent() );
-        aDrawInf.SetKern( bKern ? rPor.Width() : 0 );
+        aDrawInf.SetKern(bKern ? rPor.Width() : SwTwips(0));
         aDrawInf.SetWrong( bTmpWrong ? m_pWrongList : nullptr );
         aDrawInf.SetGrammarCheck( bTmpGrammarCheck ? m_pGrammarCheckList : 
nullptr );
         aDrawInf.SetSmartTags( bTmpSmart ? m_pSmartTags : nullptr );
diff --git a/sw/source/core/text/itradj.cxx b/sw/source/core/text/itradj.cxx
index c8abfee4868a..b2fc72614b69 100644
--- a/sw/source/core/text/itradj.cxx
+++ b/sw/source/core/text/itradj.cxx
@@ -35,7 +35,7 @@
 #include "portab.hxx"
 #include <memory>
 
-#define MIN_TAB_WIDTH 60
+constexpr SwTwips MIN_TAB_WIDTH(60);
 
 using namespace ::com::sun::star;
 
@@ -478,7 +478,7 @@ SwTwips SwTextAdjuster::CalcKanaAdj( SwLineLayout* pCurrent 
)
                 nRest = ! bNoCompression &&
                         ( pPos->Width() > MIN_TAB_WIDTH ) ?
                         pPos->Width() - MIN_TAB_WIDTH :
-                        0;
+                        SwTwips(0);
 
                 // for simplifying the handling of left, right ... tabs,
                 // we do expand portions, which are lying behind
@@ -586,7 +586,7 @@ SwMarginPortion *SwTextAdjuster::CalcRightMargin( 
SwLineLayout *pCurrent,
             pLast = pFly;
             if( pFly->GetFix() > nPrtWidth )
                 pFly->Width( ( pFly->GetFix() - nPrtWidth) + pFly->Width() + 
1);
-            nPrtWidth += pFly->Width() + 1;
+            nPrtWidth += pFly->Width() + 1_twip;
             aCurrRect.Left( nLeftMar + nPrtWidth );
             pFly = CalcFlyPortion( nRealWidth, aCurrRect );
         }
@@ -851,7 +851,7 @@ void SwTextAdjuster::CalcDropRepaint()
         rRepaint.Top( Y() );
     for( sal_Int32 i = 1; i < GetDropLines(); ++i )
         NextLine();
-    const SwTwips nBottom = Y() + GetLineHeight() - 1;
+    const SwTwips nBottom = Y() + GetLineHeight() - 1_twip;
     if( rRepaint.Bottom() < nBottom )
         rRepaint.Bottom( nBottom );
 }
diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx
index 1a8c500ef92f..be7774b38614 100644
--- a/sw/source/core/text/itrcrsr.cxx
+++ b/sw/source/core/text/itrcrsr.cxx
@@ -100,7 +100,7 @@ static void lcl_GetCharRectInsideField( SwTextSizeInfo& 
rInf, SwRect& rOrig,
             const_cast<SwLinePortion*>(pPor)->SetLen(TextFrameIndex(nLen - 1));
             const SwTwips nX1 = pPor->GetLen() ?
                                 pPor->GetTextSize( rInf ).Width() :
-                                0;
+                                SwTwips(0);
 
             SwTwips nX2 = 0;
             if ( rCMS.m_bRealWidth )
@@ -112,16 +112,14 @@ static void lcl_GetCharRectInsideField( SwTextSizeInfo& 
rInf, SwRect& rOrig,
             const_cast<SwLinePortion*>(pPor)->SetLen( nOldLen );
 
             rOrig.Pos().AdjustX(nX1 );
-            rOrig.Width( ( nX2 > nX1 ) ?
-                         ( nX2 - nX1 ) :
-                           1 );
+            rOrig.Width((nX2 > nX1) ? nX2 - nX1 : SwTwips(1));
         }
     }
     else
     {
         // special cases: no common fields, e.g., graphic number portion,
         // FlyInCntPortions, Notes
-        rOrig.Width( rCMS.m_bRealWidth && rPor.Width() ? rPor.Width() : 1 );
+        rOrig.Width(rCMS.m_bRealWidth && rPor.Width() ? rPor.Width() : 
SwTwips(1));
     }
 }
 
@@ -239,7 +237,7 @@ void SwTextMargin::CtorInitTextMargin( SwTextFrame 
*pNewFrame, SwTextSizeInfo *p
     {
         mnLeft = m_pFrame->getFramePrintArea().Left() + 
m_pFrame->getFrameArea().Left();
         if( mnLeft >= mnRight )   // e.g. with large paragraph indentations in 
slim table columns
-            mnRight = mnLeft + 1; // einen goennen wir uns immer
+            mnRight = mnLeft + 1_twip; // einen goennen wir uns immer
     }
 
     if( m_pFrame->IsFollow() && m_pFrame->GetOffset() )
@@ -495,7 +493,7 @@ void SwTextCursor::GetEndCharRect(SwRect* pOrig, const 
TextFrameIndex nOfst,
     pOrig->Pos( GetTopLeft() );
     pOrig->SSize( aCharSize );
     pOrig->Pos().AdjustX(nLast );
-    const SwTwips nTmpRight = Right() - 1;
+    const SwTwips nTmpRight = Right() - 1_twip;
     if( pOrig->Left() > nTmpRight )
         pOrig->Pos().setX( nTmpRight );
 
@@ -809,9 +807,8 @@ void SwTextCursor::GetCharRect_( SwRect* pOrig, 
TextFrameIndex const nOfst,
 
                         if ( bChgHeight )
                         {
-                            m_pCurr->Height( pOldCurr->Height() - nRubyHeight 
);
-                            m_pCurr->SetRealHeight( pOldCurr->GetRealHeight() -
-                                                  nRubyHeight );
+                            m_pCurr->Height(pOldCurr->Height() - 
SwTwips(nRubyHeight));
+                            m_pCurr->SetRealHeight(pOldCurr->GetRealHeight() - 
SwTwips(nRubyHeight));
                         }
 
                         SwLayoutModeModifier aLayoutModeModifier( 
*GetInfo().GetOut() );
@@ -1399,7 +1396,7 @@ TextFrameIndex 
SwTextCursor::GetModelPositionForViewPoint( SwPosition *pPos, con
     SwTwips x = rPoint.X();
     const SwTwips nLeftMargin  = GetLineStart();
     SwTwips nRightMargin = GetLineEnd() +
-        ( GetCurr()->IsHanging() ? GetCurr()->GetHangingMargin() : 0 );
+        (GetCurr()->IsHanging() ? GetCurr()->GetHangingMargin() : SwTwips(0));
     if( nRightMargin == nLeftMargin )
         nRightMargin += 30;
 
@@ -1469,7 +1466,7 @@ TextFrameIndex 
SwTextCursor::GetModelPositionForViewPoint( SwPosition *pPos, con
         nWidth30 = 0;
     else
         nWidth30 = ! nWidth && pPor->GetLen() && pPor->InToxRefOrFieldGrp() ?
-                     30 :
+                     SwTwips(30) :
                      nWidth;
 
     while (ConsiderNextPortionForCursorOffset(pPor, nWidth30, nX))
@@ -1512,8 +1509,7 @@ TextFrameIndex 
SwTextCursor::GetModelPositionForViewPoint( SwPosition *pPos, con
             nWidth30 = 0;
         else
             nWidth30 = ! nWidth && pPor->GetLen() && 
pPor->InToxRefOrFieldGrp() ?
-                         30 :
-                         nWidth;
+                         SwTwips(30) : nWidth;
         if( !pPor->IsFlyPortion() && !pPor->IsMarginPortion() )
             bLastHyph = pPor->InHyphGrp();
     }
@@ -1541,7 +1537,7 @@ TextFrameIndex 
SwTextCursor::GetModelPositionForViewPoint( SwPosition *pPos, con
 
     if( bFieldInfo && ( nWidth30 < nX || bRightOver || bLeftOver ||
         ( pPor->InNumberGrp() && !pPor->IsFootnoteNumPortion() ) ||
-        ( pPor->IsMarginPortion() && nWidth > nX + 30 ) ) )
+        ( pPor->IsMarginPortion() && nWidth > nX + 30_twip ) ) )
         pCMS->m_bPosCorr = true;
 
     // #i27615#
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 2d19e046430f..a43320910eb8 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -257,7 +257,7 @@ SwLinePortion *SwTextFormatter::Underflow( SwTextFormatInfo 
&rInf )
 
     // line width is adjusted, so that pPor does not fit to current
     // line anymore
-    rInf.Width( rInf.X() + (pPor->Width() ? pPor->Width() - 1 : 0) );
+    rInf.Width( rInf.X() + (pPor->Width() ? pPor->Width() - 1_twip : 
SwTwips(0)) );
     rInf.SetLen( pPor->GetLen() );
     rInf.SetFull( false );
     if( pFly )
@@ -592,7 +592,7 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo &rInf 
)
             if ( nOfst )
             {
                 const sal_uLong i = ( nOfst > 0 ) ?
-                                ( ( nOfst - 1 ) / nGridWidth + 1 ) :
+                                ( (nOfst - 1_twip) / nGridWidth + 1 ) :
                                 0;
                 const SwTwips nKernWidth = i * nGridWidth - nOfst;
                 const SwTwips nRestWidth = rInf.Width() - rInf.X();
@@ -736,7 +736,7 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo &rInf 
)
                 }
 
                 const SwTwips i = nSumWidth ?
-                                 ( nSumWidth - 1 ) / nGridWidth + 1 :
+                                 ( nSumWidth - 1_twip ) / nGridWidth + 1 :
                                  0;
                 const SwTwips nTmpWidth = i * nGridWidth;
                 const SwTwips nKernWidth = std::min(nTmpWidth - nSumWidth, 
nRestWidth);
@@ -912,7 +912,7 @@ void SwTextFormatter::CalcAscent( SwTextFormatInfo &rInf, 
SwLinePortion *pPor )
     if( pPor->InTextGrp() && bCalc )
     {
         pPor->SetAscent(pPor->GetAscent() +
-            rInf.GetFont()->GetTopBorderSpace());
+            SwTwips(rInf.GetFont()->GetTopBorderSpace()));
         pPor->Height(pPor->Height() +
             rInf.GetFont()->GetTopBorderSpace() +
             rInf.GetFont()->GetBottomBorderSpace() );
@@ -1430,7 +1430,7 @@ SwTextPortion *SwTextFormatter::NewTextPortion( 
SwTextFormatInfo &rInf )
     CalcAscent( rInf, pPor );
 
     const SwFont* pTmpFnt = rInf.GetFont();
-    auto nCharWidthGuess = std::min(pTmpFnt->GetHeight(), pPor->GetAscent()) / 
8;
+    auto nCharWidthGuess = std::min(SwTwips(pTmpFnt->GetHeight()), 
pPor->GetAscent()) / 8;
     if (!nCharWidthGuess)
         nCharWidthGuess = 1;
     auto nExpect = rInf.GetIdx() + TextFrameIndex(rInf.GetLineWidth() / 
nCharWidthGuess);
@@ -2080,8 +2080,8 @@ TextFrameIndex SwTextFormatter::FormatLine(TextFrameIndex 
const nStartPos)
         if( GetInfo().IsStop() )
         {
             m_pCurr->SetLen(TextFrameIndex(0));
-            m_pCurr->Height( GetFrameRstHeight() + 1, false );
-            m_pCurr->SetRealHeight( GetFrameRstHeight() + 1 );
+            m_pCurr->Height(GetFrameRstHeight() + 1_twip, false);
+            m_pCurr->SetRealHeight(GetFrameRstHeight() + 1_twip);
 
             // Don't oversize the line in case of split flys, so we don't try 
to move the anchor
             // of a precede fly forward, next to its follow.
@@ -2274,7 +2274,7 @@ void SwTextFormatter::CalcRealHeight( bool bNewLine )
                     // require this and it seems harmless to emulate.
                     if (pSpace->GetLineHeight() == 0)
                     {
-                        nLineHeight = m_pCurr->Height() + nRubyHeight;
+                        nLineHeight = m_pCurr->Height() + SwTwips(nRubyHeight);
                     }
 
                     if (nLineHeight < pSpace->GetLineHeight())
@@ -2293,9 +2293,9 @@ void SwTextFormatter::CalcRealHeight( bool bNewLine )
         }
 
         const SwTwips nAsc = m_pCurr->GetAscent() +
-                      ( bRubyTop ?
-                       ( nLineHeight - m_pCurr->Height() + nRubyHeight ) / 2 :
-                       ( nLineHeight - m_pCurr->Height() - nRubyHeight ) / 2 );
+                      (bRubyTop ?
+                       (nLineHeight - m_pCurr->Height() + 
SwTwips(nRubyHeight)) / 2 :
+                       (nLineHeight - m_pCurr->Height() - 
SwTwips(nRubyHeight)) / 2);
 
         m_pCurr->Height( nLineHeight, false );
         m_pCurr->SetAscent( nAsc );
@@ -2512,7 +2512,7 @@ SwTwips SwTextFormatter::CalcBottomLine() const
             if( bRepaint )
             {
                 const_cast<SwRepaint&>(GetInfo().GetParaPortion()
-                    ->GetRepaint()).Bottom( nRet-1 );
+                    ->GetRepaint()).Bottom(nRet - 1_twip);
                 const_cast<SwTextFormatInfo&>(GetInfo()).SetPaintOfst( 0 );
             }
         }
@@ -2893,7 +2893,7 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo 
&rInf )
     }
 
     const tools::Long nLeftMar = GetLeftMargin();
-    const tools::Long nLeftMin = (rInf.X() || GetDropLeft()) ? nLeftMar : 
GetLeftMin();
+    const tools::Long nLeftMin = (rInf.X() || GetDropLeft()) ? 
SwTwips(nLeftMar) : GetLeftMin();
 
     SwRect aLine( rInf.X() + nLeftMin, nTop, rInf.RealWidth() - rInf.X()
                   + nLeftMar - nLeftMin , nHeight );
@@ -3133,7 +3133,7 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo 
&rInf )
 
     const SwTwips i = nTmpWidth / nGridWidth + 1;
 
-    const SwTwips nNewWidth = ( i - 1 ) * nGridWidth - nOfst;
+    const SwTwips nNewWidth = ( i - 1_twip ) * nGridWidth - nOfst;
     if ( nNewWidth > 0 )
         rInf.Width( nNewWidth );
     else
diff --git a/sw/source/core/text/itrpaint.cxx b/sw/source/core/text/itrpaint.cxx
index 6e9d48a3a8f3..65b7a388d56d 100644
--- a/sw/source/core/text/itrpaint.cxx
+++ b/sw/source/core/text/itrpaint.cxx
@@ -388,13 +388,13 @@ void SwTextPainter::DrawTextLine( const SwRect &rPaint, 
SwSaveClip &rClip,
         }
 
         // We calculate a separate font for underlining.
-        CheckSpecialUnderline( pPor, bAdjustBaseLine ? nOldY : 0 );
+        CheckSpecialUnderline( pPor, bAdjustBaseLine ? nOldY : SwTwips(0));
         SwUnderlineFont* pUnderLineFnt = GetInfo().GetUnderFnt();
         if ( pUnderLineFnt )
         {
             const Point aTmpPoint( GetInfo().X(),
                                    bAdjustBaseLine ?
-                                   pUnderLineFnt->GetPos().Y() :
+                                   SwTwips(pUnderLineFnt->GetPos().Y()) :
                                    nLineBaseLine );
             pUnderLineFnt->SetPos( aTmpPoint );
         }
@@ -569,8 +569,8 @@ void SwTextPainter::DrawTextLine( const SwRect &rPaint, 
SwSaveClip &rClip,
                 // to show the terminating pilcrow at the correct position, 
and not before that
                 ( ( !( pEndTempl->GetNextPortion() && 
pEndTempl->GetNextPortion()->IsHolePortion() ) &&
                     std::abs( m_pCurr->Width() - 
m_pCurr->GetFirstPortion()->Width() ) <= 1 && m_pCurr->ExtraShrunkWidth() > 0 )
-                        ? m_pCurr->ExtraShrunkWidth() - m_pCurr->Width() : 0 ) 
+
-                    ( GetCurr()->IsHanging() ? GetCurr()->GetHangingMargin() : 
0 ) );
+                        ? m_pCurr->ExtraShrunkWidth() - m_pCurr->Width() : 
SwTwips(0) ) +
+                    ( GetCurr()->IsHanging() ? GetCurr()->GetHangingMargin() : 
SwTwips(0) ) );
             aEnd.Paint( GetInfo() );
             GetInfo().Y( nOldY );
         }
diff --git a/sw/source/core/text/itrtxt.cxx b/sw/source/core/text/itrtxt.cxx
index 1d1eed3e0837..93e7ecdc207b 100644
--- a/sw/source/core/text/itrtxt.cxx
+++ b/sw/source/core/text/itrtxt.cxx
@@ -249,11 +249,11 @@ SwTwips SwTextCursor::AdjustBaseLine( const SwLineLayout& 
rLine,
                 // centered inside the whole line.
 
                 //for text refactor
-                const sal_uInt16 nLineNet =  rLine.Height() - nRubyHeight;
+                const sal_uInt16 nLineNet =  rLine.Height() - 
SwTwips(nRubyHeight);
                 //const sal_uInt16 nLineNet = ( nPorHeight > nGridWidth ) ?
                  //                           rLine.Height() - nRubyHeight :
                  //                           nGridWidth;
-                nOfst += ( nLineNet - nPorHeight ) / 2;
+                nOfst += (SwTwips(nLineNet) - nPorHeight) / 2;
                 if ( bRubyTop )
                     nOfst += nRubyHeight;
             }
diff --git a/sw/source/core/text/itrtxt.hxx b/sw/source/core/text/itrtxt.hxx
index eb3a9a859854..74cdc0a987aa 100644
--- a/sw/source/core/text/itrtxt.hxx
+++ b/sw/source/core/text/itrtxt.hxx
@@ -188,7 +188,7 @@ public:
     bool IsLastBlock() const { return m_bLastBlock; }
     bool IsLastCenter() const { return m_bLastCenter; }
     SvxAdjust GetAdjust() const { return mnAdjust; }
-    SwTwips GetLineWidth() const { return Right() - GetLeftMargin() + 1; }
+    SwTwips GetLineWidth() const { return Right() - GetLeftMargin() + 1_twip; }
     SwTwips GetLeftMin() const { return std::min(mnFirst, mnLeft); }
     bool HasNegFirst() const { return mnFirst < mnLeft; }
 
@@ -332,7 +332,7 @@ inline SwTwips SwTextMargin::GetLeftMargin() const
 
 inline SwTwips SwTextMargin::Left() const
 {
-    return (mnDropLines >= m_nLineNr && 1 != m_nLineNr) ? mnFirst + mnDropLeft 
: mnLeft;
+    return (mnDropLines >= m_nLineNr && 1 != m_nLineNr) ? SwTwips(mnFirst + 
mnDropLeft) : mnLeft;
 }
 
 
diff --git a/sw/source/core/text/porexp.cxx b/sw/source/core/text/porexp.cxx
index afdf71da21c0..54932c32ab80 100644
--- a/sw/source/core/text/porexp.cxx
+++ b/sw/source/core/text/porexp.cxx
@@ -292,7 +292,7 @@ void SwPostItsPortion::Paint( const SwTextPaintInfo &rInf ) 
const
 SwTwips SwPostItsPortion::GetViewWidth(const SwTextSizeInfo& rInf) const
 {
     // Unbelievable: PostIts are always visible
-    return rInf.OnWin() ? SwViewOption::GetPostItsWidth( rInf.GetOut() ) : 0;
+    return rInf.OnWin() ? SwViewOption::GetPostItsWidth( rInf.GetOut() ) : 
SwTwips(0);
 }
 
 bool SwPostItsPortion::Format( SwTextFormatInfo &rInf )
diff --git a/sw/source/core/text/porfld.cxx b/sw/source/core/text/porfld.cxx
index b3355286c205..120ed5d5cb95 100644
--- a/sw/source/core/text/porfld.cxx
+++ b/sw/source/core/text/porfld.cxx
@@ -606,11 +606,11 @@ bool SwNumberPortion::Format( SwTextFormatInfo &rInf )
                  
rInf.GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::NO_GAP_AFTER_NOTE_NUMBER)))
             {
                 nDiff = rInf.Left()
-                        + rInf.GetTextFrame()
+                        + SwTwips(rInf.GetTextFrame()
                               ->GetTextNodeForParaProps()
                               ->GetSwAttrSet()
                               .GetFirstLineIndent()
-                              .ResolveTextFirstLineOffset({})
+                              .ResolveTextFirstLineOffset({}))
                         - rInf.First() + rInf.ForcedLeftMargin();
             }
             else
@@ -780,7 +780,7 @@ void SwNumberPortion::Paint( const SwTextPaintInfo &rInf ) 
const
                 rInf.GetUnderFnt()->SetPos( aNewPos );
             }
 
-            pThis->Width( nOldWidth - nSpaceOffs + 12 );
+            pThis->Width(nOldWidth - nSpaceOffs + 12_twip);
             {
                 SwTextSlot aDiffText( &aInf, this, true, false, u"  "_ustr );
                 aInf.DrawText( *this, aInf.GetLen(), true );
@@ -804,7 +804,7 @@ SwBulletPortion::SwBulletPortion( const sal_UCS4 cBullet,
     SetWhichPor( PortionType::Bullet );
 }
 
-#define GRFNUM_SECURE 10
+constexpr SwTwips GRFNUM_SECURE(10);
 
 SwGrfNumPortion::SwGrfNumPortion(
         const OUString& rGraphicFollowedBy,
@@ -886,7 +886,7 @@ bool SwGrfNumPortion::Format( SwTextFormatInfo &rInf )
     const bool bFull = rInf.Width() < rInf.X() + Width();
     const bool bFly = rInf.GetFly() ||
         ( rInf.GetLast() && rInf.GetLast()->IsFlyPortion() );
-    SetAscent( GetRelPos() > 0 ? GetRelPos() : 0 );
+    SetAscent(GetRelPos() > 0 ? GetRelPos() : SwTwips(0));
     if( GetAscent() > Height() )
         Height( GetAscent() );
 
@@ -904,7 +904,7 @@ bool SwGrfNumPortion::Format( SwTextFormatInfo &rInf )
     rInf.SetNumDone( true );
 //    long nDiff = rInf.Left() - rInf.First() + rInf.ForcedLeftMargin();
     tools::Long nDiff = mbLabelAlignmentPosAndSpaceModeActive
-                 ? 0
+                 ? SwTwips(0)
                  : rInf.Left() - rInf.First() + rInf.ForcedLeftMargin();
     // The TextPortion should at least always start on the
     // left margin
@@ -977,7 +977,7 @@ void SwGrfNumPortion::Paint( const SwTextPaintInfo &rInf ) 
const
 
     if( m_bReplace )
     {
-        const tools::Long nTmpH = GetNextPortion() ? 
GetNextPortion()->GetAscent() : 120;
+        const tools::Long nTmpH = GetNextPortion() ? 
GetNextPortion()->GetAscent() : SwTwips(120);
         aSize = Size( nTmpH, nTmpH );
         aPos.setY( rInf.Y() - nTmpH );
     }
@@ -1313,7 +1313,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf )
     // the portion grows. This looks better, if there's a character background.
     if( GetAscent() < nMainAscent )
     {
-        Height( Height() + nMainAscent - GetAscent() );
+        Height( Height() + SwTwips(nMainAscent) - GetAscent() );
         SetAscent( nMainAscent );
     }
     if( Height() < nMainAscent + nMainDescent )
diff --git a/sw/source/core/text/porfly.cxx b/sw/source/core/text/porfly.cxx
index d4612cbd26d0..cc739e41da64 100644
--- a/sw/source/core/text/porfly.cxx
+++ b/sw/source/core/text/porfly.cxx
@@ -123,7 +123,7 @@ bool SwFlyCntPortion::Format( SwTextFormatInfo &rInf )
-e 
... etc. - the rest is truncated

Reply via email to