Skip to main content

shared_collection

Function shared_collection 

Source
pub fn shared_collection() -> Collection
Available on crate feature unstable-fontique-07 only.
Expand description

Returns a clone of fontique::Collection that’s used by Slint for text rendering. It’s set up with shared storage, so fonts registered with the returned collection or additionally configured font fallbacks apply to the entire process.

Note: The recommended way of including custom fonts is at compile time of Slint files. For details, see also the Font Handling documentation.

The example below sketches out the steps for registering a downloaded font to add additional glyph coverage for Japanese text:

Cargo.toml:

slint = { version = "~1.15", features = ["unstable-fontique-07"] }

main.rs:

use slint::fontique_07::fontique;

fn main() {
    // ...
    let downloaded_font: Vec<u8> = todo!("Download https://somewebsite.com/font.ttf");
    let blob = fontique::Blob::new(std::sync::Arc::new(downloaded_font));
    let mut collection = slint::fontique_07::shared_collection();
    let fonts = collection.register_fonts(blob, None);
    collection
        .append_fallbacks(fontique::FallbackKey::new("Hira", None), fonts.iter().map(|x| x.0));
    collection
        .append_fallbacks(fontique::FallbackKey::new("Kana", None), fonts.iter().map(|x| x.0));
    collection
        .append_fallbacks(fontique::FallbackKey::new("Hani", None), fonts.iter().map(|x| x.0));
    // ...
}