• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSBezierPath Fill and Stroke woes;
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: NSBezierPath Fill and Stroke woes;
      • From: Scott Thompson <email@hidden>
  • Prev by Date: [MEET] St. Louis, MO : CocoaHeads
  • Next by Date: NSPopupButton contentObjects binding
  • Previous by thread: [MEET] St. Louis, MO : CocoaHeads
  • Next by thread: Re: NSBezierPath Fill and Stroke woes;
  • Index(es):
    • Date
    • Thread