sw/source/filter/html/css1atr.cxx        |   17 ++------
 sw/source/filter/html/htmlatr.cxx        |   25 ++++++------
 sw/source/filter/html/htmldrawreader.cxx |   15 ++-----
 sw/source/filter/html/htmldrawwriter.cxx |    6 --
 sw/source/filter/html/htmlflywriter.cxx  |   64 +++----------------------------
 sw/source/filter/html/htmlform.cxx       |   44 ++++-----------------
 sw/source/filter/html/htmlforw.cxx       |   14 ------
 sw/source/filter/html/htmlgrin.cxx       |   15 +++----
 sw/source/filter/html/htmlnumreader.cxx  |    4 -
 sw/source/filter/html/htmlplug.cxx       |   19 ++-------
 sw/source/filter/html/htmlsect.cxx       |   12 +----
 sw/source/filter/html/htmltab.cxx        |   14 +-----
 sw/source/filter/html/htmltabw.cxx       |   60 ++++++-----------------------
 sw/source/filter/html/svxcss1.cxx        |   11 -----
 sw/source/filter/html/swhtml.cxx         |   24 +----------
 sw/source/filter/html/wrthtml.cxx        |    6 --
 sw/source/filter/html/wrthtml.hxx        |    5 +-
 17 files changed, 90 insertions(+), 265 deletions(-)

New commits:
commit 6d5848ec01d615e89d9c62e18a29fcb0a9febcca
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Aug 5 06:59:26 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Aug 5 13:34:15 2023 +0200

    Define px as 1/96 in in HTML filter
    
    Ref: https://www.w3.org/TR/css3-values/#absolute-lengths
    
    Change-Id: Idf1def9497b35f67ef1554220d1abbe640840f22
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155366
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/source/filter/html/css1atr.cxx 
b/sw/source/filter/html/css1atr.cxx
index 3af5f38498e4..a922be479841 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -466,10 +466,9 @@ void SwHTMLWriter::OutCSS1_UnitProperty( std::string_view 
pProp, tools::Long nVa
     OutCSS1_PropertyAscii(pProp, sOut);
 }
 
-void SwHTMLWriter::OutCSS1_PixelProperty( std::string_view pProp, tools::Long 
nVal,
-                                          bool bVert )
+void SwHTMLWriter::OutCSS1_PixelProperty( std::string_view pProp, tools::Long 
nTwips )
 {
-    OString sOut(OString::number(ToPixel(nVal,bVert)) + sCSS1_UNIT_px);
+    OString sOut(OString::number(ToPixel(nTwips)) + sCSS1_UNIT_px);
     OutCSS1_PropertyAscii(pProp, sOut);
 }
 
@@ -1965,16 +1964,14 @@ void SwHTMLWriter::OutCSS1_FrameFormatOptions( const 
SwFrameFormat& rFrameFormat
                 if( nFrameOpts & HtmlFrmOpts::SWidth )
                 {
                     if( nFrameOpts & HtmlFrmOpts::SPixSize )
-                        OutCSS1_PixelProperty( sCSS1_P_width, aTwipSz.Width(),
-                                               false );
+                        OutCSS1_PixelProperty( sCSS1_P_width, aTwipSz.Width() 
);
                     else
                         OutCSS1_UnitProperty( sCSS1_P_width, aTwipSz.Width() );
                 }
                 if( nFrameOpts & HtmlFrmOpts::SHeight )
                 {
                     if( nFrameOpts & HtmlFrmOpts::SPixSize )
-                        OutCSS1_PixelProperty( sCSS1_P_height, 
aTwipSz.Height(),
-                                               true );
+                        OutCSS1_PixelProperty( sCSS1_P_height, 
aTwipSz.Height() );
                     else
                         OutCSS1_UnitProperty( sCSS1_P_height, aTwipSz.Height() 
);
                 }
@@ -2780,7 +2777,7 @@ static SwHTMLWriter& OutCSS1_SwFormatFrameSize( 
SwHTMLWriter& rWrt, const SfxPoo
         else if( nMode & Css1FrameSize::Pixel )
         {
             rWrt.OutCSS1_PixelProperty( sCSS1_P_width,
-                                            rFSItem.GetSize().Width(), false );
+                                            rFSItem.GetSize().Width() );
         }
         else
         {
@@ -3235,9 +3232,7 @@ static void OutCSS1_SvxBorderLine( SwHTMLWriter& rWrt,
     sal_Int32 nWidth = pLine->GetWidth();
 
     OStringBuffer sOut;
-    if( Application::GetDefaultDevice() &&
-        nWidth <= Application::GetDefaultDevice()->PixelToLogic(
-                    Size( 1, 1 ), MapMode( MapUnit::MapTwip) ).Width() )
+    if( nWidth <= o3tl::convert(1, o3tl::Length::px, o3tl::Length::twip) )
     {
         // If the width is smaller than one pixel, then export as 1px
         // so that Netscape and IE show the line.
diff --git a/sw/source/filter/html/htmlatr.cxx 
b/sw/source/filter/html/htmlatr.cxx
index 167da9d7115f..d38f759acb84 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -2074,7 +2074,7 @@ SwHTMLWriter& OutHTML_SwTextNode( SwHTMLWriter& rWrt, 
const SwContentNode& rNode
                         nPageWidth = 
pBox->GetFrameFormat()->GetFrameSize().GetWidth();
                 }
 
-                OString sWidth = 
OString::number(SwHTMLWriter::ToPixel(nPageWidth - nLeft - nRight, false));
+                OString sWidth = 
OString::number(SwHTMLWriter::ToPixel(nPageWidth - nLeft - nRight));
                 aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_width, sWidth);
 
                 if( !nLeft )
@@ -2092,7 +2092,7 @@ SwHTMLWriter& OutHTML_SwTextNode( SwHTMLWriter& rWrt, 
const SwContentNode& rNode
             if( pBorderLine )
             {
                 sal_uInt16 nWidth = pBorderLine->GetScaledWidth();
-                OString sWidth = OString::number(SwHTMLWriter::ToPixel(nWidth, 
false));
+                OString sWidth = 
OString::number(SwHTMLWriter::ToPixel(nWidth));
                 aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_size, sWidth);
 
                 const Color& rBorderColor = pBorderLine->GetColor();
@@ -2625,17 +2625,18 @@ SwHTMLWriter& OutHTML_SwTextNode( SwHTMLWriter& rWrt, 
const SwContentNode& rNode
     return rWrt;
 }
 
-sal_uInt32 SwHTMLWriter::ToPixel( sal_uInt32 nVal, const bool bVert )
+// In CSS, "px" is 1/96 of inch: 
https://www.w3.org/TR/css3-values/#absolute-lengths
+sal_uInt32 SwHTMLWriter::ToPixel(sal_uInt32 nTwips)
 {
-    if( Application::GetDefaultDevice() && nVal )
-    {
-        Size aSz( bVert ? 0 : nVal, bVert ? nVal : 0 );
-        aSz = Application::GetDefaultDevice()->LogicToPixel(aSz, MapMode( 
MapUnit::MapTwip ));
-        nVal = bVert ? aSz.Height() : aSz.Width();
-        if( !nVal )     // if there is a Twip, there should be a pixel as well
-            nVal = 1;
-    }
-    return nVal;
+    // if there is a Twip, there should be a pixel as well
+    return nTwips
+               ? std::max(o3tl::convert(nTwips, o3tl::Length::twip, 
o3tl::Length::px), sal_Int64(1))
+               : 0;
+}
+
+Size SwHTMLWriter::ToPixel(Size aTwips)
+{
+    return Size(ToPixel(aTwips.Width()), ToPixel(aTwips.Height()));
 }
 
 static SwHTMLWriter& OutHTML_CSS1Attr( SwHTMLWriter& rWrt, const SfxPoolItem& 
rHt )
diff --git a/sw/source/filter/html/htmldrawreader.cxx 
b/sw/source/filter/html/htmldrawreader.cxx
index 809aa5bec0c3..4e5cb320408a 100644
--- a/sw/source/filter/html/htmldrawreader.cxx
+++ b/sw/source/filter/html/htmldrawreader.cxx
@@ -87,14 +87,10 @@ void SwHTMLParser::InsertDrawObject( SdrObject* pNewDrawObj,
         Reader::ResetFrameFormatAttrs( aFrameSet );
 
     sal_uInt16 nLeftSpace = 0, nRightSpace = 0, nUpperSpace = 0, nLowerSpace = 
0;
-    if( (rPixSpace.Width() || rPixSpace.Height()) && 
Application::GetDefaultDevice() )
+    if( rPixSpace.Width() || rPixSpace.Height() )
     {
-        Size aTwipSpc( rPixSpace.Width(), rPixSpace.Height() );
-        aTwipSpc =
-            Application::GetDefaultDevice()->PixelToLogic( aTwipSpc,
-                                                MapMode(MapUnit::MapTwip) );
-        nLeftSpace = nRightSpace = 
o3tl::narrowing<sal_uInt16>(aTwipSpc.Width());
-        nUpperSpace = nLowerSpace = 
o3tl::narrowing<sal_uInt16>(aTwipSpc.Height());
+        nLeftSpace = nRightSpace = o3tl::convert(rPixSpace.Width(), 
o3tl::Length::px, o3tl::Length::twip);
+        nUpperSpace = nLowerSpace = o3tl::convert(rPixSpace.Height(), 
o3tl::Length::px, o3tl::Length::twip);
     }
 
     // set left/right border
@@ -454,10 +450,9 @@ void SwHTMLParser::NewMarquee( HTMLTable *pCurTable )
 
     // now set the size
     Size aTwipSz( bPercentWidth ? 0 : nWidth, nHeight );
-    if( (aTwipSz.Width() || aTwipSz.Height()) && 
Application::GetDefaultDevice() )
+    if( aTwipSz.Width() || aTwipSz.Height() )
     {
-        aTwipSz = Application::GetDefaultDevice()
-                    ->PixelToLogic( aTwipSz, MapMode( MapUnit::MapTwip ) );
+        aTwipSz = o3tl::convert(aTwipSz, o3tl::Length::px, o3tl::Length::twip);
     }
 
     if( SVX_CSS1_LTYPE_TWIP== aPropInfo.m_eWidthType )
diff --git a/sw/source/filter/html/htmldrawwriter.cxx 
b/sw/source/filter/html/htmldrawwriter.cxx
index 14ea4ad28d73..cf37c1948b90 100644
--- a/sw/source/filter/html/htmldrawwriter.cxx
+++ b/sw/source/filter/html/htmldrawwriter.cxx
@@ -187,11 +187,9 @@ SwHTMLWriter& OutHTML_DrawFrameFormatAsMarquee( 
SwHTMLWriter& rWrt,
     {
         nAmount = -nAmount;
     }
-    else if( nAmount && Application::GetDefaultDevice() )
+    else
     {
-        nAmount = Application::GetDefaultDevice()
-                            ->LogicToPixel( Size(nAmount,0),
-                                            MapMode(MapUnit::MapTwip) 
).Width();
+        nAmount = SwHTMLWriter::ToPixel(nAmount);
     }
     if( nAmount )
     {
diff --git a/sw/source/filter/html/htmlflywriter.cxx 
b/sw/source/filter/html/htmlflywriter.cxx
index 6aafdeaa0f2f..ed25c65d162e 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -610,16 +610,9 @@ OString SwHTMLWriter::OutFrameFormatOptions( const 
SwFrameFormat &rFrameFormat,
 
     if( (nFrameOpts & HtmlFrmOpts::Space) &&
         (aTwipSpc.Width() || aTwipSpc.Height()) &&
-        Application::GetDefaultDevice() &&
         !mbReqIF )
     {
-        Size aPixelSpc =
-            Application::GetDefaultDevice()->LogicToPixel( aTwipSpc,
-                                                MapMode(MapUnit::MapTwip) );
-        if( !aPixelSpc.Width() && aTwipSpc.Width() )
-            aPixelSpc.setWidth( 1 );
-        if( !aPixelSpc.Height() && aTwipSpc.Height() )
-            aPixelSpc.setHeight( 1 );
+        Size aPixelSpc = SwHTMLWriter::ToPixel(aTwipSpc);
 
         if( aPixelSpc.Width() )
         {
@@ -680,18 +673,7 @@ OString SwHTMLWriter::OutFrameFormatOptions( const 
SwFrameFormat &rFrameFormat,
         if( aTwipSz.Height() < 0 )
             aTwipSz.setHeight( 0 );
 
-        Size aPixelSz( 0, 0 );
-        if( (aTwipSz.Width() || aTwipSz.Height()) &&
-            Application::GetDefaultDevice() )
-        {
-            aPixelSz =
-                Application::GetDefaultDevice()->LogicToPixel( aTwipSz,
-                                                    MapMode(MapUnit::MapTwip) 
);
-            if( !aPixelSz.Width() && aTwipSz.Width() )
-                aPixelSz.setWidth( 1 );
-            if( !aPixelSz.Height() && aTwipSz.Height() )
-                aPixelSz.setHeight( 1 );
-        }
+        Size aPixelSz(SwHTMLWriter::ToPixel(aTwipSz));
 
         if( (nFrameOpts & HtmlFrmOpts::Width) &&
             ((nPercentWidth && nPercentWidth!=255) || aPixelSz.Width()) )
@@ -878,16 +860,9 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& 
aHtml, const SwFrameForma
 
     if( (nFrameOptions & HtmlFrmOpts::Space) &&
         (aTwipSpc.Width() || aTwipSpc.Height()) &&
-        Application::GetDefaultDevice() &&
         !mbReqIF )
     {
-        Size aPixelSpc =
-            Application::GetDefaultDevice()->LogicToPixel( aTwipSpc,
-                                                MapMode(MapUnit::MapTwip) );
-        if( !aPixelSpc.Width() && aTwipSpc.Width() )
-            aPixelSpc.setWidth( 1 );
-        if( !aPixelSpc.Height() && aTwipSpc.Height() )
-            aPixelSpc.setHeight( 1 );
+        Size aPixelSpc = SwHTMLWriter::ToPixel(aTwipSpc);
 
         if (aPixelSpc.Width())
         {
@@ -959,18 +934,7 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& 
aHtml, const SwFrameForma
         if( aTwipSz.Height() < 0 )
             aTwipSz.setHeight( 0 );
 
-        Size aPixelSz( 0, 0 );
-        if( (aTwipSz.Width() || aTwipSz.Height()) &&
-            Application::GetDefaultDevice() )
-        {
-            aPixelSz =
-                Application::GetDefaultDevice()->LogicToPixel( aTwipSz,
-                                                    MapMode(MapUnit::MapTwip) 
);
-            if( !aPixelSz.Width() && aTwipSz.Width() )
-                aPixelSz.setWidth( 1 );
-            if( !aPixelSz.Height() && aTwipSz.Height() )
-                aPixelSz.setHeight( 1 );
-        }
+        Size aPixelSz(SwHTMLWriter::ToPixel(aTwipSz));
 
         if( (nFrameOptions & HtmlFrmOpts::Width) &&
             ((nPercentWidth && nPercentWidth!=255) || aPixelSz.Width()) )
@@ -1389,13 +1353,7 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, 
SwHTMLWriter& rWrt, const S
         if( (aTwipBorder.Width() || aTwipBorder.Height()) &&
             Application::GetDefaultDevice() )
         {
-            Size aPixelBorder =
-                Application::GetDefaultDevice()->LogicToPixel( aTwipBorder,
-                                                    MapMode(MapUnit::MapTwip) 
);
-            if( !aPixelBorder.Width() && aTwipBorder.Width() )
-                aPixelBorder.setWidth( 1 );
-            if( !aPixelBorder.Height() && aTwipBorder.Height() )
-                aPixelBorder.setHeight( 1 );
+            Size aPixelBorder = SwHTMLWriter::ToPixel(aTwipBorder);
 
             if( aPixelBorder.Width() )
                 aPixelBorder.setHeight( 0 );
@@ -1655,12 +1613,7 @@ static SwHTMLWriter & OutHTML_FrameFormatAsMulticol( 
SwHTMLWriter& rWrt,
     sal_uInt16 nGutter = rFormatCol.GetGutterWidth( true );
     if( nGutter!=USHRT_MAX )
     {
-        if( nGutter && Application::GetDefaultDevice() )
-        {
-            nGutter = 
o3tl::narrowing<sal_uInt16>(Application::GetDefaultDevice()
-                            ->LogicToPixel( Size(nGutter,0),
-                                            MapMode(MapUnit::MapTwip) 
).Width());
-        }
+        nGutter = SwHTMLWriter::ToPixel(nGutter);
         sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_gutter
                 "=\"" + OString::number(nGutter) + "\"");
     }
@@ -2121,11 +2074,10 @@ SwHTMLWriter& OutHTML_HeaderFooter( SwHTMLWriter& rWrt, 
const SwFrameFormat& rFr
 
     OString aSpacer;
     if( rWrt.IsHTMLMode(HTMLMODE_VERT_SPACER) &&
-        nSize > HTML_PARSPACE && Application::GetDefaultDevice() )
+        nSize > HTML_PARSPACE )
     {
         nSize -= HTML_PARSPACE;
-        nSize = static_cast<sal_Int16>(Application::GetDefaultDevice()
-            ->LogicToPixel( Size(nSize,0), MapMode(MapUnit::MapTwip) 
).Width());
+        nSize = SwHTMLWriter::ToPixel(nSize);
 
         aSpacer = OOO_STRING_SVTOOLS_HTML_spacer
                 " " OOO_STRING_SVTOOLS_HTML_O_type
diff --git a/sw/source/filter/html/htmlform.cxx 
b/sw/source/filter/html/htmlform.cxx
index f5685a4dbf63..d37abddc68d1 100644
--- a/sw/source/filter/html/htmlform.cxx
+++ b/sw/source/filter/html/htmlform.cxx
@@ -467,16 +467,8 @@ void SwHTMLImageWatcher::init( sal_Int32 Width, sal_Int32 
Height )
         return;
 
     awt::Size aNewSz;
-    aNewSz.Width = Width;
-    aNewSz.Height = Height;
-    if( Application::GetDefaultDevice() )
-    {
-        Size aTmp(aNewSz.Width, aNewSz.Height);
-        aTmp = Application::GetDefaultDevice()
-                    ->PixelToLogic( aTmp, MapMode( MapUnit::Map100thMM ) );
-        aNewSz.Width = aTmp.Width();
-        aNewSz.Height = aTmp.Height();
-    }
+    aNewSz.Width = o3tl::convert(Width, o3tl::Length::px, o3tl::Length::mm100);
+    aNewSz.Height = o3tl::convert(Height, o3tl::Length::px, 
o3tl::Length::mm100);
 
     if( !m_bSetWidth || !m_bSetHeight )
     {
@@ -711,14 +703,8 @@ void SwHTMLParser::SetControlSize( const uno::Reference< 
drawing::XShape >& rSha
         }
     }
 
-    if( Application::GetDefaultDevice() )
-    {
-        Size aTmpSz( aNewSz.Width, aNewSz.Height );
-        aTmpSz = Application::GetDefaultDevice()
-                        ->PixelToLogic( aTmpSz, MapMode( MapUnit::Map100thMM ) 
);
-        aNewSz.Width  = aTmpSz.Width();
-        aNewSz.Height = aTmpSz.Height();
-    }
+    aNewSz.Width = o3tl::convert(aNewSz.Width, o3tl::Length::px, 
o3tl::Length::mm100);
+    aNewSz.Height = o3tl::convert(aNewSz.Height, o3tl::Length::px, 
o3tl::Length::mm100);
     if( aNewSz.Width )
     {
         if( aNewSz.Width < MINLAY )
@@ -1666,14 +1652,8 @@ void SwHTMLParser::InsertInput()
     case HTMLInputType::Image:
         {
             // SIZE = WIDTH
-            aSz.setWidth( nSize ? nSize : nWidth );
-            aSz.setWidth( nWidth );
-            aSz.setHeight( nHeight );
-            if( (aSz.Width() || aSz.Height()) && 
Application::GetDefaultDevice() )
-            {
-                aSz = Application::GetDefaultDevice()
-                    ->PixelToLogic( aSz, MapMode( MapUnit::Map100thMM ) );
-            }
+            aSz.setWidth(o3tl::convert(nWidth, o3tl::Length::px, 
o3tl::Length::mm100));
+            aSz.setHeight(o3tl::convert(nHeight, o3tl::Length::px, 
o3tl::Length::mm100));
             aTmp <<= FormButtonType_SUBMIT;
             xPropSet->setPropertyValue("ButtonType", aTmp );
 
@@ -1756,15 +1736,9 @@ void SwHTMLParser::InsertInput()
 
     if( bUseSize && nSize>0 )
     {
-        if( Application::GetDefaultDevice() )
-        {
-            Size aNewSz( nSize, 0 );
-            aNewSz = Application::GetDefaultDevice()
-                        ->PixelToLogic( aNewSz, MapMode( MapUnit::Map100thMM ) 
);
-            aSz.setWidth( aNewSz.Width() );
-            OSL_ENSURE( !aTextSz.Width(), "text width is present" );
-            bMinWidth = false;
-        }
+        aSz.setWidth(o3tl::convert(nSize, o3tl::Length::px, 
o3tl::Length::mm100));
+        OSL_ENSURE( !aTextSz.Width(), "text width is present" );
+        bMinWidth = false;
     }
 
     SfxItemSet aCSS1ItemSet( m_xDoc->GetAttrPool(), 
m_pCSS1Parser->GetWhichMap() );
diff --git a/sw/source/filter/html/htmlforw.cxx 
b/sw/source/filter/html/htmlforw.cxx
index 741ceff97c33..ce0bfe7bb2cf 100644
--- a/sw/source/filter/html/htmlforw.cxx
+++ b/sw/source/filter/html/htmlforw.cxx
@@ -972,19 +972,7 @@ SwHTMLWriter& OutHTML_DrawFrameFormatAsControl( 
SwHTMLWriter& rWrt,
             }
         }
 
-        Size aTwipSz( rFormObj.GetLogicRect().GetSize() );
-        Size aPixelSz( 0, 0 );
-        if( (aTwipSz.Width() || aTwipSz.Height()) &&
-            Application::GetDefaultDevice() )
-        {
-            aPixelSz =
-                Application::GetDefaultDevice()->LogicToPixel( aTwipSz,
-                                                    MapMode(MapUnit::MapTwip) 
);
-            if( !aPixelSz.Width() && aTwipSz.Width() )
-                aPixelSz.setWidth( 1 );
-            if( !aPixelSz.Height() && aTwipSz.Height() )
-                aPixelSz.setHeight( 1 );
-        }
+        Size 
aPixelSz(SwHTMLWriter::ToPixel(rFormObj.GetLogicRect().GetSize()));
 
         if( aPixelSz.Width() )
         {
diff --git a/sw/source/filter/html/htmlgrin.cxx 
b/sw/source/filter/html/htmlgrin.cxx
index f8f6c8ba31a8..1deccee5f9b2 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -68,6 +68,7 @@
 #include <frameformats.hxx>
 
 #include <vcl/graphicfilter.hxx>
+#include <tools/UnitConversion.hxx>
 #include <tools/urlobj.hxx>
 #include <unotools/securityoptions.hxx>
 
@@ -611,19 +612,19 @@ IMAGE_SETEVENT:
     SetFrameFormatAttrs( aItemSet, HtmlFrameFormatFlags::Box, aFrameSet );
 
     Size aTwipSz( bPercentWidth ? 0 : nWidth, bPercentHeight ? 0 : nHeight );
-    if( (aTwipSz.Width() || aTwipSz.Height()) && 
Application::GetDefaultDevice() )
+    if( aTwipSz.Width() || aTwipSz.Height() )
     {
         if (bWidthProvided || bHeightProvided || // attributes imply pixel!
             aGraphic.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel)
         {
-            aTwipSz = Application::GetDefaultDevice()
-                    ->PixelToLogic( aTwipSz, MapMode( MapUnit::MapTwip ) );
+            aTwipSz = o3tl::convert(aTwipSz, o3tl::Length::px, 
o3tl::Length::twip);
         }
         else
         {   // some bitmaps may have a size in metric units (e.g. PNG); use 
that
             assert(aGraphic.GetPrefMapMode().GetMapUnit() < MapUnit::MapPixel);
-            aTwipSz = OutputDevice::LogicToLogic(aGraphic.GetPrefSize(),
-                    aGraphic.GetPrefMapMode(), MapMode(MapUnit::MapTwip));
+            aTwipSz = o3tl::convert(aGraphic.GetPrefSize(),
+                                    
MapToO3tlLength(aGraphic.GetPrefMapMode().GetMapUnit()),
+                                    o3tl::Length::twip);
         }
     }
 
@@ -679,8 +680,8 @@ IMAGE_SETEVENT:
         {
             // Try to use size info from the image header before defaulting to
             // HTML_DFLT_IMG_WIDTH/HEIGHT.
-            aTwipSz = 
Application::GetDefaultDevice()->PixelToLogic(aDescriptor.GetSizePixel(),
-                                                                    
MapMode(MapUnit::MapTwip));
+            aTwipSz
+                = o3tl::convert(aDescriptor.GetSizePixel(), o3tl::Length::px, 
o3tl::Length::twip);
             if (!bPercentWidth && !nWidth)
             {
                 nWidth = aTwipSz.getWidth();
diff --git a/sw/source/filter/html/htmlnumreader.cxx 
b/sw/source/filter/html/htmlnumreader.cxx
index 191ba1e21add..c21a45e87768 100644
--- a/sw/source/filter/html/htmlnumreader.cxx
+++ b/sw/source/filter/html/htmlnumreader.cxx
@@ -224,9 +224,7 @@ void SwHTMLParser::NewNumberBulletList( HtmlTokenId nToken )
         Size aTwipSz( nWidth, nHeight), *pTwipSz=nullptr;
         if( nWidth!=USHRT_MAX && nHeight!=USHRT_MAX )
         {
-            aTwipSz =
-                Application::GetDefaultDevice()->PixelToLogic( aTwipSz,
-                                                    MapMode(MapUnit::MapTwip) 
);
+            aTwipSz = o3tl::convert(aTwipSz, o3tl::Length::px, 
o3tl::Length::twip);
             pTwipSz = &aTwipSz;
         }
 
diff --git a/sw/source/filter/html/htmlplug.cxx 
b/sw/source/filter/html/htmlplug.cxx
index 57f756631a8b..e078b00e2d3b 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -172,11 +172,9 @@ void SwHTMLParser::SetFixSize( const Size& rPixSize,
     sal_uInt8 nPercentWidth = 0, nPercentHeight = 0;
     Size aTwipSz( bPercentWidth || USHRT_MAX==rPixSize.Width() ? 0 : 
rPixSize.Width(),
                   bPercentHeight || USHRT_MAX==rPixSize.Height() ? 0 : 
rPixSize.Height() );
-    if( (aTwipSz.Width() || aTwipSz.Height()) && 
Application::GetDefaultDevice() )
+    if( aTwipSz.Width() || aTwipSz.Height() )
     {
-        aTwipSz =
-            Application::GetDefaultDevice()->PixelToLogic( aTwipSz,
-                                                MapMode(MapUnit::MapTwip) );
+        aTwipSz = o3tl::convert(aTwipSz, o3tl::Length::px, o3tl::Length::twip);
     }
 
     // process width
@@ -247,14 +245,10 @@ void SwHTMLParser::SetSpace( const Size& rPixSpace,
 {
     sal_Int32 nLeftSpace = 0, nRightSpace = 0;
     sal_uInt16 nUpperSpace = 0, nLowerSpace = 0;
-    if( (rPixSpace.Width() || rPixSpace.Height()) && 
Application::GetDefaultDevice() )
+    if( rPixSpace.Width() || rPixSpace.Height() )
     {
-        Size aTwipSpc( rPixSpace.Width(), rPixSpace.Height() );
-        aTwipSpc =
-            Application::GetDefaultDevice()->PixelToLogic( aTwipSpc,
-                                                MapMode(MapUnit::MapTwip) );
-        nLeftSpace = nRightSpace = aTwipSpc.Width();
-        nUpperSpace = nLowerSpace = 
o3tl::narrowing<sal_uInt16>(aTwipSpc.Height());
+        nLeftSpace = nRightSpace = o3tl::convert(rPixSpace.Width(), 
o3tl::Length::px, o3tl::Length::twip);
+        nUpperSpace = nLowerSpace = o3tl::convert(rPixSpace.Height(), 
o3tl::Length::px, o3tl::Length::twip);
     }
 
     // set left/right margin
@@ -525,8 +519,7 @@ bool SwHTMLParser::InsertEmbed()
             return true;
         SwAttrSet aAttrSet(pFormat->GetAttrSet());
         aAttrSet.ClearItem(RES_CNTNT);
-        OutputDevice* pDevice = Application::GetDefaultDevice();
-        Size 
aDefaultTwipSize(pDevice->PixelToLogic(aGraphic.GetSizePixel(pDevice), 
MapMode(MapUnit::MapTwip)));
+        Size aDefaultTwipSize(o3tl::convert(aGraphic.GetSizePixel(), 
o3tl::Length::px, o3tl::Length::twip));
 
         if (aSize.Width() == USHRT_MAX && bPercentHeight)
         {
diff --git a/sw/source/filter/html/htmlsect.cxx 
b/sw/source/filter/html/htmlsect.cxx
index e503d0546af7..26a1ec8d0e19 100644
--- a/sw/source/filter/html/htmlsect.cxx
+++ b/sw/source/filter/html/htmlsect.cxx
@@ -600,11 +600,9 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss )
     // Calculate width.
     sal_uInt8 nPercentWidth = bPercentWidth ? static_cast<sal_uInt8>(nWidth) : 
0;
     SwTwips nTwipWidth = 0;
-    if( !bPercentWidth && nWidth && Application::GetDefaultDevice() )
+    if( !bPercentWidth && nWidth )
     {
-        nTwipWidth = Application::GetDefaultDevice()
-                             ->PixelToLogic( Size(nWidth, 0),
-                                             MapMode(MapUnit::MapTwip) 
).Width();
+        nTwipWidth = o3tl::convert(nWidth, o3tl::Length::px, 
o3tl::Length::twip);
     }
 
     if( !nPercentWidth && nTwipWidth < MINFLY )
@@ -689,11 +687,9 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss )
         if( !IsNewDoc() )
             Reader::ResetFrameFormatAttrs(aFrameItemSet );
 
-        if( nGutter && Application::GetDefaultDevice() )
+        if( nGutter )
         {
-            nGutter = 
o3tl::narrowing<sal_uInt16>(Application::GetDefaultDevice()
-                             ->PixelToLogic( Size(nGutter, 0),
-                                             MapMode(MapUnit::MapTwip) 
).Width());
+            nGutter = o3tl::convert(nGutter, o3tl::Length::px, 
o3tl::Length::twip);
         }
 
         SwFormatCol aFormatCol;
diff --git a/sw/source/filter/html/htmltab.cxx 
b/sw/source/filter/html/htmltab.cxx
index a028a8fe86c4..861152083455 100644
--- a/sw/source/filter/html/htmltab.cxx
+++ b/sw/source/filter/html/htmltab.cxx
@@ -2031,10 +2031,9 @@ void HTMLTable::InsertCell( 
std::shared_ptr<HTMLTableCnts> const& rCnts,
     }
 
     Size aTwipSz( bRelWidth ? 0 : nCellWidth, nCellHeight );
-    if( (aTwipSz.Width() || aTwipSz.Height()) && 
Application::GetDefaultDevice() )
+    if( aTwipSz.Width() || aTwipSz.Height() )
     {
-        aTwipSz = Application::GetDefaultDevice()
-                    ->PixelToLogic( aTwipSz, MapMode( MapUnit::MapTwip ) );
+        aTwipSz = o3tl::convert(aTwipSz, o3tl::Length::px, o3tl::Length::twip);
     }
 
     // Only set width on the first cell!
@@ -2164,17 +2163,12 @@ void HTMLTable::InsertCol( sal_uInt16 nSpan, sal_uInt16 
nColWidth, bool bRelWidt
         m_nCols = nColsReq;
     }
 
-    Size aTwipSz( bRelWidth ? 0 : nColWidth, 0 );
-    if( aTwipSz.Width() && Application::GetDefaultDevice() )
-    {
-        aTwipSz = Application::GetDefaultDevice()
-                    ->PixelToLogic( aTwipSz, MapMode( MapUnit::MapTwip ) );
-    }
+    sal_uInt16 nTwipWidth(bRelWidth ? 0 : o3tl::convert(nColWidth, 
o3tl::Length::px, o3tl::Length::twip));
 
     for( i=m_nCurrentColumn; i<nColsReq; i++ )
     {
         HTMLTableColumn& rCol = m_aColumns[i];
-        sal_uInt16 nTmp = bRelWidth ? nColWidth : 
o3tl::narrowing<sal_uInt16>(aTwipSz.Width());
+        sal_uInt16 nTmp = bRelWidth ? nColWidth : 
o3tl::narrowing<sal_uInt16>(nTwipWidth);
         rCol.SetWidth( nTmp, bRelWidth );
         rCol.SetAdjust( eAdjust );
         rCol.SetVertOri( eVertOrient );
diff --git a/sw/source/filter/html/htmltabw.cxx 
b/sw/source/filter/html/htmltabw.cxx
index d7e5e107969d..22e57e54f772 100644
--- a/sw/source/filter/html/htmltabw.cxx
+++ b/sw/source/filter/html/htmltabw.cxx
@@ -119,14 +119,9 @@ SwHTMLWrtTable::SwHTMLWrtTable( const SwHTMLTableLayout 
*pLayoutInfo )
 
 void SwHTMLWrtTable::Pixelize( sal_uInt16& rValue )
 {
-    if( rValue && Application::GetDefaultDevice() )
+    if( rValue )
     {
-        Size aSz( rValue, 0 );
-        aSz = Application::GetDefaultDevice()->LogicToPixel( aSz, 
MapMode(MapUnit::MapTwip) );
-        if( !aSz.Width() )
-            aSz.setWidth( 1 );
-        aSz = Application::GetDefaultDevice()->PixelToLogic( aSz, 
MapMode(MapUnit::MapTwip) );
-        rValue = o3tl::narrowing<sal_uInt16>(aSz.Width());
+        rValue = o3tl::convert(SwHTMLWriter::ToPixel(rValue), 
o3tl::Length::px, o3tl::Length::twip);
     }
 }
 
@@ -358,19 +353,7 @@ void SwHTMLWrtTable::OutTableCell( SwHTMLWriter& rWrt,
     tools::Long nHeight = pCell->GetHeight() > 0
                         ? GetAbsHeight( pCell->GetHeight(), nRow, nRowSpan )
                         : 0;
-    Size aPixelSz( nWidth, nHeight );
-
-    // output WIDTH (Argh: only for Netscape)
-    if( (aPixelSz.Width() || aPixelSz.Height()) && 
Application::GetDefaultDevice() )
-    {
-        Size aOldSz( aPixelSz );
-        aPixelSz = Application::GetDefaultDevice()->LogicToPixel( aPixelSz,
-                                                        
MapMode(MapUnit::MapTwip) );
-        if( aOldSz.Width() && !aPixelSz.Width() )
-            aPixelSz.setWidth( 1 );
-        if( aOldSz.Height() && !aPixelSz.Height() )
-            aPixelSz.setHeight( 1 );
-    }
+    Size aPixelSz(SwHTMLWriter::ToPixel(nWidth), 
SwHTMLWriter::ToPixel(nHeight));
 
     // output WIDTH: from layout or calculated
     if( bOutWidth )
@@ -676,53 +659,36 @@ void SwHTMLWrtTable::Write( SwHTMLWriter& rWrt, sal_Int16 
eAlign,
         sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_width "=\"");
         if( HasRelWidths() )
             sOut.append(OString::number(static_cast<sal_Int32>(m_nTabWidth)) + 
"%");
-        else if( Application::GetDefaultDevice() )
-        {
-            sal_Int32 nPixWidth = 
Application::GetDefaultDevice()->LogicToPixel(
-                        Size(m_nTabWidth,0), MapMode(MapUnit::MapTwip) 
).Width();
-            if( !nPixWidth )
-                nPixWidth = 1;
-
-            sOut.append(nPixWidth);
-        }
         else
         {
-            OSL_ENSURE( Application::GetDefaultDevice(), "no 
Application-Window!?" );
-            sOut.append("100%");
+            sal_Int32 nPixWidth =  SwHTMLWriter::ToPixel(m_nTabWidth);
+            sOut.append(nPixWidth);
         }
         sOut.append("\"");
     }
 
-    if( (nHSpace || nVSpace) && Application::GetDefaultDevice() && 
!rWrt.mbReqIF)
+    if( (nHSpace || nVSpace) && !rWrt.mbReqIF)
     {
-        Size aPixelSpc =
-            Application::GetDefaultDevice()->LogicToPixel( 
Size(nHSpace,nVSpace),
-                                                   MapMode(MapUnit::MapTwip) );
-        if( !aPixelSpc.Width() && nHSpace )
-            aPixelSpc.setWidth( 1 );
-        if( !aPixelSpc.Height() && nVSpace )
-            aPixelSpc.setHeight( 1 );
-
-        if( aPixelSpc.Width() )
+        if (auto nPixHSpace = SwHTMLWriter::ToPixel(nHSpace))
         {
             sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_hspace
-                    "=\"" + OString::number(aPixelSpc.Width()) + "\"");
+                    "=\"" + OString::number(nPixHSpace) + "\"");
         }
 
-        if( aPixelSpc.Height() )
+        if (auto nPixVSpace = SwHTMLWriter::ToPixel(nVSpace))
         {
             sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_vspace
-                    "=\"" + OString::number(aPixelSpc.Height()) + "\"");
+                    "=\"" + OString::number(nPixVSpace) + "\"");
         }
     }
 
     // output CELLPADDING: from layout or calculated
     sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_cellpadding
-            "=\"" + 
OString::number(SwHTMLWriter::ToPixel(m_nCellPadding,false)) + "\"");
+            "=\"" + OString::number(SwHTMLWriter::ToPixel(m_nCellPadding)) + 
"\"");
 
     // output CELLSPACING: from layout or calculated
     sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_cellspacing
-            "=\"" + 
OString::number(SwHTMLWriter::ToPixel(m_nCellSpacing,false)) + "\"");
+            "=\"" + OString::number(SwHTMLWriter::ToPixel(m_nCellSpacing)) + 
"\"");
 
     rWrt.Strm().WriteOString( sOut );
     sOut.setLength(0);
@@ -801,7 +767,7 @@ void SwHTMLWrtTable::Write( SwHTMLWriter& rWrt, sal_Int16 
eAlign,
             if( bRel )
                 html.attribute(OOO_STRING_SVTOOLS_HTML_O_width, 
Concat2View(OString::number(nWidth) + "*"));
             else
-                html.attribute(OOO_STRING_SVTOOLS_HTML_O_width, 
OString::number(SwHTMLWriter::ToPixel(nWidth,false)));
+                html.attribute(OOO_STRING_SVTOOLS_HTML_O_width, 
OString::number(SwHTMLWriter::ToPixel(nWidth)));
             html.end();
 
             if( bColGroups && pColumn->m_bRightBorder && nCol<nCols-1 )
diff --git a/sw/source/filter/html/svxcss1.cxx 
b/sw/source/filter/html/svxcss1.cxx
index d53c0a0484f9..0150971144fe 100644
--- a/sw/source/filter/html/svxcss1.cxx
+++ b/sw/source/filter/html/svxcss1.cxx
@@ -885,15 +885,8 @@ bool SvxCSS1Parser::GetEnum( const CSS1PropertyEnum 
*pPropTable,
 
 void SvxCSS1Parser::PixelToTwip( tools::Long &rWidth, tools::Long &rHeight )
 {
-    if( Application::GetDefaultDevice() )
-    {
-        Size aTwipSz( rWidth, rHeight );
-        aTwipSz = Application::GetDefaultDevice()->PixelToLogic( aTwipSz,
-                                                          
MapMode(MapUnit::MapTwip) );
-
-        rWidth = aTwipSz.Width();
-        rHeight = aTwipSz.Height();
-    }
+    rWidth = o3tl::convert(rWidth, o3tl::Length::px, o3tl::Length::twip);
+    rHeight = o3tl::convert(rHeight, o3tl::Length::px, o3tl::Length::twip);
 }
 
 sal_uInt32 SvxCSS1Parser::GetFontHeight( sal_uInt16 nSize ) const
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index c8fd6c55bf2e..4e5138b135e6 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -4995,12 +4995,7 @@ void SwHTMLParser::InsertSpacer()
     case HTML_SPTYPE_VERT:
         if( nSize > 0 )
         {
-            if (Application::GetDefaultDevice())
-            {
-                nSize = Application::GetDefaultDevice()
-                            ->PixelToLogic( Size(0,nSize),
-                                            MapMode(MapUnit::MapTwip) 
).Height();
-            }
+            nSize = o3tl::convert(nSize, o3tl::Length::px, o3tl::Length::twip);
 
             // set a paragraph margin
             SwTextNode *pTextNode = nullptr;
@@ -5042,12 +5037,7 @@ void SwHTMLParser::InsertSpacer()
             // If the paragraph is still empty, set first line
             // indentation, otherwise apply letter spacing over a space.
 
-            if (Application::GetDefaultDevice())
-            {
-                nSize = Application::GetDefaultDevice()
-                            ->PixelToLogic( Size(nSize,0),
-                                            MapMode(MapUnit::MapTwip) 
).Width();
-            }
+            nSize = o3tl::convert(nSize, o3tl::Length::px, o3tl::Length::twip);
 
             if( !m_pPam->GetPoint()->GetContentIndex() )
             {
@@ -5080,14 +5070,8 @@ void SwHTMLParser::InsertSpacer()
 
 sal_uInt16 SwHTMLParser::ToTwips( sal_uInt16 nPixel )
 {
-    if( nPixel && Application::GetDefaultDevice() )
-    {
-        SwTwips nTwips = Application::GetDefaultDevice()->PixelToLogic(
-                    Size( nPixel, nPixel ), MapMode( MapUnit::MapTwip ) 
).Width();
-        return o3tl::narrowing<sal_uInt16>(std::min(nTwips, 
SwTwips(SAL_MAX_UINT16)));
-    }
-    else
-        return nPixel;
+    return std::min(o3tl::convert(nPixel, o3tl::Length::px, 
o3tl::Length::twip),
+                    sal_Int64(SAL_MAX_UINT16));
 }
 
 SwTwips SwHTMLParser::GetCurrentBrowseWidth()
diff --git a/sw/source/filter/html/wrthtml.cxx 
b/sw/source/filter/html/wrthtml.cxx
index 26b97e431027..e0b4ee6fb187 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -781,11 +781,7 @@ static void lcl_html_OutSectionStartTag( SwHTMLWriter& 
rHTMLWrt,
         sal_uInt16 nGutter = pCol->GetGutterWidth( true );
         if( nGutter!=USHRT_MAX )
         {
-            if( nGutter && Application::GetDefaultDevice() )
-            {
-                nGutter = 
o3tl::narrowing<sal_uInt16>(Application::GetDefaultDevice()
-                                ->LogicToPixel( Size(nGutter, 0), 
MapMode(MapUnit::MapTwip) ).Width());
-            }
+            nGutter = SwHTMLWriter::ToPixel(nGutter);
             sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_gutter "=\"" + 
OString::number(nGutter) + "\"");
         }
     }
diff --git a/sw/source/filter/html/wrthtml.hxx 
b/sw/source/filter/html/wrthtml.hxx
index 4a8ca7007a56..9c11c2969c31 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -484,7 +484,7 @@ public:
     void OutCSS1_Property( std::string_view pProp, std::string_view pVal,
                            const OUString *pSVal, 
std::optional<sw::Css1Background> oBackground = std::nullopt );
     void OutCSS1_UnitProperty( std::string_view pProp, tools::Long nVal );
-    void OutCSS1_PixelProperty( std::string_view pProp, tools::Long nVal, bool 
bVert );
+    void OutCSS1_PixelProperty( std::string_view pProp, tools::Long nTwips );
     void OutCSS1_SfxItemSet( const SfxItemSet& rItemSet, bool bDeep=true );
 
     // events of BODY tag from SFX configuration
@@ -542,7 +542,8 @@ public:
     SwPaM* GetEndPaM() { return m_pOrigPam; }
     void SetEndPaM( SwPaM* pPam ) { m_pOrigPam = pPam; }
 
-    static sal_uInt32 ToPixel( sal_uInt32 nVal, const bool bVert );
+    static sal_uInt32 ToPixel(sal_uInt32 nTwips);
+    static Size ToPixel(Size aTwips);
 
     SwHTMLFrameType GuessFrameType( const SwFrameFormat& rFrameFormat,
                          const SdrObject*& rpStrObj );

Reply via email to