• 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: How to size a TextView to fit a given line?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to size a TextView to fit a given line?


  • Subject: Re: How to size a TextView to fit a given line?
  • From: Ross Carter <email@hidden>
  • Date: Mon, 13 Aug 2012 12:24:29 -0400

On Aug 12, 2012, at 5:34 AM, Gerriet M. Denkmann <email@hidden> wrote:

> In windowWillUseStandardFrame:defaultFrame: in a subclass of NSDocument (which is also the delegate of it's window) I want to set the window to just contain a certain line.
>
> - (NSRect)windowWillUseStandardFrame:(NSWindow *)sender defaultFrame:(NSRect)defaultFrame
> {
> 	//	myTextView is an NSTextView inside a scroll view, which is the sole window content
>
> 	NSString *mySpecialLine = @"... something...";
> 	NSDictionary *typingAttributes = [ myTextView typingAttributes ];
> 	NSFont *typingFont = [ typingAttributes objectForKey: NSFontAttributeName ];
>
> 	NSSize oneSize = [ mySpecialLine sizeWithAttributes: typingAttributes ];
> 	//	this does not work - it always uses printer fonts even if myTextView does not.

I think the basic problem is in assuming that the Cocoa text system and the string drawing methods use the same layout. That assumption is not safe. If you need to know the metrics of a line as it appears in a NSTextView, you need to ask the NSLayoutManager for the metrics of that specific line fragment; you cannot ask the attributed string itself, because its calculations are likely to be different. For one thing, the string drawing methods might use a different typesetter compatibility setting.
_______________________________________________

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

References: 
 >How to size a TextView to fit a given line? (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: __weak pointer collection firing prematurely???
  • Next by Date: Re: Classes incompatible with weak references
  • Previous by thread: How to size a TextView to fit a given line?
  • Next by thread: Re: How to size a TextView to fit a given line?
  • Index(es):
    • Date
    • Thread