Permalink
Browse files

Load available fonts into override table

Now the +initialize of DTCoreTextFontDescriptor gets a list of all available fonts and registers them in the override table. This way fonts can be found even if they are not registered in the override plist, in fact the override plist can be reduced or omitted.

This fixes a problem on iOS 5 where some fonts could not be matched if their family name contained a space.

Fixes #365
  • Loading branch information...
1 parent f4c4ff6 commit bba99599a4e65b11889ede2fd11e3766c4d6239c @odrobnik odrobnik committed Mar 30, 2013
Showing with 24 additions and 0 deletions.
  1. +24 −0 Core/Source/DTCoreTextFontDescriptor.m
@@ -7,6 +7,7 @@
//
#import "DTCoreTextFontDescriptor.h"
+#import "DTCoreTextFontCollection.h"
#import "DTVersion.h"
static NSCache *_fontCache = nil;
@@ -16,6 +17,14 @@
// adds "STHeitiSC-Light" font for cascading fix on iOS 5
static BOOL _needsChineseFontCascadeFix = NO;
+@interface DTCoreTextFontDescriptor ()
+
+// gets descriptors of all available fonts from system and registers them as overrides
++ (void)_loadAvailableFontsIntoOverrideTable;
+
+@end
+
+
@implementation DTCoreTextFontDescriptor
{
NSString *_fontFamily;
@@ -41,6 +50,10 @@ + (void)initialize
// init/load of overrides
_fontOverrides = [[NSMutableDictionary alloc] init];
+ // first we load the available system fonts for quick lookup
+ [DTCoreTextFontDescriptor _loadAvailableFontsIntoOverrideTable];
+
+ // then - if it exists - we override from the plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"DTCoreTextFontOverrides" ofType:@"plist"];
NSArray *fileArray = [NSArray arrayWithContentsOfFile:path];
@@ -77,6 +90,17 @@ + (void)initialize
#endif
}
+// gets descriptors of all available fonts from system and registers them as overrides
++ (void)_loadAvailableFontsIntoOverrideTable
+{
+ DTCoreTextFontCollection *allFonts = [DTCoreTextFontCollection availableFontsCollection];
+
+ for (DTCoreTextFontDescriptor *oneFontDescriptor in [allFonts fontDescriptors])
+ {
+ [DTCoreTextFontDescriptor setOverrideFontName:oneFontDescriptor.fontName forFontFamily:oneFontDescriptor.fontFamily bold:oneFontDescriptor.boldTrait italic:oneFontDescriptor.italicTrait];
+ }
+}
+
+ (void)setSmallCapsFontName:(NSString *)fontName forFontFamily:(NSString *)fontFamily bold:(BOOL)bold italic:(BOOL)italic
{
NSString *key = [NSString stringWithFormat:@"%@-%d-%d-smallcaps", fontFamily, bold, italic];

0 comments on commit bba9959

Please sign in to comment.