Changeset 866
- Timestamp:
- 04/22/08 22:42:09 (5 months ago)
- Files:
-
- trunk/Subtitles/SubATSUIRenderer.m (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Subtitles/SubATSUIRenderer.m
r864 r866 287 287 } 288 288 289 static NSMutableDictionary *fontIDCache = nil; 290 291 static void CleanupFontIDCache() __attribute__((destructor)); 292 static void CleanupFontIDCache() 293 { 294 if (fontIDCache) [fontIDCache release]; 295 fontIDCache = nil; 296 } 297 289 298 // XXX: Assumes ATSUFontID = ATSFontRef. This is true. 290 // May appear as a memory leak, but it isn't, not really.291 299 static ATSUFontID GetFontIDForSSAName(NSString *name) 292 300 { 293 301 ByteCount nlen = [name length]; 294 302 unichar *uname = (unichar*)[name cStringUsingEncoding:NSUnicodeStringEncoding]; 295 static NSMutableDictionary *fontIDCache = nil;296 303 297 304 if (!fontIDCache) fontIDCache = [[NSMutableDictionary alloc] init]; … … 305 312 ATSUFindFontFromName(uname, nlen * sizeof(unichar), kFontFamilyName, kFontNoPlatformCode, kFontNoScript, kFontNoLanguage, &font); 306 313 314 if (font == kATSUInvalidFontID) font = ATSFontFindFromName((CFStringRef)name, kATSOptionFlagsDefault); // for bugs in ATS under 10.4 307 315 if (font == kATSUInvalidFontID) { // try a case-insensitive search 308 316 ItemCount fontCount; … … 317 325 ByteCount len; 318 326 ItemCount x, index; 319 const ByteCount kBufLength = 1024 ;320 char buf[kBufLength];327 const ByteCount kBufLength = 1024/sizeof(unichar); 328 unichar buf[kBufLength]; 321 329 322 330 for (x = 0; x < fontCount; x++) { 323 ATSUFindFontName(fontIDs[x], kFontFamilyName, kFontMicrosoftPlatform, kFontNoScript, kFontNoLanguage, kBufLength, buf, &len, &index); 331 ATSUFindFontName(fontIDs[x], kFontFamilyName, kFontMicrosoftPlatform, kFontNoScript, kFontNoLanguage, kBufLength, (Ptr)buf, &len, &index); 332 NSString *fname = [NSString stringWithCharacters:buf length:len/sizeof(unichar)]; 324 333 325 CFStringRef fname = CFStringCreateWithBytes(NULL,(UInt8 *) buf, len, kCFStringEncodingUnicode, false); 326 if ([name caseInsensitiveCompare:(NSString *) fname] == NSOrderedSame) { 334 if ([name caseInsensitiveCompare:fname] == NSOrderedSame) { 327 335 font = fontIDs[x]; 328 336 break; 329 337 } 330 331 CFRelease(fname);332 338 } 333 339 334 if (font == kATSUInvalidFontID) font = ATSFontFindFromName((CFStringRef)name, kATSOptionFlagsDefault); // for bugs in ATS under 10.4335 340 if (font == kATSUInvalidFontID) font = ATSFontFindFromName((CFStringRef)@"Helvetica",kATSOptionFlagsDefault); // final fallback 336 341 }
