Re: Removing or ignoring "lineWidth" property of an NSBezierPath instance
On 28/04/2009, at 3:54 AM, Tobias Zimmerman wrote: I think that, at best, the documentation is ambiguous. It would be clearer specifically saying "If no value was set explicitly for the receiver, this method [lineWidth] returns the default line width ->at the time the receiver was created<-" I may file a RADR on that. Well, it didn't seem too ambiguous to me - but then again additional clarification wouldn't hurt. It is further confusing because the actual effect of the lineWidth property is dependent on the view in which the drawing takes place -- that is, a line width of "1.0" in one view will not necessarily appear the same width in a separate view that has a different dot-pitch, pixel ratio, etc. That's not the case. The whole point of Quartz is that it is resolution independent. 1.0 points always means 1.0 points, and when that's rasterized it will set as many pixels as necessary on the device it's drawing to. Of course if the resolution is such that the smallest pixel is effectively 2 points, Quartz can only fake it by drawing the 2pt pixel at half brightness. This happens when you use a line width of, say 0.5, and the smallest pixel is 1.0 points. However the appearance of the line will be consistent, within reason (very coarse resolutions obviously cause problems with this approach, but these days 72dpi is definitely a minimum). Don't confuse points and pixels. While by default without scaling, on screen there is a 1:1 correspondence between them they are completely independent. The only exception to this is when you specify a line width of 0 with NSBezierPath - that will be resolution dependent but it's a special case, and doesn't apply to the CGPath functions. If your aim is to always draw a 1-pixel wide line no matter what the target resolution is, a line width of 0 will do that. If your aim is to always draw a 2- pixel line, you'd have to calculate the necessary line width knowing the resolution of the device and scaling appropriately, as there's no built-in way to force this kind of resolution dependence. If you want to use a fixed resolution regardless, you could create a suitable bitmap and draw into that, then draw that to the target device as needed (and turn off anti-aliasing for that genuine Windows 3.1 look). Where a drawn line width will also appear differently is when a view is scaled (i.e. the view context has a scaling transform in force), but then you'd expect that I would have thought. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Removing or ignoring "lineWidth" property of an NSBezierPath instance
Thanks Alastair and Graham for responding, and apologies for the delay in following up. I think that, at best, the documentation is ambiguous. It would be clearer specifically saying "If no value was set explicitly for the receiver, this method [lineWidth] returns the default line width ->at the time the receiver was created<-" I may file a RADR on that. It is further confusing because the actual effect of the lineWidth property is dependent on the view in which the drawing takes place -- that is, a line width of "1.0" in one view will not necessarily appear the same width in a separate view that has a different dot-pitch, pixel ratio, etc. > From: Graham Cox > Date: Thu, 23 Apr 2009 10:27:25 +1000 > To: Tobias Zimmerman > Cc: "cocoa-dev@lists.apple.com" > Subject: Re: Removing or ignoring "lineWidth" property of an NSBezierPath > instance > > > On 23/04/2009, at 7:19 AM, Tobias Zimmerman wrote: > >> (By way of further explanation, the project this arises in involves >> a set of >> bezier paths that are generated in one program and archived for use >> in a >> separate program. I would like the lineWidth and other drawing >> specifics >> such as line/fill colors to be controlled by the view where the >> reusable >> paths are drawn, rather than a property of the paths themselves). > > > I don't think that's going to work. > > My take on what +setDefaultLineWidth: means is that this establishes > the value for a path's -lineWidth when it is first created. From that > instant on, the path itself has a defined line width, a copy of the > default value. If you never set the default I believe it defaults to > 1.0. > > When you dearchive the paths the line width of each will be whatever > is recorded for them, which came from the default on the source > machine at the time they were created. Changing the default line width > on your machine will have no effect on these values. > > If you want to change the line width when the paths are drawn, you'll > have to set each one individually prior to drawing. > > --Graham > > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Removing or ignoring "lineWidth" property of an NSBezierPath instance
On 23/04/2009, at 7:19 AM, Tobias Zimmerman wrote: (By way of further explanation, the project this arises in involves a set of bezier paths that are generated in one program and archived for use in a separate program. I would like the lineWidth and other drawing specifics such as line/fill colors to be controlled by the view where the reusable paths are drawn, rather than a property of the paths themselves). I don't think that's going to work. My take on what +setDefaultLineWidth: means is that this establishes the value for a path's -lineWidth when it is first created. From that instant on, the path itself has a defined line width, a copy of the default value. If you never set the default I believe it defaults to 1.0. When you dearchive the paths the line width of each will be whatever is recorded for them, which came from the default on the source machine at the time they were created. Changing the default line width on your machine will have no effect on these values. If you want to change the line width when the paths are drawn, you'll have to set each one individually prior to drawing. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Removing or ignoring "lineWidth" property of an NSBezierPath instance
On 22 Apr 2009, at 22:19, Tobias Zimmerman wrote: First, the documentation for NSBezierPath’s -(CGFloat)lineWidth method states that: "If no value was set explicitly for the receiver, this method returns the default line width." This suggests that a newly created NSBezierPath should have no value set for lineWidth. I think it means that it behaves exactly how your code demonstrates that it does. By which I mean that when you create an NSBezierPath, the initial lineWidth is whatever the default was set to at the time of creation. I don't think any other behaviour is very likely, especially given that, as you correctly point out, doing something else would mean either reserving some special value or adding an extra flag to every NSBezierPath. Kind regards, Alastair. -- http://alastairs-place.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Removing or ignoring "lineWidth" property of an NSBezierPath instance
I am trying to find a way to ensure that a series of NSBezierPaths are drawn using [NSBezierPath defaultLineWidth] value. However, contrary to documentation and expectation, my paths seem to automatically assign themselves the value 1.0 for their own lineWidth property. First, the documentation for NSBezierPath¹s -(CGFloat)lineWidth method states that: "If no value was set explicitly for the receiver, this method returns the default line width." This suggests that a newly created NSBezierPath should have no value set for lineWidth. The following custom view class demonstrates the problem: @interface AppView : NSView { NSMutableArray*pathsToDraw; } @end @implementation AppView - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { pathsToDraw = [NSMutableArray array]; [pathsToDraw retain]; //Creates a series of 10 overlapping boxes stored in an array CGFloat boxWidth = 15.0; CGFloat boxHeight = 12.0; for (int i = 0; i < 10; i++) { NSBezierPath *newPath = [NSBezierPath bezierPathWithRect:NSMakeRect(i * (boxWidth + 1.0), i * (boxHeight + 1.0), i * boxWidth, i * boxHeight)]; [pathsToDraw addObject:newPath]; //Note, we never call [newPath setLineWidth], so none of the paths should have its lineWidth property set } } return self; } - (void)drawRect:(NSRect)rect { [[NSColor blackColor] set]; //set default to an arbitrary number other than 1.0 This is the width we want the paths to be drawn with. [NSBezierPath setDefaultLineWidth:4.0]; for (NSBezierPath *path in pathsToDraw) { /* The following line logs the specific and default line widths. Since we never set any lineWidth for any of the paths in the array, these values should be identical, or, at least that¹s what the documentation suggests. */ NSLog(@"Path width = %0.3f; default width = %0.3f", [path lineWidth], [NSBezierPath defaultLineWidth]); [path stroke]; } // The following line proves that the defaultLineWidth class property of NSBezierPath is functioning, as the resulting box is drawn at the correct thickness [NSBezierPath strokeRect:[self bounds]]; } @end The output from the NSLog statement is the following line (10 times): > 2009-04-22 16:30:21.640 BezPathLineWidthTester[7347:10b] Path width = 1.000; > default width = 4.000 Changing the value passed to [NSBezierPath setDefaultLineWidth:] has no effect on the boxes drawn out of the array, although it does effect the ³anonymous² path created by the strokeRect command. So, my question(s): is there a way to remove or ignore an NSBezierPath¹s individual lineWidth property in favor of the default? (Note that setting the individual path¹s lineWidth property to 0.0 will not work because a lineWidth of 0.0 has a specific meaning to the drawing system. Since this property is a float, it can¹t be set to nil). Is this indeed a bug (either in NSBezierPath or in the documentation), or am I overlooking something? (By way of further explanation, the project this arises in involves a set of bezier paths that are generated in one program and archived for use in a separate program. I would like the lineWidth and other drawing specifics such as line/fill colors to be controlled by the view where the reusable paths are drawn, rather than a property of the paths themselves). ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com