Skip to main content

harfrust/ot/shaper/
syllabic.rs

1use crate::buffer::*;
2use crate::plan::ShapePlan;
3use crate::BufferFlags;
4use crate::GlyphInfo;
5use crate::ShaperFont;
6
7pub fn insert_dotted_circles(
8    font: &ShaperFont<'_, '_>,
9    buffer: &mut Buffer,
10    broken_syllable_type: u8,
11    dottedcircle_category: u8,
12    repha_category: Option<u8>,
13    dottedcircle_position: Option<u8>,
14) -> Option<bool> {
15    if buffer
16        .flags
17        .contains(BufferFlags::DO_NOT_INSERT_DOTTED_CIRCLE)
18    {
19        return Some(false);
20    }
21
22    if (buffer.scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_BROKEN_SYLLABLE) == 0 {
23        buffer_message!(
24            buffer,
25            font,
26            "skipped inserting dotted-circles because there is no broken syllables",
27        );
28        return Some(false);
29    }
30
31    if !buffer_message!(buffer, font, "start inserting dotted-circles") {
32        return Some(false);
33    }
34
35    let dottedcircle_glyph = match font.nominal_glyph(0x25CC) {
36        Some(g) => g.to_u32(),
37        None => return Some(false),
38    };
39
40    let mut dottedcircle = GlyphInfo {
41        glyph_id: 0x25CC,
42        ..GlyphInfo::default()
43    };
44    dottedcircle.set_ot_shaper_var_u8_category(dottedcircle_category);
45    if let Some(dottedcircle_position) = dottedcircle_position {
46        dottedcircle.set_ot_shaper_var_u8_auxiliary(dottedcircle_position);
47    }
48    dottedcircle.glyph_id = dottedcircle_glyph;
49
50    buffer.clear_output();
51
52    buffer.idx = 0;
53    let mut last_syllable = 0;
54    while buffer.idx < buffer.len {
55        let syllable = buffer.cur(0)?.syllable();
56        if last_syllable != syllable && (syllable & 0x0F) == broken_syllable_type {
57            last_syllable = syllable;
58
59            let mut ginfo = dottedcircle;
60            ginfo.cluster = buffer.cur(0)?.cluster;
61            ginfo.mask = buffer.cur(0)?.mask;
62            ginfo.set_syllable(buffer.cur(0)?.syllable());
63
64            // Insert dottedcircle after possible Repha.
65            if let Some(repha_category) = repha_category {
66                while buffer.idx < buffer.len
67                    && last_syllable == buffer.cur(0)?.syllable()
68                    && buffer.cur(0)?.ot_shaper_var_u8_category() == repha_category
69                {
70                    buffer.next_glyph();
71                }
72            }
73
74            buffer.output_info(ginfo);
75        } else {
76            buffer.next_glyph();
77        }
78    }
79
80    buffer.sync();
81
82    buffer_message!(buffer, font, "end inserting dotted-circles");
83
84    Some(true)
85}
86
87pub(crate) fn syllabic_clear_var(
88    _: &ShapePlan,
89    _: &ShaperFont<'_, '_>,
90    buffer: &mut Buffer,
91) -> Option<bool> {
92    for info in &mut buffer.info {
93        info.set_syllable(0);
94    }
95    buffer.deallocate_var(GlyphInfo::SYLLABLE_VAR);
96
97    Some(false)
98}