From 2326879229535f97ce099958e494005d1092ee5b Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Thu, 31 Aug 2023 15:28:06 -0700 Subject: [PATCH] [instancer] add serialize() for VarRegionList The region list argument comes from item_variations_t.get_region_list() --- src/hb-ot-layout-common.hh | 47 +++++++++++++++++++++++++++++++ src/hb-subset-plan-member-list.hh | 2 ++ src/hb-subset-plan.cc | 1 + 3 files changed, 50 insertions(+) diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 2f73c5816..fc374c5ad 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -2475,6 +2475,12 @@ struct VarRegionAxis * have to do that at runtime. */ } + bool serialize (hb_serialize_context_t *c) const + { + TRACE_SERIALIZE (this); + return_trace (c->embed (this)); + } + public: F2DOT14 startCoord; F2DOT14 peakCoord; @@ -2532,6 +2538,47 @@ struct VarRegionList return_trace (c->check_struct (this) && axesZ.sanitize (c, axisCount * regionCount)); } + bool serialize (hb_serialize_context_t *c, + const hb_vector_t& axis_tags, + const hb_vector_t*>& regions) + { + TRACE_SERIALIZE (this); + unsigned axis_count = axis_tags.length; + unsigned region_count = regions.length; + if (!axis_count || !region_count) return_trace (false); + if (unlikely (hb_unsigned_mul_overflows (axis_count * region_count, + VarRegionAxis::static_size))) return_trace (false); + if (unlikely (!c->extend_min (this))) return_trace (false); + axisCount = axis_count; + regionCount = region_count; + + for (unsigned r = 0; r < region_count; r++) + { + const auto& region = regions[r]; + for (unsigned i = 0; i < axis_count; i++) + { + hb_tag_t tag = axis_tags.arrayZ[i]; + VarRegionAxis var_region_rec; + Triple *coords; + if (region->has (tag, &coords)) + { + var_region_rec.startCoord.set_float (coords->minimum); + var_region_rec.peakCoord.set_float (coords->middle); + var_region_rec.endCoord.set_float (coords->maximum); + } + else + { + var_region_rec.startCoord.set_int (0); + var_region_rec.peakCoord.set_int (0); + var_region_rec.endCoord.set_int (0); + } + if (!var_region_rec.serialize (c)) + return_trace (false); + } + } + return_trace (true); + } + bool serialize (hb_serialize_context_t *c, const VarRegionList *src, const hb_inc_bimap_t ®ion_map) { TRACE_SERIALIZE (this); diff --git a/src/hb-subset-plan-member-list.hh b/src/hb-subset-plan-member-list.hh index 01d8b0f8b..46837aded 100644 --- a/src/hb-subset-plan-member-list.hh +++ b/src/hb-subset-plan-member-list.hh @@ -113,6 +113,8 @@ HB_SUBSET_PLAN_MEMBER (hb_map_t, axes_index_map) //axis_index->axis_tag mapping in fvar axis array HB_SUBSET_PLAN_MEMBER (hb_map_t, axes_old_index_tag_map) +//vector of retained axis tags in the order of axes given in the 'fvar' table +HB_SUBSET_PLAN_MEMBER (hb_vector_t, axis_tags) //hmtx metrics map: new gid->(advance, lsb) HB_SUBSET_PLAN_MEMBER (mutable hb_hashmap_t E()>), hmtx_map) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index c293ba3ba..7cb306eb5 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -927,6 +927,7 @@ _normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan) { axis_not_pinned = true; plan->axes_index_map.set (old_axis_idx, new_axis_idx); + plan->axis_tags.push (axis_tag); new_axis_idx++; }