Skip to content

Commit

Permalink
Merge pull request #1 from croquiscom/feature/APP-10289-apply
Browse files Browse the repository at this point in the history
APP-10289 : Custom Font 사용 시에 Weight 제대로 적용안되는 이슈 수정
  • Loading branch information
Haccoon committed May 16, 2024
2 parents 62ea6a7 + 0bd58b5 commit 4e72f34
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions Sources/ZMarkupParser/Core/MarkupStyle/MarkupStyleFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ extension MarkupStyleFont {
traits.append(.traitItalic)
}

if traits.isEmpty {
return font
return if traits.isEmpty {
font.withWeight(weight)
} else {
return withTraits(font: font, traits: traits)
withTraits(font: font, traits: traits).withWeight(weight)
}
}

Expand Down Expand Up @@ -349,3 +349,20 @@ private extension NSFont.Weight {
}

#endif

private extension UIFont {
func withWeight(_ weight: UIFont.Weight) -> UIFont {
var attributes = fontDescriptor.fontAttributes
var traits = (attributes[.traits] as? [UIFontDescriptor.TraitKey: Any]) ?? [:]

traits[.weight] = weight

attributes[.name] = nil
attributes[.traits] = traits
attributes[.family] = familyName

let descriptor = UIFontDescriptor(fontAttributes: attributes)

return UIFont(descriptor: descriptor, size: pointSize)
}
}

0 comments on commit 4e72f34

Please sign in to comment.