diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-03-11 16:52:37 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-03-12 00:38:11 +0100 |
commit | 7a6e7ed16ed57e131079ee79d06b03141117d9d7 (patch) | |
tree | a816b329dcd872f8eafb17291b8be36944e38a56 | |
parent | 8307ecbd6afd5012d46841d7bac34befea1b6d05 (diff) |
better adjustment algorithm for dynamic sized widgets
A algorithm that gives better results for dynamically sized
widgets is to increase proportionally only the points in shapes
that are over the half of the widget width (or height, when
adjusting the other dimension). This preserves the margins and
doesn't distort the shape of the paths, which is especially
visible when the source needs to be largely resized in one
dimension only.
Change-Id: I2cceb249063387c0f7400ef8d75adb5899aa8c23
Reviewed-on: https://gerrit.libreoffice.org/69056
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 897f6f6252f38e93764aa0e72135768ab1ec3679)
-rw-r--r-- | vcl/source/gdi/FileDefinitionWidgetDraw.cxx | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx index ae303d966897..a15010014aa4 100644 --- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx +++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx @@ -168,24 +168,18 @@ void drawFromDrawCommands(gfx::DrawRoot const& rDrawRoot, SalGraphics& rGraphics basegfx::B2DRange aInputRectangle(rRectangle.maRectangle); + double fDeltaX = aTargetSurface.getWidth() - aSVGRect.getWidth(); + double fDeltaY = aTargetSurface.getHeight() - aSVGRect.getHeight(); + basegfx::B2DRange aFinalRectangle( - aTargetSurface.getMinX() + aInputRectangle.getMinX(), - aTargetSurface.getMinY() + aInputRectangle.getMinY(), - aTargetSurface.getMaxX() - (aSVGRect.getMaxX() - aInputRectangle.getMaxX()), - aTargetSurface.getMaxY() - (aSVGRect.getMaxY() - aInputRectangle.getMaxY())); - - aInputRectangle.transform(basegfx::utils::createTranslateB2DHomMatrix( - -aInputRectangle.getMinX(), -aInputRectangle.getMinY())); - aInputRectangle.transform(basegfx::utils::createScaleB2DHomMatrix( - aFinalRectangle.getWidth() / aInputRectangle.getWidth(), - aFinalRectangle.getHeight() / aInputRectangle.getHeight())); - aInputRectangle.transform(basegfx::utils::createTranslateB2DHomMatrix( - aFinalRectangle.getMinX() - 0.5, - aFinalRectangle.getMinY() - - 0.5)); // compensate 0.5 for different interpretation of where the center of a pixel is + aInputRectangle.getMinX(), aInputRectangle.getMinY(), + aInputRectangle.getMaxX() + fDeltaX, aInputRectangle.getMaxY() + fDeltaY); + + aFinalRectangle.transform(basegfx::utils::createTranslateB2DHomMatrix( + aTargetSurface.getMinX() - 0.5, aTargetSurface.getMinY() - 0.5)); basegfx::B2DPolygon aB2DPolygon = basegfx::utils::createPolygonFromRect( - aInputRectangle, rRectangle.mnRx / aFinalRectangle.getWidth() * 2.0, + aFinalRectangle, rRectangle.mnRx / aFinalRectangle.getWidth() * 2.0, rRectangle.mnRy / aFinalRectangle.getHeight() * 2.0); if (rRectangle.mpFillColor) @@ -209,29 +203,27 @@ void drawFromDrawCommands(gfx::DrawRoot const& rDrawRoot, SalGraphics& rGraphics { auto const& rPath = static_cast<gfx::DrawPath const&>(*pDrawBase); - basegfx::B2DRange aPolyPolygonRange(rPath.maPolyPolygon.getB2DRange()); - basegfx::B2DPolyPolygon aPolyPolygon(rPath.maPolyPolygon); - - basegfx::B2DRange aFinalRectangle( - aTargetSurface.getMinX() + aPolyPolygonRange.getMinX(), - aTargetSurface.getMinY() + aPolyPolygonRange.getMinY(), - aTargetSurface.getMaxX() - (aSVGRect.getMaxX() - aPolyPolygonRange.getMaxX()), - aTargetSurface.getMaxY() - (aSVGRect.getMaxY() - aPolyPolygonRange.getMaxY())); - - aPolyPolygon.transform(basegfx::utils::createTranslateB2DHomMatrix( - -aPolyPolygonRange.getMinX(), -aPolyPolygonRange.getMinY())); - - double fScaleX = 1.0; - double fScaleY = 1.0; - if (aPolyPolygonRange.getWidth() > 0.0) - fScaleX = aFinalRectangle.getWidth() / aPolyPolygonRange.getWidth(); - if (aPolyPolygonRange.getHeight() > 0.0) - fScaleY = aFinalRectangle.getHeight() / aPolyPolygonRange.getHeight(); - - aPolyPolygon.transform(basegfx::utils::createScaleB2DHomMatrix(fScaleX, fScaleY)); + double fDeltaX = aTargetSurface.getWidth() - aSVGRect.getWidth(); + double fDeltaY = aTargetSurface.getHeight() - aSVGRect.getHeight(); + basegfx::B2DPolyPolygon aPolyPolygon(rPath.maPolyPolygon); + for (auto& rPolygon : aPolyPolygon) + { + for (size_t i = 0; i < rPolygon.count(); ++i) + { + auto& rPoint = rPolygon.getB2DPoint(i); + double x = rPoint.getX(); + double y = rPoint.getY(); + + if (x > aSVGRect.getCenterX()) + x = x + fDeltaX; + if (y > aSVGRect.getCenterY()) + y = y + fDeltaY; + rPolygon.setB2DPoint(i, basegfx::B2DPoint(x, y)); + } + } aPolyPolygon.transform(basegfx::utils::createTranslateB2DHomMatrix( - aFinalRectangle.getMinX() - 0.5, aFinalRectangle.getMinY() - 0.5)); + aTargetSurface.getMinX() - 0.5, aTargetSurface.getMinY() - 0.5)); if (rPath.mpFillColor) { |