Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 2 | * Copyright © 2011,2012 Google, Inc. |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 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 Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 27 | #include "hb-ot-shape-normalize-private.hh" |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 28 | #include "hb-ot-shape-private.hh" |
| 29 | |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 30 | |
Behdad Esfahbod | 5d90a34 | 2011-07-21 15:25:01 -0400 | [diff] [blame] | 31 | /* |
| 32 | * HIGHLEVEL DESIGN: |
| 33 | * |
| 34 | * This file exports one main function: _hb_ot_shape_normalize(). |
| 35 | * |
| 36 | * This function closely reflects the Unicode Normalization Algorithm, |
Behdad Esfahbod | c346671 | 2012-03-06 20:47:50 -0500 | [diff] [blame] | 37 | * yet it's different. |
| 38 | * |
| 39 | * Each shaper specifies whether it prefers decomposed (NFD) or composed (NFC). |
| 40 | * The logic however tries to use whatever the font can support. |
Behdad Esfahbod | 5d90a34 | 2011-07-21 15:25:01 -0400 | [diff] [blame] | 41 | * |
| 42 | * In general what happens is that: each grapheme is decomposed in a chain |
Behdad Esfahbod | 947c9a7 | 2011-09-16 16:33:18 -0400 | [diff] [blame] | 43 | * of 1:2 decompositions, marks reordered, and then recomposed if desired, |
Behdad Esfahbod | 5d90a34 | 2011-07-21 15:25:01 -0400 | [diff] [blame] | 44 | * so far it's like Unicode Normalization. However, the decomposition and |
| 45 | * recomposition only happens if the font supports the resulting characters. |
| 46 | * |
| 47 | * The goals are: |
| 48 | * |
| 49 | * - Try to render all canonically equivalent strings similarly. To really |
| 50 | * achieve this we have to always do the full decomposition and then |
| 51 | * selectively recompose from there. It's kinda too expensive though, so |
| 52 | * we skip some cases. For example, if composed is desired, we simply |
| 53 | * don't touch 1-character clusters that are supported by the font, even |
| 54 | * though their NFC may be different. |
| 55 | * |
| 56 | * - When a font has a precomposed character for a sequence but the 'ccmp' |
Behdad Esfahbod | 947c9a7 | 2011-09-16 16:33:18 -0400 | [diff] [blame] | 57 | * feature in the font is not adequate, use the precomposed character |
Behdad Esfahbod | 5d90a34 | 2011-07-21 15:25:01 -0400 | [diff] [blame] | 58 | * which typically has better mark positioning. |
| 59 | * |
Behdad Esfahbod | 55deff7 | 2011-09-28 16:20:09 -0400 | [diff] [blame] | 60 | * - When a font does not support a combining mark, but supports it precomposed |
Behdad Esfahbod | c346671 | 2012-03-06 20:47:50 -0500 | [diff] [blame] | 61 | * with previous base, use that. This needs the itemizer to have this |
Behdad Esfahbod | e3b2e07 | 2012-03-07 10:21:24 -0500 | [diff] [blame] | 62 | * knowledge too. We need to provide assistance to the itemizer. |
Behdad Esfahbod | 55deff7 | 2011-09-28 16:20:09 -0400 | [diff] [blame] | 63 | * |
Behdad Esfahbod | 5d90a34 | 2011-07-21 15:25:01 -0400 | [diff] [blame] | 64 | * - When a font does not support a character but supports its decomposition, |
| 65 | * well, use the decomposition. |
| 66 | * |
| 67 | * - The Indic shaper requests decomposed output. This will handle splitting |
| 68 | * matra for the Indic shaper. |
| 69 | */ |
| 70 | |
Behdad Esfahbod | 683b503 | 2012-04-14 20:47:14 -0400 | [diff] [blame] | 71 | static inline void |
| 72 | set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unicode) |
| 73 | { |
| 74 | info->general_category() = hb_unicode_general_category (unicode, info->codepoint); |
| 75 | info->combining_class() = _hb_unicode_modified_combining_class (unicode, info->codepoint); |
| 76 | } |
| 77 | |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 78 | static void |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 79 | output_glyph (hb_font_t *font, hb_buffer_t *buffer, |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 80 | hb_codepoint_t glyph) |
| 81 | { |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 82 | buffer->output_glyph (glyph); |
Behdad Esfahbod | 683b503 | 2012-04-14 20:47:14 -0400 | [diff] [blame] | 83 | set_unicode_props (&buffer->out_info[buffer->out_len - 1], buffer->unicode); |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 84 | } |
Behdad Esfahbod | 5c6f598 | 2011-07-21 11:31:08 -0400 | [diff] [blame] | 85 | |
Behdad Esfahbod | 4541252 | 2011-07-22 11:07:05 -0400 | [diff] [blame] | 86 | static bool |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 87 | decompose (hb_font_t *font, hb_buffer_t *buffer, |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 88 | bool shortest, |
Behdad Esfahbod | 4541252 | 2011-07-22 11:07:05 -0400 | [diff] [blame] | 89 | hb_codepoint_t ab) |
| 90 | { |
| 91 | hb_codepoint_t a, b, glyph; |
Behdad Esfahbod | 4541252 | 2011-07-22 11:07:05 -0400 | [diff] [blame] | 92 | |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 93 | if (!hb_unicode_decompose (buffer->unicode, ab, &a, &b) || |
| 94 | (b && !hb_font_get_glyph (font, b, 0, &glyph))) |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 95 | return FALSE; |
Behdad Esfahbod | 4541252 | 2011-07-22 11:07:05 -0400 | [diff] [blame] | 96 | |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 97 | bool has_a = hb_font_get_glyph (font, a, 0, &glyph); |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 98 | if (shortest && has_a) { |
| 99 | /* Output a and b */ |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 100 | output_glyph (font, buffer, a); |
Behdad Esfahbod | dcdc51c | 2011-07-22 17:14:46 -0400 | [diff] [blame] | 101 | if (b) |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 102 | output_glyph (font, buffer, b); |
Behdad Esfahbod | 4541252 | 2011-07-22 11:07:05 -0400 | [diff] [blame] | 103 | return TRUE; |
| 104 | } |
| 105 | |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 106 | if (decompose (font, buffer, shortest, a)) { |
Behdad Esfahbod | dcdc51c | 2011-07-22 17:14:46 -0400 | [diff] [blame] | 107 | if (b) |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 108 | output_glyph (font, buffer, b); |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 109 | return TRUE; |
| 110 | } |
Behdad Esfahbod | 5c6f598 | 2011-07-21 11:31:08 -0400 | [diff] [blame] | 111 | |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 112 | if (has_a) { |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 113 | output_glyph (font, buffer, a); |
Behdad Esfahbod | dcdc51c | 2011-07-22 17:14:46 -0400 | [diff] [blame] | 114 | if (b) |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 115 | output_glyph (font, buffer, b); |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 116 | return TRUE; |
| 117 | } |
| 118 | |
Behdad Esfahbod | 5c6f598 | 2011-07-21 11:31:08 -0400 | [diff] [blame] | 119 | return FALSE; |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 120 | } |
| 121 | |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 122 | static void |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 123 | decompose_current_glyph (hb_font_t *font, hb_buffer_t *buffer, |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 124 | bool shortest) |
Behdad Esfahbod | d6b9c6d | 2011-07-21 12:16:45 -0400 | [diff] [blame] | 125 | { |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 126 | if (decompose (font, buffer, shortest, buffer->info[buffer->idx].codepoint)) |
| 127 | buffer->skip_glyph (); |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 128 | else |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 129 | buffer->next_glyph (); |
Behdad Esfahbod | d6b9c6d | 2011-07-21 12:16:45 -0400 | [diff] [blame] | 130 | } |
| 131 | |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 132 | static void |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 133 | decompose_single_char_cluster (hb_font_t *font, hb_buffer_t *buffer, |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 134 | bool will_recompose) |
| 135 | { |
| 136 | hb_codepoint_t glyph; |
| 137 | |
| 138 | /* If recomposing and font supports this, we're good to go */ |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 139 | if (will_recompose && hb_font_get_glyph (font, buffer->info[buffer->idx].codepoint, 0, &glyph)) { |
| 140 | buffer->next_glyph (); |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 141 | return; |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 142 | } |
| 143 | |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 144 | decompose_current_glyph (font, buffer, will_recompose); |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 145 | } |
| 146 | |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 147 | static void |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 148 | decompose_multi_char_cluster (hb_font_t *font, hb_buffer_t *buffer, |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 149 | unsigned int end) |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 150 | { |
Behdad Esfahbod | 5d90a34 | 2011-07-21 15:25:01 -0400 | [diff] [blame] | 151 | /* TODO Currently if there's a variation-selector we give-up, it's just too hard. */ |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 152 | for (unsigned int i = buffer->idx; i < end; i++) |
| 153 | if (unlikely (_hb_unicode_is_variation_selector (buffer->info[i].codepoint))) { |
| 154 | while (buffer->idx < end) |
| 155 | buffer->next_glyph (); |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 156 | return; |
Behdad Esfahbod | af913c5 | 2011-10-17 11:39:28 -0700 | [diff] [blame] | 157 | } |
Behdad Esfahbod | d6b9c6d | 2011-07-21 12:16:45 -0400 | [diff] [blame] | 158 | |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 159 | while (buffer->idx < end) |
| 160 | decompose_current_glyph (font, buffer, FALSE); |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 163 | static int |
| 164 | compare_combining_class (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) |
| 165 | { |
| 166 | unsigned int a = pa->combining_class(); |
| 167 | unsigned int b = pb->combining_class(); |
| 168 | |
| 169 | return a < b ? -1 : a == b ? 0 : +1; |
| 170 | } |
| 171 | |
Behdad Esfahbod | 4541252 | 2011-07-22 11:07:05 -0400 | [diff] [blame] | 172 | void |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 173 | _hb_ot_shape_normalize (hb_font_t *font, hb_buffer_t *buffer, |
| 174 | hb_ot_shape_normalization_mode_t mode) |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 175 | { |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 176 | bool recompose = mode != HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED; |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 177 | bool has_multichar_clusters = FALSE; |
Behdad Esfahbod | 34c22f8 | 2011-07-22 17:04:20 -0400 | [diff] [blame] | 178 | unsigned int count; |
Behdad Esfahbod | 5c6f598 | 2011-07-21 11:31:08 -0400 | [diff] [blame] | 179 | |
Behdad Esfahbod | c311d85 | 2011-07-23 23:43:54 -0400 | [diff] [blame] | 180 | /* We do a fairly straightforward yet custom normalization process in three |
Behdad Esfahbod | 5389ff4 | 2011-07-22 20:22:49 -0400 | [diff] [blame] | 181 | * separate rounds: decompose, reorder, recompose (if desired). Currently |
| 182 | * this makes two buffer swaps. We can make it faster by moving the last |
| 183 | * two rounds into the inner loop for the first round, but it's more readable |
| 184 | * this way. */ |
Behdad Esfahbod | 5d90a34 | 2011-07-21 15:25:01 -0400 | [diff] [blame] | 185 | |
Behdad Esfahbod | 34c22f8 | 2011-07-22 17:04:20 -0400 | [diff] [blame] | 186 | |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 187 | /* First round, decompose */ |
| 188 | |
Behdad Esfahbod | 5389ff4 | 2011-07-22 20:22:49 -0400 | [diff] [blame] | 189 | buffer->clear_output (); |
Behdad Esfahbod | 34c22f8 | 2011-07-22 17:04:20 -0400 | [diff] [blame] | 190 | count = buffer->len; |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 191 | for (buffer->idx = 0; buffer->idx < count;) |
Behdad Esfahbod | 5d90a34 | 2011-07-21 15:25:01 -0400 | [diff] [blame] | 192 | { |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 193 | unsigned int end; |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 194 | for (end = buffer->idx + 1; end < count; end++) |
| 195 | if (buffer->info[buffer->idx].cluster != buffer->info[end].cluster) |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 196 | break; |
Behdad Esfahbod | 5d90a34 | 2011-07-21 15:25:01 -0400 | [diff] [blame] | 197 | |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 198 | if (buffer->idx + 1 == end) |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 199 | decompose_single_char_cluster (font, buffer, recompose); |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 200 | else { |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 201 | decompose_multi_char_cluster (font, buffer, end); |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 202 | has_multichar_clusters = TRUE; |
| 203 | } |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 204 | } |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 205 | buffer->swap_buffers (); |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 206 | |
Behdad Esfahbod | 34c22f8 | 2011-07-22 17:04:20 -0400 | [diff] [blame] | 207 | |
Behdad Esfahbod | 9683184 | 2012-04-07 14:57:21 -0400 | [diff] [blame] | 208 | if (mode != HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL && !has_multichar_clusters) |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 209 | return; /* Done! */ |
| 210 | |
Behdad Esfahbod | 34c22f8 | 2011-07-22 17:04:20 -0400 | [diff] [blame] | 211 | |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 212 | /* Second round, reorder (inplace) */ |
| 213 | |
Behdad Esfahbod | 34c22f8 | 2011-07-22 17:04:20 -0400 | [diff] [blame] | 214 | count = buffer->len; |
| 215 | for (unsigned int i = 0; i < count; i++) |
| 216 | { |
| 217 | if (buffer->info[i].combining_class() == 0) |
| 218 | continue; |
| 219 | |
| 220 | unsigned int end; |
| 221 | for (end = i + 1; end < count; end++) |
| 222 | if (buffer->info[end].combining_class() == 0) |
| 223 | break; |
| 224 | |
| 225 | /* We are going to do a bubble-sort. Only do this if the |
| 226 | * sequence is short. Doing it on long sequences can result |
| 227 | * in an O(n^2) DoS. */ |
| 228 | if (end - i > 10) { |
| 229 | i = end; |
| 230 | continue; |
| 231 | } |
| 232 | |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 233 | hb_bubble_sort (buffer->info + i, end - i, compare_combining_class); |
Behdad Esfahbod | 34c22f8 | 2011-07-22 17:04:20 -0400 | [diff] [blame] | 234 | |
| 235 | i = end; |
| 236 | } |
| 237 | |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 238 | |
Behdad Esfahbod | 5389ff4 | 2011-07-22 20:22:49 -0400 | [diff] [blame] | 239 | if (!recompose) |
| 240 | return; |
| 241 | |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 242 | /* Third round, recompose */ |
Behdad Esfahbod | 34c22f8 | 2011-07-22 17:04:20 -0400 | [diff] [blame] | 243 | |
Behdad Esfahbod | 5389ff4 | 2011-07-22 20:22:49 -0400 | [diff] [blame] | 244 | /* As noted in the comment earlier, we don't try to combine |
| 245 | * ccc=0 chars with their previous Starter. */ |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 246 | |
Behdad Esfahbod | 5389ff4 | 2011-07-22 20:22:49 -0400 | [diff] [blame] | 247 | buffer->clear_output (); |
| 248 | count = buffer->len; |
| 249 | unsigned int starter = 0; |
| 250 | buffer->next_glyph (); |
| 251 | while (buffer->idx < count) |
| 252 | { |
Behdad Esfahbod | 5389ff4 | 2011-07-22 20:22:49 -0400 | [diff] [blame] | 253 | hb_codepoint_t composed, glyph; |
Behdad Esfahbod | 9683184 | 2012-04-07 14:57:21 -0400 | [diff] [blame] | 254 | if (/* If mode is NOT COMPOSED_FULL (ie. it's COMPOSED_DIACRITICS), we don't try to |
| 255 | * compose a CCC=0 character with it's preceding starter. */ |
| 256 | (mode == HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL || |
| 257 | buffer->info[buffer->idx].combining_class() != 0) && |
| 258 | /* If there's anything between the starter and this char, they should have CCC |
| 259 | * smaller than this character's. */ |
| 260 | (starter == buffer->out_len - 1 || |
Behdad Esfahbod | bec2ac4 | 2012-04-07 14:51:17 -0400 | [diff] [blame] | 261 | buffer->out_info[buffer->out_len - 1].combining_class() < buffer->info[buffer->idx].combining_class()) && |
Behdad Esfahbod | 9683184 | 2012-04-07 14:57:21 -0400 | [diff] [blame] | 262 | /* And compose. */ |
Behdad Esfahbod | e02d925 | 2012-04-07 14:49:13 -0400 | [diff] [blame] | 263 | hb_unicode_compose (buffer->unicode, |
| 264 | buffer->out_info[starter].codepoint, |
| 265 | buffer->info[buffer->idx].codepoint, |
| 266 | &composed) && |
Behdad Esfahbod | 9683184 | 2012-04-07 14:57:21 -0400 | [diff] [blame] | 267 | /* And the font has glyph for the composite. */ |
Behdad Esfahbod | e02d925 | 2012-04-07 14:49:13 -0400 | [diff] [blame] | 268 | hb_font_get_glyph (font, composed, 0, &glyph)) |
Behdad Esfahbod | 5389ff4 | 2011-07-22 20:22:49 -0400 | [diff] [blame] | 269 | { |
Behdad Esfahbod | e02d925 | 2012-04-07 14:49:13 -0400 | [diff] [blame] | 270 | /* Composes. Modify starter and carry on. */ |
| 271 | buffer->out_info[starter].codepoint = composed; |
Behdad Esfahbod | 29a7e30 | 2012-04-24 16:01:30 -0400 | [diff] [blame^] | 272 | /* XXX update cluster */ |
Behdad Esfahbod | 683b503 | 2012-04-14 20:47:14 -0400 | [diff] [blame] | 273 | set_unicode_props (&buffer->out_info[starter], buffer->unicode); |
Behdad Esfahbod | e02d925 | 2012-04-07 14:49:13 -0400 | [diff] [blame] | 274 | |
| 275 | buffer->skip_glyph (); |
Behdad Esfahbod | 5389ff4 | 2011-07-22 20:22:49 -0400 | [diff] [blame] | 276 | continue; |
| 277 | } |
| 278 | |
Behdad Esfahbod | e02d925 | 2012-04-07 14:49:13 -0400 | [diff] [blame] | 279 | /* Blocked, or doesn't compose. */ |
| 280 | buffer->next_glyph (); |
Behdad Esfahbod | 9683184 | 2012-04-07 14:57:21 -0400 | [diff] [blame] | 281 | |
| 282 | if (buffer->out_info[buffer->out_len - 1].combining_class() == 0) |
| 283 | starter = buffer->out_len - 1; |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 284 | } |
Behdad Esfahbod | 5389ff4 | 2011-07-22 20:22:49 -0400 | [diff] [blame] | 285 | buffer->swap_buffers (); |
Behdad Esfahbod | 34c22f8 | 2011-07-22 17:04:20 -0400 | [diff] [blame] | 286 | |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 287 | } |