diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-01-16 19:38:01 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-01-17 11:33:16 -0500 |
commit | d4d174a6752f923c5a0b2560bac674f54d239a01 (patch) | |
tree | 2161912074f13d5a02555ff3e13cd2d4e6b61d07 /vcl | |
parent | 009b7be7c8a6033e2e93b07214e4545eeeda734a (diff) |
Ensure that we display patterned lines at all zoom levels.
VCL doesn't draw polygons if either its width or height is 1 pixel.
Detect when the polygon is too small to display, and substitute it
with a minimum displayable rectangle.
Change-Id: I7e3174d549880d00ffa55fd2239484c2db3d7829
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/gdi/outdev6.cxx | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/vcl/source/gdi/outdev6.cxx b/vcl/source/gdi/outdev6.cxx index 81f7df7fea0b..ef1def54baf5 100644 --- a/vcl/source/gdi/outdev6.cxx +++ b/vcl/source/gdi/outdev6.cxx @@ -42,10 +42,46 @@ #include <math.h> -// ======================================================================== +namespace { +/** + * Perform a safe approximation of a polygon from double-precision + * coordinates to integer coordinates, to ensure that it has at least 2 + * pixels in both X and Y directions. + */ +Polygon toPolygon( const basegfx::B2DPolygon& rPoly ) +{ + basegfx::B2DRange aRange = rPoly.getB2DRange(); + double fW = aRange.getWidth(), fH = aRange.getHeight(); + if (0.0 < fW && 0.0 < fH && (fW <= 1.0 || fH <= 1.0)) + { + // This polygon not empty but is too small to display. Approximate it + // with a rectangle large enough to be displayed. + double nX = aRange.getMinX(), nY = aRange.getMinY(); + double nW = std::max<double>(1.0, round(fW)); + double nH = std::max<double>(1.0, round(fH)); + + Polygon aTarget; + aTarget.Insert(0, Point(nX, nY)); + aTarget.Insert(1, Point(nX+nW, nY)); + aTarget.Insert(2, Point(nX+nW, nY+nH)); + aTarget.Insert(3, Point(nX, nY+nH)); + aTarget.Insert(4, Point(nX, nY)); + return aTarget; + } + return Polygon(rPoly); +} -// ------------------------------------------------------------------------ +PolyPolygon toPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPoly ) +{ + PolyPolygon aTarget; + for (sal_uInt32 i = 0; i < rPolyPoly.count(); ++i) + aTarget.Insert(toPolygon(rPolyPoly.getB2DPolygon(i))); + + return aTarget; +} + +} void OutputDevice::DrawGrid( const Rectangle& rRect, const Size& rDist, sal_uLong nFlags ) { @@ -201,7 +237,7 @@ void OutputDevice::DrawTransparent( const basegfx::B2DPolyPolygon& rB2DPolyPoly, } // fallback to old polygon drawing if needed - DrawTransparent(PolyPolygon(rB2DPolyPoly), static_cast< sal_uInt16 >(fTransparency * 100.0)); + DrawTransparent(toPolyPolygon(rB2DPolyPoly), static_cast<sal_uInt16>(fTransparency * 100.0)); } // ------------------------------------------------------------------------ |