[buffer] In hb_buffer_get_positions(), return NULL if inside message callback
As discussed in https://github.com/harfbuzz/harfbuzz/issues/2468#issuecomment-645666066 Part of fixing https://github.com/harfbuzz/harfbuzz/issues/2468
This commit is contained in:
parent
855a3f478e
commit
c61ce962cf
|
@ -1363,6 +1363,11 @@ hb_buffer_get_glyph_infos (hb_buffer_t *buffer,
|
|||
* Returns @buffer glyph position array. Returned pointer
|
||||
* is valid as long as @buffer contents are not modified.
|
||||
*
|
||||
* If buffer did not have positions before, the positions will be
|
||||
* initialized to zeros, unless this function is called from
|
||||
* within a buffer message callback (see hb_buffer_set_message_func()),
|
||||
* in which case %NULL is returned.
|
||||
*
|
||||
* Return value: (transfer none) (array length=length):
|
||||
* The @buffer glyph position array.
|
||||
* The value valid as long as buffer has not been modified.
|
||||
|
@ -1373,12 +1378,17 @@ hb_glyph_position_t *
|
|||
hb_buffer_get_glyph_positions (hb_buffer_t *buffer,
|
||||
unsigned int *length)
|
||||
{
|
||||
if (!buffer->have_positions)
|
||||
buffer->clear_positions ();
|
||||
|
||||
if (length)
|
||||
*length = buffer->len;
|
||||
|
||||
if (!buffer->have_positions)
|
||||
{
|
||||
if (unlikely (buffer->message_depth))
|
||||
return nullptr;
|
||||
|
||||
buffer->clear_positions ();
|
||||
}
|
||||
|
||||
return (hb_glyph_position_t *) buffer->pos;
|
||||
}
|
||||
|
||||
|
|
|
@ -128,6 +128,9 @@ struct hb_buffer_t
|
|||
hb_buffer_message_func_t message_func;
|
||||
void *message_data;
|
||||
hb_destroy_func_t message_destroy;
|
||||
unsigned message_depth; /* How deeply are we inside a message callback? */
|
||||
#else
|
||||
static constexpr unsigned message_depth = 0u;
|
||||
#endif
|
||||
|
||||
/* Internal debugging. */
|
||||
|
@ -400,10 +403,16 @@ struct hb_buffer_t
|
|||
#else
|
||||
if (!messaging ())
|
||||
return true;
|
||||
|
||||
message_depth++;
|
||||
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
bool ret = message_impl (font, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
message_depth--;
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue