Quartz theory (Re: How to draw hairline ?)
Quartz theory (Re: How to draw hairline ?)
- Subject: Quartz theory (Re: How to draw hairline ?)
- From: Chris Hanson <email@hidden>
- Date: Sat, 14 Feb 2004 13:45:24 -0500
On Feb 13, 2004, at 11:30 PM, Julien Guimont wrote:
So here is the answer on a practical note (theory will be found with a
little googling of your part). You have to make the bezier path1 pixel
thick and draw on 0.5 pixel alignment (OS X does some anti aliasing and
drawing on 0 makes the line fall between 2 pixel thus antialised).
Actually, the theory underlying Quartz -- also known as the PostScript
imaging model (PSIM) -- is important, particularly as higher-density
displays become more common.
In the PostScript imaging model, drawing takes place in a coordinate
system called "user space" and gets translated to a coordinate system
called "device space" for rendering. The current transformation matrix
is used for this translation. User space is measured by default in
units of "points," 1/72 of an inch, and fractional coordinates are
allowed.
Currently in Quartz, the screen's device space is also a 72dpi
coordinate system making the default for the current transformation
matrix the identity matrix. However, this isn't the case when
printing.
Also, in the PostScript imaging model all drawing takes place directly
along the coordinates rather than offset from them. This is due to its
mathematical basis; it takes care to properly preserve things like line
widths, line joints, end caps, and so on, regardless of the orientation
of what it's drawing and this is easier if it draws on the coordinates.
(QuickDraw on the other hand draws "next to" coordinates.)
Of course, sometimes you want to do something device-specific like draw
a hairline. You don't want to specify that the line is 1 point, or 0.5
points, or 0.1 points, or... So the PostScript imaging model gives you
a shortcut; you can set the line width to 0.0, and this is interpreted
as "the thinnest line you can draw on this device."
Quartz complicates things further because right now its primary
rendering target has a relatively low resolution (72dpi). It employs
antialiasing to get a higher effective resolution out of the screen.
Drawing on the coordinates means that a one-point line will half-cover
two device pixels, which means it has to antialias to make the line
appear correctly.
But on a 72dpi screen, that's not necessarily the effect you want. So
you can shift the 72dpi user coordinate system by (0.5, 0.5) to make
rendering occur down the center of the 72dpi device coordinate system.
You need to be aware exactly why you're doing this, though, so you can
avoid doing it in situations where the user and device coordinate
systems aren't identical.
This is currently the case when printing. However, IBM has been making
200dpi LCD displays for a couple years now (3840 by 2560 resolution,
24-inch diagonal) and the cost is coming down while the yield is going
up. Microsoft has announced that Longhorn will support high-density
displays, and I fully expect Apple will do the same in the future.
(After all, Quartz already has all of the machinery it needs to do so.)
On such a display, asking for a 1-point line and a hairline will mean
different things, and that 1-point line can be drawn down the edge of
your coordinates and look good even with antialiasing. (That 1-point
line will cover about 2.778 device pixels at 200dpi, and 4.167 at
300dpi.)
-- Chris
--
Chris Hanson <email@hidden>
bDistributed.com, Inc.
Outsourcing Vendor Evaluation
Custom Mac OS X Development
Cocoa Developer Training
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.