Skip to content

Commit fb942ae

Browse files
committed
fix: font style
1 parent a5aceb1 commit fb942ae

14 files changed

Lines changed: 163 additions & 71 deletions

File tree

packages/font-manager/font-face.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class FontFace {
233233
}
234234

235235
get style() {
236-
return this.native_.fontDescriptors.style;
236+
return NSCFontStyleToString(this.native_.fontDescriptors.style);
237237
}
238238

239239
set style(value: string) {

packages/font-manager/nativescript.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
{
77
name: 'FontManager',
88
libs: ['FontManager'],
9-
version: '1.0.4',
9+
version: '1.0.5',
1010
repositoryURL: 'https://github.com/NativeScript/font-manager.git',
1111
},
1212
],

packages/font-manager/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/font-manager",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "A NativeScript plugin for managing fonts",
55
"main": "index",
66
"types": "index.d.ts",

packages/font-manager/src-native/ios/FontManager/Sources/FontManager/NSCFontDescriptors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NS_ASSUME_NONNULL_BEGIN
77

88
@property (nonatomic) NSCFontWeight weight;
99
@property (nonatomic, copy) NSString *family;
10-
@property (nonatomic, copy) NSString *style;
10+
@property (nonatomic) NSCFontStyle style;
1111
@property (nonatomic, copy, nullable) NSString *obliqueAngle;
1212
@property (nonatomic, copy) NSString *variant;
1313
@property (nonatomic, copy) NSString *ascentOverride;

packages/font-manager/src-native/ios/FontManager/Sources/FontManager/NSCFontDescriptors.m

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ - (instancetype)initWithFamily:(NSString *)family {
99
if (self) {
1010
_weight = NSCFontWeightNormal;
1111
_family = [family copy];
12-
_style = @"normal";
12+
_style = NSCFontStyleNormal;
1313
_obliqueAngle = nil;
1414
_variant = @"normal";
1515
_ascentOverride = @"normal";
@@ -169,19 +169,15 @@ - (void)setFontStyleFromString:(NSString *)value {
169169
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
170170

171171
if ([trimmed hasPrefix:@"oblique"]) {
172-
_style = @"oblique";
173-
174-
NSString *rest = [trimmed substringFromIndex:@"oblique".length];
175-
rest = [rest stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
176-
172+
_style = NSCFontStyleOblique;
173+
NSString *rest = [[trimmed substringFromIndex:@"oblique".length]
174+
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
177175
_obliqueAngle = rest.length > 0 ? rest : @"0deg";
178176
return;
179177
}
180178

181-
if ([trimmed isEqualToString:@"italic"] || [trimmed isEqualToString:@"normal"]) {
182-
_style = trimmed;
183-
_obliqueAngle = nil;
184-
}
179+
_style = NSCFontStyleFromString(trimmed);
180+
_obliqueAngle = nil;
185181
}
186182

187183
- (void)setFontDisplayFromString:(NSString *)value {

packages/font-manager/src-native/ios/FontManager/Sources/FontManager/NSCFontFace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import <Foundation/Foundation.h>
2+
#import <CoreGraphics/CoreGraphics.h>
23
#import "NSCFontTypes.h"
34
#import "NSCFontDescriptors.h"
45

@@ -16,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
1617
// Descriptor pass-throughs (mirrors Web FontFace API)
1718
@property (nonatomic) NSCFontDisplay display;
1819
@property (nonatomic) NSCFontWeight weight;
19-
@property (nonatomic, copy) NSString *style;
20+
@property (nonatomic) NSCFontStyle style;
2021
@property (nonatomic, copy) NSString *variant;
2122
@property (nonatomic, copy) NSString *stretch;
2223
@property (nonatomic, copy) NSString *unicodeRange;

packages/font-manager/src-native/ios/FontManager/Sources/FontManager/NSCFontFace.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ - (void)setWeight:(NSCFontWeight)weight {
8484
[self _scheduleReloadIfNeeded];
8585
}
8686

87-
- (NSString *)style { return self.fontDescriptors.style; }
88-
- (void)setStyle:(NSString *)style {
87+
- (NSCFontStyle)style { return self.fontDescriptors.style; }
88+
- (void)setStyle:(NSCFontStyle)style {
8989
self.fontDescriptors.style = style;
9090
[self _scheduleReloadIfNeeded];
9191
}

packages/font-manager/src-native/ios/FontManager/Sources/FontManager/NSCFontFaceSet.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#import "NSCFontFaceSet.h"
22
#import "NSCFontParser.h"
33
#import "NSCFontResolver.h"
4+
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
45
#import <UIKit/UIKit.h>
6+
#endif
57

68
@interface NSCFontFaceSet ()
79

@@ -235,7 +237,7 @@ - (BOOL)_isGeneric:(NSString *)family {
235237
for (NSCFontFace *face in candidates) {
236238
NSInteger score =
237239
labs(face.fontDescriptors.weight - parsed.weight) +
238-
([face.fontDescriptors.style isEqualToString:parsed.style] ? 0 : 1000);
240+
(face.fontDescriptors.style == parsed.style ? 0 : 1000);
239241
if (score < bestScore) { bestScore = score; best = face; }
240242
}
241243
if (best) return @[best];

packages/font-manager/src-native/ios/FontManager/Sources/FontManager/NSCFontParser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#import <Foundation/Foundation.h>
2+
#import "NSCFontTypes.h"
23

34
NS_ASSUME_NONNULL_BEGIN
45

56
@interface NSCFontParseResult : NSObject
67

7-
@property (nonatomic, copy) NSString *style;
8+
@property (nonatomic, assign) NSCFontStyle style;
89
@property (nonatomic, assign) NSInteger weight;
910
@property (nonatomic, assign) NSInteger sizePx;
1011
@property (nonatomic, strong, nullable) NSNumber *lineHeight;

packages/font-manager/src-native/ios/FontManager/Sources/FontManager/NSCFontParser.m

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ + (nullable NSCFontParseResult *)parse:(NSString *)input {
2121

2222
NSArray<NSString *> *tokens = [self tokenize:input];
2323

24-
NSString *style = @"normal";
24+
NSCFontStyle style = NSCFontStyleNormal;
2525
NSInteger weight = 400;
2626
NSInteger size = -1;
2727
NSNumber *lineHeight = nil;
@@ -40,19 +40,11 @@ + (nullable NSCFontParseResult *)parse:(NSString *)input {
4040

4141
if ([token isEqualToString:@"italic"]) {
4242

43-
style = @"italic";
43+
style = NSCFontStyleItalic;
4444

4545
} else if ([token hasPrefix:@"oblique"]) {
4646

47-
NSString *angleStr =
48-
[[token stringByReplacingOccurrencesOfString:@"oblique"
49-
withString:@""]
50-
stringByTrimmingCharactersInSet:
51-
[NSCharacterSet whitespaceCharacterSet]];
52-
53-
style = angleStr.length == 0
54-
? @"oblique"
55-
: [NSString stringWithFormat:@"oblique %@", angleStr];
47+
style = NSCFontStyleOblique;
5648

5749
} else if ([token isEqualToString:@"bold"]) {
5850

0 commit comments

Comments
 (0)