blob: 0d84a76b85f3fc1519578035bd497546452d0f30 [file] [log] [blame]
Behdad Esfahbodc98b7182013-12-31 15:55:40 +08001/*
2 * Copyright © 2013 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 Esfahbod7aad5362019-06-26 13:21:03 -070027#include "hb.hh"
28
29#ifndef HB_NO_OT_SHAPE
30
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070031#include "hb-ot-shape-complex.hh"
Behdad Esfahbodc98b7182013-12-31 15:55:40 +080032
33
34/* Hangul shaper */
35
36
Jonathan Kew10343682014-01-20 10:35:07 +000037/* Same order as the feature array below */
38enum {
Behdad Esfahbod00adf9c2017-01-09 00:00:49 -080039 _JMO,
Jonathan Kew10343682014-01-20 10:35:07 +000040
41 LJMO,
42 VJMO,
43 TJMO,
44
45 FIRST_HANGUL_FEATURE = LJMO,
46 HANGUL_FEATURE_COUNT = TJMO + 1
47};
48
49static const hb_tag_t hangul_features[HANGUL_FEATURE_COUNT] =
Behdad Esfahbodc98b7182013-12-31 15:55:40 +080050{
Jonathan Kew10343682014-01-20 10:35:07 +000051 HB_TAG_NONE,
Behdad Esfahbodc98b7182013-12-31 15:55:40 +080052 HB_TAG('l','j','m','o'),
53 HB_TAG('v','j','m','o'),
Jonathan Kew10343682014-01-20 10:35:07 +000054 HB_TAG('t','j','m','o')
Behdad Esfahbodc98b7182013-12-31 15:55:40 +080055};
56
57static void
58collect_features_hangul (hb_ot_shape_planner_t *plan)
59{
Jonathan Kew10343682014-01-20 10:35:07 +000060 hb_ot_map_builder_t *map = &plan->map;
61
62 for (unsigned int i = FIRST_HANGUL_FEATURE; i < HANGUL_FEATURE_COUNT; i++)
Behdad Esfahbodf048ead2018-09-24 18:01:53 -040063 map->add_feature (hangul_features[i]);
Behdad Esfahbodc98b7182013-12-31 15:55:40 +080064}
65
Behdad Esfahbodac534432014-07-31 18:51:37 -040066static void
67override_features_hangul (hb_ot_shape_planner_t *plan)
68{
69 /* Uniscribe does not apply 'calt' for Hangul, and certain fonts
70 * (Noto Sans CJK, Source Sans Han, etc) apply all of jamo lookups
71 * in calt, which is not desirable. */
Behdad Esfahbod1676f602018-09-24 17:55:03 -040072 plan->map.disable_feature (HB_TAG('c','a','l','t'));
Behdad Esfahbodac534432014-07-31 18:51:37 -040073}
74
Jonathan Kew10343682014-01-20 10:35:07 +000075struct hangul_shape_plan_t
76{
Jonathan Kew10343682014-01-20 10:35:07 +000077 hb_mask_t mask_array[HANGUL_FEATURE_COUNT];
78};
79
80static void *
81data_create_hangul (const hb_ot_shape_plan_t *plan)
82{
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -060083 hangul_shape_plan_t *hangul_plan = (hangul_shape_plan_t *) hb_calloc (1, sizeof (hangul_shape_plan_t));
Jonathan Kew10343682014-01-20 10:35:07 +000084 if (unlikely (!hangul_plan))
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +020085 return nullptr;
Jonathan Kew10343682014-01-20 10:35:07 +000086
87 for (unsigned int i = 0; i < HANGUL_FEATURE_COUNT; i++)
88 hangul_plan->mask_array[i] = plan->map.get_1_mask (hangul_features[i]);
89
90 return hangul_plan;
91}
92
93static void
94data_destroy_hangul (void *data)
95{
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -060096 hb_free (data);
Jonathan Kew10343682014-01-20 10:35:07 +000097}
98
99/* Constants for algorithmic hangul syllable [de]composition. */
Behdad Esfahbod76271002014-07-11 14:54:42 -0400100#define LBase 0x1100u
101#define VBase 0x1161u
102#define TBase 0x11A7u
103#define LCount 19u
104#define VCount 21u
105#define TCount 28u
106#define SBase 0xAC00u
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800107#define NCount (VCount * TCount)
108#define SCount (LCount * NCount)
109
Ebrahim Byagowi3b0e47c2017-06-19 14:47:09 +0430110#define isCombiningL(u) (hb_in_range<hb_codepoint_t> ((u), LBase, LBase+LCount-1))
111#define isCombiningV(u) (hb_in_range<hb_codepoint_t> ((u), VBase, VBase+VCount-1))
112#define isCombiningT(u) (hb_in_range<hb_codepoint_t> ((u), TBase+1, TBase+TCount-1))
113#define isCombinedS(u) (hb_in_range<hb_codepoint_t> ((u), SBase, SBase+SCount-1))
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800114
Ebrahim Byagowi3b0e47c2017-06-19 14:47:09 +0430115#define isL(u) (hb_in_ranges<hb_codepoint_t> ((u), 0x1100u, 0x115Fu, 0xA960u, 0xA97Cu))
116#define isV(u) (hb_in_ranges<hb_codepoint_t> ((u), 0x1160u, 0x11A7u, 0xD7B0u, 0xD7C6u))
117#define isT(u) (hb_in_ranges<hb_codepoint_t> ((u), 0x11A8u, 0x11FFu, 0xD7CBu, 0xD7FBu))
Jonathan Kew10343682014-01-20 10:35:07 +0000118
Ebrahim Byagowi3b0e47c2017-06-19 14:47:09 +0430119#define isHangulTone(u) (hb_in_range<hb_codepoint_t> ((u), 0x302Eu, 0x302Fu))
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000120
Jonathan Kew10343682014-01-20 10:35:07 +0000121/* buffer var allocations */
Behdad Esfahbod9dd61c52021-01-15 18:42:30 -0700122#define hangul_shaping_feature() complex_var_u8_auxiliary() /* hangul jamo shaping feature */
Jonathan Kew10343682014-01-20 10:35:07 +0000123
124static bool
125is_zero_width_char (hb_font_t *font,
126 hb_codepoint_t unicode)
127{
128 hb_codepoint_t glyph;
129 return hb_font_get_glyph (font, unicode, 0, &glyph) && hb_font_get_glyph_h_advance (font, glyph) == 0;
130}
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800131
132static void
Behdad Esfahbod39bd07a2018-10-26 21:01:11 -0700133preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED,
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800134 hb_buffer_t *buffer,
135 hb_font_t *font)
136{
Jonathan Kew10343682014-01-20 10:35:07 +0000137 HB_BUFFER_ALLOCATE_VAR (buffer, hangul_shaping_feature);
138
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800139 /* Hangul syllables come in two shapes: LV, and LVT. Of those:
140 *
141 * - LV can be precomposed, or decomposed. Lets call those
142 * <LV> and <L,V>,
143 * - LVT can be fully precomposed, partically precomposed, or
144 * fully decomposed. Ie. <LVT>, <LV,T>, or <L,V,T>.
145 *
146 * The composition / decomposition is mechanical. However, not
147 * all <L,V> sequences compose, and not all <LV,T> sequences
148 * compose.
149 *
150 * Here are the specifics:
151 *
152 * - <L>: U+1100..115F, U+A960..A97F
153 * - <V>: U+1160..11A7, U+D7B0..D7C7
Behdad Esfahbod32478652014-01-02 14:01:56 +0800154 * - <T>: U+11A8..11FF, U+D7CB..D7FB
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800155 *
Behdad Esfahbod93dad9a2018-03-31 17:06:17 +0200156 * - Only the <L,V> sequences for some of the U+11xx ranges combine.
157 * - Only <LV,T> sequences for some of the Ts in U+11xx range combine.
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800158 *
159 * Here is what we want to accomplish in this shaper:
160 *
161 * - If the whole syllable can be precomposed, do that,
Jonathan Kew10343682014-01-20 10:35:07 +0000162 * - Otherwise, fully decompose and apply ljmo/vjmo/tjmo features.
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000163 * - If a valid syllable is followed by a Hangul tone mark, reorder the tone
164 * mark to precede the whole syllable - unless it is a zero-width glyph, in
165 * which case we leave it untouched, assuming it's designed to overstrike.
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800166 *
167 * That is, of the different possible syllables:
168 *
169 * <L>
170 * <L,V>
171 * <L,V,T>
172 * <LV>
173 * <LVT>
174 * <LV, T>
175 *
176 * - <L> needs no work.
177 *
178 * - <LV> and <LVT> can stay the way they are if the font supports them, otherwise we
179 * should fully decompose them if font supports.
180 *
181 * - <L,V> and <L,V,T> we should compose if the whole thing can be composed.
182 *
183 * - <LV,T> we should compose if the whole thing can be composed, otherwise we should
184 * decompose.
185 */
186
187 buffer->clear_output ();
Jonathan Kew10343682014-01-20 10:35:07 +0000188 unsigned int start = 0, end = 0; /* Extent of most recently seen syllable;
189 * valid only if start < end
190 */
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800191 unsigned int count = buffer->len;
Jonathan Kew10343682014-01-20 10:35:07 +0000192
Behdad Esfahbod7185b272018-05-31 20:03:00 -0700193 for (buffer->idx = 0; buffer->idx < count && buffer->successful;)
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800194 {
195 hb_codepoint_t u = buffer->cur().codepoint;
196
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000197 if (isHangulTone (u))
198 {
199 /*
200 * We could cache the width of the tone marks and the existence of dotted-circle,
201 * but the use of the Hangul tone mark characters seems to be rare enough that
202 * I didn't bother for now.
203 */
204 if (start < end && end == buffer->out_len)
205 {
206 /* Tone mark follows a valid syllable; move it in front, unless it's zero width. */
Ebrahim Byagowia0b4ac42019-08-24 17:57:14 +0430207 buffer->unsafe_to_break_from_outbuffer (start, buffer->idx);
Behdad Esfahbod8450f432021-03-15 15:18:06 -0600208 if (unlikely (!buffer->next_glyph ())) break;
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000209 if (!is_zero_width_char (font, u))
210 {
Behdad Esfahbod0d438f82015-09-01 16:24:13 +0100211 buffer->merge_out_clusters (start, end + 1);
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000212 hb_glyph_info_t *info = buffer->out_info;
213 hb_glyph_info_t tone = info[end];
214 memmove (&info[start + 1], &info[start], (end - start) * sizeof (hb_glyph_info_t));
215 info[start] = tone;
216 }
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000217 }
218 else
219 {
220 /* No valid syllable as base for tone mark; try to insert dotted circle. */
Behdad Esfahbod99767f92021-03-15 12:36:59 -0600221 if (!(buffer->flags & HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE) &&
222 font->has_glyph (0x25CCu))
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000223 {
224 hb_codepoint_t chars[2];
Behdad Esfahbod99767f92021-03-15 12:36:59 -0600225 if (!is_zero_width_char (font, u))
226 {
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000227 chars[0] = u;
Behdad Esfahbod76271002014-07-11 14:54:42 -0400228 chars[1] = 0x25CCu;
Behdad Esfahbod99767f92021-03-15 12:36:59 -0600229 } else
230 {
Behdad Esfahbod76271002014-07-11 14:54:42 -0400231 chars[0] = 0x25CCu;
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000232 chars[1] = u;
233 }
Behdad Esfahbod607979d2021-03-15 13:23:48 -0600234 (void) buffer->replace_glyphs (1, 2, chars);
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000235 }
236 else
237 {
238 /* No dotted circle available in the font; just leave tone mark untouched. */
Behdad Esfahbod8450f432021-03-15 15:18:06 -0600239 (void) buffer->next_glyph ();
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000240 }
241 }
242 start = end = buffer->out_len;
243 continue;
244 }
245
Jonathan Kew10343682014-01-20 10:35:07 +0000246 start = buffer->out_len; /* Remember current position as a potential syllable start;
247 * will only be used if we set end to a later position.
248 */
249
250 if (isL (u) && buffer->idx + 1 < count)
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800251 {
252 hb_codepoint_t l = u;
253 hb_codepoint_t v = buffer->cur(+1).codepoint;
Jonathan Kew10343682014-01-20 10:35:07 +0000254 if (isV (v))
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800255 {
Jonathan Kew10343682014-01-20 10:35:07 +0000256 /* Have <L,V> or <L,V,T>. */
257 hb_codepoint_t t = 0;
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800258 unsigned int tindex = 0;
259 if (buffer->idx + 2 < count)
260 {
Jonathan Kew10343682014-01-20 10:35:07 +0000261 t = buffer->cur(+2).codepoint;
262 if (isT (t))
263 tindex = t - TBase; /* Only used if isCombiningT (t); otherwise invalid. */
264 else
265 t = 0; /* The next character was not a trailing jamo. */
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800266 }
Behdad Esfahbodeae00962017-08-10 20:50:48 -0700267 buffer->unsafe_to_break (buffer->idx, buffer->idx + (t ? 3 : 2));
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800268
Jonathan Kew10343682014-01-20 10:35:07 +0000269 /* We've got a syllable <L,V,T?>; see if it can potentially be composed. */
270 if (isCombiningL (l) && isCombiningV (v) && (t == 0 || isCombiningT (t)))
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800271 {
Jonathan Kew10343682014-01-20 10:35:07 +0000272 /* Try to compose; if this succeeds, end is set to start+1. */
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800273 hb_codepoint_t s = SBase + (l - LBase) * NCount + (v - VBase) * TCount + tindex;
Behdad Esfahbod8de20b12014-01-02 14:30:45 +0800274 if (font->has_glyph (s))
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800275 {
Behdad Esfahbod607979d2021-03-15 13:23:48 -0600276 (void) buffer->replace_glyphs (t ? 3 : 2, 1, &s);
Jonathan Kew10343682014-01-20 10:35:07 +0000277 end = start + 1;
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800278 continue;
279 }
280 }
Jonathan Kew10343682014-01-20 10:35:07 +0000281
282 /* We didn't compose, either because it's an Old Hangul syllable without a
283 * precomposed character in Unicode, or because the font didn't support the
284 * necessary precomposed glyph.
285 * Set jamo features on the individual glyphs, and advance past them.
286 */
287 buffer->cur().hangul_shaping_feature() = LJMO;
Behdad Esfahbod8450f432021-03-15 15:18:06 -0600288 (void) buffer->next_glyph ();
Jonathan Kew10343682014-01-20 10:35:07 +0000289 buffer->cur().hangul_shaping_feature() = VJMO;
Behdad Esfahbod8450f432021-03-15 15:18:06 -0600290 (void) buffer->next_glyph ();
Jonathan Kew10343682014-01-20 10:35:07 +0000291 if (t)
292 {
293 buffer->cur().hangul_shaping_feature() = TJMO;
Behdad Esfahbod8450f432021-03-15 15:18:06 -0600294 (void) buffer->next_glyph ();
Jonathan Kew10343682014-01-20 10:35:07 +0000295 end = start + 3;
296 }
297 else
298 end = start + 2;
Behdad Esfahboda5b8e7d2021-03-15 12:46:58 -0600299 if (unlikely (!buffer->successful))
300 break;
Behdad Esfahbod376d5872015-07-22 16:51:12 +0100301 if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES)
302 buffer->merge_out_clusters (start, end);
Jonathan Kew10343682014-01-20 10:35:07 +0000303 continue;
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800304 }
305 }
306
Jonathan Kew10343682014-01-20 10:35:07 +0000307 else if (isCombinedS (u))
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800308 {
Jonathan Kew10343682014-01-20 10:35:07 +0000309 /* Have <LV>, <LVT>, or <LV,T> */
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800310 hb_codepoint_t s = u;
Behdad Esfahbodea512f72015-11-26 19:22:22 -0500311 bool has_glyph = font->has_glyph (s);
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800312 unsigned int lindex = (s - SBase) / NCount;
313 unsigned int nindex = (s - SBase) % NCount;
Behdad Esfahbodbdb20da2014-01-02 14:04:30 +0800314 unsigned int vindex = nindex / TCount;
315 unsigned int tindex = nindex % TCount;
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800316
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800317 if (!tindex &&
318 buffer->idx + 1 < count &&
319 isCombiningT (buffer->cur(+1).codepoint))
320 {
321 /* <LV,T>, try to combine. */
Behdad Esfahbod29ea4032014-01-02 14:20:00 +0800322 unsigned int new_tindex = buffer->cur(+1).codepoint - TBase;
323 hb_codepoint_t new_s = s + new_tindex;
Jonathan Kew10343682014-01-20 10:35:07 +0000324 if (font->has_glyph (new_s))
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800325 {
Behdad Esfahbod607979d2021-03-15 13:23:48 -0600326 (void) buffer->replace_glyphs (2, 1, &new_s);
Jonathan Kew10343682014-01-20 10:35:07 +0000327 end = start + 1;
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800328 continue;
329 }
Behdad Esfahbodeae00962017-08-10 20:50:48 -0700330 else
331 buffer->unsafe_to_break (buffer->idx, buffer->idx + 2); /* Mark unsafe between LV and T. */
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800332 }
333
Behdad Esfahbod29ea4032014-01-02 14:20:00 +0800334 /* Otherwise, decompose if font doesn't support <LV> or <LVT>,
335 * or if having non-combining <LV,T>. Note that we already handled
336 * combining <LV,T> above. */
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800337 if (!has_glyph ||
Behdad Esfahbod29ea4032014-01-02 14:20:00 +0800338 (!tindex &&
339 buffer->idx + 1 < count &&
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800340 isT (buffer->cur(+1).codepoint)))
341 {
342 hb_codepoint_t decomposed[3] = {LBase + lindex,
343 VBase + vindex,
344 TBase + tindex};
Jonathan Kew10343682014-01-20 10:35:07 +0000345 if (font->has_glyph (decomposed[0]) &&
Behdad Esfahbod8de20b12014-01-02 14:30:45 +0800346 font->has_glyph (decomposed[1]) &&
347 (!tindex || font->has_glyph (decomposed[2])))
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800348 {
Jonathan Kew10343682014-01-20 10:35:07 +0000349 unsigned int s_len = tindex ? 3 : 2;
Behdad Esfahbod607979d2021-03-15 13:23:48 -0600350 (void) buffer->replace_glyphs (1, s_len, decomposed);
Jonathan Kew10343682014-01-20 10:35:07 +0000351
352 /* If we decomposed an LV because of a non-combining T following,
353 * we want to include this T in the syllable.
354 */
355 if (has_glyph && !tindex)
356 {
Behdad Esfahbod8450f432021-03-15 15:18:06 -0600357 (void) buffer->next_glyph ();
Ebrahim Byagowia0b4ac42019-08-24 17:57:14 +0430358 s_len++;
359 }
Behdad Esfahboded2ee782018-10-13 09:47:51 -0400360 if (unlikely (!buffer->successful))
Behdad Esfahboda5b8e7d2021-03-15 12:46:58 -0600361 break;
Behdad Esfahboded2ee782018-10-13 09:47:51 -0400362
363 /* We decomposed S: apply jamo features to the individual glyphs
364 * that are now in buffer->out_info.
365 */
366 hb_glyph_info_t *info = buffer->out_info;
Ebrahim Byagowia0b4ac42019-08-24 17:57:14 +0430367 end = start + s_len;
Jonathan Kew10343682014-01-20 10:35:07 +0000368
369 unsigned int i = start;
370 info[i++].hangul_shaping_feature() = LJMO;
371 info[i++].hangul_shaping_feature() = VJMO;
372 if (i < end)
373 info[i++].hangul_shaping_feature() = TJMO;
Behdad Esfahboded2ee782018-10-13 09:47:51 -0400374
Behdad Esfahbod376d5872015-07-22 16:51:12 +0100375 if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES)
376 buffer->merge_out_clusters (start, end);
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800377 continue;
378 }
Behdad Esfahbod14a639e2017-08-11 11:30:39 -0700379 else if ((!tindex && buffer->idx + 1 < count && isT (buffer->cur(+1).codepoint)))
Behdad Esfahbodeae00962017-08-10 20:50:48 -0700380 buffer->unsafe_to_break (buffer->idx, buffer->idx + 2); /* Mark unsafe between LV and T. */
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800381 }
Jonathan Kew10343682014-01-20 10:35:07 +0000382
383 if (has_glyph)
384 {
Behdad Esfahbod8450f432021-03-15 15:18:06 -0600385 /* We didn't decompose the S, so just advance past it and fall through. */
Jonathan Kew10343682014-01-20 10:35:07 +0000386 end = start + 1;
Jonathan Kew10343682014-01-20 10:35:07 +0000387 }
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800388 }
389
Jonathan Kew7244b3f2014-01-20 10:35:51 +0000390 /* Didn't find a recognizable syllable, so we leave end <= start;
391 * this will prevent tone-mark reordering happening.
392 */
Behdad Esfahbod8450f432021-03-15 15:18:06 -0600393 (void) buffer->next_glyph ();
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800394 }
395 buffer->swap_buffers ();
396}
397
Jonathan Kew10343682014-01-20 10:35:07 +0000398static void
399setup_masks_hangul (const hb_ot_shape_plan_t *plan,
400 hb_buffer_t *buffer,
401 hb_font_t *font HB_UNUSED)
402{
403 const hangul_shape_plan_t *hangul_plan = (const hangul_shape_plan_t *) plan->data;
404
405 if (likely (hangul_plan))
406 {
407 unsigned int count = buffer->len;
408 hb_glyph_info_t *info = buffer->info;
409 for (unsigned int i = 0; i < count; i++, info++)
410 info->mask |= hangul_plan->mask_array[info->hangul_shaping_feature()];
411 }
412
413 HB_BUFFER_DEALLOCATE_VAR (buffer, hangul_shaping_feature);
414}
415
416
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800417const hb_ot_complex_shaper_t _hb_ot_complex_shaper_hangul =
418{
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800419 collect_features_hangul,
Behdad Esfahbodac534432014-07-31 18:51:37 -0400420 override_features_hangul,
Behdad Esfahbod13686332015-11-05 13:24:15 -0800421 data_create_hangul,
422 data_destroy_hangul,
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800423 preprocess_text_hangul,
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200424 nullptr, /* postprocess_glyphs */
Behdad Esfahbod8fc1f7f2014-01-02 17:04:04 +0800425 HB_OT_SHAPE_NORMALIZATION_MODE_NONE,
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200426 nullptr, /* decompose */
427 nullptr, /* compose */
Behdad Esfahbod13686332015-11-05 13:24:15 -0800428 setup_masks_hangul,
Behdad Esfahbod48c513f2018-10-02 14:17:42 +0200429 HB_TAG_NONE, /* gpos_tag */
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200430 nullptr, /* reorder_marks */
Jonathan Kewdeef1862014-01-20 10:38:27 +0000431 HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE,
Behdad Esfahbodc98b7182013-12-31 15:55:40 +0800432 false, /* fallback_position */
433};
Behdad Esfahbod7aad5362019-06-26 13:21:03 -0700434
435
436#endif