diff options
-rw-r--r-- | starmath/inc/utility.hxx | 29 | ||||
-rw-r--r-- | starmath/source/cfgitem.cxx | 6 | ||||
-rw-r--r-- | starmath/source/dialog.cxx | 7 | ||||
-rw-r--r-- | starmath/source/format.cxx | 2 | ||||
-rw-r--r-- | starmath/source/mathml/mathmlexport.cxx | 14 | ||||
-rw-r--r-- | starmath/source/node.cxx | 6 | ||||
-rw-r--r-- | starmath/source/unomodel.cxx | 7 | ||||
-rw-r--r-- | starmath/source/utility.cxx | 2 |
8 files changed, 22 insertions, 51 deletions
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 233b5fb7f351..395bf932d822 100644 --- a/starmath/source/cfgitem.cxx +++ b/starmath/source/cfgitem.cxx @@ -888,7 +888,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; @@ -959,8 +959,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 8cf4029c1bb6..1180853e9bcd 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 a4bf960fd583..d11aa65f842f 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 d0f5089e241c..ca9453d8d0ab 100644 --- a/starmath/source/mathml/mathmlexport.cxx +++ b/starmath/source/mathml/mathmlexport.cxx @@ -1171,12 +1171,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: @@ -1191,14 +1191,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 5306908cefbe..d7615befe26d 100644 --- a/starmath/source/node.cxx +++ b/starmath/source/node.cxx @@ -134,8 +134,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(); @@ -167,7 +167,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 4b32900cbf26..09f00170bca9 100644 --- a/starmath/source/unomodel.cxx +++ b/starmath/source/unomodel.cxx @@ -482,7 +482,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 @@ -731,9 +731,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 ); |