From 5d94eb61b883eb194bd952d6d5c552a614c68c19 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 8 Jan 2023 11:55:13 -0700 Subject: [PATCH] [hb-cairo] Fix hb_cairo_glyphs_from_buffer() when utf8 missing Fixes https://github.com/harfbuzz/harfbuzz/issues/4016 --- src/hb-cairo.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hb-cairo.cc b/src/hb-cairo.cc index 9867c960c..90f3030ec 100644 --- a/src/hb-cairo.cc +++ b/src/hb-cairo.cc @@ -831,7 +831,7 @@ hb_cairo_glyphs_from_buffer (hb_buffer_t *buffer, if (orig_num_glyphs < *num_glyphs + 1) *glyphs = cairo_glyph_allocate (*num_glyphs + 1); - if (clusters) + if (clusters && utf8) { unsigned orig_num_clusters = *num_clusters; *num_clusters = *num_glyphs ? 1 : 0; @@ -860,7 +860,7 @@ hb_cairo_glyphs_from_buffer (hb_buffer_t *buffer, (*glyphs)[i].x = round (hx * x_scale); (*glyphs)[i].y = round (hy * y_scale); - if (clusters && *num_clusters) + if (clusters && *num_clusters && utf8) { memset ((void *) *clusters, 0, *num_clusters * sizeof ((*clusters)[0])); hb_bool_t backward = HB_DIRECTION_IS_BACKWARD (hb_buffer_get_direction (buffer)); @@ -909,6 +909,8 @@ hb_cairo_glyphs_from_buffer (hb_buffer_t *buffer, (*clusters)[cluster].num_bytes = utf8 + utf8_len - start; } } + else if (num_clusters) + *num_clusters = 0; } #endif