The iPhone doesn't have very many built in fonts. Is there a way to embed fonts inside your program to display?
There's actually a thread on the Cocoa-dev mailing list going around about this. The same plist key would probably work on the OSX side, although the bundling is a bit different for iPhone.
http://www.cocoabuilder.com/archive/message/cocoa/2008/4/6/203410
http://developer.apple.com/document...PListKeys.html/apple_ref/doc/uid/20001431-SW8
See where that'll get ya.
Just in case anyone wanted the solution to this problem, all you need to do to display the correct characters is make the CGGlyph = (the decimal value of your character - 29)
Example: Say if you want to print a capital A.
You would want to set your CGGlyph = 65(Decimal value of A) - 29;
Then call CGContextShowGlyphsAtPoint or CGContextShowGlyphs as appropriate.
I have no idea as to why 29 is the magic number but there is your solution as to how to load and display(correctly) a custom font in a .ttf format = )
An index into the internal glyph table of a font.
The cmap table is used to convert from an outside encoding (such as Unicode) to internal glyph ids.
NSTextStorage
setFont
You have to pass an NSFont to this. This might complicate things because you have a CGFontRef, but hopefully it's easy to get the NSFont pretty similarly.
setCharacters
Pass an NSArray of characters. I would just pass in 0-127 or 0-256
NSLayoutManager
glyphIndexForCharacterAtIndex
You should be able to pass in a character index (which would just be the ascii values or unicode code points) and get the glyph back. it will be a NSUInteger, but you should be able to cast that to a CGGlyph. The CGGlyph is an unsigned short, not an integer, but I think the cast should do it.
void GetGlyphsForUniChars( const UtilStr& inTypefaceName, const UniChar inChars[], int inNumChars, CGGlyph outGlyphs[] ) {
// A negative length denotes that inChars[] is NUL terminated.
if ( inNumChars < 0 ) {
inNumChars = 0;
while ( inChars && inChars[ inNumChars ] )
inNumChars++;
}
if ( inNumChars <= 0 )
return;
NSString* srcChars = [ NSString stringWithCharacters: inChars length: inNumChars ];
NSString* fontName = [ NSString stringWithUTF8String: inTypefaceName.CStr() ];
NSFont* font = [ NSFont fontWithName:fontName size:0 ];
NSTextStorage* textStorage = [[ NSTextStorage alloc ] initWithString: srcChars ];
if ( font ) {
[ textStorage setFont: font ];
} else {
ss_break();
}
NSLayoutManager* layoutMgr = [[ NSLayoutManager alloc ] init ];
[ textStorage addLayoutManager: layoutMgr ];
// Unicode strings can be arbitraily complex and all kinds of reordering and glyph combination can occur (including consolidation to fewer glyphs).
// We assume below that one unicode char maps to one glyph and that they occur in order. Since this assuption doesn't hold for asian languages,
// we must be careful. Fortunately, for typical western fonts and the text we intend to convert, this is good enough.
SInt32 numGlyphs = [ layoutMgr numberOfGlyphs ];
ss_assert( (int) numGlyphs == inNumChars );
NSGlyph* nsglyphs = (NSGlyph*) ss_malloc( sizeof( NSGlyph ) * numGlyphs );
NSRange range = { 0, numGlyphs };
[ layoutMgr getGlyphsInRange : range glyphs: nsglyphs characterIndexes:NULL glyphInscriptions:NULL elasticBits:NULL ];
{
int i;
for ( i = 0; i < numGlyphs; i++ ) {
if ( nsglyphs[ i ] < 0xFFFF ) {
outGlyphs[ i ] = (CGGlyph) nsglyphs[ i ];
} else {
outGlyphs[ i ] = 0;
}
}
for ( ; i < inNumChars; i++ ) {
outGlyphs[ i ] = 0;
}
}
ss_free( nsglyphs );
nsglyphs = NULL;
[ layoutMgr release ];
[ textStorage release ];
}