GNOME Bugzilla – Bug 768631
gdk_quartz_draw_segments does not draw 1-pixel line
Last modified: 2018-05-02 17:17:40 UTC
Created attachment 331157 [details] 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)) { gdk_quartz_drawable_release_context (drawable, context); return; @@ -586,8 +586,14 @@ gdk_quartz_draw_segments (GdkDrawable *drawable, segs[i].x2, segs[i].y2, &xfix, &yfix); - 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);
Created attachment 331159 [details] [review] Proposed solution
Created attachment 331172 [details] [review] Patch using git format-patch command
We're moving to gitlab! As part of this move, we are moving bugs to NEEDINFO if they haven't seen activity in more than a year. If this issue is still important to you and still relevant with GTK+ 3.22 or master, please reopen it and we will migrate it to gitlab.
It is still important to me and would like to see my patch applied. However I cannot re-open the ticket.
As per comment 4; thanks for your patience!
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/646.