Visitar URL original
fix(core): Android font-weight is ignored for custom fonts on API 26+ (no wght axis mapping) · Issue #11513 · NativeScript/NativeScript · GitHub
Skip to content

fix(core): Android font-weight is ignored for custom fonts on API 26+ (no wght axis mapping) #11513

Description

@aleclarson

Issue Description

On Android API 26+, @nativescript/core loads custom font files through android.graphics.Typeface.Builder and passes font-variation-settings via setFontVariationSettings. For a variable font, the font-weight CSS property has no effect unless the caller also knows to pass an explicit 'wght' variation setting: loadFontFromFile never maps fontWeight onto the wght axis, so e.g. font-family: 'MyVariableFont'; font-weight: 700 renders at the font's default weight.

Two adjacent problems:

  • computeFontCacheKey keys the typeface cache only on family + explicit variation settings, so once the weight is forwarded (by workaround or fix), two weights of the same family collide in the cache.
  • If a font doesn't support the wght axis, builder.build() throws and there is no retry — the file load fails outright instead of falling back to the explicit variation settings.

Reproduction

On an API 26+ Android device/emulator with a variable font (e.g. fonts/Inter.var.ttf):

<Label fontFamily="Inter.var" fontWeight="700" text="should be bold" />

The label renders at the font's default weight (400) because setFontVariationSettings is called with '' (no wght axis).

Proposed fix

In loadFontFromFile, inject { axis: 'wght', value: <numeric fontWeight> } into the variation settings when the caller did not set wght explicitly, include fontWeight in computeFontCacheKey, and retry the build with the caller's explicit settings if the wght-augmented build throws.

Environment

  • @nativescript/core 9.x, Android API 26+

I have a PR with this fix plus unit tests ready to submit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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