rustybuzz/hb/
ot_shape_plan.rs

1use alloc::boxed::Box;
2use alloc::vec::Vec;
3use core::any::Any;
4
5use super::ot_map::*;
6use super::ot_shape::*;
7use super::ot_shaper::*;
8use super::{hb_font_t, hb_mask_t, Direction, Feature, Language, Script};
9
10/// A reusable plan for shaping a text buffer.
11pub struct hb_ot_shape_plan_t {
12    pub(crate) direction: Direction,
13    pub(crate) script: Option<Script>,
14    pub(crate) shaper: &'static hb_ot_shaper_t,
15    pub(crate) ot_map: hb_ot_map_t,
16    pub(crate) data: Option<Box<dyn Any + Send + Sync>>,
17
18    pub(crate) frac_mask: hb_mask_t,
19    pub(crate) numr_mask: hb_mask_t,
20    pub(crate) dnom_mask: hb_mask_t,
21    pub(crate) rtlm_mask: hb_mask_t,
22    pub(crate) kern_mask: hb_mask_t,
23    pub(crate) trak_mask: hb_mask_t,
24
25    pub(crate) requested_kerning: bool,
26    pub(crate) has_frac: bool,
27    pub(crate) has_vert: bool,
28    pub(crate) has_gpos_mark: bool,
29    pub(crate) zero_marks: bool,
30    pub(crate) fallback_glyph_classes: bool,
31    pub(crate) fallback_mark_positioning: bool,
32    pub(crate) adjust_mark_positioning_when_zeroing: bool,
33
34    pub(crate) apply_gpos: bool,
35    pub(crate) apply_fallback_kern: bool,
36    pub(crate) apply_kern: bool,
37    pub(crate) apply_kerx: bool,
38    pub(crate) apply_morx: bool,
39    pub(crate) apply_trak: bool,
40
41    pub(crate) user_features: Vec<Feature>,
42}
43
44impl hb_ot_shape_plan_t {
45    /// Returns a plan that can be used for shaping any buffer with the
46    /// provided properties.
47    pub fn new(
48        face: &hb_font_t,
49        direction: Direction,
50        script: Option<Script>,
51        language: Option<&Language>,
52        user_features: &[Feature],
53    ) -> Self {
54        assert_ne!(direction, Direction::Invalid);
55        let mut planner = hb_ot_shape_planner_t::new(face, direction, script, language);
56        planner.collect_features(user_features);
57        planner.compile(user_features)
58    }
59
60    pub(crate) fn data<T: 'static>(&self) -> &T {
61        self.data.as_ref().unwrap().downcast_ref().unwrap()
62    }
63}
64
65#[cfg(test)]
66mod tests {
67    use super::hb_ot_shape_plan_t;
68
69    #[test]
70    fn test_shape_plan_is_send_and_sync() {
71        fn ensure_send_and_sync<T: Send + Sync>() {}
72        ensure_send_and_sync::<hb_ot_shape_plan_t>();
73    }
74}