summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-02-19 08:46:10 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-02-19 07:27:34 +0100
commitce671c2275195f7545366ec9a11100c105ac366b (patch)
tree75f2eba6d1640ba3d43f6abd41333f59709bca2d /svx
parent409a9dbc04c4b98a3f9ca81618906b16937ff2f0 (diff)
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.kaganski@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/svdraw/svdopath.cxx5
-rw-r--r--svx/source/table/viewcontactoftableobj.cxx4
-rw-r--r--svx/source/unodraw/unoshape.cxx142
3 files changed, 61 insertions, 90 deletions
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!");
}
}