-drawInRect: variant is designed for matching the field editor layout. -drawWithRect: variant is the base and should be used over the other two.
Aki Inoue On 2011/01/03, at 16:45, George Nachman <gnach...@llamas.org> wrote: > On Mon, Jan 3, 2011 at 1:47 PM, Wim Lewis <w...@omnigroup.com> wrote: >> >> On 2 Jan 2011, at 1:23 PM, George Nachman wrote: >>> I'm using CGContextShowGlyphsWithAdvances to render fixed-width text >>> because it is very fast. If a glyph is missing, I use >>> CTFontCreateForString() to pick a better font, and that usually works. >>> I ran into a case that I just can't solve with this technique [...] >> >> Do you need layout+rendering to be fast, or just rendering? If the latter, >> for example if you're drawing a fixed string multiple times, you could use a >> higher level routine to do the layout (e.g. CTTypesetterCreateLine() or >> CTLineCreateWithAttributedString()) and then extract the glyphs, offsets, so >> on from the typeset line to draw with CGContextShowGlyphsWithAdvances(). >> >> (Actually I'd be surprised if CGContextShowGlyphsWithAdvances() is much >> faster than CTLineDraw() --- I'd guess that simply caching the typeset line >> will get you most of the available speedup.) > > It's rare that I have text that requires layout. 99% is plain old > ASCII. It's not fixed text but I don't mind having a slower code path > for more complex text. > > I tried using CTLineCreateWithAttributedString() and then rendering it > with CTLineDraw() but it still fails to draw certain glyphs. For > example, U+23B7: RADICAL SYMBOL BOTTOM appears as a box (the missing > glyph symbol). It exists in the "Apple Symbols" font, but I guess it's > just using the font I requested. If I use -[NSAttributedString > drawInRect:], it can render the glyph, despite my specifying > AndaleMono as the font. I wish I could do all my text drawing with > -[NSAttributedString drawInRect:], but it is very slow. I tried using > that call for only "problem" characters and > CGContextShowGlyphsWithAdvances for "normal" characters, but I can't > get the baselines to line up correctly (the attributed string draws a > few pixels lower for some reason). If I could get the baselines to > match up, this would be an ideal solution. > > Another smaller issue is that CTLineCreateWithAttributedString() + > CTLineDraw() doesn't perform layout as nicely as -[NSAttributedString > drawInRect:] in some edge cases. For instance, the sequence U+0061 > U+20D1 (where the latter is COMBINING RIGHT HARPOON ABOVE) draws the > diacritic through the top of the letter, while -[NSAttributedString > drawInRect:] places it just above the letter. > _______________________________________________ > > 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/aki%40apple.com > > This email sent to a...@apple.com _______________________________________________ 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