@@ -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+
71101extension 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}
0 commit comments