Skip to main content

shared_collection

Function shared_collection 

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

Returns a clone of the fontique::Collection used for text rendering in the current thread’s context. It uses shared storage, so Slint sees the fonts you register and the fallbacks you configure.

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.19", features = ["unstable-fontique-012"] }

main.rs:

use slint::fontique_012::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_012::shared_collection();
    let fonts = collection.register_fonts(blob, None);
    collection
        .append_fallbacks(fontique::FallbackKey::new(fontique::Script::from_bytes(*b"Hira"), None), fonts.iter().map(|x| x.0));
    collection
        .append_fallbacks(fontique::FallbackKey::new(fontique::Script::from_bytes(*b"Kana"), None), fonts.iter().map(|x| x.0));
    collection
        .append_fallbacks(fontique::FallbackKey::new(fontique::Script::from_bytes(*b"Hani"), None), fonts.iter().map(|x| x.0));
    // ...
}