After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 768631 - gdk_quartz_draw_segments does not draw 1-pixel line
gdk_quartz_draw_segments does not draw 1-pixel line
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Backend: Quartz
2.24.x
Other Mac OS
: Normal major
: ---
Assigned To: gtk-quartz maintainers
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-07-10 11:59 UTC by Emmanuel Stapf
Modified: 2018-05-02 17:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Pixmap with chess like mask pattern (2.78 KB, image/png)
2016-07-10 11:59 UTC, Emmanuel Stapf
  Details
Proposed solution (1.49 KB, patch)
2016-07-10 12:12 UTC, Emmanuel Stapf
none Details | Review
Patch using git format-patch command (1.70 KB, patch)
2016-07-10 22:48 UTC, Emmanuel Stapf
none Details | Review

Description Emmanuel Stapf 2016-07-10 11:59:13 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);
Comment 1 Emmanuel Stapf 2016-07-10 12:12:22 UTC
Created attachment 331159 [details] [review]
Proposed solution
Comment 2 Emmanuel Stapf 2016-07-10 22:48:16 UTC
Created attachment 331172 [details] [review]
Patch using git format-patch command
Comment 3 Matthias Clasen 2018-02-10 05:06:31 UTC
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.
Comment 4 Emmanuel Stapf 2018-02-10 16:46:13 UTC
It is still important to me and would like to see my patch applied. However I cannot re-open the ticket.
Comment 5 Emmanuele Bassi (:ebassi) 2018-02-10 18:48:01 UTC
As per comment 4; thanks for your patience!
Comment 6 GNOME Infrastructure Team 2018-05-02 17:17:40 UTC
-- 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.