mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-12-01 18:44:09 +01:00
[subset] Add avar2 plan members and v1-only normalization
Add has_avar2 flag and old_intermediates map to subset plan. Add map_coords_v1_only() to avar that applies segment maps without avar v2 processing. Modify normalize_axes_location() to detect avar2 partial instancing and compute intermediate-space coordinates using v1-only mapping. When avar2 partial instancing is detected, all axes (including pinned) are kept in axes_index_map so they remain in fvar. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a0b37f74a9
commit
85ba4a1315
5 files changed
+92
-22
No files matched your search
@@ -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<SegmentMaps> (*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
|
||||
|
||||
@@ -134,6 +134,9 @@ HB_SUBSET_PLAN_MEMBER (hb_hashmap_t E(<hb_tag_t, TripleDistances>), 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(<hb_tag_t, Triple>), 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
|
||||
|
||||
+70
-22
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user