Skip to main content

ferroui_harfbuzz/
harf_buzz_application_extensions.rs

1use crate::HarfBuzzTextShaper;
2use ferroui_base::platform::ITextShaperImpl;
3use ferroui_base::FerroLocator;
4use ferroui_controls::AppBuilder;
5use std::rc::Rc;
6
7/// HarfBuzz text shaping subsystem initializer.
8pub struct HarfBuzzPlatform;
9
10impl HarfBuzzPlatform {
11    /// Registers the HarfBuzz text shaper in the service locator.
12    pub fn initialize() {
13        let text_shaper: Rc<dyn ITextShaperImpl> = Rc::new(HarfBuzzTextShaper::new());
14
15        FerroLocator::current_mutable().bind::<dyn ITextShaperImpl>().to_constant(text_shaper);
16    }
17}
18
19/// HarfBuzz application extensions.
20pub trait HarfBuzzApplicationExtensions {
21    /// Enable the HarfBuzz text shaper.
22    fn use_harfbuzz(&self) -> AppBuilder;
23}
24
25impl HarfBuzzApplicationExtensions for AppBuilder {
26    fn use_harfbuzz(&self) -> AppBuilder {
27        self.use_text_shaping_subsystem(HarfBuzzPlatform::initialize, "HarfBuzz")
28    }
29}