From cd1d8b8bf34468e72bb3d1dfaa0aea7201cafa4a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 23 Apr 2024 14:18:06 -0600 Subject: [PATCH] [varc] Use multiVarStore instead of GDEF varStore That's what we agreed upon. --- src/OT/Var/VARC/VARC.cc | 6 +-- src/hb-ot-layout-common.hh | 75 ++++++++++++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/src/OT/Var/VARC/VARC.cc b/src/OT/Var/VARC/VARC.cc index 2903a8592..326edf2e5 100644 --- a/src/OT/Var/VARC/VARC.cc +++ b/src/OT/Var/VARC/VARC.cc @@ -144,9 +144,7 @@ VarComponent::get_path_at (hb_font_t *font, auto &VARC = *font->face->table.VARC; auto &varStore = &VARC+VARC.varStore; - - const GDEF &gdef = *font->face->table.GDEF->table; - auto gdefInstancer = ItemVarStoreInstancer(&gdef.get_var_store(), nullptr, coords); + auto instancer = MultiItemVarStoreInstancer(&varStore, nullptr, coords); #define READ_UINT32VAR(name) \ HB_STMT_START { \ @@ -189,7 +187,7 @@ VarComponent::get_path_at (hb_font_t *font, unsigned conditionIndex; READ_UINT32VAR (conditionIndex); const auto &condition = (&VARC+VARC.conditionList)[conditionIndex]; - show = condition.evaluate (coords.arrayZ, coords.length, &gdefInstancer); + show = condition.evaluate (coords.arrayZ, coords.length, &instancer); } // Axis values diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 89ffd400a..3a4c6b0d7 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -3718,20 +3718,65 @@ struct ItemVarStoreInstancer ItemVarStoreInstancer (const ItemVariationStore *varStore, const DeltaSetIndexMap *varIdxMap, hb_array_t coords) : - varStore (varStore), varIdxMap (varIdxMap), coords (coords) {} + varStore (varStore), varIdxMap (varIdxMap), coords (coords) + { + if (!varStore) + varStore = &Null(ItemVariationStore); + } operator bool () const { return varStore && bool (coords); } + float operator[] (uint32_t varIdx) const + { return (*this) (varIdx); } + /* according to the spec, if colr table has varStore but does not have * varIdxMap, then an implicit identity mapping is used */ + /* Humm? https://github.com/harfbuzz/harfbuzz/issues/4677 */ float operator() (uint32_t varIdx, unsigned short offset = 0) const - { return coords ? varStore->get_delta (varIdxMap ? varIdxMap->map (VarIdx::add (varIdx, offset)) : varIdx + offset, coords) : 0; } + { return coords ? varStore->get_delta (varIdxMap ? varIdxMap->map (VarIdx::add (varIdx, offset)) : varIdx + offset, coords) : 0.f; } const ItemVariationStore *varStore; const DeltaSetIndexMap *varIdxMap; hb_array_t coords; }; +struct MultiItemVarStoreInstancer +{ + MultiItemVarStoreInstancer (const MultiItemVariationStore *varStore, + const DeltaSetIndexMap *varIdxMap, + hb_array_t coords) : + varStore (varStore), varIdxMap (varIdxMap), coords (coords) + { + if (!varStore) + varStore = &Null(MultiItemVariationStore); + } + + operator bool () const { return varStore && bool (coords); } + + float operator[] (uint32_t varIdx) const + { + float v = 0; + (*this) (hb_array (&v, 1), varIdx); + return v; + } + + /* according to the spec, if colr table has varStore but does not have + * varIdxMap, then an implicit identity mapping is used */ + /* Humm? https://github.com/harfbuzz/harfbuzz/issues/4677 */ + void operator() (hb_array_t out, uint32_t varIdx, unsigned short offset = 0) const + { + if (coords) + varStore->get_delta (varIdxMap ? varIdxMap->map (VarIdx::add (varIdx, offset)) : varIdx + offset, coords, out); + else + for (unsigned i = 0; i < out.length; i++) + out.arrayZ[i] = 0.f; + } + + const MultiItemVariationStore *varStore; + const DeltaSetIndexMap *varIdxMap; + hb_array_t coords; +}; + /* * Feature Variations @@ -3745,11 +3790,12 @@ enum Cond_with_Var_flag_t }; +template static bool _hb_recurse_condition_evaluate (const struct Condition &condition, const int *coords, unsigned int coord_len, - ItemVarStoreInstancer *instancer); + Instancer *instancer); struct ConditionAxisRange { @@ -3844,8 +3890,9 @@ struct ConditionAxisRange return KEEP_RECORD_WITH_VAR; } + template bool evaluate (const int *coords, unsigned int coord_len, - ItemVarStoreInstancer *instancer HB_UNUSED) const + Instancer *instancer HB_UNUSED) const { int coord = axisIndex < coord_len ? coords[axisIndex] : 0; return filterRangeMinValue.to_int () <= coord && coord <= filterRangeMaxValue.to_int (); @@ -3878,11 +3925,12 @@ struct ConditionValue } private: + template bool evaluate (const int *coords, unsigned int coord_len, - ItemVarStoreInstancer *instancer) const + Instancer *instancer) const { signed value = defaultValue; - value += instancer[varIdx]; + value += (*instancer)[varIdx]; return value > 0; } @@ -3921,8 +3969,9 @@ struct ConditionAnd } private: + template bool evaluate (const int *coords, unsigned int coord_len, - ItemVarStoreInstancer *instancer) const + Instancer *instancer) const { unsigned int count = conditions.len; for (unsigned int i = 0; i < count; i++) @@ -3967,8 +4016,9 @@ struct ConditionOr } private: + template bool evaluate (const int *coords, unsigned int coord_len, - ItemVarStoreInstancer *instancer) const + Instancer *instancer) const { unsigned int count = conditions.len; for (unsigned int i = 0; i < count; i++) @@ -4013,8 +4063,9 @@ struct ConditionNegate } private: + template bool evaluate (const int *coords, unsigned int coord_len, - ItemVarStoreInstancer *instancer) const + Instancer *instancer) const { return !_hb_recurse_condition_evaluate (this+condition, coords, coord_len, @@ -4045,8 +4096,9 @@ struct ConditionNegate struct Condition { + template bool evaluate (const int *coords, unsigned int coord_len, - ItemVarStoreInstancer *instancer) const + Instancer *instancer) const { switch (u.format) { case 1: return u.format1.evaluate (coords, coord_len, instancer); @@ -4111,11 +4163,12 @@ struct Condition DEFINE_SIZE_UNION (2, format); }; +template bool _hb_recurse_condition_evaluate (const struct Condition &condition, const int *coords, unsigned int coord_len, - ItemVarStoreInstancer *instancer) + Instancer *instancer) { return condition.evaluate (coords, coord_len, instancer); }