Use auxbuffer for serialize_unicode_text

This commit is contained in:
Simon Cozens 2020-09-18 09:27:27 +01:00 committed by Behdad Esfahbod
parent a0203a28bb
commit aff6a36266
1 changed files with 22 additions and 17 deletions

View File

@ -334,21 +334,26 @@ _hb_buffer_serialize_unicode_text (hb_buffer_t *buffer,
{
hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, nullptr);
*buf_consumed = 0;
char *p = buf;
/* We can use a much simpler implementation for this and copy text
* directly into the output buffer. */
for (unsigned int i = start; i < end; i++)
{
if (i) {
*p++ = '|';
}
char b[1024];
char *p = b;
p += hb_max (0, snprintf (p, buf_size - *buf_consumed, "U+%X", info[i].codepoint));
*buf_consumed = p - buf;
if (*buf_consumed > buf_size)
if (i)
*p++ = '|';
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "U+%04X", info[i].codepoint));
unsigned int l = p - b;
if (buf_size > l)
{
memcpy (buf, b, l);
buf += l;
buf_size -= l;
*buf_consumed += l;
*buf = '\0';
} else
return i - start;
}
*p = '\0';
return end - start;
}