Detect/Disable Font Fallbacks in NSLayoutManager
Detect/Disable Font Fallbacks in NSLayoutManager
- Subject: Detect/Disable Font Fallbacks in NSLayoutManager
- From: Chip Bradford <email@hidden>
- Date: Tue, 15 Jul 2008 13:54:20 -0400
I'm working on a program to generate bitmap font textures to use with
OpenGL to render text. I have things mostly working, but I seem to run
into issues when a font doesn't contain a glyph for a certain
character and OS X uses a fallback font to render the glyph (at least,
I believe this is what's happening).
My basic setup is that I have a bunch of single character strings,
each with their own NSLayoutManager, NSTextStorage, and
NSTextContainer. I loop through these objects to get a bounding
rectangle for each character, and then draw the character to an
NSBitmapImageRep.
The important bits are:
NSFont *myFont = [[NSFontManager sharedFontManager] selectedFont];
NSDictionary * attsDict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSColor whiteColor], NSForegroundColorAttributeName,
myFont, NSFontAttributeName,
nil];
textStorage.font = myFont;
NSRect rect = [myFont boundingRectForGlyph:[layoutManager
glyphAtIndex:0]];
[textStorage.string drawAtPoint:drawPoint withAttributes:attsDict];
This works great for normal characters in normal fonts, but when I
tried a font like Computer Modern (which doesn't even contain a full
set of ascii characters in a single font file) I still get all the
characters to render, but the bounding boxes for some are wrong.
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).
Looking through the docs, it appears that I can disable font fallbacks
if I switch to using ATSUI methods, but I'd really like to stick with
the AppKit objects if possible. Is there any way to either disable an
NSLayoutManager from using fallback fonts (so it just renders a dummy
or blank glyph) or to detect when the fallback is happening so I have
a chance to compute the correct bounding boxes in those cases?
Thanks,
- 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