diff --git a/src/gen-vowel-constraints.py b/src/gen-vowel-constraints.py index 55a9ecf86..2e9b50bad 100755 --- a/src/gen-vowel-constraints.py +++ b/src/gen-vowel-constraints.py @@ -171,8 +171,8 @@ print () print ('static void') print ('_output_dotted_circle (hb_buffer_t *buffer)') print ('{') -print (' hb_glyph_info_t &dottedcircle = buffer->output_glyph (0x25CCu);') -print (' _hb_glyph_info_reset_continuation (&dottedcircle);') +print (' (void) buffer->output_glyph (0x25CCu);') +print (' _hb_glyph_info_reset_continuation (&buffer->prev());') print ('}') print () print ('static void') diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index b9fabe2b1..e3bc268d2 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -738,8 +738,7 @@ struct InsertionSubtable if (buffer->idx < buffer->len && !before) if (unlikely (!buffer->copy_glyph ())) return; /* TODO We ignore KashidaLike setting. */ - for (unsigned int i = 0; i < count; i++) - buffer->output_glyph (glyphs[i]); + if (unlikely (!buffer->replace_glyphs (0, count, glyphs))) return; if (buffer->idx < buffer->len && !before) buffer->skip_glyph (); @@ -766,8 +765,7 @@ struct InsertionSubtable if (buffer->idx < buffer->len && !before) if (unlikely (!buffer->copy_glyph ())) return; /* TODO We ignore KashidaLike setting. */ - for (unsigned int i = 0; i < count; i++) - buffer->output_glyph (glyphs[i]); + if (unlikely (!buffer->replace_glyphs (0, count, glyphs))) return; if (buffer->idx < buffer->len && !before) buffer->skip_glyph (); diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 494bf395e..8cad6ab8e 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -342,33 +342,6 @@ hb_buffer_t::swap_buffers () idx = 0; } - -bool -hb_buffer_t::replace_glyphs (unsigned int num_in, - unsigned int num_out, - const uint32_t *glyph_data) -{ - if (unlikely (!make_room_for (num_in, num_out))) return false; - - assert (idx + num_in <= len); - - merge_clusters (idx, idx + num_in); - - hb_glyph_info_t orig_info = info[idx]; - hb_glyph_info_t *pinfo = &out_info[out_len]; - for (unsigned int i = 0; i < num_out; i++) - { - *pinfo = orig_info; - pinfo->codepoint = glyph_data[i]; - pinfo++; - } - - idx += num_in; - out_len += num_out; - - return true; -} - bool hb_buffer_t::move_to (unsigned int i) { diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index 97c5a0279..c457e7392 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -210,10 +210,31 @@ struct hb_buffer_t HB_INTERNAL void clear_output (); HB_INTERNAL void clear_positions (); - HB_INTERNAL HB_NODISCARD - bool replace_glyphs (unsigned int num_in, - unsigned int num_out, - const hb_codepoint_t *glyph_data); + template + HB_NODISCARD bool replace_glyphs (unsigned int num_in, + unsigned int num_out, + const T *glyph_data) + { + if (unlikely (!make_room_for (num_in, num_out))) return false; + + assert (idx + num_in <= len); + + merge_clusters (idx, idx + num_in); + + hb_glyph_info_t &orig_info = idx < len ? cur() : prev(); + + hb_glyph_info_t *pinfo = &out_info[out_len]; + for (unsigned int i = 0; i < num_out; i++) + { + *pinfo = orig_info; + pinfo->codepoint = glyph_data[i]; + pinfo++; + } + + idx += num_in; + out_len += num_out; + return true; + } HB_NODISCARD bool replace_glyph (hb_codepoint_t glyph_index) { @@ -229,18 +250,15 @@ struct hb_buffer_t return true; } /* Makes a copy of the glyph at idx to output and replace glyph_index */ - hb_glyph_info_t & output_glyph (hb_codepoint_t glyph_index) + HB_NODISCARD bool output_glyph (hb_codepoint_t glyph_index) { - if (unlikely (!make_room_for (0, 1))) return Crap (hb_glyph_info_t); + if (unlikely (!make_room_for (0, 1))) return false; - if (unlikely (idx == len && !out_len)) - return Crap (hb_glyph_info_t); - - out_info[out_len] = idx < len ? info[idx] : out_info[out_len - 1]; + out_info[out_len] = idx < len ? cur() : prev(); out_info[out_len].codepoint = glyph_index; out_len++; - return out_info[out_len - 1]; + return true; } HB_NODISCARD bool output_info (const hb_glyph_info_t &glyph_info) { diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index bfc58624f..b93b73c04 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -676,7 +676,7 @@ struct hb_ot_apply_context_t : unsigned int class_guess) const { _set_glyph_props (glyph_index, class_guess, false, true); - buffer->output_glyph (glyph_index); + (void) buffer->output_glyph (glyph_index); } }; diff --git a/src/hb-ot-shape-complex-thai.cc b/src/hb-ot-shape-complex-thai.cc index 9159c9f36..925e28d3b 100644 --- a/src/hb-ot-shape-complex-thai.cc +++ b/src/hb-ot-shape-complex-thai.cc @@ -332,10 +332,9 @@ preprocess_text_thai (const hb_ot_shape_plan_t *plan, } /* Is SARA AM. Decompose and reorder. */ - hb_glyph_info_t &nikhahit = buffer->output_glyph (NIKHAHIT_FROM_SARA_AM (u)); - _hb_glyph_info_set_continuation (&nikhahit); - if (unlikely (!buffer->replace_glyph (SARA_AA_FROM_SARA_AM (u)))) - break; + if (unlikely (!buffer->output_glyph (NIKHAHIT_FROM_SARA_AM (u)))) break; + _hb_glyph_info_set_continuation (&buffer->prev()); + if (unlikely (!buffer->replace_glyph (SARA_AA_FROM_SARA_AM (u)))) break; /* Make Nikhahit be recognized as a ccc=0 mark when zeroing widths. */ unsigned int end = buffer->out_len; diff --git a/src/hb-ot-shape-complex-vowel-constraints.cc b/src/hb-ot-shape-complex-vowel-constraints.cc index 124716eb6..2c61e976f 100644 --- a/src/hb-ot-shape-complex-vowel-constraints.cc +++ b/src/hb-ot-shape-complex-vowel-constraints.cc @@ -23,8 +23,8 @@ static void _output_dotted_circle (hb_buffer_t *buffer) { - hb_glyph_info_t &dottedcircle = buffer->output_glyph (0x25CCu); - _hb_glyph_info_reset_continuation (&dottedcircle); + (void) buffer->output_glyph (0x25CCu); + _hb_glyph_info_reset_continuation (&buffer->prev()); } static void diff --git a/src/hb-ot-shape-normalize.cc b/src/hb-ot-shape-normalize.cc index bce9dcf5d..8ad2d771a 100644 --- a/src/hb-ot-shape-normalize.cc +++ b/src/hb-ot-shape-normalize.cc @@ -101,8 +101,9 @@ set_glyph (hb_glyph_info_t &info, hb_font_t *font) static inline void output_char (hb_buffer_t *buffer, hb_codepoint_t unichar, hb_codepoint_t glyph) { + /* This is very confusing indeed. */ buffer->cur().glyph_index() = glyph; - buffer->output_glyph (unichar); /* This is very confusing indeed. */ + (void) buffer->output_glyph (unichar); _hb_glyph_info_set_unicode_props (&buffer->prev(), buffer); }