Status Update
Comments
ki...@google.com <ki...@google.com>
si...@google.com <si...@google.com>
ja...@gmail.com <ja...@gmail.com> #2
The issue is reproducible with core-ktx 1.2.0 and 1.3.0-rc01.
ru...@gcpsoftware.com <ru...@gcpsoftware.com> #3
The Typeface.weight is not a weight of the underlying font file. It is a display style. On older APIs, the display style is adjusted if the Typeface is created from single font. However, after moving to CustomFallbackBuilder, that adjustment is removed since it can crate Typeface from multiple style font files.
Looks like it is good to set display style by ResourcesCompat.getFont for backward compatibility.
e....@gmail.com <e....@gmail.com> #4
Hi Nona,
Can you please schedule a release after you merge the fix?
jh...@themeetgroup.com <jh...@themeetgroup.com> #5
Branch: androidx-master-dev
commit 3d6aa2e9b3243dcc4de1f54bd8d40339bd69cb05
Author: Seigo Nonaka <nona@google.com>
Date: Wed May 27 17:38:05 2020
Adjust the Typeface display style with the style of given font
This behavir is implicitly done by Typeface.Builder and
Typeface.createXXX function but not to be done by
Typeface.CustomFallbackBuilder since it is designed to be working
with multiple font files which has different style.
Looks like the style argument is ignored on older API implementation.
Bug: 156853883
Bug: 152023266
Test: ResourcesCompatTest#testGetFont_adjustDisplayStyle passes on 29
Test: ./gradlew core:core:connectedAndroidTest on API 29, 28, 23
Change-Id: I3a377c339a7aed50973cf11df86ddf0069f4ec25
A core/core/src/androidTest/assets/fonts/thin_italic.ttf
A core/core/src/androidTest/assets/fonts/thin_italic.ttx
M core/core/src/androidTest/java/androidx/core/content/res/ResourcesCompatTest.java
A core/core/src/androidTest/res/font/thin_italic.ttf
M core/core/src/main/java/androidx/core/graphics/TypefaceCompatApi29Impl.java
ap...@google.com <ap...@google.com> #7
Any way I can tell what version this will land in?
ap...@google.com <ap...@google.com> #9
Great—works as expected, thanks!
e....@gmail.com <e....@gmail.com> #10
This can be closed now
xa...@gmail.com <xa...@gmail.com> #11
TypefaceCompat.create was backported
but TextView textFontWeight attribute seams not
why?
Description
Motivation:
With android:textFontWeight backported (backed by the above-mentioned method) we could use text appearances with different weights - by referencing font family and weight - since API 16 (?) in AppCompatTextView.
This is currently only possible since API 28.
Another potential use is a future TypeAppearanceSpanCompat.
Example:
res/font/raleway.xml
<font-family xmlns:app="
<font
app:font="@font/raleway_thin"
app:fontStyle="normal"
app:fontWeight="100" />
<font
app:font="@font/raleway_thin_italic"
app:fontStyle="italic"
app:fontWeight="100" />
<font
app:font="@font/raleway_regular"
app:fontStyle="normal"
app:fontWeight="400" />
</font-family>
res/values/styles.xml
<resources>
<style name="TextAppearance.Raleway.Regular" parent="TextAppearance.AppCompat">
<item name="android:fontFamily">@font/raleway</item>
<item name="android:textFontWeight">400</item>
<item name="textFontWeight">400</item>
</style>
<style name="TextAppearance.Raleway.Thin" parent="TextAppearance.AppCompat">
<item name="android:fontFamily">@font/raleway</item>
<item name="android:textFontWeight">100</item>
<item name="textFontWeight">100</item>
</style>
<style name="TextAppearance.Raleway.Thin.Italic" parent="TextAppearance.AppCompat">
<item name="android:fontFamily">@font/raleway</item>
<item name="android:textFontWeight">100</item>
<item name="textFontWeight">100</item>
<item name="android:textStyle">italic</item>
</style>
</resources>
Example implementation:
On API 26-27 we could re-implement Typeface.create mentioned above as the backing JNI method already exists.
See
On API 21-25 we'd need to first create a Typeface with matching italic (using the Typeface.create with style API) and then use the JNI method to create weight alias.
See
On API 20 and below we could leverage the fact that the only place weight typefaces could come from are from ResourcesCompat.getFont so we use TypefaceCompat internals to find the font family and look for best match in Java.
See