[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
This commit is contained in:
Behdad Esfahbod committed 2026-06-05 12:34:52 +02:00
1 parent 16fce0eb2f
commit d8906a8acd
4 files changed
+101 -30

No files matched your search

-13
View File
@@ -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),
-9
View File
@@ -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<glyf> (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
-3
View File
@@ -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)
+101 -5
View File
@@ -1021,11 +1021,107 @@ struct GVAR : gvar_GVAR<MediumTypes>
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<GVAR> (face);
if (GVAR_accel && GVAR_accel->has_data ())
{
gvar_accel = nullptr;
return;
}
destroy_accelerator (GVAR_accel);
GVAR_accel = nullptr;
#endif
gvar_accel = create_accelerator<gvar> (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<const int> coords,
const hb_array_t<contour_point_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 <typename Table>
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 <typename Accel>
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 */