Skip to content

Commit

Permalink
FIX small crash when no font was defined in the AttributedString and …
Browse files Browse the repository at this point in the history
…we try to set some text in bold.

Note: Despite being related to fonts, this commit does NOT fix issue 89 (which is due to an Apple bug)
  • Loading branch information
AliSoftware committed Sep 26, 2012
1 parent c3ac004 commit bb5abd0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion OHAttributedLabel/NSAttributedString+Attributes.m
Expand Up @@ -226,6 +226,11 @@ -(void)setTextBold:(BOOL)isBold range:(NSRange)range
do {
// Get font at startPoint
CTFontRef currentFont = (BRIDGE_CAST CTFontRef)[self attribute:(BRIDGE_CAST NSString*)kCTFontAttributeName atIndex:startPoint effectiveRange:&effectiveRange];
if (!currentFont)
{
currentFont = CTFontCreateUIFontForLanguage(kCTFontLabelFontType, 0.0, NULL);
[(BRIDGE_CAST id)currentFont autorelease];
}
// The range for which this font is effective
NSRange fontRange = NSIntersectionRange(range, effectiveRange);
// Create bold/unbold font variant for this font and apply
Expand All @@ -239,7 +244,7 @@ -(void)setTextBold:(BOOL)isBold range:(NSRange)range
CFStringRef fontName = CTFontCopyFullName(currentFont);
NSLog(@"[OHAttributedLabel] Warning: can't find a bold font variant for font %@. Try another font family (like Helvetica) instead.",
(BRIDGE_CAST NSString*)fontName);
CFRelease(fontName);
if (fontName) CFRelease(fontName);
}
////[self removeAttribute:(NSString*)kCTFontWeightTrait range:fontRange]; // Work around for Apple leak
////[self addAttribute:(NSString*)kCTFontWeightTrait value:(id)[NSNumber numberWithInt:1.0f] range:fontRange];
Expand Down

0 comments on commit bb5abd0

Please sign in to comment.