GNOME Bugzilla – Bug 332662
Hollow polygons have wrong linecaps
Last modified: 2006-03-11 20:34:42 UTC
Also with 2.6 and HEAD. The following patch fixes it, but why was Polyline used at all? --- from-cvs/gtk+-2-6/gdk/win32/gdkdrawable-win32.c Sat Jul 30 16:25:42 2005 +++ my-gtk/gtk+-2-6/gdk/win32/gdkdrawable-win32.c Sat Jan 28 21:05:12 2006 @@ -1029,7 +1029,15 @@ GDI_CALL (SelectObject, (hdc, old_pen)); } else - GDI_CALL (Polyline, (hdc, pts, npoints)); + { + HBRUSH old_brush; + + if ((old_brush = SelectObject (hdc, GetStockObject (HOLLOW_BRUSH))) == NULL) + WIN32_GDI_FAILED ("SelectObject"); + GDI_CALL (Polygon, (hdc, pts, npoints)); + if (old_brush != NULL) + GDI_CALL (SelectObject, (hdc, old_brush)); + } } static void
> why was Polyline used at all? Good question... I don't find a test case for gdk_draw_polygon() right now myself, could you check if this somewhat simpler patch also works? (It works much like the code in draw_rectangle in that it either sets the current pen to a null pen, or current brush to a hollow brush, then calls Polygon(). It also removes the crap in gdk_win32_draw_polygon() that adds an extra point equal to the starting one. That isn't necessary now when Polygon() is always used.) Index: gdk/win32/gdkdrawable-win32.c =================================================================== RCS file: /cvs/gnome/gtk+/gdk/win32/gdkdrawable-win32.c,v retrieving revision 1.80.2.1 diff -p -u -2 -r1.80.2.1 gdkdrawable-win32.c --- gdk/win32/gdkdrawable-win32.c 30 Sep 2005 23:51:49 -0000 1.80.2.1 +++ gdk/win32/gdkdrawable-win32.c 27 Feb 2006 00:47:32 -0000 @@ -995,5 +995,5 @@ draw_polygon (GdkGCWin32 *gcwin32, gboolean filled; POINT *pts; - HPEN old_pen; + HGDIOBJ old_pen_or_brush; gint npoints; gint i; @@ -1011,14 +1011,12 @@ draw_polygon (GdkGCWin32 *gcwin32, if (filled) - { - old_pen = SelectObject (hdc, GetStockObject (NULL_PEN)); - if (old_pen == NULL) - WIN32_GDI_FAILED ("SelectObject"); - GDI_CALL (Polygon, (hdc, pts, npoints)); - if (old_pen != NULL) - GDI_CALL (SelectObject, (hdc, old_pen)); - } + old_pen_or_brush = SelectObject (hdc, GetStockObject (NULL_PEN)); else - GDI_CALL (Polyline, (hdc, pts, npoints)); + old_pen_or_brush = SelectObject (hdc, GetStockObject (HOLLOW_BRUSH)); + if (old_pen_or_brush == NULL) + WIN32_GDI_FAILED ("SelectObject"); + GDI_CALL (Polygon, (hdc, pts, npoints)); + if (old_pen_or_brush != NULL) + GDI_CALL (SelectObject, (hdc, old_pen_or_brush)); } @@ -1047,5 +1045,5 @@ gdk_win32_draw_polygon (GdkDrawable *dra bounds.height = 0; - pts = g_new (POINT, npoints+1); + pts = g_new (POINT, npoints); for (i = 0; i < npoints; i++) @@ -1063,12 +1061,4 @@ gdk_win32_draw_polygon (GdkDrawable *dra } - if (points[0].x != points[npoints-1].x || - points[0].y != points[npoints-1].y) - { - pts[npoints].x = points[0].x; - pts[npoints].y = points[0].y; - npoints++; - } - region = widen_bounds (&bounds, GDK_GC_WIN32 (gc)->pen_width);
The patch works equally well - starngely enough it did not apply cleanly (Hunk #2 FAILED at 1011.) but was easy to apply by hand. My test case is Dia with the included render-test.dia. Zoom in to the rectangle "as polygon" and watch the formerly missing corner. Apply to three branches (2-6, 2-8, HEAD)?
Patch applied to HEAD and gtk-2-8. 2.6 is not maintained any longer. 2006-03-11 Tor Lillqvist <tml@novell.com> * gdk/win32/gdkdrawable-win32.c (draw_polygon): Use Polygon() for outlined polygons, too. Same idea as in draw_rectangle(): Set pen to NULL_PEN if drawing a filled polygon, set brush to HOLLOW_BRUSH if drawing a polygon outline. (#332662) (gdk_win32_draw_polygon): Corresponding simplification: no need to add an extra final copy of the starting point.