On May 5, 2012, at 1:12 PM, Peter Teeson wrote:

> As to odd number of pixels I was under the impression that the parameters are 
> in points,
> which are a unit of length* whereas pixels are related to hardware specs. 
> e.g. Line width is in points. 

That’s right. But everything you draw is going to be mapped onto pixels by the 
time it’s onscreen.

> So it is not the responsibility of the device driver to map points to pixels 
> in a device dependent way?

It does that, but the results may not always be exactly what you want. :) The 
default behavior is to antialias, so if you stroke a one-point-wide black 
rectangle on integer point boundaries (assuming the usual 1pt==1px scaling) you 
will in fact get a two-pixel wide gray rectangle. Which is probably not what 
you wanted. This is because the edges are on pixel boundaries so the strokes 
are going halfway through the pixels on either side. The solution as I said is 
to add 0.5 to the coordinates so that the stroke edges fall on pixel boundaries.

(IIRC there are some AppKit geometry utility functions that will adjust 
coordinate values to fit pixel boundaries in a resolution-independent way. I 
don’t remember their names offhand.)

Someday every device will have retina-quality graphics and these details won’t 
matter, but currently they definitely do, especially for UI elements with thin 
horizontal and vertical lines. (And actually they may matter even on retina 
displays. These details of pixel rounding are definitely important at 300dpi on 
printers, which is why PostScript fonts are hinted — hinting consists almost 
entirely of moving edges of curves onto pixel boundaries. I remember from the 
old days that unhinted fonts on a 300dpi LaserWriter looked like shit. It turns 
out that even if your eye can’t distinguish individual pixels 1/300” across, it 
can easily tell the difference between a 1/300” and a 1/150” thick line.)

—Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to