1// Hebrew's shaper (hb-ot-shaper-hebrew.cc): presentation forms composed2// for faces without GPOS marks, and patah or qamats moved after a sheva3// or hiriq before a meteg.45import std::vector;6import std::option;78import pkg::alloy::text::shaping::buffer;9import pkg::alloy::text::shaping::plan;10import pkg::alloy::text::shaping::shapers;1112// Presentation forms with dagesh, for U+05D0 to U+05EA (0 where none).13const DAGESH_FORMS: [u32 : 27] = [14 0xFB30, 0xFB31, 0xFB32, 0xFB33, 0xFB34, 0xFB35, 0xFB36, 0x0000, 0xFB38, 0xFB39, 0xFB3A,15 0xFB3B, 0xFB3C, 0x0000, 0xFB3E, 0x0000, 0xFB40, 0xFB41, 0x0000, 0xFB43, 0xFB44, 0x0000,16 0xFB46, 0xFB47, 0xFB48, 0xFB49, 0xFB4A17];1819// The canonical composition, or for a face without GPOS marks the20// presentation forms normalization leaves out.21pub fn compose_hebrew(plan: &Plan, a: u32, b: u32) -> Option<u32> {22 if (unicode_composition(a, b) is ::Some |c|) {23 return ::Some(c);24 }25 if (plan.has_gpos_mark) {26 return ::None;27 }28 const found: u32 = match (b) {29 0x05B4 if (a == 0x05D9) 0xFB1D else 0; // hiriq30 0x05B7 if (a == 0x05F2) 0xFB1F else if (a == 0x05D0) 0xFB2E else 0; // patah31 0x05B8 if (a == 0x05D0) 0xFB2F else 0; // qamats32 0x05B9 if (a == 0x05D5) 0xFB4B else 0; // holam33 0x05BC dagesh_form(a); // dagesh34 0x05BF match (a) {35 // rafe36 0x05D1 0xFB4C;37 0x05DB 0xFB4D;38 0x05E4 0xFB4E;39 else 0;40 };41 0x05C1 if (a == 0x05E9) 0xFB2A else if (a == 0xFB49) 0xFB2C else 0; // shin dot42 0x05C2 if (a == 0x05E9) 0xFB2B else if (a == 0xFB49) 0xFB2D else 0; // sin dot43 else 0;44 };45 return if (found == 0) ::None else ::Some(found);46}4748fn dagesh_form(a: u32) -> u32 {49 if (a >= 0x05D0 && a <= 0x05EA) {50 return DAGESH_FORMS[(a - 0x05D0) to u64];51 }52 return if (a == 0xFB2A) 0xFB2C else if (a == 0xFB2B) 0xFB2D else 0;53}5455// A patah or qamats before a sheva or hiriq and a meteg or a mark below56// moves after the sheva or hiriq.57pub fn reorder_marks_hebrew(buffer: &var Buffer, start: u64, end: u64) {58 if (end < start + 3) {59 return;60 }61 for ([start + 2..end]) |i| {62 const c0 = buffer.infos.get(i - 2).combining_class();63 const c1 = buffer.infos.get(i - 1).combining_class();64 const c2 = buffer.infos.get(i).combining_class();65 if ((c0 == 20 || c0 == 21) && (c1 == 22 || c1 == 23) && (c2 == 25 || c2 == 220)) {66 buffer.merge_clusters(i - 1, i + 1);67 const moved = buffer.infos.get(i - 1);68 buffer.infos.get_var(i - 1) = buffer.infos.get(i);69 buffer.infos.get_var(i) = moved;70 break;71 }72 }73}