1 | use crate::hb::buffer::HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT; |
2 | use crate::hb::ot_layout_gpos_table::{attach_type, AnchorExt}; |
3 | use crate::hb::ot_layout_gsubgpos::OT::hb_ot_apply_context_t; |
4 | use ttf_parser::gpos::{AnchorMatrix, MarkArray}; |
5 | |
6 | pub(crate) trait MarkArrayExt { |
7 | fn apply( |
8 | &self, |
9 | ctx: &mut hb_ot_apply_context_t, |
10 | anchors: AnchorMatrix, |
11 | mark_index: u16, |
12 | glyph_index: u16, |
13 | glyph_pos: usize, |
14 | ) -> Option<()>; |
15 | } |
16 | |
17 | impl MarkArrayExt for MarkArray<'_> { |
18 | fn apply( |
19 | &self, |
20 | ctx: &mut hb_ot_apply_context_t, |
21 | anchors: AnchorMatrix, |
22 | mark_index: u16, |
23 | glyph_index: u16, |
24 | glyph_pos: usize, |
25 | ) -> Option<()> { |
26 | // If this subtable doesn't have an anchor for this base and this class |
27 | // return `None` such that the subsequent subtables have a chance at it. |
28 | let (mark_class, mark_anchor) = self.get(mark_index)?; |
29 | let base_anchor = anchors.get(glyph_index, mark_class)?; |
30 | |
31 | let (mark_x, mark_y) = mark_anchor.get(ctx.face); |
32 | let (base_x, base_y) = base_anchor.get(ctx.face); |
33 | |
34 | ctx.buffer |
35 | .unsafe_to_break(Some(glyph_pos), Some(ctx.buffer.idx + 1)); |
36 | |
37 | let idx = ctx.buffer.idx; |
38 | let pos = ctx.buffer.cur_pos_mut(); |
39 | pos.x_offset = base_x - mark_x; |
40 | pos.y_offset = base_y - mark_y; |
41 | pos.set_attach_type(attach_type::MARK); |
42 | pos.set_attach_chain((glyph_pos as isize - idx as isize) as i16); |
43 | |
44 | ctx.buffer.scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT; |
45 | ctx.buffer.idx += 1; |
46 | |
47 | Some(()) |
48 | } |
49 | } |
50 | |