Skip to content
This repository
Browse code

Lock for font actions

  • Loading branch information...
commit dce97b9e7521721f374c32d70e8f56ed681e4903 1 parent 7ef4451
David Hoerl dhoerl authored

Showing 1 changed file with 24 additions and 4 deletions. Show diff stats Hide diff stats

  1. +24 4 Classes/DTCoreTextFontDescriptor.m
28 Classes/DTCoreTextFontDescriptor.m
@@ -11,10 +11,22 @@
11 11 static DTCache *_fontCache = nil;
12 12 static NSMutableDictionary *_fontOverrides = nil;
13 13
  14 +@interface DTCoreTextFontDescriptor ()
  15 +{
  16 + CTFontRef fontRef;
  17 +}
  18 +- (void)_newMatchingFont;
14 19
15   -@implementation DTCoreTextFontDescriptor
  20 +@end
  21 +
  22 +static pthread_mutex_t mutex;
16 23
  24 +@implementation DTCoreTextFontDescriptor
17 25
  26 ++ (void)initialize
  27 +{
  28 + pthread_mutex_init(&mutex, NULL);
  29 +}
18 30
19 31 + (DTCache *)fontCache
20 32 {
@@ -395,6 +407,14 @@ - (BOOL)supportsNativeSmallCaps
395 407
396 408 - (CTFontRef)newMatchingFont
397 409 {
  410 + pthread_mutex_lock(&mutex);
  411 + [self performSelectorOnMainThread:@selector(_newMatchingFont) withObject:nil waitUntilDone:YES];
  412 + pthread_mutex_unlock(&mutex);
  413 + return fontRef;
  414 +}
  415 +
  416 +- (void)_newMatchingFont
  417 +{
398 418 NSDictionary *attributes = [self fontAttributes];
399 419
400 420 DTCache *fontCache = [DTCoreTextFontDescriptor fontCache];
@@ -405,7 +425,8 @@ - (CTFontRef)newMatchingFont
405 425 if (cachedFont)
406 426 {
407 427 CFRetain(cachedFont);
408   - return cachedFont;
  428 + fontRef = cachedFont;
  429 + return;
409 430 }
410 431
411 432 CTFontDescriptorRef fontDesc = NULL;
@@ -414,7 +435,6 @@ - (CTFontRef)newMatchingFont
414 435
415 436 NSString *usedName = fontName;
416 437
417   -
418 438 // override fontName if a small caps or regular override is registered
419 439 if (fontFamily)
420 440 {
@@ -487,7 +507,7 @@ - (CTFontRef)newMatchingFont
487 507 [fontCache setObject:(id)matchingFont forKey:cacheKey];
488 508 }
489 509
490   - return matchingFont;
  510 + fontRef = matchingFont;
491 511 }
492 512
493 513 - (void)normalizeSlow

0 comments on commit dce97b9

Please sign in to comment.
Something went wrong with that request. Please try again.