Re: Forcing text layout
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