From 6a66992842dea6e3ad9c717a3fa047341ab50af6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 3 Jan 2022 11:21:29 -0700 Subject: [PATCH] Add hb_segment_properties_overlay() New API: + hb_segment_properties_overlay() --- docs/harfbuzz-sections.txt | 1 + src/hb-buffer.cc | 39 ++++++++++++++++++++++++++++++++++++++ src/hb-buffer.h | 3 +++ 3 files changed, 43 insertions(+) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index a808da299..34a3918b4 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -103,6 +103,7 @@ hb_buffer_serialize_format_to_string hb_buffer_serialize_list_formats hb_segment_properties_equal hb_segment_properties_hash +hb_segment_properties_overlay hb_buffer_diff hb_buffer_set_message_func hb_buffer_t diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index be3161a54..abfb75f1c 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -86,7 +86,46 @@ hb_segment_properties_hash (const hb_segment_properties_t *p) (intptr_t) (p->language); } +/** + * hb_segment_properties_overlay: + * @p: #hb_segment_properties_t to fill in. + * @src: #hb_segment_properties_t to fill in from. + * + * Fills in missing fields of @p from @src in a considered manner. + * + * First, if @p does not have direction set, direction is copied from @src. + * + * Next, if @p and @src have the same direction (which can be unset), if @p + * does not have script set, script is copied from @src. + * + * Finally, if @p and @src have the same direction and script (which either + * can be unset), if @p does not have language set, language is copied from + * @src. + * + * Since: REPLACEME + **/ +HB_EXTERN void +hb_segment_properties_overlay (hb_segment_properties_t *p, + const hb_segment_properties_t *src) +{ + if (unlikely (!p || !src)) + return; + + if (!p->direction) + p->direction = src->direction; + + if (p->direction != src->direction) + return; + if (!p->script) + p->script = src->script; + + if (p->script != src->script) + return; + + if (!p->language) + p->language = src->language; +} /* Here is how the buffer works internally: * diff --git a/src/hb-buffer.h b/src/hb-buffer.h index a183cb9d4..deb76d411 100644 --- a/src/hb-buffer.h +++ b/src/hb-buffer.h @@ -170,6 +170,9 @@ hb_segment_properties_equal (const hb_segment_properties_t *a, HB_EXTERN unsigned int hb_segment_properties_hash (const hb_segment_properties_t *p); +HB_EXTERN void +hb_segment_properties_overlay (hb_segment_properties_t *p, + const hb_segment_properties_t *src); /**