2 * Copyright © 2011,2012,2013 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
29 #ifndef HB_NO_OT_SHAPE
31 #include "hb-ot-shape-complex-myanmar.hh"
39 myanmar_basic_features[] =
43 * These features are applied in order, one at a time, after reordering.
45 HB_TAG('r','p','h','f'),
46 HB_TAG('p','r','e','f'),
47 HB_TAG('b','l','w','f'),
48 HB_TAG('p','s','t','f'),
51 myanmar_other_features[] =
55 * These features are applied all at once, after clearing syllables.
57 HB_TAG('p','r','e','s'),
58 HB_TAG('a','b','v','s'),
59 HB_TAG('b','l','w','s'),
60 HB_TAG('p','s','t','s'),
64 setup_syllables_myanmar (const hb_ot_shape_plan_t *plan,
68 reorder_myanmar (const hb_ot_shape_plan_t *plan,
73 collect_features_myanmar (hb_ot_shape_planner_t *plan)
75 hb_ot_map_builder_t *map = &plan->map;
77 /* Do this before any lookups have been applied. */
78 map->add_gsub_pause (setup_syllables_myanmar);
80 map->enable_feature (HB_TAG('l','o','c','l'));
81 /* The Indic specs do not require ccmp, but we apply it here since if
82 * there is a use of it, it's typically at the beginning. */
83 map->enable_feature (HB_TAG('c','c','m','p'));
86 map->add_gsub_pause (reorder_myanmar);
88 for (unsigned int i = 0; i < ARRAY_LENGTH (myanmar_basic_features); i++)
90 map->enable_feature (myanmar_basic_features[i], F_MANUAL_ZWJ);
91 map->add_gsub_pause (nullptr);
94 map->add_gsub_pause (_hb_clear_syllables);
96 for (unsigned int i = 0; i < ARRAY_LENGTH (myanmar_other_features); i++)
97 map->enable_feature (myanmar_other_features[i], F_MANUAL_ZWJ);
101 override_features_myanmar (hb_ot_shape_planner_t *plan)
103 plan->map.disable_feature (HB_TAG('l','i','g','a'));
107 enum myanmar_syllable_type_t {
108 myanmar_consonant_syllable,
109 myanmar_punctuation_cluster,
110 myanmar_broken_cluster,
111 myanmar_non_myanmar_cluster,
114 #include "hb-ot-shape-complex-myanmar-machine.hh"
118 setup_masks_myanmar (const hb_ot_shape_plan_t *plan HB_UNUSED,
120 hb_font_t *font HB_UNUSED)
122 HB_BUFFER_ALLOCATE_VAR (buffer, myanmar_category);
123 HB_BUFFER_ALLOCATE_VAR (buffer, myanmar_position);
125 /* We cannot setup masks here. We save information about characters
126 * and setup masks later on in a pause-callback. */
128 unsigned int count = buffer->len;
129 hb_glyph_info_t *info = buffer->info;
130 for (unsigned int i = 0; i < count; i++)
131 set_myanmar_properties (info[i]);
135 setup_syllables_myanmar (const hb_ot_shape_plan_t *plan HB_UNUSED,
136 hb_font_t *font HB_UNUSED,
139 find_syllables_myanmar (buffer);
140 foreach_syllable (buffer, start, end)
141 buffer->unsafe_to_break (start, end);
145 compare_myanmar_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb)
147 int a = pa->myanmar_position();
148 int b = pb->myanmar_position();
150 return a < b ? -1 : a == b ? 0 : +1;
155 * https://docs.microsoft.com/en-us/typography/script-development/myanmar */
158 initial_reordering_consonant_syllable (hb_buffer_t *buffer,
159 unsigned int start, unsigned int end)
161 hb_glyph_info_t *info = buffer->info;
163 unsigned int base = end;
164 bool has_reph = false;
167 unsigned int limit = start;
168 if (start + 3 <= end &&
169 info[start ].myanmar_category() == OT_Ra &&
170 info[start+1].myanmar_category() == OT_As &&
171 info[start+2].myanmar_category() == OT_H)
182 for (unsigned int i = limit; i < end; i++)
183 if (is_consonant (info[i]))
193 unsigned int i = start;
194 for (; i < start + (has_reph ? 3 : 0); i++)
195 info[i].myanmar_position() = POS_AFTER_MAIN;
196 for (; i < base; i++)
197 info[i].myanmar_position() = POS_PRE_C;
200 info[i].myanmar_position() = POS_BASE_C;
203 indic_position_t pos = POS_AFTER_MAIN;
204 /* The following loop may be ugly, but it implements all of
205 * Myanmar reordering! */
208 if (info[i].myanmar_category() == OT_MR) /* Pre-base reordering */
210 info[i].myanmar_position() = POS_PRE_C;
213 if (info[i].myanmar_position() < POS_BASE_C) /* Left matra */
217 if (info[i].myanmar_category() == OT_VS)
219 info[i].myanmar_position() = info[i - 1].myanmar_position();
223 if (pos == POS_AFTER_MAIN && info[i].myanmar_category() == OT_VBlw)
226 info[i].myanmar_position() = pos;
230 if (pos == POS_BELOW_C && info[i].myanmar_category() == OT_A)
232 info[i].myanmar_position() = POS_BEFORE_SUB;
235 if (pos == POS_BELOW_C && info[i].myanmar_category() == OT_VBlw)
237 info[i].myanmar_position() = pos;
240 if (pos == POS_BELOW_C && info[i].myanmar_category() != OT_A)
243 info[i].myanmar_position() = pos;
246 info[i].myanmar_position() = pos;
250 /* Sit tight, rock 'n roll! */
251 buffer->sort (start, end, compare_myanmar_order);
255 reorder_syllable_myanmar (const hb_ot_shape_plan_t *plan HB_UNUSED,
256 hb_face_t *face HB_UNUSED,
258 unsigned int start, unsigned int end)
260 myanmar_syllable_type_t syllable_type = (myanmar_syllable_type_t) (buffer->info[start].syllable() & 0x0F);
261 switch (syllable_type) {
263 case myanmar_broken_cluster: /* We already inserted dotted-circles, so just call the consonant_syllable. */
264 case myanmar_consonant_syllable:
265 initial_reordering_consonant_syllable (buffer, start, end);
268 case myanmar_punctuation_cluster:
269 case myanmar_non_myanmar_cluster:
275 insert_dotted_circles_myanmar (const hb_ot_shape_plan_t *plan HB_UNUSED,
279 if (unlikely (buffer->flags & HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE))
282 /* Note: This loop is extra overhead, but should not be measurable.
283 * TODO Use a buffer scratch flag to remove the loop. */
284 bool has_broken_syllables = false;
285 unsigned int count = buffer->len;
286 hb_glyph_info_t *info = buffer->info;
287 for (unsigned int i = 0; i < count; i++)
288 if ((info[i].syllable() & 0x0F) == myanmar_broken_cluster)
290 has_broken_syllables = true;
293 if (likely (!has_broken_syllables))
297 hb_codepoint_t dottedcircle_glyph;
298 if (!font->get_nominal_glyph (0x25CCu, &dottedcircle_glyph))
301 hb_glyph_info_t dottedcircle = {0};
302 dottedcircle.codepoint = 0x25CCu;
303 set_myanmar_properties (dottedcircle);
304 dottedcircle.codepoint = dottedcircle_glyph;
306 buffer->clear_output ();
309 unsigned int last_syllable = 0;
310 while (buffer->idx < buffer->len && buffer->successful)
312 unsigned int syllable = buffer->cur().syllable();
313 myanmar_syllable_type_t syllable_type = (myanmar_syllable_type_t) (syllable & 0x0F);
314 if (unlikely (last_syllable != syllable && syllable_type == myanmar_broken_cluster))
316 last_syllable = syllable;
318 hb_glyph_info_t ginfo = dottedcircle;
319 ginfo.cluster = buffer->cur().cluster;
320 ginfo.mask = buffer->cur().mask;
321 ginfo.syllable() = buffer->cur().syllable();
323 buffer->output_info (ginfo);
326 buffer->next_glyph ();
328 buffer->swap_buffers ();
332 reorder_myanmar (const hb_ot_shape_plan_t *plan,
336 insert_dotted_circles_myanmar (plan, font, buffer);
338 foreach_syllable (buffer, start, end)
339 reorder_syllable_myanmar (plan, font->face, buffer, start, end);
341 HB_BUFFER_DEALLOCATE_VAR (buffer, myanmar_category);
342 HB_BUFFER_DEALLOCATE_VAR (buffer, myanmar_position);
346 const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar =
348 collect_features_myanmar,
349 override_features_myanmar,
350 nullptr, /* data_create */
351 nullptr, /* data_destroy */
352 nullptr, /* preprocess_text */
353 nullptr, /* postprocess_glyphs */
354 HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
355 nullptr, /* decompose */
356 nullptr, /* compose */
358 HB_TAG_NONE, /* gpos_tag */
359 nullptr, /* reorder_marks */
360 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY,
361 false, /* fallback_position */
365 /* Ugly Zawgyi encoding.
366 * Disable all auto processing.
367 * https://github.com/harfbuzz/harfbuzz/issues/1162 */
368 const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar_zawgyi =
370 nullptr, /* collect_features */
371 nullptr, /* override_features */
372 nullptr, /* data_create */
373 nullptr, /* data_destroy */
374 nullptr, /* preprocess_text */
375 nullptr, /* postprocess_glyphs */
376 HB_OT_SHAPE_NORMALIZATION_MODE_NONE,
377 nullptr, /* decompose */
378 nullptr, /* compose */
379 nullptr, /* setup_masks */
380 HB_TAG_NONE, /* gpos_tag */
381 nullptr, /* reorder_marks */
382 HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE,
383 false, /* fallback_position */