From e2a2b5b229c92f1de3b9c3ea111cd1ffa75b18fc Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 10 Aug 2017 20:10:12 -0700 Subject: [PATCH] [unsafe-to-break] Be careful with flag propagation when merging clusters --- src/hb-buffer-private.hh | 13 +++++++++++++ src/hb-buffer.cc | 17 ++++++++++------- src/hb-ot-shape.cc | 3 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index e598f9e1a..01972af65 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -288,6 +288,19 @@ struct hb_buffer_t { return ret; } HB_INTERNAL bool message_impl (hb_font_t *font, const char *fmt, va_list ap) HB_PRINTF_FUNC(3, 0); + + static inline void + set_cluster (hb_glyph_info_t &info, unsigned int cluster, unsigned int mask = 0) + { + if (info.cluster != cluster) + { + if (mask & HB_GLYPH_FLAG_UNSAFE_TO_BREAK) + info.mask |= HB_GLYPH_FLAG_UNSAFE_TO_BREAK; + else + info.mask &= ~HB_GLYPH_FLAG_UNSAFE_TO_BREAK; + } + info.cluster = cluster; + } }; diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 2fcb06dab..4b0f96035 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -552,7 +552,7 @@ hb_buffer_t::merge_clusters_impl (unsigned int start, if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS) return; - uint32_t cluster = info[start].cluster; + unsigned int cluster = info[start].cluster; for (unsigned int i = start + 1; i < end; i++) cluster = MIN (cluster, info[i].cluster); @@ -568,10 +568,10 @@ hb_buffer_t::merge_clusters_impl (unsigned int start, /* If we hit the start of buffer, continue in out-buffer. */ if (idx == start) for (unsigned int i = out_len; i && out_info[i - 1].cluster == info[start].cluster; i--) - out_info[i - 1].cluster = cluster; + set_cluster (out_info[i - 1], cluster); for (unsigned int i = start; i < end; i++) - info[i].cluster = cluster; + set_cluster (info[i], cluster); } void hb_buffer_t::merge_out_clusters (unsigned int start, @@ -583,7 +583,7 @@ hb_buffer_t::merge_out_clusters (unsigned int start, if (unlikely (end - start < 2)) return; - uint32_t cluster = out_info[start].cluster; + unsigned int cluster = out_info[start].cluster; for (unsigned int i = start + 1; i < end; i++) cluster = MIN (cluster, out_info[i].cluster); @@ -599,14 +599,16 @@ hb_buffer_t::merge_out_clusters (unsigned int start, /* If we hit the end of out-buffer, continue in buffer. */ if (end == out_len) for (unsigned int i = idx; i < len && info[i].cluster == out_info[end - 1].cluster; i++) - info[i].cluster = cluster; + set_cluster (info[i], cluster); for (unsigned int i = start; i < end; i++) - out_info[i].cluster = cluster; + set_cluster (out_info[i], cluster); } void hb_buffer_t::delete_glyph () { + /* The logic here is duplicated in hb_ot_hide_default_ignorables(). */ + unsigned int cluster = info[idx].cluster; if (idx + 1 < len && cluster == info[idx + 1].cluster) { @@ -619,9 +621,10 @@ hb_buffer_t::delete_glyph () /* Merge cluster backward. */ if (cluster < out_info[out_len - 1].cluster) { + unsigned int mask = info[idx].mask; unsigned int old_cluster = out_info[out_len - 1].cluster; for (unsigned i = out_len; i && out_info[i - 1].cluster == old_cluster; i--) - out_info[i - 1].cluster = cluster; + set_cluster (out_info[i - 1], cluster, mask); } goto done; } diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 29f5e58e5..5cd69927e 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -509,9 +509,10 @@ hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c) /* Merge cluster backward. */ if (cluster < info[j - 1].cluster) { + unsigned int mask = info[i].mask; unsigned int old_cluster = info[j - 1].cluster; for (unsigned k = j; k && info[k - 1].cluster == old_cluster; k--) - info[k - 1].cluster = cluster; + buffer->set_cluster (info[k - 1], cluster, mask); } continue; }