From 0721f40b71710ed9e6aa0a32da73707711462a2d Mon Sep 17 00:00:00 2001 From: Xavier Lowmiller Date: Wed, 2 Dec 2020 15:22:27 +0100 Subject: [PATCH 1/2] Fix an issue with system font names --- Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift b/Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift index 4141aa6..796d483 100644 --- a/Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift +++ b/Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift @@ -118,8 +118,11 @@ extension SwiftyMarkdown { let styleDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: textStyle) finalSize = styleDescriptor.fontAttributes[.size] as? CGFloat ?? CGFloat(14) } - - if let customFont = UIFont(name: existentFontName, size: finalSize) { + + if existentFontName.hasPrefix(".SFUI") { + let fontMetrics = UIFontMetrics(forTextStyle: textStyle) + font = fontMetrics.scaledFont(for: UIFont.systemFont(ofSize: finalSize)) + } else if let customFont = UIFont(name: existentFontName, size: finalSize) { let fontMetrics = UIFontMetrics(forTextStyle: textStyle) font = fontMetrics.scaledFont(for: customFont) } else { From 15f8f67e444f940519673533e145be76b1ddff5b Mon Sep 17 00:00:00 2001 From: Xavier Lowmiller Date: Wed, 20 Jan 2021 14:20:36 +0100 Subject: [PATCH 2/2] Enable the ability to ignore dynamic size --- Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift | 12 ++++++++++-- Sources/SwiftyMarkdown/SwiftyMarkdown.swift | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift b/Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift index 796d483..7dde25e 100644 --- a/Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift +++ b/Sources/SwiftyMarkdown/SwiftyMarkdown+iOS.swift @@ -121,10 +121,18 @@ extension SwiftyMarkdown { if existentFontName.hasPrefix(".SFUI") { let fontMetrics = UIFontMetrics(forTextStyle: textStyle) - font = fontMetrics.scaledFont(for: UIFont.systemFont(ofSize: finalSize)) + if ignoresDynamicSize { + font = UIFont.systemFont(ofSize: finalSize) + } else { + font = fontMetrics.scaledFont(for: UIFont.systemFont(ofSize: finalSize)) + } } else if let customFont = UIFont(name: existentFontName, size: finalSize) { let fontMetrics = UIFontMetrics(forTextStyle: textStyle) - font = fontMetrics.scaledFont(for: customFont) + if ignoresDynamicSize { + font = customFont + } else { + font = fontMetrics.scaledFont(for: customFont) + } } else { font = UIFont.preferredFont(forTextStyle: textStyle) } diff --git a/Sources/SwiftyMarkdown/SwiftyMarkdown.swift b/Sources/SwiftyMarkdown/SwiftyMarkdown.swift index 1e9ef16..e446ec8 100644 --- a/Sources/SwiftyMarkdown/SwiftyMarkdown.swift +++ b/Sources/SwiftyMarkdown/SwiftyMarkdown.swift @@ -267,6 +267,8 @@ If that is not set, then the system default will be used. var previouslyFoundTokens : [Token] = [] var applyAttachments = true + public var ignoresDynamicSize = false + let perfomanceLog = PerformanceLog(with: "SwiftyMarkdownPerformanceLogging", identifier: "Swifty Markdown", log: .swiftyMarkdownPerformance)