On 20/10/2009, at 11:03 PM, Ben Haller wrote:

AFAIK even -[NSAttributedString drawWithRect:options:] doesn't let you draw a string centered or right-aligned in the rect, which seems like a big oversight. I've just logged 7318495 on that.


That's not the case - NSAttributedString takes its left/right/center/ justified setting from the NSParagraphStyle attribute attached to the string. If it's not there, it defaults to natural alignment for the font (left for English).

I.e. I'm trying to understand what the tradeoffs are here.

Convenience versus speed. Setting up a text layout system programatically is quite involved, and for a high-level solution that is equivalent to olde-worlde DrawThemeTextBox the string drawing methods do that for you. But they have to build up and tear down a text system for every call, so incur this overhead and can't cache any layout information. I still think it's the case (borne out by profiling here) that glyph rendering still dominates the process however.

But if you're drawing text left-aligned, and thus don't need to measure it, is there any speedup doing things yourself?

Yes, if you are drawing the same string over and over again (as in repeated refreshes of the same string in a view). The question is whether the speed-up matters. If you have thousands of text objects in your view, probably yes. If just one or two, probably not. There's no need to (and you can't) draw faster than 60 fps so you have ~16mS to draw everything. If it takes longer, text caching etc may help.

--Graham


_______________________________________________

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