OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2011,2012 Google, Inc. | 2 * Copyright © 2011,2012 Google, Inc. |
3 * | 3 * |
4 * This is part of HarfBuzz, a text shaping library. | 4 * This is part of HarfBuzz, a text shaping library. |
5 * | 5 * |
6 * Permission is hereby granted, without written agreement and without | 6 * Permission is hereby granted, without written agreement and without |
7 * license or royalty fees, to use, copy, modify, and distribute this | 7 * license or royalty fees, to use, copy, modify, and distribute this |
8 * software and its documentation for any purpose, provided that the | 8 * software and its documentation for any purpose, provided that the |
9 * above copyright notice and the following two paragraphs appear in | 9 * above copyright notice and the following two paragraphs appear in |
10 * all copies of this software. | 10 * all copies of this software. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 output_char (c->buffer, b, b_glyph); | 163 output_char (c->buffer, b, b_glyph); |
164 return 2; | 164 return 2; |
165 } | 165 } |
166 return 1; | 166 return 1; |
167 } | 167 } |
168 | 168 |
169 return 0; | 169 return 0; |
170 } | 170 } |
171 | 171 |
172 /* Returns 0 if didn't decompose, number of resulting characters otherwise. */ | 172 /* Returns 0 if didn't decompose, number of resulting characters otherwise. */ |
173 static inline bool | 173 static inline unsigned int |
174 decompose_compatibility (const hb_ot_shape_normalize_context_t *c, hb_codepoint_
t u) | 174 decompose_compatibility (const hb_ot_shape_normalize_context_t *c, hb_codepoint_
t u) |
175 { | 175 { |
176 unsigned int len, i; | 176 unsigned int len, i; |
177 hb_codepoint_t decomposed[HB_UNICODE_MAX_DECOMPOSITION_LEN]; | 177 hb_codepoint_t decomposed[HB_UNICODE_MAX_DECOMPOSITION_LEN]; |
178 hb_codepoint_t glyphs[HB_UNICODE_MAX_DECOMPOSITION_LEN]; | 178 hb_codepoint_t glyphs[HB_UNICODE_MAX_DECOMPOSITION_LEN]; |
179 | 179 |
180 len = c->buffer->unicode->decompose_compatibility (u, decomposed); | 180 len = c->buffer->unicode->decompose_compatibility (u, decomposed); |
181 if (!len) | 181 if (!len) |
182 return 0; | 182 return 0; |
183 | 183 |
184 for (i = 0; i < len; i++) | 184 for (i = 0; i < len; i++) |
185 if (!c->font->get_glyph (decomposed[i], 0, &glyphs[i])) | 185 if (!c->font->get_glyph (decomposed[i], 0, &glyphs[i])) |
186 return 0; | 186 return 0; |
187 | 187 |
188 for (i = 0; i < len; i++) | 188 for (i = 0; i < len; i++) |
189 output_char (c->buffer, decomposed[i], glyphs[i]); | 189 output_char (c->buffer, decomposed[i], glyphs[i]); |
190 | 190 |
191 return len; | 191 return len; |
192 } | 192 } |
193 | 193 |
194 /* Returns true if recomposition may be benefitial. */ | |
195 static inline void | 194 static inline void |
196 decompose_current_character (const hb_ot_shape_normalize_context_t *c, bool shor
test) | 195 decompose_current_character (const hb_ot_shape_normalize_context_t *c, bool shor
test) |
197 { | 196 { |
198 hb_buffer_t * const buffer = c->buffer; | 197 hb_buffer_t * const buffer = c->buffer; |
199 hb_codepoint_t glyph; | 198 hb_codepoint_t glyph; |
200 | 199 |
201 /* Kind of a cute waterfall here... */ | 200 /* Kind of a cute waterfall here... */ |
202 if (shortest && c->font->get_glyph (buffer->cur().codepoint, 0, &glyph)) | 201 if (shortest && c->font->get_glyph (buffer->cur().codepoint, 0, &glyph)) |
203 next_char (buffer, glyph); | 202 next_char (buffer, glyph); |
204 else if (decompose (c, shortest, buffer->cur().codepoint)) | 203 else if (decompose (c, shortest, buffer->cur().codepoint)) |
(...skipping 19 matching lines...) Expand all Loading... |
224 set_glyph (buffer->cur(), c->font); | 223 set_glyph (buffer->cur(), c->font); |
225 buffer->next_glyph (); | 224 buffer->next_glyph (); |
226 } | 225 } |
227 } | 226 } |
228 if (likely (buffer->idx < end)) { | 227 if (likely (buffer->idx < end)) { |
229 set_glyph (buffer->cur(), c->font); | 228 set_glyph (buffer->cur(), c->font); |
230 buffer->next_glyph (); | 229 buffer->next_glyph (); |
231 } | 230 } |
232 } | 231 } |
233 | 232 |
234 /* Returns true if recomposition may be benefitial. */ | |
235 static inline void | 233 static inline void |
236 decompose_multi_char_cluster (const hb_ot_shape_normalize_context_t *c, unsigned
int end) | 234 decompose_multi_char_cluster (const hb_ot_shape_normalize_context_t *c, unsigned
int end) |
237 { | 235 { |
238 hb_buffer_t * const buffer = c->buffer; | 236 hb_buffer_t * const buffer = c->buffer; |
239 /* TODO Currently if there's a variation-selector we give-up, it's just too ha
rd. */ | 237 /* TODO Currently if there's a variation-selector we give-up, it's just too ha
rd. */ |
240 for (unsigned int i = buffer->idx; i < end; i++) | 238 for (unsigned int i = buffer->idx; i < end; i++) |
241 if (unlikely (buffer->unicode->is_variation_selector (buffer->info[i].codepo
int))) { | 239 if (unlikely (buffer->unicode->is_variation_selector (buffer->info[i].codepo
int))) { |
242 handle_variation_selector_cluster (c, end); | 240 handle_variation_selector_cluster (c, end); |
243 return; | 241 return; |
244 } | 242 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 /* As noted in the comment earlier, we don't try to combine | 344 /* As noted in the comment earlier, we don't try to combine |
347 * ccc=0 chars with their previous Starter. */ | 345 * ccc=0 chars with their previous Starter. */ |
348 | 346 |
349 buffer->clear_output (); | 347 buffer->clear_output (); |
350 count = buffer->len; | 348 count = buffer->len; |
351 unsigned int starter = 0; | 349 unsigned int starter = 0; |
352 buffer->next_glyph (); | 350 buffer->next_glyph (); |
353 while (buffer->idx < count) | 351 while (buffer->idx < count) |
354 { | 352 { |
355 hb_codepoint_t composed, glyph; | 353 hb_codepoint_t composed, glyph; |
356 if (/* If mode is NOT COMPOSED_FULL (ie. it's COMPOSED_DIACRITICS), we don't
try to | 354 if (/* We don't try to compose a non-mark character with it's preceding star
ter. |
357 » * compose a non-mark character with it's preceding starter. This is ju
st an | 355 » * This is both an optimization to avoid trying to compose every two nei
ghboring |
358 » * optimization to avoid trying to compose every two neighboring glyphs
in most | 356 » * glyphs in most scripts AND a desired feature for Hangul. Apparently
Hangul |
359 » * scripts. */ | 357 » * fonts are not designed to mix-and-match pre-composed syllables and Ja
mo. */ |
360 » (mode == HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL || | 358 » HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category
(&buffer->cur())) && |
361 » HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_categor
y (&buffer->cur()))) && | |
362 /* If there's anything between the starter and this char, they should ha
ve CCC | 359 /* If there's anything between the starter and this char, they should ha
ve CCC |
363 * smaller than this character's. */ | 360 * smaller than this character's. */ |
364 (starter == buffer->out_len - 1 || | 361 (starter == buffer->out_len - 1 || |
365 _hb_glyph_info_get_modified_combining_class (&buffer->prev()) < _hb_gly
ph_info_get_modified_combining_class (&buffer->cur())) && | 362 _hb_glyph_info_get_modified_combining_class (&buffer->prev()) < _hb_gly
ph_info_get_modified_combining_class (&buffer->cur())) && |
366 /* And compose. */ | 363 /* And compose. */ |
367 c.compose (&c, | 364 c.compose (&c, |
368 buffer->out_info[starter].codepoint, | 365 buffer->out_info[starter].codepoint, |
369 buffer->cur().codepoint, | 366 buffer->cur().codepoint, |
370 &composed) && | 367 &composed) && |
371 /* And the font has glyph for the composite. */ | 368 /* And the font has glyph for the composite. */ |
(...skipping 14 matching lines...) Expand all Loading... |
386 | 383 |
387 /* Blocked, or doesn't compose. */ | 384 /* Blocked, or doesn't compose. */ |
388 buffer->next_glyph (); | 385 buffer->next_glyph (); |
389 | 386 |
390 if (_hb_glyph_info_get_modified_combining_class (&buffer->prev()) == 0) | 387 if (_hb_glyph_info_get_modified_combining_class (&buffer->prev()) == 0) |
391 starter = buffer->out_len - 1; | 388 starter = buffer->out_len - 1; |
392 } | 389 } |
393 buffer->swap_buffers (); | 390 buffer->swap_buffers (); |
394 | 391 |
395 } | 392 } |
OLD | NEW |