• 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: text to bezier path
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: text to bezier path


  • Subject: Re: text to bezier path
  • From: Douglas Davidson <email@hidden>
  • Date: Mon, 18 Jun 2007 13:21:55 -0700


On Jun 18, 2007, at 1:03 PM, Chase wrote:

I forgot to say thanks for that link, Scott. It got me up and going nicely and the text looks gorgeous over playing video.

http://developer.apple.com/samplecode/SpeedometerView/index.html

However, I need a little more control over text placement (like paragraph alignment, and so forth)...

Couldn't I just have a hidden textview that I print into **and format**, and then convert that to a bezier path?

I can **sort of** envision how to do this using an NSTextView and the NSString category additions in that SpeedometerView project, but I can't connect enough of the dots in mind. The text storage mechanism in cocoa has always been a pretty confusing concept to me.

Can someone help me out a little here. Thanks.

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
_______________________________________________

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


References: 
 >Re: text to bezier path (From: "Chase" <email@hidden>)

  • Prev by Date: Re: How to compute optimal NSField size?
  • Next by Date: Re: NSTreeController, minus set mutation, array exception
  • Previous by thread: Re: text to bezier path
  • Next by thread: Re: text to bezier path
  • Index(es):
    • Date
    • Thread