@@ -41,7 +41,8 @@ - (void)DISABLED_testWeight // task #7118691
4141- (void )testSize
4242{
4343 {
44- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue" size: 18.5 ];
44+ UIFont *expected =
45+ [UIFont fontWithName: [UIFont systemFontOfSize: 18.5 ].fontName size: 18.5 ];
4546 UIFont *result = [RCTConvert UIFont: @{@" fontSize" : @18.5 }];
4647 RCTAssertEqualFonts (expected, result);
4748 }
@@ -68,13 +69,33 @@ - (void)testFamily
6869
6970- (void )testStyle
7071{
72+ NSString *systemFontName = [UIFont systemFontOfSize: 14 ].fontName ;
7173 {
72- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue-Italic" size: 14 ];
74+ UIFont *bestMatch = [UIFont fontWithName: systemFontName size: 14 ];
75+ CGFloat closestWeight = INFINITY;
76+
77+ for (NSString *name in [UIFont fontNamesForFamilyName: systemFontName]) {
78+ UIFont *match = [UIFont fontWithName: name size: 14 ];
79+ NSDictionary *traits = [match.fontDescriptor objectForKey: UIFontDescriptorTraitsAttribute];
80+ UIFontDescriptorSymbolicTraits symbolicTraits =
81+ [traits[UIFontSymbolicTrait] unsignedIntValue ];
82+ BOOL isItalic = (symbolicTraits & UIFontDescriptorTraitItalic) != 0 ;
83+ BOOL isCondensed = (symbolicTraits & UIFontDescriptorTraitCondensed) != 0 ;
84+ CGFloat weightOfFont = [traits[UIFontWeightTrait] doubleValue ];
85+
86+ if (isItalic && !isCondensed) {
87+ if (ABS (weightOfFont) < ABS (closestWeight)) {
88+ bestMatch = match;
89+ closestWeight = weightOfFont;
90+ }
91+ }
92+ }
93+ UIFont *expected = [UIFont fontWithName: bestMatch.fontName size: 14 ];
7394 UIFont *result = [RCTConvert UIFont: @{@" fontStyle" : @" italic" }];
7495 RCTAssertEqualFonts (expected, result);
7596 }
7697 {
77- UIFont *expected = [UIFont fontWithName: @" HelveticaNeue " size: 14 ];
98+ UIFont *expected = [UIFont fontWithName: systemFontName size: 14 ];
7899 UIFont *result = [RCTConvert UIFont: @{@" fontStyle" : @" normal" }];
79100 RCTAssertEqualFonts (expected, result);
80101 }
0 commit comments