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