Skip to content

Font.custom(_:size:relativeTo:) adds size to the text style's size instead of scaling it #495

Description

@gurmeherchawla

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:):

let absoluteSize = size

Environment

  • Skip 1.9.4, skip-ui current main (verified in Sources/SkipUI/SkipUI/Text/Font.swift)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions