diff --git a/src/hb-ot-var-avar-table.hh b/src/hb-ot-var-avar-table.hh index 4bb9d4a36..2da5e7627 100644 --- a/src/hb-ot-var-avar-table.hh +++ b/src/hb-ot-var-avar-table.hh @@ -414,6 +414,21 @@ struct avar bool has_v2_data () const { return version.major > 1; } + /* Apply avar v1 segment maps only, deliberately omitting avar v2 processing. + * Used during avar2 partial instancing to compute intermediate-space coords. */ + bool map_coords_v1_only (float *coords, unsigned int coords_length) const + { + unsigned int count = hb_min (coords_length, axisCount); + const SegmentMaps *map = &firstAxisSegmentMaps; + for (unsigned int i = 0; i < count; i++) + { + int v = roundf (map->map_float (coords[i]) * 16384.f); + coords[i] = v / 16384.f; + map = &StructAfter (*map); + } + return true; + } + // axis normalization is done in 2.14 here // TODO: deprecate this API once fonttools is updated to use 16.16 normalization bool map_coords_2_14 (float *coords, unsigned int coords_length) const diff --git a/src/hb-subset-plan-member-list.hh b/src/hb-subset-plan-member-list.hh index d91edba9d..be4541378 100644 --- a/src/hb-subset-plan-member-list.hh +++ b/src/hb-subset-plan-member-list.hh @@ -134,6 +134,9 @@ HB_SUBSET_PLAN_MEMBER (hb_hashmap_t E(), axes_triple_ //retained old axis index -> new axis index mapping in fvar axis array HB_SUBSET_PLAN_MEMBER (hb_map_t, axes_index_map) +//old intermediate coords (post-fvar, post-avar-v1, pre-avar-v2) at new min/default/max +HB_SUBSET_PLAN_MEMBER (hb_hashmap_t E(), old_intermediates) + //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 diff --git a/src/hb-subset-plan-var.cc b/src/hb-subset-plan-var.cc index 2e265ae65..6885722ce 100644 --- a/src/hb-subset-plan-var.cc +++ b/src/hb-subset-plan-var.cc @@ -253,34 +253,82 @@ normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan) if (has_avar) { const OT::avar* avar_table = face->table.avar; + unsigned coords_len = last_idx + 1; + if (avar_table->has_v2_data () && !plan->all_axes_pinned) { - DEBUG_MSG (SUBSET, nullptr, "Partial-instancing avar2 table is not supported."); - return false; - } + /* avar2 partial instancing: use v1-only mapping to get intermediate-space + * coords. These are used for IVS rebasing and offset compensation. */ + plan->has_avar2 = true; - unsigned coords_len = last_idx + 1; - if (!plan->check_success (avar_table->map_coords_2_14 (normalized_mins.arrayZ, coords_len)) || - !plan->check_success (avar_table->map_coords_2_14 (normalized_defaults.arrayZ, coords_len)) || - !plan->check_success (avar_table->map_coords_2_14 (normalized_maxs.arrayZ, coords_len))) - return false; + if (!plan->check_success (avar_table->map_coords_v1_only (normalized_mins.arrayZ, coords_len)) || + !plan->check_success (avar_table->map_coords_v1_only (normalized_defaults.arrayZ, coords_len)) || + !plan->check_success (avar_table->map_coords_v1_only (normalized_maxs.arrayZ, coords_len))) + return false; - for (const auto& _ : + hb_enumerate (axes)) - { - unsigned i = _.first; - hb_tag_t axis_tag = _.second.get_axis_tag (); - if (plan->user_axes_location.has (axis_tag)) + for (const auto& _ : + hb_enumerate (axes)) { - plan->axes_location.set (axis_tag, Triple ((double) normalized_mins[i], - (double) normalized_defaults[i], - (double) normalized_maxs[i])); - float normalized_default = normalized_defaults[i]; - if (normalized_default == -0.f) - normalized_default = 0.f; // Normalize -0 to 0 - if (normalized_default != 0.f) - plan->pinned_at_default = false; + unsigned i = _.first; + hb_tag_t axis_tag = _.second.get_axis_tag (); + if (plan->user_axes_location.has (axis_tag)) + { + /* Store intermediate-space coords for offset compensation */ + plan->old_intermediates.set (axis_tag, Triple ((double) normalized_mins[i], + (double) normalized_defaults[i], + (double) normalized_maxs[i])); + /* axes_location is also in intermediate space for avar2 */ + plan->axes_location.set (axis_tag, Triple ((double) normalized_mins[i], + (double) normalized_defaults[i], + (double) normalized_maxs[i])); - plan->normalized_coords[i] = roundf (normalized_default * 16384.f); + float normalized_default = normalized_defaults[i]; + if (normalized_default == -0.f) + normalized_default = 0.f; + if (normalized_default != 0.f) + plan->pinned_at_default = false; + + plan->normalized_coords[i] = roundf (normalized_default * 16384.f); + } + } + + /* For avar2, keep ALL axes in axes_index_map (including pinned ones), + * so pinned axes remain in fvar as hidden. */ + plan->axes_index_map.reset (); + plan->axis_tags.reset (); + for (const auto& _ : + hb_enumerate (axes)) + { + unsigned i = _.first; + hb_tag_t axis_tag = _.second.get_axis_tag (); + plan->axes_index_map.set (i, (unsigned) _.first); + plan->axis_tags.push (axis_tag); + } + plan->all_axes_pinned = false; + } + else + { + /* Standard avar v1 (or v1+v2 with all axes pinned) */ + if (!plan->check_success (avar_table->map_coords_2_14 (normalized_mins.arrayZ, coords_len)) || + !plan->check_success (avar_table->map_coords_2_14 (normalized_defaults.arrayZ, coords_len)) || + !plan->check_success (avar_table->map_coords_2_14 (normalized_maxs.arrayZ, coords_len))) + return false; + + for (const auto& _ : + hb_enumerate (axes)) + { + unsigned i = _.first; + hb_tag_t axis_tag = _.second.get_axis_tag (); + if (plan->user_axes_location.has (axis_tag)) + { + plan->axes_location.set (axis_tag, Triple ((double) normalized_mins[i], + (double) normalized_defaults[i], + (double) normalized_maxs[i])); + float normalized_default = normalized_defaults[i]; + if (normalized_default == -0.f) + normalized_default = 0.f; + if (normalized_default != 0.f) + plan->pinned_at_default = false; + + plan->normalized_coords[i] = roundf (normalized_default * 16384.f); + } } } } diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 02f891a14..6ea9e6238 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -648,6 +648,7 @@ hb_subset_plan_t::hb_subset_plan_t (hb_face_t *face, all_axes_pinned = false; pinned_at_default = true; has_gdef_varstore = false; + has_avar2 = false; #ifdef HB_EXPERIMENTAL_API for (auto _ : input->name_table_overrides) diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 2a935b8f1..9baf3d82e 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -169,6 +169,9 @@ struct hb_subset_plan_t // whether GDEF ItemVariationStore is retained mutable bool has_gdef_varstore; + // whether we're doing avar2 partial instancing + bool has_avar2; + #define HB_SUBSET_PLAN_MEMBER(Type, Name) Type Name; #include "hb-subset-plan-member-list.hh" #undef HB_SUBSET_PLAN_MEMBER