diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-11-11 10:27:23 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-11-11 10:18:07 +0100 |
commit | 4cdca3702cda246ecc490c65973e525ff5cf25ab (patch) | |
tree | bb40f5ece57a5913c5b8f052bbd7c0244fc1f1d7 /svgio | |
parent | 1ef0261539ca6ee8ad9f43d91536c9caa4f7ea53 (diff) |
Use o3tl::convert
Change-Id: I62239252efed514de7db88b4bea6f4d4d719fb17
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125021
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'svgio')
-rw-r--r-- | svgio/inc/SvgNumber.hxx | 13 | ||||
-rw-r--r-- | svgio/source/svgreader/SvgNumber.cxx | 16 | ||||
-rw-r--r-- | svgio/source/svgreader/svgstyleattributes.cxx | 6 | ||||
-rw-r--r-- | svgio/source/svgreader/svgsvgnode.cxx | 6 |
4 files changed, 20 insertions, 21 deletions
diff --git a/svgio/inc/SvgNumber.hxx b/svgio/inc/SvgNumber.hxx index 9b6907a02031..4d03335cf424 100644 --- a/svgio/inc/SvgNumber.hxx +++ b/svgio/inc/SvgNumber.hxx @@ -25,9 +25,6 @@ namespace svgio::svgreader { -// recommended value for this device dependent unit, see CSS2 section 4.3.2 Lengths -constexpr const double F_SVG_PIXEL_PER_INCH = 96.0; - enum class NumberType { xcoordinate, @@ -52,11 +49,11 @@ enum class SvgUnit ex, // relative to current x-height px, // 'user unit' - pt, // points, 1.25 px - pc, // 15.0 px - cm, // 35.43307 px - mm, // 3.543307 px - in, // 90 px + pt, // points, 1/72 in + pc, // 1/6 in + cm, + mm, + in, percent, // relative to range none // for stroke-miterlimit, which has no unit diff --git a/svgio/source/svgreader/SvgNumber.cxx b/svgio/source/svgreader/SvgNumber.cxx index 9a11c1979962..d5cd9b819ff2 100644 --- a/svgio/source/svgreader/SvgNumber.cxx +++ b/svgio/source/svgreader/SvgNumber.cxx @@ -18,6 +18,8 @@ */ #include <svgtools.hxx> + +#include <o3tl/unit_conversion.hxx> #include <sal/log.hxx> namespace svgio::svgreader @@ -40,15 +42,15 @@ double SvgNumber::solveNonPercentage(const InfoProvider& rInfoProvider) const case SvgUnit::px: return mfNumber; case SvgUnit::pt: - return mfNumber * F_SVG_PIXEL_PER_INCH / 72.0; + return o3tl::convert(mfNumber, o3tl::Length::pt, o3tl::Length::px); case SvgUnit::pc: - return mfNumber * F_SVG_PIXEL_PER_INCH / 6.0; + return o3tl::convert(mfNumber, o3tl::Length::pc, o3tl::Length::px); case SvgUnit::cm: - return mfNumber * F_SVG_PIXEL_PER_INCH / 2.54; + return o3tl::convert(mfNumber, o3tl::Length::cm, o3tl::Length::px); case SvgUnit::mm: - return mfNumber * 0.1 * F_SVG_PIXEL_PER_INCH / 2.54; + return o3tl::convert(mfNumber, o3tl::Length::mm, o3tl::Length::px); case SvgUnit::in: - return mfNumber * F_SVG_PIXEL_PER_INCH; + return o3tl::convert(mfNumber, o3tl::Length::in, o3tl::Length::px); case SvgUnit::none: { SAL_WARN("svgio", "Design error, this case should have been handled in the caller"); @@ -84,8 +86,8 @@ double SvgNumber::solve(const InfoProvider& rInfoProvider, NumberType aNumberTyp aViewPort = basegfx::B2DRange( 0.0, 0.0, - 210.0 * F_SVG_PIXEL_PER_INCH / 2.54, - 297.0 * F_SVG_PIXEL_PER_INCH / 2.54); + o3tl::convert(210.0, o3tl::Length::cm, o3tl::Length::px), // should it be mm? + o3tl::convert(297.0, o3tl::Length::cm, o3tl::Length::px)); } diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index 8a61d2e9dfe6..e7a0d90b7efc 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -43,6 +43,7 @@ #include <basegfx/polygon/b2dpolygontools.hxx> #include <drawinglayer/primitive2d/maskprimitive2d.hxx> #include <drawinglayer/primitive2d/pagehierarchyprimitive2d.hxx> +#include <o3tl/unit_conversion.hxx> const int nStyleDepthLimit = 1024; @@ -2494,9 +2495,8 @@ namespace svgio::svgreader SvgNumber SvgStyleAttributes::getFontSizeNumber() const { - // default size is 'medium' or 16px, which is equal to the default PPI used in svgio ( 96.0 ) - // converted to pixels - const double aDefaultSize = F_SVG_PIXEL_PER_INCH / 6.0; + // default size is 'medium', i.e. 12 pt, or 16px + constexpr double aDefaultSize = o3tl::convert(12.0, o3tl::Length::pt, o3tl::Length::px); if(maFontSizeNumber.isSet()) { diff --git a/svgio/source/svgreader/svgsvgnode.cxx b/svgio/source/svgreader/svgsvgnode.cxx index 027f9e505ae7..7132c2e6d7bc 100644 --- a/svgio/source/svgreader/svgsvgnode.cxx +++ b/svgio/source/svgreader/svgsvgnode.cxx @@ -26,6 +26,7 @@ #include <basegfx/matrix/b2dhommatrixtools.hxx> #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx> +#include <o3tl/unit_conversion.hxx> #include <svgdocument.hxx> namespace svgio::svgreader @@ -677,9 +678,8 @@ namespace svgio::svgreader if(bEmbedInFinalTransformPxTo100ThMM) { // embed in transform primitive to scale to 1/100th mm - // where 1 inch == 25.4 mm to get from Svg coordinates (px) to - // drawinglayer coordinates - const double fScaleTo100thmm(25.4 * 100.0 / F_SVG_PIXEL_PER_INCH); + // to get from Svg coordinates (px) to drawinglayer coordinates + constexpr double fScaleTo100thmm(o3tl::convert(1.0, o3tl::Length::px, o3tl::Length::mm100)); const basegfx::B2DHomMatrix aTransform( basegfx::utils::createScaleB2DHomMatrix( fScaleTo100thmm, |