Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25161] iOS: Add thin, light, ultra-light & semi-bold font-sizes #9308

Merged
merged 4 commits into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions apidoc/Titanium/UI/Font.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ properties:
type: [ Number, String ]
default: 15px
- name: fontWeight
summary: Font weight. Valid values are "bold" or "normal".
description: The "semibold" weight is recognized on iOS only.
summary: |
Font weight. Valid values are "bold", "semibold", "normal", "thin",
"light" and "ultralight".
description: |
The "semibold", "thin", "light" and "ultralight" weights are recognized
on iOS only. "thin", "light" and "ultralight" are only available on iOS 8.2
and later.
type: String
default: normal
- name: fontStyle
Expand Down
21 changes: 20 additions & 1 deletion iphone/Classes/WebFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
CGFloat size;
BOOL isSemiboldWeight;
BOOL isBoldWeight;
BOOL isThinWeight;
BOOL isLightWeight;
BOOL isUltraLightWeight;
BOOL isNormalWeight;
BOOL isItalicStyle;
BOOL isNormalStyle;

UIFont *font;

NSString *textStyle;
Expand Down Expand Up @@ -50,6 +54,21 @@
*/
@property (nonatomic) BOOL isNormalWeight;

/**
Whether or not the font weight is thin.
*/
@property (nonatomic) BOOL isThinWeight;

/**
Whether or not the font weight is light.
*/
@property (nonatomic) BOOL isLightWeight;

/**
Whether or not the font weight is ultra light.
*/
@property (nonatomic) BOOL isUltraLightWeight;

/**
Whether or not the font style is italic.
*/
Expand Down Expand Up @@ -86,7 +105,7 @@

/**
Indicates if the style specified by the string is a valid value for textStyle
@param theStyle The String to check
@param theStyle The String to check
@return _YES_ is it is a valid value for textStyle, _NO_ otherwise
*/
- (BOOL)isValidTextStyle:(NSString *)theStyle;
Expand Down
57 changes: 51 additions & 6 deletions iphone/Classes/WebFont.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@implementation WebFont

@synthesize family, size, isBoldWeight, isNormalWeight, isItalicStyle, isNormalStyle, isSemiboldWeight, textStyle;
@synthesize family, size, isBoldWeight, isNormalWeight, isThinWeight, isLightWeight, isUltraLightWeight, isItalicStyle, isNormalStyle, isSemiboldWeight, textStyle;

- (void)dealloc
{
Expand Down Expand Up @@ -151,7 +151,7 @@ - (UIFont *)font
if (font == nil) {
//NO valid family specified. Just check for characteristics. Semi bold is ignored here.
if (self.isBoldWeight) {
UIFont *theFont = [UIFont boldSystemFontOfSize:self.size];
UIFont *theFont = ([TiUtils isIOSVersionOrGreater:@"8.2"]) ? [UIFont systemFontOfSize:self.size weight:UIFontWeightBold] : [UIFont boldSystemFontOfSize:self.size];
if (self.isItalicStyle) {
NSString *fontFamily = [theFont familyName];
NSArray *fontNames = [UIFont fontNamesForFamilyName:fontFamily];
Expand All @@ -178,13 +178,25 @@ - (UIFont *)font
}
} else if (self.isItalicStyle) {
font = [[UIFont italicSystemFontOfSize:self.size] retain];
} else if ([TiUtils isIOSVersionOrGreater:@"8.2"]) {
if (self.isSemiboldWeight) {
font = [[UIFont systemFontOfSize:self.size weight:UIFontWeightSemibold] retain];
} else if (self.isThinWeight) {
font = [[UIFont systemFontOfSize:self.size weight:UIFontWeightThin] retain];
} else if (self.isLightWeight) {
font = [[UIFont systemFontOfSize:self.size weight:UIFontWeightLight] retain];
} else if (self.isUltraLightWeight) {
font = [[UIFont systemFontOfSize:self.size weight:UIFontWeightUltraLight] retain];
} else {
font = [[UIFont systemFontOfSize:self.size] retain];
}
} else {
font = [[UIFont systemFontOfSize:self.size] retain];
}
}
}
}
//WORST-CASE-SCENARIO
// WORST-CASE-SCENARIO
if (font == nil) {
font = [[UIFont systemFontOfSize:self.size] retain];
}
Expand Down Expand Up @@ -247,20 +259,53 @@ - (BOOL)updateWithDict:(NSDictionary *)fontDict inherits:(WebFont *)inheritedFon
if ([fontWeightObject isKindOfClass:[NSString class]]) {
fontWeightObject = [fontWeightObject lowercaseString];
if ([fontWeightObject isEqualToString:@"semibold"]) {
didChange |= !(self.isSemiboldWeight) || (self.isBoldWeight) || (self.isNormalWeight);
didChange |= !(self.isSemiboldWeight) || (self.isBoldWeight) || (self.isNormalWeight) || (self.isThinWeight) || (self.isLightWeight) || (self.isUltraLightWeight);
self.isSemiboldWeight = YES;
self.isBoldWeight = NO;
self.isNormalWeight = NO;
self.isThinWeight = NO;
self.isLightWeight = NO;
self.isUltraLightWeight = NO;
} else if ([fontWeightObject isEqualToString:@"bold"]) {
didChange |= !(self.isBoldWeight) || (self.isSemiboldWeight) || (self.isNormalWeight);
didChange |= !(self.isBoldWeight) || (self.isSemiboldWeight) || (self.isNormalWeight) || (self.isThinWeight) || (self.isLightWeight) || (self.isUltraLightWeight);
self.isBoldWeight = YES;
self.isSemiboldWeight = NO;
self.isNormalWeight = NO;
self.isThinWeight = NO;
self.isLightWeight = NO;
self.isUltraLightWeight = NO;
} else if ([fontWeightObject isEqualToString:@"thin"]) {
didChange |= !(self.isThinWeight) || (self.isBoldWeight) || (self.isSemiboldWeight) || (self.isNormalWeight) || (self.isLightWeight) || (self.isUltraLightWeight);
self.isThinWeight = YES;
self.isBoldWeight = NO;
self.isSemiboldWeight = NO;
self.isNormalWeight = NO;
self.isLightWeight = NO;
self.isUltraLightWeight = NO;
} else if ([fontWeightObject isEqualToString:@"light"]) {
didChange |= !(self.isLightWeight) || (self.isBoldWeight) || (self.isSemiboldWeight) || (self.isNormalWeight) || (self.isThinWeight) || (self.isUltraLightWeight);
self.isLightWeight = YES;
self.isBoldWeight = NO;
self.isSemiboldWeight = NO;
self.isNormalWeight = NO;
self.isThinWeight = NO;
self.isUltraLightWeight = NO;
} else if ([fontWeightObject isEqualToString:@"ultralight"]) {
didChange |= !(self.isUltraLightWeight) || (self.isBoldWeight) || (self.isSemiboldWeight) || (self.isNormalWeight) || (self.isLightWeight) || (self.isThinWeight);
self.isUltraLightWeight = YES;
self.isBoldWeight = NO;
self.isSemiboldWeight = NO;
self.isNormalWeight = NO;
self.isLightWeight = NO;
self.isThinWeight = NO;
} else if ([fontWeightObject isEqualToString:@"normal"]) {
didChange |= (self.isBoldWeight) || (self.isSemiboldWeight) || !(self.isNormalWeight);
didChange |= (self.isBoldWeight) || (self.isSemiboldWeight) || !(self.isNormalWeight) || (self.isThinWeight) || (self.isLightWeight) || (self.isUltraLightWeight);
self.isBoldWeight = NO;
self.isSemiboldWeight = NO;
self.isNormalWeight = YES;
self.isThinWeight = NO;
self.isLightWeight = NO;
self.isUltraLightWeight = NO;
}
} else if ((inheritedFont != NULL) && (fontWeightObject == nil)) {
BOOL isBoldBool = inheritedFont.isBoldWeight;
Expand Down