mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-23 16:01:07 +01:00
[subset] Instance self-contained pinned axes for avar2
A pinned axis whose final coordinate is CONSTANT over the retained box -- its varIdx is NO_VARIATION_INDEX, or its avar2 delta row is constant (zero-width delta interval, detected with the same plan-time interval arithmetic as the reachable ranges) -- is "self-contained": there is no reason to keep it in the instance. Remove it from fvar and avar entirely and bake its constant contribution into the variation tables, mirroring fontTools' selfContainedAxes handling on its avar2-instancing branch. The key move fits fontTools' second instancing pass into HarfBuzz's single-pass architecture: the plan presents the self-contained pins to every other table as an ORDINARY partial instancing in old final-coordinate space. plan->axes_location and plan->normalized_coords now hold only those pins (empty when there are none), while the intermediate-space ranges that avar itself needs move to a new plan->avar2_axes_location. With that, the blanket "normalized_coords && !has_avar2" instancing skips added earlier reduce to plain "normalized_coords" checks: under avar2 with no self-contained axes the tables take their non-instancing paths exactly as before, and with self-contained axes the standard instancing machinery pins exactly those axes -- correct, because their final coordinates are constants in the space the variation tables live in. This effectively reverts the special-casing from "[subset] Skip glyf instancing and hmtx MVAR for avar2", "[subset] Skip remaining instancing paths for avar2" and "[subset] Skip GPOS value format optimization for avar2" in favor of the emptiness of the plan's instancing state. cvar and MVAR also instance (rather than pass through) when self-contained axes exist. avar-side changes: _subset_avar2 skips dropped axes for privatization and offset compensation, writes the DeltaSetIndexMap over the retained axes only, and rebases the IVS with avar2_axes_location; SegmentMaps::subset picks the right location map; fvar InstanceRecords drop the removed axes' coordinates. The avar2 variation culling now also hooks the decompiled instancing paths (tuple_variations_t::cull_unreachable, called from item_variations_t::instantiate and gvar's glyph_variations_t), since self-contained axes route those tables through instantiation, where the byte-level culling paths don't apply. Under non-avar2, all of this is a no-op (has_avar2 was always false in the flipped guards). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
7c87fea07e
commit
c752b532bd
24 files changed
+198
-74
No files matched your search
@@ -2437,7 +2437,7 @@ struct COLR
|
||||
return_trace (true);
|
||||
|
||||
const ItemVariationStore& var_store = this+varStore;
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
{
|
||||
item_variations_t item_vars;
|
||||
/* turn off varstore optimization when varIdxMap is null, so we maintain
|
||||
@@ -2595,9 +2595,9 @@ struct COLR
|
||||
* after instancing */
|
||||
if (!subset_varstore (c, colr_prime)) return_trace (false);
|
||||
|
||||
ItemVarStoreInstancer instancer (c->plan->has_avar2 ? nullptr : get_var_store_ptr (),
|
||||
c->plan->has_avar2 ? nullptr : get_delta_set_index_map_ptr (),
|
||||
c->plan->has_avar2 ? hb_array<const int> () : c->plan->normalized_coords.as_array ());
|
||||
ItemVarStoreInstancer instancer (c->plan->normalized_coords ? get_var_store_ptr () : nullptr,
|
||||
c->plan->normalized_coords ? get_delta_set_index_map_ptr () : nullptr,
|
||||
c->plan->normalized_coords.as_array ());
|
||||
|
||||
if (!colr_prime->baseGlyphList.serialize_subset (c, baseGlyphList, this, instancer))
|
||||
return_trace (false);
|
||||
|
||||
@@ -678,7 +678,7 @@ struct GDEFVersion1_2
|
||||
if (unlikely (!c->serializer->embed (varStore))) return_trace (false);
|
||||
if (c->plan->all_axes_pinned)
|
||||
out->varStore = 0;
|
||||
else if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
else if (c->plan->normalized_coords)
|
||||
{
|
||||
if (varStore)
|
||||
{
|
||||
|
||||
@@ -156,7 +156,7 @@ struct PairPosFormat1_3
|
||||
|
||||
hb_pair_t<unsigned, unsigned> newFormats = hb_pair (valueFormat[0], valueFormat[1]);
|
||||
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
{
|
||||
/* all device flags will be dropped when full instancing, no need to strip
|
||||
* hints, also do not strip emtpy cause we don't compute the new default
|
||||
|
||||
@@ -312,7 +312,7 @@ struct PairPosFormat2_4 : ValueBase
|
||||
|
||||
hb_pair_t<unsigned, unsigned> newFormats = hb_pair (valueFormat1, valueFormat2);
|
||||
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
{
|
||||
/* in case of full instancing, all var device flags will be dropped so no
|
||||
* need to strip hints here */
|
||||
|
||||
@@ -149,7 +149,7 @@ struct SinglePosFormat1 : ValueBase
|
||||
|
||||
unsigned new_format = valueFormat;
|
||||
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
{
|
||||
new_format = valueFormat.get_effective_format (values.arrayZ, false, false, this, &c->plan->layout_variation_idx_delta_map);
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ struct SinglePosFormat2 : ValueBase
|
||||
;
|
||||
|
||||
unsigned new_format = compute_effective_format (c->plan->source, it,
|
||||
bool (c->plan->normalized_coords) && !c->plan->has_avar2,
|
||||
bool (c->plan->normalized_coords),
|
||||
bool (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING),
|
||||
c->plan->has_gdef_varstore,
|
||||
&c->plan->layout_variation_idx_delta_map);
|
||||
|
||||
@@ -64,7 +64,7 @@ _add_head_and_set_loca_version (hb_subset_plan_t *plan, bool use_short_loca)
|
||||
|
||||
head *head_prime = (head *) hb_blob_get_data_writable (head_prime_blob, nullptr);
|
||||
head_prime->indexToLocFormat = use_short_loca ? 0 : 1;
|
||||
if (plan->normalized_coords && !plan->has_avar2)
|
||||
if (plan->normalized_coords)
|
||||
{
|
||||
head_prime->xMin = plan->head_maxp_info.xMin;
|
||||
head_prime->xMax = plan->head_maxp_info.xMax;
|
||||
|
||||
+14
-1
@@ -86,7 +86,7 @@ struct glyf
|
||||
}
|
||||
|
||||
hb_font_t *font = nullptr;
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
{
|
||||
font = _create_font_for_instancing (c->plan);
|
||||
if (unlikely (!font))
|
||||
@@ -614,6 +614,19 @@ glyf::_create_font_for_instancing (const hb_subset_plan_t *plan) const
|
||||
hb_font_t *font = hb_font_create (plan->source);
|
||||
if (unlikely (font == hb_font_get_empty ())) return nullptr;
|
||||
|
||||
#ifndef HB_NO_VAR
|
||||
if (plan->has_avar2)
|
||||
{
|
||||
/* Under avar2, instancing applies only to the self-contained pins,
|
||||
* whose constant final coordinates the plan holds in normalized_coords.
|
||||
* Setting user-space variations would run the full avar2 mapping and
|
||||
* bake contributions that remain live in the instance's variations. */
|
||||
hb_font_set_var_coords_normalized (font, plan->normalized_coords.arrayZ,
|
||||
plan->normalized_coords.length);
|
||||
return font;
|
||||
}
|
||||
#endif
|
||||
|
||||
hb_vector_t<hb_variation_t> vars;
|
||||
if (unlikely (!vars.alloc (plan->user_axes_location.get_population (), true)))
|
||||
{
|
||||
|
||||
@@ -66,7 +66,7 @@ struct head
|
||||
head *out = c->serializer->embed (this);
|
||||
if (unlikely (!out)) return_trace (false);
|
||||
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
{
|
||||
if (unlikely (!c->serializer->check_assign (out->xMin, c->plan->head_maxp_info.xMin,
|
||||
HB_SERIALIZE_ERROR_INT_OVERFLOW)))
|
||||
|
||||
@@ -89,7 +89,7 @@ struct hmtxvmtx
|
||||
c->serializer->check_assign (table->numberOfLongMetrics, num_hmetrics, HB_SERIALIZE_ERROR_INT_OVERFLOW);
|
||||
|
||||
#ifndef HB_NO_VAR
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
{
|
||||
auto &MVAR = *c->plan->source->table.MVAR;
|
||||
if (T::is_horizontal)
|
||||
|
||||
@@ -726,7 +726,7 @@ struct BASE
|
||||
TRACE_SUBSET (this);
|
||||
if (!c->serializer->allocate_size<Offset32To<ItemVariationStore>> (Offset32To<ItemVariationStore>::static_size))
|
||||
return_trace (false);
|
||||
if (!c->plan->normalized_coords || c->plan->has_avar2)
|
||||
if (!c->plan->normalized_coords)
|
||||
return_trace (out->varStore.serialize_subset (c, varStore, this, c->plan->base_varstore_inner_maps.as_array ()));
|
||||
|
||||
if (c->plan->all_axes_pinned)
|
||||
|
||||
@@ -111,7 +111,7 @@ struct maxp
|
||||
if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
|
||||
drop_hint_fields (dest_v1);
|
||||
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
instancing_update_fields (c->plan->head_maxp_info, dest_v1);
|
||||
}
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ struct OS2
|
||||
if (unlikely (!os2_prime)) return_trace (false);
|
||||
|
||||
#ifndef HB_NO_VAR
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
{
|
||||
auto &MVAR = *c->plan->source->table.MVAR;
|
||||
auto *table = os2_prime;
|
||||
|
||||
@@ -103,7 +103,7 @@ struct post
|
||||
return_trace (false);
|
||||
|
||||
#ifndef HB_NO_VAR
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
{
|
||||
auto &MVAR = *c->plan->source->table.MVAR;
|
||||
auto *table = post_prime;
|
||||
|
||||
@@ -264,9 +264,14 @@ struct SegmentMaps : Array16Of<AxisValueMap>
|
||||
* We should instead keep the design coords in the shape plan and use
|
||||
* those. unmap_axis_range needs to be killed. */
|
||||
|
||||
/* avar mapped normalized axis range*/
|
||||
/* avar mapped normalized axis range. Under avar2, axes_location holds
|
||||
* only the self-contained pins for the other tables; avar itself uses
|
||||
* the intermediate-space ranges of all restricted axes. */
|
||||
const auto &axes_location = c->plan->has_avar2
|
||||
? c->plan->avar2_axes_location
|
||||
: c->plan->axes_location;
|
||||
Triple *axis_range;
|
||||
if (!c->plan->axes_location.has (axis_tag, &axis_range))
|
||||
if (!axes_location.has (axis_tag, &axis_range))
|
||||
return c->serializer->embed (*this);
|
||||
|
||||
TripleDistances *axis_triple_distances;
|
||||
@@ -767,7 +772,7 @@ struct avar
|
||||
item_variations_t item_vars;
|
||||
if (!item_vars.create_from_item_varstore (var_store, c->plan->axes_old_index_tag_map))
|
||||
return false;
|
||||
if (!item_vars.instantiate_tuple_vars_no_region_build (c->plan->axes_location,
|
||||
if (!item_vars.instantiate_tuple_vars_no_region_build (c->plan->avar2_axes_location,
|
||||
c->plan->axes_triple_distances))
|
||||
return false;
|
||||
|
||||
@@ -793,6 +798,7 @@ struct avar
|
||||
hb_hashmap_t<uint32_t, unsigned> varidx_ref_count;
|
||||
for (unsigned i = 0; i < axisCount; i++)
|
||||
{
|
||||
if (!c->plan->axes_index_map.has (i)) continue; /* self-contained: dropped */
|
||||
uint32_t varidx = new_varidx_mapping[i];
|
||||
if (varidx == HB_OT_LAYOUT_NO_VARIATIONS_INDEX) continue;
|
||||
unsigned *count;
|
||||
@@ -806,7 +812,8 @@ struct avar
|
||||
hb_tag_t *axis_tag_ptr;
|
||||
/* Only axes that will receive offset compensation (restricted or
|
||||
* pinned) can contaminate a shared row. */
|
||||
if (!c->plan->axes_old_index_tag_map.has (i, &axis_tag_ptr) ||
|
||||
if (!c->plan->axes_index_map.has (i) ||
|
||||
!c->plan->axes_old_index_tag_map.has (i, &axis_tag_ptr) ||
|
||||
!c->plan->user_axes_location.has (*axis_tag_ptr))
|
||||
continue;
|
||||
uint32_t varidx = new_varidx_mapping[i];
|
||||
@@ -833,6 +840,11 @@ struct avar
|
||||
continue;
|
||||
hb_tag_t axis_tag = *axis_tag_ptr;
|
||||
|
||||
/* Self-contained pinned axes are removed from fvar/avar; their
|
||||
* contribution is baked into the variation tables instead. */
|
||||
if (!c->plan->axes_index_map.has (i))
|
||||
continue;
|
||||
|
||||
Triple *new_user;
|
||||
if (c->plan->user_axes_location.has (axis_tag, &new_user))
|
||||
{
|
||||
@@ -1057,7 +1069,10 @@ struct avar
|
||||
* We serialize each sub-object via push/pop_pack, write the tail
|
||||
* struct inline, and link offsets to the avar table start. */
|
||||
|
||||
/* Serialize DeltaSetIndexMap (push a new object) */
|
||||
/* Serialize DeltaSetIndexMap (push a new object). Entries cover the
|
||||
* RETAINED axes only (self-contained pinned axes are removed from
|
||||
* fvar), in their retained order. */
|
||||
unsigned retained_axis_count = c->plan->axes_index_map.get_population ();
|
||||
hb_serialize_context_t::objidx_t packed_map;
|
||||
{
|
||||
/* Compute width and inner_bit_count for the mapping.
|
||||
@@ -1067,6 +1082,7 @@ struct avar
|
||||
unsigned max_outer = 0, max_inner = 0;
|
||||
for (unsigned i = 0; i < axisCount; i++)
|
||||
{
|
||||
if (!c->plan->axes_index_map.has (i)) continue;
|
||||
uint32_t varidx = new_varidx_mapping[i];
|
||||
if (varidx == HB_OT_LAYOUT_NO_VARIATIONS_INDEX)
|
||||
{
|
||||
@@ -1111,13 +1127,14 @@ struct avar
|
||||
|
||||
auto *map_count_field = c->serializer->allocate_size<HBUINT16> (HBUINT16::static_size);
|
||||
if (unlikely (!map_count_field)) { c->serializer->pop_discard (); return false; }
|
||||
*map_count_field = axisCount;
|
||||
*map_count_field = retained_axis_count;
|
||||
|
||||
HBUINT8 *p = c->serializer->allocate_size<HBUINT8> (width * axisCount);
|
||||
HBUINT8 *p = c->serializer->allocate_size<HBUINT8> (width * retained_axis_count);
|
||||
if (unlikely (!p)) { c->serializer->pop_discard (); return false; }
|
||||
|
||||
for (unsigned i = 0; i < axisCount; i++)
|
||||
{
|
||||
if (!c->plan->axes_index_map.has (i)) continue;
|
||||
uint32_t varidx = new_varidx_mapping[i];
|
||||
unsigned o = varidx >> 16;
|
||||
unsigned in = varidx & 0xFFFF;
|
||||
|
||||
@@ -1305,6 +1305,22 @@ struct TupleVariationData
|
||||
}
|
||||
|
||||
public:
|
||||
/* avar2 partial-instancing culling: drop tuples whose region a partial
|
||||
* instance can never reach (hb_subset_plan_t::avar2_reachable_ranges). */
|
||||
void cull_unreachable (const hb_hashmap_t<hb_tag_t, Triple> &reachable_ranges)
|
||||
{
|
||||
unsigned j = 0;
|
||||
for (unsigned i = 0; i < tuple_vars.length; i++)
|
||||
{
|
||||
if (_hb_avar2_region_is_dead (tuple_vars.arrayZ[i].axis_tuples, reachable_ranges))
|
||||
continue;
|
||||
if (i != j)
|
||||
tuple_vars.arrayZ[j] = std::move (tuple_vars.arrayZ[i]);
|
||||
j++;
|
||||
}
|
||||
tuple_vars.shrink (j);
|
||||
}
|
||||
|
||||
bool instantiate (const hb_hashmap_t<hb_tag_t, Triple>& normalized_axes_location,
|
||||
const hb_hashmap_t<hb_tag_t, TripleDistances>& axes_triple_distances,
|
||||
optimize_scratch_t &scratch,
|
||||
@@ -1839,6 +1855,10 @@ struct item_variations_t
|
||||
{
|
||||
if (!create_from_item_varstore (varStore, plan->axes_old_index_tag_map, inner_maps))
|
||||
return false;
|
||||
/* avar2 partial instancing: cull unreachable regions. */
|
||||
if (plan->has_avar2 && plan->avar2_reachable_ranges.get_population ())
|
||||
for (tuple_variations_t& tuple_vars : vars)
|
||||
tuple_vars.cull_unreachable (plan->avar2_reachable_ranges);
|
||||
if (!instantiate_tuple_vars (plan->axes_location, plan->axes_triple_distances))
|
||||
return false;
|
||||
return as_item_varstore (optimize, use_no_variation_idx);
|
||||
|
||||
@@ -107,8 +107,9 @@ struct InstanceRecord
|
||||
if (!axis_coord_pinned_or_within_axis_range (coords, i, *axis_limit))
|
||||
return_trace (false);
|
||||
|
||||
//skip pinned axis (but not for avar2, where pinned axes stay in fvar)
|
||||
if (axis_limit->is_point () && !c->plan->has_avar2)
|
||||
//skip axes dropped from fvar (pinned; or self-contained under avar2,
|
||||
//where other pinned axes stay in fvar as hidden)
|
||||
if (axis_limit->is_point () && !c->plan->axes_index_map.has (i))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +150,9 @@ struct glyph_variations_t
|
||||
contour_point_vector_t *all_points;
|
||||
if (!plan->new_gid_contour_points_map.has (new_gid, &all_points))
|
||||
return false;
|
||||
/* avar2 partial instancing: cull unreachable tuples. */
|
||||
if (plan->has_avar2 && plan->avar2_reachable_ranges.get_population ())
|
||||
glyph_variations[i].cull_unreachable (plan->avar2_reachable_ranges);
|
||||
if (!glyph_variations[i].instantiate (plan->axes_location, plan->axes_triple_distances, scratch, &pool, all_points, iup_optimize))
|
||||
return false;
|
||||
}
|
||||
@@ -428,7 +431,7 @@ struct gvar_GVAR
|
||||
if (c->plan->all_axes_pinned)
|
||||
return_trace (false);
|
||||
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
return_trace (instantiate (c));
|
||||
|
||||
unsigned glyph_count = version.to_int () ? c->plan->source->get_num_glyphs () : 0;
|
||||
|
||||
@@ -369,7 +369,7 @@ struct HVARVVAR
|
||||
out->version.major = 1;
|
||||
out->version.minor = 0;
|
||||
|
||||
if (c->plan->normalized_coords && !c->plan->has_avar2)
|
||||
if (c->plan->normalized_coords)
|
||||
{
|
||||
item_variations_t item_vars;
|
||||
if (!item_vars.instantiate (this+varStore, c->plan,
|
||||
|
||||
@@ -502,7 +502,7 @@ struct cff2_subset_plan
|
||||
orig_fdcount = acc.fdArray->count;
|
||||
|
||||
drop_hints = plan->flags & HB_SUBSET_FLAGS_NO_HINTING;
|
||||
pinned = (bool) plan->normalized_coords && !plan->has_avar2;
|
||||
pinned = (bool) plan->normalized_coords;
|
||||
normalized_coords = plan->normalized_coords;
|
||||
head_maxp_info = plan->head_maxp_info;
|
||||
hmtx_map = &plan->hmtx_map;
|
||||
|
||||
@@ -143,6 +143,17 @@ HB_SUBSET_PLAN_MEMBER (hb_hashmap_t E(<hb_tag_t, Triple>), old_intermediates)
|
||||
//variation tuples/regions that a partial instance can never reach.
|
||||
HB_SUBSET_PLAN_MEMBER (hb_hashmap_t E(<hb_tag_t, Triple>), avar2_reachable_ranges)
|
||||
|
||||
//avar2: intermediate-space (post-avar-v1) axis ranges of all restricted
|
||||
//axes, used by avar itself for segment-map renormalization and IVS
|
||||
//rebasing. Under avar2, axes_location instead holds only the
|
||||
//self-contained pins (final space) for the other tables to instance.
|
||||
HB_SUBSET_PLAN_MEMBER (hb_hashmap_t E(<hb_tag_t, Triple>), avar2_axes_location)
|
||||
|
||||
//avar2: self-contained pinned axes -> constant old-space final coord.
|
||||
//These axes are removed from fvar/avar entirely; their contribution is
|
||||
//baked into the variation tables like an ordinary pin at that coord.
|
||||
HB_SUBSET_PLAN_MEMBER (hb_hashmap_t E(<hb_tag_t, double>), avar2_self_contained)
|
||||
|
||||
//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
|
||||
|
||||
+99
-42
@@ -136,39 +136,62 @@
|
||||
if (!box.has (tag, &identity)) return;
|
||||
|
||||
double dmin = 0.0, dmax = 0.0;
|
||||
bool bounded = true;
|
||||
uint32_t varidx = varidx_map->map (i);
|
||||
if (varidx != HB_OT_LAYOUT_NO_VARIATIONS_INDEX)
|
||||
{
|
||||
unsigned outer = varidx >> 16;
|
||||
unsigned inner = varidx & 0xFFFF;
|
||||
if (outer >= var_store->get_sub_table_count ()) continue;
|
||||
const OT::VarData &vd = var_store->get_sub_table (outer);
|
||||
if (inner >= vd.get_item_count ()) continue;
|
||||
const OT::HBUINT8 *delta_bytes = vd.get_delta_bytes ();
|
||||
unsigned row_size = vd.get_row_size ();
|
||||
unsigned region_count = vd.get_region_index_count ();
|
||||
for (unsigned r = 0; r < region_count; r++)
|
||||
if (outer >= var_store->get_sub_table_count ()) bounded = false;
|
||||
else
|
||||
{
|
||||
int delta = vd.get_item_delta_fast (inner, r, delta_bytes, row_size);
|
||||
if (!delta) continue;
|
||||
unsigned region_idx = vd.get_region_index (r);
|
||||
if (region_idx >= regions.length) continue;
|
||||
double smin = 1.0, smax = 1.0;
|
||||
for (const auto &_ : regions[region_idx])
|
||||
{
|
||||
hb_pair_t<double, double> *input;
|
||||
double blo = -1.0, bhi = +1.0;
|
||||
if (box.has (_.first, &input)) { blo = input->first; bhi = input->second; }
|
||||
double tmin, tmax;
|
||||
_tent_value_range (_.second, blo, bhi, &tmin, &tmax);
|
||||
smin *= tmin;
|
||||
smax *= tmax;
|
||||
if (smax == 0.0) break;
|
||||
}
|
||||
if (delta > 0) { dmin += smin * delta; dmax += smax * delta; }
|
||||
else { dmin += smax * delta; dmax += smin * delta; }
|
||||
const OT::VarData &vd = var_store->get_sub_table (outer);
|
||||
if (inner >= vd.get_item_count ()) bounded = false;
|
||||
else
|
||||
{
|
||||
const OT::HBUINT8 *delta_bytes = vd.get_delta_bytes ();
|
||||
unsigned row_size = vd.get_row_size ();
|
||||
unsigned region_count = vd.get_region_index_count ();
|
||||
for (unsigned r = 0; r < region_count && bounded; r++)
|
||||
{
|
||||
int delta = vd.get_item_delta_fast (inner, r, delta_bytes, row_size);
|
||||
if (!delta) continue;
|
||||
unsigned region_idx = vd.get_region_index (r);
|
||||
if (region_idx >= regions.length) { bounded = false; break; }
|
||||
double smin = 1.0, smax = 1.0;
|
||||
for (const auto &_ : regions[region_idx])
|
||||
{
|
||||
hb_pair_t<double, double> *input;
|
||||
double blo = -1.0, bhi = +1.0;
|
||||
if (box.has (_.first, &input)) { blo = input->first; bhi = input->second; }
|
||||
double tmin, tmax;
|
||||
_tent_value_range (_.second, blo, bhi, &tmin, &tmax);
|
||||
smin *= tmin;
|
||||
smax *= tmax;
|
||||
if (smax == 0.0) break;
|
||||
}
|
||||
if (delta > 0) { dmin += smin * delta; dmax += smax * delta; }
|
||||
else { dmin += smax * delta; dmax += smin * delta; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!bounded)
|
||||
continue; /* malformed row: no constraint, not self-contained */
|
||||
|
||||
/* A pinned axis whose delta is constant over the box is self-contained:
|
||||
* its final coordinate is a constant. It can be removed from fvar/avar
|
||||
* and its contribution baked into the variation tables like an ordinary
|
||||
* pin at that coordinate (in old final space). */
|
||||
Triple *user;
|
||||
if (dmin == dmax &&
|
||||
plan->user_axes_location.has (tag, &user) && user->is_point ())
|
||||
{
|
||||
double v = hb_clamp (identity->first + dmin / 16384.0, -1.0, +1.0);
|
||||
v = (double) roundf ((float) (v * 16384.0)) / 16384.0;
|
||||
if (!plan->avar2_self_contained.set (tag, v)) return;
|
||||
continue; /* axis is dropped; no region can reference it afterwards */
|
||||
}
|
||||
|
||||
/* Pad by one F2Dot14 unit against rounding differences with the
|
||||
* runtime's fixed-point evaluation. */
|
||||
@@ -189,6 +212,17 @@
|
||||
{
|
||||
hb_font_t *font = hb_font_create (plan->source);
|
||||
|
||||
if (plan->has_avar2)
|
||||
{
|
||||
/* Under avar2, instancing applies only to the self-contained pins,
|
||||
* whose constant final coordinates the plan holds in normalized_coords.
|
||||
* Setting user-space variations would run the full avar2 mapping and
|
||||
* bake contributions that remain live in the instance's variations. */
|
||||
hb_font_set_var_coords_normalized (font, plan->normalized_coords.arrayZ,
|
||||
plan->normalized_coords.length);
|
||||
return font;
|
||||
}
|
||||
|
||||
hb_vector_t<hb_variation_t> vars;
|
||||
if (!vars.alloc (plan->user_axes_location.get_population ())) {
|
||||
hb_font_destroy (font);
|
||||
@@ -400,39 +434,62 @@ normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan)
|
||||
hb_tag_t axis_tag = _.second.get_axis_tag ();
|
||||
if (plan->user_axes_location.has (axis_tag))
|
||||
{
|
||||
/* Store intermediate-space coords for offset compensation */
|
||||
/* Store intermediate-space coords for offset compensation and
|
||||
* for avar's own segment-map renormalization and IVS rebasing. */
|
||||
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]));
|
||||
|
||||
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);
|
||||
plan->avar2_axes_location.set (axis_tag, Triple ((double) normalized_mins[i],
|
||||
(double) normalized_defaults[i],
|
||||
(double) normalized_maxs[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/* For avar2, keep ALL axes in axes_index_map (including pinned ones),
|
||||
* so pinned axes remain in fvar as hidden. */
|
||||
/* Reachable-range computation also detects self-contained pinned
|
||||
* axes: pinned axes whose final coordinate is constant. */
|
||||
_compute_avar2_reachable_ranges (plan, axes, avar_table);
|
||||
|
||||
/* Keep all axes in fvar (pinned ones as hidden), EXCEPT self-contained
|
||||
* pinned axes, which are removed entirely. */
|
||||
plan->axes_index_map.reset ();
|
||||
plan->axis_tags.reset ();
|
||||
unsigned retained_axis_idx = 0;
|
||||
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);
|
||||
if (plan->avar2_self_contained.has (axis_tag))
|
||||
continue;
|
||||
plan->axes_index_map.set (i, retained_axis_idx++);
|
||||
plan->axis_tags.push (axis_tag);
|
||||
}
|
||||
plan->all_axes_pinned = false;
|
||||
|
||||
_compute_avar2_reachable_ranges (plan, axes, avar_table);
|
||||
/* The other tables see ONLY the self-contained pins, as an ordinary
|
||||
* partial instancing in old final-coordinate space; the standard
|
||||
* instancing machinery bakes those axes' contributions in. The
|
||||
* remaining restriction is carried entirely by avar. */
|
||||
plan->axes_location.reset ();
|
||||
if (plan->avar2_self_contained.get_population ())
|
||||
{
|
||||
bool sc_pinned_at_default = true;
|
||||
for (auto _ : plan->avar2_self_contained)
|
||||
{
|
||||
plan->axes_location.set (_.first, Triple (_.second, _.second, _.second));
|
||||
if (_.second != 0.0)
|
||||
sc_pinned_at_default = false;
|
||||
}
|
||||
for (const auto& _ : + hb_enumerate (axes))
|
||||
{
|
||||
double *v;
|
||||
plan->normalized_coords[_.first] =
|
||||
plan->avar2_self_contained.has (_.second.get_axis_tag (), &v)
|
||||
? (int) roundf ((float) (*v * 16384.0)) : 0;
|
||||
}
|
||||
plan->pinned_at_default = sc_pinned_at_default;
|
||||
}
|
||||
else
|
||||
plan->normalized_coords.shrink (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -30,7 +30,8 @@ bool _hb_subset_table_var (hb_subset_plan_t *plan, hb_vector_t<char> &buf, hb_t
|
||||
case HB_TAG('c','v','a','r'):
|
||||
/* TODO: For avar2 partial instancing, cull unreachable tuple
|
||||
* variations (avar2_reachable_ranges) instead of passing through. */
|
||||
if (plan->user_axes_location.is_empty () || plan->has_avar2)
|
||||
if (plan->user_axes_location.is_empty () ||
|
||||
(plan->has_avar2 && !plan->normalized_coords))
|
||||
*success = _hb_subset_table_passthrough (plan, tag);
|
||||
else
|
||||
*success = _hb_subset_table<const OT::cvar> (plan, buf);
|
||||
@@ -38,7 +39,8 @@ bool _hb_subset_table_var (hb_subset_plan_t *plan, hb_vector_t<char> &buf, hb_t
|
||||
case HB_TAG('M','V','A','R'):
|
||||
/* TODO: For avar2 partial instancing, cull unreachable VarStore
|
||||
* regions (avar2_reachable_ranges) instead of passing through. */
|
||||
if (plan->user_axes_location.is_empty () || plan->has_avar2)
|
||||
if (plan->user_axes_location.is_empty () ||
|
||||
(plan->has_avar2 && !plan->normalized_coords))
|
||||
*success = _hb_subset_table_passthrough (plan, tag);
|
||||
else
|
||||
*success = _hb_subset_table<const OT::MVAR> (plan, buf);
|
||||
|
||||
+1
-1
@@ -295,7 +295,7 @@ _subset_table (hb_subset_plan_t *plan,
|
||||
case HB_TAG('c','v','t',' '):
|
||||
#ifndef HB_NO_VAR
|
||||
if (_is_table_present (plan->source, HB_TAG('c','v','a','r')) &&
|
||||
plan->normalized_coords && !plan->pinned_at_default && !plan->has_avar2)
|
||||
plan->normalized_coords && !plan->pinned_at_default)
|
||||
{
|
||||
auto &cvar = *plan->source->table.cvar;
|
||||
return OT::cvar::add_cvt_and_apply_deltas (plan, cvar.get_tuple_var_data (), &cvar);
|
||||
|
||||
Reference in new issue
Block a user