gdk_quartz_draw_segments does not draw 1-pixel line
Submitted by Emmanuel Stapf
Assigned to gtk-quartz maintainers
Link to original bug (#768631)
Description
Created attachment 331157 Pixmap with chess like mask pattern
When you call gdk_pixbuf_render_threshold_alpha
to extract a bitmap mask of a PixBuf, the mask is incorrect when you have a one pixel of mask not surrounding by other pixels. The easiest way to see this is to use the attached png.
Not knowing much of the Mac OS drawing API, I found that the issue is caused by the implementation of gdk_quartz_draw_segments
which calls to CGContextAddLineToPoint
that doesn't seem to work when starting point and ending point are the same.
I found a workaround by calling CGContextFillRect for 1-pixel lines. Here is my patch.
diff --git a/gdk/quartz/gdkdrawable-quartz.c b/gdk/quartz/gdkdrawable-quartz.c --- a/gdk/quartz/gdkdrawable-quartz.c +++ b/gdk/quartz/gdkdrawable-quartz.c @@ -572,7 +572,7 @@ gdk_quartz_draw_segments (GdkDrawable *drawable, private = GDK_GC_QUARTZ (gc);
if (!_gdk_quartz_gc_update_cg_context (gc, drawable, context,
-
GDK_QUARTZ_CONTEXT_STROKE))
-
GDK_QUARTZ_CONTEXT_STROKE | GDK_QUARTZ_CONTEXT_FILL))
-
CGContextMoveToPoint (context, segs[i].x1 + 0.5, segs[i].y1 + 0.5);
-
CGContextAddLineToPoint (context, segs[i].x2 + 0.5 + xfix, segs[i].y2 + 0.5 + yfix);
-
// Drawing a one pixel line doesn't work, so instead we use CGContextFillRect
-
if ((segs[i].x1 == (segs[i].x2 + xfix)) && (segs[i].y1 == (segs[i].y2 + yfix))) {
-
CGRect rect = CGRectMake(segs[i].x1, segs[i].y1, 1, 1);
-
CGContextFillRect (context, rect);
-
} else {
-
CGContextMoveToPoint (context, segs[i].x1 + 0.5, segs[i].y1 + 0.5);
-
CGContextAddLineToPoint (context, segs[i].x2 + 0.5 + xfix, segs[i].y2 + 0.5 + yfix);
-
}
}
CGContextStrokePath (context);
Attachment 331157, "Pixmap with chess like mask pattern":
Version: 2.24.x