summaryrefslogtreecommitdiff
path: root/emfio
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-11-10 00:25:38 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-11-10 07:30:35 +0100
commit40e6ae66b893b86bdda7d414b4bd58bfc612566f (patch)
tree3d14d7e0dc3e5af1a311b32502769482e1b5f703 /emfio
parent41b4053d7a395146a488c4aba0bc17b98b0a9502 (diff)
Simplify MtfTools::ImplMap
Use o3tl::convert instead of homemade constants; unify logic and move common code out of the switch. Change-Id: I31e53d04017aac7d6a2f435adb9233b9c0e3ba6e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124939 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'emfio')
-rw-r--r--emfio/inc/mtftools.hxx2
-rw-r--r--emfio/source/reader/mtftools.cxx100
2 files changed, 30 insertions, 72 deletions
diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index 3bae0285a9bc..8e3ccba65b84 100644
--- a/emfio/inc/mtftools.hxx
+++ b/emfio/inc/mtftools.hxx
@@ -259,8 +259,6 @@ namespace emfio
//Scalar constants
#define UNDOCUMENTED_WIN_RCL_RELATION 32
#define MS_FIXPOINT_BITCOUNT_28_4 4
-#define HUNDREDTH_MILLIMETERS_PER_MILLIINCH 2.54
-#define MILLIINCH_PER_TWIPS 1.44
class MetaFontAction;
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index b98fa7c11d19..204a598d4550 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -519,84 +519,38 @@ namespace emfio
if ( mnGfxMode == GM_COMPATIBLE )
{
+ fX2 -= mnWinOrgX;
+ fY2 -= mnWinOrgY;
+
switch( mnMapMode )
{
case MM_LOENGLISH :
{
- fX2 -= mnWinOrgX;
- fY2 = mnWinOrgY-fY2;
- fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH * 10;
- fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH * 10;
- double nDevOrgX = mnDevOrgX;
- if (mnPixX)
- nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
- fX2 += nDevOrgX;
- double nDevOrgY = mnDevOrgY;
- if (mnPixY)
- nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
- fY2 += nDevOrgY;
+ fX2 = o3tl::convert(fX2, o3tl::Length::in100, o3tl::Length::mm100);
+ fY2 = o3tl::convert(-fY2, o3tl::Length::in100, o3tl::Length::mm100);
}
break;
case MM_HIENGLISH :
{
- fX2 -= mnWinOrgX;
- fY2 = mnWinOrgY-fY2;
- fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH;
- fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH;
- double nDevOrgX = mnDevOrgX;
- if (mnPixX)
- nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
- fX2 += nDevOrgX;
- double nDevOrgY = mnDevOrgY;
- if (mnPixY)
- nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
- fY2 += nDevOrgY;
+ fX2 = o3tl::convert(fX2, o3tl::Length::in1000, o3tl::Length::mm100);
+ fY2 = o3tl::convert(-fY2, o3tl::Length::in1000, o3tl::Length::mm100);
}
break;
case MM_TWIPS:
{
- fX2 -= mnWinOrgX;
- fY2 = mnWinOrgY-fY2;
- fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH / MILLIINCH_PER_TWIPS;
- fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH / MILLIINCH_PER_TWIPS;
- double nDevOrgX = mnDevOrgX;
- if (mnPixX)
- nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
- fX2 += nDevOrgX;
- double nDevOrgY = mnDevOrgY;
- if (mnPixY)
- nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
- fY2 += nDevOrgY;
+ fX2 = o3tl::convert(fX2, o3tl::Length::twip, o3tl::Length::mm100);
+ fY2 = o3tl::convert(-fY2, o3tl::Length::twip, o3tl::Length::mm100);
}
break;
case MM_LOMETRIC :
{
- fX2 -= mnWinOrgX;
- fY2 = mnWinOrgY-fY2;
- fX2 *= 10;
- fY2 *= 10;
- double nDevOrgX = mnDevOrgX;
- if (mnPixX)
- nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
- fX2 += nDevOrgX;
- double nDevOrgY = mnDevOrgY;
- if (mnPixY)
- nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
- fY2 += nDevOrgY;
+ fX2 = o3tl::convert(fX2, o3tl::Length::mm10, o3tl::Length::mm100);
+ fY2 = o3tl::convert(-fY2, o3tl::Length::mm10, o3tl::Length::mm100);
}
break;
case MM_HIMETRIC : // in hundredth of a millimeter
{
- fX2 -= mnWinOrgX;
- fY2 = mnWinOrgY-fY2;
- double nDevOrgX = mnDevOrgX;
- if (mnPixX)
- nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
- fX2 += nDevOrgX;
- double nDevOrgY = mnDevOrgY;
- if (mnPixY)
- nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
- fY2 += nDevOrgY;
+ fY2 *= -1;
}
break;
default :
@@ -608,8 +562,6 @@ namespace emfio
}
else
{
- fX2 -= mnWinOrgX;
- fY2 -= mnWinOrgY;
if ( mnMapMode != MM_TEXT )
{
fX2 /= mnWinExtX;
@@ -617,14 +569,22 @@ namespace emfio
fX2 *= mnDevWidth;
fY2 *= mnDevHeight;
}
- fX2 += mnDevOrgX;
- fY2 += mnDevOrgY; // fX2, fY2 now in device units
fX2 *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
fY2 *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
}
}
break;
}
+
+ double nDevOrgX = mnDevOrgX;
+ if (mnPixX)
+ nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
+ fX2 += nDevOrgX;
+ double nDevOrgY = mnDevOrgY;
+ if (mnPixY)
+ nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
+ fY2 += nDevOrgY;
+
fX2 -= mrclFrame.Left();
fY2 -= mrclFrame.Top();
}
@@ -667,20 +627,20 @@ namespace emfio
{
case MM_LOENGLISH :
{
- fWidth *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH*10;
- fHeight*=-HUNDREDTH_MILLIMETERS_PER_MILLIINCH*10;
+ fWidth = o3tl::convert(fWidth, o3tl::Length::in100, o3tl::Length::mm100);
+ fHeight = o3tl::convert(-fHeight, o3tl::Length::in100, o3tl::Length::mm100);
}
break;
case MM_HIENGLISH :
{
- fWidth *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH;
- fHeight*=-HUNDREDTH_MILLIMETERS_PER_MILLIINCH;
+ fWidth = o3tl::convert(fWidth, o3tl::Length::in1000, o3tl::Length::mm100);
+ fHeight = o3tl::convert(-fHeight, o3tl::Length::in1000, o3tl::Length::mm100);
}
break;
case MM_LOMETRIC :
{
- fWidth *= 10;
- fHeight*=-10;
+ fWidth = o3tl::convert(fWidth, o3tl::Length::mm10, o3tl::Length::mm100);
+ fHeight = o3tl::convert(-fHeight, o3tl::Length::mm10, o3tl::Length::mm100);
}
break;
case MM_HIMETRIC : // in hundredth of millimeters
@@ -690,8 +650,8 @@ namespace emfio
break;
case MM_TWIPS:
{
- fWidth *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH/MILLIINCH_PER_TWIPS;
- fHeight*=-HUNDREDTH_MILLIMETERS_PER_MILLIINCH/MILLIINCH_PER_TWIPS;
+ fWidth = o3tl::convert(fWidth, o3tl::Length::twip, o3tl::Length::mm100);
+ fHeight = o3tl::convert(-fHeight, o3tl::Length::twip, o3tl::Length::mm100);
}
break;
default :