diff --git a/src/gen-use-table.py b/src/gen-use-table.py index a1865e967..ae7765798 100755 --- a/src/gen-use-table.py +++ b/src/gen-use-table.py @@ -462,6 +462,7 @@ print () print ('#ifndef HB_NO_OT_SHAPE') print () print ('#include "hb-ot-shape-complex-use.hh"') +print ('#include "hb-ot-shape-complex-use-machine.hh"') print () total = 0 @@ -503,12 +504,12 @@ print ('#pragma GCC diagnostic push') print ('#pragma GCC diagnostic ignored "-Wunused-macros"') for k,v in sorted(use_mapping.items()): if k in use_positions and use_positions[k]: continue - print ("#define %s USE_%s /* %s */" % (k, k, v.__name__[3:])) + print ("#define %s USE(%s) /* %s */" % (k, k, v.__name__[3:])) for k,v in sorted(use_positions.items()): if not v: continue for suf in v.keys(): tag = k + suf - print ("#define %s USE_%s" % (tag, tag)) + print ("#define %s USE(%s)" % (tag, tag)) print ('#pragma GCC diagnostic pop') print ("") print ("static const USE_TABLE_ELEMENT_TYPE use_table[] = {") @@ -564,7 +565,7 @@ for p in sorted(pages): print (" default:") print (" break;") print (" }") -print (" return USE_O;") +print (" return USE(O);") print ("}") print () for k in sorted(use_mapping.keys()): diff --git a/src/hb-ot-shape-complex-use-machine.hh b/src/hb-ot-shape-complex-use-machine.hh index 9892ce000..27ad4f6be 100644 --- a/src/hb-ot-shape-complex-use-machine.hh +++ b/src/hb-ot-shape-complex-use-machine.hh @@ -32,6 +32,7 @@ #define HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH #include "hb.hh" +#include "hb-ot-shape-complex-use.hh" /* buffer var allocations */ #define use_category() complex_var_u8_category() @@ -50,7 +51,7 @@ enum use_syllable_type_t { }; -#line 54 "hb-ot-shape-complex-use-machine.hh" +#line 55 "hb-ot-shape-complex-use-machine.hh" #define use_syllable_machine_ex_B 1u #define use_syllable_machine_ex_CMAbv 31u #define use_syllable_machine_ex_CMBlw 32u @@ -92,7 +93,7 @@ enum use_syllable_type_t { #define use_syllable_machine_ex_ZWNJ 14u -#line 96 "hb-ot-shape-complex-use-machine.hh" +#line 97 "hb-ot-shape-complex-use-machine.hh" static const unsigned char _use_syllable_machine_trans_keys[] = { 1u, 1u, 1u, 1u, 0u, 51u, 11u, 48u, 11u, 48u, 1u, 1u, 22u, 48u, 23u, 48u, 24u, 47u, 25u, 47u, 26u, 47u, 45u, 46u, 46u, 46u, 24u, 48u, 24u, 48u, 24u, 48u, @@ -361,11 +362,11 @@ static const int use_syllable_machine_error = -1; static const int use_syllable_machine_en_main = 2; -#line 55 "hb-ot-shape-complex-use-machine.rl" +#line 56 "hb-ot-shape-complex-use-machine.rl" -#line 168 "hb-ot-shape-complex-use-machine.rl" +#line 173 "hb-ot-shape-complex-use-machine.rl" #define found_syllable(syllable_type) \ @@ -379,9 +380,9 @@ static const int use_syllable_machine_en_main = 2; static bool not_standard_default_ignorable (const hb_glyph_info_t &i) -{ return !(i.use_category() == USE_O && _hb_glyph_info_is_default_ignorable (&i)); } +{ return !(i.use_category() == USE(O) && _hb_glyph_info_is_default_ignorable (&i)); } -static void +static inline void find_syllables_use (hb_buffer_t *buffer) { hb_glyph_info_t *info = buffer->info; @@ -392,7 +393,7 @@ find_syllables_use (hb_buffer_t *buffer) hb_second) | hb_filter ([&] (const hb_pair_t p) { - if (p.second.use_category() == USE_ZWNJ) + if (p.second.use_category() == USE(ZWNJ)) for (unsigned i = p.first + 1; i < buffer->len; ++i) if (not_standard_default_ignorable (info[i])) return !_hb_glyph_info_is_unicode_mark (&info[i]); @@ -408,7 +409,7 @@ find_syllables_use (hb_buffer_t *buffer) unsigned int act HB_UNUSED; int cs; -#line 412 "hb-ot-shape-complex-use-machine.hh" +#line 413 "hb-ot-shape-complex-use-machine.hh" { cs = use_syllable_machine_start; ts = 0; @@ -416,12 +417,12 @@ find_syllables_use (hb_buffer_t *buffer) act = 0; } -#line 212 "hb-ot-shape-complex-use-machine.rl" +#line 217 "hb-ot-shape-complex-use-machine.rl" unsigned int syllable_serial = 1; -#line 425 "hb-ot-shape-complex-use-machine.hh" +#line 426 "hb-ot-shape-complex-use-machine.hh" { int _slen; int _trans; @@ -435,7 +436,7 @@ _resume: #line 1 "NONE" {ts = p;} break; -#line 439 "hb-ot-shape-complex-use-machine.hh" +#line 440 "hb-ot-shape-complex-use-machine.hh" } _keys = _use_syllable_machine_trans_keys + (cs<<1); @@ -458,62 +459,62 @@ _eof_trans: {te = p+1;} break; case 5: -#line 155 "hb-ot-shape-complex-use-machine.rl" +#line 160 "hb-ot-shape-complex-use-machine.rl" {te = p+1;{ found_syllable (independent_cluster); }} break; case 9: -#line 158 "hb-ot-shape-complex-use-machine.rl" +#line 163 "hb-ot-shape-complex-use-machine.rl" {te = p+1;{ found_syllable (standard_cluster); }} break; case 7: -#line 163 "hb-ot-shape-complex-use-machine.rl" +#line 168 "hb-ot-shape-complex-use-machine.rl" {te = p+1;{ found_syllable (broken_cluster); }} break; case 6: -#line 164 "hb-ot-shape-complex-use-machine.rl" +#line 169 "hb-ot-shape-complex-use-machine.rl" {te = p+1;{ found_syllable (non_cluster); }} break; case 10: -#line 156 "hb-ot-shape-complex-use-machine.rl" +#line 161 "hb-ot-shape-complex-use-machine.rl" {te = p;p--;{ found_syllable (virama_terminated_cluster); }} break; case 11: -#line 157 "hb-ot-shape-complex-use-machine.rl" +#line 162 "hb-ot-shape-complex-use-machine.rl" {te = p;p--;{ found_syllable (sakot_terminated_cluster); }} break; case 8: -#line 158 "hb-ot-shape-complex-use-machine.rl" +#line 163 "hb-ot-shape-complex-use-machine.rl" {te = p;p--;{ found_syllable (standard_cluster); }} break; case 13: -#line 159 "hb-ot-shape-complex-use-machine.rl" +#line 164 "hb-ot-shape-complex-use-machine.rl" {te = p;p--;{ found_syllable (number_joiner_terminated_cluster); }} break; case 12: -#line 160 "hb-ot-shape-complex-use-machine.rl" +#line 165 "hb-ot-shape-complex-use-machine.rl" {te = p;p--;{ found_syllable (numeral_cluster); }} break; case 14: -#line 161 "hb-ot-shape-complex-use-machine.rl" +#line 166 "hb-ot-shape-complex-use-machine.rl" {te = p;p--;{ found_syllable (symbol_cluster); }} break; case 17: -#line 162 "hb-ot-shape-complex-use-machine.rl" +#line 167 "hb-ot-shape-complex-use-machine.rl" {te = p;p--;{ found_syllable (hieroglyph_cluster); }} break; case 15: -#line 163 "hb-ot-shape-complex-use-machine.rl" +#line 168 "hb-ot-shape-complex-use-machine.rl" {te = p;p--;{ found_syllable (broken_cluster); }} break; case 16: -#line 164 "hb-ot-shape-complex-use-machine.rl" +#line 169 "hb-ot-shape-complex-use-machine.rl" {te = p;p--;{ found_syllable (non_cluster); }} break; case 1: -#line 163 "hb-ot-shape-complex-use-machine.rl" +#line 168 "hb-ot-shape-complex-use-machine.rl" {{p = ((te))-1;}{ found_syllable (broken_cluster); }} break; -#line 517 "hb-ot-shape-complex-use-machine.hh" +#line 518 "hb-ot-shape-complex-use-machine.hh" } _again: @@ -522,7 +523,7 @@ _again: #line 1 "NONE" {ts = 0;} break; -#line 526 "hb-ot-shape-complex-use-machine.hh" +#line 527 "hb-ot-shape-complex-use-machine.hh" } if ( ++p != pe ) @@ -538,7 +539,7 @@ _again: } -#line 217 "hb-ot-shape-complex-use-machine.rl" +#line 222 "hb-ot-shape-complex-use-machine.rl" } diff --git a/src/hb-ot-shape-complex-use-machine.rl b/src/hb-ot-shape-complex-use-machine.rl index 4c248e60b..c3408c922 100644 --- a/src/hb-ot-shape-complex-use-machine.rl +++ b/src/hb-ot-shape-complex-use-machine.rl @@ -30,6 +30,7 @@ #define HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH #include "hb.hh" +#include "hb-ot-shape-complex-use.hh" /* buffer var allocations */ #define use_category() complex_var_u8_category() @@ -56,6 +57,9 @@ enum use_syllable_type_t { %%{ +# Cateories used in the Universal Shaping Engine spec: +# https://docs.microsoft.com/en-us/typography/script-development/use + export O = 0; # OTHER export B = 1; # BASE @@ -99,6 +103,7 @@ export FMAbv = 45; # CONS_FINAL_MOD UIPC = Top export FMBlw = 46; # CONS_FINAL_MOD UIPC = Bottom export FMPst = 47; # CONS_FINAL_MOD UIPC = Not_Applicable + h = H | HVM | Sk; consonant_modifiers = CMAbv* CMBlw* ((h B | SUB) CMAbv? CMBlw*)*; @@ -178,9 +183,9 @@ main := |* static bool not_standard_default_ignorable (const hb_glyph_info_t &i) -{ return !(i.use_category() == USE_O && _hb_glyph_info_is_default_ignorable (&i)); } +{ return !(i.use_category() == USE(O) && _hb_glyph_info_is_default_ignorable (&i)); } -static void +static inline void find_syllables_use (hb_buffer_t *buffer) { hb_glyph_info_t *info = buffer->info; @@ -191,7 +196,7 @@ find_syllables_use (hb_buffer_t *buffer) hb_second) | hb_filter ([&] (const hb_pair_t p) { - if (p.second.use_category() == USE_ZWNJ) + if (p.second.use_category() == USE(ZWNJ)) for (unsigned i = p.first + 1; i < buffer->len; ++i) if (not_standard_default_ignorable (info[i])) return !_hb_glyph_info_is_unicode_mark (&info[i]); diff --git a/src/hb-ot-shape-complex-use-table.cc b/src/hb-ot-shape-complex-use-table.cc index cc1c1bd9f..f19e3814b 100644 --- a/src/hb-ot-shape-complex-use-table.cc +++ b/src/hb-ot-shape-complex-use-table.cc @@ -36,48 +36,49 @@ #ifndef HB_NO_OT_SHAPE #include "hb-ot-shape-complex-use.hh" +#include "hb-ot-shape-complex-use-machine.hh" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-macros" -#define B USE_B /* BASE */ -#define CS USE_CS /* CONS_WITH_STACKER */ -#define G USE_G /* HIEROGLYPH */ -#define GB USE_GB /* BASE_OTHER */ -#define H USE_H /* HALANT */ -#define HN USE_HN /* HALANT_NUM */ -#define HVM USE_HVM /* HALANT_OR_VOWEL_MODIFIER */ -#define J USE_J /* HIEROGLYPH_JOINER */ -#define N USE_N /* BASE_NUM */ -#define O USE_O /* OTHER */ -#define R USE_R /* REPHA */ -#define S USE_S /* SYM */ -#define SB USE_SB /* HIEROGLYPH_SEGMENT_BEGIN */ -#define SE USE_SE /* HIEROGLYPH_SEGMENT_END */ -#define SUB USE_SUB /* CONS_SUB */ -#define Sk USE_Sk /* SAKOT */ -#define ZWNJ USE_ZWNJ /* ZWNJ */ -#define CMAbv USE_CMAbv -#define CMBlw USE_CMBlw -#define FAbv USE_FAbv -#define FBlw USE_FBlw -#define FPst USE_FPst -#define FMAbv USE_FMAbv -#define FMBlw USE_FMBlw -#define FMPst USE_FMPst -#define MAbv USE_MAbv -#define MBlw USE_MBlw -#define MPst USE_MPst -#define MPre USE_MPre -#define SMAbv USE_SMAbv -#define SMBlw USE_SMBlw -#define VAbv USE_VAbv -#define VBlw USE_VBlw -#define VPst USE_VPst -#define VPre USE_VPre -#define VMAbv USE_VMAbv -#define VMBlw USE_VMBlw -#define VMPst USE_VMPst -#define VMPre USE_VMPre +#define B USE(B) /* BASE */ +#define CS USE(CS) /* CONS_WITH_STACKER */ +#define G USE(G) /* HIEROGLYPH */ +#define GB USE(GB) /* BASE_OTHER */ +#define H USE(H) /* HALANT */ +#define HN USE(HN) /* HALANT_NUM */ +#define HVM USE(HVM) /* HALANT_OR_VOWEL_MODIFIER */ +#define J USE(J) /* HIEROGLYPH_JOINER */ +#define N USE(N) /* BASE_NUM */ +#define O USE(O) /* OTHER */ +#define R USE(R) /* REPHA */ +#define S USE(S) /* SYM */ +#define SB USE(SB) /* HIEROGLYPH_SEGMENT_BEGIN */ +#define SE USE(SE) /* HIEROGLYPH_SEGMENT_END */ +#define SUB USE(SUB) /* CONS_SUB */ +#define Sk USE(Sk) /* SAKOT */ +#define ZWNJ USE(ZWNJ) /* ZWNJ */ +#define CMAbv USE(CMAbv) +#define CMBlw USE(CMBlw) +#define FAbv USE(FAbv) +#define FBlw USE(FBlw) +#define FPst USE(FPst) +#define FMAbv USE(FMAbv) +#define FMBlw USE(FMBlw) +#define FMPst USE(FMPst) +#define MAbv USE(MAbv) +#define MBlw USE(MBlw) +#define MPst USE(MPst) +#define MPre USE(MPre) +#define SMAbv USE(SMAbv) +#define SMBlw USE(SMBlw) +#define VAbv USE(VAbv) +#define VBlw USE(VBlw) +#define VPst USE(VPst) +#define VPre USE(VPre) +#define VMAbv USE(VMAbv) +#define VMBlw USE(VMBlw) +#define VMPst USE(VMPst) +#define VMPre USE(VMPre) #pragma GCC diagnostic pop static const USE_TABLE_ELEMENT_TYPE use_table[] = { @@ -1154,7 +1155,7 @@ hb_use_get_category (hb_codepoint_t u) default: break; } - return USE_O; + return USE(O); } #undef B diff --git a/src/hb-ot-shape-complex-use.cc b/src/hb-ot-shape-complex-use.cc index 23a0b3c24..5ae06ea12 100644 --- a/src/hb-ot-shape-complex-use.cc +++ b/src/hb-ot-shape-complex-use.cc @@ -221,7 +221,7 @@ setup_rphf_mask (const hb_ot_shape_plan_t *plan, foreach_syllable (buffer, start, end) { - unsigned int limit = info[start].use_category() == USE_R ? 1 : hb_min (3u, end - start); + unsigned int limit = info[start].use_category() == USE(R) ? 1 : hb_min (3u, end - start); for (unsigned int i = start; i < start + limit; i++) info[i].mask |= mask; } @@ -318,11 +318,11 @@ record_rphf_use (const hb_ot_shape_plan_t *plan, foreach_syllable (buffer, start, end) { - /* Mark a substituted repha as USE_R. */ + /* Mark a substituted repha as USE(R). */ for (unsigned int i = start; i < end && (info[i].mask & mask); i++) if (_hb_glyph_info_substituted (&info[i])) { - info[i].use_category() = USE_R; + info[i].use_category() = USE(R); break; } } @@ -341,7 +341,7 @@ record_pref_use (const hb_ot_shape_plan_t *plan HB_UNUSED, for (unsigned int i = start; i < end; i++) if (_hb_glyph_info_substituted (&info[i])) { - info[i].use_category() = USE_VPre; + info[i].use_category() = USE(VPre); break; } } @@ -350,7 +350,7 @@ record_pref_use (const hb_ot_shape_plan_t *plan HB_UNUSED, static inline bool is_halant_use (const hb_glyph_info_t &info) { - return (info.use_category() == USE_H || info.use_category() == USE_HVM) && + return (info.use_category() == USE(H) || info.use_category() == USE(HVM)) && !_hb_glyph_info_ligated (&info); } @@ -369,24 +369,24 @@ reorder_syllable_use (hb_buffer_t *buffer, unsigned int start, unsigned int end) hb_glyph_info_t *info = buffer->info; -#define POST_BASE_FLAGS64 (FLAG64 (USE_FAbv) | \ - FLAG64 (USE_FBlw) | \ - FLAG64 (USE_FPst) | \ - FLAG64 (USE_MAbv) | \ - FLAG64 (USE_MBlw) | \ - FLAG64 (USE_MPst) | \ - FLAG64 (USE_MPre) | \ - FLAG64 (USE_VAbv) | \ - FLAG64 (USE_VBlw) | \ - FLAG64 (USE_VPst) | \ - FLAG64 (USE_VPre) | \ - FLAG64 (USE_VMAbv) | \ - FLAG64 (USE_VMBlw) | \ - FLAG64 (USE_VMPst) | \ - FLAG64 (USE_VMPre)) +#define POST_BASE_FLAGS64 (FLAG64 (USE(FAbv)) | \ + FLAG64 (USE(FBlw)) | \ + FLAG64 (USE(FPst)) | \ + FLAG64 (USE(MAbv)) | \ + FLAG64 (USE(MBlw)) | \ + FLAG64 (USE(MPst)) | \ + FLAG64 (USE(MPre)) | \ + FLAG64 (USE(VAbv)) | \ + FLAG64 (USE(VBlw)) | \ + FLAG64 (USE(VPst)) | \ + FLAG64 (USE(VPre)) | \ + FLAG64 (USE(VMAbv)) | \ + FLAG64 (USE(VMBlw)) | \ + FLAG64 (USE(VMPst)) | \ + FLAG64 (USE(VMPre))) /* Move things forward. */ - if (info[start].use_category() == USE_R && end - start > 1) + if (info[start].use_category() == USE(R) && end - start > 1) { /* Got a repha. Reorder it towards the end, but before the first post-base * glyph. */ @@ -423,7 +423,7 @@ reorder_syllable_use (hb_buffer_t *buffer, unsigned int start, unsigned int end) * shift things in between forward. */ j = i + 1; } - else if (((flag) & (FLAG (USE_VPre) | FLAG (USE_VMPre))) && + else if (((flag) & (FLAG (USE(VPre)) | FLAG (USE(VMPre)))) && /* Only move the first component of a MultipleSubst. */ 0 == _hb_glyph_info_get_lig_comp (&info[i]) && j < i) @@ -445,8 +445,8 @@ reorder_use (const hb_ot_shape_plan_t *plan, { hb_syllabic_insert_dotted_circles (font, buffer, use_broken_cluster, - USE_B, - USE_R); + USE(B), + USE(R)); foreach_syllable (buffer, start, end) reorder_syllable_use (buffer, start, end); diff --git a/src/hb-ot-shape-complex-use.hh b/src/hb-ot-shape-complex-use.hh index 063a3dfaf..3d3a42082 100644 --- a/src/hb-ot-shape-complex-use.hh +++ b/src/hb-ot-shape-complex-use.hh @@ -36,58 +36,7 @@ #define USE_TABLE_ELEMENT_TYPE uint8_t -/* Cateories used in the Universal Shaping Engine spec: - * https://docs.microsoft.com/en-us/typography/script-development/use - */ -/* Note: This enum is duplicated in the -machine.rl source file. - * Not sure how to avoid duplication. */ -enum use_category_t { - USE_O = 0, /* OTHER */ - - USE_B = 1, /* BASE */ - USE_N = 4, /* BASE_NUM */ - USE_GB = 5, /* BASE_OTHER */ - USE_SUB = 11, /* CONS_SUB */ - USE_H = 12, /* HALANT */ - - USE_HN = 13, /* HALANT_NUM */ - USE_ZWNJ = 14, /* Zero width non-joiner */ - USE_R = 18, /* REPHA */ - USE_S = 19, /* SYM */ - USE_CS = 43, /* CONS_WITH_STACKER */ - - /* https://github.com/harfbuzz/harfbuzz/issues/1102 */ - USE_HVM = 44, /* HALANT_OR_VOWEL_MODIFIER */ - - USE_Sk = 48, /* SAKOT */ - USE_G = 49, /* HIEROGLYPH */ - USE_J = 50, /* HIEROGLYPH_JOINER */ - USE_SB = 51, /* HIEROGLYPH_SEGMENT_BEGIN */ - USE_SE = 52, /* HIEROGLYPH_SEGMENT_END */ - - USE_FAbv = 24, /* CONS_FINAL_ABOVE */ - USE_FBlw = 25, /* CONS_FINAL_BELOW */ - USE_FPst = 26, /* CONS_FINAL_POST */ - USE_MAbv = 27, /* CONS_MED_ABOVE */ - USE_MBlw = 28, /* CONS_MED_BELOW */ - USE_MPst = 29, /* CONS_MED_POST */ - USE_MPre = 30, /* CONS_MED_PRE */ - USE_CMAbv = 31, /* CONS_MOD_ABOVE */ - USE_CMBlw = 32, /* CONS_MOD_BELOW */ - USE_VAbv = 33, /* VOWEL_ABOVE / VOWEL_ABOVE_BELOW / VOWEL_ABOVE_BELOW_POST / VOWEL_ABOVE_POST */ - USE_VBlw = 34, /* VOWEL_BELOW / VOWEL_BELOW_POST */ - USE_VPst = 35, /* VOWEL_POST UIPC = Right */ - USE_VPre = 22, /* VOWEL_PRE / VOWEL_PRE_ABOVE / VOWEL_PRE_ABOVE_POST / VOWEL_PRE_POST */ - USE_VMAbv = 37, /* VOWEL_MOD_ABOVE */ - USE_VMBlw = 38, /* VOWEL_MOD_BELOW */ - USE_VMPst = 39, /* VOWEL_MOD_POST */ - USE_VMPre = 23, /* VOWEL_MOD_PRE */ - USE_SMAbv = 41, /* SYM_MOD_ABOVE */ - USE_SMBlw = 42, /* SYM_MOD_BELOW */ - USE_FMAbv = 45, /* CONS_FINAL_MOD UIPC = Top */ - USE_FMBlw = 46, /* CONS_FINAL_MOD UIPC = Bottom */ - USE_FMPst = 47, /* CONS_FINAL_MOD UIPC = Not_Applicable */ -}; +#define USE(Cat) use_syllable_machine_ex_##Cat HB_INTERNAL USE_TABLE_ELEMENT_TYPE hb_use_get_category (hb_codepoint_t u);