summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-02-13 13:55:22 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-02-14 12:50:01 +0100
commitcfff893b9c82843a90aac4ecdb3a3936721b74a0 (patch)
tree2859340e329ea6dbffe5ae9c7eba0f67a88c57af /vcl
parent20305894243e24eb383ab9feefebf4a0e9f2644f (diff)
Move unit conversion code to o3tl, and unify on that in more places
This also allows to easily add more units, both of length and for other unit categories. The conversion for "Line" unit (312 twip) is questionable. Corresponding entries in aImplFactor in vcl/source/control/field.cxx were inconsistent (45/11 in; 10/13 pc; 156/10 pt). They were added without explanation in commit c85db626029fd8a5e0dfcb312937279df32339a0. I haven't found a spec of the unit (https://en.wikipedia.org/wiki/Line_(unit) is not specific). I used the definition based on "by pt", "by mm/100", "by char" (they all were consistent); "by pc" seems inverted; "by twip" was half as much. This accepted conversion makes unit test for tdf#79236 pass. Change-Id: Iae5a21d915fa8e934a1f47f8ba9f6df03b79a9fd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110839 Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/control/field.cxx116
-rw-r--r--vcl/source/gdi/pdfwriter_impl2.cxx13
-rw-r--r--vcl/source/outdev/bitmap.cxx9
-rw-r--r--vcl/source/outdev/map.cxx166
4 files changed, 101 insertions, 203 deletions
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index f232e50a7c7a..9a42dcb2d8a5 100644
--- a/vcl/source/control/field.cxx
+++ b/vcl/source/control/field.cxx
@@ -19,12 +19,14 @@
#include <sal/config.h>
+#include <cmath>
#include <string_view>
#include <sal/log.hxx>
#include <osl/diagnose.h>
#include <comphelper/string.hxx>
+#include <tools/UnitConversion.hxx>
#include <vcl/builder.hxx>
#include <vcl/fieldvalues.hxx>
@@ -972,35 +974,6 @@ static FieldUnit ImplMetricGetUnit(const OUString& rStr)
return vcl::StringToMetric(aStr);
}
-#define K *1000L
-#define M *1000000LL
-#define X *5280L
-
-// twip in km = 254 / 14 400 000 000
-// expressions too big for default size 32 bit need LL to avoid overflow
-
-const sal_Int64 aImplFactor[sal_uInt16(FieldUnit::LINE) + 1]
- [sal_uInt16(FieldUnit::LINE) + 1] =
-{ /*
-mm/100 mm cm m km twip point pica inch foot mile char line */
-{ 1, 100, 1 K, 100 K, 100 M, 2540, 2540, 2540, 2540,2540*12,2540*12 X , 53340, 396240},
-{ 1, 1, 10, 1 K, 1 M, 2540, 2540, 2540, 2540,2540*12,2540*12 X , 5334, 396240},
-{ 1, 1, 1, 100, 100 K, 254, 254, 254, 254, 254*12, 254*12 X , 5334, 39624},
-{ 1, 1, 1, 1, 1 K, 254, 254, 254, 254, 254*12, 254*12 X , 533400, 39624},
-{ 1, 1, 1, 1, 1, 254, 254, 254, 254, 254*12, 254*12 X ,533400 K, 39624},
-{ 1440,144 K,144 K,14400 K,14400LL M, 1, 20, 240, 1440,1440*12,1440*12 X , 210, 3120},
-{ 72, 7200, 7200, 720 K, 720 M, 1, 1, 12, 72, 72*12, 72*12 X , 210, 156},
-{ 6, 600, 600, 60 K, 60 M, 1, 1, 1, 6, 6*12, 6*12 X , 210, 10},
-{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 12, 12 X , 210, 45},
-{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 1, 1 X , 210, 45},
-{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 1, 1 , 210, 45},
-{ 144, 1440,14400, 14400, 14400, 1, 20, 240, 1440,1440*12, 1440*12 X, 1, 156 },
-{ 720,72000,72000, 7200 K,7200LL M, 20, 10, 13, 11, 11*12, 11*12 X, 105, 1 }
-};
-#undef X
-#undef M
-#undef K
-
static FieldUnit ImplMap2FieldUnit( MapUnit meUnit, tools::Long& nDecDigits )
{
switch( meUnit )
@@ -1057,7 +1030,7 @@ namespace vcl
else if ( nDouble >= double(SAL_MAX_INT64) )
nLong = SAL_MAX_INT64;
else
- nLong = static_cast<sal_Int64>( nDouble );
+ nLong = static_cast<sal_Int64>( std::round(nDouble) );
return nLong;
}
@@ -1094,20 +1067,11 @@ double convertValue( double nValue, tools::Long nDigits, FieldUnit eInUnit, Fiel
if ( eInUnit != eOutUnit )
{
- sal_Int64 nDiv = aImplFactor[sal_uInt16(eInUnit)][sal_uInt16(eOutUnit)];
- sal_Int64 nMult = aImplFactor[sal_uInt16(eOutUnit)][sal_uInt16(eInUnit)];
-
- SAL_WARN_IF( nMult <= 0, "vcl", "illegal *" );
- SAL_WARN_IF( nDiv <= 0, "vcl", "illegal /" );
-
- if ( nMult != 1 && nMult > 0)
- nValue *= nMult;
- if ( nDiv != 1 && nDiv > 0 )
- {
- nValue += (nValue < 0) ? (-nDiv/2) : (nDiv/2);
- nValue /= nDiv;
- }
+ const o3tl::Length eFrom = FieldToO3tlLength(eInUnit), eTo = FieldToO3tlLength(eOutUnit);
+ if (eFrom != o3tl::Length::invalid && eTo != o3tl::Length::invalid)
+ nValue = o3tl::convert(nValue, eFrom, eTo);
}
+
return nValue;
}
@@ -1143,49 +1107,22 @@ namespace vcl
{
if ( eInUnit != eOutUnit )
{
- sal_Int64 nMult = 1, nDiv = 1;
-
- if (eInUnit == FieldUnit::PERCENT)
+ if (eInUnit == FieldUnit::PERCENT && mnBaseValue > 0 && nValue > 0)
{
- if ( (mnBaseValue <= 0) || (nValue <= 0) )
- return nValue;
- nDiv = 100 * ImplPower10(nDecDigits);
+ sal_Int64 nDiv = 100 * ImplPower10(nDecDigits);
- nMult = mnBaseValue;
- }
- else if ( eOutUnit == FieldUnit::PERCENT ||
- eOutUnit == FieldUnit::CUSTOM ||
- eOutUnit == FieldUnit::NONE ||
- eOutUnit == FieldUnit::DEGREE ||
- eOutUnit == FieldUnit::SECOND ||
- eOutUnit == FieldUnit::MILLISECOND ||
- eOutUnit == FieldUnit::PIXEL ||
- eInUnit == FieldUnit::CUSTOM ||
- eInUnit == FieldUnit::NONE ||
- eInUnit == FieldUnit::DEGREE ||
- eInUnit == FieldUnit::MILLISECOND ||
- eInUnit == FieldUnit::PIXEL )
- return nValue;
- else
- {
- if (eOutUnit == FieldUnit::MM_100TH)
- eOutUnit = FieldUnit::NONE;
- if (eInUnit == FieldUnit::MM_100TH)
- eInUnit = FieldUnit::NONE;
+ if (mnBaseValue != 1)
+ nValue *= mnBaseValue;
- nDiv = aImplFactor[sal_uInt16(eInUnit)][sal_uInt16(eOutUnit)];
- nMult = aImplFactor[sal_uInt16(eOutUnit)][sal_uInt16(eInUnit)];
-
- SAL_WARN_IF( nMult <= 0, "vcl", "illegal *" );
- SAL_WARN_IF( nDiv <= 0, "vcl", "illegal /" );
+ nValue += nDiv / 2;
+ nValue /= nDiv;
}
-
- if ( nMult != 1 && nMult > 0 )
- nValue *= nMult;
- if ( nDiv != 1 && nDiv > 0 )
+ else
{
- nValue += ( nValue < 0 ) ? (-nDiv/2) : (nDiv/2);
- nValue /= nDiv;
+ const o3tl::Length eFrom = FieldToO3tlLength(eInUnit, o3tl::Length::invalid);
+ const o3tl::Length eTo = FieldToO3tlLength(eOutUnit, o3tl::Length::invalid);
+ if (eFrom != o3tl::Length::invalid && eTo != o3tl::Length::invalid)
+ nValue = o3tl::convert(nValue, eFrom, eTo);
}
}
@@ -1240,19 +1177,10 @@ namespace vcl
if ( eFieldUnit != eInUnit )
{
- sal_Int64 nDiv = aImplFactor[sal_uInt16(eInUnit)][sal_uInt16(eFieldUnit)];
- sal_Int64 nMult = aImplFactor[sal_uInt16(eFieldUnit)][sal_uInt16(eInUnit)];
-
- SAL_WARN_IF( nMult <= 0, "vcl", "illegal *" );
- SAL_WARN_IF( nDiv <= 0, "vcl", "illegal /" );
-
- if( nMult != 1 && nMult > 0 )
- nValue *= nMult;
- if( nDiv != 1 && nDiv > 0 )
- {
- nValue += (nValue < 0) ? (-nDiv/2) : (nDiv/2);
- nValue /= nDiv;
- }
+ const o3tl::Length eFrom = FieldToO3tlLength(eInUnit, o3tl::Length::invalid);
+ const o3tl::Length eTo = FieldToO3tlLength(eFieldUnit, o3tl::Length::invalid);
+ if (eFrom != o3tl::Length::invalid && eTo != o3tl::Length::invalid)
+ nValue = o3tl::convert(nValue, eFrom, eTo);
}
return nValue;
}
diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx
index e349d8e837f9..304647aa1233 100644
--- a/vcl/source/gdi/pdfwriter_impl2.cxx
+++ b/vcl/source/gdi/pdfwriter_impl2.cxx
@@ -43,6 +43,7 @@
#include <com/sun/star/beans/XMaterialHolder.hpp>
#include <cppuhelper/implbase.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <sal/log.hxx>
#include <memory>
@@ -116,8 +117,12 @@ void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSiz
const Size aDstSizeTwip( i_pDummyVDev->PixelToLogic(i_pDummyVDev->LogicToPixel(aSize), MapMode(MapUnit::MapTwip)) );
const double fBmpPixelX = aBmpSize.Width();
const double fBmpPixelY = aBmpSize.Height();
- const double fMaxPixelX = aDstSizeTwip.Width() * i_rContext.m_nMaxImageResolution / 1440.0;
- const double fMaxPixelY = aDstSizeTwip.Height() * i_rContext.m_nMaxImageResolution / 1440.0;
+ const double fMaxPixelX
+ = o3tl::convert<double>(aDstSizeTwip.Width(), o3tl::Length::twip, o3tl::Length::in)
+ * i_rContext.m_nMaxImageResolution;
+ const double fMaxPixelY
+ = o3tl::convert<double>(aDstSizeTwip.Height(), o3tl::Length::twip, o3tl::Length::in)
+ * i_rContext.m_nMaxImageResolution;
// check, if the bitmap DPI exceeds the maximum DPI (allow 4 pixel rounding tolerance)
if( ( ( fBmpPixelX > ( fMaxPixelX + 4 ) ) ||
@@ -460,8 +465,8 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa
if ( nMaxBmpDPI > i_rContext.m_nMaxImageResolution )
nMaxBmpDPI = i_rContext.m_nMaxImageResolution;
}
- const sal_Int32 nPixelX = static_cast<sal_Int32>(static_cast<double>(aDstSizeTwip.Width()) * static_cast<double>(nMaxBmpDPI) / 1440.0);
- const sal_Int32 nPixelY = static_cast<sal_Int32>(static_cast<double>(aDstSizeTwip.Height()) * static_cast<double>(nMaxBmpDPI) / 1440.0);
+ const sal_Int32 nPixelX = o3tl::convert<double>(aDstSizeTwip.Width(), o3tl::Length::twip, o3tl::Length::in) * nMaxBmpDPI;
+ const sal_Int32 nPixelY = o3tl::convert<double>(aDstSizeTwip.Height(), o3tl::Length::twip, o3tl::Length::in) * nMaxBmpDPI;
if ( nPixelX && nPixelY )
{
Size aDstSizePixel( nPixelX, nPixelY );
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index c69938b11878..6c93084f0062 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -46,6 +46,7 @@
#include <tools/helpers.hxx>
#include <tools/debug.hxx>
#include <rtl/math.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <vcl/dibtools.hxx>
#include <tools/stream.hxx>
@@ -216,8 +217,12 @@ Bitmap OutputDevice::GetDownsampledBitmap( const Size& rDstSz,
const Size aBmpSize( aBmp.GetSizePixel() );
const double fBmpPixelX = aBmpSize.Width();
const double fBmpPixelY = aBmpSize.Height();
- const double fMaxPixelX = aDstSizeTwip.Width() * nMaxBmpDPIX / 1440.0;
- const double fMaxPixelY = aDstSizeTwip.Height() * nMaxBmpDPIY / 1440.0;
+ const double fMaxPixelX
+ = o3tl::convert<double>(aDstSizeTwip.Width(), o3tl::Length::twip, o3tl::Length::in)
+ * nMaxBmpDPIX;
+ const double fMaxPixelY
+ = o3tl::convert<double>(aDstSizeTwip.Height(), o3tl::Length::twip, o3tl::Length::in)
+ * nMaxBmpDPIY;
// check, if the bitmap DPI exceeds the maximum DPI (allow 4 pixel rounding tolerance)
if( ( ( fBmpPixelX > ( fMaxPixelX + 4 ) ) ||
diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx
index 09ae63b0174d..e899fdc96fa4 100644
--- a/vcl/source/outdev/map.cxx
+++ b/vcl/source/outdev/map.cxx
@@ -33,14 +33,7 @@
#include <outdev.h>
#include <basegfx/matrix/b2dhommatrix.hxx>
-#include <o3tl/enumarray.hxx>
-
-// we don't actually handle units beyond, hence the zeros in the arrays
-const MapUnit s_MaxValidUnit = MapUnit::MapPixel;
-const o3tl::enumarray<MapUnit,tools::Long> aImplNumeratorAry =
- { 1, 1, 5, 50, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 };
-const o3tl::enumarray<MapUnit,tools::Long> aImplDenominatorAry =
- { 2540, 254, 127, 127, 1000, 100, 10, 1, 72, 1440, 1, 0, 0, 0 };
+#include <tools/UnitConversion.hxx>
/*
Reduces accuracy until it is a fraction (should become
@@ -82,6 +75,13 @@ static Fraction ImplMakeFraction( tools::Long nN1, tools::Long nN2, tools::Long
return aF;
}
+static auto setMapRes(ImplMapRes& rMapRes, const o3tl::Length eUnit)
+{
+ const auto [nNum, nDen] = o3tl::getConversionMulDiv(eUnit, o3tl::Length::in);
+ rMapRes.mnMapScNumX = rMapRes.mnMapScNumY = nNum;
+ rMapRes.mnMapScDenomX = rMapRes.mnMapScDenomY = nDen;
+};
+
static void ImplCalcMapResolution( const MapMode& rMapMode,
tools::Long nDPIX, tools::Long nDPIY, ImplMapRes& rMapRes )
{
@@ -90,64 +90,34 @@ static void ImplCalcMapResolution( const MapMode& rMapMode,
case MapUnit::MapRelative:
break;
case MapUnit::Map100thMM:
- rMapRes.mnMapScNumX = 1;
- rMapRes.mnMapScDenomX = 2540;
- rMapRes.mnMapScNumY = 1;
- rMapRes.mnMapScDenomY = 2540;
+ setMapRes(rMapRes, o3tl::Length::mm100);
break;
case MapUnit::Map10thMM:
- rMapRes.mnMapScNumX = 1;
- rMapRes.mnMapScDenomX = 254;
- rMapRes.mnMapScNumY = 1;
- rMapRes.mnMapScDenomY = 254;
+ setMapRes(rMapRes, o3tl::Length::mm10);
break;
case MapUnit::MapMM:
- rMapRes.mnMapScNumX = 5; // 10
- rMapRes.mnMapScDenomX = 127; // 254
- rMapRes.mnMapScNumY = 5; // 10
- rMapRes.mnMapScDenomY = 127; // 254
+ setMapRes(rMapRes, o3tl::Length::mm);
break;
case MapUnit::MapCM:
- rMapRes.mnMapScNumX = 50; // 100
- rMapRes.mnMapScDenomX = 127; // 254
- rMapRes.mnMapScNumY = 50; // 100
- rMapRes.mnMapScDenomY = 127; // 254
+ setMapRes(rMapRes, o3tl::Length::cm);
break;
case MapUnit::Map1000thInch:
- rMapRes.mnMapScNumX = 1;
- rMapRes.mnMapScDenomX = 1000;
- rMapRes.mnMapScNumY = 1;
- rMapRes.mnMapScDenomY = 1000;
+ setMapRes(rMapRes, o3tl::Length::in1000);
break;
case MapUnit::Map100thInch:
- rMapRes.mnMapScNumX = 1;
- rMapRes.mnMapScDenomX = 100;
- rMapRes.mnMapScNumY = 1;
- rMapRes.mnMapScDenomY = 100;
+ setMapRes(rMapRes, o3tl::Length::in100);
break;
case MapUnit::Map10thInch:
- rMapRes.mnMapScNumX = 1;
- rMapRes.mnMapScDenomX = 10;
- rMapRes.mnMapScNumY = 1;
- rMapRes.mnMapScDenomY = 10;
+ setMapRes(rMapRes, o3tl::Length::in10);
break;
case MapUnit::MapInch:
- rMapRes.mnMapScNumX = 1;
- rMapRes.mnMapScDenomX = 1;
- rMapRes.mnMapScNumY = 1;
- rMapRes.mnMapScDenomY = 1;
+ setMapRes(rMapRes, o3tl::Length::in);
break;
case MapUnit::MapPoint:
- rMapRes.mnMapScNumX = 1;
- rMapRes.mnMapScDenomX = 72;
- rMapRes.mnMapScNumY = 1;
- rMapRes.mnMapScDenomY = 72;
+ setMapRes(rMapRes, o3tl::Length::pt);
break;
case MapUnit::MapTwip:
- rMapRes.mnMapScNumX = 1;
- rMapRes.mnMapScDenomX = 1440;
- rMapRes.mnMapScNumY = 1;
- rMapRes.mnMapScDenomY = 1440;
+ setMapRes(rMapRes, o3tl::Length::twip);
break;
case MapUnit::MapPixel:
rMapRes.mnMapScNumX = 1;
@@ -701,8 +671,10 @@ void OutputDevice::SetRelativeMapMode( const MapMode& rNewMapMode )
}
else
{
- Fraction aF( aImplNumeratorAry[eNew] * aImplDenominatorAry[eOld],
- aImplNumeratorAry[eOld] * aImplDenominatorAry[eNew] );
+ const auto eFrom = MapToO3tlLength(eOld, o3tl::Length::in);
+ const auto eTo = MapToO3tlLength(eNew, o3tl::Length::in);
+ const auto& [nNum, nDen] = o3tl::getConversionMulDiv(eFrom, eTo);
+ Fraction aF(nNum, nDen);
// a?F = a?F * aF
aXF = ImplMakeFraction( aXF.GetNumerator(), aF.GetNumerator(),
@@ -1322,22 +1294,25 @@ static void verifyUnitSourceDest( MapUnit eUnitSource, MapUnit eUnitDest )
"Destination MapUnit is not permitted" );
}
-#define ENTER3( eUnitSource, eUnitDest ) \
- tools::Long nNumerator = 1; \
- tools::Long nDenominator = 1; \
- SAL_WARN_IF( eUnitSource > s_MaxValidUnit, "vcl.gdi", "Invalid source map unit"); \
- SAL_WARN_IF( eUnitDest > s_MaxValidUnit, "vcl.gdi", "Invalid destination map unit"); \
- if( (eUnitSource <= s_MaxValidUnit) && (eUnitDest <= s_MaxValidUnit) ) \
- { \
- nNumerator = aImplNumeratorAry[eUnitSource] * \
- aImplDenominatorAry[eUnitDest]; \
- nDenominator = aImplNumeratorAry[eUnitDest] * \
- aImplDenominatorAry[eUnitSource]; \
- } \
- if ( eUnitSource == MapUnit::MapPixel ) \
- nDenominator *= 72; \
- else if( eUnitDest == MapUnit::MapPixel ) \
- nNumerator *= 72
+namespace
+{
+auto getCorrectedUnit(MapUnit eMapSrc, MapUnit eMapDst)
+{
+ o3tl::Length eSrc = o3tl::Length::invalid;
+ o3tl::Length eDst = o3tl::Length::invalid;
+ if (eMapSrc > MapUnit::MapPixel)
+ SAL_WARN("vcl.gdi", "Invalid source map unit");
+ else if (eMapDst > MapUnit::MapPixel)
+ SAL_WARN("vcl.gdi", "Invalid destination map unit");
+ else if (eMapSrc != eMapDst)
+ {
+ // Here 72 PPI is assumed for MapPixel
+ eSrc = MapToO3tlLength(eMapSrc, o3tl::Length::pt);
+ eDst = MapToO3tlLength(eMapDst, o3tl::Length::pt);
+ }
+ return std::make_pair(eSrc, eDst);
+}
+}
#define ENTER4( rMapModeSource, rMapModeDest ) \
ImplMapRes aMapResSource; \
@@ -1464,13 +1439,15 @@ static tools::Long fn5( const tools::Long n1,
} // of else
}
-// return (n1 * n2) / n3
-static tools::Long fn3( const tools::Long n1, const tools::Long n2, const tools::Long n3 )
+static tools::Long fn3(const tools::Long n1, const o3tl::Length eFrom, const o3tl::Length eTo)
{
- if ( n1 == 0 || n2 == 0 || n3 == 0 )
+ if (n1 == 0 || eFrom == o3tl::Length::invalid || eTo == o3tl::Length::invalid)
return 0;
- if (std::numeric_limits<tools::Long>::max() / std::abs(n1) < std::abs(n2))
+ bool bOverflow;
+ const auto nResult = o3tl::convert(n1, eFrom, eTo, bOverflow);
+ if (bOverflow)
{
+ const auto& [n2, n3] = o3tl::getConversionMulDiv(eFrom, eTo);
BigInt a4 = n1;
a4 *= n2;
@@ -1483,20 +1460,7 @@ static tools::Long fn3( const tools::Long n1, const tools::Long n2, const tools:
return static_cast<tools::Long>(a4);
} // of if
else
- {
- tools::Long n4 = n1 * n2;
- const tools::Long n3_2 = n3 / 2;
-
- if( n4 < 0 )
- {
- if ((n4 - std::numeric_limits<tools::Long>::min()) >= n3_2)
- n4 -= n3_2;
- }
- else if ((std::numeric_limits<tools::Long>::max() - n4) >= n3_2)
- n4 += n3_2;
-
- return n4 / n3;
- } // of else
+ return nResult;
}
Point OutputDevice::LogicToLogic( const Point& rPtSource,
@@ -1566,10 +1530,8 @@ Point OutputDevice::LogicToLogic( const Point& rPtSource,
if (rMapModeSource.IsSimple() && rMapModeDest.IsSimple())
{
- ENTER3( eUnitSource, eUnitDest );
-
- return Point( fn3( rPtSource.X(), nNumerator, nDenominator ),
- fn3( rPtSource.Y(), nNumerator, nDenominator ) );
+ const auto& [eFrom, eTo] = getCorrectedUnit(eUnitSource, eUnitDest);
+ return Point(fn3(rPtSource.X(), eFrom, eTo), fn3(rPtSource.Y(), eFrom, eTo));
}
else
{
@@ -1599,10 +1561,8 @@ Size OutputDevice::LogicToLogic( const Size& rSzSource,
if (rMapModeSource.IsSimple() && rMapModeDest.IsSimple())
{
- ENTER3( eUnitSource, eUnitDest );
-
- return Size( fn3( rSzSource.Width(), nNumerator, nDenominator ),
- fn3( rSzSource.Height(), nNumerator, nDenominator ) );
+ const auto& [eFrom, eTo] = getCorrectedUnit(eUnitSource, eUnitDest);
+ return Size(fn3(rSzSource.Width(), eFrom, eTo), fn3(rSzSource.Height(), eFrom, eTo));
}
else
{
@@ -1648,9 +1608,10 @@ basegfx::B2DHomMatrix OutputDevice::LogicToLogic(const MapMode& rMapModeSource,
if (rMapModeSource.IsSimple() && rMapModeDest.IsSimple())
{
- ENTER3(eUnitSource, eUnitDest);
-
- const double fScaleFactor(static_cast<double>(nNumerator) / static_cast<double>(nDenominator));
+ const auto& [eFrom, eTo] = getCorrectedUnit(eUnitSource, eUnitDest);
+ const double fScaleFactor(eFrom == o3tl::Length::invalid || eTo == o3tl::Length::invalid
+ ? std::numeric_limits<double>::quiet_NaN()
+ : o3tl::convert(1.0, eFrom, eTo));
aTransform.set(0, 0, fScaleFactor);
aTransform.set(1, 1, fScaleFactor);
}
@@ -1685,15 +1646,15 @@ tools::Rectangle OutputDevice::LogicToLogic( const tools::Rectangle& rRectSource
if (rMapModeSource.IsSimple() && rMapModeDest.IsSimple())
{
- ENTER3( eUnitSource, eUnitDest );
+ const auto& [eFrom, eTo] = getCorrectedUnit(eUnitSource, eUnitDest);
- auto left = fn3( rRectSource.Left(), nNumerator, nDenominator );
- auto top = fn3( rRectSource.Top(), nNumerator, nDenominator );
+ auto left = fn3(rRectSource.Left(), eFrom, eTo);
+ auto top = fn3(rRectSource.Top(), eFrom, eTo);
if (rRectSource.IsEmpty())
return tools::Rectangle( left, top );
- auto right = fn3( rRectSource.Right(), nNumerator, nDenominator );
- auto bottom = fn3( rRectSource.Bottom(), nNumerator, nDenominator );
+ auto right = fn3(rRectSource.Right(), eFrom, eTo);
+ auto bottom = fn3(rRectSource.Bottom(), eFrom, eTo);
return tools::Rectangle(left, top, right, bottom);
}
else
@@ -1730,9 +1691,8 @@ tools::Long OutputDevice::LogicToLogic( tools::Long nLongSource,
return nLongSource;
verifyUnitSourceDest( eUnitSource, eUnitDest );
- ENTER3( eUnitSource, eUnitDest );
-
- return fn3( nLongSource, nNumerator, nDenominator );
+ const auto& [eFrom, eTo] = getCorrectedUnit(eUnitSource, eUnitDest);
+ return fn3(nLongSource, eFrom, eTo);
}
void OutputDevice::SetPixelOffset( const Size& rOffset )