@@ -9,16 +9,30 @@ public extension Font {
9
9
///
10
10
/// - Parameter fioriTextStyle: Text style.
11
11
/// - Returns: A scaled font for this text style.
12
- static func fiori( forTextStyle fioriTextStyle: Font . FioriTextStyle ) -> Font {
13
- guard UIFont . familyNames. contains ( " 72 " ) else {
14
- return Font . system ( fioriTextStyle. textStyle)
12
+ static func fiori( forTextStyle fioriTextStyle: Font . FioriTextStyle , weight: Font . Weight = . regular, isItalic: Bool = false , isCondensed: Bool = false ) -> Font {
13
+ var font : Font
14
+ if UIFont . familyNames. contains ( " 72 " ) {
15
+ font = Font . custom ( " 72 " , size: fioriTextStyle. size, relativeTo: fioriTextStyle. textStyle)
16
+ font = font. weight ( weight. getFioriWeight ( isItalic: isItalic, isCondensed: isCondensed) )
17
+ } else {
18
+ font = Font . system ( fioriTextStyle. textStyle) . weight ( weight)
15
19
}
16
20
17
- if #available( iOS 14 . 0 , * ) {
18
- return Font . custom ( " 72 " , size: fioriTextStyle. size, relativeTo: fioriTextStyle. textStyle)
19
- } else {
20
- return Font . custom ( " 72 " , size: fioriTextStyle. size)
21
+ if isItalic {
22
+ font = font. italic ( )
23
+ } else if isCondensed {
24
+ #if swift(>=5.7.1)
25
+ if #available( iOS 16 . 0 , watchOS 9 . 0 , * ) {
26
+ font = font. width ( Font . Width. condensed)
27
+ } else {
28
+ font = Font . fioriCondensed ( forTextStyle: fioriTextStyle, weight: weight)
29
+ }
30
+ #else
31
+ font = Font . fioriCondensed ( forTextStyle: fioriTextStyle, weight: weight)
32
+ #endif
21
33
}
34
+
35
+ return font
22
36
}
23
37
24
38
/// Fiori (72) fonts
@@ -27,13 +41,30 @@ public extension Font {
27
41
///
28
42
/// - Parameter fioriTextStyle: Text style.
29
43
/// - Returns: A font with fixed size.
30
- @available ( iOS 14 . 0 , * )
31
- static func fiori( fixedSize: CGFloat ) -> Font {
32
- guard UIFont . familyNames. contains ( " 72 " ) else {
33
- return Font . system ( size: fixedSize)
44
+ static func fiori( fixedSize: CGFloat , weight: Font . Weight = . regular, isItalic: Bool = false , isCondensed: Bool = false ) -> Font {
45
+ var font : Font
46
+ if UIFont . familyNames. contains ( " 72 " ) {
47
+ font = Font . custom ( " 72 " , fixedSize: fixedSize)
48
+ font = font. weight ( weight. getFioriWeight ( isItalic: isItalic, isCondensed: isCondensed) )
49
+ } else {
50
+ font = Font . system ( size: fixedSize) . weight ( weight)
34
51
}
35
52
36
- return Font . custom ( " 72 " , fixedSize: fixedSize)
53
+ if isItalic {
54
+ font = font. italic ( )
55
+ } else if isCondensed {
56
+ #if swift(>=5.7.1)
57
+ if #available( iOS 16 . 0 , watchOS 9 . 0 , * ) {
58
+ font = font. width ( Font . Width. condensed)
59
+ } else {
60
+ font = Font . fioriCondensed ( fixedSize: fixedSize, weight: weight)
61
+ }
62
+ #else
63
+ font = Font . fioriCondensed ( fixedSize: fixedSize, weight: weight)
64
+ #endif
65
+ }
66
+
67
+ return font
37
68
}
38
69
39
70
/// Fiori (72) condensed fonts
@@ -42,16 +73,22 @@ public extension Font {
42
73
///
43
74
/// - Parameter fioriTextStyle: Text style.
44
75
/// - Returns: A scaled condensed font for this text style.
45
- static func fioriCondensed( forTextStyle fioriTextStyle: Font . FioriTextStyle ) -> Font {
46
- guard UIFont . familyNames. contains ( " 72 " ) else {
47
- return Font . system ( fioriTextStyle. textStyle)
48
- }
49
-
50
- if #available( iOS 14 . 0 , * ) {
51
- return Font . custom ( " 72-Condensed " , size: fioriTextStyle. size, relativeTo: fioriTextStyle. textStyle)
76
+ @available ( * , deprecated, message: " Use UIFont.fiori(forTextStyle:) with isCondensed parameter set to true " )
77
+ static func fioriCondensed( forTextStyle fioriTextStyle: Font . FioriTextStyle , weight: Font . Weight = . regular) -> Font {
78
+ var font : Font
79
+ if UIFont . familyNames. contains ( " 72 " ) {
80
+ font = Font . custom ( " 72-Condensed " , size: fioriTextStyle. size, relativeTo: fioriTextStyle. textStyle)
81
+ font = font. weight ( weight. getFioriWeight ( isItalic: false , isCondensed: true ) )
52
82
} else {
53
- return Font . custom ( " 72-Condensed " , size: fioriTextStyle. size)
83
+ font = Font . system ( fioriTextStyle. textStyle) . weight ( weight)
84
+ #if swift(>=5.7.1)
85
+ if #available( iOS 16 . 0 , watchOS 9 . 0 , * ) {
86
+ font = font. width ( Font . Width. condensed)
87
+ }
88
+ #endif
54
89
}
90
+
91
+ return font
55
92
}
56
93
57
94
/// Fiori (72) condensed fonts
@@ -61,12 +98,22 @@ public extension Font {
61
98
/// - Parameter fioriTextStyle: Text style.
62
99
/// - Returns: A condensed font with fixed size.
63
100
@available ( iOS 14 . 0 , * )
64
- static func fioriCondensed( fixedSize: CGFloat ) -> Font {
65
- guard UIFont . familyNames. contains ( " 72 " ) else {
66
- return Font . system ( size: fixedSize)
101
+ @available ( * , deprecated, message: " Use UIFont.fiori(fixedSize:) with isCondensed parameter set to true " )
102
+ static func fioriCondensed( fixedSize: CGFloat , weight: Font . Weight = . regular) -> Font {
103
+ var font : Font
104
+ if UIFont . familyNames. contains ( " 72 " ) {
105
+ font = Font . custom ( " 72-Condensed " , fixedSize: fixedSize)
106
+ font = font. weight ( weight. getFioriWeight ( isItalic: false , isCondensed: true ) )
107
+ } else {
108
+ font = Font . system ( size: fixedSize) . weight ( weight)
109
+ #if swift(>=5.7.1)
110
+ if #available( iOS 16 . 0 , watchOS 9 . 0 , * ) {
111
+ font = font. width ( Font . Width. condensed)
112
+ }
113
+ #endif
67
114
}
68
115
69
- return Font . custom ( " 72-Condensed " , fixedSize : fixedSize )
116
+ return font
70
117
}
71
118
}
72
119
@@ -188,3 +235,42 @@ extension Font.FioriTextStyle: CustomStringConvertible {
188
235
}
189
236
}
190
237
}
238
+
239
+ extension Font . Weight {
240
+ func getFioriWeight( isItalic: Bool , isCondensed: Bool ) -> Font . Weight {
241
+ isItalic ? self . italicWeight : ( isCondensed ? self . condensedWeight : self . fioriWeight)
242
+ }
243
+
244
+ private var fioriWeight : Font . Weight {
245
+ switch self {
246
+ case . heavy, . black:
247
+ return . black
248
+ case . medium, . semibold, . bold:
249
+ return . bold
250
+ case . regular:
251
+ return . regular
252
+ case . ultraLight, . thin, . light:
253
+ return . light
254
+ default :
255
+ return . regular
256
+ }
257
+ }
258
+
259
+ private var italicWeight : Font . Weight {
260
+ switch self . fioriWeight {
261
+ case . black, . bold:
262
+ return . bold
263
+ default :
264
+ return . regular
265
+ }
266
+ }
267
+
268
+ private var condensedWeight : Font . Weight {
269
+ switch self . fioriWeight {
270
+ case . black, . bold:
271
+ return . bold
272
+ default :
273
+ return . regular
274
+ }
275
+ }
276
+ }
0 commit comments