sw/source/filter/html/parcss1.cxx |   94 ++++++++++++++------------------------
 vcl/source/filter/eps/eps.cxx     |   60 +++---------------------
 2 files changed, 44 insertions(+), 110 deletions(-)

New commits:
commit 64b5180534b6e87fe89467410bb33459d7179469
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Apr 13 16:50:36 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Apr 13 18:48:31 2024 +0200

    Simplify and use more o3tl::convert
    
    Change-Id: Ic7babea4eec3633d40d306488fea252d6f2636be
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166050
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/source/filter/html/parcss1.cxx 
b/sw/source/filter/html/parcss1.cxx
index f3145f1fa5bd..a32de72ab52f 100644
--- a/sw/source/filter/html/parcss1.cxx
+++ b/sw/source/filter/html/parcss1.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <o3tl/string_view.hxx>
+#include <o3tl/unit_conversion.hxx>
 #include <osl/diagnose.h>
 #include <rtl/character.hxx>
 #include <rtl/ustrbuf.hxx>
@@ -379,87 +380,62 @@ CSS1Token CSS1Parser::GetNextToken()
                         bool bEOFOld = m_bEOF;
 
                         // parse the next identifier
-                        OUString aIdent;
                         OUStringBuffer sTmpBuffer2(64);
                         do {
-                            sTmpBuffer2.append( m_cNextCh );
+                            
sTmpBuffer2.append(static_cast<sal_Unicode>(rtl::toAsciiLowerCase(m_cNextCh)));
                             m_cNextCh = GetNextChar();
                         } while( (rtl::isAsciiAlphanumeric(m_cNextCh) ||
                                  '-' == m_cNextCh) && !IsEOF() );
 
-                        aIdent += sTmpBuffer2;
+                        OUString aIdent = sTmpBuffer2.makeStringAndClear();
+                        nRet = CSS1_NUMBER;
 
                         // Is it a unit?
-                        const char *pCmp1 = nullptr, *pCmp2 = nullptr, *pCmp3 
= nullptr;
-                        double nScale1 = 1., nScale2 = 1.;
-                        CSS1Token nToken1 = CSS1_LENGTH,
-                                  nToken2 = CSS1_LENGTH,
-                                  nToken3 = CSS1_LENGTH;
                         switch( aIdent[0] )
                         {
                         case 'c':
-                        case 'C':
-                            pCmp1 = "cm";
-                            nScale1 = (72.*20.)/2.54; // twip
+                            if (aIdent == "cm")
+                            {
+                                m_nValue = o3tl::convert(m_nValue, 
o3tl::Length::cm, o3tl::Length::twip);
+                                nRet = CSS1_LENGTH;
+                            }
                             break;
                         case 'e':
-                        case 'E':
-                            pCmp1 = "em";
-                            nToken1 = CSS1_EMS;
-
-                            pCmp2 = "ex";
-                            nToken2 = CSS1_EMX;
+                            if (aIdent == "em")
+                                nRet = CSS1_EMS;
+                            else if (aIdent == "ex")
+                                nRet = CSS1_EMX;
                             break;
                         case 'i':
-                        case 'I':
-                            pCmp1 = "in";
-                            nScale1 = 72.*20.; // twip
+                            if (aIdent == "in")
+                            {
+                                nRet = CSS1_LENGTH;
+                                m_nValue = o3tl::convert(m_nValue, 
o3tl::Length::in, o3tl::Length::twip);
+                            }
                             break;
                         case 'm':
-                        case 'M':
-                            pCmp1 = "mm";
-                            nScale1 = (72.*20.)/25.4; // twip
+                            if (aIdent == "mm")
+                            {
+                                nRet = CSS1_LENGTH;
+                                m_nValue = o3tl::convert(m_nValue, 
o3tl::Length::mm, o3tl::Length::twip);
+                            }
                             break;
                         case 'p':
-                        case 'P':
-                            pCmp1 = "pt";
-                            nScale1 = 20.; // twip
-
-                            pCmp2 = "pc";
-                            nScale2 = 12.*20.; // twip
-
-                            pCmp3 = "px";
-                            nToken3 = CSS1_PIXLENGTH;
+                            if (aIdent == "pt")
+                            {
+                                nRet = CSS1_LENGTH;
+                                m_nValue = o3tl::convert(m_nValue, 
o3tl::Length::pt, o3tl::Length::twip);
+                            }
+                            else if (aIdent == "pc")
+                            {
+                                nRet = CSS1_LENGTH;
+                                m_nValue = o3tl::convert(m_nValue, 
o3tl::Length::pc, o3tl::Length::twip);
+                            }
+                            else if (aIdent == "px")
+                                nRet = CSS1_PIXLENGTH;
                             break;
                         }
 
-                        double nScale = 0.0;
-                        OSL_ENSURE( pCmp1, "Where does the first digit come 
from?" );
-                        if( aIdent.equalsIgnoreAsciiCaseAscii( pCmp1 ) )
-                        {
-                            nScale = nScale1;
-                            nRet = nToken1;
-                        }
-                        else if( pCmp2 &&
-                                 aIdent.equalsIgnoreAsciiCaseAscii( pCmp2 ) )
-                        {
-                            nScale = nScale2;
-                            nRet = nToken2;
-                        }
-                        else if( pCmp3 &&
-                                 aIdent.equalsIgnoreAsciiCaseAscii( pCmp3 ) )
-                        {
-                            nScale =  1.; // nScale3
-                            nRet = nToken3;
-                        }
-                        else
-                        {
-                            nRet = CSS1_NUMBER;
-                        }
-
-                        if( CSS1_LENGTH==nRet && nScale!=1.0 )
-                            m_nValue *= nScale;
-
                         if( nRet == CSS1_NUMBER )
                         {
                             m_nInPos = nInPosOld;
commit 72a1ab78c2f4a1bd0d8a60dbdecd8923f076d858
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Apr 13 16:49:57 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Apr 13 18:48:23 2024 +0200

    Use more o3tl::convert
    
    Change-Id: Id31185592ccbb3507c939b241d5aab82c09c96f4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166049
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/vcl/source/filter/eps/eps.cxx b/vcl/source/filter/eps/eps.cxx
index 88a9df9b8ec0..cc29c7f429a0 100644
--- a/vcl/source/filter/eps/eps.cxx
+++ b/vcl/source/filter/eps/eps.cxx
@@ -22,6 +22,7 @@
 #include <tools/poly.hxx>
 #include <tools/fract.hxx>
 #include <tools/helpers.hxx>
+#include <tools/UnitConversion.hxx>
 #include <unotools/resmgr.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/metaact.hxx>
@@ -215,7 +216,6 @@ private:
     inline void         ImplWriteTextColor( NMode nMode );
     void                ImplWriteColor( NMode nMode );
 
-    static double       ImplGetScaling( const MapMode& );
     void                ImplGetMapMode( const MapMode& );
     static bool         ImplGetBoundingBox( double* nNumb, sal_uInt8* pSource, 
sal_uInt32 nSize );
     static sal_uInt8*   ImplSearchEntry( sal_uInt8* pSource, sal_uInt8 const * 
pDest, sal_uInt32 nComp, sal_uInt32 nSize );
@@ -2173,9 +2173,14 @@ void PSWriter::ImplWriteColor( NMode nMode )
 void PSWriter::ImplGetMapMode( const MapMode& rMapMode )
 {
     ImplWriteLine( "tm setmatrix" );
-    double fMul = ImplGetScaling(rMapMode);
-    double fScaleX = static_cast<double>(rMapMode.GetScaleX()) * fMul;
-    double fScaleY = static_cast<double>(rMapMode.GetScaleY()) * fMul;
+    double fScaleX(rMapMode.GetScaleX());
+    double fScaleY(rMapMode.GetScaleY());
+    if (o3tl::Length l = MapToO3tlLength(rMapMode.GetMapUnit(), 
o3tl::Length::invalid);
+        l != o3tl::Length::invalid)
+    {
+        fScaleX = o3tl::convert(fScaleX, l, o3tl::Length::mm100);
+        fScaleY = o3tl::convert(fScaleY, l, o3tl::Length::mm100);
+    }
     ImplTranslate( rMapMode.GetOrigin().X() * fScaleX, 
rMapMode.GetOrigin().Y() * fScaleY );
     ImplScale( fScaleX, fScaleY );
 }
@@ -2214,53 +2219,6 @@ inline void PSWriter::ImplWriteLine( const char* 
pString, NMode nMode )
     ImplExecMode( nMode );
 }
 
-double PSWriter::ImplGetScaling( const MapMode& rMapMode )
-{
-    double nMul;
-    switch (rMapMode.GetMapUnit())
-    {
-        case MapUnit::MapPixel :
-        case MapUnit::MapSysFont :
-        case MapUnit::MapAppFont :
-
-        case MapUnit::Map100thMM :
-            nMul = 1;
-            break;
-        case MapUnit::Map10thMM :
-            nMul = 10;
-            break;
-        case MapUnit::MapMM :
-            nMul = 100;
-            break;
-        case MapUnit::MapCM :
-            nMul = 1000;
-            break;
-        case MapUnit::Map1000thInch :
-            nMul = 2.54;
-            break;
-        case MapUnit::Map100thInch :
-            nMul = 25.4;
-            break;
-        case MapUnit::Map10thInch :
-            nMul = 254;
-            break;
-        case MapUnit::MapInch :
-            nMul = 2540;
-            break;
-        case MapUnit::MapTwip :
-            nMul = 1.76388889;
-            break;
-        case MapUnit::MapPoint :
-            nMul = 35.27777778;
-            break;
-        default:
-            nMul = 1.0;
-            break;
-    }
-    return nMul;
-}
-
-
 void PSWriter::ImplWriteLineInfo( double fLWidth, double fMLimit,
                                   SvtGraphicStroke::CapType eLCap,
                                   SvtGraphicStroke::JoinType eJoin,

Reply via email to