harfrust/ot/shaper/
hebrew.rs1use super::Tag;
2use super::*;
3use crate::buffer::Buffer;
4use crate::plan::ShapePlan;
5use crate::unicode::{self, combining_class, modified_combining_class, Codepoint};
6
7pub const HEBREW_SHAPER: OtShaper = OtShaper {
8 collect_features: None,
9 override_features: None,
10 create_data: None,
11 preprocess_text: None,
12 postprocess_glyphs: None,
13 normalization_preference: NormalizationMode::Auto,
14 decompose: None,
15 compose: Some(compose),
16 setup_masks: None,
17 gpos_tag: Some(Tag::new(b"hebr")),
18 reorder_marks: Some(reorder_marks_hebrew),
19 zero_width_marks: ZeroWidthMarks::ByGdefLate,
20 fallback_position: true,
21};
22
23fn reorder_marks_hebrew(_: &ShapePlan, buffer: &mut Buffer, start: usize, end: usize) {
24 let marks = buffer.info.get(start..end).unwrap_or_default();
25 let found = marks.windows(3).position(|window| {
26 let [c0, c1, c2] = window else {
27 return false;
28 };
29
30 (c0.modified_combining_class() == modified_combining_class::CCC17
32 || c0.modified_combining_class() == modified_combining_class::CCC18)
33 && (c1.modified_combining_class() == modified_combining_class::CCC10
35 || c1.modified_combining_class() == modified_combining_class::CCC14)
36 && (c2.modified_combining_class() == modified_combining_class::CCC22
38 || c2.modified_combining_class() == combining_class::Below)
39 });
40
41 if let Some(offset) = found {
42 let i = start + offset + 2;
43 buffer.merge_clusters(i - 1, i + 1);
44 if let Some(pair) = buffer.info.get_mut(i - 1..=i) {
45 pair.swap(0, 1);
46 }
47 }
48}
49
50static S_DAGESH_FORMS: &[Codepoint] = &[
51 0xFB30, 0xFB31, 0xFB32, 0xFB33, 0xFB34, 0xFB35, 0xFB36, 0x0000, 0xFB38, 0xFB39, 0xFB3A, 0xFB3B, 0xFB3C, 0x0000, 0xFB3E, 0x0000, 0xFB40, 0xFB41, 0x0000, 0xFB43, 0xFB44, 0x0000, 0xFB46, 0xFB47, 0xFB48, 0xFB49, 0xFB4A, ];
79
80fn compose(ctx: &NormalizeContext, a: Codepoint, b: Codepoint) -> Option<Codepoint> {
81 match unicode::compose(a, b) {
86 Some(c) => Some(c),
87 None if !ctx.plan.has_gpos_mark => {
88 match b {
91 0x05B4 => {
92 match a {
94 0x05D9 => Some(0xFB1D), _ => None,
96 }
97 }
98 0x05B7 => {
99 match a {
101 0x05D9 => Some(0xFB1F), 0x05D0 => Some(0xFB2E), _ => None,
104 }
105 }
106 0x05B8 => {
107 match a {
109 0x05D0 => Some(0xFB2F), _ => None,
111 }
112 }
113 0x05B9 => {
114 match a {
116 0x05D5 => Some(0xFB4B), _ => None,
118 }
119 }
120 0x05BC => {
121 match a {
123 0x05D0..=0x05EA => {
124 let c = S_DAGESH_FORMS[a as usize - 0x05D0];
125 if c != 0 {
126 Some(c)
127 } else {
128 None
129 }
130 }
131 0xFB2A => Some(0xFB2C), 0xFB2B => Some(0xFB2D), _ => None,
134 }
135 }
136 0x05BF => {
137 match a {
139 0x05D1 => Some(0xFB4C), 0x05DB => Some(0xFB4D), 0x05E4 => Some(0xFB4E), _ => None,
143 }
144 }
145 0x05C1 => {
146 match a {
148 0x05E9 => Some(0xFB2A), 0xFB49 => Some(0xFB2C), _ => None,
151 }
152 }
153 0x05C2 => {
154 match a {
156 0x05E9 => Some(0xFB2B), 0xFB49 => Some(0xFB2D), _ => None,
159 }
160 }
161 _ => None,
162 }
163 }
164 None => None,
165 }
166}