Skip to content

Commit 1db75f3

Browse files
Mark Pospeselmpospese
authored andcommitted
[Issue-63] Handle case of fixed fonts where accessibility bold text is enabled
1 parent 44a78e1 commit 1db75f3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/YMatterType/Typography/Typography+Font.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ extension Typography {
4747
)
4848
scaledLineHeight = metrics.scaledValue(for: lineHeight, compatibleWith: traitCollection)
4949
}
50+
} else if fontFamily is SystemFontFamily {
51+
// In case of a fixed System font, we still need to "scale" the font
52+
// to adjust it to the correct traits.
53+
let metrics = UIFontMetrics(forTextStyle: textStyle)
54+
font = metrics.scaledFont(
55+
for: font,
56+
maximumPointSize: fontSize, // no change in size
57+
compatibleWith: traitCollection
58+
)
5059
}
5160

5261
// We need to adjust the baseline so that the text will appear vertically centered
@@ -128,7 +137,7 @@ extension Typography {
128137
private extension Typography {
129138
func generateFixedFont(compatibleWith traitCollection: UITraitCollection?) -> UIFont {
130139
var traits = traitCollection
131-
if !isFixed && fontFamily is SystemFontFamily {
140+
if fontFamily is SystemFontFamily {
132141
// System font already considers accessibility BoldText when
133142
// we get the scaled font via `UIFontMetrics.scaledFont(for:compatibleWith:)`,
134143
// so we pass a non-bold trait collection when generating the fixed font, so

0 commit comments

Comments
 (0)