Description
On Android, Font.custom(_:size:relativeTo:) renders custom fonts at roughly double the requested size. The implementation adds the requested size to the system text style's font size, rather than treating the requested size as the base size to be scaled:
// Sources/SkipUI/SkipUI/Text/Font.swift (main)
public static func custom(_ name: String, size: CGFloat, relativeTo textStyle: Font.TextStyle) -> Font {
#if SKIP
let systemFont = system(textStyle)
return Font(fontImpl: {
let absoluteSize = systemFont.fontImpl().fontSize.value + size // <-- adds instead of scales
androidx.compose.ui.text.TextStyle(fontFamily: Self.findNamedFont(name, ctx: LocalContext.current), fontSize: absoluteSize.sp)
})
#else
fatalError()
#endif
}
Expected behavior (SwiftUI semantics)
On iOS, size is the font's base size at the default Dynamic Type setting, and relativeTo: only selects which text style's scaling curve is applied. Font.custom("MyFont", size: 12, relativeTo: .caption2) renders at 12pt by default.
Actual behavior
On Android, the same call renders at caption2's size + 12 ≈ 24sp — about double the intended size. Any app sharing a typography scale between iOS and Android gets visibly larger text on Android.
Suggested fix
Since Compose's sp unit already applies the user's font scale (and per-style curves aren't available in Compose — the same reason ScaledMetric.init(relativeTo:) ignores its text style), the relativeTo: overload could simply use the requested size directly, matching custom(_:size:):
Environment
- Skip 1.9.4, skip-ui current
main (verified in Sources/SkipUI/SkipUI/Text/Font.swift)
Description
On Android,
Font.custom(_:size:relativeTo:)renders custom fonts at roughly double the requested size. The implementation adds the requested size to the system text style's font size, rather than treating the requested size as the base size to be scaled:Expected behavior (SwiftUI semantics)
On iOS,
sizeis the font's base size at the default Dynamic Type setting, andrelativeTo:only selects which text style's scaling curve is applied.Font.custom("MyFont", size: 12, relativeTo: .caption2)renders at 12pt by default.Actual behavior
On Android, the same call renders at
caption2's size + 12≈ 24sp — about double the intended size. Any app sharing a typography scale between iOS and Android gets visibly larger text on Android.Suggested fix
Since Compose's
spunit already applies the user's font scale (and per-style curves aren't available in Compose — the same reasonScaledMetric.init(relativeTo:)ignores its text style), therelativeTo:overload could simply use the requested size directly, matchingcustom(_:size:):Environment
main(verified inSources/SkipUI/SkipUI/Text/Font.swift)