From cff0defd2c35cf8c61e06c5ada0becc0e97ea87f Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sun, 15 Mar 2026 19:01:37 +0200 Subject: [PATCH] Fraction->double in FrPair Change-Id: Ibfee97e8b778bae6d93be852c78ab518285ca27c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201745 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- filter/source/msfilter/msdffimp.cxx | 53 ++++++++++------------------ filter/source/msfilter/svdfppt.cxx | 2 +- include/filter/msfilter/msdffimp.hxx | 9 ++--- include/svx/svdtrans.hxx | 20 +++++------ sd/qa/unit/data/xml/fdo64586_0.xml | 10 +++--- sd/qa/unit/data/xml/n758621_0.xml | 6 ++-- sd/qa/unit/data/xml/n758621_1.xml | 10 +++--- svx/source/svdraw/svdtrans.cxx | 8 ++--- sw/source/filter/ww8/escher.hxx | 4 +-- sw/source/filter/ww8/wrtw8esh.cxx | 5 ++- 10 files changed, 53 insertions(+), 74 deletions(-) diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index 769f6c811437..8da45c6bc631 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -3164,7 +3164,7 @@ void SvxMSDffManager::Scale( sal_Int32& rVal ) const return; } - rVal = BigMulDiv( rVal, nMapMul, nMapDiv ); + rVal = rVal * mfMap; } } @@ -3174,8 +3174,8 @@ void SvxMSDffManager::Scale( Point& rPos ) const rPos.AdjustY(nMapYOfs ); if ( bNeedMap ) { - rPos.setX( BigMulDiv( rPos.X(), nMapMul, nMapDiv ) ); - rPos.setY( BigMulDiv( rPos.Y(), nMapMul, nMapDiv ) ); + rPos.setX( rPos.X() * mfMap ); + rPos.setY( rPos.Y() * mfMap ); } } @@ -3183,14 +3183,14 @@ void SvxMSDffManager::Scale( Size& rSiz ) const { if ( bNeedMap ) { - rSiz.setWidth( BigMulDiv( rSiz.Width(), nMapMul, nMapDiv ) ); - rSiz.setHeight( BigMulDiv( rSiz.Height(), nMapMul, nMapDiv ) ); + rSiz.setWidth( rSiz.Width() * mfMap ); + rSiz.setHeight( rSiz.Height() * mfMap ); } } void SvxMSDffManager::ScaleEmu( sal_Int32& rVal ) const { - rVal = BigMulDiv( rVal, nEmuMul, nEmuDiv ); + rVal = rVal * mfEmu; } sal_uInt32 SvxMSDffManager::ScalePt( sal_uInt32 nVal ) const @@ -3205,7 +3205,7 @@ sal_uInt32 SvxMSDffManager::ScalePt( sal_uInt32 nVal ) const sal_Int32 SvxMSDffManager::ScalePoint( sal_Int32 nVal ) const { - return BigMulDiv( nVal, nPntMul, nPntDiv ); + return nVal * mfPnt; }; void SvxMSDffManager::SetModel(SdrModel* pModel, tools::Long nApplicationScale) @@ -3216,52 +3216,35 @@ void SvxMSDffManager::SetModel(SdrModel* pModel, tools::Long nApplicationScale) // PPT works in units of 576DPI // WW on the other side uses twips, i.e. 1440DPI. MapUnit eMap = pSdrModel->GetScaleUnit(); - Fraction aFact( GetMapFactor(MapUnit::MapInch, eMap).X() ); - tools::Long nMul=aFact.GetNumerator(); - tools::Long nDiv=aFact.GetDenominator()*nApplicationScale; - aFact=Fraction(nMul,nDiv); // try again to shorten it // For 100TH_MM -> 2540/576=635/144 // For Twip -> 1440/576=5/2 - nMapMul = aFact.GetNumerator(); - nMapDiv = aFact.GetDenominator(); - bNeedMap = nMapMul!=nMapDiv; + mfMap = GetMapFactor(MapUnit::MapInch, eMap).X() / nApplicationScale; + bNeedMap = mfMap != 1.0; // MS-DFF-Properties are mostly given in EMU (English Metric Units) // 1mm=36000emu, 1twip=635emu - aFact=GetMapFactor(MapUnit::Map100thMM,eMap).X(); - nMul=aFact.GetNumerator(); - nDiv=aFact.GetDenominator()*360; - aFact=Fraction(nMul,nDiv); // try again to shorten it // For 100TH_MM -> 1/360 // For Twip -> 14,40/(25,4*360)=144/91440=1/635 - nEmuMul=aFact.GetNumerator(); - nEmuDiv=aFact.GetDenominator(); + mfEmu = GetMapFactor(MapUnit::Map100thMM,eMap).X() / 360; // And something for typographic Points - aFact=GetMapFactor(MapUnit::MapPoint,eMap).X(); - nPntMul=aFact.GetNumerator(); - nPntDiv=aFact.GetDenominator(); + mfPnt = GetMapFactor(MapUnit::MapPoint,eMap).X(); } else { pModel = nullptr; - nMapMul = nMapDiv = nMapXOfs = nMapYOfs = nEmuMul = nEmuDiv = nPntMul = nPntDiv = 0; + mfMap = 0; + mfEmu = 0; + mfPnt = 0; + nMapXOfs = nMapYOfs = 0; bNeedMap = false; } if (bNeedMap) { - assert(nMapMul > nMapDiv); - - BigInt aMinVal(SAL_MIN_INT32); - aMinVal /= nMapMul; - aMinVal *= nMapDiv; - nMinAllowedVal = aMinVal; - - BigInt aMaxVal(SAL_MAX_INT32); - aMaxVal /= nMapMul; - aMaxVal *= nMapDiv; - nMaxAllowedVal = aMaxVal; + assert(mfMap > 1.0); + nMinAllowedVal = SAL_MIN_INT32 / mfMap; + nMaxAllowedVal = SAL_MAX_INT32 / mfMap; } else { diff --git a/filter/source/msfilter/svdfppt.cxx b/filter/source/msfilter/svdfppt.cxx index 062181c57a21..ad085621067a 100644 --- a/filter/source/msfilter/svdfppt.cxx +++ b/filter/source/msfilter/svdfppt.cxx @@ -2531,7 +2531,7 @@ Size SdrPowerPointImport::GetPageSize() const Scale( aRet ); // PPT works with units of 576 dpi in any case. To avoid inaccuracies // I do round the last decimal digit away. - if ( nMapMul > 2 * nMapDiv ) + if ( mfMap > 2.0 ) { MapUnit eMap = pSdrModel->GetScaleUnit(); bool bInch = IsInch( eMap ); diff --git a/include/filter/msfilter/msdffimp.hxx b/include/filter/msfilter/msdffimp.hxx index b6ef01fc9646..912897be268a 100644 --- a/include/filter/msfilter/msdffimp.hxx +++ b/include/filter/msfilter/msdffimp.hxx @@ -446,14 +446,11 @@ protected: SvStream* pStData2; SdrModel* pSdrModel; - tools::Long nMapMul; - tools::Long nMapDiv; + double mfMap; tools::Long nMapXOfs; tools::Long nMapYOfs; - tools::Long nEmuMul; - tools::Long nEmuDiv; - tools::Long nPntMul; - tools::Long nPntDiv; + double mfEmu; + double mfPnt; bool bNeedMap; sal_Int32 nMinAllowedVal; sal_Int32 nMaxAllowedVal; diff --git a/include/svx/svdtrans.hxx b/include/svx/svdtrans.hxx index e299bd10fe08..a85edb82beee 100644 --- a/include/svx/svdtrans.hxx +++ b/include/svx/svdtrans.hxx @@ -224,17 +224,17 @@ void OrthoDistance4(const Point& rPt0, Point& rPt, bool bBigOrtho); SVXCORE_DLLPUBLIC tools::Long BigMulDiv(tools::Long nVal, tools::Long nMul, tools::Long nDiv); class FrPair { - Fraction m_aX; - Fraction m_aY; + double m_aX; + double m_aY; public: - FrPair(const Fraction& rBoth) : m_aX(rBoth),m_aY(rBoth) {} - FrPair(const Fraction& rX, const Fraction& rY) : m_aX(rX),m_aY(rY) {} - FrPair(tools::Long nMul, tools::Long nDiv) : m_aX(nMul,nDiv),m_aY(nMul,nDiv) {} - FrPair(tools::Long xMul, tools::Long xDiv, tools::Long yMul, tools::Long yDiv): m_aX(xMul,xDiv),m_aY(yMul,yDiv) {} - const Fraction& X() const { return m_aX; } - const Fraction& Y() const { return m_aY; } - Fraction& X() { return m_aX; } - Fraction& Y() { return m_aY; } + FrPair(const double& rBoth) : m_aX(rBoth),m_aY(rBoth) {} + FrPair(const double& rX, const double& rY) : m_aX(rX),m_aY(rY) {} + FrPair(tools::Long nMul, tools::Long nDiv) = delete; + FrPair(tools::Long xMul, tools::Long xDiv, tools::Long yMul, tools::Long yDiv): m_aX(double(xMul)/xDiv),m_aY(double(yMul)/yDiv) {} + double X() const { return m_aX; } + double Y() const { return m_aY; } + double& X() { return m_aX; } + double& Y() { return m_aY; } }; // To convert units of measurement diff --git a/sd/qa/unit/data/xml/fdo64586_0.xml b/sd/qa/unit/data/xml/fdo64586_0.xml index cdabdd2119ad..0b15ffe33da5 100644 --- a/sd/qa/unit/data/xml/fdo64586_0.xml +++ b/sd/qa/unit/data/xml/fdo64586_0.xml @@ -1,6 +1,6 @@ - + @@ -9,12 +9,12 @@ - - + + - + @@ -23,7 +23,7 @@ - + diff --git a/sd/qa/unit/data/xml/n758621_0.xml b/sd/qa/unit/data/xml/n758621_0.xml index 3284a1da87f9..eb95c5587715 100644 --- a/sd/qa/unit/data/xml/n758621_0.xml +++ b/sd/qa/unit/data/xml/n758621_0.xml @@ -1,6 +1,6 @@ - + @@ -9,8 +9,8 @@ - - + + diff --git a/sd/qa/unit/data/xml/n758621_1.xml b/sd/qa/unit/data/xml/n758621_1.xml index 5d24431bed58..7960197fffdf 100644 --- a/sd/qa/unit/data/xml/n758621_1.xml +++ b/sd/qa/unit/data/xml/n758621_1.xml @@ -1,6 +1,6 @@ - + @@ -9,12 +9,12 @@ - + - + @@ -23,8 +23,8 @@ - - + + diff --git a/svx/source/svdraw/svdtrans.cxx b/svx/source/svdraw/svdtrans.cxx index 22db4e6b5b4a..7e9f18730a41 100644 --- a/svx/source/svdraw/svdtrans.cxx +++ b/svx/source/svdraw/svdtrans.cxx @@ -558,7 +558,7 @@ tools::Long BigMulDiv(tools::Long nVal, tools::Long nMul, tools::Long nDiv) static FrPair toPair(o3tl::Length eFrom, o3tl::Length eTo) { const auto [nNum, nDen] = o3tl::getConversionMulDiv(eFrom, eTo); - return FrPair(nNum, nDen); + return FrPair(nNum, nDen, nNum, nDen); } // How many eU units fit into a mm, respectively an inch? @@ -593,7 +593,7 @@ static FrPair GetInchOrMM(MapUnit eU) } default: break; } - return Fraction(1,1); + return 1.0; } // Calculate the factor that we need to convert units from eS to eD. @@ -611,8 +611,8 @@ FrPair GetMapFactor(MapUnit eS, MapUnit eD) bool bSInch=IsInch(eS); bool bDInch=IsInch(eD); FrPair aRet(aD.X()/aS.X(),aD.Y()/aS.Y()); - if (bSInch && !bDInch) { aRet.X()*=Fraction(127,5); aRet.Y()*=Fraction(127,5); } - if (!bSInch && bDInch) { aRet.X()*=Fraction(5,127); aRet.Y()*=Fraction(5,127); } + if (bSInch && !bDInch) { aRet.X() *= 127.0/5; aRet.Y() *= 127.0/5; } + if (!bSInch && bDInch) { aRet.X() *= 5.0/127; aRet.Y() *= 5.0/127; } return aRet; }; diff --git a/sw/source/filter/ww8/escher.hxx b/sw/source/filter/ww8/escher.hxx index 179b3a16f3d3..8d9b4f409cf0 100644 --- a/sw/source/filter/ww8/escher.hxx +++ b/sw/source/filter/ww8/escher.hxx @@ -97,7 +97,7 @@ private: protected: WW8Export& mrWrt; SvStream* mpEscherStrm; - tools::Long mnEmuMul, mnEmuDiv; + double mfEmu; virtual sal_Int32 WriteFlyFrameAttr(const SwFrameFormat& rFormat, MSO_SPT eShapeType, EscherPropertyContainer& rPropOpt); @@ -109,7 +109,7 @@ protected: static void WriteGrfAttr(const SwNoTextNode& rNd, const SwFrameFormat& rFormat, EscherPropertyContainer& rPropOpt); sal_Int32 DrawModelToEmu(sal_Int32 nVal) const - { return BigMulDiv(nVal, mnEmuMul, mnEmuDiv); } + { return nVal * mfEmu; } static sal_Int32 ToFract16(sal_Int32 nVal, sal_uInt32 nMax); diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx index 895dd78cc55e..9ec540230bba 100644 --- a/sw/source/filter/ww8/wrtw8esh.cxx +++ b/sw/source/filter/ww8/wrtw8esh.cxx @@ -2127,10 +2127,9 @@ void SwBasicEscherEx::Init() } // MS-DFF-Properties mostly are in EMU (English Metric Units) - Fraction aFact = conversionFract(o3tl::Length::mm100, o3tl::Length::emu); + double aFact(conversionFract(o3tl::Length::mm100, o3tl::Length::emu)); aFact /= GetMapFactor(MapUnit::Map100thMM, eMap).X(); - mnEmuMul = aFact.GetNumerator(); - mnEmuDiv = aFact.GetDenominator(); + mfEmu = aFact; SetHellLayerId(mrWrt.m_rDoc.getIDocumentDrawModelAccess().GetHellId()); SetHeaderFooterHellLayerId(mrWrt.m_rDoc.getIDocumentDrawModelAccess().GetHeaderFooterHellId());