2015-07-20 14:30:51 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2015 Mozilla Foundation.
|
|
|
|
* Copyright © 2015 Google, Inc.
|
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Mozilla Author(s): Jonathan Kew
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH
|
|
|
|
#define HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb.hh"
|
2021-01-29 04:40:42 +01:00
|
|
|
|
|
|
|
#include "hb-ot-shape-complex-syllabic.hh"
|
2015-07-20 14:30:51 +02:00
|
|
|
|
2021-01-29 04:27:59 +01:00
|
|
|
/* buffer var allocations */
|
|
|
|
#define use_category() complex_var_u8_category()
|
|
|
|
|
2021-01-29 04:40:42 +01:00
|
|
|
#define USE(Cat) use_syllable_machine_ex_##Cat
|
|
|
|
|
2021-01-29 04:27:59 +01:00
|
|
|
enum use_syllable_type_t {
|
|
|
|
use_independent_cluster,
|
|
|
|
use_virama_terminated_cluster,
|
|
|
|
use_sakot_terminated_cluster,
|
|
|
|
use_standard_cluster,
|
|
|
|
use_number_joiner_terminated_cluster,
|
|
|
|
use_numeral_cluster,
|
|
|
|
use_symbol_cluster,
|
|
|
|
use_hieroglyph_cluster,
|
|
|
|
use_broken_cluster,
|
|
|
|
use_non_cluster,
|
|
|
|
};
|
|
|
|
|
2015-07-20 14:30:51 +02:00
|
|
|
%%{
|
|
|
|
machine use_syllable_machine;
|
|
|
|
alphtype unsigned char;
|
2021-01-29 03:47:53 +01:00
|
|
|
write exports;
|
2015-07-20 14:30:51 +02:00
|
|
|
write data;
|
|
|
|
}%%
|
|
|
|
|
|
|
|
%%{
|
|
|
|
|
2021-02-01 19:54:12 +01:00
|
|
|
# Categories used in the Universal Shaping Engine spec:
|
2021-01-29 04:36:51 +01:00
|
|
|
# https://docs.microsoft.com/en-us/typography/script-development/use
|
|
|
|
|
2021-01-29 03:47:53 +01:00
|
|
|
export O = 0; # OTHER
|
2021-01-16 03:26:04 +01:00
|
|
|
|
2021-01-29 03:47:53 +01:00
|
|
|
export B = 1; # BASE
|
|
|
|
export N = 4; # BASE_NUM
|
|
|
|
export GB = 5; # BASE_OTHER
|
|
|
|
export SUB = 11; # CONS_SUB
|
|
|
|
export H = 12; # HALANT
|
2021-01-16 03:26:04 +01:00
|
|
|
|
2021-01-29 03:47:53 +01:00
|
|
|
export HN = 13; # HALANT_NUM
|
|
|
|
export ZWNJ = 14; # Zero width non-joiner
|
|
|
|
export R = 18; # REPHA
|
|
|
|
export S = 19; # SYM
|
|
|
|
export CS = 43; # CONS_WITH_STACKER
|
|
|
|
export HVM = 44; # HALANT_OR_VOWEL_MODIFIER
|
|
|
|
export Sk = 48; # SAKOT
|
|
|
|
export G = 49; # HIEROGLYPH
|
|
|
|
export J = 50; # HIEROGLYPH_JOINER
|
|
|
|
export SB = 51; # HIEROGLYPH_SEGMENT_BEGIN
|
|
|
|
export SE = 52; # HIEROGLYPH_SEGMENT_END
|
2021-01-16 03:26:04 +01:00
|
|
|
|
2021-01-29 03:47:53 +01:00
|
|
|
export FAbv = 24; # CONS_FINAL_ABOVE
|
|
|
|
export FBlw = 25; # CONS_FINAL_BELOW
|
|
|
|
export FPst = 26; # CONS_FINAL_POST
|
|
|
|
export MAbv = 27; # CONS_MED_ABOVE
|
|
|
|
export MBlw = 28; # CONS_MED_BELOW
|
|
|
|
export MPst = 29; # CONS_MED_POST
|
|
|
|
export MPre = 30; # CONS_MED_PRE
|
|
|
|
export CMAbv = 31; # CONS_MOD_ABOVE
|
|
|
|
export CMBlw = 32; # CONS_MOD_BELOW
|
|
|
|
export VAbv = 33; # VOWEL_ABOVE / VOWEL_ABOVE_BELOW / VOWEL_ABOVE_BELOW_POST / VOWEL_ABOVE_POST
|
|
|
|
export VBlw = 34; # VOWEL_BELOW / VOWEL_BELOW_POST
|
|
|
|
export VPst = 35; # VOWEL_POST UIPC = Right
|
|
|
|
export VPre = 22; # VOWEL_PRE / VOWEL_PRE_ABOVE / VOWEL_PRE_ABOVE_POST / VOWEL_PRE_POST
|
|
|
|
export VMAbv = 37; # VOWEL_MOD_ABOVE
|
|
|
|
export VMBlw = 38; # VOWEL_MOD_BELOW
|
|
|
|
export VMPst = 39; # VOWEL_MOD_POST
|
|
|
|
export VMPre = 23; # VOWEL_MOD_PRE
|
|
|
|
export SMAbv = 41; # SYM_MOD_ABOVE
|
|
|
|
export SMBlw = 42; # SYM_MOD_BELOW
|
|
|
|
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
|
2018-10-03 12:29:56 +02:00
|
|
|
|
2021-01-29 04:36:51 +01:00
|
|
|
|
2019-05-26 17:05:54 +02:00
|
|
|
h = H | HVM | Sk;
|
2015-07-20 14:30:51 +02:00
|
|
|
|
2020-10-17 04:41:12 +02:00
|
|
|
consonant_modifiers = CMAbv* CMBlw* ((h B | SUB) CMAbv? CMBlw*)*;
|
2020-08-13 19:37:45 +02:00
|
|
|
medial_consonants = MPre? MAbv? MBlw? MPst?;
|
2015-07-20 14:30:51 +02:00
|
|
|
dependent_vowels = VPre* VAbv* VBlw* VPst*;
|
2018-10-03 12:29:56 +02:00
|
|
|
vowel_modifiers = HVM? VMPre* VMAbv* VMBlw* VMPst*;
|
2019-05-19 16:01:20 +02:00
|
|
|
final_consonants = FAbv* FBlw* FPst*;
|
|
|
|
final_modifiers = FMAbv* FMBlw* | FMPst?;
|
2015-07-20 14:30:51 +02:00
|
|
|
|
2019-05-03 20:16:50 +02:00
|
|
|
complex_syllable_start = (R | CS)? (B | GB);
|
2019-05-26 17:05:54 +02:00
|
|
|
complex_syllable_middle =
|
2018-10-02 17:49:06 +02:00
|
|
|
consonant_modifiers
|
|
|
|
medial_consonants
|
|
|
|
dependent_vowels
|
|
|
|
vowel_modifiers
|
2019-05-26 17:05:54 +02:00
|
|
|
(Sk B)*
|
|
|
|
;
|
|
|
|
complex_syllable_tail =
|
|
|
|
complex_syllable_middle
|
2018-10-02 17:49:06 +02:00
|
|
|
final_consonants
|
2019-05-19 16:01:20 +02:00
|
|
|
final_modifiers
|
2018-10-02 17:49:06 +02:00
|
|
|
;
|
2019-05-03 20:16:50 +02:00
|
|
|
number_joiner_terminated_cluster_tail = (HN N)* HN;
|
|
|
|
numeral_cluster_tail = (HN N)+;
|
2019-05-01 22:15:58 +02:00
|
|
|
symbol_cluster_tail = SMAbv+ SMBlw* | SMBlw+;
|
2018-10-02 17:49:06 +02:00
|
|
|
|
2015-07-20 14:30:51 +02:00
|
|
|
virama_terminated_cluster =
|
2019-05-26 17:05:54 +02:00
|
|
|
complex_syllable_start
|
2015-07-20 14:30:51 +02:00
|
|
|
consonant_modifiers
|
2020-10-17 04:41:12 +02:00
|
|
|
h
|
2015-07-20 14:30:51 +02:00
|
|
|
;
|
2019-05-26 17:05:54 +02:00
|
|
|
sakot_terminated_cluster =
|
|
|
|
complex_syllable_start
|
|
|
|
complex_syllable_middle
|
|
|
|
Sk
|
|
|
|
;
|
2016-05-06 18:41:49 +02:00
|
|
|
standard_cluster =
|
2019-05-26 17:05:54 +02:00
|
|
|
complex_syllable_start
|
2018-10-02 17:49:06 +02:00
|
|
|
complex_syllable_tail
|
2015-07-20 14:30:51 +02:00
|
|
|
;
|
2015-07-21 18:14:54 +02:00
|
|
|
broken_cluster =
|
|
|
|
R?
|
2019-05-01 22:15:58 +02:00
|
|
|
(complex_syllable_tail | number_joiner_terminated_cluster_tail | numeral_cluster_tail | symbol_cluster_tail)
|
2015-07-21 18:14:54 +02:00
|
|
|
;
|
|
|
|
|
2019-05-03 20:16:50 +02:00
|
|
|
number_joiner_terminated_cluster = N number_joiner_terminated_cluster_tail;
|
|
|
|
numeral_cluster = N numeral_cluster_tail?;
|
|
|
|
symbol_cluster = (S | GB) symbol_cluster_tail?;
|
2020-08-15 00:30:20 +02:00
|
|
|
hieroglyph_cluster = SB+ | SB* G SE* (J SE* (G SE*)?)*;
|
2020-10-17 17:57:08 +02:00
|
|
|
independent_cluster = O;
|
2016-05-06 18:28:25 +02:00
|
|
|
other = any;
|
2015-07-20 14:30:51 +02:00
|
|
|
|
|
|
|
main := |*
|
2021-01-29 19:40:59 +01:00
|
|
|
independent_cluster => { found_syllable (use_independent_cluster); };
|
|
|
|
virama_terminated_cluster => { found_syllable (use_virama_terminated_cluster); };
|
|
|
|
sakot_terminated_cluster => { found_syllable (use_sakot_terminated_cluster); };
|
|
|
|
standard_cluster => { found_syllable (use_standard_cluster); };
|
|
|
|
number_joiner_terminated_cluster => { found_syllable (use_number_joiner_terminated_cluster); };
|
|
|
|
numeral_cluster => { found_syllable (use_numeral_cluster); };
|
|
|
|
symbol_cluster => { found_syllable (use_symbol_cluster); };
|
|
|
|
hieroglyph_cluster => { found_syllable (use_hieroglyph_cluster); };
|
|
|
|
broken_cluster => { found_syllable (use_broken_cluster); };
|
|
|
|
other => { found_syllable (use_non_cluster); };
|
2015-07-20 14:30:51 +02:00
|
|
|
*|;
|
|
|
|
|
|
|
|
|
|
|
|
}%%
|
|
|
|
|
|
|
|
#define found_syllable(syllable_type) \
|
|
|
|
HB_STMT_START { \
|
2019-05-03 20:16:50 +02:00
|
|
|
if (0) fprintf (stderr, "syllable %d..%d %s\n", (*ts).second.first, (*te).second.first, #syllable_type); \
|
|
|
|
for (unsigned i = (*ts).second.first; i < (*te).second.first; ++i) \
|
2021-01-29 19:40:59 +01:00
|
|
|
info[i].syllable() = (syllable_serial << 4) | syllable_type; \
|
2015-07-20 14:30:51 +02:00
|
|
|
syllable_serial++; \
|
|
|
|
if (unlikely (syllable_serial == 16)) syllable_serial = 1; \
|
|
|
|
} HB_STMT_END
|
|
|
|
|
2021-01-29 04:40:42 +01:00
|
|
|
|
|
|
|
template <typename Iter>
|
|
|
|
struct machine_index_t :
|
|
|
|
hb_iter_with_fallback_t<machine_index_t<Iter>,
|
|
|
|
typename Iter::item_t>
|
|
|
|
{
|
|
|
|
machine_index_t (const Iter& it) : it (it) {}
|
|
|
|
machine_index_t (const machine_index_t& o) : it (o.it) {}
|
|
|
|
|
|
|
|
static constexpr bool is_random_access_iterator = Iter::is_random_access_iterator;
|
|
|
|
static constexpr bool is_sorted_iterator = Iter::is_sorted_iterator;
|
|
|
|
|
|
|
|
typename Iter::item_t __item__ () const { return *it; }
|
|
|
|
typename Iter::item_t __item_at__ (unsigned i) const { return it[i]; }
|
|
|
|
unsigned __len__ () const { return it.len (); }
|
|
|
|
void __next__ () { ++it; }
|
|
|
|
void __forward__ (unsigned n) { it += n; }
|
|
|
|
void __prev__ () { --it; }
|
|
|
|
void __rewind__ (unsigned n) { it -= n; }
|
|
|
|
void operator = (unsigned n)
|
|
|
|
{ unsigned index = (*it).first; if (index < n) it += n - index; else if (index > n) it -= index - n; }
|
|
|
|
void operator = (const machine_index_t& o) { *this = (*o.it).first; }
|
|
|
|
bool operator == (const machine_index_t& o) const { return (*it).first == (*o.it).first; }
|
|
|
|
bool operator != (const machine_index_t& o) const { return !(*this == o); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Iter it;
|
|
|
|
};
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
template <typename Iter,
|
|
|
|
hb_requires (hb_is_iterable (Iter))>
|
|
|
|
machine_index_t<hb_iter_type<Iter>>
|
|
|
|
operator () (Iter&& it) const
|
|
|
|
{ return machine_index_t<hb_iter_type<Iter>> (hb_iter (it)); }
|
|
|
|
}
|
|
|
|
HB_FUNCOBJ (machine_index);
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-03 20:16:50 +02:00
|
|
|
static bool
|
|
|
|
not_standard_default_ignorable (const hb_glyph_info_t &i)
|
2021-01-29 04:36:51 +01:00
|
|
|
{ return !(i.use_category() == USE(O) && _hb_glyph_info_is_default_ignorable (&i)); }
|
2019-05-03 20:16:50 +02:00
|
|
|
|
2021-01-29 04:36:51 +01:00
|
|
|
static inline void
|
2019-07-02 23:42:45 +02:00
|
|
|
find_syllables_use (hb_buffer_t *buffer)
|
2015-07-20 14:30:51 +02:00
|
|
|
{
|
|
|
|
hb_glyph_info_t *info = buffer->info;
|
2019-05-03 20:16:50 +02:00
|
|
|
auto p =
|
|
|
|
+ hb_iter (info, buffer->len)
|
|
|
|
| hb_enumerate
|
2020-09-29 03:12:46 +02:00
|
|
|
| hb_filter ([] (const hb_glyph_info_t &i) { return not_standard_default_ignorable (i); },
|
|
|
|
hb_second)
|
2019-05-03 20:16:50 +02:00
|
|
|
| hb_filter ([&] (const hb_pair_t<unsigned, const hb_glyph_info_t &> p)
|
|
|
|
{
|
2021-01-29 04:36:51 +01:00
|
|
|
if (p.second.use_category() == USE(ZWNJ))
|
2019-05-03 20:16:50 +02:00
|
|
|
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]);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
| hb_enumerate
|
|
|
|
| machine_index
|
|
|
|
;
|
|
|
|
auto pe = p + p.len ();
|
|
|
|
auto eof = +pe;
|
|
|
|
auto ts = +p;
|
|
|
|
auto te = +p;
|
2020-11-21 15:06:27 +01:00
|
|
|
unsigned int act HB_UNUSED;
|
2019-05-03 20:16:50 +02:00
|
|
|
int cs;
|
2015-07-20 14:30:51 +02:00
|
|
|
%%{
|
|
|
|
write init;
|
2019-05-03 20:16:50 +02:00
|
|
|
getkey (*p).second.second.use_category();
|
2015-07-20 14:30:51 +02:00
|
|
|
}%%
|
|
|
|
|
|
|
|
unsigned int syllable_serial = 1;
|
|
|
|
%%{
|
|
|
|
write exec;
|
|
|
|
}%%
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef found_syllable
|
|
|
|
|
|
|
|
#endif /* HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH */
|