[Libreoffice-commits] core.git: Branch 'feature/calc-cell-borders' - vcl/source

Kohei Yoshida kohei.yoshida at collabora.com
Thu Jan 16 16:40:18 PST 2014


 vcl/source/gdi/outdev6.cxx |   42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

New commits:
commit 4eec891f7c70b60ee936962bae724139f40683f4
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Thu Jan 16 19:38:01 2014 -0500

    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

diff --git a/vcl/source/gdi/outdev6.cxx b/vcl/source/gdi/outdev6.cxx
index 81f7df7..ef1def5 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));
 }
 
 // ------------------------------------------------------------------------


More information about the Libreoffice-commits mailing list