blob: 88d16267b39dc54c9aa5bd56fd1d6ecacf6e5235 [file] [log] [blame]
Behdad Esfahboddcf4d952018-01-05 14:54:31 +00001/*
2 * Copyright © 2011,2012 Google, Inc.
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
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.
11 *
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
16 * DAMAGE.
17 *
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.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070027#include "hb-ot-shape-complex-khmer.hh"
28#include "hb-ot-layout.hh"
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000029
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000030
31/*
Behdad Esfahbod0d3a2742018-01-05 17:01:37 +000032 * Khmer shaper.
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000033 */
34
Behdad Esfahbod1676f602018-09-24 17:55:03 -040035static const hb_ot_map_feature_t
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000036khmer_features[] =
37{
38 /*
39 * Basic features.
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -070040 * These features are applied in order, one at a time, after reordering.
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000041 */
Behdad Esfahbodb1e07e12018-09-30 05:43:22 -040042 {HB_TAG('p','r','e','f'), F_MANUAL_JOINERS},
43 {HB_TAG('b','l','w','f'), F_MANUAL_JOINERS},
44 {HB_TAG('a','b','v','f'), F_MANUAL_JOINERS},
45 {HB_TAG('p','s','t','f'), F_MANUAL_JOINERS},
46 {HB_TAG('c','f','a','r'), F_MANUAL_JOINERS},
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000047 /*
48 * Other features.
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -070049 * These features are applied all at once.
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000050 */
Behdad Esfahbodb1e07e12018-09-30 05:43:22 -040051 {HB_TAG('p','r','e','s'), F_GLOBAL_MANUAL_JOINERS},
52 {HB_TAG('a','b','v','s'), F_GLOBAL_MANUAL_JOINERS},
53 {HB_TAG('b','l','w','s'), F_GLOBAL_MANUAL_JOINERS},
54 {HB_TAG('p','s','t','s'), F_GLOBAL_MANUAL_JOINERS},
Behdad Esfahbod3583fb02018-09-23 22:33:38 -040055 /*
56 * Positioning features.
57 * We don't care about the types.
58 */
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000059 {HB_TAG('d','i','s','t'), F_GLOBAL},
60 {HB_TAG('a','b','v','m'), F_GLOBAL},
61 {HB_TAG('b','l','w','m'), F_GLOBAL},
62};
63
64/*
65 * Must be in the same order as the khmer_features array.
66 */
67enum {
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000068 PREF,
69 BLWF,
70 ABVF,
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000071 PSTF,
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000072 CFAR,
73
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000074 _PRES,
75 _ABVS,
76 _BLWS,
77 _PSTS,
Behdad Esfahbod3583fb02018-09-23 22:33:38 -040078
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000079 _DIST,
80 _ABVM,
81 _BLWM,
82
Behdad Esfahbodbfad6ab2018-01-05 16:13:09 +000083 KHMER_NUM_FEATURES,
Behdad Esfahbod3583fb02018-09-23 22:33:38 -040084 KHMER_BASIC_FEATURES = _PRES, /* Don't forget to update this! */
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000085};
86
87static void
88setup_syllables (const hb_ot_shape_plan_t *plan,
89 hb_font_t *font,
90 hb_buffer_t *buffer);
91static void
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -070092reorder (const hb_ot_shape_plan_t *plan,
93 hb_font_t *font,
94 hb_buffer_t *buffer);
Behdad Esfahboddcf4d952018-01-05 14:54:31 +000095static void
96clear_syllables (const hb_ot_shape_plan_t *plan,
97 hb_font_t *font,
98 hb_buffer_t *buffer);
99
100static void
101collect_features_khmer (hb_ot_shape_planner_t *plan)
102{
103 hb_ot_map_builder_t *map = &plan->map;
104
105 /* Do this before any lookups have been applied. */
106 map->add_gsub_pause (setup_syllables);
Behdad Esfahbod7c658ea2018-07-31 12:49:02 -0700107 map->add_gsub_pause (reorder);
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000108
Behdad Esfahbod5772edc2018-07-31 14:10:31 -0700109 /* Testing suggests that Uniscribe does NOT pause between basic
Behdad Esfahbod8eef1962018-07-31 13:35:10 -0700110 * features. Test with KhmerUI.ttf and the following three
111 * sequences:
Behdad Esfahbod7c658ea2018-07-31 12:49:02 -0700112 *
113 * U+1789,U+17BC
114 * U+1789,U+17D2,U+1789
115 * U+1789,U+17D2,U+1789,U+17BC
116 *
117 * https://github.com/harfbuzz/harfbuzz/issues/974
118 */
Behdad Esfahbodf048ead2018-09-24 18:01:53 -0400119 map->enable_feature (HB_TAG('l','o','c','l'));
120 map->enable_feature (HB_TAG('c','c','m','p'));
Behdad Esfahbod8eef1962018-07-31 13:35:10 -0700121
122 unsigned int i = 0;
Behdad Esfahbod3583fb02018-09-23 22:33:38 -0400123 for (; i < KHMER_BASIC_FEATURES; i++)
Behdad Esfahbod1676f602018-09-24 17:55:03 -0400124 map->add_feature (khmer_features[i]);
Behdad Esfahbod8eef1962018-07-31 13:35:10 -0700125
Behdad Esfahbod6ddd6692018-07-31 13:38:07 -0700126 map->add_gsub_pause (clear_syllables);
Behdad Esfahbod7c658ea2018-07-31 12:49:02 -0700127
Behdad Esfahbod3583fb02018-09-23 22:33:38 -0400128 for (; i < KHMER_NUM_FEATURES; i++)
Behdad Esfahbod1676f602018-09-24 17:55:03 -0400129 map->add_feature (khmer_features[i]);
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000130
Behdad Esfahbodf048ead2018-09-24 18:01:53 -0400131 map->enable_feature (HB_TAG('c','a','l','t'));
132 map->enable_feature (HB_TAG('c','l','i','g'));
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000133
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000134}
135
136static void
137override_features_khmer (hb_ot_shape_planner_t *plan)
138{
139 /* Uniscribe does not apply 'kern' in Khmer. */
140 if (hb_options ().uniscribe_bug_compatible)
141 {
Behdad Esfahbod1676f602018-09-24 17:55:03 -0400142 plan->map.disable_feature (HB_TAG('k','e','r','n'));
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000143 }
144
Behdad Esfahbod1676f602018-09-24 17:55:03 -0400145 plan->map.disable_feature (HB_TAG('l','i','g','a'));
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000146}
147
148
149struct would_substitute_feature_t
150{
151 inline void init (const hb_ot_map_t *map, hb_tag_t feature_tag, bool zero_context_)
152 {
153 zero_context = zero_context_;
154 map->get_stage_lookups (0/*GSUB*/,
155 map->get_feature_stage (0/*GSUB*/, feature_tag),
156 &lookups, &count);
157 }
158
159 inline bool would_substitute (const hb_codepoint_t *glyphs,
160 unsigned int glyphs_count,
161 hb_face_t *face) const
162 {
163 for (unsigned int i = 0; i < count; i++)
164 if (hb_ot_layout_lookup_would_substitute_fast (face, lookups[i].index, glyphs, glyphs_count, zero_context))
165 return true;
166 return false;
167 }
168
169 private:
170 const hb_ot_map_t::lookup_map_t *lookups;
171 unsigned int count;
172 bool zero_context;
173};
174
175struct khmer_shape_plan_t
176{
177 ASSERT_POD ();
178
179 inline bool get_virama_glyph (hb_font_t *font, hb_codepoint_t *pglyph) const
180 {
181 hb_codepoint_t glyph = virama_glyph;
182 if (unlikely (virama_glyph == (hb_codepoint_t) -1))
183 {
Behdad Esfahbod9b135d92018-01-05 15:43:11 +0000184 if (!font->get_nominal_glyph (0x17D2u, &glyph))
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000185 glyph = 0;
186 /* Technically speaking, the spec says we should apply 'locl' to virama too.
187 * Maybe one day... */
188
189 /* Our get_nominal_glyph() function needs a font, so we can't get the virama glyph
190 * during shape planning... Instead, overwrite it here. It's safe. Don't worry! */
191 virama_glyph = glyph;
192 }
193
194 *pglyph = glyph;
195 return glyph != 0;
196 }
197
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000198 mutable hb_codepoint_t virama_glyph;
199
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000200 would_substitute_feature_t pref;
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000201
Behdad Esfahbodbfad6ab2018-01-05 16:13:09 +0000202 hb_mask_t mask_array[KHMER_NUM_FEATURES];
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000203};
204
205static void *
206data_create_khmer (const hb_ot_shape_plan_t *plan)
207{
208 khmer_shape_plan_t *khmer_plan = (khmer_shape_plan_t *) calloc (1, sizeof (khmer_shape_plan_t));
209 if (unlikely (!khmer_plan))
210 return nullptr;
211
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000212 khmer_plan->virama_glyph = (hb_codepoint_t) -1;
213
Behdad Esfahbod7eb3ac22018-01-05 15:41:31 +0000214 khmer_plan->pref.init (&plan->map, HB_TAG('p','r','e','f'), true);
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000215
216 for (unsigned int i = 0; i < ARRAY_LENGTH (khmer_plan->mask_array); i++)
217 khmer_plan->mask_array[i] = (khmer_features[i].flags & F_GLOBAL) ?
218 0 : plan->map.get_1_mask (khmer_features[i].tag);
219
220 return khmer_plan;
221}
222
223static void
224data_destroy_khmer (void *data)
225{
226 free (data);
227}
228
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000229
230enum syllable_type_t {
231 consonant_syllable,
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000232 broken_cluster,
233 non_khmer_cluster,
234};
235
236#include "hb-ot-shape-complex-khmer-machine.hh"
237
238static void
239setup_masks_khmer (const hb_ot_shape_plan_t *plan HB_UNUSED,
240 hb_buffer_t *buffer,
241 hb_font_t *font HB_UNUSED)
242{
243 HB_BUFFER_ALLOCATE_VAR (buffer, khmer_category);
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000244
245 /* We cannot setup masks here. We save information about characters
246 * and setup masks later on in a pause-callback. */
247
248 unsigned int count = buffer->len;
249 hb_glyph_info_t *info = buffer->info;
250 for (unsigned int i = 0; i < count; i++)
251 set_khmer_properties (info[i]);
252}
253
254static void
255setup_syllables (const hb_ot_shape_plan_t *plan HB_UNUSED,
256 hb_font_t *font HB_UNUSED,
257 hb_buffer_t *buffer)
258{
259 find_syllables (buffer);
260 foreach_syllable (buffer, start, end)
261 buffer->unsafe_to_break (start, end);
262}
263
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000264
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000265/* Rules from:
Ebrahim Byagowif24b0b92018-04-12 13:40:45 +0430266 * https://docs.microsoft.com/en-us/typography/script-development/devanagari */
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000267
268static void
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700269reorder_consonant_syllable (const hb_ot_shape_plan_t *plan,
270 hb_face_t *face,
271 hb_buffer_t *buffer,
272 unsigned int start, unsigned int end)
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000273{
274 const khmer_shape_plan_t *khmer_plan = (const khmer_shape_plan_t *) plan->data;
275 hb_glyph_info_t *info = buffer->info;
276
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700277 /* Setup masks. */
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000278 {
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000279 /* Post-base */
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700280 hb_mask_t mask = khmer_plan->mask_array[BLWF] | khmer_plan->mask_array[ABVF] | khmer_plan->mask_array[PSTF];
281 for (unsigned int i = start + 1; i < end; i++)
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000282 info[i].mask |= mask;
283 }
284
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700285 unsigned int num_coengs = 0;
286 for (unsigned int i = start + 1; i < end; i++)
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000287 {
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700288 /* """
289 * When a COENG + (Cons | IndV) combination are found (and subscript count
290 * is less than two) the character combination is handled according to the
291 * subscript type of the character following the COENG.
292 *
293 * ...
294 *
295 * Subscript Type 2 - The COENG + RO characters are reordered to immediately
296 * before the base glyph. Then the COENG + RO characters are assigned to have
297 * the 'pref' OpenType feature applied to them.
298 * """
299 */
300 if (info[i].khmer_category() == OT_Coeng && num_coengs <= 2 && i + 1 < end)
301 {
302 num_coengs++;
303
304 if (info[i + 1].khmer_category() == OT_Ra)
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000305 {
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700306 for (unsigned int j = 0; j < 2; j++)
307 info[i + j].mask |= khmer_plan->mask_array[PREF];
308
309 /* Move the Coeng,Ro sequence to the start. */
310 buffer->merge_clusters (start, i + 2);
311 hb_glyph_info_t t0 = info[i];
312 hb_glyph_info_t t1 = info[i + 1];
313 memmove (&info[start + 2], &info[start], (i - start) * sizeof (info[0]));
314 info[start] = t0;
315 info[start + 1] = t1;
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000316
317 /* Mark the subsequent stuff with 'cfar'. Used in Khmer.
318 * Read the feature spec.
319 * This allows distinguishing the following cases with MS Khmer fonts:
320 * U+1784,U+17D2,U+179A,U+17D2,U+1782
321 * U+1784,U+17D2,U+1782,U+17D2,U+179A
322 */
323 if (khmer_plan->mask_array[CFAR])
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700324 for (unsigned int j = i + 2; j < end; j++)
325 info[j].mask |= khmer_plan->mask_array[CFAR];
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000326
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700327 num_coengs = 2; /* Done. */
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000328 }
329 }
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700330
331 /* Reorder left matra piece. */
Behdad Esfahbod51436542018-10-01 19:09:58 +0200332 else if (info[i].khmer_category() == OT_VPre)
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700333 {
334 /* Move to the start. */
335 buffer->merge_clusters (start, i + 1);
336 hb_glyph_info_t t = info[i];
337 memmove (&info[start + 1], &info[start], (i - start) * sizeof (info[0]));
338 info[start] = t;
339 }
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000340 }
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000341}
342
343static void
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000344initial_reordering_syllable (const hb_ot_shape_plan_t *plan,
345 hb_face_t *face,
346 hb_buffer_t *buffer,
347 unsigned int start, unsigned int end)
348{
349 syllable_type_t syllable_type = (syllable_type_t) (buffer->info[start].syllable() & 0x0F);
350 switch (syllable_type)
351 {
Behdad Esfahbode6618f32018-01-05 17:21:55 +0000352 case broken_cluster: /* We already inserted dotted-circles, so just call the consonant_syllable. */
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000353 case consonant_syllable:
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700354 reorder_consonant_syllable (plan, face, buffer, start, end);
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000355 break;
356
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000357 case non_khmer_cluster:
358 break;
359 }
360}
361
362static inline void
363insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED,
364 hb_font_t *font,
365 hb_buffer_t *buffer)
366{
367 /* Note: This loop is extra overhead, but should not be measurable. */
368 bool has_broken_syllables = false;
369 unsigned int count = buffer->len;
370 hb_glyph_info_t *info = buffer->info;
371 for (unsigned int i = 0; i < count; i++)
372 if ((info[i].syllable() & 0x0F) == broken_cluster)
373 {
374 has_broken_syllables = true;
375 break;
376 }
377 if (likely (!has_broken_syllables))
378 return;
379
380
381 hb_codepoint_t dottedcircle_glyph;
382 if (!font->get_nominal_glyph (0x25CCu, &dottedcircle_glyph))
383 return;
384
385 hb_glyph_info_t dottedcircle = {0};
386 dottedcircle.codepoint = 0x25CCu;
387 set_khmer_properties (dottedcircle);
388 dottedcircle.codepoint = dottedcircle_glyph;
389
390 buffer->clear_output ();
391
392 buffer->idx = 0;
393 unsigned int last_syllable = 0;
Behdad Esfahbod7185b272018-05-31 20:03:00 -0700394 while (buffer->idx < buffer->len && buffer->successful)
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000395 {
396 unsigned int syllable = buffer->cur().syllable();
397 syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F);
398 if (unlikely (last_syllable != syllable && syllable_type == broken_cluster))
399 {
400 last_syllable = syllable;
401
402 hb_glyph_info_t ginfo = dottedcircle;
403 ginfo.cluster = buffer->cur().cluster;
404 ginfo.mask = buffer->cur().mask;
405 ginfo.syllable() = buffer->cur().syllable();
406 /* TODO Set glyph_props? */
407
408 /* Insert dottedcircle after possible Repha. */
Behdad Esfahbod7185b272018-05-31 20:03:00 -0700409 while (buffer->idx < buffer->len && buffer->successful &&
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000410 last_syllable == buffer->cur().syllable() &&
411 buffer->cur().khmer_category() == OT_Repha)
412 buffer->next_glyph ();
413
414 buffer->output_info (ginfo);
415 }
416 else
417 buffer->next_glyph ();
418 }
419
420 buffer->swap_buffers ();
421}
422
423static void
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700424reorder (const hb_ot_shape_plan_t *plan,
425 hb_font_t *font,
426 hb_buffer_t *buffer)
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000427{
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000428 insert_dotted_circles (plan, font, buffer);
429
430 foreach_syllable (buffer, start, end)
431 initial_reordering_syllable (plan, font->face, buffer, start, end);
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000432
433 HB_BUFFER_DEALLOCATE_VAR (buffer, khmer_category);
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000434}
435
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000436static void
437clear_syllables (const hb_ot_shape_plan_t *plan HB_UNUSED,
438 hb_font_t *font HB_UNUSED,
439 hb_buffer_t *buffer)
440{
Behdad Esfahbod1a96cc82018-07-31 11:45:32 -0700441 /* TODO: In USE, we clear syllables right after reorder. Figure out
442 * what Uniscribe does. */
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000443 hb_glyph_info_t *info = buffer->info;
444 unsigned int count = buffer->len;
445 for (unsigned int i = 0; i < count; i++)
446 info[i].syllable() = 0;
447}
448
449
450static bool
451decompose_khmer (const hb_ot_shape_normalize_context_t *c,
452 hb_codepoint_t ab,
453 hb_codepoint_t *a,
454 hb_codepoint_t *b)
455{
456 switch (ab)
457 {
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000458 /*
459 * Decompose split matras that don't have Unicode decompositions.
460 */
461
462 /* Khmer */
463 case 0x17BEu : *a = 0x17C1u; *b= 0x17BEu; return true;
464 case 0x17BFu : *a = 0x17C1u; *b= 0x17BFu; return true;
465 case 0x17C0u : *a = 0x17C1u; *b= 0x17C0u; return true;
466 case 0x17C4u : *a = 0x17C1u; *b= 0x17C4u; return true;
467 case 0x17C5u : *a = 0x17C1u; *b= 0x17C5u; return true;
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000468 }
469
470 return (bool) c->unicode->decompose (ab, a, b);
471}
472
473static bool
474compose_khmer (const hb_ot_shape_normalize_context_t *c,
475 hb_codepoint_t a,
476 hb_codepoint_t b,
477 hb_codepoint_t *ab)
478{
479 /* Avoid recomposing split matras. */
480 if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (c->unicode->general_category (a)))
481 return false;
482
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000483 return (bool) c->unicode->compose (a, b, ab);
484}
485
486
487const hb_ot_complex_shaper_t _hb_ot_complex_shaper_khmer =
488{
489 collect_features_khmer,
490 override_features_khmer,
491 data_create_khmer,
492 data_destroy_khmer,
493 nullptr, /* preprocess_text */
494 nullptr, /* postprocess_glyphs */
495 HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
496 decompose_khmer,
497 compose_khmer,
498 setup_masks_khmer,
Behdad Esfahbod48c513f2018-10-02 14:17:42 +0200499 HB_TAG_NONE, /* gpos_tag */
Behdad Esfahboddcf4d952018-01-05 14:54:31 +0000500 nullptr, /* reorder_marks */
501 HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE,
502 false, /* fallback_position */
503};