• 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: Forcing text layout
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Forcing text layout


  • Subject: Re: Forcing text layout
  • From: Martin Wierschin <email@hidden>
  • Date: Fri, 12 Mar 2010 14:52:07 -0800

Hello Keith!

- (void)forceInitialLayout
{
NSInteger charIndex = (50000 > [[self textStorage] length] ? [[self textStorage] length] : 50000);
if (charIndex > 0)
{
charIndex -= 1;
[layoutManagerlocationForGlyphAtIndex:charIndex];

You shouldn't play loose which character/glyph indexes. I'm sure you know, but the mapping between chars/glyphs is arbitrary and your method could theoretically trigger an out-of-bounds exception. In practice it probably won't because I believe the Cocoa typesetter always produces more glyphs than characters (eg: inserting null glyphs as padding).


That point aside, I've also experienced issues with when forcing layout to a specific character index. Notably that the the mapping from characters to glyphs doesn't seem stable until layout is complete. I've seen -[NSLayoutManager numberOfGlyphs] change before/ after layout! Perhaps the TextEdit code you quoted fails for that reason, eg: the mapping from the final character index (the image attachment) to its corresponding glyph changes after layout finishes.

My solution was to conditionally use -[NSLayoutManager ensureLayoutForCharacterRange:] when running on Leopard or later. That punts the problem entirely to Apple to solve. Another thing to check: do you have discontinuous layout enabled? I never did, but perhaps that's a factor for you.

~Martin

_______________________________________________

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: Forcing text layout
      • From: Keith Blount <email@hidden>
References: 
 >Forcing text layout (From: Keith Blount <email@hidden>)

  • Prev by Date: Re: Key-Value Observing speed
  • Next by Date: Re: 10.6 Base, 10.5 Target, runs fine on everything except Intel 10.5 [KIND OF SOLVED]
  • Previous by thread: Forcing text layout
  • Next by thread: Re: Forcing text layout
  • Index(es):
    • Date
    • Thread