+
+# else // USE_IPHONE
+
+ NSMutableArray *fonts = [NSMutableArray arrayWithCapacity:100];
+ NSArray *families = [UIFont familyNames];
+ NSMutableDictionary *famdict = [NSMutableDictionary
+ dictionaryWithCapacity:100];
+ NSObject *y = [NSNumber numberWithBool:YES];
+ for (NSString *name in families) {
+ // There are many dups in the families array -- uniquify it.
+ [famdict setValue:y forKey:name];
+ }
+
+ for (NSString *name in famdict) {
+ for (NSString *fn in [UIFont fontNamesForFamilyName:name]) {
+
+# define MATCH(X) \
+ ([fn rangeOfString:X options:NSCaseInsensitiveSearch].location \
+ != NSNotFound)
+
+ BOOL bb = MATCH(@"Bold");
+ BOOL ii = MATCH(@"Italic") || MATCH(@"Oblique");
+
+ if (!bold != !bb) continue;
+ if (!ital != !ii) continue;
+
+ /* Check if it can do ASCII. No good way to accomplish this!
+ These are fonts present in iPhone Simulator as of June 2012
+ that don't include ASCII.
+ */
+ if (MATCH(@"AppleGothic") || // Korean
+ MATCH(@"Dingbats") || // Dingbats
+ MATCH(@"Emoji") || // Emoticons
+ MATCH(@"Geeza") || // Arabic
+ MATCH(@"Hebrew") || // Hebrew
+ MATCH(@"HiraKaku") || // Japanese
+ MATCH(@"HiraMin") || // Japanese
+ MATCH(@"Kailasa") || // Tibetan
+ MATCH(@"Ornaments") || // Dingbats
+ MATCH(@"STHeiti") // Chinese
+ )
+ continue;
+
+ [fonts addObject:fn];
+# undef MATCH
+ }
+ }
+
+ if (! [fonts count]) return 0; // Nothing suitable?
+
+ int i = random() % [fonts count];
+ NSString *name = [fonts objectAtIndex:i];
+ UIFont *ff = [UIFont fontWithName:name size:size];
+ *name_ret = strdup ([name cStringUsingEncoding:NSUTF8StringEncoding]);
+
+ return ff;
+
+# endif // USE_IPHONE