equal
deleted
inserted
replaced
109 /* Internal API */ |
109 /* Internal API */ |
110 |
110 |
111 bool |
111 bool |
112 hb_buffer_t::enlarge (unsigned int size) |
112 hb_buffer_t::enlarge (unsigned int size) |
113 { |
113 { |
114 if (unlikely (in_error)) |
114 if (unlikely (!successful)) |
115 return false; |
115 return false; |
116 if (unlikely (size > max_len)) |
116 if (unlikely (size > max_len)) |
117 { |
117 { |
118 in_error = true; |
118 successful = false; |
119 return false; |
119 return false; |
120 } |
120 } |
121 |
121 |
122 unsigned int new_allocated = allocated; |
122 unsigned int new_allocated = allocated; |
123 hb_glyph_position_t *new_pos = nullptr; |
123 hb_glyph_position_t *new_pos = nullptr; |
137 new_pos = (hb_glyph_position_t *) realloc (pos, new_allocated * sizeof (pos[0])); |
137 new_pos = (hb_glyph_position_t *) realloc (pos, new_allocated * sizeof (pos[0])); |
138 new_info = (hb_glyph_info_t *) realloc (info, new_allocated * sizeof (info[0])); |
138 new_info = (hb_glyph_info_t *) realloc (info, new_allocated * sizeof (info[0])); |
139 |
139 |
140 done: |
140 done: |
141 if (unlikely (!new_pos || !new_info)) |
141 if (unlikely (!new_pos || !new_info)) |
142 in_error = true; |
142 successful = false; |
143 |
143 |
144 if (likely (new_pos)) |
144 if (likely (new_pos)) |
145 pos = new_pos; |
145 pos = new_pos; |
146 |
146 |
147 if (likely (new_info)) |
147 if (likely (new_info)) |
148 info = new_info; |
148 info = new_info; |
149 |
149 |
150 out_info = separate_out ? (hb_glyph_info_t *) pos : info; |
150 out_info = separate_out ? (hb_glyph_info_t *) pos : info; |
151 if (likely (!in_error)) |
151 if (likely (successful)) |
152 allocated = new_allocated; |
152 allocated = new_allocated; |
153 |
153 |
154 return likely (!in_error); |
154 return likely (successful); |
155 } |
155 } |
156 |
156 |
157 bool |
157 bool |
158 hb_buffer_t::make_room_for (unsigned int num_in, |
158 hb_buffer_t::make_room_for (unsigned int num_in, |
159 unsigned int num_out) |
159 unsigned int num_out) |
232 hb_segment_properties_t default_props = HB_SEGMENT_PROPERTIES_DEFAULT; |
232 hb_segment_properties_t default_props = HB_SEGMENT_PROPERTIES_DEFAULT; |
233 props = default_props; |
233 props = default_props; |
234 scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; |
234 scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; |
235 |
235 |
236 content_type = HB_BUFFER_CONTENT_TYPE_INVALID; |
236 content_type = HB_BUFFER_CONTENT_TYPE_INVALID; |
237 in_error = false; |
237 successful = true; |
238 have_output = false; |
238 have_output = false; |
239 have_positions = false; |
239 have_positions = false; |
240 |
240 |
241 idx = 0; |
241 idx = 0; |
242 len = 0; |
242 len = 0; |
322 } |
322 } |
323 |
323 |
324 void |
324 void |
325 hb_buffer_t::swap_buffers (void) |
325 hb_buffer_t::swap_buffers (void) |
326 { |
326 { |
327 if (unlikely (in_error)) return; |
327 if (unlikely (!successful)) return; |
328 |
328 |
329 assert (have_output); |
329 assert (have_output); |
330 have_output = false; |
330 have_output = false; |
331 |
331 |
332 if (out_info != info) |
332 if (out_info != info) |
407 { |
407 { |
408 assert (i <= len); |
408 assert (i <= len); |
409 idx = i; |
409 idx = i; |
410 return true; |
410 return true; |
411 } |
411 } |
412 if (unlikely (in_error)) |
412 if (unlikely (!successful)) |
413 return false; |
413 return false; |
414 |
414 |
415 assert (i <= out_len + (len - idx)); |
415 assert (i <= out_len + (len - idx)); |
416 |
416 |
417 if (out_len < i) |
417 if (out_len < i) |
685 } |
685 } |
686 |
686 |
687 /* If direction is set to INVALID, guess from script */ |
687 /* If direction is set to INVALID, guess from script */ |
688 if (props.direction == HB_DIRECTION_INVALID) { |
688 if (props.direction == HB_DIRECTION_INVALID) { |
689 props.direction = hb_script_get_horizontal_direction (props.script); |
689 props.direction = hb_script_get_horizontal_direction (props.script); |
|
690 if (props.direction == HB_DIRECTION_INVALID) |
|
691 props.direction = HB_DIRECTION_LTR; |
690 } |
692 } |
691 |
693 |
692 /* If language is not set, use default language from locale */ |
694 /* If language is not set, use default language from locale */ |
693 if (props.language == HB_LANGUAGE_INVALID) { |
695 if (props.language == HB_LANGUAGE_INVALID) { |
694 /* TODO get_default_for_script? using $LANGUAGE */ |
696 /* TODO get_default_for_script? using $LANGUAGE */ |
752 HB_BUFFER_MAX_LEN_DEFAULT, |
754 HB_BUFFER_MAX_LEN_DEFAULT, |
753 HB_BUFFER_MAX_OPS_DEFAULT, |
755 HB_BUFFER_MAX_OPS_DEFAULT, |
754 |
756 |
755 HB_BUFFER_CONTENT_TYPE_INVALID, |
757 HB_BUFFER_CONTENT_TYPE_INVALID, |
756 HB_SEGMENT_PROPERTIES_DEFAULT, |
758 HB_SEGMENT_PROPERTIES_DEFAULT, |
757 true, /* in_error */ |
759 false, /* successful */ |
758 true, /* have_output */ |
760 true, /* have_output */ |
759 true /* have_positions */ |
761 true /* have_positions */ |
760 |
762 |
761 /* Zero is good enough for everything else. */ |
763 /* Zero is good enough for everything else. */ |
762 }; |
764 }; |
1267 * Since: 0.9.2 |
1269 * Since: 0.9.2 |
1268 **/ |
1270 **/ |
1269 hb_bool_t |
1271 hb_bool_t |
1270 hb_buffer_allocation_successful (hb_buffer_t *buffer) |
1272 hb_buffer_allocation_successful (hb_buffer_t *buffer) |
1271 { |
1273 { |
1272 return !buffer->in_error; |
1274 return buffer->successful; |
1273 } |
1275 } |
1274 |
1276 |
1275 /** |
1277 /** |
1276 * hb_buffer_add: |
1278 * hb_buffer_add: |
1277 * @buffer: an #hb_buffer_t. |
1279 * @buffer: an #hb_buffer_t. |
1487 * %HB_SCRIPT_INHERITED, and %HB_SCRIPT_UNKNOWN. |
1489 * %HB_SCRIPT_INHERITED, and %HB_SCRIPT_UNKNOWN. |
1488 * |
1490 * |
1489 * Next, if buffer direction is not set (ie. is %HB_DIRECTION_INVALID), |
1491 * Next, if buffer direction is not set (ie. is %HB_DIRECTION_INVALID), |
1490 * it will be set to the natural horizontal direction of the |
1492 * it will be set to the natural horizontal direction of the |
1491 * buffer script as returned by hb_script_get_horizontal_direction(). |
1493 * buffer script as returned by hb_script_get_horizontal_direction(). |
|
1494 * If hb_script_get_horizontal_direction() returns %HB_DIRECTION_INVALID, |
|
1495 * then %HB_DIRECTION_LTR is used. |
1492 * |
1496 * |
1493 * Finally, if buffer language is not set (ie. is %HB_LANGUAGE_INVALID), |
1497 * Finally, if buffer language is not set (ie. is %HB_LANGUAGE_INVALID), |
1494 * it will be set to the process's default language as returned by |
1498 * it will be set to the process's default language as returned by |
1495 * hb_language_get_default(). This may change in the future by |
1499 * hb_language_get_default(). This may change in the future by |
1496 * taking buffer script into consideration when choosing a language. |
1500 * taking buffer script into consideration when choosing a language. |
1748 if (!buffer->have_positions && source->have_positions) |
1752 if (!buffer->have_positions && source->have_positions) |
1749 buffer->clear_positions (); |
1753 buffer->clear_positions (); |
1750 |
1754 |
1751 if (buffer->len + (end - start) < buffer->len) /* Overflows. */ |
1755 if (buffer->len + (end - start) < buffer->len) /* Overflows. */ |
1752 { |
1756 { |
1753 buffer->in_error = true; |
1757 buffer->successful = false; |
1754 return; |
1758 return; |
1755 } |
1759 } |
1756 |
1760 |
1757 unsigned int orig_len = buffer->len; |
1761 unsigned int orig_len = buffer->len; |
1758 hb_buffer_set_length (buffer, buffer->len + (end - start)); |
1762 hb_buffer_set_length (buffer, buffer->len + (end - start)); |
1759 if (buffer->in_error) |
1763 if (unlikely (!buffer->successful)) |
1760 return; |
1764 return; |
1761 |
1765 |
1762 memcpy (buffer->info + orig_len, source->info + start, (end - start) * sizeof (buffer->info[0])); |
1766 memcpy (buffer->info + orig_len, source->info + start, (end - start) * sizeof (buffer->info[0])); |
1763 if (buffer->have_positions) |
1767 if (buffer->have_positions) |
1764 memcpy (buffer->pos + orig_len, source->pos + start, (end - start) * sizeof (buffer->pos[0])); |
1768 memcpy (buffer->pos + orig_len, source->pos + start, (end - start) * sizeof (buffer->pos[0])); |