Skip to content

Commit f2b7a2b

Browse files
committed
Fixed warnings in TextStyle JSON extension
1 parent 72251f5 commit f2b7a2b

File tree

4 files changed

+180
-133
lines changed

4 files changed

+180
-133
lines changed

Kumi/Core/Utility/TextStyle+JSON.swift

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,46 @@ private extension NSLineBreakMode {
6868

6969
}
7070

71+
private extension NSUnderlineStyle {
72+
73+
static func fromString(string: String) -> NSUnderlineStyle? {
74+
switch string {
75+
case "none":
76+
return NSUnderlineStyle.styleNone
77+
case "single":
78+
return NSUnderlineStyle.styleSingle
79+
case "thick":
80+
return NSUnderlineStyle.styleThick
81+
case "double":
82+
return NSUnderlineStyle.styleDouble
83+
case "patternSolid":
84+
return NSUnderlineStyle.patternSolid
85+
case "patternDot":
86+
return NSUnderlineStyle.patternDot
87+
case "patternDash":
88+
return NSUnderlineStyle.patternDash
89+
case "patternDashDot":
90+
return NSUnderlineStyle.patternDashDot
91+
case "patternDashDotDot":
92+
return NSUnderlineStyle.patternDashDotDot
93+
case "byWord":
94+
return NSUnderlineStyle.byWord
95+
default:
96+
return nil
97+
}
98+
}
99+
}
100+
71101
extension TextStyle {
72102

73103
init?(json: JSON) {
74-
guard let fontName = json["fontFamily"] as? String,
104+
guard let fontNameJSON = json["fontWeight"] as? JSON,
105+
let normalFontName = fontNameJSON["normal"] as? String,
75106
let textSize = json["textSize"] as? CGFloat else {
76107
return nil
77108
}
78109

79-
guard let font = UIFont(name: fontName, size: textSize) else {
110+
guard let font = UIFont(name: normalFontName, size: textSize) else {
80111
return nil
81112
}
82113

@@ -97,6 +128,14 @@ extension TextStyle {
97128
var strikethroughColor: UIColor?
98129
var textTransform: TextTransform = .none
99130

131+
if let emFontName = fontNameJSON["emphasis"] as? String {
132+
emFont = UIFont(name: emFontName, size: textSize)
133+
}
134+
135+
if let strongFontName = fontNameJSON["strong"] as? String {
136+
strongFont = UIFont(name: strongFontName, size: textSize)
137+
}
138+
100139
if let textColorJSON = json["color"] as? JSON {
101140
textColor = UIColor(json: textColorJSON)
102141
}
@@ -129,20 +168,26 @@ extension TextStyle {
129168
paragraphSpacingBefore = paragraphSpaceBefore
130169
}
131170

132-
if let textAlignmentString = json["textAlign"] as? String,
133-
let textAlign = NSTextAlignment.fromString(string: textAlignmentString) {
134-
textAlignment = textAlign
171+
if let textAlignmentString = json["textAlign"] as? String {
172+
textAlignment = NSTextAlignment.fromString(string: textAlignmentString)
135173
}
136174

137-
if let lineBreakModeString = json["lineBreakMode"] as? String,
138-
let lineBrkMode = NSLineBreakMode.fromString(string: lineBreakModeString) {
139-
lineBreakMode = lineBrkMode
175+
if let lineBreakModeString = json["lineBreakMode"] as? String {
176+
lineBreakMode = NSLineBreakMode.fromString(string: lineBreakModeString)
177+
}
178+
179+
if let strikethroughStyleString = json["strikethroughStyle"] as? String {
180+
strikethroughStyle = NSUnderlineStyle.fromString(string: strikethroughStyleString)
140181
}
141182

142183
if let transform = json["textTransform"] as? String {
143184
textTransform = TextTransform(string: transform)
144185
}
145186

187+
if let strikethroughColorJSON = json["strikethroughColor"] as? JSON {
188+
strikethroughColor = UIColor(json: strikethroughColorJSON)
189+
}
190+
146191
self.init(font: font,
147192
emFont: emFont,
148193
strongFont: strongFont,
@@ -160,5 +205,5 @@ extension TextStyle {
160205
strikethroughColor: strikethroughColor,
161206
textTransform: textTransform)
162207
}
163-
208+
164209
}

KumiTests/Font/FontStyle.json

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
2-
"fontFamily": "Helvetica",
3-
"textSize": 18,
4-
"fontWeight": {
5-
"normal": "roman/regular",
6-
"strong": "roman/bold",
7-
"emphasis": "roman/heavy"
8-
},
9-
"color": {
10-
"$ref": "#/theme/color/primary/normal"
11-
},
12-
"letterSpacing": 1,
13-
"lineSpacing": 0,
14-
"lineHeightMultiple": 1,
15-
"minimumLineHeight": 10,
16-
"maximumLineHeight": 25,
17-
"paragraphSpacing": 12,
18-
"paragraphSpacingBefore": 3,
19-
"textAlign": "left",
20-
"lineBreakMode": "​​byTruncatingTail",
21-
"textTransform": "none",
22-
"textDecorationLine": "none",
23-
"textDecorationColor": {
24-
"$ref": "#/theme/color/primary/normal"
25-
}
2+
"fontFamily": "Helvetica",
3+
"textSize": 18,
4+
"fontWeight": {
5+
"normal": "Helvetica",
6+
"strong": "Helvetica-Bold",
7+
"emphasis": "Helvetica-Heavy"
8+
},
9+
"color": {
10+
"$ref": "#/theme/color/primary/normal"
11+
},
12+
"letterSpacing": 1,
13+
"lineSpacing": 0,
14+
"lineHeightMultiple": 1,
15+
"minimumLineHeight": 10,
16+
"maximumLineHeight": 25,
17+
"paragraphSpacing": 12,
18+
"paragraphSpacingBefore": 3,
19+
"textAlign": "left",
20+
"lineBreakMode": "​​byTruncatingTail",
21+
"textTransform": "none",
22+
"textDecorationLine": "none",
23+
"textDecorationColor": {
24+
"$ref": "#/theme/color/primary/normal"
25+
},
26+
"strikethroughStyle": "none"
2627
}

0 commit comments

Comments
 (0)