@@ -223,25 +223,35 @@ extension CofficeFont {
223
223
}
224
224
225
225
struct FontModifier : ViewModifier {
226
- var font : CofficeFont
227
- var fontOriginalLineHeight : CGFloat {
226
+ let font : CofficeFont
227
+ let customFontLineHeight : CGFloat ?
228
+
229
+ var fontLineHeight : CGFloat {
230
+ if let customFontLineHeight {
231
+ return customFontLineHeight
232
+ }
233
+ return font. lineHeight
234
+ }
235
+
236
+ var originalFontLineHeight : CGFloat {
228
237
return UIFont ( name: font. name, size: font. size) ? . lineHeight ?? 20
229
238
}
230
239
231
- init ( font: CofficeFont ) {
240
+ init ( font: CofficeFont , lineHeight : CGFloat ? = nil ) {
232
241
self . font = font
242
+ self . customFontLineHeight = lineHeight
233
243
}
234
244
235
245
func body( content: Content ) -> some View {
236
246
content
237
247
. font ( . custom( font. name, size: font. size) )
238
- . lineSpacing ( font . lineHeight - fontOriginalLineHeight )
239
- . padding ( . vertical, ( font . lineHeight - fontOriginalLineHeight ) / 2 )
248
+ . lineSpacing ( fontLineHeight - originalFontLineHeight )
249
+ . padding ( . vertical, ( fontLineHeight - originalFontLineHeight ) / 2 )
240
250
}
241
251
}
242
252
243
253
extension View {
244
- func applyCofficeFont( font: CofficeFont ) -> some View {
245
- modifier ( FontModifier ( font: font) )
254
+ func applyCofficeFont( font: CofficeFont , lineHeight : CGFloat ? = nil ) -> some View {
255
+ modifier ( FontModifier ( font: font, lineHeight : lineHeight ) )
246
256
}
247
257
}
0 commit comments