Skip to main content

set_shared_collection

Function set_shared_collection 

Source
pub fn set_shared_collection(
    collection: Collection,
) -> Result<(), PlatformError>
Available on crate feature unstable-fontique-012 only.
Expand description

Sets the font collection used for text rendering in the current thread’s context. Slint uses your collection as is and adds the fonts that .slint files import. To skip system font discovery, create the collection with system_fonts: false.

Call this before Slint initializes the platform, for example by creating a component or by calling set_platform(). If the platform is already initialized, this returns an error.

To register fonts after this call, use the collection returned by shared_collection().

For example, to make a font bundled with your application the default font:

use slint::fontique_012::fontique;

let mut collection = fontique::Collection::new(fontique::CollectionOptions {
    system_fonts: false,
    ..Default::default()
});
let font_data = std::fs::read("fonts/MyFont.ttf")?;
let fonts = collection.register_fonts(fontique::Blob::new(std::sync::Arc::new(font_data)), None);
// Text without a `font-family` uses the generic sans-serif family.
collection.set_generic_families(
    fontique::GenericFamily::SansSerif,
    fonts.iter().map(|(family_id, _)| *family_id),
);
slint::fontique_012::set_shared_collection(collection)?;