• 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
Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath


  • Subject: Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath
  • From: Scott Thompson <email@hidden>
  • Date: Fri, 18 Apr 2008 08:21:56 -0500

Setting a line width of 0 draws a 1-pixel wide line at the resolution of the device it draws to, so on screen, that's 1/72 of an inch (approx) on a printer 1/600 inch, say. It's a useful way to isolate drawing from any CTM scaling. This is handy for drawing a selection rect outline on top of a zoomed image where you don't want the selection itself to be scaled up (among many other uses). So yes, I'd say it works - and Quartz most definitely does draw strokes with a line width of 0.

No, Quartz 2D does not draw zero width strokes.

If you use NSBezierPath and supply a stroke width of 0 then Cocoa will fudge the stroke width on your behalf and come up with something that approximates a single pixel line, but Quartz 2D itself will not draw a 0 pixel wide line. You can try it yourself:

- (void) drawRect: (NSRect) rectToDraw
{
// This, of course, will draw
NSBezierPath *bezierPath = [NSBezierPath bezierPathWithRect: NSMakeRect(20, 20, 150, 150)];
[bezierPath setLineWidth: 1];
[[NSColor blueColor] set];
[bezierPath stroke];

// This also will draw because Cocoa is nice and fudges the underlying Quartz drawing for you
bezierPath = [NSBezierPath bezierPathWithRect: NSMakeRect(10, 10, 200, 200)];
[bezierPath setLineWidth: 0];
[[NSColor redColor] set];
[bezierPath stroke];


// This will not draw anything because Quartz does not draw zero width lines.
CGContextRef cgContext = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
CGContextSetLineWidth(cgContext, 0);
CGContextSetRGBStrokeColor(cgContext, 0.0, 1.0, 0.0, 1.0);
CGContextAddRect(cgContext, CGRectMake(5, 5, 150, 150));
CGContextStrokePath(cgContext);
}
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath
      • From: Graham Cox <email@hidden>
References: 
 >Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath (From: Heinrich Giesen <email@hidden>)
 >Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath (From: Scott Thompson <email@hidden>)
 >Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath
  • Next by Date: Re: Why is [nil aMessage] a no-op?
  • Previous by thread: Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath
  • Next by thread: Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath
  • Index(es):
    • Date
    • Thread