1use super::hb_font_t;
2use super::ot_shape::{hb_ot_shape_context_t, shape_internal};
3use super::ot_shape_plan::hb_ot_shape_plan_t;
4use crate::{script, Feature, GlyphBuffer, UnicodeBuffer};
5
6pub fn shape(face: &hb_font_t, features: &[Feature], mut buffer: UnicodeBuffer) -> GlyphBuffer {
15    buffer.0.guess_segment_properties();
16    let plan = hb_ot_shape_plan_t::new(
17        face,
18        buffer.0.direction,
19        buffer.0.script,
20        buffer.0.language.as_ref(),
21        features,
22    );
23    shape_with_plan(face, &plan, buffer)
24}
25
26pub fn shape_with_plan(
39    face: &hb_font_t,
40    plan: &hb_ot_shape_plan_t,
41    buffer: UnicodeBuffer,
42) -> GlyphBuffer {
43    let mut buffer = buffer.0;
44    buffer.guess_segment_properties();
45
46    buffer.enter();
47
48    debug_assert_eq!(buffer.direction, plan.direction);
49    debug_assert_eq!(
50        buffer.script.unwrap_or(script::UNKNOWN),
51        plan.script.unwrap_or(script::UNKNOWN)
52    );
53
54    if buffer.len > 0 {
55        let target_direction = buffer.direction;
57
58        #[cfg(feature = "wasm-shaper")]
59        {
60            super::shape_wasm::shape_with_wasm(face, plan, &mut buffer).unwrap_or_else(|| {
61                shape_internal(&mut hb_ot_shape_context_t {
62                    plan,
63                    face,
64                    buffer: &mut buffer,
65                    target_direction,
66                });
67            });
68        }
69        #[cfg(not(feature = "wasm-shaper"))]
70        {
71            shape_internal(&mut hb_ot_shape_context_t {
72                plan,
73                face,
74                buffer: &mut buffer,
75                target_direction,
76            });
77        }
78    }
79
80    GlyphBuffer(buffer)
81}