diff --git a/Kumi/Core/Utility/TextStyle+JSON.swift b/Kumi/Core/Utility/TextStyle+JSON.swift index af83b15..4f9e7e7 100644 --- a/Kumi/Core/Utility/TextStyle+JSON.swift +++ b/Kumi/Core/Utility/TextStyle+JSON.swift @@ -68,15 +68,46 @@ private extension NSLineBreakMode { } +private extension NSUnderlineStyle { + + static func fromString(string: String) -> NSUnderlineStyle? { + switch string { + case "none": + return NSUnderlineStyle.styleNone + case "single": + return NSUnderlineStyle.styleSingle + case "thick": + return NSUnderlineStyle.styleThick + case "double": + return NSUnderlineStyle.styleDouble + case "patternSolid": + return NSUnderlineStyle.patternSolid + case "patternDot": + return NSUnderlineStyle.patternDot + case "patternDash": + return NSUnderlineStyle.patternDash + case "patternDashDot": + return NSUnderlineStyle.patternDashDot + case "patternDashDotDot": + return NSUnderlineStyle.patternDashDotDot + case "byWord": + return NSUnderlineStyle.byWord + default: + return nil + } + } +} + extension TextStyle { init?(json: JSON) { - guard let fontName = json["fontFamily"] as? String, + guard let fontNameJSON = json["fontWeight"] as? JSON, + let normalFontName = fontNameJSON["normal"] as? String, let textSize = json["textSize"] as? CGFloat else { return nil } - guard let font = UIFont(name: fontName, size: textSize) else { + guard let font = UIFont(name: normalFontName, size: textSize) else { return nil } @@ -97,6 +128,14 @@ extension TextStyle { var strikethroughColor: UIColor? var textTransform: TextTransform = .none + if let emFontName = fontNameJSON["emphasis"] as? String { + emFont = UIFont(name: emFontName, size: textSize) + } + + if let strongFontName = fontNameJSON["strong"] as? String { + strongFont = UIFont(name: strongFontName, size: textSize) + } + if let textColorJSON = json["color"] as? JSON { textColor = UIColor(json: textColorJSON) } @@ -129,20 +168,26 @@ extension TextStyle { paragraphSpacingBefore = paragraphSpaceBefore } - if let textAlignmentString = json["textAlign"] as? String, - let textAlign = NSTextAlignment.fromString(string: textAlignmentString) { - textAlignment = textAlign + if let textAlignmentString = json["textAlign"] as? String { + textAlignment = NSTextAlignment.fromString(string: textAlignmentString) } - if let lineBreakModeString = json["lineBreakMode"] as? String, - let lineBrkMode = NSLineBreakMode.fromString(string: lineBreakModeString) { - lineBreakMode = lineBrkMode + if let lineBreakModeString = json["lineBreakMode"] as? String { + lineBreakMode = NSLineBreakMode.fromString(string: lineBreakModeString) + } + + if let strikethroughStyleString = json["strikethroughStyle"] as? String { + strikethroughStyle = NSUnderlineStyle.fromString(string: strikethroughStyleString) } if let transform = json["textTransform"] as? String { textTransform = TextTransform(string: transform) } + if let strikethroughColorJSON = json["strikethroughColor"] as? JSON { + strikethroughColor = UIColor(json: strikethroughColorJSON) + } + self.init(font: font, emFont: emFont, strongFont: strongFont, @@ -160,5 +205,5 @@ extension TextStyle { strikethroughColor: strikethroughColor, textTransform: textTransform) } - + } diff --git a/KumiTests/Font/FontStyle.json b/KumiTests/Font/FontStyle.json index 3b8c54c..eec701e 100644 --- a/KumiTests/Font/FontStyle.json +++ b/KumiTests/Font/FontStyle.json @@ -1,26 +1,27 @@ { - "fontFamily": "Helvetica", - "textSize": 18, - "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" - }, - "color": { - "$ref": "#/theme/color/primary/normal" - }, - "letterSpacing": 1, - "lineSpacing": 0, - "lineHeightMultiple": 1, - "minimumLineHeight": 10, - "maximumLineHeight": 25, - "paragraphSpacing": 12, - "paragraphSpacingBefore": 3, - "textAlign": "left", - "lineBreakMode": "​​byTruncatingTail", - "textTransform": "none", - "textDecorationLine": "none", - "textDecorationColor": { - "$ref": "#/theme/color/primary/normal" - } + "fontFamily": "Helvetica", + "textSize": 18, + "fontWeight": { + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" + }, + "color": { + "$ref": "#/theme/color/primary/normal" + }, + "letterSpacing": 1, + "lineSpacing": 0, + "lineHeightMultiple": 1, + "minimumLineHeight": 10, + "maximumLineHeight": 25, + "paragraphSpacing": 12, + "paragraphSpacingBefore": 3, + "textAlign": "left", + "lineBreakMode": "​​byTruncatingTail", + "textTransform": "none", + "textDecorationLine": "none", + "textDecorationColor": { + "$ref": "#/theme/color/primary/normal" + }, + "strikethroughStyle": "none" } diff --git a/KumiTests/Font/Fonts.json b/KumiTests/Font/Fonts.json index a28b8d4..5583623 100644 --- a/KumiTests/Font/Fonts.json +++ b/KumiTests/Font/Fonts.json @@ -3,9 +3,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -29,9 +29,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -55,9 +55,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -81,9 +81,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -107,9 +107,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -133,9 +133,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -159,9 +159,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -185,9 +185,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -211,9 +211,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -237,9 +237,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -263,9 +263,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -289,9 +289,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -315,9 +315,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -341,9 +341,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -367,9 +367,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -393,9 +393,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -419,9 +419,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -445,9 +445,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -471,9 +471,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -497,9 +497,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -523,9 +523,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -549,9 +549,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -575,9 +575,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -601,9 +601,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -627,9 +627,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -653,9 +653,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -679,9 +679,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -705,9 +705,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -731,9 +731,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -757,9 +757,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -783,9 +783,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -809,9 +809,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" @@ -835,9 +835,9 @@ "fontFamily": "Helvetica", "textSize": 18, "fontWeight": { - "normal": "roman/regular", - "strong": "roman/bold", - "emphasis": "roman/heavy" + "normal": "Helvetica", + "strong": "Helvetica-Bold", + "emphasis": "Helvetica-Heavy" }, "color": { "$ref": "#/theme/color/primary/normal" diff --git a/KumiTests/Font/TextStyleTests.swift b/KumiTests/Font/TextStyleTests.swift index 2b05ee4..ecae321 100644 --- a/KumiTests/Font/TextStyleTests.swift +++ b/KumiTests/Font/TextStyleTests.swift @@ -42,6 +42,7 @@ class TextStyleTests: XCTestCase { XCTAssertEqual(textStyle.paragraphSpacingBefore, 3.0) XCTAssertEqual(textStyle.textAlignment, .left) XCTAssertEqual(textStyle.lineBreakMode, .byTruncatingTail) + XCTAssertEqual(textStyle.strikethroughStyle, .styleNone) } - + }