fix(android): bundle the typefaces instead of fetching them at runtime
android / Build + lint + test (push) Successful in 4m19s
android / Build + lint + test (push) Successful in 4m19s
Typography.kt resolved Fraunces, Inter and JetBrains Mono through the Play Services font provider, which fetches them over the network on first use. Same rule-164 problem the web client had, with a second failure mode on top: the provider is absent entirely on devices without Play Services, so the app fell back to the platform default and stopped looking like Minstrel — quietly, with no error. The five static instances now live in res/font, vendored by the same tools/vendor-fonts.py that produces the web bundle. Both clients draw from one list of faces so they cannot drift apart. Cost is ~0.86 MB of APK; the runtime path is removed rather than kept as a fallback — the ui-text-google-fonts dependency, its version-catalog entry and the provider certificate hashes in font_certs.xml are all gone. Two things about fetching TTFs that are worth writing down, because both fail by succeeding: Google Fonts picks the format from the User-Agent, and there is no parameter to ask for one. A modern UA gets woff2, which res/font cannot load. The obvious "use an old UA" fix gets EOT — an IE-only format that downloads happily, has a plausible size, and is entirely useless here. An Android 4.4 UA is what actually yields TrueType. css2 also collapses a multi-weight request to 400 for legacy clients, so asking for Medium silently returns Regular: a valid TrueType file that renders at the wrong weight everywhere. Each weight is therefore fetched on its own URL, and the script now asserts OS/2 usWeightClass on every download — that field is the only thing distinguishing the two files. Verified before wiring: all five carry TrueType magic, the 400/500 pairs differ, and their usWeightClass reads 400/400/500/500/400 as declared beside them in the FontFamily. Not covered: there is no guard for this on the Android side. The web equivalent is asserted by no-external-assets.test.ts, but the Android tree has no source-inspection test pattern to follow and no way to falsify one without a local Gradle run. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SQ31KQpYbStyK5y58UmPLH
This commit is contained in:
@@ -150,7 +150,6 @@ dependencies {
|
||||
implementation(libs.compose.ui)
|
||||
implementation(libs.compose.ui.graphics)
|
||||
implementation(libs.compose.material3)
|
||||
implementation(libs.compose.ui.text.google.fonts)
|
||||
debugImplementation(libs.compose.ui.tooling)
|
||||
implementation(libs.compose.ui.tooling.preview)
|
||||
|
||||
|
||||
@@ -2,72 +2,45 @@ package com.fabledsword.minstrel.theme
|
||||
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.googlefonts.Font
|
||||
import androidx.compose.ui.text.googlefonts.GoogleFont
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.fabledsword.minstrel.R
|
||||
|
||||
/**
|
||||
* Google Fonts provider — fetches font files via Play Services Fonts at
|
||||
* runtime, caches them across launches. Matches the Flutter client's
|
||||
* `google_fonts` package behaviour (no bundled .ttf files in either tree).
|
||||
* Bundled typefaces, vendored into res/font by tools/vendor-fonts.py.
|
||||
*
|
||||
* These were fetched at runtime through the Play Services font provider until
|
||||
* 2026-09-09. That is a network dependency for rendering, and a deployed
|
||||
* instance is not guaranteed one — the provider is also absent entirely on
|
||||
* devices without Play Services, where the app silently fell back to the
|
||||
* platform default and stopped looking like Minstrel. Bundling costs ~0.86 MB
|
||||
* of APK and removes both failure modes.
|
||||
*
|
||||
* Per FabledSword design system:
|
||||
* - Fraunces — display + headline (mythic serif)
|
||||
* - Inter — body + label (clean sans for UI text)
|
||||
* - JetBrains Mono — technical / monospace
|
||||
* Weights are restricted to 400 (regular) and 500 (medium) only.
|
||||
*
|
||||
* Each res/font entry is a single static instance, not a variable font: the
|
||||
* weight declared beside it here must match the file's own OS/2
|
||||
* usWeightClass, which the vendoring script asserts on download.
|
||||
*/
|
||||
private val GoogleFontProvider = GoogleFont.Provider(
|
||||
providerAuthority = "com.google.android.gms.fonts",
|
||||
providerPackage = "com.google.android.gms",
|
||||
certificates = R.array.com_google_android_gms_fonts_certs,
|
||||
)
|
||||
|
||||
private val FrauncesFont = GoogleFont("Fraunces")
|
||||
private val InterFont = GoogleFont("Inter")
|
||||
private val JetBrainsMonoFont = GoogleFont("JetBrains Mono")
|
||||
|
||||
private val Fraunces = FontFamily(
|
||||
Font(
|
||||
googleFont = FrauncesFont,
|
||||
fontProvider = GoogleFontProvider,
|
||||
weight = FontWeight.W400,
|
||||
style = FontStyle.Normal,
|
||||
),
|
||||
Font(
|
||||
googleFont = FrauncesFont,
|
||||
fontProvider = GoogleFontProvider,
|
||||
weight = FontWeight.W500,
|
||||
style = FontStyle.Normal,
|
||||
),
|
||||
Font(R.font.fraunces_regular, FontWeight.W400, FontStyle.Normal),
|
||||
Font(R.font.fraunces_medium, FontWeight.W500, FontStyle.Normal),
|
||||
)
|
||||
|
||||
private val Inter = FontFamily(
|
||||
Font(
|
||||
googleFont = InterFont,
|
||||
fontProvider = GoogleFontProvider,
|
||||
weight = FontWeight.W400,
|
||||
style = FontStyle.Normal,
|
||||
),
|
||||
Font(
|
||||
googleFont = InterFont,
|
||||
fontProvider = GoogleFontProvider,
|
||||
weight = FontWeight.W500,
|
||||
style = FontStyle.Normal,
|
||||
),
|
||||
Font(R.font.inter_regular, FontWeight.W400, FontStyle.Normal),
|
||||
Font(R.font.inter_medium, FontWeight.W500, FontStyle.Normal),
|
||||
)
|
||||
|
||||
private val JetBrainsMono = FontFamily(
|
||||
Font(
|
||||
googleFont = JetBrainsMonoFont,
|
||||
fontProvider = GoogleFontProvider,
|
||||
weight = FontWeight.W400,
|
||||
style = FontStyle.Normal,
|
||||
),
|
||||
Font(R.font.jetbrains_mono_regular, FontWeight.W400, FontStyle.Normal),
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Google Fonts provider certificate hashes for downloadable fonts via
|
||||
androidx.compose.ui.text.googlefonts.GoogleFont.Provider. Standard
|
||||
values published by Google; copied verbatim from the AndroidX docs. -->
|
||||
<resources>
|
||||
<array name="com_google_android_gms_fonts_certs">
|
||||
<item>@array/com_google_android_gms_fonts_certs_dev</item>
|
||||
<item>@array/com_google_android_gms_fonts_certs_prod</item>
|
||||
</array>
|
||||
<string-array name="com_google_android_gms_fonts_certs_dev">
|
||||
<item>MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAeFw0wODA0MTUyMzM2NTZaFw0zNTA5MDEyMzM2NTZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBANbOLggKv+IxTdGNs8/TGFy0PTP6DHThvbbR24kT9ixcOd9W+EaBPWW+wPPKQmsHxajtWjmQwWfna8mZuSeJS48LIgAZlKkpoyLcfobBPv6yyz8x1IxWWmF9c1IGN3vSL6BLNJEUyMEPzC2WZdwT4ZG2cuJTtzeETl6jWFKx68ETtZxNVHe9Iy9NMxEljDqVZ4y6+FlHaiYJqq3LcJpJVuKYz4kvOcyf3M0nDA8mUlVdfsOlw/H4uoNQ7VrAQUKB4kAyfxsKp/RZmnZSJ7+8Ag9aTC+oguTd1iFNuMqDUlpePo6CGuh73iKuq8mYvtdQQ0Yz+mF4j2YWB7Gj0R1k2cCAQOjgfwwgfkwHQYDVR0OBBYEFI0cxb6VTEM8YYY6FbBMvAPyT+CyMIHJBgNVHSMEgcEwgb6AFI0cxb6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YTcyowQHRPCRsPzCCl4ANULRpZjxAd0xUgg=</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
@@ -53,7 +53,6 @@ compose-ui-graphics = { module = "androidx.compose.ui:ui-graphics" }
|
||||
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
|
||||
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" }
|
||||
compose-material3 = { module = "androidx.compose.material3:material3" }
|
||||
compose-ui-text-google-fonts = { module = "androidx.compose.ui:ui-text-google-fonts" }
|
||||
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
|
||||
hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hilt" }
|
||||
room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
|
||||
|
||||
Reference in New Issue
Block a user