Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resizing bold and italic #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Comment on lines +133 to +138
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory this would also allow text to be both bold and italic, which wouldn't work before, however it seems like other bugs in the parsing prevent that.

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)
Comment on lines +141 to +142
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just copied this from above on lines 123-124.

}

return font

Expand Down