sw/inc/viewopt.hxx                      |    3 +
 sw/qa/extras/layout/data/tdf161368.fodt |   22 ++++++++++++
 sw/qa/extras/layout/layout3.cxx         |   14 ++++++++
 sw/source/core/inc/txtfrm.hxx           |    2 -
 sw/source/core/layout/pagechg.cxx       |    2 -
 sw/source/core/layout/tabfrm.cxx        |    6 +--
 sw/source/core/layout/wsfrm.cxx         |    2 -
 sw/source/core/text/guess.cxx           |    8 ++--
 sw/source/core/text/guess.hxx           |    8 ++--
 sw/source/core/text/inftxt.cxx          |   20 +++++------
 sw/source/core/text/inftxt.hxx          |   44 ++++++++++++-------------
 sw/source/core/text/itradj.cxx          |   16 ++++-----
 sw/source/core/text/itrform2.cxx        |   32 +++++++++---------
 sw/source/core/text/itrform2.hxx        |    2 -
 sw/source/core/text/itrtxt.hxx          |   19 +++++------
 sw/source/core/text/pordrop.hxx         |   32 +++++++++---------
 sw/source/core/text/porexp.cxx          |    4 +-
 sw/source/core/text/porexp.hxx          |    4 +-
 sw/source/core/text/porfld.cxx          |   45 ++++++++++++--------------
 sw/source/core/text/porfld.hxx          |   27 +++++++--------
 sw/source/core/text/porfly.cxx          |    6 +--
 sw/source/core/text/porftn.hxx          |    8 ++--
 sw/source/core/text/porglue.cxx         |    8 ++--
 sw/source/core/text/porglue.hxx         |   16 ++++-----
 sw/source/core/text/porhyph.hxx         |    4 +-
 sw/source/core/text/porlay.cxx          |    2 -
 sw/source/core/text/porlin.cxx          |   25 ++++++--------
 sw/source/core/text/porlin.hxx          |    5 +-
 sw/source/core/text/pormulti.cxx        |    8 ++--
 sw/source/core/text/porref.cxx          |    2 -
 sw/source/core/text/porref.hxx          |    4 +-
 sw/source/core/text/porrst.cxx          |   13 +++----
 sw/source/core/text/porrst.hxx          |   14 ++++----
 sw/source/core/text/portab.hxx          |   24 ++++++-------
 sw/source/core/text/portox.cxx          |    2 -
 sw/source/core/text/portox.hxx          |    4 +-
 sw/source/core/text/portxt.cxx          |   10 ++---
 sw/source/core/text/portxt.hxx          |    8 ++--
 sw/source/core/text/txtdrop.cxx         |   55 +++++++++++++++-----------------
 sw/source/core/text/txtfrm.cxx          |   10 ++---
 sw/source/core/text/txtftn.cxx          |   27 +++++++--------
 sw/source/core/text/txthyph.cxx         |    4 +-
 sw/source/core/text/txttab.cxx          |   48 +++++++++++++--------------
 sw/source/uibase/config/viewopt.cxx     |   17 ++++-----
 44 files changed, 330 insertions(+), 306 deletions(-)

New commits:
commit 7e9c23894bd45e015accf26ae0a77035b7eed452
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Jun 2 15:53:38 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Jun 2 19:18:27 2024 +0200

    tdf#161368: use SwTwips for twip sizes, instead of sal_uInt16
    
    Change-Id: I9179b55eb27f1bf2f28c2c86f1e67f2a4daf4819
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168341
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/inc/viewopt.hxx b/sw/inc/viewopt.hxx
index e32fea4975db..4f34c7286d3b 100644
--- a/sw/inc/viewopt.hxx
+++ b/sw/inc/viewopt.hxx
@@ -28,6 +28,7 @@
 #include <svx/swframetypes.hxx>
 #include <sfx2/zoomitem.hxx>
 #include "swdllapi.h"
+#include "swtypes.hxx"
 
 class SwRect;
 class OutputDevice;
@@ -446,7 +447,7 @@ public:
 
     void PaintPostIts( OutputDevice *pOut, const SwRect &rRect,
                               bool bIsScript ) const;
-    static sal_uInt16 GetPostItsWidth( const OutputDevice *pOut );
+    static SwTwips GetPostItsWidth(const OutputDevice* pOut);
 
     //show/hide tooltips on tracked changes
     bool IsShowInlineTooltips() const
diff --git a/sw/qa/extras/layout/data/tdf161368.fodt 
b/sw/qa/extras/layout/data/tdf161368.fodt
new file mode 100644
index 000000000000..72401c3fb29b
--- /dev/null
+++ b/sw/qa/extras/layout/data/tdf161368.fodt
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:font-face-decls>
+  <style:font-face style:name="Liberation Serif" 
svg:font-family="&apos;Liberation Serif&apos;" 
style:font-family-generic="roman" style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:automatic-styles>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="120cm" fo:page-height="120cm" 
style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" 
fo:margin-left="2cm" fo:margin-right="2cm"/>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum 
consequat mi quis pretium semper. Proin luctus orci ac neque venenatis, quis 
commodo dolor posuere. Curabitur dignissim sapien quis cursus egestas. Donec 
blandit auctor arcu, nec pellentesque eros molestie eget. In consectetur 
aliquam hendrerit. Sed cursus mauris vitae ligula pellentesque, non 
pellentesque urna aliquet. Fusce placerat mauris enim, nec rutrum purus semper 
vel. Praesent tincidunt neque eu pellentesque pharetra. Fusce pellentesque est 
orci.</text:p>
+   <text:p>Integer sodales tincidunt tristique. Sed a metus posuere, 
adipiscing nunc et, viverra odio. Donec auctor molestie sem, sit amet tristique 
lectus hendrerit sed. Cras sodales nisl sed orci mattis iaculis. Nunc eget 
dolor accumsan, pharetra risus a, vestibulum mauris. Nunc vulputate lobortis 
mollis. Vivamus nec tellus faucibus, tempor magna nec, facilisis felis. Donec 
commodo enim a vehicula pellentesque. Nullam vehicula vestibulum est vel 
ultricies.</text:p>
+   <text:p>Aliquam velit massa, laoreet vel leo nec, volutpat facilisis eros. 
Donec consequat arcu ut diam tempor luctus. Cum sociis natoque penatibus et 
magnis dis parturient montes, nascetur ridiculus mus. Praesent vitae lacus vel 
leo sodales pharetra a a nibh. Vestibulum ante ipsum primis in faucibus orci 
luctus et ultrices posuere cubilia Curae; Nam luctus tempus nibh, fringilla 
dictum augue consectetur eget. Curabitur at ante sit amet tortor pharetra 
molestie eu nec ante. Mauris tincidunt, nibh eu sollicitudin molestie, dolor 
sapien congue tortor, a pulvinar sapien turpis sed ante. Donec nec est 
elementum, euismod nulla in, mollis nunc.</text:p>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index b5f013df689a..d4775eb4ad71 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -2807,6 +2807,20 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testTdf160958_orphans)
     assertXPath(pExportDump, 
"//page[2]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1);
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf161368)
+{
+    // Given a document with a text body width of 116 mm, greater than 65535 
twips (115.6 mm)
+    createSwDoc("tdf161368.fodt");
+    auto pExportDump = parseLayoutDump();
+    // one page, three paragraphs, each one line (it was four pages, each 
paragraph split into
+    // tens of short (<= 4 mm wide) lines)
+    assertXPath(pExportDump, "//page"_ostr, 1);
+    assertXPath(pExportDump, "//page[1]/body/txt"_ostr, 3);
+    assertXPath(pExportDump, 
"//page[1]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1);
+    assertXPath(pExportDump, 
"//page[1]/body/txt[2]/SwParaPortion/SwLineLayout"_ostr, 1);
+    assertXPath(pExportDump, 
"//page[1]/body/txt[3]/SwParaPortion/SwLineLayout"_ostr, 1);
+}
+
 } // end of anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx
index 768cb6e1c70f..addf6f6fb7f9 100644
--- a/sw/source/core/inc/txtfrm.hxx
+++ b/sw/source/core/inc/txtfrm.hxx
@@ -665,7 +665,7 @@ public:
     tools::Long GetLineSpace( const bool _bNoPropLineSpacing = false ) const;
 
     /// Returns the first line height
-    sal_uInt16 FirstLineHeight() const;
+    SwTwips FirstLineHeight() const;
 
     /// Rewires FlyInContentFrame, if nEnd > Index >= nStart
     void MoveFlyInCnt(SwTextFrame *pNew, TextFrameIndex nStart, TextFrameIndex 
nEnd);
diff --git a/sw/source/core/layout/pagechg.cxx 
b/sw/source/core/layout/pagechg.cxx
index e60921c3cfa1..d6a2aaf320ac 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -1831,7 +1831,7 @@ void SwRootFrame::ImplCalcBrowseWidth()
             const SwBorderAttrs &rAttrs = *aAccess.Get();
             const SwFormatHoriOrient &rHori = 
rAttrs.GetAttrSet().GetHoriOrient();
             tools::Long nWidth = rAttrs.GetSize().Width();
-            if ( nWidth < int(USHRT_MAX)-2000 && //-2k, because USHRT_MAX gets 
missing while trying to resize!  (and cast to int to avoid -Wsign-compare due 
to broken USHRT_MAX on Android)
+            if ( nWidth < std::numeric_limits<tools::Long>::max()-2000 && 
//-2k, because it changes while trying to resize!
                  text::HoriOrientation::FULL != rHori.GetHoriOrient() )
             {
                 const SwHTMLTableLayout *pLayoutInfo =
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 21012d31a28e..77bcd536d468 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -6459,7 +6459,7 @@ static SwTwips lcl_CalcHeightOfFirstContentLine( const 
SwRowFrame& rSourceLine )
         const SwFrame *pTmp = pCurrSourceCell->Lower();
         if ( pTmp )
         {
-            SwTwips nTmpHeight = USHRT_MAX;
+            SwTwips nTmpHeight = std::numeric_limits<SwTwips>::max();
             // #i32456# Consider lower row frames
             if ( pTmp->IsRowFrame() )
             {
@@ -6487,7 +6487,7 @@ static SwTwips lcl_CalcHeightOfFirstContentLine( const 
SwRowFrame& rSourceLine )
                 nTmpHeight = pTextFrame->FirstLineHeight();
             }
 
-            if ( USHRT_MAX != nTmpHeight )
+            if (std::numeric_limits<SwTwips>::max() != nTmpHeight)
             {
                 const SwCellFrame* pPrevCell = 
pCurrSourceCell->GetPreviousCell();
                 if ( pPrevCell )
@@ -6565,7 +6565,7 @@ static SwTwips lcl_CalcHeightOfFirstContentLine( const 
SwRowFrame& rSourceLine )
             else
             {
                 // maximum
-                if ( nTmpHeight > nHeight && USHRT_MAX != nTmpHeight )
+                if (nTmpHeight > nHeight && 
std::numeric_limits<SwTwips>::max() != nTmpHeight)
                     nHeight = nTmpHeight;
             }
         }
diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index 455a091a611b..225416da96af 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -3738,7 +3738,7 @@ static tools::Long lcl_CalcMinColDiff( SwLayoutFrame 
*pLayFrame )
         if ( pFrame && pFrame->IsTextFrame() )
         {
             const tools::Long nTmp = 
static_cast<SwTextFrame*>(pFrame)->FirstLineHeight();
-            if ( nTmp != USHRT_MAX )
+            if (nTmp != std::numeric_limits<SwTwips>::max())
             {
                 if ( pCol == pLayFrame->Lower() )
                     nFirstDiff = nTmp;
diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx
index 789cae852921..ad95c41fd39d 100644
--- a/sw/source/core/text/guess.cxx
+++ b/sw/source/core/text/guess.cxx
@@ -77,8 +77,8 @@ bool hasBlanksInLine(const SwTextFormatInfo& rInf, 
TextFrameIndex end)
 // values, and returns 'false' value that SwTextGuess::Guess should return, to 
create a
 // trailing SwHolePortion.
 bool maybeAdjustPositionsForBlockAdjust(TextFrameIndex& rCutPos, 
TextFrameIndex& rBreakPos,
-                                        TextFrameIndex& rBreakStart, 
sal_uInt16& rBreakWidth,
-                                        sal_uInt16& rExtraBlankWidth, 
sal_uInt16& rMaxSizeDiff,
+                                        TextFrameIndex& rBreakStart, SwTwips& 
rBreakWidth,
+                                        SwTwips& rExtraBlankWidth, 
tools::Long& rMaxSizeDiff,
                                         const SwTextFormatInfo& rInf, const 
SwScriptInfo& rSI,
                                         sal_uInt16 maxComp,
                                         
std::optional<SwLinePortionLayoutContext> nLayoutContext)
@@ -167,7 +167,7 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, 
SwTextFormatInfo &rInf,
 
     OSL_ENSURE( nPorHeight, "+SwTextGuess::Guess: no height" );
 
-    sal_uInt16 nMaxSizeDiff;
+    tools::Long nMaxSizeDiff;
 
     const SwScriptInfo& rSI = rInf.GetParaPortion()->GetScriptInfo();
 
@@ -420,7 +420,7 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, 
SwTextFormatInfo &rInf,
 #if OSL_DEBUG_LEVEL > 1
         if ( TextFrameIndex(COMPLETE_STRING) != m_nCutPos )
         {
-            sal_uInt16 nMinSize;
+            SwTwips nMinSize;
             rInf.GetTextSize(&rSI, rInf.GetIdx(), m_nCutPos - rInf.GetIdx(), 
std::nullopt, nMaxComp,
                              nMinSize, nMaxSizeDiff);
             OSL_ENSURE( nMinSize <= nLineWidth, "What a Guess!!!" );
diff --git a/sw/source/core/text/guess.hxx b/sw/source/core/text/guess.hxx
index 5a7a9ac1cfa2..309e86221aa4 100644
--- a/sw/source/core/text/guess.hxx
+++ b/sw/source/core/text/guess.hxx
@@ -37,8 +37,8 @@ class SwTextGuess
     TextFrameIndex m_nBreakPos;       // start index of break position
     TextFrameIndex m_nFieldDiff;      // absolute positions can be wrong if we
                                // a field in the text has been expanded
-    sal_uInt16 m_nBreakWidth;    // width of the broken portion
-    sal_uInt16 m_nExtraBlankWidth;    // width of spaces after the break
+    SwTwips m_nBreakWidth; // width of the broken portion
+    SwTwips m_nExtraBlankWidth; // width of spaces after the break
 public:
     SwTextGuess(): m_nCutPos(0), m_nBreakStart(0),
                    m_nBreakPos(0), m_nFieldDiff(0), m_nBreakWidth(0), 
m_nExtraBlankWidth(0)
@@ -51,8 +51,8 @@ public:
 
     SwHangingPortion* GetHangingPortion() const { return m_pHanging.get(); }
     SwHangingPortion* ReleaseHangingPortion() { return m_pHanging.release(); }
-    sal_uInt16 BreakWidth() const { return m_nBreakWidth; }
-    sal_uInt16 ExtraBlankWidth() const { return m_nExtraBlankWidth; }
+    SwTwips BreakWidth() const { return m_nBreakWidth; }
+    SwTwips ExtraBlankWidth() const { return m_nExtraBlankWidth; }
     TextFrameIndex CutPos() const { return m_nCutPos; }
     TextFrameIndex BreakStart() const { return m_nBreakStart; }
     TextFrameIndex BreakPos() const {return m_nBreakPos; }
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index 72a8be323fb8..40b113fa41da 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -151,7 +151,7 @@ void SwLineInfo::CtorInitLineInfo( const SwAttrSet& 
rAttrSet,
 
     m_pSpace = &rAttrSet.GetLineSpacing();
     m_nVertAlign = rAttrSet.GetParaVertAlign().GetValue();
-    m_nDefTabStop = USHRT_MAX;
+    m_nDefTabStop = std::numeric_limits<SwTwips>::max();
 }
 
 void SwTextInfo::CtorInitTextInfo( SwTextFrame *pFrame )
@@ -437,8 +437,8 @@ 
SwTextSizeInfo::GetTextSize(std::optional<SwLinePortionLayoutContext> nLayoutCon
 void SwTextSizeInfo::GetTextSize(const SwScriptInfo* pSI, const TextFrameIndex 
nIndex,
                                  const TextFrameIndex nLength,
                                  std::optional<SwLinePortionLayoutContext> 
nLayoutContext,
-                                 const sal_uInt16 nComp, sal_uInt16& nMinSize,
-                                 sal_uInt16& nMaxSizeDiff,
+                                 const sal_uInt16 nComp, SwTwips& nMinSize,
+                                 tools::Long& nMaxSizeDiff,
                                  vcl::text::TextLayoutCache const* const 
pCache) const
 {
     SwDrawTextInfo aDrawInf(m_pVsh, *m_pOut, pSI, *m_pText, nIndex, nLength, 
nLayoutContext, 0,
@@ -448,7 +448,7 @@ void SwTextSizeInfo::GetTextSize(const SwScriptInfo* pSI, 
const TextFrameIndex n
     aDrawInf.SetSnapToGrid( SnapToGrid() );
     aDrawInf.SetKanaComp( nComp );
     SwPosSize aSize( m_pFnt->GetTextSize_( aDrawInf ) );
-    nMaxSizeDiff = o3tl::narrowing<sal_uInt16>(aDrawInf.GetKanaDiff());
+    nMaxSizeDiff = aDrawInf.GetKanaDiff();
     nMinSize = aSize.Width();
 }
 
@@ -945,8 +945,8 @@ static void lcl_DrawSpecial( const SwTextPaintInfo& 
rTextPaintInfo, const SwLine
 
     Point aTmpPos( nX, nY );
     rNonConstTextPaintInfo.SetPos( aTmpPos );
-    sal_uInt16 nOldWidth = rPor.Width();
-    const_cast<SwLinePortion&>(rPor).Width( 
o3tl::narrowing<sal_uInt16>(aFontSize.Width()) );
+    SwTwips nOldWidth = rPor.Width();
+    const_cast<SwLinePortion&>(rPor).Width(aFontSize.Width());
     rTextPaintInfo.DrawText( aTmp, rPor );
     const_cast<SwLinePortion&>(rPor).Width( nOldWidth );
     rNonConstTextPaintInfo.SetFont( const_cast<SwFont*>(pOldFnt) );
@@ -994,7 +994,7 @@ void SwTextPaintInfo::DrawLineBreak( const SwLinePortion 
&rPor ) const
         eClear = rBreakPortion.GetClear();
     }
 
-    sal_uInt16 nOldWidth = rPor.Width();
+    SwTwips nOldWidth = rPor.Width();
     const_cast<SwLinePortion&>(rPor).Width( LINE_BREAK_WIDTH );
 
     SwRect aRect;
@@ -1069,7 +1069,7 @@ void SwTextPaintInfo::DrawPostIts( bool bScript ) const
     Size aSize;
     Point aTmp;
 
-    const sal_uInt16 nPostItsWidth = SwViewOption::GetPostItsWidth( GetOut() );
+    const SwTwips nPostItsWidth = SwViewOption::GetPostItsWidth(GetOut());
     const sal_uInt16 nFontHeight = m_pFnt->GetHeight( m_pVsh, *GetOut() );
     const sal_uInt16 nFontAscent = m_pFnt->GetAscent( m_pVsh, *GetOut() );
 
@@ -1760,7 +1760,7 @@ SwTextFormatInfo::SwTextFormatInfo( const 
SwTextFormatInfo& rInf,
     m_nLeft(rInf.m_nLeft),
     m_nRight(rInf.m_nRight),
     m_nFirst(rInf.m_nLeft),
-    m_nRealWidth(sal_uInt16(nActWidth)),
+    m_nRealWidth(nActWidth),
     m_nWidth(m_nRealWidth),
     m_nLineHeight(0),
     m_nLineNetHeight(0),
@@ -1825,7 +1825,7 @@ void SwTextFormatInfo::SetLast(SwLinePortion* pNewLast)
 
 bool SwTextFormatInfo::CheckFootnotePortion_( SwLineLayout const * pCurr )
 {
-    const sal_uInt16 nHeight = pCurr->GetRealHeight();
+    const SwTwips nHeight = pCurr->GetRealHeight();
     for( SwLinePortion *pPor = pCurr->GetNextPortion(); pPor; pPor = 
pPor->GetNextPortion() )
     {
         if( pPor->IsFootnotePortion() && nHeight > 
static_cast<SwFootnotePortion*>(pPor)->Orig() )
diff --git a/sw/source/core/text/inftxt.hxx b/sw/source/core/text/inftxt.hxx
index 19c02a3e479c..4cc49a0e3e57 100644
--- a/sw/source/core/text/inftxt.hxx
+++ b/sw/source/core/text/inftxt.hxx
@@ -64,7 +64,7 @@ class SwLineInfo
     std::optional<SvxTabStopItem> m_oRuler;
     const SvxLineSpacingItem *m_pSpace;
     SvxParaVertAlignItem::Align m_nVertAlign;
-    sal_uInt16 m_nDefTabStop;
+    SwTwips m_nDefTabStop;
     bool m_bListTabStopIncluded;
     tools::Long m_nListTabStopPosition;
 
@@ -77,8 +77,8 @@ public:
     // #i24363# tab stops relative to indent - returns the tab stop following 
nSearchPos or NULL
     const SvxTabStop* GetTabStop(const SwTwips nSearchPos, SwTwips& nRight) 
const;
     const SvxLineSpacingItem *GetLineSpacing() const { return m_pSpace; }
-    sal_uInt16 GetDefTabStop() const { return m_nDefTabStop; }
-    void SetDefTabStop( sal_uInt16 nNew ) const
+    SwTwips GetDefTabStop() const { return m_nDefTabStop; }
+    void SetDefTabStop(SwTwips nNew) const
         { const_cast<SwLineInfo*>(this)->m_nDefTabStop = nNew; }
 
     // vertical alignment
@@ -126,7 +126,7 @@ public:
 class SwTextSizeInfo : public SwTextInfo
 {
 private:
-    typedef std::map< SwLinePortion const *, sal_uInt16 > SwTextPortionMap;
+    typedef std::map<SwLinePortion const*, SwTwips> SwTextPortionMap;
 
 protected:
     // during formatting, a small database is built, mapping portion pointers
@@ -253,7 +253,7 @@ public:
                           = std::nullopt) const;
     void GetTextSize(const SwScriptInfo* pSI, TextFrameIndex nIdx, 
TextFrameIndex nLen,
                      std::optional<SwLinePortionLayoutContext> nLayoutContext,
-                     const sal_uInt16 nComp, sal_uInt16& nMinSize, sal_uInt16& 
nMaxSizeDiff,
+                     const sal_uInt16 nComp, SwTwips& nMinSize, tools::Long& 
nMaxSizeDiff,
                      vcl::text::TextLayoutCache const* = nullptr) const;
     inline SwPosSize GetTextSize(const SwScriptInfo* pSI, TextFrameIndex nIdx,
                                  TextFrameIndex nLen) const;
@@ -304,11 +304,11 @@ public:
     // space among compressed kanas.
     // During formatting, the maximum values of compressible portions are
     // stored in m_aMaxWidth and discarded after a line has been formatted.
-    void SetMaxWidthDiff( const SwLinePortion *nKey, sal_uInt16 nVal )
+    void SetMaxWidthDiff(const SwLinePortion* nKey, SwTwips nVal)
     {
         m_aMaxWidth.insert( std::make_pair( nKey, nVal ) );
     };
-    sal_uInt16 GetMaxWidthDiff( const SwLinePortion *nKey )
+    SwTwips GetMaxWidthDiff(const SwLinePortion* nKey)
     {
         SwTextPortionMap::iterator it = m_aMaxWidth.find( nKey );
 
@@ -501,11 +501,11 @@ class SwTextFormatInfo : public SwTextPaintInfo
     SwTwips m_nFirst;             // EZE
     /// First or left margin, depending on context.
     SwTwips m_nLeftMargin = 0;
-    sal_uInt16 m_nRealWidth;      // "real" line width
-    sal_uInt16 m_nWidth;          // "virtual" line width
-    sal_uInt16 m_nLineHeight;     // Final height after CalcLine
-    sal_uInt16 m_nLineNetHeight; // line height without spacing
-    sal_uInt16 m_nForcedLeftMargin; // Shift of left margin due to frame
+    SwTwips m_nRealWidth; // "real" line width
+    SwTwips m_nWidth; // "virtual" line width
+    SwTwips m_nLineHeight;     // Final height after CalcLine
+    SwTwips m_nLineNetHeight; // line height without spacing
+    SwTwips m_nForcedLeftMargin; // Shift of left margin due to frame
 
     bool m_bFull : 1;             // Line is full
     bool m_bFootnoteDone : 1;          // Footnote already formatted
@@ -558,8 +558,8 @@ public:
     SwTextFormatInfo( const SwTextFormatInfo& rInf, SwLineLayout& rLay,
         SwTwips nActWidth );
 
-    sal_uInt16 Width() const { return m_nWidth; }
-    void Width( const sal_uInt16 nNew ) { m_nWidth = nNew; }
+    SwTwips Width() const { return m_nWidth; }
+    void Width(const SwTwips nNew) { m_nWidth = nNew; }
            void Init();
 
     /**
@@ -579,10 +579,10 @@ public:
     SwTwips First() const { return m_nFirst; }
     void First( const SwTwips nNew ) { m_nFirst = nNew; }
     void LeftMargin( const SwTwips nNew) { m_nLeftMargin = nNew; }
-    sal_uInt16 RealWidth() const { return m_nRealWidth; }
-    void RealWidth( const sal_uInt16 nNew ) { m_nRealWidth = nNew; }
-    sal_uInt16 ForcedLeftMargin() const { return m_nForcedLeftMargin; }
-    void ForcedLeftMargin( const sal_uInt16 nN ) { m_nForcedLeftMargin = nN; }
+    SwTwips RealWidth() const { return m_nRealWidth; }
+    void RealWidth(const SwTwips nNew) { m_nRealWidth = nNew; }
+    SwTwips ForcedLeftMargin() const { return m_nForcedLeftMargin; }
+    void ForcedLeftMargin(const SwTwips nN) { m_nForcedLeftMargin = nN; }
 
     sal_uInt8 &MaxHyph() { return m_nMaxHyph; }
     const sal_uInt8 &MaxHyph() const { return m_nMaxHyph; }
@@ -631,10 +631,10 @@ public:
     void SetLineStart(TextFrameIndex const nNew) { m_nLineStart = nNew; }
 
     // these are used during fly calculation
-    sal_uInt16 GetLineHeight() const { return m_nLineHeight; }
-    void SetLineHeight( const sal_uInt16 nNew ) { m_nLineHeight = nNew; }
-    sal_uInt16 GetLineNetHeight() const { return m_nLineNetHeight; }
-    void SetLineNetHeight( const sal_uInt16 nNew ) { m_nLineNetHeight = nNew; }
+    SwTwips GetLineHeight() const { return m_nLineHeight; }
+    void SetLineHeight(const SwTwips nNew) { m_nLineHeight = nNew; }
+    SwTwips GetLineNetHeight() const { return m_nLineNetHeight; }
+    void SetLineNetHeight(const SwTwips nNew) { m_nLineNetHeight = nNew; }
 
     const SwLinePortion *GetUnderflow() const { return m_pUnderflow; }
     SwLinePortion *GetUnderflow() { return m_pUnderflow; }
diff --git a/sw/source/core/text/itradj.cxx b/sw/source/core/text/itradj.cxx
index c5e24b0913f5..1a49b9aa8819 100644
--- a/sw/source/core/text/itradj.cxx
+++ b/sw/source/core/text/itradj.cxx
@@ -466,7 +466,7 @@ SwTwips SwTextAdjuster::CalcKanaAdj( SwLineLayout* pCurrent 
)
         {
             // get maximum portion width from info structure, calculated
             // during text formatting
-            sal_uInt16 nMaxWidthDiff = GetInfo().GetMaxWidthDiff( pPos );
+            SwTwips nMaxWidthDiff = GetInfo().GetMaxWidthDiff(pPos);
 
             // check, if information is stored under other key
             if ( !nMaxWidthDiff && pPos == pCurrent->GetFirstPortion() )
@@ -577,10 +577,10 @@ SwMarginPortion *SwTextAdjuster::CalcRightMargin( 
SwLineLayout *pCurrent,
     SwTwips nReal )
 {
     tools::Long nRealWidth;
-    const sal_uInt16 nRealHeight = GetLineHeight();
-    const sal_uInt16 nLineHeight = pCurrent->Height();
+    const SwTwips nRealHeight = GetLineHeight();
+    const SwTwips nLineHeight = pCurrent->Height();
 
-    sal_uInt16 nPrtWidth = pCurrent->PrtWidth();
+    SwTwips nPrtWidth = pCurrent->PrtWidth();
     SwLinePortion *pLast = pCurrent->FindLastPortion();
 
     if( GetInfo().IsMulti() )
@@ -611,7 +611,7 @@ SwMarginPortion *SwTextAdjuster::CalcRightMargin( 
SwLineLayout *pCurrent,
     pLast->Append( pRight );
 
     if( tools::Long( nPrtWidth )< nRealWidth )
-        pRight->PrtWidth( sal_uInt16( nRealWidth - nPrtWidth ) );
+        pRight->PrtWidth(nRealWidth - nPrtWidth);
 
     // pCurrent->Width() is set to the real size, because we attach the
     // MarginPortions.
@@ -620,7 +620,7 @@ SwMarginPortion *SwTextAdjuster::CalcRightMargin( 
SwLineLayout *pCurrent,
     // implicitly. GetLeftMarginAdjust() and IsJustified() think they have a
     // line filled with chars.
 
-    pCurrent->PrtWidth( sal_uInt16( nRealWidth ) );
+    pCurrent->PrtWidth(nRealWidth);
     return pRight;
 }
 
@@ -734,7 +734,7 @@ SwFlyPortion *SwTextAdjuster::CalcFlyPortion( const 
tools::Long nRealWidth,
 {
     SwTextFly aTextFly( GetTextFrame() );
 
-    const sal_uInt16 nCurrWidth = m_pCurr->PrtWidth();
+    const SwTwips nCurrWidth = m_pCurr->PrtWidth();
     SwFlyPortion *pFlyPortion = nullptr;
 
     SwRect aLineVert( rCurrRect );
@@ -766,7 +766,7 @@ SwFlyPortion *SwTextAdjuster::CalcFlyPortion( const 
tools::Long nRealWidth,
             aLocal.Width( nRealWidth - aLocal.Left() );
         GetInfo().GetParaPortion()->SetFly();
         pFlyPortion = new SwFlyPortion( aLocal );
-        pFlyPortion->Height( sal_uInt16( rCurrRect.Height() ) );
+        pFlyPortion->Height(rCurrRect.Height());
         // The Width could be smaller than the FixWidth, thus:
         pFlyPortion->AdjFixWidth();
     }
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 4ef317931b67..9d8e9ae0b77a 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -138,7 +138,7 @@ void SwTextFormatter::Insert( SwLineLayout *pLay )
         m_pCurr = pLay;
 }
 
-sal_uInt16 SwTextFormatter::GetFrameRstHeight() const
+SwTwips SwTextFormatter::GetFrameRstHeight() const
 {
     // We want the rest height relative to the page.
     // If we're in a table, then pFrame->GetUpper() is not the page.
@@ -152,7 +152,7 @@ sal_uInt16 SwTextFormatter::GetFrameRstHeight() const
     if( 0 > nHeight )
         return m_pCurr->Height();
     else
-        return sal_uInt16( nHeight );
+        return nHeight;
 }
 
 bool SwTextFormatter::ClearIfIsFirstOfBorderMerge(const SwLinePortion* 
pPortion)
@@ -476,7 +476,7 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo &rInf 
)
         {
             SwFontScript nNxtActual = rInf.GetFont()->GetActual();
             SwFontScript nLstActual = nNxtActual;
-            sal_uInt16 nLstHeight = 
o3tl::narrowing<sal_uInt16>(rInf.GetFont()->GetHeight());
+            tools::Long nLstHeight = rInf.GetFont()->GetHeight();
             bool bAllowBehind = false;
             const CharClass& rCC = GetAppCharClass();
 
@@ -519,7 +519,7 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo &rInf 
)
                         if ( pTmpFnt )
                         {
                             nLstActual = pTmpFnt->GetActual();
-                            nLstHeight = 
o3tl::narrowing<sal_uInt16>(pTmpFnt->GetHeight());
+                            nLstHeight = pTmpFnt->GetHeight();
                         }
                     }
                 }
@@ -721,7 +721,7 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo &rInf 
)
 
                 // calculate size
                 SwLinePortion* pTmpPor = pGridKernPortion->GetNextPortion();
-                sal_uInt16 nSumWidth = pPor->Width();
+                SwTwips nSumWidth = pPor->Width();
                 while ( pTmpPor )
                 {
                     nSumWidth = nSumWidth + pTmpPor->Width();
@@ -1814,7 +1814,7 @@ SwLinePortion 
*SwTextFormatter::NewPortion(SwTextFormatInfo &rInf,
                              PortionType::TabDecimal == 
pLastTabPortion->GetWhichPor() )
                         {
                             OSL_ENSURE( rInf.X() >= pLastTabPortion->GetFix(), 
"Decimal tab stop position cannot be calculated" );
-                            const sal_uInt16 
nWidthOfPortionsUpToDecimalPosition = o3tl::narrowing<sal_uInt16>(rInf.X() - 
pLastTabPortion->GetFix() );
+                            const SwTwips nWidthOfPortionsUpToDecimalPosition 
= rInf.X() - pLastTabPortion->GetFix();
                             
static_cast<SwTabDecimalPortion*>(pLastTabPortion)->SetWidthOfPortionsUpToDecimalPosition(
 nWidthOfPortionsUpToDecimalPosition );
                             rInf.SetTabDecimal( 0 );
                         }
@@ -2100,7 +2100,7 @@ TextFrameIndex SwTextFormatter::FormatLine(TextFrameIndex 
const nStartPos)
     // the SwLineLayout is wider as well.
     if 
(GetInfo().GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::TAB_OVER_MARGIN))
     {
-        sal_uInt16 nSum = 0;
+        SwTwips nSum = 0;
         SwLinePortion* pPor = m_pCurr->GetFirstPortion();
 
         while (pPor)
@@ -2183,10 +2183,10 @@ void SwTextFormatter::CalcRealHeight( bool bNewLine )
         const bool bRubyTop = ! pGrid->GetRubyTextBelow();
 
         nLineHeight = nGridWidth + nRubyHeight;
-        const sal_uInt16 nAmpRatio = (m_pCurr->Height() + nLineHeight - 
1)/nLineHeight;
+        const auto nAmpRatio = (m_pCurr->Height() + nLineHeight - 1) / 
nLineHeight;
         nLineHeight *= nAmpRatio;
 
-        const sal_uInt16 nAsc = m_pCurr->GetAscent() +
+        const SwTwips nAsc = m_pCurr->GetAscent() +
                       ( bRubyTop ?
                        ( nLineHeight - m_pCurr->Height() + nRubyHeight ) / 2 :
                        ( nLineHeight - m_pCurr->Height() - nRubyHeight ) / 2 );
@@ -2242,7 +2242,7 @@ void SwTextFormatter::CalcRealHeight( bool bNewLine )
                             if( !nTmp )
                                 ++nTmp;
                             nLineHeight = nTmp;
-                            sal_uInt16 nAsc = ( 4 * nLineHeight ) / 5;  // 80%
+                            SwTwips nAsc = (4 * nLineHeight) / 5; // 80%
 #if 0
                             // could do clipping here (like Word does)
                             // but at 0.5 its unreadable either way...
@@ -2266,7 +2266,7 @@ void SwTextFormatter::CalcRealHeight( bool bNewLine )
                 case SvxLineSpaceRule::Fix:
                 {
                     nLineHeight = pSpace->GetLineHeight();
-                    const sal_uInt16 nAsc = ( 4 * nLineHeight ) / 5;  // 80%
+                    const SwTwips nAsc = (4 * nLineHeight) / 5; // 80%
                     if( nAsc < m_pCurr->GetAscent() ||
                         nLineHeight - nAsc < m_pCurr->Height() - 
m_pCurr->GetAscent() )
                         m_pCurr->SetClipping( true );
@@ -2341,7 +2341,7 @@ void SwTextFormatter::FeedInf( SwTextFormatInfo &rInf ) 
const
     rInf.First( FirstLeft() );
     rInf.LeftMargin(GetLeftMargin());
 
-    rInf.RealWidth( sal_uInt16(rInf.Right() - GetLeftMargin()) );
+    rInf.RealWidth(rInf.Right() - GetLeftMargin());
     rInf.Width( rInf.RealWidth() );
     if( const_cast<SwTextFormatter*>(this)->GetRedln() )
     {
@@ -2652,7 +2652,7 @@ bool SwTextFormatter::ChkFlyUnderflow( SwTextFormatInfo 
&rInf ) const
     {
         // First we check, whether a fly overlaps with the line.
         // = GetLineHeight()
-        const sal_uInt16 nHeight = GetCurr()->GetRealHeight();
+        const SwTwips nHeight = GetCurr()->GetRealHeight();
         SwRect aLine( GetLeftMargin(), Y(), rInf.RealWidth(), nHeight );
 
         SwRect aLineVert( aLine );
@@ -2925,7 +2925,7 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo 
&rInf )
     if( bForced )
     {
         m_pCurr->SetForcedLeftMargin();
-        rInf.ForcedLeftMargin( o3tl::narrowing<sal_uInt16>(aInter.Width()) );
+        rInf.ForcedLeftMargin(aInter.Width());
     }
 
     if( bFullLine )
@@ -3190,8 +3190,8 @@ void SwTextFormatter::MergeCharacterBorder( 
SwLinePortion& rPortion, SwLinePorti
         {
             // Calculate maximum height and ascent
             SwLinePortion* pActPor = m_pFirstOfBorderMerge;
-            sal_uInt16 nMaxAscent = 0;
-            sal_uInt16 nMaxHeight = 0;
+            SwTwips nMaxAscent = 0;
+            SwTwips nMaxHeight = 0;
             bool bReachCurrent = false;
             while( pActPor )
             {
diff --git a/sw/source/core/text/itrform2.hxx b/sw/source/core/text/itrform2.hxx
index 2d71fad34cd5..18ee69f2fac4 100644
--- a/sw/source/core/text/itrform2.hxx
+++ b/sw/source/core/text/itrform2.hxx
@@ -186,7 +186,7 @@ public:
     void Insert( SwLineLayout *pLine );
 
     // The remaining height to the page border
-    sal_uInt16 GetFrameRstHeight() const;
+    SwTwips GetFrameRstHeight() const;
 
     // How wide would you be without any bounds (Flys etc.)?
     SwTwips CalcFitToContent_( );
diff --git a/sw/source/core/text/itrtxt.hxx b/sw/source/core/text/itrtxt.hxx
index b5ea78369d5f..eb3a9a859854 100644
--- a/sw/source/core/text/itrtxt.hxx
+++ b/sw/source/core/text/itrtxt.hxx
@@ -144,9 +144,9 @@ private:
           SwTwips mnLeft;
           SwTwips mnRight;
           SwTwips mnFirst;
-          sal_uInt16  mnDropLeft;
-          sal_uInt16  mnDropHeight;
-          sal_uInt16  mnDropDescent;
+          SwTwips mnDropLeft;
+          SwTwips mnDropHeight;
+          SwTwips mnDropDescent;
           sal_uInt16  mnDropLines;
           SvxAdjust  mnAdjust;
           // #i91133#
@@ -188,8 +188,7 @@ public:
     bool IsLastBlock() const { return m_bLastBlock; }
     bool IsLastCenter() const { return m_bLastCenter; }
     SvxAdjust GetAdjust() const { return mnAdjust; }
-    sal_uInt16 GetLineWidth() const
-           { return sal_uInt16( Right() - GetLeftMargin() + 1 ); }
+    SwTwips GetLineWidth() const { return Right() - GetLeftMargin() + 1; }
     SwTwips GetLeftMin() const { return std::min(mnFirst, mnLeft); }
     bool HasNegFirst() const { return mnFirst < mnLeft; }
 
@@ -201,11 +200,11 @@ public:
     // DropCaps
     sal_uInt16 GetDropLines() const { return mnDropLines; }
     void SetDropLines( const sal_uInt16 nNew ) { mnDropLines = nNew; }
-    sal_uInt16 GetDropLeft() const { return mnDropLeft; }
-    sal_uInt16 GetDropHeight() const { return mnDropHeight; }
-    void SetDropHeight( const sal_uInt16 nNew ) { mnDropHeight = nNew; }
-    sal_uInt16 GetDropDescent() const { return mnDropDescent; }
-    void SetDropDescent( const sal_uInt16 nNew ) { mnDropDescent = nNew; }
+    SwTwips GetDropLeft() const { return mnDropLeft; }
+    SwTwips GetDropHeight() const { return mnDropHeight; }
+    void SetDropHeight(const SwTwips nNew) { mnDropHeight = nNew; }
+    SwTwips GetDropDescent() const { return mnDropDescent; }
+    void SetDropDescent(const SwTwips nNew) { mnDropDescent = nNew; }
     void DropInit();
 
     // Returns the TextPos for start and end of the current line without 
whitespace
diff --git a/sw/source/core/text/pordrop.hxx b/sw/source/core/text/pordrop.hxx
index 50dd00e5668e..6d36d8a3d462 100644
--- a/sw/source/core/text/pordrop.hxx
+++ b/sw/source/core/text/pordrop.hxx
@@ -38,7 +38,7 @@ class SwDropPortionPart
     std::unique_ptr<SwDropPortionPart> m_pFollow;
     std::unique_ptr<SwFont> m_pFnt;
     TextFrameIndex m_nLen;
-    sal_uInt16 m_nWidth;
+    SwTwips m_nWidth;
     bool m_bJoinBorderWithNext;
     bool m_bJoinBorderWithPrev;
 
@@ -51,8 +51,8 @@ public:
     void SetFollow( std::unique_ptr<SwDropPortionPart> pNew ) { m_pFollow = 
std::move(pNew); };
     SwFont& GetFont() const { return *m_pFnt; }
     TextFrameIndex GetLen() const { return m_nLen; }
-    sal_uInt16 GetWidth() const { return m_nWidth; }
-    void SetWidth( sal_uInt16 nNew )  { m_nWidth = nNew; }
+    SwTwips GetWidth() const { return m_nWidth; }
+    void SetWidth(SwTwips nNew) { m_nWidth = nNew; }
 
     bool GetJoinBorderWithPrev() const { return m_bJoinBorderWithPrev; }
     bool GetJoinBorderWithNext() const { return m_bJoinBorderWithNext; }
@@ -66,33 +66,33 @@ class SwDropPortion : public SwTextPortion
     friend class SwDropCapCache;
     std::unique_ptr<SwDropPortionPart> m_pPart; // due to script/attribute 
changes
     sal_uInt16 m_nLines;          // Line count
-    sal_uInt16 m_nDropHeight;     // Height
-    sal_uInt16 m_nDropDescent;    // Distance to the next line
-    sal_uInt16 m_nDistance;       // Distance to the text
-    sal_uInt16 m_nFix;            // Fixed position
-    short m_nY;               // Y Offset
+    SwTwips m_nDropHeight;     // Height
+    SwTwips m_nDropDescent;    // Distance to the next line
+    SwTwips m_nDistance;       // Distance to the text
+    SwTwips m_nFix;            // Fixed position
+    SwTwips m_nY; // Y Offset
 
     bool FormatText( SwTextFormatInfo &rInf );
     void PaintText( const SwTextPaintInfo &rInf ) const;
 
 public:
     SwDropPortion( const sal_uInt16 nLineCnt,
-                   const sal_uInt16 nDropHeight,
-                   const sal_uInt16 nDropDescent,
-                   const sal_uInt16 nDistance );
+                   const SwTwips nDropHeight,
+                   const SwTwips nDropDescent,
+                   const SwTwips nDistance );
     virtual ~SwDropPortion() override;
 
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
             void PaintDrop( const SwTextPaintInfo &rInf ) const;
     virtual bool Format( SwTextFormatInfo &rInf ) override;
     virtual SwPosSize GetTextSize( const SwTextSizeInfo &rInfo ) const 
override;
-    virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) 
const override;
+    virtual TextFrameIndex GetModelPositionForViewPoint(SwTwips nOfst) const 
override;
 
     sal_uInt16 GetLines() const { return m_nLines; }
-    sal_uInt16 GetDistance() const { return m_nDistance; }
-    sal_uInt16 GetDropHeight() const { return m_nDropHeight; }
-    sal_uInt16 GetDropDescent() const { return m_nDropDescent; }
-    sal_uInt16 GetDropLeft() const { return Width() + m_nFix; }
+    SwTwips GetDistance() const { return m_nDistance; }
+    SwTwips GetDropHeight() const { return m_nDropHeight; }
+    SwTwips GetDropDescent() const { return m_nDropDescent; }
+    SwTwips GetDropLeft() const { return Width() + m_nFix; }
 
     SwDropPortionPart* GetPart() const { return m_pPart.get(); }
     void SetPart( std::unique_ptr<SwDropPortionPart> pNew ) { m_pPart = 
std::move(pNew); }
diff --git a/sw/source/core/text/porexp.cxx b/sw/source/core/text/porexp.cxx
index 377af4671f2b..2361c3acab82 100644
--- a/sw/source/core/text/porexp.cxx
+++ b/sw/source/core/text/porexp.cxx
@@ -23,7 +23,7 @@
 #include "inftxt.hxx"
 #include "porexp.hxx"
 
-TextFrameIndex SwExpandPortion::GetModelPositionForViewPoint(const sal_uInt16 
nOfst) const
+TextFrameIndex SwExpandPortion::GetModelPositionForViewPoint(const SwTwips 
nOfst) const
 { return SwLinePortion::GetModelPositionForViewPoint( nOfst ); }
 
 bool SwExpandPortion::GetExpText( const SwTextSizeInfo&, OUString &rText ) 
const
@@ -289,7 +289,7 @@ void SwPostItsPortion::Paint( const SwTextPaintInfo &rInf ) 
const
         rInf.DrawPostIts( IsScript() );
 }
 
-sal_uInt16 SwPostItsPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
+SwTwips SwPostItsPortion::GetViewWidth(const SwTextSizeInfo& rInf) const
 {
     // Unbelievable: PostIts are always visible
     return rInf.OnWin() ? SwViewOption::GetPostItsWidth( rInf.GetOut() ) : 0;
diff --git a/sw/source/core/text/porexp.hxx b/sw/source/core/text/porexp.hxx
index 82de5b1be4fc..0e0eadf3dd2d 100644
--- a/sw/source/core/text/porexp.hxx
+++ b/sw/source/core/text/porexp.hxx
@@ -26,7 +26,7 @@ class SwExpandPortion : public SwTextPortion
 public:
     SwExpandPortion() { SetWhichPor( PortionType::Expand ); }
     virtual bool Format( SwTextFormatInfo &rInf ) override;
-    virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) 
const override;
+    virtual TextFrameIndex GetModelPositionForViewPoint(SwTwips nOfst) const 
override;
     virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) 
const override;
     virtual SwPosSize GetTextSize( const SwTextSizeInfo &rInfo ) const 
override;
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
@@ -70,7 +70,7 @@ public:
     explicit SwPostItsPortion( bool bScrpt );
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
     virtual bool Format( SwTextFormatInfo &rInf ) override;
-    virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const 
override;
+    virtual SwTwips GetViewWidth(const SwTextSizeInfo& rInf) const override;
     virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) 
const override;
     bool IsScript() const { return m_bScript; }
 };
diff --git a/sw/source/core/text/porfld.cxx b/sw/source/core/text/porfld.cxx
index c1d5c80409dd..6e8cfa4a3770 100644
--- a/sw/source/core/text/porfld.cxx
+++ b/sw/source/core/text/porfld.cxx
@@ -118,7 +118,7 @@ SwFieldPortion::~SwFieldPortion()
     m_pFont.reset();
 }
 
-sal_uInt16 SwFieldPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
+SwTwips SwFieldPortion::GetViewWidth(const SwTextSizeInfo& rInf) const
 {
     // even though this is const, nViewWidth should be computed at the very 
end:
     SwFieldPortion* pThis = const_cast<SwFieldPortion*>(this);
@@ -223,7 +223,7 @@ void SwFieldPortion::CheckScript( const SwTextSizeInfo 
&rInf )
         return;
 
     SwFontScript nActual = m_pFont ? m_pFont->GetActual() : 
rInf.GetFont()->GetActual();
-    sal_uInt16 nScript = g_pBreakIt->GetBreakIter()->getScriptType( aText, 0 );
+    sal_Int16 nScript = g_pBreakIt->GetBreakIter()->getScriptType( aText, 0 );
     sal_Int32 nChg = 0;
     if( i18n::ScriptType::WEAK == nScript )
     {
@@ -550,8 +550,7 @@ bool SwHiddenPortion::GetExpText( const SwTextSizeInfo 
&rInf, OUString &rText )
 SwNumberPortion::SwNumberPortion( const OUString &rExpand,
                                   std::unique_ptr<SwFont> pFont,
                                   const bool bLft,
-                                  const bool bCntr,
-                                  const sal_uInt16 nMinDst,
+                                  const bool bCntr, const SwTwips nMinDst,
                                   const bool 
bLabelAlignmentPosAndSpaceModeActive )
     : SwFieldPortion(rExpand, std::move(pFont), TextFrameIndex(0))
     , m_nFixWidth(0)
@@ -564,7 +563,7 @@ SwNumberPortion::SwNumberPortion( const OUString &rExpand,
     SetCenter( bCntr );
 }
 
-TextFrameIndex SwNumberPortion::GetModelPositionForViewPoint(const sal_uInt16) 
const
+TextFrameIndex SwNumberPortion::GetModelPositionForViewPoint(const SwTwips) 
const
 {
     return TextFrameIndex(0);
 }
@@ -691,9 +690,9 @@ void SwNumberPortion::Paint( const SwTextPaintInfo &rInf ) 
const
     }
 
     // calculate the width of the number portion, including follows
-    const sal_uInt16 nOldWidth = Width();
-    sal_uInt16 nSumWidth = 0;
-    sal_uInt16 nOffset = 0;
+    const SwTwips nOldWidth = Width();
+    SwTwips nSumWidth = 0;
+    SwTwips nOffset = 0;
 
     const SwLinePortion* pTmp = this;
     while ( pTmp && pTmp->InNumberGrp() )
@@ -741,7 +740,7 @@ void SwNumberPortion::Paint( const SwTextPaintInfo &rInf ) 
const
         // logical const: reset width
         SwNumberPortion *pThis = const_cast<SwNumberPortion*>(this);
         bPaintSpace = bPaintSpace && m_nFixWidth < nOldWidth;
-        sal_uInt16 nSpaceOffs = m_nFixWidth;
+        SwTwips nSpaceOffs = m_nFixWidth;
         pThis->Width( m_nFixWidth );
 
         if( ( IsLeft() && ! rInf.GetTextFrame()->IsRightToLeft() ) ||
@@ -757,7 +756,7 @@ void SwNumberPortion::Paint( const SwTextPaintInfo &rInf ) 
const
                 if( IsCenter() )
                 {
                     /* #110778# a / 2 * 2 == a is not a tautology */
-                    sal_uInt16 nTmpOffset = nOffset;
+                    SwTwips nTmpOffset = nOffset;
                     nOffset /= 2;
                     if( nOffset < m_nMinDist )
                         nOffset = nTmpOffset - m_nMinDist;
@@ -797,7 +796,7 @@ SwBulletPortion::SwBulletPortion( const sal_UCS4 cBullet,
                                   std::unique_ptr<SwFont> pFont,
                                   const bool bLft,
                                   const bool bCntr,
-                                  const sal_uInt16 nMinDst,
+                                 const SwTwips nMinDst,
                                   const bool 
bLabelAlignmentPosAndSpaceModeActive )
     : SwNumberPortion( OUString(&cBullet, 1) + rBulletFollowedBy,
                        std::move(pFont), bLft, bCntr, nMinDst,
@@ -812,7 +811,7 @@ SwGrfNumPortion::SwGrfNumPortion(
         const OUString& rGraphicFollowedBy,
         const SvxBrushItem* pGrfBrush, OUString const & referer,
         const SwFormatVertOrient* pGrfOrient, const Size& rGrfSize,
-        const bool bLft, const bool bCntr, const sal_uInt16 nMinDst,
+        const bool bLft, const bool bCntr, const SwTwips nMinDst,
         const bool bLabelAlignmentPosAndSpaceModeActive ) :
     SwNumberPortion( rGraphicFollowedBy, nullptr, bLft, bCntr, nMinDst,
                      bLabelAlignmentPosAndSpaceModeActive ),
@@ -843,7 +842,7 @@ SwGrfNumPortion::SwGrfNumPortion(
     Width( rGrfSize.Width() + 2 * GRFNUM_SECURE );
     m_nFixWidth = Width();
     m_nGrfHeight = rGrfSize.Height() + 2 * GRFNUM_SECURE;
-    Height( sal_uInt16(m_nGrfHeight) );
+    Height(m_nGrfHeight);
     m_bNoPaint = false;
 }
 
@@ -872,7 +871,7 @@ bool SwGrfNumPortion::Format( SwTextFormatInfo &rInf )
 {
     SetHide( false );
 //    Width( nFixWidth );
-    sal_uInt16 nFollowedByWidth( 0 );
+    SwTwips nFollowedByWidth(0);
     if ( mbLabelAlignmentPosAndSpaceModeActive )
     {
         SwFieldPortion::Format( rInf );
@@ -955,7 +954,7 @@ void SwGrfNumPortion::Paint( const SwTextPaintInfo &rInf ) 
const
 
     if( m_nFixWidth < Width() && !bTmpLeft )
     {
-        sal_uInt16 nOffset = Width() - m_nFixWidth;
+        SwTwips nOffset = Width() - m_nFixWidth;
         if( nOffset < m_nMinDist )
             nOffset = 0;
         else
@@ -1121,9 +1120,7 @@ void SwTextFrame::StopAnimation( const OutputDevice* pOut 
)
  */
 SwCombinedPortion::SwCombinedPortion( const OUString &rText )
     : SwFieldPortion( rText )
-    , m_aWidth{ static_cast<sal_uInt16>(0),
-                static_cast<sal_uInt16>(0),
-                static_cast<sal_uInt16>(0) }
+    , m_aWidth{ 0, 0, 0 }
     , m_nUpPos(0)
     , m_nLowPos(0)
     , m_nProportion(55)
@@ -1228,7 +1225,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf )
             {
                 rInf.GetOut()->SetFont( rInf.GetFont()->GetFnt( m_aScrType[i] 
) );
                 m_aWidth[ m_aScrType[i] ] =
-                        o3tl::narrowing<sal_uInt16>(2 * 
rInf.GetOut()->GetFontMetric().GetFontSize().Width() / 3);
+                        2 * 
rInf.GetOut()->GetFontMetric().GetFontSize().Width() / 3;
             }
         }
     }
@@ -1240,7 +1237,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf )
     m_nProportion = 55;
     // In nMainAscent/Descent we store the ascent and descent
     // of the original surrounding font
-    sal_uInt16 nMaxDescent, nMaxAscent, nMaxWidth;
+    SwTwips nMaxDescent, nMaxAscent, nMaxWidth;
     sal_uInt16 nMainDescent = rInf.GetFont()->GetHeight( pSh, *rInf.GetOut() );
     const sal_uInt16 nMainAscent = rInf.GetFont()->GetAscent( pSh, 
*rInf.GetOut() );
     nMainDescent = nMainDescent - nMainAscent;
@@ -1275,7 +1272,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf )
             SwDrawTextInfo aDrawInf(pSh, *rInf.GetOut(), m_aExpand, i, 1);
             Size aSize = aTmpFont.GetTextSize_( aDrawInf );
             const sal_uInt16 nAsc = aTmpFont.GetAscent( pSh, *rInf.GetOut() );
-            m_aPos[ i ] = o3tl::narrowing<sal_uInt16>(aSize.Width());
+            m_aPos[i] = aSize.Width();
             if( i == nTop ) // enter the second line
             {
                 m_nLowPos = nMaxDescent;
@@ -1319,8 +1316,8 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf )
         Height( nMainAscent + nMainDescent );
 
     // We calculate the x positions of the characters in both lines...
-    sal_uInt16 nTopDiff = 0;
-    sal_uInt16 nBotDiff = 0;
+    SwTwips nTopDiff = 0;
+    SwTwips nBotDiff = 0;
     if( nMaxWidth > Width() )
     {
         nTopDiff = ( nMaxWidth - Width() ) / 2;
@@ -1366,7 +1363,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf )
     return bFull;
 }
 
-sal_uInt16 SwCombinedPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
+SwTwips SwCombinedPortion::GetViewWidth(const SwTextSizeInfo& rInf) const
 {
     if( !GetLen() ) // for the dummy part at the end of the line, where
         return 0;   // the combined portion doesn't fit.
diff --git a/sw/source/core/text/porfld.hxx b/sw/source/core/text/porfld.hxx
index b92372942425..0f038487c11f 100644
--- a/sw/source/core/text/porfld.hxx
+++ b/sw/source/core/text/porfld.hxx
@@ -41,7 +41,7 @@ protected:
     TextFrameIndex m_nNextScriptChg;
     TextFrameIndex m_nFieldLen; //< Length of field text, 1 for normal fields, 
any number for input fields
     // TODO ^ do we need this as member or is base class len enough?
-    sal_uInt16  m_nViewWidth;     // Screen width for empty fields
+    SwTwips m_nViewWidth; // Screen width for empty fields
     bool m_bFollow : 1;           // 2nd or later part of a field
     bool m_bLeft : 1;             // Used by SwNumberPortion
     bool m_bHide : 1;             // Used by SwNumberPortion
@@ -76,7 +76,7 @@ public:
     // Empty fields are also allowed
     virtual SwLinePortion *Compress() override;
 
-    virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const 
override;
+    virtual SwTwips GetViewWidth(const SwTextSizeInfo& rInf) const override;
 
     bool IsFollow() const { return m_bFollow; }
     void SetFollow( bool bNew ) { m_bFollow = bNew; }
@@ -132,19 +132,18 @@ public:
 class SwNumberPortion : public SwFieldPortion
 {
 protected:
-    sal_uInt16  m_nFixWidth;      // See Glues
-    sal_uInt16  m_nMinDist;       // Minimal distance to the text
+    SwTwips m_nFixWidth; // See Glues
+    SwTwips m_nMinDist; // Minimal distance to the text
     bool    mbLabelAlignmentPosAndSpaceModeActive;
 
 public:
     SwNumberPortion( const OUString &rExpand,
                      std::unique_ptr<SwFont> pFnt,
                      const bool bLeft,
-                     const bool bCenter,
-                     const sal_uInt16 nMinDst,
+                     const bool bCenter, const SwTwips nMinDst,
                      const bool bLabelAlignmentPosAndSpaceModeActive );
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
-    virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) 
const override;
+    virtual TextFrameIndex GetModelPositionForViewPoint(SwTwips nOfst) const 
override;
     virtual bool Format( SwTextFormatInfo &rInf ) override;
 
     // Field cloner for SplitGlue
@@ -160,7 +159,7 @@ public:
                      std::unique_ptr<SwFont> pFnt,
                      const bool bLeft,
                      const bool bCenter,
-                     const sal_uInt16 nMinDst,
+                     const SwTwips nMinDst,
                      const bool bLabelAlignmentPosAndSpaceModeActive );
 };
 
@@ -179,7 +178,7 @@ public:
                      const Size& rGrfSize,
                      const bool bLeft,
                      const bool bCenter,
-                     const sal_uInt16 nMinDst,
+                     const SwTwips nMinDst,
                      const bool bLabelAlignmentPosAndSpaceModeActive );
     virtual ~SwGrfNumPortion() override;
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
@@ -210,17 +209,17 @@ public:
  */
 class SwCombinedPortion : public SwFieldPortion
 {
-    sal_uInt16 m_aPos[6];     // up to six X positions
-    o3tl::enumarray<SwFontScript,sal_uInt16> m_aWidth; // one width for every 
scripttype
+    SwTwips m_aPos[6]; // up to six X positions
+    o3tl::enumarray<SwFontScript, SwTwips> m_aWidth; // one width for every 
scripttype
     SwFontScript m_aScrType[6];  // scripttype of every character
-    sal_uInt16 m_nUpPos;      // the Y position of the upper baseline
-    sal_uInt16 m_nLowPos;     // the Y position of the lower baseline
+    SwTwips m_nUpPos; // the Y position of the upper baseline
+    SwTwips m_nLowPos; // the Y position of the lower baseline
     sal_uInt8 m_nProportion;  // relative font height
 public:
     explicit SwCombinedPortion( const OUString &rExpand );
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
     virtual bool Format( SwTextFormatInfo &rInf ) override;
-    virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const 
override;
+    virtual SwTwips GetViewWidth(const SwTextSizeInfo& rInf) const override;
 };
 
 namespace sw::mark { class IFieldmark; }
diff --git a/sw/source/core/text/porfly.cxx b/sw/source/core/text/porfly.cxx
index 19ac692cf42f..6cfcec2962b4 100644
--- a/sw/source/core/text/porfly.cxx
+++ b/sw/source/core/text/porfly.cxx
@@ -68,7 +68,7 @@ bool SwFlyPortion::Format( SwTextFormatInfo &rInf )
         rInf.X(rInf.X() - blankWidth); // Step back
     }
 
-    PrtWidth( o3tl::narrowing<sal_uInt16>(GetFix() - rInf.X() + PrtWidth()) );
+    PrtWidth(GetFix() - rInf.X() + PrtWidth());
     if( !Width() )
     {
         OSL_ENSURE( Width(), "+SwFlyPortion::Format: a fly is a fly is a fly" 
);
@@ -92,7 +92,7 @@ bool SwFlyPortion::Format( SwTextFormatInfo &rInf )
         SetLen(TextFrameIndex(1));
     }
 
-    const sal_uInt16 nNewWidth = o3tl::narrowing<sal_uInt16>(rInf.X() + 
PrtWidth());
+    const SwTwips nNewWidth = rInf.X() + PrtWidth();
     if( rInf.Width() <= nNewWidth )
     {
         Truncate();
@@ -410,7 +410,7 @@ void SwFlyCntPortion::SetBase( const SwTextFrame& rFrame, 
const Point &rBase,
         else
         {
             mnAscent = 0;
-            Height( Height() + o3tl::narrowing<sal_uInt16>(nRelPos) );
+            Height(Height() + nRelPos);
         }
     }
     else
diff --git a/sw/source/core/text/porftn.hxx b/sw/source/core/text/porftn.hxx
index 925a04f7793b..58ece78aab34 100644
--- a/sw/source/core/text/porftn.hxx
+++ b/sw/source/core/text/porftn.hxx
@@ -30,14 +30,14 @@ class SwTextFootnote;
 class SwFootnotePortion : public SwFieldPortion
 {
     SwTextFootnote *m_pFootnote;
-    sal_uInt16 m_nOrigHeight;
+    SwTwips m_nOrigHeight;
     // #i98418#
     bool mbPreferredScriptTypeSet;
     SwFontScript mnPreferredScriptType;
 public:
     SwFootnotePortion( const OUString &rExpand, SwTextFootnote *pFootnote,
-                  sal_uInt16 nOrig = USHRT_MAX );
-    sal_uInt16& Orig() { return m_nOrigHeight; }
+                      SwTwips nOrig = std::numeric_limits<SwTwips>::max());
+    SwTwips& Orig() { return m_nOrigHeight; }
 
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
     virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) 
const override;
@@ -94,7 +94,7 @@ class SwErgoSumPortion : public SwFieldPortion
 {
 public:
     SwErgoSumPortion( const OUString &rExp, std::u16string_view rStr );
-    virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) 
const override;
+    virtual TextFrameIndex GetModelPositionForViewPoint(SwTwips nOfst) const 
override;
     virtual bool Format( SwTextFormatInfo &rInf ) override;
 
     // Field cloner for SplitGlue
diff --git a/sw/source/core/text/porglue.cxx b/sw/source/core/text/porglue.cxx
index 5f1fd2a7dc8d..8d72a5b8745c 100644
--- a/sw/source/core/text/porglue.cxx
+++ b/sw/source/core/text/porglue.cxx
@@ -25,14 +25,14 @@
 #include "porfly.hxx"
 #include <comphelper/string.hxx>
 
-SwGluePortion::SwGluePortion( const sal_uInt16 nInitFixWidth )
+SwGluePortion::SwGluePortion(const SwTwips nInitFixWidth)
     : m_nFixWidth( nInitFixWidth )
 {
     PrtWidth( m_nFixWidth );
     SetWhichPor( PortionType::Glue );
 }
 
-TextFrameIndex SwGluePortion::GetModelPositionForViewPoint(const sal_uInt16 
nOfst) const
+TextFrameIndex SwGluePortion::GetModelPositionForViewPoint(const SwTwips 
nOfst) const
 {
     // FIXME why nOfst > GetLen() ? is that supposed to be > Width() ?
     if( !GetLen() || nOfst > sal_Int32(GetLen()) || !Width() )
@@ -145,9 +145,9 @@ void SwGluePortion::dumpAsXml(xmlTextWriterPtr pWriter, 
const OUString& rText,
  * We're expecting a frame-local SwRect!
  */
 SwFixPortion::SwFixPortion( const SwRect &rRect )
-       :SwGluePortion( sal_uInt16(rRect.Width()) ), m_nFix( 
sal_uInt16(rRect.Left()) )
+       :SwGluePortion(rRect.Width()), m_nFix(rRect.Left())
 {
-    Height( sal_uInt16(rRect.Height()) );
+    Height(rRect.Height());
     SetWhichPor( PortionType::Fix );
 }
 
diff --git a/sw/source/core/text/porglue.hxx b/sw/source/core/text/porglue.hxx
index aaaeec339f31..c48d063144ff 100644
--- a/sw/source/core/text/porglue.hxx
+++ b/sw/source/core/text/porglue.hxx
@@ -30,21 +30,21 @@ class SwLineLayout;
 class SwGluePortion : public SwLinePortion
 {
 private:
-    sal_uInt16 m_nFixWidth;
+    SwTwips m_nFixWidth;
 public:
-    explicit SwGluePortion( const sal_uInt16 nInitFixWidth );
+    explicit SwGluePortion(const SwTwips nInitFixWidth);
 
     void Join( SwGluePortion *pVictim );
 
     inline tools::Long GetPrtGlue() const;
-    sal_uInt16 GetFixWidth() const { return m_nFixWidth; }
-    void SetFixWidth( const sal_uInt16 nNew ) { m_nFixWidth = nNew; }
+    SwTwips GetFixWidth() const { return m_nFixWidth; }
+    void SetFixWidth(const SwTwips nNew) { m_nFixWidth = nNew; }
     void MoveGlue( SwGluePortion *pTarget, const tools::Long nPrtGlue );
     inline void MoveAllGlue( SwGluePortion *pTarget );
     inline void MoveHalfGlue( SwGluePortion *pTarget );
     inline void AdjFixWidth();
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
-    virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) 
const override;
+    virtual TextFrameIndex GetModelPositionForViewPoint(SwTwips nOfst) const 
override;
     virtual SwPosSize GetTextSize( const SwTextSizeInfo &rInfo ) const 
override;
     virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) 
const override;
 
@@ -53,12 +53,12 @@ public:
 
 class SwFixPortion : public SwGluePortion
 {
-    sal_uInt16 m_nFix;        // The width offset in the line
+    SwTwips m_nFix; // The width offset in the line
 public:
     explicit SwFixPortion( const SwRect &rFlyRect );
     SwFixPortion();
-    void   SetFix( const sal_uInt16 nNewFix ) { m_nFix = nNewFix; }
-    sal_uInt16 GetFix() const { return m_nFix; }
+    void SetFix(const SwTwips nNewFix) { m_nFix = nNewFix; }
+    SwTwips GetFix() const { return m_nFix; }
 
     void dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText, 
TextFrameIndex& nOffset) const override;
 };
diff --git a/sw/source/core/text/porhyph.hxx b/sw/source/core/text/porhyph.hxx
index dc3c6651d0a8..a8340089add1 100644
--- a/sw/source/core/text/porhyph.hxx
+++ b/sw/source/core/text/porhyph.hxx
@@ -60,7 +60,7 @@ public:
 class SwSoftHyphPortion : public SwHyphPortion
 {
     bool    m_bExpand;
-    sal_uInt16  m_nViewWidth;
+    SwTwips m_nViewWidth;
 
 public:
     SwSoftHyphPortion();
@@ -72,7 +72,7 @@ public:
     void SetExpand( const bool bNew ) { m_bExpand = bNew; }
     bool IsExpand() const { return m_bExpand; }
 
-    virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const 
override;
+    virtual SwTwips GetViewWidth(const SwTextSizeInfo& rInf) const override;
 
     // Accessibility: pass information about this portion to the PortionHandler
     virtual void HandlePortion( SwPortionHandler& rPH ) const override;
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 2e2d1e6e17a4..44f709eec1f1 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -372,7 +372,7 @@ static bool lcl_HasOnlyBlanks(std::u16string_view rText, 
TextFrameIndex nStt, Te
 // Swapped out from FormatLine()
 void SwLineLayout::CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf )
 {
-    const sal_uInt16 nLineWidth = rInf.RealWidth();
+    const SwTwips nLineWidth = rInf.RealWidth();
 
     sal_uInt16 nFlyAscent = 0;
     sal_uInt16 nFlyHeight = 0;
diff --git a/sw/source/core/text/porlin.cxx b/sw/source/core/text/porlin.cxx
index a420d64301ff..845fcda08830 100644
--- a/sw/source/core/text/porlin.cxx
+++ b/sw/source/core/text/porlin.cxx
@@ -59,10 +59,7 @@ SwLinePortion *SwLinePortion::Compress()
     return GetLen() || Width() ? this : nullptr;
 }
 
-sal_uInt16 SwLinePortion::GetViewWidth( const SwTextSizeInfo & ) const
-{
-    return 0;
-}
+SwTwips SwLinePortion::GetViewWidth(const SwTextSizeInfo&) const { return 0; }
 
 SwLinePortion::SwLinePortion( ) :
     mpNextPortion( nullptr ),
@@ -81,18 +78,18 @@ void SwLinePortion::PrePaint( const SwTextPaintInfo& rInf,
     OSL_ENSURE( rInf.OnWin(), "SwLinePortion::PrePaint: don't prepaint on a 
printer");
     OSL_ENSURE( !Width(), "SwLinePortion::PrePaint: For Width()==0 only!");
 
-    const sal_uInt16 nViewWidth = GetViewWidth( rInf );
+    const SwTwips nViewWidth = GetViewWidth(rInf);
 
     if( ! nViewWidth )
         return;
 
-    const sal_uInt16 nHalfView = nViewWidth / 2;
-    sal_uInt16 nLastWidth = pLast->Width() + pLast->ExtraBlankWidth();
+    const SwTwips nHalfView = nViewWidth / 2;
+    SwTwips nLastWidth = pLast->Width() + pLast->ExtraBlankWidth();
 
     if ( pLast->InSpaceGrp() && rInf.GetSpaceAdd(/*bShrink=*/true) )
         nLastWidth += pLast->CalcSpacing( rInf.GetSpaceAdd(/*bShrink=*/true), 
rInf );
 
-    sal_uInt16 nPos;
+    SwTwips nPos;
     SwTextPaintInfo aInf( rInf );
 
     const bool bBidiPor = rInf.GetTextFrame()->IsRightToLeft() !=
@@ -109,22 +106,22 @@ void SwLinePortion::PrePaint( const SwTextPaintInfo& rInf,
         switch (nDir.get())
         {
         case 0:
-            nPos = sal_uInt16( rInf.X() );
+            nPos = rInf.X();
             nPos += nLastWidth - nHalfView;
             aInf.X( nPos );
             break;
         case 900:
-            nPos = sal_uInt16( rInf.Y() );
+            nPos = rInf.Y();
             nPos -= nLastWidth - nHalfView;
             aInf.Y( nPos );
             break;
         case 1800:
-            nPos = sal_uInt16( rInf.X() );
+            nPos = rInf.X();
             nPos -= nLastWidth - nHalfView;
             aInf.X( nPos );
             break;
         case 2700:
-            nPos = sal_uInt16( rInf.Y() );
+            nPos = rInf.Y();
             nPos += nLastWidth - nHalfView;
             aInf.Y( nPos );
             break;
@@ -224,7 +221,7 @@ SwLinePortion *SwLinePortion::FindPrevPortion( const 
SwLinePortion *pRoot )
     return pPos;
 }
 
-TextFrameIndex SwLinePortion::GetModelPositionForViewPoint(const sal_uInt16 
nOfst) const
+TextFrameIndex SwLinePortion::GetModelPositionForViewPoint(const SwTwips 
nOfst) const
 {
     if( nOfst > ( PrtWidth() / 2 ) )
         return GetLen();
@@ -251,7 +248,7 @@ bool SwLinePortion::Format( SwTextFormatInfo &rInf )
     const SwLinePortion *pLast = rInf.GetLast();
     Height( pLast->Height() );
     SetAscent( pLast->GetAscent() );
-    const sal_uInt16 nNewWidth = o3tl::narrowing<sal_uInt16>(rInf.X() + 
PrtWidth());
+    const SwTwips nNewWidth = rInf.X() + PrtWidth();
     // Only portions with true width can return true
     // Notes for example never set bFull==true
     if( rInf.Width() <= nNewWidth && PrtWidth() && ! IsKernPortion() )
diff --git a/sw/source/core/text/porlin.hxx b/sw/source/core/text/porlin.hxx
index 695cf5cb9103..1b4b50ba44b8 100644
--- a/sw/source/core/text/porlin.hxx
+++ b/sw/source/core/text/porlin.hxx
@@ -139,8 +139,7 @@ public:
     SwLinePortion *FindPrevPortion( const SwLinePortion *pRoot );
     SwLinePortion *FindLastPortion();
 
-    /// the parameter is actually SwTwips apparently?
-    virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) 
const;
+    virtual TextFrameIndex GetModelPositionForViewPoint(SwTwips nOfst) const;
     virtual SwPosSize GetTextSize( const SwTextSizeInfo &rInfo ) const;
     void CalcTextSize( const SwTextSizeInfo &rInfo );
 
@@ -157,7 +156,7 @@ public:
     virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) 
const;
 
     // For SwFieldPortion, SwSoftHyphPortion
-    virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const;
+    virtual SwTwips GetViewWidth(const SwTextSizeInfo& rInf) const;
 
     // for text- and multi-portions
     virtual SwTwips CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo 
&rInf ) const;
diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx
index aaf8339b37ef..df352e6aa785 100644
--- a/sw/source/core/text/pormulti.cxx
+++ b/sw/source/core/text/pormulti.cxx
@@ -2012,7 +2012,9 @@ bool SwTextFormatter::BuildMultiPortion( SwTextFormatInfo 
&rInf,
                     ( rInf.GetTextFrame()->IsVertical() ?
                       pUpperFrame->getFramePrintArea().Width() :
                       pUpperFrame->getFramePrintArea().Height() ) :
-                    USHRT_MAX;
+                    std::numeric_limits<SwTwips>::max();
+        if (nMaxWidth < 0)
+            nMaxWidth = 0;
     }
     else
         nTmpX = rInf.X();
@@ -2084,8 +2086,8 @@ bool SwTextFormatter::BuildMultiPortion( SwTextFormatInfo 
&rInf,
         bRet = false;
         FormatReset( aInf );
         aInf.X( nTmpX );
-        aInf.Width( sal_uInt16(nActWidth) );
-        aInf.RealWidth( sal_uInt16(nActWidth) );
+        aInf.Width(nActWidth);
+        aInf.RealWidth(nActWidth);
         aInf.SetFirstMulti( bFirstMulti );
         aInf.SetNumDone( rInf.IsNumDone() );
         aInf.SetFootnoteDone( rInf.IsFootnoteDone() );
diff --git a/sw/source/core/text/porref.cxx b/sw/source/core/text/porref.cxx
index a64f2df1fe1d..3cf5449d2814 100644
--- a/sw/source/core/text/porref.cxx
+++ b/sw/source/core/text/porref.cxx
@@ -40,7 +40,7 @@ SwIsoRefPortion::SwIsoRefPortion() : m_nViewWidth(0)
     SetWhichPor( PortionType::IsoRef );
 }
 
-sal_uInt16 SwIsoRefPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
+SwTwips SwIsoRefPortion::GetViewWidth(const SwTextSizeInfo& rInf) const
 {
     // Although we are const, nViewWidth should be calculated in the last
     // moment possible
diff --git a/sw/source/core/text/porref.hxx b/sw/source/core/text/porref.hxx
index d12803080345..953d7462b3d6 100644
--- a/sw/source/core/text/porref.hxx
+++ b/sw/source/core/text/porref.hxx
@@ -29,14 +29,14 @@ public:
 
 class SwIsoRefPortion : public SwRefPortion
 {
-    sal_uInt16 m_nViewWidth;
+    SwTwips m_nViewWidth;
 
 public:
     SwIsoRefPortion();
     virtual bool Format(SwTextFormatInfo& rInf) override;
     virtual void Paint(const SwTextPaintInfo& rInf) const override;
     virtual SwLinePortion* Compress() override;
-    virtual sal_uInt16 GetViewWidth(const SwTextSizeInfo& rInf) const override;
+    virtual SwTwips GetViewWidth(const SwTextSizeInfo& rInf) const override;
 
     // Accessibility: pass information about this portion to the PortionHandler
     virtual void HandlePortion(SwPortionHandler& rPH) const override;
diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx
index 8f0b89852450..dcbd6085f812 100644
--- a/sw/source/core/text/porrst.cxx
+++ b/sw/source/core/text/porrst.cxx
@@ -128,13 +128,12 @@ SwBreakPortion::SwBreakPortion( const SwLinePortion 
&rPortion, const SwTextAttr*
     m_nTextHeight = 0;
 }
 
-TextFrameIndex SwBreakPortion::GetModelPositionForViewPoint(const sal_uInt16) 
const
+TextFrameIndex SwBreakPortion::GetModelPositionForViewPoint(const SwTwips) 
const
 {
     return TextFrameIndex(0);
 }
 
-sal_uInt16 SwBreakPortion::GetViewWidth( const SwTextSizeInfo & ) const
-{ return 0; }
+SwTwips SwBreakPortion::GetViewWidth(const SwTextSizeInfo&) const { return 0; }
 
 SwLinePortion *SwBreakPortion::Compress()
 { return (GetNextPortion() && GetNextPortion()->InTextGrp() ? nullptr : this); 
}
@@ -329,7 +328,7 @@ SwArrowPortion::SwArrowPortion( const SwLinePortion 
&rPortion ) :
 SwArrowPortion::SwArrowPortion( const SwTextPaintInfo &rInf )
     : m_bLeft( false )
 {
-    Height( 
o3tl::narrowing<sal_uInt16>(rInf.GetTextFrame()->getFramePrintArea().Height()) 
);
+    Height(rInf.GetTextFrame()->getFramePrintArea().Height());
     m_aPos.setX( rInf.GetTextFrame()->getFrameArea().Left() +
                rInf.GetTextFrame()->getFramePrintArea().Right() );
     m_aPos.setY( rInf.GetTextFrame()->getFrameArea().Top() +
@@ -847,13 +846,13 @@ void SwBookmarkPortion::Paint( const SwTextPaintInfo 
&rInf ) const
         // some |text| here
         //     [[    ]]
         if (m_nStart > 1)
-            aNewPos.AdjustX(static_cast<tools::Long>(mnHalfCharWidth) * -2 * 
(m_aColors.size() - 1));
+            aNewPos.AdjustX(mnHalfCharWidth * -2 * (m_aColors.size() - 1));
     }
     else if ( m_nStart != 0 && m_nEnd != 0 )
         // both end and start boundary marks: adjust them around the bookmark 
position
         // |te|xt|
         //  ]] [[
-        aNewPos.AdjustX(static_cast<tools::Long>(mnHalfCharWidth) * -(2 * 
m_nEnd - 1 + m_nPoint) );
+        aNewPos.AdjustX(mnHalfCharWidth * -(2 * m_nEnd - 1 + m_nPoint) );
 
     const_cast< SwTextPaintInfo& >( rInf ).SetPos( aNewPos );
 
@@ -951,7 +950,7 @@ bool SwControlCharPortion::Format( SwTextFormatInfo &rInf )
     return false;
 }
 
-sal_uInt16 SwControlCharPortion::GetViewWidth( const SwTextSizeInfo& rInf ) 
const
+SwTwips SwControlCharPortion::GetViewWidth(const SwTextSizeInfo& rInf) const
 {
     if( !mnViewWidth )
         mnViewWidth = rInf.GetTextSize(OUString(' ')).Width();
diff --git a/sw/source/core/text/porrst.hxx b/sw/source/core/text/porrst.hxx
index 56108cd08846..889f7e7d775a 100644
--- a/sw/source/core/text/porrst.hxx
+++ b/sw/source/core/text/porrst.hxx
@@ -72,8 +72,8 @@ public:
     virtual SwLinePortion *Compress() override;
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
     virtual bool Format( SwTextFormatInfo &rInf ) override;
-    virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const 
override;
-    virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) 
const override;
+    virtual SwTwips GetViewWidth(const SwTextSizeInfo& rInf) const override;
+    virtual TextFrameIndex GetModelPositionForViewPoint(SwTwips nOfst) const 
override;
 
     // Accessibility: pass information about this portion to the PortionHandler
     virtual void HandlePortion( SwPortionHandler& rPH ) const override;
@@ -131,7 +131,7 @@ public:
 // The SwHangingPortion is the corresponding textportion to do that.
 class SwHangingPortion : public SwTextPortion
 {
-    sal_uInt16 m_nInnerWidth;
+    SwTwips m_nInnerWidth;
 public:
     explicit SwHangingPortion( SwPosSize aSize ) : m_nInnerWidth( 
aSize.Width() )
     {
@@ -140,7 +140,7 @@ public:
         Height( aSize.Height() );
     }
 
-    sal_uInt16 GetInnerWidth() const { return m_nInnerWidth; }
+    SwTwips GetInnerWidth() const { return m_nInnerWidth; }
 };
 
 // Used to hide text
@@ -160,9 +160,9 @@ class SwControlCharPortion : public SwLinePortion
 {
 
 private:
-    mutable sal_uInt16 mnViewWidth;            // used to cache a calculated 
value
+    mutable SwTwips mnViewWidth; // used to cache a calculated value
 protected:
-    mutable sal_uInt16 mnHalfCharWidth;        // used to cache a calculated 
value
+    mutable SwTwips mnHalfCharWidth; // used to cache a calculated value
     sal_Unicode mcChar;
 
 public:
@@ -177,7 +177,7 @@ public:
         OUString & rOutString, SwFont & rTmpFont, int & rDeltaY) const;
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
     virtual bool Format( SwTextFormatInfo &rInf ) override;
-    virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo& rInf ) const 
override;
+    virtual SwTwips GetViewWidth(const SwTextSizeInfo& rInf) const override;
 };
 
 /// for showing bookmark starts and ends; note that in contrast to
diff --git a/sw/source/core/text/portab.hxx b/sw/source/core/text/portab.hxx
index 9ffe7be50651..a37ef06c5d35 100644
--- a/sw/source/core/text/portab.hxx
+++ b/sw/source/core/text/portab.hxx
@@ -22,20 +22,20 @@
 
 class SwTabPortion : public SwFixPortion
 {
-    const sal_uInt16 m_nTabPos;
+    const SwTwips m_nTabPos;
     const sal_Unicode m_cFill;
     const bool m_bAutoTabStop;
 
     // Format() branches either into PreFormat() or PostFormat()
     bool PreFormat( SwTextFormatInfo &rInf );
 public:
-    SwTabPortion( const sal_uInt16 nTabPos, const sal_Unicode cFill, const 
bool bAutoTab = true );
+    SwTabPortion(const SwTwips nTabPos, const sal_Unicode cFill, const bool 
bAutoTab = true);
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
     virtual bool Format( SwTextFormatInfo &rInf ) override;
     virtual void FormatEOL( SwTextFormatInfo &rInf ) override;
     bool PostFormat( SwTextFormatInfo &rInf );
     bool IsFilled() const { return 0 != m_cFill; }
-    sal_uInt16 GetTabPos() const { return m_nTabPos; }
+    SwTwips GetTabPos() const { return m_nTabPos; }
 
     // Accessibility: pass information about this portion to the PortionHandler
     virtual void HandlePortion( SwPortionHandler& rPH ) const override;
@@ -44,7 +44,7 @@ public:
 class SwTabLeftPortion : public SwTabPortion
 {
 public:
-    SwTabLeftPortion( const sal_uInt16 nTabPosVal, const sal_Unicode 
cFillChar, bool bAutoTab )
+    SwTabLeftPortion(const SwTwips nTabPosVal, const sal_Unicode cFillChar, 
bool bAutoTab)
          : SwTabPortion( nTabPosVal, cFillChar, bAutoTab )
     { SetWhichPor( PortionType::TabLeft ); }
 };
@@ -52,7 +52,7 @@ public:
 class SwTabRightPortion : public SwTabPortion
 {
 public:
-    SwTabRightPortion( const sal_uInt16 nTabPosVal, const sal_Unicode 
cFillChar )
+    SwTabRightPortion(const SwTwips nTabPosVal, const sal_Unicode cFillChar)
          : SwTabPortion( nTabPosVal, cFillChar )
     { SetWhichPor( PortionType::TabRight ); }
 };
@@ -60,7 +60,7 @@ public:
 class SwTabCenterPortion : public SwTabPortion
 {
 public:
-    SwTabCenterPortion( const sal_uInt16 nTabPosVal, const sal_Unicode 
cFillChar )
+    SwTabCenterPortion(const SwTwips nTabPosVal, const sal_Unicode cFillChar)
          : SwTabPortion( nTabPosVal, cFillChar )
     { SetWhichPor( PortionType::TabCenter ); }
 };
@@ -74,23 +74,23 @@ class SwTabDecimalPortion : public SwTabPortion
      * following the tab stop up to the decimal position. This value is
      * evaluated during pLastTab->FormatEOL. FME 2006-01-06 #127428#.
      */
-    sal_uInt16 mnWidthOfPortionsUpTpDecimalPosition;
+    SwTwips mnWidthOfPortionsUpTpDecimalPosition;
 
 public:
-    SwTabDecimalPortion( const sal_uInt16 nTabPosVal, const sal_Unicode cTab,
+    SwTabDecimalPortion(const SwTwips nTabPosVal, const sal_Unicode cTab,
                                 const sal_Unicode cFillChar )
          : SwTabPortion( nTabPosVal, cFillChar ),
            mcTab(cTab),
-           mnWidthOfPortionsUpTpDecimalPosition( USHRT_MAX )
+           mnWidthOfPortionsUpTpDecimalPosition( 
std::numeric_limits<SwTwips>::max() )
     { SetWhichPor( PortionType::TabDecimal ); }
 
     sal_Unicode GetTabDecimal() const { return mcTab; }
 
-    void SetWidthOfPortionsUpToDecimalPosition( sal_uInt16 nNew )
+    void SetWidthOfPortionsUpToDecimalPosition(SwTwips nNew)
     {
         mnWidthOfPortionsUpTpDecimalPosition = nNew;
     }
-    sal_uInt16 GetWidthOfPortionsUpToDecimalPosition() const
+    SwTwips GetWidthOfPortionsUpToDecimalPosition() const
     {
         return mnWidthOfPortionsUpTpDecimalPosition;
     }
@@ -99,7 +99,7 @@ public:
 class SwAutoTabDecimalPortion : public SwTabDecimalPortion
 {
 public:
-    SwAutoTabDecimalPortion( const sal_uInt16 nTabPosVal, const sal_Unicode 
cTab,
+    SwAutoTabDecimalPortion(const SwTwips nTabPosVal, const sal_Unicode cTab,
                                     const sal_Unicode cFillChar )
          : SwTabDecimalPortion( nTabPosVal, cTab, cFillChar )
     {
diff --git a/sw/source/core/text/portox.cxx b/sw/source/core/text/portox.cxx
index bd72e83b042d..f953316c1375 100644
--- a/sw/source/core/text/portox.cxx
+++ b/sw/source/core/text/portox.cxx
@@ -40,7 +40,7 @@ SwIsoToxPortion::SwIsoToxPortion() : m_nViewWidth(0)
     SetWhichPor( PortionType::IsoTox );
 }
 
-sal_uInt16 SwIsoToxPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
+SwTwips SwIsoToxPortion::GetViewWidth(const SwTextSizeInfo& rInf) const
 {
     // Although we are const, nViewWidth should be calculated in the last
     // moment possible
diff --git a/sw/source/core/text/portox.hxx b/sw/source/core/text/portox.hxx
index 07d7c44fb24e..541963570823 100644
--- a/sw/source/core/text/portox.hxx
+++ b/sw/source/core/text/portox.hxx
@@ -30,14 +30,14 @@ public:
 
 class SwIsoToxPortion : public SwToxPortion
 {
-    sal_uInt16 m_nViewWidth;
+    SwTwips m_nViewWidth;
 
 public:
     SwIsoToxPortion();
     virtual bool Format(SwTextFormatInfo& rInf) override;
     virtual void Paint(const SwTextPaintInfo& rInf) const override;
     virtual SwLinePortion* Compress() override;
-    virtual sal_uInt16 GetViewWidth(const SwTextSizeInfo& rInf) const override;
+    virtual SwTwips GetViewWidth(const SwTextSizeInfo& rInf) const override;
 
     // Accessibility: pass information about this portion to the PortionHandler
     virtual void HandlePortion(SwPortionHandler& rPH) const override;
diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx
index 866b40a0f46b..8dcf75dc0019 100644
--- a/sw/source/core/text/portxt.cxx
+++ b/sw/source/core/text/portxt.cxx
@@ -221,7 +221,7 @@ void SwTextPortion::BreakCut( SwTextFormatInfo &rInf, const 
SwTextGuess &rGuess
     // The word/char is larger than the line
     // Special case 1: The word is larger than the line
     // We truncate ...
-    const sal_uInt16 nLineWidth = o3tl::narrowing<sal_uInt16>(rInf.Width() - 
rInf.X());
+    const SwTwips nLineWidth = rInf.Width() - rInf.X();
     TextFrameIndex nLen = rGuess.CutPos() - rInf.GetIdx();
     if (nLen > TextFrameIndex(0))
     {
@@ -235,7 +235,7 @@ void SwTextPortion::BreakCut( SwTextFormatInfo &rInf, const 
SwTextGuess &rGuess
 
             // changing these values requires also changing them in
             // guess.cxx
-            sal_uInt16 nItalic = 0;
+            SwTwips nItalic = 0;
             if( ITALIC_NONE != rInf.GetFont()->GetItalic() && !rInf.NotEOL() )
             {
                 nItalic = Height() / 12;
@@ -523,7 +523,7 @@ void SwTextPortion::FormatEOL( SwTextFormatInfo &rInf )
 
     // First set ourselves and the insert, because there could be
     // a SwLineLayout
-    sal_uInt16 nBlankSize;
+    SwTwips nBlankSize;
     if( nHoleLen == GetLen() )
         nBlankSize = Width();
     else
@@ -538,7 +538,7 @@ void SwTextPortion::FormatEOL( SwTextFormatInfo &rInf )
 
 }
 
-TextFrameIndex SwTextPortion::GetModelPositionForViewPoint(const sal_uInt16 
nOfst) const
+TextFrameIndex SwTextPortion::GetModelPositionForViewPoint(const SwTwips 
nOfst) const
 {
     OSL_ENSURE( false, "SwTextPortion::GetModelPositionForViewPoint: don't use 
this method!" );
     return SwLinePortion::GetModelPositionForViewPoint( nOfst );
@@ -742,7 +742,7 @@ void SwTextInputFieldPortion::Paint( const SwTextPaintInfo 
&rInf ) const
         // highlight empty input field, elsewhere they are completely 
invisible for the user
         SwRect aIntersect;
         rInf.CalcRect(*this, &aIntersect);
-        const sal_uInt16 aAreaWidth = rInf.GetTextSize(OUString(' ')).Width();
+        const SwTwips aAreaWidth = rInf.GetTextSize(OUString(' ')).Width();
         aIntersect.Left(aIntersect.Left() - aAreaWidth/2);
         aIntersect.Width(aAreaWidth);
 
diff --git a/sw/source/core/text/portxt.hxx b/sw/source/core/text/portxt.hxx
index c826395272e1..438764e31318 100644
--- a/sw/source/core/text/portxt.hxx
+++ b/sw/source/core/text/portxt.hxx
@@ -35,7 +35,7 @@ public:
     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
     virtual bool Format( SwTextFormatInfo &rInf ) override;
     virtual void FormatEOL( SwTextFormatInfo &rInf ) override;
-    virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) 
const override;
+    virtual TextFrameIndex GetModelPositionForViewPoint(SwTwips nOfst) const 
override;
     virtual SwPosSize GetTextSize( const SwTextSizeInfo &rInfo ) const 
override;
     virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) 
const override;
     virtual SwTwips CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo 
&rInf ) const override;
@@ -62,11 +62,11 @@ public:
 
 class SwHolePortion : public SwLinePortion
 {
-    sal_uInt16 m_nBlankWidth;
+    SwTwips m_nBlankWidth;
 public:
     explicit SwHolePortion( const SwTextPortion &rPor );
-    sal_uInt16 GetBlankWidth( ) const { return m_nBlankWidth; }
-    void SetBlankWidth( const sal_uInt16 nNew ) { m_nBlankWidth = nNew; }
+    SwTwips GetBlankWidth() const { return m_nBlankWidth; }
+    void SetBlankWidth(const SwTwips nNew) { m_nBlankWidth = nNew; }
     virtual SwLinePortion *Compress() override;
     virtual bool Format( SwTextFormatInfo &rInf ) override;
     virtual SwPosSize GetTextSize(const SwTextSizeInfo& rInfo) const override;
diff --git a/sw/source/core/text/txtdrop.cxx b/sw/source/core/text/txtdrop.cxx
index afbe3b1470eb..7e57d80c7cd5 100644
--- a/sw/source/core/text/txtdrop.cxx
+++ b/sw/source/core/text/txtdrop.cxx
@@ -46,8 +46,7 @@ using namespace ::com::sun::star;
  * The width and height of the drop caps portion are passed as arguments,
  * the position is calculated from the values in rInf
  */
-static bool lcl_IsDropFlyInter( const SwTextFormatInfo &rInf,
-                             sal_uInt16 nWidth, sal_uInt16 nHeight )
+static bool lcl_IsDropFlyInter(const SwTextFormatInfo& rInf, SwTwips nWidth, 
sal_uInt16 nHeight)
 {
     const SwTextFly& rTextFly = rInf.GetTextFly();
     if( rTextFly.IsOn() )
@@ -103,9 +102,9 @@ SwDropPortionPart::~SwDropPortionPart()
 
 /// SwDropPortion CTor, DTor
 SwDropPortion::SwDropPortion( const sal_uInt16 nLineCnt,
-                              const sal_uInt16 nDrpHeight,
-                              const sal_uInt16 nDrpDescent,
-                              const sal_uInt16 nDist )
+                              const SwTwips nDrpHeight,
+                              const SwTwips nDrpDescent,
+                              const SwTwips nDist )
   : m_nLines( nLineCnt ),
     m_nDropHeight(nDrpHeight),
     m_nDropDescent(nDrpDescent),
@@ -304,8 +303,8 @@ void SwDropPortion::PaintText( const SwTextPaintInfo &rInf 
) const
 
     const SwDropPortionPart* pCurrPart = GetPart();
     const TextFrameIndex nOldLen = GetLen();
-    const sal_uInt16 nOldWidth = Width();
-    const sal_uInt16 nOldAscent = GetAscent();
+    const SwTwips nOldWidth = Width();
+    const SwTwips nOldAscent = GetAscent();
 
     const SwTwips nBasePosY  = rInf.Y();
     const_cast<SwTextPaintInfo&>(rInf).Y( nBasePosY + m_nY );
@@ -353,9 +352,9 @@ void SwDropPortion::PaintDrop( const SwTextPaintInfo &rInf 
) const
         return;
 
     // set the lying values
-    const sal_uInt16 nOldHeight = Height();
-    const sal_uInt16 nOldWidth  = Width();
-    const sal_uInt16 nOldAscent = GetAscent();
+    const SwTwips nOldHeight = Height();
+    const SwTwips nOldWidth = Width();
+    const SwTwips nOldAscent = GetAscent();
     const SwTwips nOldPosY  = rInf.Y();
     const SwTwips nOldPosX  = rInf.X();
     const SwParaPortion *pPara = rInf.GetParaPortion();
@@ -435,7 +434,7 @@ bool SwDropPortion::FormatText( SwTextFormatInfo &rInf )
 
 SwPosSize SwDropPortion::GetTextSize( const SwTextSizeInfo &rInf ) const
 {
-    sal_uInt16 nMyX = 0;
+    SwTwips nMyX = 0;
     TextFrameIndex nIdx(0);
 
     const SwDropPortionPart* pCurrPart = GetPart();
@@ -476,7 +475,7 @@ SwPosSize SwDropPortion::GetTextSize( const SwTextSizeInfo 
&rInf ) const
     return aPosSize;
 }
 
-TextFrameIndex SwDropPortion::GetModelPositionForViewPoint(const sal_uInt16) 
const
+TextFrameIndex SwDropPortion::GetModelPositionForViewPoint(const SwTwips) const
 {
     return TextFrameIndex(0);
 }
@@ -484,7 +483,7 @@ TextFrameIndex 
SwDropPortion::GetModelPositionForViewPoint(const sal_uInt16) con
 void SwTextFormatter::CalcDropHeight( const sal_uInt16 nLines )
 {
     const SwLinePortion *const pOldCurr = GetCurr();
-    sal_uInt16 nDropHght = 0;
+    SwTwips nDropHght = 0;
     SwTwips nAscent = 0;
     SwTwips nHeight = 0;
     sal_uInt16 nDropLns = 0;
@@ -699,9 +698,9 @@ class SwDropCapCache
 {
     const void* m_aFontCacheId[ DROP_CACHE_SIZE ] = {};
     OUString m_aText[ DROP_CACHE_SIZE ];
-    sal_uInt16 m_aFactor[ DROP_CACHE_SIZE ];
-    sal_uInt16 m_aWishedHeight[ DROP_CACHE_SIZE ] = {};
-    short m_aDescent[ DROP_CACHE_SIZE ];
+    tools::Long m_aFactor[ DROP_CACHE_SIZE ];
+    SwTwips m_aWishedHeight[DROP_CACHE_SIZE] = {};
+    SwTwips m_aDescent[DROP_CACHE_SIZE];
     sal_uInt16 m_nIndex = 0;
 public:
     SwDropCapCache() = default;
@@ -752,7 +751,7 @@ void SwDropCapCache::CalcFontSize( SwDropPortion* pDrop, 
SwTextFormatInfo &rInf
         m_nIndex %= DROP_CACHE_SIZE;
         nTmpIdx = m_nIndex;
 
-        tools::Long nWishedHeight = pDrop->GetDropHeight();
+        SwTwips nWishedHeight = pDrop->GetDropHeight();
         tools::Long nAscent = 0;
 
         // find out biggest font size for initial scaling factor
@@ -774,15 +773,15 @@ void SwDropCapCache::CalcFontSize( SwDropPortion* pDrop, 
SwTextFormatInfo &rInf
             // save keys for cache
             m_aFontCacheId[ nTmpIdx ] = nFntCacheId;
             m_aText[ nTmpIdx ] = aStr;
-            m_aWishedHeight[ nTmpIdx ] = sal_uInt16(nWishedHeight);
+            m_aWishedHeight[ nTmpIdx ] = nWishedHeight;
             // save initial scaling factor
-            m_aFactor[ nTmpIdx ] = o3tl::narrowing<sal_uInt16>(nFactor);
+            m_aFactor[ nTmpIdx ] = nFactor;
         }
 
         bool bGrow = (pDrop->GetLen() != TextFrameIndex(0));
 
         // for growing control
-        tools::Long nMax = USHRT_MAX;
+        tools::Long nMax = std::numeric_limits<tools::Long>::max();
         tools::Long nMin = 0;
 #if OSL_DEBUG_LEVEL > 1
         tools::Long nGrow = 0;
@@ -939,7 +938,7 @@ void SwDropCapCache::CalcFontSize( SwDropPortion* pDrop, 
SwTextFormatInfo &rInf
                 else
                 {
                     if ( bUseCache )
-                        m_aFactor[ nTmpIdx ] = 
o3tl::narrowing<sal_uInt16>(nFactor);
+                        m_aFactor[ nTmpIdx ] = nFactor;
                     nMin = nFactor;
                 }
 
@@ -996,7 +995,7 @@ void SwDropCapCache::CalcFontSize( SwDropPortion* pDrop, 
SwTextFormatInfo &rInf
 bool SwDropPortion::Format( SwTextFormatInfo &rInf )
 {
     bool bFull = false;
-    m_nFix = o3tl::narrowing<sal_uInt16>(rInf.X());
+    m_nFix = rInf.X();
 
     SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
     aLayoutModeModifier.SetAuto();
@@ -1009,7 +1008,7 @@ bool SwDropPortion::Format( SwTextFormatInfo &rInf )
         // adjust font sizes to fit into the rectangle
         pDropCapCache->CalcFontSize( this, rInf );
 
-        const tools::Long nOldX = rInf.X();
+        const SwTwips nOldX = rInf.X();
         {
             SwDropSave aSave( rInf );
             SwDropPortionPart* pCurrPart = m_pPart.get();
@@ -1034,7 +1033,7 @@ bool SwDropPortion::Format( SwTextFormatInfo &rInf )
                         Width();
 
                 // set values
-                pCurrPart->SetWidth( o3tl::narrowing<sal_uInt16>(nTmpWidth) );
+                pCurrPart->SetWidth(nTmpWidth);
 
                 // Move
                 rInf.SetIdx( rInf.GetIdx() + pCurrPart->GetLen() );
@@ -1043,7 +1042,7 @@ bool SwDropPortion::Format( SwTextFormatInfo &rInf )
             }
             SetJoinBorderWithNext(false);
             SetJoinBorderWithPrev(false);
-            Width( o3tl::narrowing<sal_uInt16>(rInf.X() - nOldX) );
+            Width(rInf.X() - nOldX);
         }
 
         // reset my length
@@ -1079,10 +1078,10 @@ bool SwDropPortion::Format( SwTextFormatInfo &rInf )
         m_nDistance = 0;
     else
     {
-        const sal_uInt16 nWant = Width() + GetDistance();
-        const sal_uInt16 nRest = o3tl::narrowing<sal_uInt16>(rInf.Width() - 
rInf.X());
+        const SwTwips nWant = Width() + GetDistance();
+        const SwTwips nRest = rInf.Width() - rInf.X();
         if( ( nWant > nRest ) ||
-            lcl_IsDropFlyInter( rInf, Width() + GetDistance(), m_nDropHeight ) 
)
+            lcl_IsDropFlyInter( rInf, nWant, m_nDropHeight ) )
             m_nDistance = 0;
 
         Width( Width() + m_nDistance );
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index 179099eda623..a6c1423909f2 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -3878,24 +3878,24 @@ tools::Long SwTextFrame::GetLineSpace( const bool 
_bNoPropLineSpace ) const
     return nRet;
 }
 
-sal_uInt16 SwTextFrame::FirstLineHeight() const
+SwTwips SwTextFrame::FirstLineHeight() const
 {
     if ( !HasPara() )
     {
         if( IsEmpty() && isFrameAreaDefinitionValid() )
-            return IsVertical() ? 
o3tl::narrowing<sal_uInt16>(getFramePrintArea().Width()) : 
o3tl::narrowing<sal_uInt16>(getFramePrintArea().Height());
-        return USHRT_MAX;
+            return IsVertical() ? getFramePrintArea().Width() : 
getFramePrintArea().Height();
+        return std::numeric_limits<SwTwips>::max();
     }
     const SwParaPortion *pPara = GetPara();
     if ( !pPara )
-        return USHRT_MAX;
+        return std::numeric_limits<SwTwips>::max();
 
     // tdf#146500 Lines with only fly overlap cannot be "moved", so the idea
     // here is to continue until there's some text.
     // FIXME ideally we want to count a fly to the line in which it is anchored
     // - it may even be anchored in some other paragraph! SwFlyPortion doesn't
     // have a pointer sadly so no way to find out.
-    sal_uInt16 nHeight(0);
+    SwTwips nHeight(0);
     for (SwLineLayout const* pLine = pPara; pLine; pLine = pLine->GetNext())
     {
         nHeight += pLine->Height();
diff --git a/sw/source/core/text/txtftn.cxx b/sw/source/core/text/txtftn.cxx
index bb21b6ab0f29..da51233ac190 100644
--- a/sw/source/core/text/txtftn.cxx
+++ b/sw/source/core/text/txtftn.cxx
@@ -803,11 +803,11 @@ SwFootnotePortion *SwTextFormatter::NewFootnotePortion( 
SwTextFormatInfo &rInf,
 
     SwSwapIfSwapped swap(m_pFrame);
 
-    sal_uInt16 nReal;
+    SwTwips nReal;
     {
-        sal_uInt16 nOldReal = m_pCurr->GetRealHeight();
-        sal_uInt16 nOldAscent = m_pCurr->GetAscent();
-        sal_uInt16 nOldHeight = m_pCurr->Height();
+        SwTwips nOldReal = m_pCurr->GetRealHeight();
+        SwTwips nOldAscent = m_pCurr->GetAscent();
+        SwTwips nOldHeight = m_pCurr->Height();
         CalcRealHeight();
         nReal = m_pCurr->GetRealHeight();
         if( nReal < nOldReal )
@@ -1114,7 +1114,7 @@ TextFrameIndex 
SwTextFormatter::FormatQuoVadis(TextFrameIndex const nOffset)
     // position we want to insert the Quovadis text
     // Let's see if it is that bad indeed:
     SwLinePortion *pPor = m_pCurr->GetFirstPortion();
-    sal_uInt16 nLastLeft = 0;
+    SwTwips nLastLeft = 0;
     while( pPor )
     {
         if ( pPor->IsFlyPortion() )
@@ -1126,7 +1126,7 @@ TextFrameIndex 
SwTextFormatter::FormatQuoVadis(TextFrameIndex const nOffset)
     // The old game all over again: we want the Line to wrap around
     // at a certain point, so we adjust the width.
     // nLastLeft is now basically the right margin
-    const sal_uInt16 nOldRealWidth = rInf.RealWidth();
+    const SwTwips nOldRealWidth = rInf.RealWidth();
     rInf.RealWidth( nOldRealWidth - nLastLeft );
 
     OUString aErgo = lcl_GetPageNumber( pErgoFrame->FindPageFrame() );
@@ -1134,7 +1134,7 @@ TextFrameIndex 
SwTextFormatter::FormatQuoVadis(TextFrameIndex const nOffset)
     pQuo->SetAscent( rInf.GetAscent()  );
     pQuo->Height( rInf.GetTextHeight() );
     pQuo->Format( rInf );
-    sal_uInt16 nQuoWidth = pQuo->Width();
+    SwTwips nQuoWidth = pQuo->Width();
     SwLinePortion* pCurrPor = pQuo;
 
     while ( rInf.GetRest() )
@@ -1212,12 +1212,12 @@ TextFrameIndex 
SwTextFormatter::FormatQuoVadis(TextFrameIndex const nOffset)
                     if( nDiff < 0 )
                     {
                         nLastLeft = pQuo->GetAscent();
-                        nQuoWidth = o3tl::narrowing<sal_uInt16>(-nDiff + 
nLastLeft);
+                        nQuoWidth = -nDiff + nLastLeft;
                     }
                     else
                     {
                         nQuoWidth = 0;
-                        nLastLeft = sal_uInt16(( pQuo->GetAscent() + nDiff ) / 
2);
+                        nLastLeft = (pQuo->GetAscent() + nDiff) / 2;
                     }
                     break;
                 }
@@ -1268,7 +1268,7 @@ TextFrameIndex 
SwTextFormatter::FormatQuoVadis(TextFrameIndex const nOffset)
  */
 void SwTextFormatter::MakeDummyLine()
 {
-    sal_uInt16 nRstHeight = GetFrameRstHeight();
+    SwTwips nRstHeight = GetFrameRstHeight();
     if( m_pCurr && nRstHeight > m_pCurr->Height() )
     {
         SwLineLayout *pLay = new SwLineLayout;
@@ -1369,8 +1369,7 @@ SwFootnoteSave::~SwFootnoteSave() COVERITY_NOEXCEPT_FALSE
     }
 }
 
-SwFootnotePortion::SwFootnotePortion( const OUString &rExpand,
-                            SwTextFootnote *pFootn, sal_uInt16 nReal )
+SwFootnotePortion::SwFootnotePortion(const OUString& rExpand, SwTextFootnote* 
pFootn, SwTwips nReal)
         : SwFieldPortion( rExpand, nullptr )
         , m_pFootnote(pFootn)
         , m_nOrigHeight( nReal )
@@ -1458,7 +1457,7 @@ bool SwQuoVadisPortion::Format( SwTextFormatInfo &rInf )
         SetLen(TextFrameIndex(0));
         if( bFull  )
             // Third try; we're done: we crush
-            Width( sal_uInt16(rInf.Width() - rInf.X()) );
+            Width(rInf.Width() - rInf.X());
 
         // No multiline Fields for QuoVadis and ErgoSum
         if( rInf.GetRest() )
@@ -1514,7 +1513,7 @@ SwErgoSumPortion::SwErgoSumPortion(const OUString &rExp, 
std::u16string_view rSt
     SetWhichPor( PortionType::ErgoSum );
 }
 
-TextFrameIndex SwErgoSumPortion::GetModelPositionForViewPoint(const 
sal_uInt16) const
+TextFrameIndex SwErgoSumPortion::GetModelPositionForViewPoint(const SwTwips) 
const
 {
     return TextFrameIndex(0);
 }
diff --git a/sw/source/core/text/txthyph.cxx b/sw/source/core/text/txthyph.cxx
index 98bfc9480c01..f1dd3acc5b75 100644
--- a/sw/source/core/text/txthyph.cxx
+++ b/sw/source/core/text/txthyph.cxx
@@ -298,7 +298,7 @@ bool SwTextPortion::CreateHyphen( SwTextFormatInfo &rInf, 
SwTextGuess const &rGu
         pHyphPor->SetLen(TextFrameIndex(1));
 
         static const void* nLastFontCacheId = nullptr;
-        static sal_uInt16 aMiniCacheH = 0, aMiniCacheW = 0;
+        static SwTwips aMiniCacheH = 0, aMiniCacheW = 0;
         const void* nTmpFontCacheId;
         sal_uInt16 nFntIdx;
         rInf.GetFont()->GetFontCacheId( nTmpFontCacheId, nFntIdx, 
rInf.GetFont()->GetActual() );
@@ -404,7 +404,7 @@ SwSoftHyphPortion::SwSoftHyphPortion() :
     SetWhichPor( PortionType::SoftHyphen );
 }
 
-sal_uInt16 SwSoftHyphPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
+SwTwips SwSoftHyphPortion::GetViewWidth(const SwTextSizeInfo& rInf) const
 {
     // Although we're in the const, nViewWidth should be calculated at
     // the last possible moment
diff --git a/sw/source/core/text/txttab.cxx b/sw/source/core/text/txttab.cxx
index e19dd8efe9b4..2c5dbdb1a6db 100644
--- a/sw/source/core/text/txttab.cxx
+++ b/sw/source/core/text/txttab.cxx
@@ -82,7 +82,7 @@ SwTabPortion *SwTextFormatter::NewTabPortion( 
SwTextFormatInfo &rInf, bool bAuto
     sal_Unicode cDec = 0;
     SvxTabAdjust eAdj;
 
-    sal_uInt16 nNewTabPos;
+    SwTwips nNewTabPos;
     bool bAutoTabStop = true;
     {
         const bool bRTL = m_pFrame->IsRightToLeft();
@@ -180,13 +180,13 @@ SwTabPortion *SwTextFormatter::NewTabPortion( 
SwTextFormatInfo &rInf, bool bAuto
         }
         else
         {
-            sal_uInt16 nDefTabDist = m_aLineInf.GetDefTabStop();
-            if( USHRT_MAX == nDefTabDist )
+            SwTwips nDefTabDist = m_aLineInf.GetDefTabStop();
+            if (std::numeric_limits<SwTwips>::max() == nDefTabDist)
             {
                 const SvxTabStopItem& rTab =
                     
m_pFrame->GetAttrSet()->GetPool()->GetUserOrPoolDefaultItem( RES_PARATR_TABSTOP 
);
                 if( rTab.Count() )
-                    nDefTabDist = 
o3tl::narrowing<sal_uInt16>(rTab[0].GetTabPos());
+                    nDefTabDist = rTab[0].GetTabPos();
                 else
                     nDefTabDist = SVX_TAB_DEFDIST;
                 m_aLineInf.SetDefTabStop( nDefTabDist );
@@ -282,7 +282,7 @@ SwTabPortion *SwTextFormatter::NewTabPortion( 
SwTextFormatInfo &rInf, bool bAuto
         if (!bAbsoluteNextPos)
             nNextPos += bRTL ? nLinePos - nTabLeft : nTabLeft - nLinePos;
         OSL_ENSURE( nNextPos >= 0, "GetTabStop: Don't go back!" );
-        nNewTabPos = sal_uInt16(nNextPos);
+        nNewTabPos = nNextPos;
     }
 
     SwTabPortion *pTabPor = nullptr;
@@ -329,7 +329,7 @@ SwTabPortion *SwTextFormatter::NewTabPortion( 
SwTextFormatInfo &rInf, bool bAuto
 /**
  * The base class is initialized without setting anything
  */
-SwTabPortion::SwTabPortion( const sal_uInt16 nTabPosition, const sal_Unicode 
cFillChar, const bool bAutoTab )
+SwTabPortion::SwTabPortion( const SwTwips nTabPosition, const sal_Unicode 
cFillChar, const bool bAutoTab )
     : m_nTabPos(nTabPosition), m_cFill(cFillChar), m_bAutoTabStop( bAutoTab )
 {
     mnLineLength = TextFrameIndex(1);
@@ -358,19 +358,19 @@ bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf )
     OSL_ENSURE( rInf.X() <= GetTabPos(), "SwTabPortion::PreFormat: rush hour" 
);
 
     // Here we settle down ...
-    SetFix( o3tl::narrowing<sal_uInt16>(rInf.X()) );
+    SetFix(rInf.X());
 
     IDocumentSettingAccess const& 
rIDSA(rInf.GetTextFrame()->GetDoc().getIDocumentSettingAccess());
     const bool bTabCompat = rIDSA.get(DocumentSettingId::TAB_COMPAT);
     const bool bTabOverflow = rIDSA.get(DocumentSettingId::TAB_OVERFLOW);
     const bool bTabOverMargin = rIDSA.get(DocumentSettingId::TAB_OVER_MARGIN);
     const bool bTabOverSpacing = 
rIDSA.get(DocumentSettingId::TAB_OVER_SPACING);
-    const sal_Int32 nTextFrameWidth = 
rInf.GetTextFrame()->getFrameArea().Width();
+    const tools::Long nTextFrameWidth = 
rInf.GetTextFrame()->getFrameArea().Width();
 
     // The minimal width of a tab is one blank at least.
     // #i37686# In compatibility mode, the minimum width
     // should be 1, even for non-left tab stops.
-    sal_uInt16 nMinimumTabWidth = 1;
+    SwTwips nMinimumTabWidth = 1;
     if ( !bTabCompat )
     {
         // #i89179#
@@ -434,7 +434,7 @@ bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf )
                     }
                 }
 
-                PrtWidth( o3tl::narrowing<sal_uInt16>(GetTabPos() - rInf.X()) 
);
+                PrtWidth(GetTabPos() - rInf.X());
                 bFull = rInf.Width() <= rInf.X() + PrtWidth();
 
                 // In tabulator compatibility mode, we reset the bFull flag
@@ -464,7 +464,7 @@ bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf )
             // line if there is a fly reducing the line width:
             !rInf.GetFly() )
         {
-            PrtWidth( o3tl::narrowing<sal_uInt16>(rInf.Width() - rInf.X()) );
+            PrtWidth(rInf.Width() - rInf.X());
             SetFixWidth( PrtWidth() );
         }
         else
@@ -497,15 +497,15 @@ bool SwTabPortion::PostFormat( SwTextFormatInfo &rInf )
 
     // If the tab position is larger than the right margin, it gets scaled 
down by default.
     // However, if compat mode enabled, we allow tabs to go over the margin: 
the rest of the paragraph is not broken into lines.
-    const sal_uInt16 nRight
+    const SwTwips nRight
         = bTabOverMargin
               ? GetTabPos()
               : bTabOverSpacing
-                    ? std::min<long>(GetTabPos(), 
rInf.GetTextFrame()->getFrameArea().Right())
+                    ? std::min(GetTabPos(), 
rInf.GetTextFrame()->getFrameArea().Right())
                     : std::min(GetTabPos(), rInf.Width());
     const SwLinePortion *pPor = GetNextPortion();
 
-    sal_uInt16 nPorWidth = 0;
+    SwTwips nPorWidth = 0;
     while( pPor )
     {
         nPorWidth = nPorWidth + pPor->Width();
@@ -523,10 +523,10 @@ bool SwTabPortion::PostFormat( SwTextFormatInfo &rInf )
     // #127428# Abandon dec. tab position if line is full
-e 
... etc. - the rest is truncated

Reply via email to