From ff1cfaf87ce0aa9673e1c3f92308cde6a2c6aa69 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Wed, 17 Mar 2021 16:03:12 +0100 Subject: round polygon points before merging them for Skia drawing (tdf#140848) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit basegfx::utils::mergeToSinglePolyPolygon() appears to have rounding problems. Point coordinates are in pixels anyway. Change-Id: I9880cc32f934a08923a5c59278f6aa07852c05f9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112647 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- vcl/skia/gdiimpl.cxx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'vcl/skia') diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx index aa934f1e4942..be31e0ee649a 100644 --- a/vcl/skia/gdiimpl.cxx +++ b/vcl/skia/gdiimpl.cxx @@ -1015,6 +1015,20 @@ bool SkiaSalGraphicsImpl::delayDrawPolyPolygon(const basegfx::B2DPolyPolygon& aP return true; } +// Tdf#140848 - basegfx::utils::mergeToSinglePolyPolygon() seems to have rounding +// errors that sometimes cause it to merge incorrectly. +static void roundPolygonPoints(basegfx::B2DPolyPolygon& polyPolygon) +{ + for (basegfx::B2DPolygon& polygon : polyPolygon) + { + polygon.makeUnique(); + for (sal_uInt32 i = 0; i < polygon.count(); ++i) + polygon.setB2DPoint(i, basegfx::B2DPoint(basegfx::fround(polygon.getB2DPoint(i)))); + // Control points are saved as vectors relative to points, so hopefully + // there's no need to round those. + } +} + void SkiaSalGraphicsImpl::checkPendingDrawing() { if (mLastPolyPolygonInfo.polygons.size() != 0) @@ -1026,10 +1040,12 @@ void SkiaSalGraphicsImpl::checkPendingDrawing() if (polygons.size() == 1) performDrawPolyPolygon(polygons.front(), transparency, true); else - // TODO: tdf#136222 shows that basegfx::utils::mergeToSinglePolyPolygon() is unreliable - // in corner cases, possibly either a bug or rounding errors somewhere. + { + for (basegfx::B2DPolyPolygon& p : polygons) + roundPolygonPoints(p); performDrawPolyPolygon(basegfx::utils::mergeToSinglePolyPolygon(polygons), transparency, true); + } } } -- cgit