Re: Detect/Disable Font Fallbacks in NSLayoutManager
Re: Detect/Disable Font Fallbacks in NSLayoutManager
- Subject: Re: Detect/Disable Font Fallbacks in NSLayoutManager
- From: Chip Bradford <email@hidden>
- Date: Tue, 15 Jul 2008 15:02:45 -0400
On Jul 15, 2008, at 2:13 PM, Douglas Davidson wrote:
On Jul 15, 2008, at 10:54 AM, Chip Bradford wrote:
What seems to be happening is the [NSString
drawAtPoint:withAttributes:] method is happily performing font
substitution to render the missing glyphs, and [NSLayoutManager
glyphAtIndex:] method is giving me the glyphID in that fallback
font as well. However, I have no way of knowing when I'm getting
back glyphIDs from my chosen font and when I'm getting glyphIDs
from the fallback font (nor do I know what that fallback font is)
so I can't figure out how I would go about looking up the correct
bounding boxes. (I end up looking up the bounding-box for the
glyphID in the wrong font).
You can get the substituted font easily--just ask the text storage
for the value of the font attribute for the corresponding
character. However, you might be better off asking the layout
manager for geometry information rather than asking the font for the
bounding box. In general, of course, you can't assume a one-to-one
correspondence between characters and glyphs, so single-character
strings won't reproduce all of the features of general layout.
Douglas Davidson
Perfect! Thank you :)
I'm now doing this:
NSFont *actualFont = [textStorage attribute:NSFontAttributeName
atIndex:0 effectiveRange:NULL];
NSRect rect = [actualFont boundingRectForGlyph:[layoutManager
glyphAtIndex:0]];
which seems to be doing exactly what I want.
I had tried using the NSLayoutManager methods initially to get the
font metrics I wanted, but those seemed to only return the typographic
bounding boxes and what I want is the actual image rectangles. For a
while I thought I might have to fall back to ATSUI for the
ATSUMeasureTextImage() function to get what I wanted, but then I found
the font method.
I'm also definitely aware of the potential complexities when mapping
characters to glyphs in general. However, in the end I'm basically
implementing a text rendering system in OpenGL and this program is
just to generate a texture that I can use to draw the glyphs with. I'm
targeting the iPhone, so I can't really use several MB worth of
textures to support Unicode character set with complicated ligatures,
etc anyway, so simplifying things is just fine for what I'm doing.
Thanks again,
- Chip
_______________________________________________
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