Skip to content

Commit

Permalink
feat(ios): support font scaling for custom fonts (#11364)
Browse files Browse the repository at this point in the history
Fixes TIMOB-25847
  • Loading branch information
vijaysingh-axway authored and sgtcoolguy committed Dec 18, 2019
1 parent 6e7604f commit 8045620
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions apidoc/Titanium/UI/Font.yml
Expand Up @@ -100,6 +100,10 @@ properties:
description: |
Use one of the TEXT_STYLE constants from <Titanium.UI> to set the font to a predefined system font.
When this property is set to a valid value, all other font properties are ignored.
Notes:
Since SDK 9.0.0 property <Font.fontFamily> will not be ignored for iOS 11+.
Custom fonts can be used with this property for dynamic font management.
type: String
constants: Titanium.UI.TEXT_STYLE_*
platforms: [iphone, ipad]
Expand Down
15 changes: 10 additions & 5 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/WebFont.m
Expand Up @@ -36,8 +36,15 @@ - (BOOL)isSizeNotSet

- (UIFont *)font
{
// TO DO: Refactor this function
if (font == nil) {
if (textStyle != nil && [textStyle isKindOfClass:[NSString class]]) {
if (textStyle != nil && [textStyle isKindOfClass:[NSString class]] && family != nil && [TiUtils isIOSVersionOrGreater:@"11.0"]) {
UIFont *tempFont = [UIFont fontWithName:family size:self.size];
if (tempFont) {
UIFontMetrics *fontMetrics = [UIFontMetrics metricsForTextStyle:textStyle];
font = [[fontMetrics scaledFontForFont:tempFont] retain];
}
} else if (textStyle != nil && [textStyle isKindOfClass:[NSString class]]) {
font = [[UIFont preferredFontForTextStyle:textStyle] retain];
} else {
if (family != nil) {
Expand Down Expand Up @@ -126,7 +133,7 @@ - (UIFont *)font
if (font == nil) {
//NO valid family specified. Just check for characteristics. Semi bold is ignored here.
if (self.isBoldWeight) {
UIFont *theFont = ([TiUtils isIOSVersionOrGreater:@"8.2"]) ? [UIFont systemFontOfSize:self.size weight:UIFontWeightBold] : [UIFont boldSystemFontOfSize:self.size];
UIFont *theFont = [UIFont systemFontOfSize:self.size weight:UIFontWeightBold];
if (self.isItalicStyle) {
NSString *fontFamily = [theFont familyName];
NSArray *fontNames = [UIFont fontNamesForFamilyName:fontFamily];
Expand All @@ -153,7 +160,7 @@ - (UIFont *)font
}
} else if (self.isItalicStyle) {
font = [[UIFont italicSystemFontOfSize:self.size] retain];
} else if ([TiUtils isIOSVersionOrGreater:@"8.2"]) {
} else {
if (self.isSemiboldWeight) {
font = [[UIFont systemFontOfSize:self.size weight:UIFontWeightSemibold] retain];
} else if (self.isThinWeight) {
Expand All @@ -165,8 +172,6 @@ - (UIFont *)font
} else {
font = [[UIFont systemFontOfSize:self.size] retain];
}
} else {
font = [[UIFont systemFontOfSize:self.size] retain];
}
}
}
Expand Down

0 comments on commit 8045620

Please sign in to comment.