Skip to content

Conversation

task-jp
Copy link
Contributor

@task-jp task-jp commented Oct 17, 2025

  • Bundle translations and detect browser language automatically
  • Load Noto Sans CJK fonts dynamically from GitHub at runtime
  • Add register_font_from_memory() API for runtime font registration
  • Export main() with #[wasm_bindgen] for explicit app startup control

Fonts are loaded before app initialization to ensure proper CJK text rendering across all major browsers without bundling font files.

- Bundle translations and detect browser language automatically
- Load Noto Sans CJK fonts dynamically from GitHub at runtime
- Add register_font_from_memory() API for runtime font registration
- Export main() with #[wasm_bindgen] for explicit app startup control

Fonts are loaded before app initialization to ensure proper CJK text
rendering across all major browsers without bundling font files.
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for doing this.

This adds API and we should be careful to either make it properly internal, or have it public.

Ideally our examples shouldn't use the internal API as they should show the capability for everyone, so I would recommend we try to polish this API and make this public.

slint_build::compile_with_config(
"gallery.slint",
slint_build::CompilerConfiguration::new()
.with_bundled_translations(concat!(env!("CARGO_MANIFEST_DIR"), "/lang/")),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the printerdemo only does it for wasm and android.

if target.contains("android") || target.contains("wasm32") {

I think we should do the same.

software-renderer-systemfonts = ["renderer-software", "i-slint-core/software-renderer-systemfonts"]

## Internal feature: Enable shared fontique font handling
shared-fontique = ["i-slint-core/shared-fontique"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this feature is meant to be internal , it should not be documented and have a name that shows it.
Example: https://github.com/slint-ui/slint/blob/55a45a6c339223a19bcd79fc191e79193f495a79/api/rs/build/Cargo.toml#L28C1-L28C14

Maybe something like experimental-register-font

But actually, i'd rather not have experimental API like this enabled from the slint crate, but directly on the i-slint-core crate, and have app that want to use internal API to use the i-slint-core directly.

}

/// Register a font from byte data dynamically.
pub fn register_font_from_memory(font_data: Vec<u8>) -> usize {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just wondering what's the most efficient and future proof API.
Also in the light of #4250

I'm thinking we could have something like
fn register_font_from_memory(font_data : impl AsRef[u8] + Sync + Send /* + 'static ? */) -> Result<???>

That way we could also pass a &'static str embedded in the binary or in mapped memory.


/// Register a font from memory.
#[cfg(feature = "shared-fontique")]
pub fn register_font_from_memory(font_data: alloc::vec::Vec<u8>) -> usize {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a re-export, it can be done with pub use.

///
/// Returns the number of font families that were registered from the provided data.
#[cfg(feature = "shared-fontique")]
pub fn register_font_from_memory(font_data: Vec<u8>) -> usize {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just wondering what's the most efficient and future proof API.
Also in the light of #4250

I'm thinking we could have something like
fn register_font_from_memory(font_data : impl AsRef[u8] + Sync + Send /* + 'static ? */) -> Result<???, RegisterFontError>

That way we could also pass a &'static str embedded in the binary or in mapped memory.

I see that you are returning the count, any reason to do that?
Maybe we could return some kind of FontHandle? Not sure what the use-case is to get access to that.
However, I think this could error for several reason (invalid format, unsupported by the backend or renderer, and stuff like that.)

We can also bike shed the name of this function.


let app = App::new().unwrap();

// For WASM builds, select translation after App::new()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably something we should do in i_slint_core instead.

fn index_for_locale(languages: &[&'static str]) -> Option<usize> {

Actually, we're already using the sys_locale crate and it should support wasm. But we probably need to enable extra feature in it for it to work?

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

Successfully merging this pull request may close these issues.

2 participants