[Drawkit] Fix for aliasing of drawing edges
Brad Larson
larson at sonoplot.com
Mon May 19 18:41:17 PDT 2008
I inserted some floor() statements in the DKGridLayer.m
createGridCacheInRect: method that seem to remove aliasing from the
background grid. The modified source file is attached.
I can't think of an easy way to make the points of the NSBezierPath
defining the stroke of an object all be floored in the same way so
that the drawable objects won't be aliased. Maybe something in
DKStroke's renderPath: method or the Geometry category of NSBezierPath.
On May 19, 2008, at 6:03 PM, 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
______________________
Brad Larson
SonoPlot, Inc.
3030 Laura Lane, Suite 120
Middleton, WI 53562
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DKGridLayer.m
Type: application/octet-stream
Size: 49373 bytes
Desc: not available
URL: <http://lists.apptree.net/pipermail/drawkit-apptree.net/attachments/20080519/dd532b1f/attachment-0001.obj>
-------------- next part --------------
More information about the Drawkit
mailing list