Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Load fonts from /system/fonts by default? #243

Open
hrydgard opened this issue Mar 16, 2024 · 3 comments
Open

Android: Load fonts from /system/fonts by default? #243

hrydgard opened this issue Mar 16, 2024 · 3 comments

Comments

@hrydgard
Copy link

On Android, cosmic-text will crash by default since it doesn't find any fonts. Once you do add fonts though, it works just fine, which is great.

On every Android device, a set of default fonts is located in /system/fonts, which is user-readable. This does not appear to be documented by the Android project officially anywhere - nevertheless, it's a fact that you'll find these fonts in that folder on every device, and there surely are lots of apps out there that depend on this.

Here's all I needed to do to get basic font families to work on Android (although there might also be some work to be done with fallbacks):

        let mut font_system = cosmic_text::FontSystem::new();

        #[cfg(target_os = "android")]
        {
            font_system.db_mut().load_fonts_dir("/system/fonts");
            font_system.db_mut().set_sans_serif_family("Roboto");
            font_system.db_mut().set_serif_family("Noto Serif");
            font_system.db_mut().set_monospace_family("Droid Sans Mono"); // Cutive Mono looks more printer-like
            font_system.db_mut().set_cursive_family("Dancing Script");
            font_system.db_mut().set_fantasy_family("Dancing Script");
        }

        // ... use the FontSystem as normal

If the project doesn't want to add this, at least this Github issue will now be searchable to find this workaround.

I'm not sure exactly how to set up the CJK fallback fonts, though. I've logged the info about the found faces from a PocoPhone F1 here.

@jackpot51
Copy link
Member

You could make a pr to fontdb to add this folder

@hrydgard
Copy link
Author

Right, I suppose this issue belongs more in the fontdb repo, although the fallback code is in the cosmic-text repo: https://github.com/pop-os/cosmic-text/tree/main/src/font/fallback

@jackpot51
Copy link
Member

Yes, there may need to be custom fallback code in cosmic-text, but the system font directories should be added in fontdb so other projects using it find the fonts as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants