drawinglayer/source/tools/emfphelperdata.cxx | 34 +++++++++++++-------------- drawinglayer/source/tools/emfphelperdata.hxx | 10 ++++++- emfio/qa/cppunit/emf/EmfImportTest.cxx | 2 - hwpfilter/source/drawing.h | 1 4 files changed, 26 insertions(+), 21 deletions(-)
New commits: commit 4695d84b78d04af6682961732ae92655e03f49eb Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Apr 13 16:51:33 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat Apr 13 18:48:38 2024 +0200 Use more o3tl::convert Change-Id: Ia525e051b53dd6082f2f11ff884677c8b8c6a20c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166051 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx index 664902f9bc2d..1d95f0a8f38a 100644 --- a/drawinglayer/source/tools/emfphelperdata.cxx +++ b/drawinglayer/source/tools/emfphelperdata.cxx @@ -229,33 +229,33 @@ namespace emfplushelper { } - float EmfPlusHelperData::getUnitToPixelMultiplier(const UnitType aUnitType, const sal_uInt32 aDPI) + double EmfPlusHelperData::unitToPixel(double n, sal_uInt32 aUnitType, Direction d) { - switch (aUnitType) + switch (static_cast<UnitType>(aUnitType)) { case UnitTypePixel: - return 1.0f; + return n; case UnitTypePoint: - return aDPI / 72.0; + return o3tl::convert(n, o3tl::Length::pt, o3tl::Length::in) * DPI(d); case UnitTypeInch: - return aDPI; + return n * DPI(d); case UnitTypeMillimeter: - return aDPI / 25.4; + return o3tl::convert(n, o3tl::Length::mm, o3tl::Length::in) * DPI(d); case UnitTypeDocument: - return aDPI / 300.0; + return n * DPI(d) / 300.0; case UnitTypeWorld: case UnitTypeDisplay: SAL_WARN("drawinglayer.emf", "EMF+ Converting to World/Display."); - return 1.0f; + return n; default: SAL_WARN("drawinglayer.emf", "EMF+ TODO Unimplemented support of Unit Type: 0x" << std::hex << aUnitType); - return 1.0f; + return n; } } @@ -281,7 +281,7 @@ namespace emfplushelper EMFPPen *pen = new EMFPPen(); maEMFPObjects[index].reset(pen); pen->Read(rObjectStream, *this); - pen->penWidth = pen->penWidth * getUnitToPixelMultiplier(static_cast<UnitType>(pen->penUnit), mnHDPI); + pen->penWidth = unitToPixel(pen->penWidth, pen->penUnit, Direction::horizontal); break; } case EmfPlusObjectTypePath: @@ -325,7 +325,7 @@ namespace emfplushelper font->fontFlags = 0; font->Read(rObjectStream); // tdf#113624 Convert unit to Pixels - font->emSize = font->emSize * getUnitToPixelMultiplier(static_cast<UnitType>(font->sizeUnit), mnHDPI); + font->emSize = unitToPixel(font->emSize, font->sizeUnit, Direction::horizontal); break; } @@ -1755,8 +1755,8 @@ namespace emfplushelper } else { - mnMmX *= mfPageScale * getUnitToPixelMultiplier(static_cast<UnitType>(flags), mnHDPI); - mnMmY *= mfPageScale * getUnitToPixelMultiplier(static_cast<UnitType>(flags), mnVDPI); + mnMmX = std::round(unitToPixel(static_cast<double>(mnMmX) * mfPageScale, flags, Direction::horizontal)); + mnMmY = std::round(unitToPixel(static_cast<double>(mnMmY) * mfPageScale, flags, Direction::vertical)); mappingChanged(); } break; @@ -1853,12 +1853,12 @@ namespace emfplushelper SAL_WARN("drawinglayer.emf", "EMF+ file error. UnitTypeDisplay and UnitTypeWorld are not supported by BeginContainer in EMF+ specification."); break; } - const float aPageScaleX = getUnitToPixelMultiplier(static_cast<UnitType>(flags), mnHDPI); - const float aPageScaleY = getUnitToPixelMultiplier(static_cast<UnitType>(flags), mnVDPI); GraphicStatePush(mGSContainerStack, stackIndex); const basegfx::B2DHomMatrix transform = basegfx::utils::createScaleTranslateB2DHomMatrix( - aPageScaleX * ( dw / sw ), aPageScaleY * ( dh / sh ), - aPageScaleX * ( dx - sx ), aPageScaleY * ( dy - sy) ); + unitToPixel(static_cast<double>(dw) / sw, flags, Direction::horizontal), + unitToPixel(static_cast<double>(dh) / sh, flags, Direction::vertical), + unitToPixel(static_cast<double>(dx) - sx, flags, Direction::horizontal), + unitToPixel(static_cast<double>(dy) - sy, flags, Direction::vertical)); maWorldTransform *= transform; mappingChanged(); break; diff --git a/drawinglayer/source/tools/emfphelperdata.hxx b/drawinglayer/source/tools/emfphelperdata.hxx index cf9e3b8855d6..d2ed1008b67b 100644 --- a/drawinglayer/source/tools/emfphelperdata.hxx +++ b/drawinglayer/source/tools/emfphelperdata.hxx @@ -244,6 +244,14 @@ namespace emfplushelper // helper functions Color EMFPGetBrushColorOrARGBColor(const sal_uInt16 flags, const sal_uInt32 brushIndexOrColor) const; + enum class Direction + { + horizontal, + vertical + }; + sal_uInt32 DPI(Direction d) { return d == Direction::horizontal ? mnHDPI : mnVDPI; } + double unitToPixel(double n, sal_uInt32 aUnitType, Direction d); + public: EmfPlusHelperData( SvMemoryStream& rMS, @@ -262,8 +270,6 @@ namespace emfplushelper static void ReadRectangle(SvStream& s, float& x, float& y, float &width, float& height, bool bCompressed = false); static bool readXForm(SvStream& rIn, basegfx::B2DHomMatrix& rTarget); static ::basegfx::B2DPolyPolygon combineClip(::basegfx::B2DPolyPolygon const & leftPolygon, int combineMode, ::basegfx::B2DPolyPolygon const & rightPolygon); - - static float getUnitToPixelMultiplier(const UnitType aUnitType, const sal_uInt32 aDPI); }; } diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx index 8e9b1847fa81..da1ead889431 100644 --- a/emfio/qa/cppunit/emf/EmfImportTest.cxx +++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx @@ -353,7 +353,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDrawLine) "linecap"_ostr, "BUTT"); assertXPath(pDocument, aXPathPrefix + "mask/unifiedtransparence/polypolygonstroke/polypolygon", "path"_ostr, - "m55.5192348773662 403.573503917507 874.352660545936-345.821325648415"); + "m89.1506452315894 403.573503917507 895.170581035125-345.821325648415"); } CPPUNIT_TEST_FIXTURE(Test, testDrawLineWithCaps) diff --git a/hwpfilter/source/drawing.h b/hwpfilter/source/drawing.h index e3f2a512e7c7..e549896a5eed 100644 --- a/hwpfilter/source/drawing.h +++ b/hwpfilter/source/drawing.h @@ -491,7 +491,6 @@ int cmd, void * /*argp*/, int /*argv*/) return HWPDODefaultFunc(cmd); } -#define WTMM(x) ((double)(x) / 1800. * 25.4) static int HWPDOEllipse2Func(int /*type*/, HWPDrawingObject * hdo, int cmd, void * /*argp*/, int /*argv*/)