starmath/inc/utility.hxx                |   29 -----------------------------
 starmath/source/cfgitem.cxx             |    6 +++---
 starmath/source/dialog.cxx              |    7 ++++---
 starmath/source/format.cxx              |    2 +-
 starmath/source/mathml/mathmlexport.cxx |   14 +++++++-------
 starmath/source/node.cxx                |    6 +++---
 starmath/source/unomodel.cxx            |    7 +++----
 starmath/source/utility.cxx             |    2 +-
 8 files changed, 22 insertions(+), 51 deletions(-)

New commits:
commit a37a979107a8643136ff3733b5b350b6b1be2bb7
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Nov 3 21:36:26 2022 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Nov 4 05:32:27 2022 +0100

    Use o3tl::convert in Math
    
    ... and use our standard definition of pt.
    
    Change-Id: I5a162b137360210335b84de33606dc7404cfc2de
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142204
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/starmath/inc/utility.hxx b/starmath/inc/utility.hxx
index ee504017038a..c0b473264532 100644
--- a/starmath/inc/utility.hxx
+++ b/starmath/inc/utility.hxx
@@ -27,35 +27,6 @@
 #include <tools/fract.hxx>
 #include <deque>
 
-inline tools::Long SmPtsTo100th_mm(tools::Long nNumPts)
-    // returns the length (in 100th of mm) that corresponds to the length
-    // 'nNumPts' (in units points).
-    // 72.27 [pt] = 1 [inch] = 2,54 [cm] = 2540 [100th of mm].
-    // result is being rounded to the nearest integer.
-{
-    SAL_WARN_IF( nNumPts < 0, "starmath", "Ooops..." );
-    // broken into multiple and fraction of 'nNumPts' to reduce chance
-    // of overflow
-    // (7227 / 2) is added in order to round to the nearest integer
-    return 35 * nNumPts + (nNumPts * 1055L + (7227 / 2)) / 7227L;
-}
-
-
-inline Fraction Sm100th_mmToPts(tools::Long nNum100th_mm)
-    // returns the length (in points) that corresponds to the length
-    // 'nNum100th_mm' (in 100th of mm).
-{
-    SAL_WARN_IF( nNum100th_mm < 0, "starmath", "Ooops..." );
-    return Fraction(7227L, 254000L) * Fraction(nNum100th_mm);
-}
-
-
-inline tools::Long SmRoundFraction(const Fraction &rFrac)
-{
-    SAL_WARN_IF( rFrac <= Fraction(), "starmath", "Ooops..." );
-    return (rFrac.GetNumerator() + rFrac.GetDenominator() / 2) / 
rFrac.GetDenominator();
-}
-
 
 class SmViewShell;
 SmViewShell * SmGetActiveView();
diff --git a/starmath/source/cfgitem.cxx b/starmath/source/cfgitem.cxx
index a8c0e5fcae38..9b6a4eadd184 100644
--- a/starmath/source/cfgitem.cxx
+++ b/starmath/source/cfgitem.cxx
@@ -988,7 +988,7 @@ void SmMathConfig::LoadFormat()
     ++pVal;
     // StandardFormat/BaseSize
     if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
-        pFormat->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16 )) );
+        pFormat->SetBaseSize(Size(0, o3tl::convert(nTmp16, o3tl::Length::pt, 
o3tl::Length::mm100)));
     ++pVal;
 
     sal_uInt16 i;
@@ -1059,8 +1059,8 @@ void SmMathConfig::SaveFormat()
     // StandardFormat/HorizontalAlignment
     *pValue++ <<= static_cast<sal_Int16>(pFormat->GetHorAlign());
     // StandardFormat/BaseSize
-    *pValue++ <<= static_cast<sal_Int16>(SmRoundFraction( Sm100th_mmToPts(
-                                    pFormat->GetBaseSize().Height() ) ));
+    *pValue++ <<= static_cast<sal_Int16>(
+        o3tl::convert(pFormat->GetBaseSize().Height(), o3tl::Length::mm100, 
o3tl::Length::pt));
 
     sal_uInt16 i;
     for (i = SIZ_BEGIN;  i <= SIZ_END;  ++i)
diff --git a/starmath/source/dialog.cxx b/starmath/source/dialog.cxx
index 043739cf5c0d..f700b8e6ce9a 100644
--- a/starmath/source/dialog.cxx
+++ b/starmath/source/dialog.cxx
@@ -392,8 +392,9 @@ SmFontSizeDialog::~SmFontSizeDialog()
 void SmFontSizeDialog::ReadFrom(const SmFormat &rFormat)
 {
     //! watch out: round properly!
-    m_xBaseSize->set_value( SmRoundFraction(
-        Sm100th_mmToPts( rFormat.GetBaseSize().Height() ) ), FieldUnit::NONE );
+    m_xBaseSize->set_value(
+        o3tl::convert(rFormat.GetBaseSize().Height(), o3tl::Length::mm100, 
o3tl::Length::pt),
+        FieldUnit::NONE);
 
     m_xTextSize->set_value( rFormat.GetRelSize(SIZ_TEXT), FieldUnit::NONE );
     m_xIndexSize->set_value( rFormat.GetRelSize(SIZ_INDEX), FieldUnit::NONE );
@@ -404,7 +405,7 @@ void SmFontSizeDialog::ReadFrom(const SmFormat &rFormat)
 
 void SmFontSizeDialog::WriteTo(SmFormat &rFormat) const
 {
-    rFormat.SetBaseSize( Size(0, SmPtsTo100th_mm( static_cast< tools::Long 
>(m_xBaseSize->get_value(FieldUnit::NONE)))) );
+    rFormat.SetBaseSize( Size(0, 
o3tl::convert(m_xBaseSize->get_value(FieldUnit::NONE), o3tl::Length::pt, 
o3tl::Length::mm100)) );
 
     rFormat.SetRelSize(SIZ_TEXT,     
sal::static_int_cast<sal_uInt16>(m_xTextSize->get_value(FieldUnit::NONE)));
     rFormat.SetRelSize(SIZ_INDEX,    
sal::static_int_cast<sal_uInt16>(m_xIndexSize->get_value(FieldUnit::NONE)));
diff --git a/starmath/source/format.cxx b/starmath/source/format.cxx
index 65ec09558d56..f1f7a00f3806 100644
--- a/starmath/source/format.cxx
+++ b/starmath/source/format.cxx
@@ -21,7 +21,7 @@
 
 
 SmFormat::SmFormat()
-:   aBaseSize(0, SmPtsTo100th_mm(12))
+:   aBaseSize(0, o3tl::convert(12, o3tl::Length::pt, o3tl::Length::mm100))
 {
     eHorAlign       = SmHorAlign::Center;
     nGreekCharStyle = 0;
diff --git a/starmath/source/mathml/mathmlexport.cxx 
b/starmath/source/mathml/mathmlexport.cxx
index 172e0c1fe284..fe667fd52818 100644
--- a/starmath/source/mathml/mathmlexport.cxx
+++ b/starmath/source/mathml/mathmlexport.cxx
@@ -1175,12 +1175,12 @@ void SmXMLExport::ExportFont(const SmNode* pNode, int 
nLevel)
             {
                 case FontSizeType::MULTIPLY:
                     ::sax::Converter::convertDouble(sStrBuf,
-                                                    static_cast<double>(aFrac 
* Fraction(100.00)));
+                                                    static_cast<double>(aFrac 
* Fraction(100, 1)));
                     sStrBuf.append('%');
                     break;
                 case FontSizeType::DIVIDE:
                     ::sax::Converter::convertDouble(sStrBuf,
-                                                    
static_cast<double>(Fraction(100.00) / aFrac));
+                                                    
static_cast<double>(Fraction(100, 1) / aFrac));
                     sStrBuf.append('%');
                     break;
                 case FontSizeType::ABSOLUT:
@@ -1195,14 +1195,14 @@ void SmXMLExport::ExportFont(const SmNode* pNode, int 
nLevel)
                     //value specified in points.
 
                     //Must fix StarMath to retain the original pt values
-                    Fraction aTemp = 
Sm100th_mmToPts(pFontNode->GetFont().GetFontSize().Height());
+                    double mytest
+                        = 
o3tl::convert<double>(pFontNode->GetFont().GetFontSize().Height(),
+                                                o3tl::Length::mm100, 
o3tl::Length::pt);
 
                     if (pFontNode->GetSizeType() == FontSizeType::MINUS)
-                        aTemp -= aFrac;
+                        mytest -= static_cast<double>(aFrac);
                     else
-                        aTemp += aFrac;
-
-                    double mytest = static_cast<double>(aTemp);
+                        mytest += static_cast<double>(aFrac);
 
                     mytest = ::rtl::math::round(mytest, 1);
                     ::sax::Converter::convertDouble(sStrBuf, mytest);
diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx
index 421c9e03955e..7b7f331bbf10 100644
--- a/starmath/source/node.cxx
+++ b/starmath/source/node.cxx
@@ -135,8 +135,8 @@ void SmNode::SetFontSize(const Fraction &rSize, 
FontSizeType nType)
 
     if (!(Flags() & FontChangeMask::Size))
     {
-        Fraction  aVal (SmPtsTo100th_mm(rSize.GetNumerator()),
-                        rSize.GetDenominator());
+        constexpr auto md = o3tl::getConversionMulDiv(o3tl::Length::pt, 
o3tl::Length::mm100);
+        Fraction aVal (Fraction(md.first, md.second) * rSize);
         tools::Long      nHeight = static_cast<tools::Long>(aVal);
 
         aFntSize = GetFont().GetFontSize();
@@ -168,7 +168,7 @@ void SmNode::SetFontSize(const Fraction &rSize, 
FontSizeType nType)
         }
 
         // check the requested size against maximum value
-        static int const    nMaxVal = SmPtsTo100th_mm(128);
+        constexpr int nMaxVal = o3tl::convert(128, o3tl::Length::pt, 
o3tl::Length::mm100);
         if (aFntSize.Height() > nMaxVal)
             aFntSize.setHeight( nMaxVal );
 
diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx
index 3c0d750f5737..51a5fc822af0 100644
--- a/starmath/source/unomodel.cxx
+++ b/starmath/source/unomodel.cxx
@@ -478,7 +478,7 @@ void SmModel::_setPropertyValues(const PropertyMapEntry** 
ppEntries, const Any*
                 if(nVal < 1)
                     throw IllegalArgumentException();
                 Size aSize = aFormat.GetBaseSize();
-                aSize.setHeight( SmPtsTo100th_mm(nVal) );
+                aSize.setHeight(o3tl::convert(nVal, o3tl::Length::pt, 
o3tl::Length::mm100));
                 aFormat.SetBaseSize(aSize);
 
                 // apply base size to fonts
@@ -727,9 +727,8 @@ void SmModel::_getPropertyValues( const PropertyMapEntry 
**ppEntries, Any *pValu
             case HANDLE_BASE_FONT_HEIGHT                   :
             {
                 // Point!
-                *pValue <<= sal_Int16(
-                    SmRoundFraction(
-                        Sm100th_mmToPts(aFormat.GetBaseSize().Height())));
+                *pValue <<= 
sal_Int16(o3tl::convert(aFormat.GetBaseSize().Height(),
+                                                    o3tl::Length::mm100, 
o3tl::Length::pt));
             }
             break;
             case HANDLE_RELATIVE_FONT_HEIGHT_TEXT           :
diff --git a/starmath/source/utility.cxx b/starmath/source/utility.cxx
index e8406c10380f..35680ed24b73 100644
--- a/starmath/source/utility.cxx
+++ b/starmath/source/utility.cxx
@@ -203,7 +203,7 @@ void SmFace::SetSize(const Size& rSize)
     Size  aSize (rSize);
 
     // check the requested size against minimum value
-    static int const    nMinVal = SmPtsTo100th_mm(2);
+    constexpr int nMinVal = o3tl::convert(2, o3tl::Length::pt, 
o3tl::Length::mm100);
 
     if (aSize.Height() < nMinVal)
         aSize.setHeight( nMinVal );

Reply via email to