Re: NSBezierPath + thin lines + antialias = :(
Re: NSBezierPath + thin lines + antialias = :(
- Subject: Re: NSBezierPath + thin lines + antialias = :(
- From: Jens Alfke <email@hidden>
- Date: Mon, 09 Feb 2015 13:36:58 -0800
> On Feb 9, 2015, at 1:18 PM, Jerry Krinock <email@hidden> wrote:
>
> Is there a way to draw thin lines in code, and get good results on non-Retina displays? What should I read to learn how?
(The listserv strips image attachments, so we can’t see the pictures.)
The typical problem drawing thin horizontal/vertical lines is that the line gets split between pixels, so you get a 2-pixel-wide gray line when what you wanted was a 1-pixel black line. The reason this happens is that when you use integer coordinates the line is centered on a pixel boundary, so the left half of the line is in one pixel and the right half is in another.
Instead, to draw a one-point line, the coordinate on the axis perpendicular to the line should end in .5. For example, to draw a vertical line at x=100, the x coord of the line should be 100.5. That way you completely fill the pixels at x=100 and no others.
(This only applies to odd widths, though. For a 2pt line, you do want whole-number coords.)
(It gets more complicated if you’ve transformed the coordinate system, because the above considerations apply to device coords, so you’d have to transform your drawing coords into device coords, do the rounding/offset, and then back. This happens with scaling, but can also occur if you’ve scrolled/offset your coordinates by non-integral amounts.)
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden