drawinglayer/source/tools/wmfemfhelper.cxx | 34 +----- svx/source/svdraw/svdopath.cxx | 5 - svx/source/table/viewcontactoftableobj.cxx | 4 svx/source/unodraw/unoshape.cxx | 142 +++++++++++------------------ 4 files changed, 69 insertions(+), 116 deletions(-)
New commits: commit ce671c2275195f7545366ec9a11100c105ac366b Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Feb 19 08:46:10 2021 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Feb 19 07:27:34 2021 +0100 Some more unit conversion unification Change-Id: I8f0afb93ffb8bd1b88efca802fad5e9aeb447021 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111168 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/drawinglayer/source/tools/wmfemfhelper.cxx b/drawinglayer/source/tools/wmfemfhelper.cxx index f5a171b9e204..f287e2a4e23c 100644 --- a/drawinglayer/source/tools/wmfemfhelper.cxx +++ b/drawinglayer/source/tools/wmfemfhelper.cxx @@ -47,6 +47,7 @@ #include <sal/log.hxx> #include <tools/fract.hxx> #include <tools/stream.hxx> +#include <tools/UnitConversion.hxx> #include <vcl/canvastools.hxx> #include <vcl/gradient.hxx> #include <vcl/hatch.hxx> @@ -2523,34 +2524,15 @@ namespace wmfemfhelper } else { - switch(rMapMode.GetMapUnit()) + const auto eFrom = MapToO3tlLength(rPropertyHolders.Current().getMapUnit()), + eTo = MapToO3tlLength(rMapMode.GetMapUnit()); + if (eFrom != o3tl::Length::invalid && eTo != o3tl::Length::invalid) { - case MapUnit::Map100thMM : - { - if(MapUnit::MapTwip == rPropertyHolders.Current().getMapUnit()) - { - // MapUnit::MapTwip -> MapUnit::Map100thMM - const double fTwipTo100thMm(127.0 / 72.0); - aMapping.scale(fTwipTo100thMm, fTwipTo100thMm); - } - break; - } - case MapUnit::MapTwip : - { - if(MapUnit::Map100thMM == rPropertyHolders.Current().getMapUnit()) - { - // MapUnit::Map100thMM -> MapUnit::MapTwip - const double f100thMmToTwip(72.0 / 127.0); - aMapping.scale(f100thMmToTwip, f100thMmToTwip); - } - break; - } - default : - { - OSL_FAIL("implInterpretMetafile: MetaActionType::MAPMODE with unsupported MapUnit (!)"); - break; - } + const double fConvert(o3tl::convert(1.0, eFrom, eTo)); + aMapping.scale(fConvert, fConvert); } + else + OSL_FAIL("implInterpretMetafile: MetaActionType::MAPMODE with unsupported MapUnit (!)"); aMapping = getTransformFromMapMode(rMapMode) * aMapping; rPropertyHolders.Current().setMapUnit(rMapMode.GetMapUnit()); diff --git a/svx/source/svdraw/svdopath.cxx b/svx/source/svdraw/svdopath.cxx index aea01d2d279d..c3b1995e2b16 100644 --- a/svx/source/svdraw/svdopath.cxx +++ b/svx/source/svdraw/svdopath.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <o3tl/unit_conversion.hxx> #include <tools/bigint.hxx> #include <tools/helpers.hxx> #include <rtl/ustrbuf.hxx> @@ -2935,8 +2936,8 @@ void SdrPathObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const b // is no length but only a factor here. Convert back. if (getSdrModelFromSdrObject().IsWriter()) { - aScale.setX(aScale.getX() * 127.0 / 72.0); - aScale.setY(aScale.getY() * 127.0 / 72.0); + aScale.setX(o3tl::convert(aScale.getX(), o3tl::Length::twip, o3tl::Length::mm100)); + aScale.setY(o3tl::convert(aScale.getY(), o3tl::Length::twip, o3tl::Length::mm100)); } fScaleX *= fabs(aScale.getX()); fScaleY *= fabs(aScale.getY()); diff --git a/svx/source/table/viewcontactoftableobj.cxx b/svx/source/table/viewcontactoftableobj.cxx index 56f68c0f7781..967bfe820738 100644 --- a/svx/source/table/viewcontactoftableobj.cxx +++ b/svx/source/table/viewcontactoftableobj.cxx @@ -38,6 +38,7 @@ #include <svx/framelinkarray.hxx> #include <svx/sdooitm.hxx> #include <vcl/canvastools.hxx> +#include <o3tl/unit_conversion.hxx> #include <cell.hxx> #include "tablelayouter.hxx" @@ -186,7 +187,8 @@ namespace sdr::contact aLine.SetMirrorWidths( ); } - const double fTwipsToMM(127.0 / 72.0); + constexpr double fTwipsToMM( + o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::mm100)); return svx::frame::Style(&aLine, fTwipsToMM); } } diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx index c44d3e62daa6..965df6b63cbd 100644 --- a/svx/source/unodraw/unoshape.cxx +++ b/svx/source/unodraw/unoshape.cxx @@ -461,18 +461,14 @@ void SvxShape::ForceMetricToItemPoolMetric(Pair& rPoint) const throw() if(eMapUnit == MapUnit::Map100thMM) return; - switch(eMapUnit) + if (const auto eTo = MapToO3tlLength(eMapUnit); eTo != o3tl::Length::invalid) { - case MapUnit::MapTwip : - { - rPoint.A() = convertMm100ToTwip(rPoint.A()); - rPoint.B() = convertMm100ToTwip(rPoint.B()); - break; - } - default: - { - OSL_FAIL("AW: Missing unit translation to PoolMetric!"); - } + rPoint.A() = o3tl::convert(rPoint.A(), o3tl::Length::mm100, eTo); + rPoint.B() = o3tl::convert(rPoint.B(), o3tl::Length::mm100, eTo); + } + else + { + OSL_FAIL("AW: Missing unit translation to PoolMetric!"); } } @@ -486,21 +482,14 @@ void SvxShape::ForceMetricToItemPoolMetric(basegfx::B2DPolyPolygon& rPolyPolygon if(eMapUnit == MapUnit::Map100thMM) return; - switch(eMapUnit) + if (const auto eTo = MapToO3tlLength(eMapUnit); eTo != o3tl::Length::invalid) { - case MapUnit::MapTwip : - { - basegfx::B2DHomMatrix aTransform; - const double fMMToTWIPS(72.0 / 127.0); - - aTransform.scale(fMMToTWIPS, fMMToTWIPS); - rPolyPolygon.transform(aTransform); - break; - } - default: - { - OSL_FAIL("Missing unit translation to PoolMetric!"); - } + const double fConvert(o3tl::convert(1.0, o3tl::Length::mm100, eTo)); + rPolyPolygon.transform(basegfx::utils::createScaleB2DHomMatrix(fConvert, fConvert)); + } + else + { + OSL_FAIL("Missing unit translation to PoolMetric!"); } } @@ -514,108 +503,87 @@ void SvxShape::ForceMetricToItemPoolMetric(basegfx::B2DHomMatrix& rB2DHomMatrix) if(eMapUnit == MapUnit::Map100thMM) return; - switch(eMapUnit) + if (const auto eTo = MapToO3tlLength(eMapUnit); eTo != o3tl::Length::invalid) { - case MapUnit::MapTwip : - { - const double fMMToTWIPS(72.0 / 127.0); - const basegfx::utils::B2DHomMatrixBufferedDecompose aDecomposedTransform(rB2DHomMatrix); - rB2DHomMatrix = basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix( - aDecomposedTransform.getScale() * fMMToTWIPS, - aDecomposedTransform.getShearX(), - aDecomposedTransform.getRotate(), - aDecomposedTransform.getTranslate() * fMMToTWIPS); - break; - } - default: - { - OSL_FAIL("Missing unit translation to PoolMetric!"); - } + const double fConvert(o3tl::convert(1.0, o3tl::Length::mm100, eTo)); + const basegfx::utils::B2DHomMatrixBufferedDecompose aDecomposedTransform(rB2DHomMatrix); + rB2DHomMatrix = basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix( + aDecomposedTransform.getScale() * fConvert, + aDecomposedTransform.getShearX(), + aDecomposedTransform.getRotate(), + aDecomposedTransform.getTranslate() * fConvert); + } + else + { + OSL_FAIL("Missing unit translation to PoolMetric!"); } } void SvxShape::ForceMetricTo100th_mm(Pair& rPoint) const throw() { DBG_TESTSOLARMUTEX(); - MapUnit eMapUnit = MapUnit::Map100thMM; if(!HasSdrObject()) return; - eMapUnit = GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetMetric(0); + MapUnit eMapUnit = GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetMetric(0); if(eMapUnit == MapUnit::Map100thMM) return; - switch(eMapUnit) + if (const auto eFrom = MapToO3tlLength(eMapUnit); eFrom != o3tl::Length::invalid) { - case MapUnit::MapTwip : - { - rPoint.A() = convertTwipToMm100(rPoint.A()); - rPoint.B() = convertTwipToMm100(rPoint.B()); - break; - } - default: - { - OSL_FAIL("AW: Missing unit translation to 100th mm!"); - } + rPoint.A() = o3tl::convert(rPoint.A(), eFrom, o3tl::Length::mm100); + rPoint.B() = o3tl::convert(rPoint.B(), eFrom, o3tl::Length::mm100); + } + else + { + OSL_FAIL("AW: Missing unit translation to 100th mm!"); } } void SvxShape::ForceMetricTo100th_mm(basegfx::B2DPolyPolygon& rPolyPolygon) const throw() { DBG_TESTSOLARMUTEX(); - MapUnit eMapUnit = MapUnit::Map100thMM; if(!HasSdrObject()) return; - eMapUnit = GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetMetric(0); + MapUnit eMapUnit = GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetMetric(0); if(eMapUnit == MapUnit::Map100thMM) return; - switch(eMapUnit) + if (const auto eFrom = MapToO3tlLength(eMapUnit); eFrom != o3tl::Length::invalid) { - case MapUnit::MapTwip : - { - basegfx::B2DHomMatrix aTransform; - const double fTWIPSToMM(127.0 / 72.0); - aTransform.scale(fTWIPSToMM, fTWIPSToMM); - rPolyPolygon.transform(aTransform); - break; - } - default: - { - OSL_FAIL("Missing unit translation to 100th mm!"); - } + const double fConvert(o3tl::convert(1.0, eFrom, o3tl::Length::mm100)); + rPolyPolygon.transform(basegfx::utils::createScaleB2DHomMatrix(fConvert, fConvert)); + } + else + { + OSL_FAIL("Missing unit translation to 100th mm!"); } } void SvxShape::ForceMetricTo100th_mm(basegfx::B2DHomMatrix& rB2DHomMatrix) const throw() { DBG_TESTSOLARMUTEX(); - MapUnit eMapUnit = MapUnit::Map100thMM; if(!HasSdrObject()) return; - eMapUnit = GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetMetric(0); + MapUnit eMapUnit = GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetMetric(0); if(eMapUnit == MapUnit::Map100thMM) return; - switch(eMapUnit) + if (const auto eFrom = MapToO3tlLength(eMapUnit); eFrom != o3tl::Length::invalid) { - case MapUnit::MapTwip : - { - const double fTWIPSToMM(127.0 / 72.0); - const basegfx::utils::B2DHomMatrixBufferedDecompose aDecomposedTransform(rB2DHomMatrix); - rB2DHomMatrix = basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix( - aDecomposedTransform.getScale() * fTWIPSToMM, - aDecomposedTransform.getShearX(), - aDecomposedTransform.getRotate(), - aDecomposedTransform.getTranslate() * fTWIPSToMM); - break; - } - default: - { - OSL_FAIL("Missing unit translation to 100th mm!"); - } + const double fConvert(o3tl::convert(1.0, eFrom, o3tl::Length::mm100)); + const basegfx::utils::B2DHomMatrixBufferedDecompose aDecomposedTransform(rB2DHomMatrix); + rB2DHomMatrix = basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix( + aDecomposedTransform.getScale() * fConvert, + aDecomposedTransform.getShearX(), + aDecomposedTransform.getRotate(), + aDecomposedTransform.getTranslate() * fConvert); + } + else + { + OSL_FAIL("Missing unit translation to 100th mm!"); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits