Skip to content

Commit

Permalink
scaledFont(for:)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsbernstein committed Jan 31, 2024
1 parent dde451a commit 202f34a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,18 @@ extension SwiftyMarkdown {
font = UIFont.preferredFont(forTextStyle: textStyle)
}

if globalItalic, let italicDescriptor = font.fontDescriptor.withSymbolicTraits(.traitItalic) {
font = UIFont(descriptor: italicDescriptor, size: fontSize ?? 0)
}
if globalBold, let boldDescriptor = font.fontDescriptor.withSymbolicTraits(.traitBold) {
font = UIFont(descriptor: boldDescriptor, size: fontSize ?? 0)
}
var traits: UIFontDescriptor.SymbolicTraits = []
if globalItalic {
traits.insert(.traitItalic)
}
if globalBold {
traits.insert(.traitBold)
}
if !traits.isEmpty, let descriptor = font.fontDescriptor.withSymbolicTraits(traits) {
let customFont = UIFont(descriptor: descriptor, size: fontSize ?? 0)
let fontMetrics = UIFontMetrics(forTextStyle: textStyle)
font = fontMetrics.scaledFont(for: customFont)
}

return font

Expand Down

0 comments on commit 202f34a

Please sign in to comment.