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.
Issue Description
On Android API 26+,
@nativescript/coreloads custom font files throughandroid.graphics.Typeface.Builderand passesfont-variation-settingsviasetFontVariationSettings. For a variable font, thefont-weightCSS property has no effect unless the caller also knows to pass an explicit'wght'variation setting:loadFontFromFilenever mapsfontWeightonto thewghtaxis, so e.g.font-family: 'MyVariableFont'; font-weight: 700renders at the font's default weight.Two adjacent problems:
computeFontCacheKeykeys 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.wghtaxis,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):The label renders at the font's default weight (400) because
setFontVariationSettingsis called with''(nowghtaxis).Proposed fix
In
loadFontFromFile, inject{ axis: 'wght', value: <numeric fontWeight> }into the variation settings when the caller did not setwghtexplicitly, includefontWeightincomputeFontCacheKey, and retry the build with the caller's explicit settings if thewght-augmented build throws.Environment
I have a PR with this fix plus unit tests ready to submit.