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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to