views:

181

answers:

3

Is there a way to detect whether a Unicode character is present in a font on the iPhone, i.e., to detect whether the character will map to a printable glyph or instead to the square "missing character" symbol?

For example, if I want to generate a random Wingding character with this snippet:

NSString *s = [NSString stringWithFormat:@"%C", (0x2700 + (arc4random() % 0x0100))];

is there a way to tell if the generated string will render as the little square, or a real glyph when I draw it with this:

[s drawAtPoint:x withFont:[UIFont systemFontOfSize:30]];

Thanks!

...R

A: 

I don't know of any method that checks for this specifically, however I imagine it'd be possible to set up an NSDictionary with paired values for each table of characters encoded into Unicode, then run a check to ensure that the generated value falls within the ranges specified by one of the paired values.

Kaji
+1  A: 

NSFont has a property coveredCharacterSet that UIFont does not have. So I would recommend to use your desktop PC to create the coveredCharacterSet information and put it into your iphone app.

A list of fonts that are available on the iphone can be found at: http://daringfireball.net/misc/2007/07/iphone-osx-fonts

f3lix
A: 

Why not generate it on your computer, if you're using the system font it should be Helvetica and there's the character maps in the Font menu option of almost any program.

JoePasq