Rebased ref, commits from common ancestor:
commit 1c240218323b100844f55a61fe918df8c3431e87
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Jun 11 22:39:19 2025 +0200
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Wed Jun 11 22:39:45 2025 +0200

    svx: Simplify multiple similar constructors of SdrTextObj into one
    
    Change-Id: I8ca01d8dedb3232ac6763bd554a9de2b6cca0b0c

diff --git a/filter/source/msfilter/msdffimp.cxx 
b/filter/source/msfilter/msdffimp.cxx
index a972ccf5ba00..38ec1addcf2b 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -5370,10 +5370,7 @@ rtl::Reference<SdrObject> 
SvxMSDffManager::ProcessObj(SvStream& rSt,
                 }
             }
 
-            pTextObj = new SdrRectObj(
-                *pSdrModel,
-                SdrObjKind::Text,
-                rTextRect);
+            pTextObj = new SdrRectObj(*pSdrModel, rTextRect, SdrObjKind::Text);
             pTextImpRec = new SvxMSDffImportRec(*pImpRec);
             bDeleteTextImpRec = true;
 
diff --git a/filter/source/msfilter/svdfppt.cxx 
b/filter/source/msfilter/svdfppt.cxx
index 3f69def9cf52..3f3fb724100e 100644
--- a/filter/source/msfilter/svdfppt.cxx
+++ b/filter/source/msfilter/svdfppt.cxx
@@ -1068,7 +1068,7 @@ rtl::Reference<SdrObject> SdrEscherImport::ProcessObj( 
SvStream& rSt, DffObjData
                         pRet = nullptr;
                     }
                     pTObj = new SdrRectObj(
-                        *pSdrModel,
+                        *pSdrModel, tools::Rectangle(),
                         eTextKind != SdrObjKind::Rectangle ? eTextKind : 
SdrObjKind::Text);
                     SfxItemSet aSet( pSdrModel->GetItemPool() );
                     if ( !pRet )
diff --git a/include/svx/svdocapt.hxx b/include/svx/svdocapt.hxx
index 16683fffd05b..7bf457fc59e0 100644
--- a/include/svx/svdocapt.hxx
+++ b/include/svx/svdocapt.hxx
@@ -73,12 +73,11 @@ private:
 
 public:
     SAL_DLLPRIVATE SdrCaptionObj(SdrModel& rSdrModel);
+
     // Copy constructor
     SAL_DLLPRIVATE SdrCaptionObj(SdrModel& rSdrModel, SdrCaptionObj const & 
rSource);
-    SdrCaptionObj(
-        SdrModel& rSdrModel,
-        const tools::Rectangle& rRect,
-        const Point& rTail);
+
+    SdrCaptionObj(SdrModel& rSdrModel, const tools::Rectangle& rRect, const 
Point& rTail);
 
     // tdf#118662 getter for SuppressGetBitmap
     bool isSuppressGetBitmap() const { return mbSuppressGetBitmap; }
diff --git a/include/svx/svdorect.hxx b/include/svx/svdorect.hxx
index 7b1c1fca7629..f0f2844246bc 100644
--- a/include/svx/svdorect.hxx
+++ b/include/svx/svdorect.hxx
@@ -68,19 +68,9 @@ public:
      *
      * Constructor of a rectangular drawing object
      */
-    SdrRectObj(SdrModel& rSdrModel);
-    SdrRectObj(
-        SdrModel& rSdrModel,
-        const tools::Rectangle& rRect);
-
-    // Constructor of a text frame
-    SdrRectObj(
-        SdrModel& rSdrModel,
-        SdrObjKind eNewTextKind);
-    SdrRectObj(
-        SdrModel& rSdrModel,
-        SdrObjKind eNewTextKind,
-        const tools::Rectangle& rRect);
+    SdrRectObj(SdrModel& rSdrModel,
+               const tools::Rectangle& rRectangle = tools::Rectangle(),
+               SdrObjKind eTextKind = SdrObjKind::Text); // Onnly valid types 
Text, OutlineText, TitleText
 
     // Copy constructor
     SdrRectObj(SdrModel& rSdrModel, SdrRectObj const & rSource);
diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index 5f8ed57e9e02..6193120c5889 100644
--- a/include/svx/svdotext.hxx
+++ b/include/svx/svdotext.hxx
@@ -345,23 +345,12 @@ protected:
     // and object sizes
     virtual void AdaptTextMinSize();
 
-    // constructors for labeled graphical objects
-    SdrTextObj(SdrModel& rSdrModel);
-    SdrTextObj(
-        SdrModel& rSdrModel,
-        const tools::Rectangle& rNewRect);
-
-    // constructors for text frames
-    SdrTextObj(
-        SdrModel& rSdrModel,
-        SdrObjKind eNewTextKind);
-    SdrTextObj(
-        SdrModel& rSdrModel,
-        SdrObjKind eNewTextKind,
-        const tools::Rectangle& rNewRect);
-
+    // constructor
+    SdrTextObj(SdrModel& rSdrModel,
+               const tools::Rectangle& rNewRect = tools::Rectangle(),
+               std::optional<SdrObjKind> oeTextKind = std::nullopt);
     // copy constructor
-    SdrTextObj(SdrModel& rSdrModel, SdrTextObj const & rSource);
+    SdrTextObj(SdrModel& rSdrModel, SdrTextObj const& rSource);
 
     // protected destructor
     virtual ~SdrTextObj() override;
diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx
index 5ae97e8bdf21..6acc1abb983f 100644
--- a/sd/source/core/sdpage.cxx
+++ b/sd/source/core/sdpage.cxx
@@ -298,7 +298,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool 
bVertical, const ::t
     {
         case PresObjKind::Title:
         {
-            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), 
SdrObjKind::TitleText);
+            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), 
tools::Rectangle(), SdrObjKind::TitleText);
 
             if (mbMaster)
             {
@@ -309,7 +309,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool 
bVertical, const ::t
 
         case PresObjKind::Outline:
         {
-            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), 
SdrObjKind::OutlineText);
+            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), 
tools::Rectangle(), SdrObjKind::OutlineText);
 
             if (mbMaster)
             {
@@ -320,7 +320,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool 
bVertical, const ::t
 
         case PresObjKind::Notes:
         {
-            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), 
SdrObjKind::Text);
+            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), 
tools::Rectangle(), SdrObjKind::Text);
 
             if (mbMaster)
             {
@@ -331,7 +331,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool 
bVertical, const ::t
 
         case PresObjKind::Text:
         {
-            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), 
SdrObjKind::Text);
+            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), 
tools::Rectangle(), SdrObjKind::Text);
         }
         break;
 
@@ -433,7 +433,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool 
bVertical, const ::t
         case PresObjKind::DateTime:
         case PresObjKind::SlideNumber:
         {
-            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), 
SdrObjKind::Text);
+            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), 
tools::Rectangle(), SdrObjKind::Text);
             bEmptyPresObj = false;
             bForceText = true;
         }
diff --git a/sd/source/ui/annotations/annotationmanager.cxx 
b/sd/source/ui/annotations/annotationmanager.cxx
index f480487a4786..c22724090d15 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -1076,7 +1076,7 @@ void AnnotationManagerImpl::SyncAnnotationObjects()
         }
         else if (rInfo.meType == sdr::annotation::AnnotationType::FreeText)
         {
-            rtl::Reference<SdrRectObj> pRectangleObject = new 
SdrRectObj(rModel, SdrObjKind::Text, aRectangle);
+            rtl::Reference<SdrRectObj> pRectangleObject = new 
SdrRectObj(rModel, aRectangle, SdrObjKind::Text);
             pNewObject = pRectangleObject;
 
             applyAnnotationCommon(*pNewObject, xAnnotation);
diff --git a/sd/source/ui/func/fuinsfil.cxx b/sd/source/ui/func/fuinsfil.cxx
index aa26cb8609f9..011d9245a4f4 100644
--- a/sd/source/ui/func/fuinsfil.cxx
+++ b/sd/source/ui/func/fuinsfil.cxx
@@ -486,8 +486,7 @@ void FuInsertFile::InsTextOrRTFinDrMode(SfxMedium* pMedium)
         else
         {
             rtl::Reference<SdrRectObj> pTO = new SdrRectObj(
-                mpView->getSdrModelFromSdrView(),
-                SdrObjKind::Text);
+                mpView->getSdrModelFromSdrView(), ::tools::Rectangle(), 
SdrObjKind::Text);
             pTO->SetOutlinerParaObject(std::move(pOPO));
 
             const bool bUndo = mpView->IsUndoEnabled();
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index a9d14dabb16d..cb49d368a7d8 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -605,7 +605,7 @@ public:
 
             rtl::Reference<SdrRectObj> pObject = new SdrRectObj(
                 *m_rDrawViewShell.GetDoc(), // TTTT should be reference
-                SdrObjKind::Text);
+                ::tools::Rectangle(), SdrObjKind::Text);
             pObject->SetMergedItem(makeSdrTextAutoGrowWidthItem(true));
             pObject->SetOutlinerParaObject(pOutliner->CreateParaObject());
             pMasterPage->InsertObject(pObject.get());
@@ -3118,8 +3118,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
                 std::optional<OutlinerParaObject> pOutlParaObject = 
pOutl->CreateParaObject();
 
                 rtl::Reference<SdrRectObj> pRectObj = new SdrRectObj(
-                    *GetDoc(),
-                    SdrObjKind::Text);
+                    *GetDoc(), ::tools::Rectangle(), SdrObjKind::Text);
                 pRectObj->SetMergedItem(makeSdrTextAutoGrowWidthItem(true));
 
                 pOutl->UpdateFields();
diff --git a/sd/source/ui/view/drviewse.cxx b/sd/source/ui/view/drviewse.cxx
index 718b634f22b4..3db14bad6062 100644
--- a/sd/source/ui/view/drviewse.cxx
+++ b/sd/source/ui/view/drviewse.cxx
@@ -1593,8 +1593,7 @@ void DrawViewShell::InsertURLField(const OUString& rURL, 
const OUString& rText,
         std::optional<OutlinerParaObject> pOutlParaObject = 
pOutl->CreateParaObject();
 
         rtl::Reference<SdrRectObj> pRectObj = new SdrRectObj(
-            GetView()->getSdrModelFromSdrView(),
-            SdrObjKind::Text);
+            GetView()->getSdrModelFromSdrView(), ::tools::Rectangle(), 
SdrObjKind::Text);
 
         pOutl->UpdateFields();
         pOutl->SetUpdateLayout( true );
diff --git a/svx/source/sdr/contact/viewcontactofgraphic.cxx 
b/svx/source/sdr/contact/viewcontactofgraphic.cxx
index b9f7755b5a03..c72040f5e05b 100644
--- a/svx/source/sdr/contact/viewcontactofgraphic.cxx
+++ b/svx/source/sdr/contact/viewcontactofgraphic.cxx
@@ -246,7 +246,7 @@ namespace sdr::contact
                 // needed and can be deleted.
 
                 // create temp RectObj as TextObj and set needed attributes
-                rtl::Reference<SdrRectObj> pRectObj(new 
SdrRectObj(GetGrafObject().getSdrModelFromSdrObject(), SdrObjKind::Text));
+                rtl::Reference<SdrRectObj> pRectObj(new 
SdrRectObj(GetGrafObject().getSdrModelFromSdrObject(), tools::Rectangle(), 
SdrObjKind::Text));
                 pRectObj->NbcSetText(aDraftText);
                 pRectObj->SetMergedItem(SvxColorItem(COL_LIGHTRED, 
EE_CHAR_COLOR));
 
diff --git a/svx/source/svdraw/svdedtv2.cxx b/svx/source/svdraw/svdedtv2.cxx
index 1dbc7afd83f1..5dc8998e9c87 100644
--- a/svx/source/svdraw/svdedtv2.cxx
+++ b/svx/source/svdraw/svdedtv2.cxx
@@ -1279,7 +1279,7 @@ void SdrEditView::CombineMarkedTextObjects()
 
     if ( rMarkList.GetMarkCount() > 1 )
     {
-        rtl::Reference<SdrRectObj> pReplacement = new SdrRectObj( 
getSdrModelFromSdrView(), SdrObjKind::Text );
+        rtl::Reference<SdrRectObj> pReplacement = new SdrRectObj( 
getSdrModelFromSdrView(), tools::Rectangle(), SdrObjKind::Text );
         pReplacement->SetOutlinerParaObject( rDrawOutliner.CreateParaObject() 
);
         pReplacement->SetSnapRect( GetMarkedObjRect() );
 
diff --git a/svx/source/svdraw/svdfmtf.cxx b/svx/source/svdraw/svdfmtf.cxx
index 8cb0c248d59d..3552b8b21525 100644
--- a/svx/source/svdraw/svdfmtf.cxx
+++ b/svx/source/svdraw/svdfmtf.cxx
@@ -1039,10 +1039,7 @@ void ImpSdrGDIMetaFileImport::ImportText( const Point& 
rPos, const OUString& rSt
         aPos.AdjustY( -nTextHeight );
 
     tools::Rectangle aTextRect( aPos, aSize );
-    rtl::Reference<SdrRectObj> pText = new SdrRectObj(
-        *mpModel,
-        SdrObjKind::Text,
-        aTextRect);
+    rtl::Reference<SdrRectObj> pText = new SdrRectObj(*mpModel, aTextRect, 
SdrObjKind::Text);
 
     pText->SetMergedItem ( makeSdrTextUpperDistItem (0));
     pText->SetMergedItem ( makeSdrTextLowerDistItem (0));
@@ -1417,7 +1414,8 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaGradientAction 
const & rAct)
             floor(aRange.getMinX()),
             floor(aRange.getMinY()),
             ceil(aRange.getMaxX()),
-            ceil(aRange.getMaxY())));
+            ceil(aRange.getMaxY())),
+        SdrObjKind::Text);
     // #i125211# Use the ranges from the SdrObject to create a new empty 
SfxItemSet
     SfxItemSet aGradientAttr(mpModel->GetItemPool(), 
pRect->GetMergedItemSet().GetRanges());
     const XFillGradientItem aXFillGradientItem(
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index da26a8852a88..69d889e6a3d8 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -3411,16 +3411,13 @@ rtl::Reference<SdrObject> SdrObjFactory::MakeNewObject(
                 if(nullptr != pSnapRect)
                 {
                     pObj = new SdrRectObj(
-                        rSdrModel,
-                        nIdentifier,
-                        *pSnapRect);
+                        rSdrModel, *pSnapRect, nIdentifier);
                     bSetSnapRect = false;
                 }
                 else
                 {
                     pObj = new SdrRectObj(
-                        rSdrModel,
-                        nIdentifier);
+                        rSdrModel, tools::Rectangle(), nIdentifier);
                 }
             }
             break;
diff --git a/svx/source/svdraw/svdocapt.cxx b/svx/source/svdraw/svdocapt.cxx
index d3032f6ba108..ea90f5f57cd7 100644
--- a/svx/source/svdraw/svdocapt.cxx
+++ b/svx/source/svdraw/svdocapt.cxx
@@ -180,14 +180,24 @@ std::unique_ptr<sdr::contact::ViewContact> 
SdrCaptionObj::CreateObjectSpecificVi
 
 
 SdrCaptionObj::SdrCaptionObj(SdrModel& rSdrModel)
-:   SdrRectObj(rSdrModel, SdrObjKind::Text),
-    maTailPoly(3),  // default size: 3 points = 2 lines
-    mbSpecialTextBoxShadow(false),
-    mbFixedTail(false),
-    mbSuppressGetBitmap(false)
+    : SdrRectObj(rSdrModel, tools::Rectangle(), SdrObjKind::Text)
+    , maTailPoly(3)  // default size: 3 points = 2 lines
+    , mbSpecialTextBoxShadow(false)
+    , mbFixedTail(false)
+    , mbSuppressGetBitmap(false)
 {
 }
 
+SdrCaptionObj::SdrCaptionObj(SdrModel& rSdrModel, const tools::Rectangle& 
rRect, const Point& rTail)
+    : SdrRectObj(rSdrModel, rRect, SdrObjKind::Text)
+    , maTailPoly(3)  // default size: 3 points = 2 lines
+    , mbSpecialTextBoxShadow(false)
+    , mbFixedTail(false)
+    , mbSuppressGetBitmap(false)
+{
+    maTailPoly[0] = maFixedTailPos = rTail;
+}
+
 SdrCaptionObj::SdrCaptionObj(SdrModel& rSdrModel, SdrCaptionObj const & 
rSource)
 :   SdrRectObj(rSdrModel, rSource),
     mbSuppressGetBitmap(false)
@@ -198,22 +208,7 @@ SdrCaptionObj::SdrCaptionObj(SdrModel& rSdrModel, 
SdrCaptionObj const & rSource)
     maFixedTailPos = rSource.maFixedTailPos;
 }
 
-SdrCaptionObj::SdrCaptionObj(
-    SdrModel& rSdrModel,
-    const tools::Rectangle& rRect,
-    const Point& rTail)
-:   SdrRectObj(rSdrModel, SdrObjKind::Text,rRect),
-    maTailPoly(3),  // default size: 3 points = 2 lines
-    mbSpecialTextBoxShadow(false),
-    mbFixedTail(false),
-    mbSuppressGetBitmap(false)
-{
-    maTailPoly[0]=maFixedTailPos=rTail;
-}
-
-SdrCaptionObj::~SdrCaptionObj()
-{
-}
+SdrCaptionObj::~SdrCaptionObj() = default;
 
 void SdrCaptionObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
 {
diff --git a/svx/source/svdraw/svdorect.cxx b/svx/source/svdraw/svdorect.cxx
index dfd04fd299b5..271f25340ab9 100644
--- a/svx/source/svdraw/svdorect.cxx
+++ b/svx/source/svdraw/svdorect.cxx
@@ -49,54 +49,24 @@ std::unique_ptr<sdr::contact::ViewContact> 
SdrRectObj::CreateObjectSpecificViewC
     return std::make_unique<sdr::contact::ViewContactOfSdrRectObj>(*this);
 }
 
-
-SdrRectObj::SdrRectObj(SdrModel& rSdrModel)
-:   SdrTextObj(rSdrModel)
+SdrRectObj::SdrRectObj(SdrModel& rSdrModel, const tools::Rectangle& 
rRectangle, SdrObjKind eTextKind)
+    : SdrTextObj(rSdrModel, rRectangle, eTextKind)
 {
-    m_bClosedObj=true;
+    DBG_ASSERT(meTextKind == SdrObjKind::Text ||
+               meTextKind == SdrObjKind::OutlineText || meTextKind == 
SdrObjKind::TitleText,
+               "SdrRectObj::SdrRectObj(SdrObjKind,...) can only be applied to 
text frames.");
+
+    m_bClosedObj = true;
 }
 
 SdrRectObj::SdrRectObj(SdrModel& rSdrModel, SdrRectObj const & rSource)
 :   SdrTextObj(rSdrModel, rSource)
 {
-    m_bClosedObj=true;
+    m_bClosedObj = true;
     mpXPoly = rSource.mpXPoly;
 }
 
-SdrRectObj::SdrRectObj(
-    SdrModel& rSdrModel,
-    const tools::Rectangle& rRect)
-:   SdrTextObj(rSdrModel, rRect)
-{
-    m_bClosedObj=true;
-}
-
-SdrRectObj::SdrRectObj(
-    SdrModel& rSdrModel,
-    SdrObjKind eNewTextKind)
-:   SdrTextObj(rSdrModel, eNewTextKind)
-{
-    DBG_ASSERT(meTextKind == SdrObjKind::Text ||
-               meTextKind == SdrObjKind::OutlineText || meTextKind == 
SdrObjKind::TitleText,
-               "SdrRectObj::SdrRectObj(SdrObjKind) can only be applied to text 
frames.");
-    m_bClosedObj=true;
-}
-
-SdrRectObj::SdrRectObj(
-    SdrModel& rSdrModel,
-    SdrObjKind eNewTextKind,
-    const tools::Rectangle& rRect)
-:   SdrTextObj(rSdrModel, eNewTextKind, rRect)
-{
-    DBG_ASSERT(meTextKind == SdrObjKind::Text ||
-               meTextKind == SdrObjKind::OutlineText || meTextKind == 
SdrObjKind::TitleText,
-               "SdrRectObj::SdrRectObj(SdrObjKind,...) can only be applied to 
text frames.");
-    m_bClosedObj=true;
-}
-
-SdrRectObj::~SdrRectObj()
-{
-}
+SdrRectObj::~SdrRectObj() = default;
 
 void SdrRectObj::SetXPolyDirty()
 {
@@ -525,6 +495,7 @@ SdrGluePoint SdrRectObj::GetCornerGluePoint(sal_uInt16 
nPosNum) const
     if (maGeo.m_nRotationAngle)
         RotatePoint(aPt, 
rRectangle.TopLeft(),maGeo.mfSinRotationAngle,maGeo.mfCosRotationAngle);
     aPt-=GetSnapRect().Center();
+
     SdrGluePoint aGP(aPt);
     aGP.SetPercent(false);
     return aGP;
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index f9e8d7d4c071..05dcbb9076f5 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -71,11 +71,11 @@ std::unique_ptr<sdr::contact::ViewContact> 
SdrTextObj::CreateObjectSpecificViewC
     return std::make_unique<sdr::contact::ViewContactOfTextObj>(*this);
 }
 
-SdrTextObj::SdrTextObj(SdrModel& rSdrModel)
+SdrTextObj::SdrTextObj(SdrModel& rSdrModel, const tools::Rectangle& 
rRectangle, std::optional<SdrObjKind> oeTextKind)
     : SdrAttrObj(rSdrModel)
     , mpEditingOutliner(nullptr)
-    , meTextKind(SdrObjKind::Text)
-    , maTextEditOffset(Point(0, 0))
+    , meTextKind(oeTextKind ? *oeTextKind : SdrObjKind::Text)
+    , maTextEditOffset(Point())
     , mbTextFrame(false)
     , mbNoShear(false)
     , mbTextSizeDirty(false)
@@ -84,7 +84,19 @@ SdrTextObj::SdrTextObj(SdrModel& rSdrModel)
     , mbTextAnimationAllowed(true)
     , mbInDownScale(false)
 {
-    // #i25616#
+    if (!rRectangle.IsEmpty())
+    {
+        tools::Rectangle aRectangle(rRectangle);
+        ImpJustifyRect(aRectangle);
+        setRectangle(aRectangle);
+    }
+
+    if (oeTextKind)
+    {
+        mbTextFrame = true;
+        mbNoShear = true;
+    }
+
     mbSupportTextIndentingOnLineWidthChange = true;
 }
 
@@ -136,66 +148,6 @@ SdrTextObj::SdrTextObj(SdrModel& rSdrModel, SdrTextObj 
const & rSource)
     ImpSetTextStyleSheetListeners();
 }
 
-SdrTextObj::SdrTextObj(SdrModel& rSdrModel, const tools::Rectangle& rNewRect)
-    : SdrAttrObj(rSdrModel)
-    , mpEditingOutliner(nullptr)
-    , meTextKind(SdrObjKind::Text)
-    , maTextEditOffset(Point(0, 0))
-    , mbTextFrame(false)
-    , mbNoShear(false)
-    , mbTextSizeDirty(false)
-    , mbInEditMode(false)
-    , mbDisableAutoWidthOnDragging(false)
-    , mbTextAnimationAllowed(true)
-    , mbInDownScale(false)
-{
-    tools::Rectangle aRectangle(rNewRect);
-    ImpJustifyRect(aRectangle);
-    setRectangle(aRectangle);
-
-    // #i25616#
-    mbSupportTextIndentingOnLineWidthChange = true;
-}
-
-SdrTextObj::SdrTextObj(SdrModel& rSdrModel, SdrObjKind eNewTextKind)
-    : SdrAttrObj(rSdrModel)
-    , mpEditingOutliner(nullptr)
-    , meTextKind(eNewTextKind)
-    , maTextEditOffset(Point(0, 0))
-    , mbTextFrame(true)
-    , mbNoShear(true)
-    , mbTextSizeDirty(false)
-    , mbInEditMode(false)
-    , mbDisableAutoWidthOnDragging(false)
-    , mbTextAnimationAllowed(true)
-    , mbInDownScale(false)
-{
-    // #i25616#
-    mbSupportTextIndentingOnLineWidthChange = true;
-}
-
-SdrTextObj::SdrTextObj(SdrModel& rSdrModel, SdrObjKind eNewTextKind,
-                       const tools::Rectangle& rNewRect)
-    : SdrAttrObj(rSdrModel)
-    , mpEditingOutliner(nullptr)
-    , meTextKind(eNewTextKind)
-    , maTextEditOffset(Point(0, 0))
-    , mbTextFrame(true)
-    , mbNoShear(true)
-    , mbTextSizeDirty(false)
-    , mbInEditMode(false)
-    , mbDisableAutoWidthOnDragging(false)
-    , mbTextAnimationAllowed(true)
-    , mbInDownScale(false)
-{
-    tools::Rectangle aRectangle(rNewRect);
-    ImpJustifyRect(aRectangle);
-    setRectangle(aRectangle);
-
-    // #i25616#
-    mbSupportTextIndentingOnLineWidthChange = true;
-}
-
 SdrTextObj::~SdrTextObj()
 {
     mxText.clear();
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 7c0251c8b0b1..a519ebd45cca 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -796,7 +796,7 @@ void ImpSdrPdfImport::InsertTextObject(const Point& rPos, 
const Size& rSize, con
         aPosition.AdjustY(-nTextHeight);
 
     tools::Rectangle aTextRect(aPosition, aSize);
-    rtl::Reference<SdrRectObj> pText = new SdrRectObj(*mpModel, 
SdrObjKind::Text, aTextRect);
+    rtl::Reference<SdrRectObj> pText = new SdrRectObj(*mpModel, aTextRect, 
SdrObjKind::Text);
 
     pText->SetMergedItem(makeSdrTextUpperDistItem(0));
     pText->SetMergedItem(makeSdrTextLowerDistItem(0));
diff --git a/svx/source/svdraw/svdxcgv.cxx b/svx/source/svdraw/svdxcgv.cxx
index 3e86051e4f0e..8a50c888664e 100644
--- a/svx/source/svdraw/svdxcgv.cxx
+++ b/svx/source/svdraw/svdxcgv.cxx
@@ -145,9 +145,7 @@ bool SdrExchangeView::Paste(const OUString& rStr, const 
Point& rPos, SdrObjList*
         aTextRect.SetSize(pPage->getSize().toToolsSize());
     }
     rtl::Reference<SdrRectObj> pObj = new SdrRectObj(
-        getSdrModelFromSdrView(),
-        SdrObjKind::Text,
-        aTextRect);
+        getSdrModelFromSdrView(), aTextRect, SdrObjKind::Text);
 
     pObj->SetLayer(nLayer);
     pObj->NbcSetText(rStr); // SetText before SetAttr, else SetAttr doesn't 
work!
@@ -185,9 +183,7 @@ bool SdrExchangeView::Paste(SvStream& rInput, EETextFormat 
eFormat, const Point&
         aTextRect.SetSize(pPage->getSize().toToolsSize());
     }
     rtl::Reference<SdrRectObj> pObj = new SdrRectObj(
-        getSdrModelFromSdrView(),
-        SdrObjKind::Text,
-        aTextRect);
+        getSdrModelFromSdrView(), aTextRect, SdrObjKind::Text);
 
     pObj->SetLayer(nLayer);
     if (mpDefaultStyleSheet!=nullptr) 
pObj->NbcSetStyleSheet(mpDefaultStyleSheet, false);
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index 377bf099aa98..981b30248ba8 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -1306,9 +1306,7 @@ rtl::Reference<SdrObject> 
SwWW8ImplReader::ReadTextBox(WW8_DPHEAD const * pHd, S
     aP1.AdjustY(SVBT16ToInt16(pHd->dya));
 
     rtl::Reference<SdrRectObj> pObj = new SdrRectObj(
-        *m_pDrawModel,
-        SdrObjKind::Text,
-        tools::Rectangle(aP0, aP1));
+        *m_pDrawModel, tools::Rectangle(aP0, aP1), SdrObjKind::Text);
 
     pObj->NbcSetSnapRect(tools::Rectangle(aP0, aP1));
     Size aSize(SVBT16ToInt16(pHd->dxa), SVBT16ToInt16(pHd->dya));
@@ -2966,9 +2964,7 @@ SwFrameFormat* 
SwWW8ImplReader::MungeTextIntoDrawBox(SvxMSDffImportRec& rRecord,
         // Group objects don't have text. Insert a text object into
         // the group for holding the text.
         pSdrTextObj = new SdrRectObj(
-            *m_pDrawModel,
-            SdrObjKind::Text,
-            pThisGroup->GetCurrentBoundRect());
+            *m_pDrawModel, pThisGroup->GetCurrentBoundRect(), 
SdrObjKind::Text);
 
         SfxItemSet aSet(m_pDrawModel->GetItemPool());
         aSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index fb9f4d3f7d85..68357d899a26 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -800,9 +800,7 @@ rtl::Reference<SdrObject> 
SwMSDffManager::ProcessObj(SvStream& rSt,
             if (bIsSimpleDrawingTextBox)
             {
                 pObj = new SdrRectObj(
-                    *pSdrModel,
-                    SdrObjKind::Text,
-                    rTextRect);
+                    *pSdrModel, rTextRect,SdrObjKind::Text );
             }
 
             // The vertical paragraph justification are contained within the
commit 4ffdc899aa187788ae7e46d610e55905862d181d
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Jun 11 21:26:18 2025 +0200
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Wed Jun 11 21:26:18 2025 +0200

    svx: convert SnapRect to SnapRange which uses gfx::Range2DLWrap
    
    Change-Id: Ib84b6a95847742e14f2b35b3b77e3731f0187542

diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index c53223601501..9ecc0176fbe6 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -551,6 +551,12 @@ public:
     /// SetSnapRect() tries to size the Object so that it fits into the
     /// passed Rect (without stroke width, ...)
     virtual void RecalcSnapRect();
+
+    virtual const gfx::Range2DL& getSnapRange() const
+    {
+        return m_aOutterRange;
+    }
+
     virtual const tools::Rectangle& GetSnapRect() const;
     virtual void SetSnapRect(const tools::Rectangle& rRect);
     virtual void NbcSetSnapRect(const tools::Rectangle& rRect);
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index 4433c023baa8..da26a8852a88 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -33,6 +33,7 @@
 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
 #include <basegfx/units/Range2DLWrap.hxx>
+#include <basegfx/units/Tuple2DLWrap.hxx>
 #include <basegfx/units/LengthTypes.hxx>
 #include <basegfx/range/b2drange.hxx>
 #include <drawinglayer/processor2d/contourextractor2d.hxx>
@@ -2314,16 +2315,40 @@ SdrGluePoint SdrObject::GetVertexGluePoint(sal_uInt16 
nPosNum) const
 
 SdrGluePoint SdrObject::GetCornerGluePoint(sal_uInt16 nPosNum) const
 {
-    tools::Rectangle aR(GetCurrentBoundRect());
-    Point aPt;
-    switch (nPosNum) {
-        case 0 : aPt=aR.TopLeft();     break;
-        case 1 : aPt=aR.TopRight();    break;
-        case 2 : aPt=aR.BottomRight(); break;
-        case 3 : aPt=aR.BottomLeft();  break;
+    auto const& rCurrentBoundRange = getCurrentBoundRange();
+
+    gfx::Length x;
+    gfx::Length y;
+
+    switch (nPosNum)
+    {
+        case 0:
+            x = rCurrentBoundRange.getMinX();
+            y = rCurrentBoundRange.getMinY();
+        break;
+
+        case 1:
+            x = rCurrentBoundRange.getMaxX();
+            y = rCurrentBoundRange.getMinY();
+        break;
+        case 2:
+            x = rCurrentBoundRange.getMaxX();
+            y = rCurrentBoundRange.getMaxY();
+        break;
+        case 3:
+            x = rCurrentBoundRange.getMinX();
+            y = rCurrentBoundRange.getMaxY();
+        break;
     }
-    aPt-=GetSnapRect().Center();
-    SdrGluePoint aGP(aPt);
+
+    x -= getSnapRange().getCenterX();
+    y -= getSnapRange().getCenterY();
+
+    auto eUnit = getSdrModelFromSdrObject().getUnit();
+    gfx::Tuple2DLWrap aTuple2D(x, y, eUnit);
+
+    // TODO
+    SdrGluePoint aGP(aTuple2D.toPoint());
     aGP.SetPercent(false);
     return aGP;
 }
commit 9c274116a50f55f2c234571653bb8795921cda38
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:50:26 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();
-e 
... etc. - the rest is truncated

Reply via email to