Skip to content

Commit

Permalink
fix(ios): return weight of zero for invalid font
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifanyuan authored and wwwcg committed Dec 26, 2023
1 parent a6b0e04 commit 5328610
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions renderer/native/ios/renderer/HippyFont.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ static NativeRenderFontWeight weightOfFont(UIFont *font) {
};

NSString *fontName = font.fontName;
if(fontName == nil){
return 0.0;
}
CFStringCompareFlags options = kCFCompareCaseInsensitive | kCFCompareAnchored | kCFCompareBackwards;
for(int i = 0; i < sizeof(suffixToWeight) / sizeof(suffixToWeight[0]); ++i){
struct SuffixWeight item = suffixToWeight[i];
Expand All @@ -78,11 +81,11 @@ static NativeRenderFontWeight weightOfFont(UIFont *font) {
}

static BOOL isItalicFont(UIFont *font) {
return (CTFontGetSymbolicTraits((CTFontRef)font) & kCTFontTraitItalic) != 0;
return font != nil && (CTFontGetSymbolicTraits((CTFontRef)font) & kCTFontTraitItalic) != 0;
}

static BOOL isCondensedFont(UIFont *font) {
return (CTFontGetSymbolicTraits((CTFontRef)font) & kCTFontTraitCondensed) != 0;
return font != nil && (CTFontGetSymbolicTraits((CTFontRef)font) & kCTFontTraitCondensed) != 0;
}

static UIFont *cachedSystemFont(CGFloat size, NativeRenderFontWeight weight) {
Expand Down

0 comments on commit 5328610

Please sign in to comment.