From d8906a8acd7ed689e1e70048581dea596e54944b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 4 Jun 2026 22:52:42 +0200 Subject: [PATCH] [var] Hide gvar/GVAR selection behind gvar accelerator Expose only face->table.gvar to clients and let its accelerator prefer GVAR before falling back to gvar. Keep the concrete table types for tagged parsing and subsetting, while removing the separate GVAR face-table slot from callers. The facade owns the selected concrete accelerator so GVAR still uses MediumTypes and gvar still uses SmallTypes. Tested with meson test -C build and local subset-fuzzer target builds. Assisted-by: OpenAI Codex --- src/OT/glyf/Glyph.hh | 13 ----- src/OT/glyf/glyf.hh | 9 --- src/hb-ot-face-table-list.hh | 3 - src/hb-ot-var-gvar-table.hh | 106 +++++++++++++++++++++++++++++++++-- 4 files changed, 101 insertions(+), 30 deletions(-) diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index 83d3eaed0..d842d7983 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -382,19 +382,6 @@ struct Glyph #ifndef HB_NO_VAR if (hb_any (coords)) { -#ifndef HB_NO_BEYOND_64K - if (glyf_accelerator.GVAR->has_data ()) - { - if (!glyf_accelerator.GVAR->apply_deltas_to_points (gid, - coords, - points.as_array ().sub_array (old_length), - scratch, - gvar_cache, - phantom_only && type == SIMPLE)) - return false; - } - else -#endif if (!glyf_accelerator.gvar->apply_deltas_to_points (gid, coords, points.as_array ().sub_array (old_length), diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index a54587c87..dd51ba491 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -172,9 +172,6 @@ struct glyf_accelerator_t glyf_table = nullptr; #ifndef HB_NO_VAR gvar = nullptr; -#ifndef HB_NO_BEYOND_64K - GVAR = nullptr; -#endif #endif hmtx = nullptr; #ifndef HB_NO_VERTICAL @@ -190,9 +187,6 @@ struct glyf_accelerator_t glyf_table = hb_sanitize_context_t ().reference_table (face); #ifndef HB_NO_VAR gvar = face->table.gvar; -#ifndef HB_NO_BEYOND_64K - GVAR = face->table.GVAR; -#endif #endif hmtx = face->table.hmtx; #ifndef HB_NO_VERTICAL @@ -544,9 +538,6 @@ struct glyf_accelerator_t #ifndef HB_NO_VAR const gvar_accelerator_t *gvar; -#ifndef HB_NO_BEYOND_64K - const GVAR_accelerator_t *GVAR; -#endif #endif const hmtx_accelerator_t *hmtx; #ifndef HB_NO_VERTICAL diff --git a/src/hb-ot-face-table-list.hh b/src/hb-ot-face-table-list.hh index 417eaac56..07ef77545 100644 --- a/src/hb-ot-face-table-list.hh +++ b/src/hb-ot-face-table-list.hh @@ -90,9 +90,6 @@ HB_OT_TABLE (OT, fvar) HB_OT_TABLE (OT, avar) HB_OT_TABLE (OT, cvar) HB_OT_ACCELERATOR (OT, gvar) -#ifndef HB_NO_BEYOND_64K -HB_OT_ACCELERATOR (OT, GVAR) -#endif HB_OT_TABLE (OT, MVAR) #ifndef HB_NO_VAR_COMPOSITES HB_OT_ACCELERATOR (OT, VARC) diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 935472228..12cff131d 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -1021,11 +1021,107 @@ struct GVAR : gvar_GVAR static constexpr hb_tag_t tableTag = HB_OT_TAG_GVAR; }; -struct gvar_accelerator_t : gvar::accelerator_t { - gvar_accelerator_t (hb_face_t *face) : gvar::accelerator_t (face, gvar::tableTag) {} -}; -struct GVAR_accelerator_t : GVAR::accelerator_t { - GVAR_accelerator_t (hb_face_t *face) : GVAR::accelerator_t (face, GVAR::tableTag) {} +struct gvar_accelerator_t +{ + gvar_accelerator_t (hb_face_t *face) : + gvar_accel (nullptr) +#ifndef HB_NO_BEYOND_64K + , GVAR_accel (nullptr) +#endif + { +#ifndef HB_NO_BEYOND_64K + GVAR_accel = create_accelerator (face); + if (GVAR_accel && GVAR_accel->has_data ()) + { + gvar_accel = nullptr; + return; + } + destroy_accelerator (GVAR_accel); + GVAR_accel = nullptr; +#endif + + gvar_accel = create_accelerator (face); + } + + ~gvar_accelerator_t () + { + destroy_accelerator (gvar_accel); +#ifndef HB_NO_BEYOND_64K + destroy_accelerator (GVAR_accel); +#endif + } + + hb_scalar_cache_t *create_cache () const + { +#ifndef HB_NO_BEYOND_64K + if (GVAR_accel) return GVAR_accel->create_cache (); +#endif + if (unlikely (!gvar_accel)) return nullptr; + return gvar_accel->create_cache (); + } + + static void destroy_cache (hb_scalar_cache_t *cache) + { + hb_scalar_cache_t::destroy (cache); + } + + bool has_data () const + { +#ifndef HB_NO_BEYOND_64K + if (GVAR_accel) return GVAR_accel->has_data (); +#endif + if (unlikely (!gvar_accel)) return false; + return gvar_accel->has_data (); + } + + bool apply_deltas_to_points (hb_codepoint_t glyph, + hb_array_t coords, + const hb_array_t points, + hb_glyf_scratch_t &scratch, + hb_scalar_cache_t *gvar_cache = nullptr, + bool phantom_only = false) const + { +#ifndef HB_NO_BEYOND_64K + if (GVAR_accel) + return GVAR_accel->apply_deltas_to_points (glyph, coords, points, scratch, + gvar_cache, phantom_only); +#endif + if (unlikely (!gvar_accel)) return true; + return gvar_accel->apply_deltas_to_points (glyph, coords, points, scratch, + gvar_cache, phantom_only); + } + + unsigned int get_axis_count () const + { +#ifndef HB_NO_BEYOND_64K + if (GVAR_accel) return GVAR_accel->get_axis_count (); +#endif + if (unlikely (!gvar_accel)) return 0; + return gvar_accel->get_axis_count (); + } + + private: + template + static typename Table::accelerator_t *create_accelerator (hb_face_t *face) + { + typename Table::accelerator_t *accel = + (typename Table::accelerator_t *) hb_calloc (1, sizeof (typename Table::accelerator_t)); + if (unlikely (!accel)) return nullptr; + return new (accel) typename Table::accelerator_t (face, Table::tableTag); + } + + template + static void destroy_accelerator (Accel *accel) + { + if (!accel) return; + accel->~Accel (); + hb_free (accel); + } + + gvar::accelerator_t *gvar_accel; +#ifndef HB_NO_BEYOND_64K + GVAR::accelerator_t *GVAR_accel; +#endif }; } /* namespace OT */