| 307 | | if (font == kATSUInvalidFontID) { |
|---|
| 308 | | font = ATSFontFindFromName((CFStringRef)name,kATSOptionFlagsDefault); |
|---|
| 309 | | |
|---|
| 310 | | if (font == kATSUInvalidFontID) font = ATSFontFindFromName((CFStringRef)@"Helvetica",kATSOptionFlagsDefault); |
|---|
| 311 | | } |
|---|
| 312 | | |
|---|
| 313 | | [fontIDCache setValue:[NSNumber numberWithInt:font] forKey:name]; |
|---|
| | 307 | if (font == kATSUInvalidFontID) { // try a case-insensitive search |
|---|
| | 308 | ItemCount fontCount; |
|---|
| | 309 | ATSUFontCount(&fontCount); |
|---|
| | 310 | |
|---|
| | 311 | ATSUFontID fontIDs[fontCount]; |
|---|
| | 312 | ItemCount arraySize = fontCount; |
|---|
| | 313 | ATSUGetFontIDs(fontIDs, arraySize, &fontCount); |
|---|
| | 314 | |
|---|
| | 315 | // I do not want to call ATSUFindFontName twice |
|---|
| | 316 | // so I make the buffer large enough. |
|---|
| | 317 | ByteCount len; |
|---|
| | 318 | ItemCount x, index; |
|---|
| | 319 | const ByteCount kBufLength = 1024; |
|---|
| | 320 | char buf[kBufLength]; |
|---|
| | 321 | |
|---|
| | 322 | for (x = 0; x < fontCount; x++) { |
|---|
| | 323 | ATSUFindFontName(fontIDs[x], kFontFamilyName, kFontMicrosoftPlatform, kFontNoScript, kFontNoLanguage, kBufLength, buf, &len, &index); |
|---|
| | 324 | |
|---|
| | 325 | CFStringRef fname = CFStringCreateWithBytes(NULL,(UInt8 *) buf, len, kCFStringEncodingUnicode, false); |
|---|
| | 326 | if ([name caseInsensitiveCompare:(NSString *) fname] == NSOrderedSame) { |
|---|
| | 327 | font = fontIDs[x]; |
|---|
| | 328 | break; |
|---|
| | 329 | } |
|---|
| | 330 | |
|---|
| | 331 | CFRelease(fname); |
|---|
| | 332 | } |
|---|
| | 333 | |
|---|
| | 334 | if (font == kATSUInvalidFontID) font = ATSFontFindFromName((CFStringRef)name, kATSOptionFlagsDefault); // for bugs in ATS under 10.4 |
|---|
| | 335 | if (font == kATSUInvalidFontID) font = ATSFontFindFromName((CFStringRef)@"Helvetica",kATSOptionFlagsDefault); // final fallback |
|---|
| | 336 | } |
|---|
| | 337 | |
|---|
| | 338 | [fontIDCache setValue:[NSNumber numberWithInt:font] forKey:[name lowercaseString]]; |
|---|