From 9d05b03f83ac4064a15cf5e59fd8acfc952867ce Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 9 Mar 2025 01:34:37 -0700 Subject: [PATCH] [font] Add HB_FONT_FUNCS work into hb_font_set_funcs_using() --- src/hb-font.cc | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/hb-font.cc b/src/hb-font.cc index 5568dd8fc..2c79c0d83 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -1867,19 +1867,7 @@ hb_font_create (hb_face_t *face) { hb_font_t *font = _hb_font_create (face); - static hb_atomic_ptr_t static_funcs_name; - const char *funcs_name = static_funcs_name.get_acquire (); - if (!funcs_name) - { - funcs_name = getenv ("HB_FONT_FUNCS"); - if (!funcs_name) - funcs_name = ""; - if (!static_funcs_name.cmpexch (nullptr, funcs_name)) - funcs_name = static_funcs_name.get_acquire (); - } - - if (unlikely (!hb_font_set_funcs_using (font, funcs_name))) - hb_font_set_funcs_using (font, nullptr); + hb_font_set_funcs_using (font, nullptr); #ifndef HB_NO_VAR if (face && face->index >> 16) @@ -2341,7 +2329,9 @@ static struct supported_font_funcs_t { * Sets the font-functions structure to use for a font, based on the * specified name. * - * If @name is `NULL` or empty string, the first functioning font-functions are used. + * If @name is `NULL` or empty string, the default (first) functioning font-functions + * are used. This default can be changed by setting the `HB_FONT_FUNCS` environment + * variable to the name of the desired font-functions. * * Return value: `true` if the font-functions was found and set, `false` otherwise * @@ -2351,8 +2341,25 @@ hb_bool_t hb_font_set_funcs_using (hb_font_t *font, const char *name) { + bool retry = false; + + if (!name || !*name) + { + static hb_atomic_ptr_t static_funcs_name; + name = static_funcs_name.get_acquire (); + if (!name) + { + name = getenv ("HB_FONT_FUNCS"); + if (!name) + name = ""; + if (!static_funcs_name.cmpexch (nullptr, name)) + name = static_funcs_name.get_acquire (); + } + retry = true; + } if (name && !*name) name = nullptr; +retry: for (unsigned i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++) if (!name || strcmp (supported_font_funcs[i].name, name) == 0) { @@ -2361,6 +2368,13 @@ hb_font_set_funcs_using (hb_font_t *font, return true; } + if (retry) + { + retry = false; + name = nullptr; + goto retry; + } + return false; }