Behdad Esfahbod | a2a9a02 | 2008-01-15 22:46:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1998-2004 David Turner and Werner Lemberg |
| 3 | * Copyright (C) 2004,2007 Red Hat, Inc. |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 4 | * |
Behdad Esfahbod | a2a9a02 | 2008-01-15 22:46:32 +0000 | [diff] [blame] | 5 | * This is part of HarfBuzz, an OpenType Layout engine library. |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 6 | * |
Behdad Esfahbod | a2a9a02 | 2008-01-15 22:46:32 +0000 | [diff] [blame] | 7 | * Permission is hereby granted, without written agreement and without |
| 8 | * license or royalty fees, to use, copy, modify, and distribute this |
| 9 | * software and its documentation for any purpose, provided that the |
| 10 | * above copyright notice and the following two paragraphs appear in |
| 11 | * all copies of this software. |
| 12 | * |
| 13 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 14 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 16 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 17 | * DAMAGE. |
| 18 | * |
| 19 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 20 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 22 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 23 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 24 | * |
| 25 | * Red Hat Author(s): Owen Taylor, Behdad Esfahbod |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
Behdad Esfahbod | 5c0adce | 2009-05-20 05:42:12 -0400 | [diff] [blame] | 28 | #include "hb-buffer-private.h" |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 29 | |
Behdad Esfahbod | 88a5f5a | 2009-05-25 03:39:11 -0400 | [diff] [blame] | 30 | #include <string.h> |
| 31 | |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 32 | |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 33 | static hb_buffer_t _hb_buffer_nil = { |
| 34 | HB_REFERENCE_COUNT_INVALID /* ref_count */ |
| 35 | }; |
| 36 | |
Behdad Esfahbod | a8abb8b | 2007-10-11 00:07:58 +0000 | [diff] [blame] | 37 | /* Here is how the buffer works internally: |
| 38 | * |
| 39 | * There are two string pointers: in_string and out_string. They |
| 40 | * always have same allocated size, but different length and positions. |
| 41 | * |
| 42 | * As an optimization, both in_string and out_string may point to the |
| 43 | * same piece of memory, which is owned by in_string. This remains the |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 44 | * case as long as out_length doesn't exceed in_length at any time. |
| 45 | * In that case, swap() is no-op and the glyph operations operate mostly |
| 46 | * in-place. |
Behdad Esfahbod | a8abb8b | 2007-10-11 00:07:58 +0000 | [diff] [blame] | 47 | * |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 48 | * As soon as out_string gets longer than in_string, out_string is moved over |
Behdad Esfahbod | cbe5a4e | 2009-08-10 20:24:49 -0400 | [diff] [blame] | 49 | * to an alternate buffer (which we reuse the positions buffer for!), and its |
| 50 | * current contents (out_length entries) are copied to the alt buffer. |
| 51 | * This should all remain transparent to the user. swap() then switches |
| 52 | * in_string and out_string. |
Behdad Esfahbod | a8abb8b | 2007-10-11 00:07:58 +0000 | [diff] [blame] | 53 | */ |
| 54 | |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 55 | /* XXX err handling */ |
| 56 | |
Behdad Esfahbod | 6b34713 | 2007-10-11 08:30:50 +0000 | [diff] [blame] | 57 | /* Internal API */ |
| 58 | |
Behdad Esfahbod | 88a5f5a | 2009-05-25 03:39:11 -0400 | [diff] [blame] | 59 | static void |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 60 | hb_buffer_ensure_separate (hb_buffer_t *buffer, unsigned int size) |
| 61 | { |
| 62 | hb_buffer_ensure (buffer, size); |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 63 | if (buffer->out_string == buffer->in_string) |
| 64 | { |
Behdad Esfahbod | cbe5a4e | 2009-08-10 20:24:49 -0400 | [diff] [blame] | 65 | if (!buffer->positions) |
| 66 | buffer->positions = calloc (buffer->allocated, sizeof (buffer->positions[0])); |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 67 | |
Behdad Esfahbod | fbaf8ff | 2009-08-10 20:59:25 -0400 | [diff] [blame] | 68 | buffer->out_string = (hb_internal_glyph_info_t *) buffer->positions; |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 69 | memcpy (buffer->out_string, buffer->in_string, buffer->out_length * sizeof (buffer->out_string[0])); |
| 70 | } |
Behdad Esfahbod | a8abb8b | 2007-10-11 00:07:58 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Behdad Esfahbod | 6b34713 | 2007-10-11 08:30:50 +0000 | [diff] [blame] | 73 | /* Public API */ |
| 74 | |
Behdad Esfahbod | b857b49 | 2009-05-20 05:35:14 -0400 | [diff] [blame] | 75 | hb_buffer_t * |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 76 | hb_buffer_create (unsigned int pre_alloc_size) |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 77 | { |
Behdad Esfahbod | b857b49 | 2009-05-20 05:35:14 -0400 | [diff] [blame] | 78 | hb_buffer_t *buffer; |
| 79 | |
Behdad Esfahbod | 5fc22e6 | 2009-08-03 22:43:02 -0400 | [diff] [blame] | 80 | if (!HB_OBJECT_DO_CREATE (hb_buffer_t, buffer)) |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 81 | return &_hb_buffer_nil; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 82 | |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 83 | if (pre_alloc_size) |
| 84 | hb_buffer_ensure(buffer, pre_alloc_size); |
Behdad Esfahbod | f9cd101 | 2009-07-28 15:43:34 -0400 | [diff] [blame] | 85 | |
Behdad Esfahbod | b857b49 | 2009-05-20 05:35:14 -0400 | [diff] [blame] | 86 | return buffer; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 89 | hb_buffer_t * |
| 90 | hb_buffer_reference (hb_buffer_t *buffer) |
Behdad Esfahbod | 7a26864 | 2007-10-11 07:21:31 +0000 | [diff] [blame] | 91 | { |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 92 | HB_OBJECT_DO_REFERENCE (buffer); |
| 93 | } |
| 94 | |
| 95 | unsigned int |
| 96 | hb_buffer_get_reference_count (hb_buffer_t *buffer) |
| 97 | { |
| 98 | HB_OBJECT_DO_GET_REFERENCE_COUNT (buffer); |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | hb_buffer_destroy (hb_buffer_t *buffer) |
| 103 | { |
| 104 | HB_OBJECT_DO_DESTROY (buffer); |
| 105 | |
Behdad Esfahbod | b857b49 | 2009-05-20 05:35:14 -0400 | [diff] [blame] | 106 | free (buffer->in_string); |
Behdad Esfahbod | b857b49 | 2009-05-20 05:35:14 -0400 | [diff] [blame] | 107 | free (buffer->positions); |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 108 | |
Behdad Esfahbod | b857b49 | 2009-05-20 05:35:14 -0400 | [diff] [blame] | 109 | free (buffer); |
Behdad Esfahbod | 7a26864 | 2007-10-11 07:21:31 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | void |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 113 | hb_buffer_clear (hb_buffer_t *buffer) |
Behdad Esfahbod | 7a26864 | 2007-10-11 07:21:31 +0000 | [diff] [blame] | 114 | { |
| 115 | buffer->in_length = 0; |
| 116 | buffer->out_length = 0; |
| 117 | buffer->in_pos = 0; |
| 118 | buffer->out_pos = 0; |
| 119 | buffer->out_string = buffer->in_string; |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 120 | buffer->max_lig_id = 0; |
Behdad Esfahbod | 7a26864 | 2007-10-11 07:21:31 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Behdad Esfahbod | b857b49 | 2009-05-20 05:35:14 -0400 | [diff] [blame] | 123 | void |
Behdad Esfahbod | f9cd101 | 2009-07-28 15:43:34 -0400 | [diff] [blame] | 124 | hb_buffer_ensure (hb_buffer_t *buffer, unsigned int size) |
| 125 | { |
| 126 | unsigned int new_allocated = buffer->allocated; |
| 127 | |
| 128 | if (size > new_allocated) |
| 129 | { |
| 130 | while (size > new_allocated) |
| 131 | new_allocated += (new_allocated >> 1) + 8; |
| 132 | |
| 133 | if (buffer->positions) |
| 134 | buffer->positions = realloc (buffer->positions, new_allocated * sizeof (buffer->positions[0])); |
| 135 | |
| 136 | if (buffer->out_string != buffer->in_string) |
| 137 | { |
| 138 | buffer->in_string = realloc (buffer->in_string, new_allocated * sizeof (buffer->in_string[0])); |
Behdad Esfahbod | fbaf8ff | 2009-08-10 20:59:25 -0400 | [diff] [blame] | 139 | buffer->out_string = (hb_internal_glyph_info_t *) buffer->positions; |
Behdad Esfahbod | f9cd101 | 2009-07-28 15:43:34 -0400 | [diff] [blame] | 140 | } |
| 141 | else |
| 142 | { |
| 143 | buffer->in_string = realloc (buffer->in_string, new_allocated * sizeof (buffer->in_string[0])); |
| 144 | buffer->out_string = buffer->in_string; |
Behdad Esfahbod | f9cd101 | 2009-07-28 15:43:34 -0400 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | buffer->allocated = new_allocated; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | void |
Behdad Esfahbod | 3015c41 | 2009-05-20 06:01:16 -0400 | [diff] [blame] | 152 | hb_buffer_add_glyph (hb_buffer_t *buffer, |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 153 | hb_codepoint_t codepoint, |
Behdad Esfahbod | 468769b | 2009-08-08 16:53:23 -0400 | [diff] [blame] | 154 | hb_mask_t mask, |
Behdad Esfahbod | 3015c41 | 2009-05-20 06:01:16 -0400 | [diff] [blame] | 155 | unsigned int cluster) |
Behdad Esfahbod | 6b34713 | 2007-10-11 08:30:50 +0000 | [diff] [blame] | 156 | { |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 157 | hb_internal_glyph_info_t *glyph; |
Behdad Esfahbod | 5c0adce | 2009-05-20 05:42:12 -0400 | [diff] [blame] | 158 | |
Behdad Esfahbod | b857b49 | 2009-05-20 05:35:14 -0400 | [diff] [blame] | 159 | hb_buffer_ensure (buffer, buffer->in_length + 1); |
Behdad Esfahbod | 6b34713 | 2007-10-11 08:30:50 +0000 | [diff] [blame] | 160 | |
| 161 | glyph = &buffer->in_string[buffer->in_length]; |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 162 | glyph->codepoint = codepoint; |
Behdad Esfahbod | 468769b | 2009-08-08 16:53:23 -0400 | [diff] [blame] | 163 | glyph->mask = mask; |
Behdad Esfahbod | 6b34713 | 2007-10-11 08:30:50 +0000 | [diff] [blame] | 164 | glyph->cluster = cluster; |
| 165 | glyph->component = 0; |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 166 | glyph->lig_id = 0; |
| 167 | glyph->gproperty = HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN; |
Behdad Esfahbod | 6b34713 | 2007-10-11 08:30:50 +0000 | [diff] [blame] | 168 | |
Behdad Esfahbod | b857b49 | 2009-05-20 05:35:14 -0400 | [diff] [blame] | 169 | buffer->in_length++; |
Behdad Esfahbod | 6b34713 | 2007-10-11 08:30:50 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Behdad Esfahbod | 02a3706 | 2009-07-29 18:41:25 -0400 | [diff] [blame] | 172 | void |
| 173 | hb_buffer_set_direction (hb_buffer_t *buffer, |
| 174 | hb_direction_t direction) |
| 175 | |
| 176 | { |
| 177 | buffer->direction = direction; |
| 178 | } |
| 179 | |
| 180 | |
Behdad Esfahbod | 6b34713 | 2007-10-11 08:30:50 +0000 | [diff] [blame] | 181 | /* HarfBuzz-Internal API */ |
| 182 | |
| 183 | HB_INTERNAL void |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 184 | _hb_buffer_clear_output (hb_buffer_t *buffer) |
Behdad Esfahbod | 7a26864 | 2007-10-11 07:21:31 +0000 | [diff] [blame] | 185 | { |
| 186 | buffer->out_length = 0; |
| 187 | buffer->out_pos = 0; |
| 188 | buffer->out_string = buffer->in_string; |
Behdad Esfahbod | 7a26864 | 2007-10-11 07:21:31 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 191 | void |
| 192 | hb_buffer_clear_positions (hb_buffer_t *buffer) |
Behdad Esfahbod | 0600390 | 2007-10-11 07:05:09 +0000 | [diff] [blame] | 193 | { |
Behdad Esfahbod | 15c3e75 | 2009-05-17 06:03:42 -0400 | [diff] [blame] | 194 | _hb_buffer_clear_output (buffer); |
| 195 | |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 196 | if (HB_UNLIKELY (!buffer->positions)) |
| 197 | { |
| 198 | buffer->positions = calloc (buffer->allocated, sizeof (buffer->positions[0])); |
| 199 | return; |
| 200 | } |
Behdad Esfahbod | 0600390 | 2007-10-11 07:05:09 +0000 | [diff] [blame] | 201 | |
| 202 | memset (buffer->positions, 0, sizeof (buffer->positions[0]) * buffer->in_length); |
Behdad Esfahbod | 0600390 | 2007-10-11 07:05:09 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Behdad Esfahbod | 6b34713 | 2007-10-11 08:30:50 +0000 | [diff] [blame] | 205 | HB_INTERNAL void |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 206 | _hb_buffer_swap (hb_buffer_t *buffer) |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 207 | { |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 208 | unsigned int tmp; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 209 | |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 210 | if (buffer->out_string != buffer->in_string) |
| 211 | { |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 212 | hb_internal_glyph_info_t *tmp_string; |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 213 | tmp_string = buffer->in_string; |
| 214 | buffer->in_string = buffer->out_string; |
Behdad Esfahbod | fbaf8ff | 2009-08-10 20:59:25 -0400 | [diff] [blame] | 215 | buffer->out_string = tmp_string; |
| 216 | buffer->positions = (hb_internal_glyph_position_t *) buffer->out_string; |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 217 | } |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 218 | |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 219 | tmp = buffer->in_length; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 220 | buffer->in_length = buffer->out_length; |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 221 | buffer->out_length = tmp; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 222 | |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 223 | tmp = buffer->in_pos; |
Behdad Esfahbod | a8abb8b | 2007-10-11 00:07:58 +0000 | [diff] [blame] | 224 | buffer->in_pos = buffer->out_pos; |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 225 | buffer->out_pos = tmp; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 228 | /* The following function copies `num_out' elements from `glyph_data' |
| 229 | to `buffer->out_string', advancing the in array pointer in the structure |
| 230 | by `num_in' elements, and the out array pointer by `num_out' elements. |
| 231 | Finally, it sets the `length' field of `out' equal to |
| 232 | `pos' of the `out' structure. |
| 233 | |
| 234 | If `component' is 0xFFFF, the component value from buffer->in_pos |
| 235 | will copied `num_out' times, otherwise `component' itself will |
| 236 | be used to fill the `component' fields. |
| 237 | |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 238 | If `lig_id' is 0xFFFF, the lig_id value from buffer->in_pos |
| 239 | will copied `num_out' times, otherwise `lig_id' itself will |
| 240 | be used to fill the `lig_id' fields. |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 241 | |
Behdad Esfahbod | 468769b | 2009-08-08 16:53:23 -0400 | [diff] [blame] | 242 | The mask for all replacement glyphs are taken |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 243 | from the glyph at position `buffer->in_pos'. |
| 244 | |
| 245 | The cluster value for the glyph at position buffer->in_pos is used |
| 246 | for all replacement glyphs */ |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 247 | HB_INTERNAL void |
Behdad Esfahbod | 3015c41 | 2009-05-20 06:01:16 -0400 | [diff] [blame] | 248 | _hb_buffer_add_output_glyphs (hb_buffer_t *buffer, |
| 249 | unsigned int num_in, |
| 250 | unsigned int num_out, |
Behdad Esfahbod | 88a5f5a | 2009-05-25 03:39:11 -0400 | [diff] [blame] | 251 | const uint16_t *glyph_data_be, |
Behdad Esfahbod | 3015c41 | 2009-05-20 06:01:16 -0400 | [diff] [blame] | 252 | unsigned short component, |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 253 | unsigned short lig_id) |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 254 | { |
Behdad Esfahbod | 3015c41 | 2009-05-20 06:01:16 -0400 | [diff] [blame] | 255 | unsigned int i; |
Behdad Esfahbod | 468769b | 2009-08-08 16:53:23 -0400 | [diff] [blame] | 256 | unsigned int mask; |
Behdad Esfahbod | 3015c41 | 2009-05-20 06:01:16 -0400 | [diff] [blame] | 257 | unsigned int cluster; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 258 | |
Behdad Esfahbod | b196e6f | 2009-07-28 15:50:42 -0400 | [diff] [blame] | 259 | if (buffer->out_string != buffer->in_string || |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 260 | buffer->out_pos + num_out > buffer->in_pos + num_in) |
| 261 | { |
| 262 | hb_buffer_ensure_separate (buffer, buffer->out_pos + num_out); |
| 263 | } |
Behdad Esfahbod | a8abb8b | 2007-10-11 00:07:58 +0000 | [diff] [blame] | 264 | |
Behdad Esfahbod | 468769b | 2009-08-08 16:53:23 -0400 | [diff] [blame] | 265 | mask = buffer->in_string[buffer->in_pos].mask; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 266 | cluster = buffer->in_string[buffer->in_pos].cluster; |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 267 | if (component == 0xFFFF) |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 268 | component = buffer->in_string[buffer->in_pos].component; |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 269 | if (lig_id == 0xFFFF) |
| 270 | lig_id = buffer->in_string[buffer->in_pos].lig_id; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 271 | |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 272 | for (i = 0; i < num_out; i++) |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 273 | { |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 274 | hb_internal_glyph_info_t *info = &buffer->out_string[buffer->out_pos + i]; |
| 275 | info->codepoint = hb_be_uint16 (glyph_data_be[i]); |
Behdad Esfahbod | 468769b | 2009-08-08 16:53:23 -0400 | [diff] [blame] | 276 | info->mask = mask; |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 277 | info->cluster = cluster; |
| 278 | info->component = component; |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 279 | info->lig_id = lig_id; |
| 280 | info->gproperty = HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | buffer->in_pos += num_in; |
| 284 | buffer->out_pos += num_out; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 285 | buffer->out_length = buffer->out_pos; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Behdad Esfahbod | 88a5f5a | 2009-05-25 03:39:11 -0400 | [diff] [blame] | 288 | |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 289 | HB_INTERNAL void |
Behdad Esfahbod | 3015c41 | 2009-05-20 06:01:16 -0400 | [diff] [blame] | 290 | _hb_buffer_add_output_glyph (hb_buffer_t *buffer, |
| 291 | hb_codepoint_t glyph_index, |
| 292 | unsigned short component, |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 293 | unsigned short lig_id) |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 294 | { |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 295 | hb_internal_glyph_info_t *info; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 296 | |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 297 | if (buffer->out_string != buffer->in_string) |
| 298 | { |
| 299 | hb_buffer_ensure (buffer, buffer->out_pos + 1); |
| 300 | buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; |
| 301 | } |
| 302 | else if (buffer->out_pos != buffer->in_pos) |
| 303 | buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 304 | |
| 305 | info = &buffer->out_string[buffer->out_pos]; |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 306 | info->codepoint = glyph_index; |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 307 | if (component != 0xFFFF) |
| 308 | info->component = component; |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 309 | if (lig_id != 0xFFFF) |
| 310 | info->lig_id = lig_id; |
| 311 | info->gproperty = HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN; |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 312 | |
| 313 | buffer->in_pos++; |
| 314 | buffer->out_pos++; |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 315 | buffer->out_length = buffer->out_pos; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 318 | HB_INTERNAL void |
| 319 | _hb_buffer_next_glyph (hb_buffer_t *buffer) |
Behdad Esfahbod | 15c3e75 | 2009-05-17 06:03:42 -0400 | [diff] [blame] | 320 | { |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 321 | if (buffer->out_string != buffer->in_string) |
| 322 | { |
| 323 | hb_buffer_ensure (buffer, buffer->out_pos + 1); |
| 324 | buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; |
| 325 | } |
| 326 | else if (buffer->out_pos != buffer->in_pos) |
| 327 | buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; |
Behdad Esfahbod | a8abb8b | 2007-10-11 00:07:58 +0000 | [diff] [blame] | 328 | |
| 329 | buffer->in_pos++; |
| 330 | buffer->out_pos++; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 331 | buffer->out_length = buffer->out_pos; |
Behdad Esfahbod | a8abb8b | 2007-10-11 00:07:58 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 334 | HB_INTERNAL void |
Behdad Esfahbod | 3015c41 | 2009-05-20 06:01:16 -0400 | [diff] [blame] | 335 | _hb_buffer_replace_glyph (hb_buffer_t *buffer, |
| 336 | hb_codepoint_t glyph_index) |
Behdad Esfahbod | a8abb8b | 2007-10-11 00:07:58 +0000 | [diff] [blame] | 337 | { |
Behdad Esfahbod | e35bbd5 | 2009-05-30 12:02:46 -0400 | [diff] [blame] | 338 | _hb_buffer_add_output_glyph (buffer, glyph_index, 0xFFFF, 0xFFFF); |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Behdad Esfahbod | 3015c41 | 2009-05-20 06:01:16 -0400 | [diff] [blame] | 341 | HB_INTERNAL unsigned short |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 342 | _hb_buffer_allocate_lig_id (hb_buffer_t *buffer) |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 343 | { |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 344 | return ++buffer->max_lig_id; |
Behdad Esfahbod | 9f8da38 | 2006-03-31 12:28:09 +0000 | [diff] [blame] | 345 | } |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 346 | |
| 347 | |
| 348 | unsigned int |
| 349 | hb_buffer_get_len (hb_buffer_t *buffer) |
| 350 | { |
| 351 | return buffer->in_length; |
| 352 | } |
| 353 | |
| 354 | /* Return value valid as long as buffer not modified */ |
| 355 | hb_glyph_info_t * |
| 356 | hb_buffer_get_glyph_infos (hb_buffer_t *buffer) |
| 357 | { |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 358 | return (hb_glyph_info_t *) buffer->in_string; |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | /* Return value valid as long as buffer not modified */ |
| 362 | hb_glyph_position_t * |
| 363 | hb_buffer_get_glyph_positions (hb_buffer_t *buffer) |
| 364 | { |
| 365 | if (buffer->in_length && !buffer->positions) |
| 366 | hb_buffer_clear_positions (buffer); |
| 367 | |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 368 | return (hb_glyph_position_t *) buffer->positions; |
Behdad Esfahbod | 11fbb54 | 2009-08-01 22:19:06 -0400 | [diff] [blame] | 369 | } |
Behdad Esfahbod | fbaf8ff | 2009-08-10 20:59:25 -0400 | [diff] [blame] | 370 | |
| 371 | |
| 372 | void |
| 373 | hb_buffer_reverse (hb_buffer_t *buffer) |
| 374 | { |
| 375 | unsigned int i, j; |
| 376 | |
| 377 | for (i = 0, j = buffer->in_length - 1; i < buffer->in_length / 2; i++, j--) { |
| 378 | hb_internal_glyph_info_t t; |
| 379 | |
| 380 | t = buffer->in_string[i]; |
| 381 | buffer->in_string[i] = buffer->in_string[j]; |
| 382 | buffer->in_string[j] = t; |
| 383 | } |
| 384 | |
| 385 | if (buffer->positions) { |
| 386 | for (i = 0, j = buffer->in_length - 1; i < buffer->in_length / 2; i++, j--) { |
| 387 | hb_internal_glyph_position_t t; |
| 388 | |
| 389 | t = buffer->positions[i]; |
| 390 | buffer->positions[i] = buffer->positions[j]; |
| 391 | buffer->positions[j] = t; |
| 392 | } |
| 393 | } |
| 394 | } |