[font/var] Try to regain performance of all-normalized-coords=0

This commit is contained in:
Behdad Esfahbod committed 2025-03-02 17:00:14 -07:00
1 parent 1f0aae5280
commit 9b6da29971
7 files changed
+42 -15

No files matched your search

+3 -3
View File
@@ -37,12 +37,12 @@ struct AnchorFormat3
*x = font->em_fscale_x (xCoordinate);
*y = font->em_fscale_y (yCoordinate);
if ((font->x_ppem || font->num_coords) && xDeviceTable.sanitize (&c->sanitizer, this))
if ((font->x_ppem || font->has_nonzero_coords) && xDeviceTable.sanitize (&c->sanitizer, this))
{
hb_barrier ();
*x += (this+xDeviceTable).get_x_delta (font, c->var_store, c->var_store_cache);
}
if ((font->y_ppem || font->num_coords) && yDeviceTable.sanitize (&c->sanitizer, this))
if ((font->y_ppem || font->has_nonzero_coords) && yDeviceTable.sanitize (&c->sanitizer, this))
{
hb_barrier ();
*y += (this+yDeviceTable).get_y_delta (font, c->var_store, c->var_store_cache);
@@ -63,7 +63,7 @@ struct AnchorFormat3
hb_pair_t<unsigned, int> *new_varidx_delta;
if (!c->plan->layout_variation_idx_delta_map.has (x_varidx, &new_varidx_delta))
return_trace (false);
x_varidx = hb_first (*new_varidx_delta);
int delta = hb_second (*new_varidx_delta);
if (delta != 0)
+3 -2
View File
@@ -379,7 +379,7 @@ struct glyf_accelerator_t
bool success = false;
contour_point_t phantoms[glyf_impl::PHANTOM_COUNT];
if (font->num_coords)
if (font->has_nonzero_coords)
{
hb_glyf_scratch_t scratch;
success = get_points (font, gid, points_aggregator_t (font, nullptr, phantoms, false),
@@ -433,7 +433,8 @@ struct glyf_accelerator_t
bool get_extents (hb_font_t *font,
hb_codepoint_t gid,
hb_glyph_extents_t *extents) const
{ return get_extents_at (font, gid, extents, hb_array (font->coords, font->num_coords)); }
{ return get_extents_at (font, gid, extents, hb_array (font->coords,
font->has_nonzer_coords ? font->num_coords : 0)); }
bool get_extents_at (hb_font_t *font,
hb_codepoint_t gid,
+16 -4
View File
@@ -1797,6 +1797,7 @@ DEFINE_NULL_INSTANCE (hb_font_t) =
0, /* ptem */
HB_FONT_NO_VAR_NAMED_INSTANCE, /* instance_index */
false, /* has_nonzero_coords */
0, /* num_coords */
nullptr, /* coords */
nullptr, /* design_coords */
@@ -1861,10 +1862,13 @@ hb_font_create (hb_face_t *face)
#ifndef HB_NO_VAR
// Initialize variations.
if (face && face->index >> 16)
hb_font_set_var_named_instance (font, (face->index >> 16) - 1);
else
hb_font_set_variations (font, nullptr, 0);
if (likely (face))
{
if (face->index >> 16)
hb_font_set_var_named_instance (font, (face->index >> 16) - 1);
else if (face->table.avar->is_biased ())
hb_font_set_variations (font, nullptr, 0);
}
#endif
return font;
@@ -1883,6 +1887,14 @@ _hb_font_adopt_var_coords (hb_font_t *font,
font->design_coords = design_coords;
font->num_coords = coords_length;
font->has_nonzero_coords = false;
for (unsigned int i = 0; i < coords_length; i++)
if (coords[i])
{
font->has_nonzero_coords = true;
break;
}
font->mults_changed (); // Easiest to call this to drop cached data
}
+1
View File
@@ -135,6 +135,7 @@ struct hb_font_t
/* Font variation coordinates. */
unsigned int instance_index;
bool has_nonzero_coords;
unsigned int num_coords;
int *coords;
float *design_coords;
+4 -4
View File
@@ -226,9 +226,9 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data,
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
const OT::HVAR &HVAR = *hmtx.var_table;
const OT::ItemVariationStore &varStore = &HVAR + HVAR.varStore;
OT::ItemVariationStore::cache_t *varStore_cache = font->num_coords * count >= 128 ? varStore.create_cache () : nullptr;
OT::ItemVariationStore::cache_t *varStore_cache = font->has_nonzero_coords && font->num_coords * count >= 128 ? varStore.create_cache () : nullptr;
bool use_cache = font->num_coords;
bool use_cache = font->has_nonzero_coords;
#else
OT::ItemVariationStore::cache_t *varStore_cache = nullptr;
bool use_cache = false;
@@ -345,7 +345,7 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data,
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
const OT::VVAR &VVAR = *vmtx.var_table;
const OT::ItemVariationStore &varStore = &VVAR + VVAR.varStore;
OT::ItemVariationStore::cache_t *varStore_cache = font->num_coords ? varStore.create_cache () : nullptr;
OT::ItemVariationStore::cache_t *varStore_cache = font->has_nonzero_coords ? varStore.create_cache () : nullptr;
#else
OT::ItemVariationStore::cache_t *varStore_cache = nullptr;
#endif
@@ -425,7 +425,7 @@ hb_ot_get_glyph_v_origin (hb_font_t *font,
#ifndef HB_NO_VAR
const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx;
const OT::VVAR &VVAR = *vmtx.var_table;
if (font->num_coords)
if (font->has_nonzero_coords)
VVAR.get_vorg_delta_unscaled (glyph,
font->coords, font->num_coords,
&delta);
+2 -2
View File
@@ -347,7 +347,7 @@ struct hmtxvmtx
hb_codepoint_t glyph,
int *lsb) const
{
if (!font->num_coords)
if (!font->has_nonzero_coords)
return get_leading_bearing_without_var_unscaled (glyph, lsb);
#ifndef HB_NO_VAR
@@ -403,7 +403,7 @@ struct hmtxvmtx
unsigned int advance = get_advance_without_var_unscaled (glyph);
#ifndef HB_NO_VAR
if (unlikely (glyph >= num_bearings) || !font->num_coords)
if (unlikely (glyph >= num_bearings) || !font->has_nonzero_coords)
return advance;
if (var_table.get_length ())
+13
View File
@@ -386,6 +386,19 @@ struct avar
}
}
bool is_biased () const
{
// Whether this table can map a 0 to a non-0 value.
const SegmentMaps *map = &firstAxisSegmentMaps;
for (unsigned int i = 0; i < axisCount; i++)
{
if (map->map (0) != 0)
return true;
map = &StructAfter<SegmentMaps> (*map);
}
return false;
}
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);