NSBezierPath Fill and Stroke woes;
NSBezierPath Fill and Stroke woes;
- Subject: NSBezierPath Fill and Stroke woes;
- From: "Matt Budd (Madentec)" <email@hidden>
- Date: Wed, 20 Jul 2005 13:03:39 -0600
I am having some issues filling and stroking a NSBezierPath. The
problem happens when the NSBezierPath doesn't have an integer origin.
I need to translate my origin coords by subtracting 0.5 so that they
don't straddle the pixel border and I get a clean crisp stroke. See
the following example:
------------------------------------------------------------------------
------
NSBezierPath *loBadFill = [NSBezierPath bezierPathWithRect: NSMakeRect
(10.5, 10.5, 50, 50)];
[[NSColor magentaColor] set];
[loBadFill fill];
[[NSColor cyanColor] set];
[loBadFill fill];
NSBezierPath *loGoodStroke = [NSBezierPath bezierPathWithRect:
NSMakeRect(10.5, 70.5, 50, 50)];
[[NSColor blackColor] set];
[loGoodStroke stroke];
NSBezierPath *loGoodFill = [NSBezierPath bezierPathWithRect:
NSMakeRect(70, 10, 50, 50)];
[[NSColor magentaColor] set];
[loGoodFill fill];
[[NSColor cyanColor] set];
[loGoodFill fill];
NSBezierPath *loBadStroke = [NSBezierPath bezierPathWithRect:
NSMakeRect(70, 70.5, 50, 50)];
[[NSColor blackColor] set];
[loBadStroke stroke];
------------------------------------------------------------------------
------
There's 2 sets of beziers: the first set is beziers that are
translated by -0.5; the second have integer origins.
If you run this code in a view's -drawRect: method, you'll see some
weird things with the first set (loBadFill): even though I am filling
the _same_ rect twice in a row with a different color, the second
fill doesn't completely cover the rect (i.e. I get a bit of bleed of
the first fill color on the edges). However, when I use the non-
translated one from the second set (loGoodFill), I get what I would
expect (no bleed of the magenta, and only cyan showing). And I have
to use the translated set, as you can see with the loBadStroke one
(the stroke is not crisp).
Is this a known issue, or is something else weird? I have tried it on
both Tiger and Panther and get the same result. I have also tried
turning of the anti-aliasing using "[[NSGraphicsContext
currentContext] setImageInterpolation: NSImageInterpolationNone];".
Any thoughts?
- Matt Budd
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden