@@ -12,167 +12,167 @@ import Foundation
12
12
import UIKit
13
13
14
14
extension SwiftyMarkdown {
15
-
16
- func font( for line : SwiftyLine , characterOverride : CharacterStyle ? = nil ) -> UIFont {
17
- let textStyle : UIFont . TextStyle
18
- var fontName : String ?
19
- var fontSize : CGFloat ?
20
-
21
- var globalBold = false
22
- var globalItalic = false
23
-
24
- let style : FontProperties
25
- // What type are we and is there a font name set?
26
- switch line. lineStyle as! MarkdownLineStyle {
27
- case . h1:
28
- style = self . h1
29
- if #available( iOS 9 , * ) {
30
- textStyle = UIFont . TextStyle. title1
31
- } else {
32
- textStyle = UIFont . TextStyle. headline
33
- }
34
- case . h2:
35
- style = self . h2
36
- if #available( iOS 9 , * ) {
37
- textStyle = UIFont . TextStyle. title2
38
- } else {
39
- textStyle = UIFont . TextStyle. headline
40
- }
41
- case . h3:
42
- style = self . h3
43
- if #available( iOS 9 , * ) {
44
- textStyle = UIFont . TextStyle. title2
45
- } else {
46
- textStyle = UIFont . TextStyle. subheadline
47
- }
48
- case . h4:
49
- style = self . h4
50
- textStyle = UIFont . TextStyle. headline
51
- case . h5:
52
- style = self . h5
53
- textStyle = UIFont . TextStyle. subheadline
54
- case . h6:
55
- style = self . h6
56
- textStyle = UIFont . TextStyle. footnote
57
- case . codeblock:
58
- style = self . code
59
- textStyle = UIFont . TextStyle. body
60
- case . blockquote:
61
- style = self . blockquotes
62
- textStyle = UIFont . TextStyle. body
63
- default :
64
- style = self . body
65
- textStyle = UIFont . TextStyle. body
66
- }
67
-
68
- fontName = style. fontName
69
- fontSize = style. fontSize
70
- switch style. fontStyle {
71
- case . bold:
72
- globalBold = true
73
- case . italic:
74
- globalItalic = true
75
- case . boldItalic:
76
- globalItalic = true
77
- globalBold = true
78
- case . normal:
79
- break
80
- }
15
+
16
+ func font( for line : SwiftyLine , characterOverride : CharacterStyle ? = nil ) -> UIFont {
17
+ let textStyle : UIFont . TextStyle
18
+ var fontName : String ?
19
+ var fontSize : CGFloat ?
20
+
21
+ var globalBold = false
22
+ var globalItalic = false
23
+
24
+ let style : FontProperties
25
+ // What type are we and is there a font name set?
26
+ switch line. lineStyle as! MarkdownLineStyle {
27
+ case . h1:
28
+ style = self . h1
29
+ if #available( iOS 9 , * ) {
30
+ textStyle = UIFont . TextStyle. title1
31
+ } else {
32
+ textStyle = UIFont . TextStyle. headline
33
+ }
34
+ case . h2:
35
+ style = self . h2
36
+ if #available( iOS 9 , * ) {
37
+ textStyle = UIFont . TextStyle. title2
38
+ } else {
39
+ textStyle = UIFont . TextStyle. headline
40
+ }
41
+ case . h3:
42
+ style = self . h3
43
+ if #available( iOS 9 , * ) {
44
+ textStyle = UIFont . TextStyle. title2
45
+ } else {
46
+ textStyle = UIFont . TextStyle. subheadline
47
+ }
48
+ case . h4:
49
+ style = self . h4
50
+ textStyle = UIFont . TextStyle. headline
51
+ case . h5:
52
+ style = self . h5
53
+ textStyle = UIFont . TextStyle. subheadline
54
+ case . h6:
55
+ style = self . h6
56
+ textStyle = UIFont . TextStyle. footnote
57
+ case . codeblock:
58
+ style = self . code
59
+ textStyle = UIFont . TextStyle. body
60
+ case . blockquote:
61
+ style = self . blockquotes
62
+ textStyle = UIFont . TextStyle. body
63
+ default :
64
+ style = self . body
65
+ textStyle = UIFont . TextStyle. body
66
+ }
67
+
68
+ fontName = style. fontName
69
+ fontSize = style. fontSize
70
+ switch style. fontStyle {
71
+ case . bold:
72
+ globalBold = true
73
+ case . italic:
74
+ globalItalic = true
75
+ case . boldItalic:
76
+ globalItalic = true
77
+ globalBold = true
78
+ case . normal:
79
+ break
80
+ }
81
81
82
- if fontName == nil {
83
- fontName = body. fontName
84
- }
85
-
86
- if let characterOverride = characterOverride {
87
- switch characterOverride {
88
- case . code:
89
- fontName = code. fontName ?? fontName
90
- fontSize = code. fontSize
91
- case . link:
92
- fontName = link. fontName ?? fontName
93
- fontSize = link. fontSize
94
- case . bold:
95
- fontName = bold. fontName ?? fontName
96
- fontSize = bold. fontSize
97
- globalBold = true
98
- case . italic:
99
- fontName = italic. fontName ?? fontName
100
- fontSize = italic. fontSize
101
- globalItalic = true
102
- case . strikethrough:
103
- fontName = strikethrough. fontName ?? fontName
104
- fontSize = strikethrough. fontSize
105
- default :
106
- break
107
- }
108
- }
109
-
110
- fontSize = fontSize == 0.0 ? nil : fontSize
111
- var font : UIFont
112
- if let existentFontName = fontName {
113
- font = UIFont . preferredFont ( forTextStyle: textStyle)
114
- let finalSize : CGFloat
115
- if let existentFontSize = fontSize {
116
- finalSize = existentFontSize
117
- } else {
118
- let styleDescriptor = UIFontDescriptor . preferredFontDescriptor ( withTextStyle: textStyle)
119
- finalSize = styleDescriptor. fontAttributes [ . size] as? CGFloat ?? CGFloat ( 14 )
120
- }
121
-
122
- if let customFont = UIFont ( name: existentFontName, size: finalSize) {
123
- let fontMetrics = UIFontMetrics ( forTextStyle: textStyle)
124
- font = fontMetrics. scaledFont ( for: customFont)
125
- } else {
126
- font = UIFont . preferredFont ( forTextStyle: textStyle)
127
- }
128
- } else {
129
- font = UIFont . preferredFont ( forTextStyle: textStyle)
130
- }
82
+ if fontName == nil {
83
+ fontName = body. fontName
84
+ }
85
+
86
+ if let characterOverride = characterOverride {
87
+ switch characterOverride {
88
+ case . code:
89
+ fontName = code. fontName ?? fontName
90
+ fontSize = code. fontSize
91
+ case . link:
92
+ fontName = link. fontName ?? fontName
93
+ fontSize = link. fontSize
94
+ case . bold:
95
+ fontName = bold. fontName ?? fontName
96
+ fontSize = bold. fontSize
97
+ globalBold = true
98
+ case . italic:
99
+ fontName = italic. fontName ?? fontName
100
+ fontSize = italic. fontSize
101
+ globalItalic = true
102
+ case . strikethrough:
103
+ fontName = strikethrough. fontName ?? fontName
104
+ fontSize = strikethrough. fontSize
105
+ default :
106
+ break
107
+ }
108
+ }
109
+
110
+ fontSize = fontSize == 0.0 ? nil : fontSize
111
+ var font : UIFont
112
+ if let existentFontName = fontName {
113
+ font = UIFont . preferredFont ( forTextStyle: textStyle)
114
+ let finalSize : CGFloat
115
+ if let existentFontSize = fontSize {
116
+ finalSize = existentFontSize
117
+ } else {
118
+ let styleDescriptor = UIFontDescriptor . preferredFontDescriptor ( withTextStyle: textStyle)
119
+ finalSize = styleDescriptor. fontAttributes [ . size] as? CGFloat ?? CGFloat ( 14 )
120
+ }
121
+
122
+ if let customFont = UIFont ( name: existentFontName, size: finalSize) {
123
+ let fontMetrics = UIFontMetrics ( forTextStyle: textStyle)
124
+ font = fontMetrics. scaledFont ( for: customFont)
125
+ } else {
126
+ font = UIFont . preferredFont ( forTextStyle: textStyle)
127
+ }
128
+ } else {
129
+ font = UIFont . preferredFont ( forTextStyle: textStyle)
130
+ }
131
131
132
132
if ignoreDynamicFontSize, let fontSize = fontSize {
133
133
font = font. withSize ( fontSize)
134
134
}
135
-
136
- if globalItalic, let italicDescriptor = font. fontDescriptor. withSymbolicTraits ( . traitItalic) {
137
- font = UIFont ( descriptor: italicDescriptor, size: fontSize ?? 0 )
138
- }
139
- if globalBold, let boldDescriptor = font. fontDescriptor. withSymbolicTraits ( . traitBold) {
140
- font = UIFont ( descriptor: boldDescriptor, size: fontSize ?? 0 )
141
- }
142
-
143
- return font
144
-
145
- }
146
-
147
- func color( for line : SwiftyLine ) -> UIColor {
148
- // What type are we and is there a font name set?
149
- switch line. lineStyle as! MarkdownLineStyle {
150
- case . yaml:
151
- return body. color
152
- case . h1, . previousH1:
153
- return h1. color
154
- case . h2, . previousH2:
155
- return h2. color
156
- case . h3:
157
- return h3. color
158
- case . h4:
159
- return h4. color
160
- case . h5:
161
- return h5. color
162
- case . h6:
163
- return h6. color
164
- case . body:
165
- return body. color
166
- case . codeblock:
167
- return code. color
168
- case . blockquote:
169
- return blockquotes. color
170
- case . unorderedList, . unorderedListIndentFirstOrder, . unorderedListIndentSecondOrder, . orderedList, . orderedListIndentFirstOrder, . orderedListIndentSecondOrder:
171
- return body. color
172
- case . referencedLink:
173
- return link. color
174
- }
175
- }
176
-
135
+
136
+ if globalItalic, let italicDescriptor = font. fontDescriptor. withSymbolicTraits ( . traitItalic) {
137
+ font = UIFont ( descriptor: italicDescriptor, size: fontSize ?? 0 )
138
+ }
139
+ if globalBold, let boldDescriptor = font. fontDescriptor. withSymbolicTraits ( . traitBold) {
140
+ font = UIFont ( descriptor: boldDescriptor, size: fontSize ?? 0 )
141
+ }
142
+
143
+ return font
144
+
145
+ }
146
+
147
+ func color( for line : SwiftyLine ) -> UIColor {
148
+ // What type are we and is there a font name set?
149
+ switch line. lineStyle as! MarkdownLineStyle {
150
+ case . yaml:
151
+ return body. color
152
+ case . h1, . previousH1:
153
+ return h1. color
154
+ case . h2, . previousH2:
155
+ return h2. color
156
+ case . h3:
157
+ return h3. color
158
+ case . h4:
159
+ return h4. color
160
+ case . h5:
161
+ return h5. color
162
+ case . h6:
163
+ return h6. color
164
+ case . body:
165
+ return body. color
166
+ case . codeblock:
167
+ return code. color
168
+ case . blockquote:
169
+ return blockquotes. color
170
+ case . unorderedList, . unorderedListIndentFirstOrder, . unorderedListIndentSecondOrder, . orderedList, . orderedListIndentFirstOrder, . orderedListIndentSecondOrder:
171
+ return body. color
172
+ case . referencedLink:
173
+ return link. color
174
+ }
175
+ }
176
+
177
177
}
178
178
#endif
0 commit comments