Skip to content

Commit

Permalink
Fabric: Add font variant support (facebook#44112)
Browse files Browse the repository at this point in the history
Summary:
Fixes facebook#44064

## Changelog:

[IOS] [FIXED] - [iOS] Fabric: Add font variant support

Pull Request resolved: facebook#44112

Test Plan: Demo in facebook#44064 .

Reviewed By: cortinico

Differential Revision: D56189145

Pulled By: cipolleschi

fbshipit-source-id: a814cf4959b0160e36f79eaf6c7dcbffe5ef60c5
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Apr 16, 2024
1 parent 8a343c6 commit 89eb794
Showing 1 changed file with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
*/

#import "RCTFontUtils.h"
#import <CoreText/CoreText.h>

#import <algorithm>
#import <cmath>
#import <limits>
#import <map>
#import <mutex>

static RCTFontProperties RCTDefaultFontProperties()
Expand Down Expand Up @@ -62,8 +64,51 @@ static RCTFontStyle RCTGetFontStyle(UIFont *font)

static NSArray *RCTFontFeatures(RCTFontVariant fontVariant)
{
// FIXME:
return @[];
NSMutableArray *fontFeatures = [NSMutableArray array];
static std::map<RCTFontVariant, NSDictionary *> mapping;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
mapping = {
{RCTFontVariantSmallCaps, @{
UIFontFeatureTypeIdentifierKey : @(kLowerCaseType),
UIFontFeatureSelectorIdentifierKey : @(kLowerCaseSmallCapsSelector),
}},
{RCTFontVariantOldstyleNums, @{
UIFontFeatureTypeIdentifierKey : @(kNumberCaseType),
UIFontFeatureSelectorIdentifierKey : @(kLowerCaseNumbersSelector),
}},
{RCTFontVariantLiningNums, @{
UIFontFeatureTypeIdentifierKey : @(kNumberCaseType),
UIFontFeatureSelectorIdentifierKey : @(kUpperCaseNumbersSelector),
}},
{RCTFontVariantTabularNums, @{
UIFontFeatureTypeIdentifierKey : @(kNumberSpacingType),
UIFontFeatureSelectorIdentifierKey : @(kMonospacedNumbersSelector),
}},
{RCTFontVariantProportionalNums, @{
UIFontFeatureTypeIdentifierKey : @(kNumberSpacingType),
UIFontFeatureSelectorIdentifierKey : @(kProportionalNumbersSelector),
}},
};
});

if (fontVariant & RCTFontVariantSmallCaps) {
[fontFeatures addObject:mapping[RCTFontVariantSmallCaps]];
}
if (fontVariant & RCTFontVariantOldstyleNums) {
[fontFeatures addObject:mapping[RCTFontVariantOldstyleNums]];
}
if (fontVariant & RCTFontVariantLiningNums) {
[fontFeatures addObject:mapping[RCTFontVariantLiningNums]];
}
if (fontVariant & RCTFontVariantTabularNums) {
[fontFeatures addObject:mapping[RCTFontVariantTabularNums]];
}
if (fontVariant & RCTFontVariantProportionalNums) {
[fontFeatures addObject:mapping[RCTFontVariantProportionalNums]];
}

return fontFeatures;
}

static UIFont *RCTDefaultFontWithFontProperties(RCTFontProperties fontProperties)
Expand Down

0 comments on commit 89eb794

Please sign in to comment.