Re: text to bezier path
Re: text to bezier path
- Subject: Re: text to bezier path
- From: "Chase" <email@hidden>
- Date: Mon, 18 Jun 2007 20:42:06 +0000
> Sure, you can do that. However, you don't need an NSTextView to have
> formatted text. The actual underlying text is stored in an
> NSTextStorage. The sample code uses a category method on NSString
> that takes an NSFont, and uses that to set the contents of the text
> storage. It would be just as easy to have a category method on
> NSAttributedString, so that you could specify a fully formatted
> string. It might look something like this (untested):
>
> @implementation NSAttributedString (BezierConversions)
>
> - (NSBezierPath*)myBezierPathWithSize:(NSSize)size {
> NSBezierPath *bezier = nil; /* default result */
>
> /* put the attributed string's text into a text storage
> so we can access the glyphs through a layout. */
> NSTextStorage *textStore = [[NSTextStorage alloc]
> initWithAttributedString: self];
> NSTextContainer *textContainer = [[NSTextContainer alloc] init];
> BezierNSLayoutManager *myLayout = [[BezierNSLayoutManager alloc]
> init];
> [myLayout addTextContainer: textContainer];
> [textStore addLayoutManager: myLayout];
> [textContainer setContainerSize:size];
> [textContainer setLineFragmentPadding:0.0];
>
> /* create a new NSBezierPath and add it to the custom layout */
> [myLayout setTheBezierPath: [NSBezierPath bezierPath]];
> ...
>
> with the rest the same as in the sample. Here we specify a size
> because if you want to do e.g. center alignment, you need to have a
> definite width within which to center the text. The height can be
> some large number.
>
> The natural name for a method like this would be
> "bezierPathWithSize:", but I would recommend using other name for
> your category method, just in case we ever add a method with that
> name to NSAttributedString. You can customize the name however you
> like; I just picked one possibility.
>
> Douglas Davidson
hmmm.... cool. but the method for centering text is in the NSText class (alignCenter:). how will I center the text in this case?
thanks.
- chase
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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