mattt/CommonMarkAttributedString

Header style mutates font attribute on iOS

mikepulaski opened this issue · 3 comments

On iOS, using any header style will cause the font to mutate to a different family (Times New Roman). I believe this is due to how the font is transformed in the Header extension defined in CommonMark+Extensions.swift. It's not clear whether or not this happens when the font's point size is made larger, or when the bold trait is added.

image

For reference, I'm using UIFont.systemFont(ofSize:). It also seemed to be an issue when using UIFont.preferredFont(forTextStyle: .body).

I'm happy to dive in and create a PR for this -- seems like it could be an easy fix!

mattt commented

Hey, @mikepulaski. Thanks for reporting this. Yeah, if you have some time to spare, I'd really appreciate a fix for this. I think your diagnosis is spot on — macOS support was my motivating use case, and the code dealing with UIFontDescriptor was written in a bit of a hurry.

@mattt All set! I added a test (although I don't think running swift test actually imports UIKit. See #2.

Looks good, though:

image

mattt commented

Great work, @mikepulaski! Thanks again for taking a crack at that.

(I don't think running swift test actually imports UIKit)

Correct. To run these tests on CI, we generate an Xcode project and run the test bundle with xcodebuild.