[Drawkit] Fix for aliasing of drawing edges
Graham Cox
graham.cox at bigpond.com
Mon May 19 21:01:19 PDT 2008
I'm aware of the 0.5 pixel "problem", but I chose not to attempt to
compensate for it, instead deciding to go for accuracy over crispness.
That said, It definitely does look a lot sharper. One problem with the
code below is that it causes a big problem when the view is scrolled
when it's zoomed in to large scale. Not sure why at the moment, but
it's so bad I can't recommend including this at present. I think the
update area marking needs to be similarly offset otherwise there is a
small amount of overlap that doesn't get repainted when scrolling.
Regarding offsetting the grid alignment, I'll look into it, but one
thing I do want to avoid is the appearance of uneven spacing between
grid lines by forcing them to integer co-ordinates, and any
misalignment of objects visually between the grid "real" position and
the apparent position of the lines. This might not turn out to be a
problem, just thinking aloud at this stage.
cheers, Graham
On 20 May 2008, at 9:03 am, Brad Larson wrote:
> I noticed that the borders of the drawing, along with the edges of
> objects, were being aliased (one-pixel-wide black lines were drawn
> as two-pixel-wide grey lines). The Quartz drawing model is a little
> odd in that integer coordinates are considered to be between pixels,
> so you need to shift your drawing space by a half pixel in X and Y
> to get things to line up correctly.
>
> By changing
>
> if([NSGraphicsContext currentContextDrawingToScreen])
> {
> [[self paperColour] set];
> NSRectFill( rect );
> }
>
> to be
>
> if([NSGraphicsContext currentContextDrawingToScreen])
> {
> NSAffineTransform* pixelShiftToAdjustForQuartzCoordinates =
> [NSAffineTransform transform];
> [pixelShiftToAdjustForQuartzCoordinates translateXBy:0.5 yBy:0.5];
> [pixelShiftToAdjustForQuartzCoordinates concat];
>
> [[self paperColour] set];
> NSRectFill( rect );
> }
>
> in - (void) drawRect:inView: within DKDrawing.m, you can remove this
> aliasing. There is still some aliasing with the background grids
> and objects drawn on them, due to their drawing coordinates not
> mapping to integer values. In DrawDemo, you'll need to turn off
> grid snapping to see how much sharper rectangles and the like are
> with this setting, because otherwise they'll snap to the non-integer
> grid locations.
>
> A go-between function, template, or method might be needed to
> floor() or ceil() the x and y values of grids and drawable objects
> for display to the screen. Apple has some tips on this at http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/chapter_4_section_6.html
> .
>
>
> ______________________
> Brad Larson
> SonoPlot, Inc.
> 3030 Laura Lane, Suite 120
> Middleton, WI 53562
>
>
>
> _______________________________________________
> Drawkit mailing list
> Drawkit at lists.apptree.net
> http://lists.apptree.net/listinfo.cgi/drawkit-apptree.net
More information about the Drawkit
mailing list