Re: NSLayoutManager and best override point for temporary attributes
Re: NSLayoutManager and best override point for temporary attributes
- Subject: Re: NSLayoutManager and best override point for temporary attributes
- From: Keith Blount <email@hidden>
- Date: Wed, 7 Oct 2009 06:45:19 -0700 (PDT)
Hi Ross,
Many thanks for the suggestion.
>> I tried saving the edited range of text in the text storage and then
>> having my layout manager check this from:
>>
>> -textStorage:edited:range:changeInLength:invalidatedRange:
>>
>> Then my layout manager adds temp attribs in this method. Turns out
>> that this is a Bad Thing (which I should have realised beforehand),
>> as it can cause glyph generation before the text storage has ended
>> editing. D'oh.
> I haven't tried fixing temporary attributes in NSTextStorage -
> fixFontAttributeInRange:, but that might be worth a try.
Although it sounds like it should work, it doesn't unfortunately. Something very strange happens if you try to apply temporary attributes from -fixAttrubutesInRange: (or -fixFontAttributeInRange:) - the temporary attributes don't get displayed at all.
This seems way harder than it should be. I've now spent the best part of a week on essentially just trying to find the best way to apply temporary attributes to typed text without slowing everything down or causing crashes by intercepting things at the wrong time.
Although NSLayoutManager's -showPackedGlyphs:... provides the perfect override point for applying a different display colour to glyphs, there seems to be no good intercept point for changing the colour of underlines or strikethroughs.
For now, I have reverted to overriding -temporaryAttributesAtCharacterIndex:effectiveRange: and only changing the result if there is an underline or strikethrough at the passed-in index. Given that 10.6 provides a new delegate method, -layoutManager:shouldUseTemporaryAttributes:forDrawingToScreen:atCharacterIndex:effectiveRange:, which allows you to adjust temp attribs, I am guessing that this is the intended override after all, but that it is just hugely inefficient if you change the result too much... Though I'm unconvinced. Only more profiling will tell. :)
Many thanks again and all the best,
Keith
_______________________________________________
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