Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/jcbertin/DTCoreText into…
Browse files Browse the repository at this point in the history
… jcbertin-develop
  • Loading branch information
odrobnik committed Oct 17, 2014
2 parents dd63c7c + c4d5531 commit 92118c1
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 123 deletions.
46 changes: 23 additions & 23 deletions Core/Source/DTCoreTextFontDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -462,45 +462,45 @@ - (BOOL)supportsNativeSmallCaps
return YES;
}

CTFontRef tmpFont = [self newMatchingFont];

BOOL smallCapsSupported = NO;

// check if this font supports small caps
CFArrayRef fontFeatures = CTFontCopyFeatures(tmpFont);
CTFontRef tmpFont = [self newMatchingFont];

if (fontFeatures)
if (tmpFont)
{
for (NSDictionary *oneFeature in (__bridge NSArray *)fontFeatures)
// check if this font supports small caps
CFArrayRef fontFeatures = CTFontCopyFeatures(tmpFont);

if (fontFeatures)
{
NSInteger featureTypeIdentifier = [[oneFeature objectForKey:(id)kCTFontFeatureTypeIdentifierKey] integerValue];

if (featureTypeIdentifier == 3) // Letter Case
for (NSDictionary *oneFeature in (__bridge NSArray *)fontFeatures)
{
NSArray *featureSelectors = [oneFeature objectForKey:(id)kCTFontFeatureTypeSelectorsKey];
NSInteger featureTypeIdentifier = [[oneFeature objectForKey:(id)kCTFontFeatureTypeIdentifierKey] integerValue];

for (NSDictionary *oneFeatureSelector in featureSelectors)
if (featureTypeIdentifier == 3) // Letter Case
{
NSInteger featureSelectorIdentifier = [[oneFeatureSelector objectForKey:(id)kCTFontFeatureSelectorIdentifierKey] integerValue];
NSArray *featureSelectors = [oneFeature objectForKey:(id)kCTFontFeatureTypeSelectorsKey];

if (featureSelectorIdentifier == 3) // Small Caps
for (NSDictionary *oneFeatureSelector in featureSelectors)
{
// hooray, small caps supported!
smallCapsSupported = YES;
NSInteger featureSelectorIdentifier = [[oneFeatureSelector objectForKey:(id)kCTFontFeatureSelectorIdentifierKey] integerValue];

break;
if (featureSelectorIdentifier == 3) // Small Caps
{
// hooray, small caps supported!
smallCapsSupported = YES;

break;
}
}

break;
}

break;
}

CFRelease(fontFeatures);
}

CFRelease(fontFeatures);
}

if (tmpFont)
{
CFRelease(tmpFont);
}

Expand Down
117 changes: 61 additions & 56 deletions Core/Source/DTHTMLElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -867,64 +867,69 @@ - (void)applyStyleDictionary:(NSDictionary *)styles

// check if this is a known font family
CTFontRef font = [_fontDescriptor newMatchingFont];
NSString *foundFamily = CFBridgingRelease(CTFontCopyFamilyName(font));

if ([foundFamily isEqualToString:fontFamily])
if (font)
{
foundFontFamily = YES;
break;
}

NSString *lowercaseFontFamily = [fontFamily lowercaseString];

if ([lowercaseFontFamily rangeOfString:@"geneva"].length)
{
_fontDescriptor.fontFamily = @"Helvetica";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"cursive"].length)
{
_fontDescriptor.stylisticClass = kCTFontScriptsClass;
_fontDescriptor.fontFamily = nil;
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"sans-serif"].length)
{
// too many matches (24)
// fontDescriptor.stylisticClass = kCTFontSansSerifClass;
_fontDescriptor.fontFamily = @"Helvetica";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"serif"].length)
{
// kCTFontTransitionalSerifsClass = Baskerville
// kCTFontClarendonSerifsClass = American Typewriter
// kCTFontSlabSerifsClass = Courier New
//
// strangely none of the classes yields Times
_fontDescriptor.fontFamily = @"Times New Roman";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"fantasy"].length)
{
_fontDescriptor.fontFamily = @"Papyrus"; // only available on iPad
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"monospace"].length)
{
_fontDescriptor.monospaceTrait = YES;
_fontDescriptor.fontFamily = @"Courier";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"times"].length)
{
_fontDescriptor.fontFamily = @"Times New Roman";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily isEqualToString:@"inherit"])
{
_fontDescriptor.fontFamily = self.parentElement.fontDescriptor.fontFamily;
foundFontFamily = YES;
NSString *foundFamily = CFBridgingRelease(CTFontCopyFamilyName(font));
CFRelease(font);

if ([foundFamily isEqualToString:fontFamily])
{
foundFontFamily = YES;
break;
}

NSString *lowercaseFontFamily = [fontFamily lowercaseString];

if ([lowercaseFontFamily rangeOfString:@"geneva"].length)
{
_fontDescriptor.fontFamily = @"Helvetica";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"cursive"].length)
{
_fontDescriptor.stylisticClass = kCTFontScriptsClass;
_fontDescriptor.fontFamily = nil;
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"sans-serif"].length)
{
// too many matches (24)
// fontDescriptor.stylisticClass = kCTFontSansSerifClass;
_fontDescriptor.fontFamily = @"Helvetica";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"serif"].length)
{
// kCTFontTransitionalSerifsClass = Baskerville
// kCTFontClarendonSerifsClass = American Typewriter
// kCTFontSlabSerifsClass = Courier New
//
// strangely none of the classes yields Times
_fontDescriptor.fontFamily = @"Times New Roman";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"fantasy"].length)
{
_fontDescriptor.fontFamily = @"Papyrus"; // only available on iPad
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"monospace"].length)
{
_fontDescriptor.monospaceTrait = YES;
_fontDescriptor.fontFamily = @"Courier";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"times"].length)
{
_fontDescriptor.fontFamily = @"Times New Roman";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily isEqualToString:@"inherit"])
{
_fontDescriptor.fontFamily = self.parentElement.fontDescriptor.fontFamily;
foundFontFamily = YES;
}
}

if (foundFontFamily)
Expand Down
23 changes: 13 additions & 10 deletions Core/Source/DTListItemHTMLElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,21 @@ - (NSAttributedString *)_listPrefix

CTFontRef font = [fontDescriptor newMatchingFont];

#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
if (___useiOS6Attributes)
if (font)
{
UIFont *uiFont = [UIFont fontWithCTFont:font];
[newAttributes setObject:uiFont forKey:NSFontAttributeName];

CFRelease(font);
}
else
#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
if (___useiOS6Attributes)
{
UIFont *uiFont = [UIFont fontWithCTFont:font];
[newAttributes setObject:uiFont forKey:NSFontAttributeName];

CFRelease(font);
}
else
#endif
{
[newAttributes setObject:CFBridgingRelease(font) forKey:(id)kCTFontAttributeName];
{
[newAttributes setObject:CFBridgingRelease(font) forKey:(id)kCTFontAttributeName];
}
}

CGColorRef textColor = (__bridge CGColorRef)[attributes objectForKey:(id)kCTForegroundColorAttributeName];
Expand Down
30 changes: 17 additions & 13 deletions Core/Source/DTTextHTMLElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,26 @@ - (NSAttributedString *)attributedString
{
DTCoreTextFontDescriptor *smallDesc = [self.fontDescriptor copy];
smallDesc.smallCapsFeature = YES;

CTFontRef smallerFont = [smallDesc newMatchingFont];

NSMutableDictionary *smallAttributes = [attributes mutableCopy];

#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && TARGET_OS_IPHONE
if (___useiOS6Attributes)

CTFontRef smallerFont = [smallDesc newMatchingFont];

if (smallerFont)
{
UIFont *font = [UIFont fontWithCTFont:smallerFont];

[smallAttributes setObject:font forKey:NSFontAttributeName];
CFRelease(smallerFont);
}
else
#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && TARGET_OS_IPHONE
if (___useiOS6Attributes)
{
UIFont *font = [UIFont fontWithCTFont:smallerFont];

[smallAttributes setObject:font forKey:NSFontAttributeName];
CFRelease(smallerFont);
}
else
#endif
{
[smallAttributes setObject:CFBridgingRelease(smallerFont) forKey:(id)kCTFontAttributeName];
{
[smallAttributes setObject:CFBridgingRelease(smallerFont) forKey:(id)kCTFontAttributeName];
}
}

return [[NSAttributedString alloc] initWithString:_text attributes:smallAttributes];
Expand Down
23 changes: 13 additions & 10 deletions Core/Source/NSAttributedString+DTCoreText.m
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,21 @@ + (NSAttributedString *)prefixForListItemWithCounter:(NSUInteger)listCounter lis

font = [fontDesc newMatchingFont];

#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
if (___useiOS6Attributes)
if (font)
{
UIFont *uiFont = [UIFont fontWithCTFont:font];
[newAttributes setObject:uiFont forKey:NSFontAttributeName];

CFRelease(font);
}
else
#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
if (___useiOS6Attributes)
{
UIFont *uiFont = [UIFont fontWithCTFont:font];
[newAttributes setObject:uiFont forKey:NSFontAttributeName];

CFRelease(font);
}
else
#endif
{
[newAttributes setObject:CFBridgingRelease(font) forKey:(id)kCTFontAttributeName];
{
[newAttributes setObject:CFBridgingRelease(font) forKey:(id)kCTFontAttributeName];
}
}
}

Expand Down
25 changes: 14 additions & 11 deletions Core/Source/NSMutableAttributedString+HTML.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,22 @@ - (void)appendString:(NSString *)string withParagraphStyle:(DTCoreTextParagraphS
{
CTFontRef newFont = [fontDescriptor newMatchingFont];

#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && TARGET_OS_IPHONE
if (___useiOS6Attributes)
if (newFont)
{
// convert to UIFont
UIFont *uiFont = [UIFont fontWithCTFont:newFont];
[attributes setObject:uiFont forKey:NSFontAttributeName];

CFRelease(newFont);
}
else
#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && TARGET_OS_IPHONE
if (___useiOS6Attributes)
{
// convert to UIFont
UIFont *uiFont = [UIFont fontWithCTFont:newFont];
[attributes setObject:uiFont forKey:NSFontAttributeName];

CFRelease(newFont);
}
else
#endif
{
[attributes setObject:CFBridgingRelease(newFont) forKey:(id)kCTFontAttributeName];
{
[attributes setObject:CFBridgingRelease(newFont) forKey:(id)kCTFontAttributeName];
}
}
}

Expand Down

0 comments on commit 92118c1

Please sign in to comment.