Before I go into potential pain of failing fonts, ...
# compose
j
Before I go into potential pain of failing fonts, does Compose google downloadable fonts supporting iOS in compose multiplatform? Or do I need to download the font manually and add the files into iOS and Android commonMain or such?
s
No downloadable fonts on ios :/
Since it depends on play services
j
Really on play services ... I guess some kind of certificate/SSL things borrowed from it 😞 I really dont like play services, even if only in Android app its so painful to work with. Ah well I guess need to implement my own downloadable fonts layer again.
s
Just to share information, not that they are useful for yourcase: The download, schedule, updating the available fonts etc are done by play services (in a module named fonts) and developed by google fonts. That module starting from android s also updates some fonts on the system such as emoji. The download mechanism being centralized also helps to keep only one copy and serve it to all apps.
j
@Siyamed Do you know if any plans open up this? :) Would also help multiplatform in compose as well actually.
s
Please create a ticket. I do not remember the interface details at the top of my head. Would be helpful to know what blocks you.
j
Will do. The main issue its sealed interface which not allow you implement same in another JVM module. Convert to regular interface would help a lot. And also decouple Android font related stuff. Mixing a lot of Android SDK specifics internally.
s
@Sean McQuillan [G] as fyi
s
You can build it yourself!
Downloadable fonts in compose are intentionally not limited to a single provider
What you need: 1. The equivalent of
AndroidFont
for your platform (a subclassable version of
Font
) 2. Define a new
FontLoadingStrategy.Async
font subclass 3. Do whatever you need to do to load the font
Font will remain a sealed interface - platforms should vend a Font concrete subclass like AndroidFont that works with their loading engine
The complication here is a Font is just a descriptor, it doesn’t really know how to do anything - there’s a whole platform-specific font loading mechanism and Fonts should only describe things that are supportable on the platform
The GoogleFont subclass we ship will likely remain an Android thing, but I intentionally designed it to be open so alternative implementations are possible
(as an aside, if you want to build alternative font providers on Android, you can start by copy/pasting GoogleFont and editing it to load from another source - it’s by design in a separate module)
j
As of example earlier wanted fallback font and override but then neither AndroidFont or GoogleFont allows me mixing. So need implement the entire font loading chain from scratch. Where do I inject the Font loading strategy thing? What I would like todo is override FontLoader in Compose and sharing the coroutine and async cache mechanisms as very tricky get right. @Sean McQuillan [G] Will you somehow be willing open these parts up or is implement it from scratch my only option?
https://source.android.com/docs/core/fonts/custom-font-fallback And
LocalFontFamilyResolver
I refer to :)
s
Those docs are for OEMs to install fonts on a device
Basically, when an OEM installs a custom emoji font that overrides the default font, they have to keep NotoColorEmoji.ttf or allow updatable system fonts to update it. This is to ensure that even if the override font gets out of date the device still gets new emoji every winter when unicode adds new codepoint sequences
There’s no public APIs for replacing the font system (and no plans to build such hooks) - without API support on the platform you’re basically looking at replacing the entire font and text rendering stack yea
You should ask for iOS to add a Font type that’s equivalent to AndroidFont. These things are fundamentally platform specific and the APIs fork at the level of platform font definitions intentionally.
In the short term, your best bet would be to embed the font file in the APK
which does have xplat hooks
j
As for iOS font, meaning like a new androidx compose ui text iOS variant or multiplatform support inside androidx for it? And yeah include a large resource list for fonts was what I wanted to avoid, save binary size in both Android and iOS as well as support fonts for all languages. It does work even if not ideal. Like downloadable google fonts not working on iOS without google play services as mentioned.
s
It’s not really a play services dependency, this is something the iOS/compose typography will have to support
Compose fonts don’t have a play services dependency
on Android, the Google Fonts library we ship will always go through play services as that’s how we do caching etc.
j
Right now I understand, you mean compose multiplatform need to implement it 🙂 I was thinking about implement that myself as not available. This is kind of what curious about, how to mixing libraries. Like sharing some stuff with jetbrains compose stuff and some not. I know Google and Jetbrains improving this, just thinking how to solve it right now 🙂