[buffer] HB_NODISCARD output_glyph()

Also, generalize and use replace_glyphs() in morx where output_glyph() was used
in a loop.
This commit is contained in:
Behdad Esfahbod 2021-03-15 14:39:06 -06:00
parent e6be9eb4fb
commit 34a1204f10
8 changed files with 41 additions and 52 deletions

View File

@ -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')

View File

@ -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 ();

View File

@ -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)
{

View File

@ -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 <typename T>
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)
{

View File

@ -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);
}
};

View File

@ -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;

View File

@ -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

View File

@ -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);
}