TODO | 10 src/hb-buffer-private.hh | 5 src/hb-buffer.cc | 24 ++ src/hb-ot-shape-complex-indic-machine.rl | 14 - src/hb-ot-shape-complex-misc.cc | 104 +++++++++- src/hb-ot-shape-complex-private.hh | 8 test/shaping/texts/in-tree/MANIFEST | 1 test/shaping/texts/in-tree/shaper-default/MANIFEST | 1 test/shaping/texts/in-tree/shaper-default/script-hangul/MANIFEST | 1 test/shaping/texts/in-tree/shaper-default/script-hangul/misc/MANIFEST | 1 test/shaping/texts/in-tree/shaper-default/script-hangul/misc/misc.txt | 2 test/shaping/texts/in-tree/shaper-hangul/MANIFEST | 1 test/shaping/texts/in-tree/shaper-hangul/script-hangul/MANIFEST | 1 test/shaping/texts/in-tree/shaper-hangul/script-hangul/misc/MANIFEST | 1 test/shaping/texts/in-tree/shaper-hangul/script-hangul/misc/misc.txt | 2 test/shaping/texts/in-tree/shaper-thai/misc/misc.txt | 5 16 files changed, 156 insertions(+), 25 deletions(-)
New commits: commit 3b26f96ebe859570d14c6902afc23462bca40712 Author: Behdad Esfahbod <[email protected]> Date: Tue Apr 10 10:52:07 2012 -0400 Add Thai shaper that does SARA AM decomposition / reordering That's not in the OpenType spec, but it's what MS and Adobe do. diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 6b562aa..4a37e66 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -223,6 +223,7 @@ hb_buffer_t::swap_buffers (void) if (unlikely (in_error)) return; assert (have_output); + have_output = FALSE; if (out_info != info) { diff --git a/src/hb-ot-shape-complex-misc.cc b/src/hb-ot-shape-complex-misc.cc index 20e365b..d893eb3 100644 --- a/src/hb-ot-shape-complex-misc.cc +++ b/src/hb-ot-shape-complex-misc.cc @@ -27,7 +27,7 @@ #include "hb-ot-shape-complex-private.hh" -/* TODO Add kana, hangul, and other small shapers here */ +/* TODO Add kana, and other small shapers here */ /* When adding trivial shapers, eg. kana, hangul, etc, we can either * add a full shaper enum value for them, or switch on the script in @@ -54,6 +54,8 @@ _hb_ot_shape_complex_setup_masks_default (hb_ot_map_t *map, hb_buffer_t *buffer) +/* Hangul shaper */ + void _hb_ot_shape_complex_collect_features_hangul (hb_ot_map_builder_t *map, const hb_segment_properties_t *props) { @@ -69,3 +71,103 @@ void _hb_ot_shape_complex_setup_masks_hangul (hb_ot_map_t *map, hb_buffer_t *buffer) { } + + + +/* Thai / Lao shaper */ + +void +_hb_ot_shape_complex_collect_features_thai (hb_ot_map_builder_t *map, const hb_segment_properties_t *props) +{ +} + +hb_ot_shape_normalization_mode_t +_hb_ot_shape_complex_normalization_preference_thai (void) +{ + return HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL; +} + +void +_hb_ot_shape_complex_setup_masks_thai (hb_ot_map_t *map, hb_buffer_t *buffer) +{ + /* The following is NOT specified in the MS OT Thai spec, however, it seems + * to be what Uniscribe and other engines implement. According to Eric Muller: + * + * When you have a sara am, decompose it in nikhahit + sara a, *and* mode the + * nihka hit backwards over any *tone* mark (0E48-0E4B). + * + * <0E14, 0E4B, 0E33> -> <0E14, 0E4D, 0E4B, 0E32> + * + * This reordering is legit only when the nikhahit comes from a sara am, not + * when it's there to start with. The string <0E14, 0E4B, 0E4D> is probably + * not what a uâªser wanted, but the rendering is nevertheless nikhahit above + * chattawa. + * + * Same for Lao. + */ + + /* + * Here are the characters of significance: + * + * Thai Lao + * SARA AM: U+0E33 U+0EB3 + * SARA AA: U+0E32 U+0EB2 + * Nikhahit: U+0E4D U+0ECD + * + * Tone marks: + * Thai: <0E48..0E4B> CCC=107 + * Lao: <0EC8..0ECB> CCC=122 + * + * Note how the Lao versions are the same as Thai + 0x80. + */ + + /* We only get one script at a time, so a script-agnostic implementation + * is adequate here. */ +#define IS_SARA_AM(x) (((x) & ~0x0080) == 0x0E33) +#define NIKHAHIT_FROM_SARA_AM(x) ((x) - 0xE33 + 0xE4D) +#define SARA_AA_FROM_SARA_AM(x) ((x) - 1) +#define IS_TONE_MARK(x) (((x) & ~0x0083) == 0x0E48) + + buffer->clear_output (); + unsigned int count = buffer->len; + for (buffer->idx = 0; buffer->idx < count;) + { + if (!IS_SARA_AM (buffer->info[buffer->idx].codepoint)) { + buffer->next_glyph (); + continue; + } + + /* Is SARA AM. Decompose and reorder. */ + uint16_t decomposed[2] = {NIKHAHIT_FROM_SARA_AM (buffer->info[buffer->idx].codepoint), + SARA_AA_FROM_SARA_AM (buffer->info[buffer->idx].codepoint)}; + buffer->replace_glyphs (1, 2, decomposed); + if (buffer->in_error) + return; + + /* Ok, let's see... */ + unsigned int end = buffer->out_len; + unsigned int start = end - 2; + while (start > 0 && IS_TONE_MARK (buffer->out_info[start - 1].codepoint)) + start--; + + /* Move Nikhahit (end-2) to the beginning */ + hb_glyph_info_t t = buffer->out_info[end - 2]; + memmove (buffer->out_info + start + 1, + buffer->out_info + start, + sizeof (buffer->out_info[0]) * (end - start - 2)); + buffer->out_info[start] = t; + + /* Make cluster */ + for (; start > 0 && buffer->out_info[start - 1].cluster == buffer->out_info[start].cluster; start--) + ; + for (; buffer->idx < count;) + if (buffer->info[buffer->idx].cluster == buffer->out_info[buffer->out_len - 1].cluster) + buffer->next_glyph (); + else + break; + end = buffer->out_len; + + buffer->merge_out_clusters (start, end); + } + buffer->swap_buffers (); +} diff --git a/src/hb-ot-shape-complex-private.hh b/src/hb-ot-shape-complex-private.hh index 7c2c7a9..75948c0 100644 --- a/src/hb-ot-shape-complex-private.hh +++ b/src/hb-ot-shape-complex-private.hh @@ -52,6 +52,7 @@ HB_COMPLEX_SHAPER_IMPLEMENT (arabic) \ HB_COMPLEX_SHAPER_IMPLEMENT (hangul) \ HB_COMPLEX_SHAPER_IMPLEMENT (indic) \ + HB_COMPLEX_SHAPER_IMPLEMENT (thai) \ /* ^--- Add new shapers here */ enum hb_ot_complex_shaper_t { @@ -91,6 +92,13 @@ hb_ot_shape_complex_categorize (const hb_segment_properties_t *props) return hb_ot_complex_shaper_hangul; + /* Unicode-1.1 additions */ + case HB_SCRIPT_THAI: + case HB_SCRIPT_LAO: + + return hb_ot_complex_shaper_thai; + + /* ^--- Add new shapers here */ commit 0b6d2ac6a1d04877ae4542fc2a3b920185547053 Author: Behdad Esfahbod <[email protected]> Date: Tue Apr 10 10:52:03 2012 -0400 Minor diff --git a/TODO b/TODO index 7a99cd2..1436337 100644 --- a/TODO +++ b/TODO @@ -58,13 +58,11 @@ API to add (maybe after 1.0): - Add hb-fribidi? -hb-view enhancements: -==================== +hb-view / hb-shape enhancements: +=============================== -- Add --format - Add --width, --height, --auto-size, --align, etc? -- Port to GOption, --help -- Add XML and JSON formats +- Add XML and JSON formats to hb-shape Tests to write: @@ -82,4 +80,4 @@ Optimizations: - Avoid allocating blob objects internally for for_data() faces? -- Add caching layer to hb-ft +- Add caching layer to hb-ft? commit e099dd6592b4ea887696330f4718efb572494d93 Author: Behdad Esfahbod <[email protected]> Date: Tue Apr 10 10:47:33 2012 -0400 Add Thai test case for SARA AM decomposition diff --git a/test/shaping/texts/in-tree/shaper-hangul/MANIFEST b/test/shaping/texts/in-tree/shaper-hangul/MANIFEST new file mode 100644 index 0000000..ea81716 --- /dev/null +++ b/test/shaping/texts/in-tree/shaper-hangul/MANIFEST @@ -0,0 +1 @@ +script-hangul diff --git a/test/shaping/texts/in-tree/shaper-thai/misc/misc.txt b/test/shaping/texts/in-tree/shaper-thai/misc/misc.txt new file mode 100644 index 0000000..fc2dba9 --- /dev/null +++ b/test/shaping/texts/in-tree/shaper-thai/misc/misc.txt @@ -0,0 +1,5 @@ +à¸à¹à¸³ +à¸à¹à¹à¸² +à¸à¹à¹à¸² +à¸à¸³ +ำ commit 4450dc9354b18cd68980b0891b24ea8efa4f38b6 Author: Behdad Esfahbod <[email protected]> Date: Sat Apr 7 22:07:23 2012 -0400 Move around diff --git a/test/shaping/texts/in-tree/MANIFEST b/test/shaping/texts/in-tree/MANIFEST index 2448c4b..0119909 100644 --- a/test/shaping/texts/in-tree/MANIFEST +++ b/test/shaping/texts/in-tree/MANIFEST @@ -1,3 +1,4 @@ shaper-arabic shaper-default +shaper-hangul shaper-indic diff --git a/test/shaping/texts/in-tree/shaper-default/MANIFEST b/test/shaping/texts/in-tree/shaper-default/MANIFEST index 623eae4..5139532 100644 --- a/test/shaping/texts/in-tree/shaper-default/MANIFEST +++ b/test/shaping/texts/in-tree/shaper-default/MANIFEST @@ -1,3 +1,2 @@ -script-hangul script-hebrew script-linear-b diff --git a/test/shaping/texts/in-tree/shaper-default/script-hangul/MANIFEST b/test/shaping/texts/in-tree/shaper-default/script-hangul/MANIFEST deleted file mode 100644 index b8752e7..0000000 --- a/test/shaping/texts/in-tree/shaper-default/script-hangul/MANIFEST +++ /dev/null @@ -1 +0,0 @@ -misc diff --git a/test/shaping/texts/in-tree/shaper-default/script-hangul/misc/MANIFEST b/test/shaping/texts/in-tree/shaper-default/script-hangul/misc/MANIFEST deleted file mode 100644 index 29cfb2f..0000000 --- a/test/shaping/texts/in-tree/shaper-default/script-hangul/misc/MANIFEST +++ /dev/null @@ -1 +0,0 @@ -misc.txt diff --git a/test/shaping/texts/in-tree/shaper-default/script-hangul/misc/misc.txt b/test/shaping/texts/in-tree/shaper-default/script-hangul/misc/misc.txt deleted file mode 100644 index 9c374b9..0000000 --- a/test/shaping/texts/in-tree/shaper-default/script-hangul/misc/misc.txt +++ /dev/null @@ -1,2 +0,0 @@ -í´ê° ê°-- (ì¤--) -áá ²áá ¡ áá ¡-- (áá ©--) diff --git a/test/shaping/texts/in-tree/shaper-hangul/script-hangul/MANIFEST b/test/shaping/texts/in-tree/shaper-hangul/script-hangul/MANIFEST new file mode 100644 index 0000000..b8752e7 --- /dev/null +++ b/test/shaping/texts/in-tree/shaper-hangul/script-hangul/MANIFEST @@ -0,0 +1 @@ +misc diff --git a/test/shaping/texts/in-tree/shaper-hangul/script-hangul/misc/MANIFEST b/test/shaping/texts/in-tree/shaper-hangul/script-hangul/misc/MANIFEST new file mode 100644 index 0000000..29cfb2f --- /dev/null +++ b/test/shaping/texts/in-tree/shaper-hangul/script-hangul/misc/MANIFEST @@ -0,0 +1 @@ +misc.txt diff --git a/test/shaping/texts/in-tree/shaper-hangul/script-hangul/misc/misc.txt b/test/shaping/texts/in-tree/shaper-hangul/script-hangul/misc/misc.txt new file mode 100644 index 0000000..9c374b9 --- /dev/null +++ b/test/shaping/texts/in-tree/shaper-hangul/script-hangul/misc/misc.txt @@ -0,0 +1,2 @@ +í´ê° ê°-- (ì¤--) +áá ²áá ¡ áá ¡-- (áá ©--) commit d4cc44716c1e098f8abbc0e495404598026ef242 Author: Behdad Esfahbod <[email protected]> Date: Sat Apr 7 21:52:28 2012 -0400 Move code around, in prep for Thai/Lao shaper diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 4292222..06d4912 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -131,6 +131,11 @@ struct _hb_buffer_t { unsigned int cluster_start, unsigned int cluster_end); + HB_INTERNAL void merge_clusters (unsigned int start, + unsigned int end); + HB_INTERNAL void merge_out_clusters (unsigned int start, + unsigned int end); + /* Internal methods */ HB_INTERNAL bool enlarge (unsigned int size); diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index e8bdfb1..6b562aa 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -431,6 +431,29 @@ hb_buffer_t::reverse_clusters (void) } void +hb_buffer_t::merge_clusters (unsigned int start, + unsigned int end) +{ + unsigned int cluster = this->info[start].cluster; + + for (unsigned int i = start + 1; i < end; i++) + cluster = MIN (cluster, this->info[i].cluster); + for (unsigned int i = start; i < end; i++) + this->info[i].cluster = cluster; +} +void +hb_buffer_t::merge_out_clusters (unsigned int start, + unsigned int end) +{ + unsigned int cluster = this->out_info[start].cluster; + + for (unsigned int i = start + 1; i < end; i++) + cluster = MIN (cluster, this->out_info[i].cluster); + for (unsigned int i = start; i < end; i++) + this->out_info[i].cluster = cluster; +} + +void hb_buffer_t::guess_properties (void) { /* If script is set to INVALID, guess from buffer contents */ diff --git a/src/hb-ot-shape-complex-indic-machine.rl b/src/hb-ot-shape-complex-indic-machine.rl index bcca6da..7af23c1 100644 --- a/src/hb-ot-shape-complex-indic-machine.rl +++ b/src/hb-ot-shape-complex-indic-machine.rl @@ -64,7 +64,7 @@ action found_vowel_syllable { found_vowel_syllable (map, buffer, mask_array, las action found_standalone_cluster { found_standalone_cluster (map, buffer, mask_array, last, p); } action found_non_indic { found_non_indic (map, buffer, mask_array, last, p); } -action next_syllable { set_cluster (buffer, last, p); last = p; } +action next_syllable { buffer->merge_clusters (last, p); last = p; } consonant_syllable = (c.N? (z.H|H.z?))* c.N? A? (H.z? | matra_group*)? syllable_tail %(found_consonant_syllable); vowel_syllable = (Ra H)? V N? (z.H.c | ZWJ.c)? matra_group* syllable_tail %(found_vowel_syllable); @@ -84,18 +84,6 @@ main := (syllable %(next_syllable))**; static void -set_cluster (hb_buffer_t *buffer, - unsigned int start, unsigned int end) -{ - unsigned int cluster = buffer->info[start].cluster; - - for (unsigned int i = start + 1; i < end; i++) - cluster = MIN (cluster, buffer->info[i].cluster); - for (unsigned int i = start; i < end; i++) - buffer->info[i].cluster = cluster; -} - -static void find_syllables (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array) { unsigned int p, pe, eof;
_______________________________________________ HarfBuzz mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/harfbuzz
