From 5336ba70f6fc995858881c2e4339e035b16c70a0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 20 May 2022 17:03:18 -0600 Subject: [PATCH] [HVAR] Cache VarStore region scalars --- src/hb-ot-font.cc | 8 +++++++- src/hb-ot-hmtx-table.hh | 9 +++++---- src/hb-ot-var-hvar-table.hh | 11 ++++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 0f44ee4d5..ef4115a8d 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -110,12 +110,18 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data, const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx; + const OT::HVARVVAR &HVAR = *hmtx.var_table; + const OT::VariationStore &varStore = &HVAR + HVAR.varStore; + OT::VariationStore::cache_t *cache = font->num_coords ? varStore.create_cache () : nullptr; + for (unsigned int i = 0; i < count; i++) { - *first_advance = font->em_scale_x (hmtx.get_advance (*first_glyph, font)); + *first_advance = font->em_scale_x (hmtx.get_advance (*first_glyph, font, cache)); first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } + + OT::VariationStore::destroy_cache (cache); } #ifndef HB_NO_VERTICAL diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index d5e1fc91d..d0e46e0b0 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -242,7 +242,7 @@ struct hmtxvmtx return side_bearing; if (var_table.get_length ()) - return side_bearing + var_table->get_side_bearing_var (glyph, font->coords, font->num_coords); // TODO Optimize?! + return side_bearing + var_table->get_side_bearing_var (glyph, font->coords, font->num_coords); return _glyf_get_side_bearing_var (font, glyph, T::tableTag == HB_OT_TAG_vmtx); #else @@ -284,7 +284,8 @@ struct hmtxvmtx } unsigned int get_advance (hb_codepoint_t glyph, - hb_font_t *font) const + hb_font_t *font, + VariationStore::cache_t *store_cache = nullptr) const { unsigned int advance = get_advance (glyph); @@ -293,7 +294,7 @@ struct hmtxvmtx return advance; if (var_table.get_length ()) - return advance + roundf (var_table->get_advance_var (glyph, font)); // TODO Optimize?! + return advance + roundf (var_table->get_advance_var (glyph, font, store_cache)); // TODO Optimize?! return _glyf_get_advance_var (font, glyph, T::tableTag == HB_OT_TAG_vmtx); #else @@ -310,7 +311,7 @@ struct hmtxvmtx unsigned int default_advance; - private: + public: hb_blob_ptr_t table; hb_blob_ptr_t var_table; }; diff --git a/src/hb-ot-var-hvar-table.hh b/src/hb-ot-var-hvar-table.hh index e9d90352f..56efcdbee 100644 --- a/src/hb-ot-var-hvar-table.hh +++ b/src/hb-ot-var-hvar-table.hh @@ -319,10 +319,15 @@ struct HVARVVAR hvar_plan.index_map_plans.as_array ())); } - float get_advance_var (hb_codepoint_t glyph, hb_font_t *font) const + float get_advance_var (hb_codepoint_t glyph, + hb_font_t *font, + VariationStore::cache_t *store_cache = nullptr) const { uint32_t varidx = (this+advMap).map (glyph); - return (this+varStore).get_delta (varidx, font->coords, font->num_coords); + return (this+varStore).get_delta (varidx, + font->coords, + font->num_coords, + store_cache); } float get_side_bearing_var (hb_codepoint_t glyph, @@ -335,7 +340,7 @@ struct HVARVVAR bool has_side_bearing_deltas () const { return lsbMap && rsbMap; } - protected: + public: FixedVersion<>version; /* Version of the metrics variation table * initially set to 0x00010000u */ Offset32To