mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 23:41:03 +01:00
[subset] Allow instancing axes unrelated to VARC (#6265)
Replace the blanket VARC instancing rejection with validation of the axes referenced by retained components, variation regions, and nested conditions. Remap those indices when unrelated axes are removed, while keeping passthrough VARC incompatible with instancing. Preserve component-internal variation data during avar2 instancing by avoiding culling based on font-level reachable ranges. Add drawing comparisons and rejection tests with reproducible fixtures, including hidden component axes and non-default unrelated-axis pins. Serialize sparse-region axis references using the revised VARC format. Regenerate the fixtures without changing their logical VARC contents or other table bytes, apart from the head checksum adjustment. Validation: meson test -C build (283 passed); subset suite (130 passed); C++11 compile checks with HB_NO_VAR and HB_NO_VAR_COMPOSITES. Assisted-by: Codex
This commit is contained in:
1 parent
a2ccf95182
commit
1bf17d7295
9 files changed
+327
-48
No files matched your search
@@ -1,3 +1,6 @@
|
||||
- Support instancing axes not referenced by retained `VARC` data.
|
||||
|
||||
|
||||
Overview of changes leading to 14.6.0
|
||||
Monday, October 5, 2026
|
||||
=====================================
|
||||
|
||||
@@ -97,6 +97,18 @@ struct varc_subset_plan_t
|
||||
|
||||
bool create_maps ()
|
||||
{
|
||||
const auto *plan = subset_context->plan;
|
||||
if (!plan->user_axes_location.is_empty ())
|
||||
{
|
||||
/* Instancing axes referenced by VARC is not supported. Keep this
|
||||
* restriction for avar2 as well; component coordinate overrides
|
||||
* and their variation data need special handling. */
|
||||
axis_map = &axes_index_map;
|
||||
for (auto _ : plan->axes_index_map)
|
||||
if (!plan->user_axes_location.has (plan->axes_old_index_tag_map.get (_.first)))
|
||||
axes_index_map.set (_.first, _.second);
|
||||
if (unlikely (axes_index_map.in_error ())) return false;
|
||||
}
|
||||
condition_map.add_set (&condition_indices);
|
||||
axis_indices_map.add_set (&axis_indices);
|
||||
return !condition_map.in_error () && !axis_indices_map.in_error () &&
|
||||
@@ -146,11 +158,31 @@ struct varc_subset_plan_t
|
||||
bool select_axis_indices ()
|
||||
{
|
||||
if (unlikely (!selected_axis_indices.alloc_exact (
|
||||
axis_indices_map.get_population ())))
|
||||
axis_indices_map.get_population ()) ||
|
||||
(axis_map && !axis_indices_data.resize (
|
||||
axis_indices_map.get_population ()))))
|
||||
return false;
|
||||
for (unsigned i = 0; i < axis_indices_map.get_population (); i++)
|
||||
{
|
||||
hb_ubytes_t bytes = source_axis_indices[axis_indices_map.backward (i)];
|
||||
if (axis_map)
|
||||
{
|
||||
hb_vector_t<int> indices;
|
||||
const HBUINT8 *p = (const HBUINT8 *) bytes.arrayZ;
|
||||
if (unlikely (!TupleValues::decompile (p, indices, p + bytes.length, true)))
|
||||
return false;
|
||||
for (int &index : indices)
|
||||
{
|
||||
if (unlikely (!axis_map->has (index))) return false;
|
||||
index = axis_map->get (index);
|
||||
}
|
||||
auto &data = axis_indices_data[i];
|
||||
/* One control byte and at most four data bytes per value. */
|
||||
unsigned size = hb_unsigned_mul_saturate (indices.length, 5u);
|
||||
if (unlikely (size == UINT_MAX || !data.resize_dirty (size))) return false;
|
||||
data.shrink (TupleValues::compile_unsafe (indices.as_array (), data.arrayZ));
|
||||
bytes = data.as_array ();
|
||||
}
|
||||
axis_indices_data_size = hb_unsigned_add_saturate (axis_indices_data_size,
|
||||
bytes.length);
|
||||
selected_axis_indices.push (bytes);
|
||||
@@ -184,7 +216,10 @@ struct varc_subset_plan_t
|
||||
hb_vector_t<hb_ubytes_t> records;
|
||||
|
||||
hb_vector_t<hb_ubytes_t> selected_axis_indices;
|
||||
hb_vector_t<hb_vector_t<unsigned char>> axis_indices_data;
|
||||
unsigned axis_indices_data_size = 0;
|
||||
hb_map_t axes_index_map;
|
||||
const hb_map_t *axis_map = nullptr;
|
||||
|
||||
private:
|
||||
bool auxiliary_indices_unchanged () const
|
||||
@@ -332,12 +367,6 @@ VARC::subset (hb_subset_context_t *c) const
|
||||
return false;
|
||||
};
|
||||
|
||||
/* VARC instancing is not supported yet. In particular, copying the
|
||||
* auxiliary lists while fvar axes are removed would leave stale axis
|
||||
* indices in the table. */
|
||||
if (unlikely (!c->plan->user_axes_location.is_empty ()))
|
||||
return_trace (fail ());
|
||||
|
||||
const Coverage &source_coverage = this+coverage;
|
||||
const CFF2Index &source_records = this+glyphRecords;
|
||||
const ConditionList &source_conditions = this+conditionList;
|
||||
@@ -373,7 +402,8 @@ VARC::subset (hb_subset_context_t *c) const
|
||||
!out->conditionList.serialize_serialize (c->serializer,
|
||||
&source_conditions,
|
||||
subset_plan.condition_map,
|
||||
subset_plan.varidx_map)) ||
|
||||
subset_plan.varidx_map,
|
||||
subset_plan.axis_map)) ||
|
||||
(subset_plan.axis_indices_map.get_population () &&
|
||||
!out->axisIndicesList.serialize_serialize (c->serializer,
|
||||
subset_plan.selected_axis_indices.iter (),
|
||||
@@ -381,7 +411,8 @@ VARC::subset (hb_subset_context_t *c) const
|
||||
(subset_plan.var_indices.get_population () &&
|
||||
!out->varStore.serialize_serialize (c->serializer,
|
||||
&source_var_store,
|
||||
subset_plan.var_inner_maps.as_array ())) ||
|
||||
subset_plan.var_inner_maps.as_array (),
|
||||
subset_plan.axis_map)) ||
|
||||
!out->glyphRecords.serialize_serialize (c->serializer,
|
||||
subset_plan.records.iter (),
|
||||
&subset_plan.data_size)))
|
||||
|
||||
+54
-16
@@ -2602,10 +2602,25 @@ struct SparseVarRegionAxis
|
||||
return_trace (c->check_struct (this));
|
||||
}
|
||||
|
||||
bool serialize (hb_serialize_context_t *c) const
|
||||
bool serialize (hb_serialize_context_t *c,
|
||||
const SparseVarRegionAxis *src,
|
||||
const hb_map_t *axis_map)
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
return_trace (c->embed (this));
|
||||
auto *out = c->embed (src);
|
||||
if (unlikely (!out)) return_trace (false);
|
||||
if (axis_map)
|
||||
{
|
||||
if (unlikely (!axis_map->has (out->axisIndex)))
|
||||
{
|
||||
c->err (HB_SERIALIZE_ERROR_OTHER);
|
||||
return_trace (false);
|
||||
}
|
||||
if (unlikely (!c->check_assign (out->axisIndex, axis_map->get (out->axisIndex),
|
||||
HB_SERIALIZE_ERROR_INT_OVERFLOW)))
|
||||
return_trace (false);
|
||||
}
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -2933,12 +2948,14 @@ struct SparseVariationRegion
|
||||
}
|
||||
|
||||
bool serialize (hb_serialize_context_t *c,
|
||||
const SparseVariationRegion *src)
|
||||
const SparseVariationRegion *src,
|
||||
const hb_map_t *axis_map)
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
if (unlikely (!axes.serialize (c, (unsigned) src->axes.len))) return_trace (false);
|
||||
for (unsigned i = 0; i < axes.len; i++)
|
||||
if (unlikely (!axes[i].serialize_copy (c, src->axes[i], src)))
|
||||
if (unlikely (src->axes[i].is_null () ||
|
||||
!axes[i].serialize_serialize (c, &(src+src->axes[i]), axis_map)))
|
||||
return_trace (false);
|
||||
return_trace (true);
|
||||
}
|
||||
@@ -2986,7 +3003,8 @@ struct SparseVarRegionList
|
||||
|
||||
bool serialize (hb_serialize_context_t *c,
|
||||
const SparseVarRegionList *src,
|
||||
const hb_inc_bimap_t ®ion_map)
|
||||
const hb_inc_bimap_t ®ion_map,
|
||||
const hb_map_t *axis_map)
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
if (unlikely (!c->extend_min (this))) return_trace (false);
|
||||
@@ -2998,7 +3016,8 @@ struct SparseVarRegionList
|
||||
unsigned old_index = region_map.backward (i);
|
||||
if (unlikely (old_index >= src->regions.len ||
|
||||
!regions[i].serialize_serialize (c,
|
||||
&(src+src->regions[old_index]))))
|
||||
&(src+src->regions[old_index]),
|
||||
axis_map)))
|
||||
return_trace (false);
|
||||
}
|
||||
return_trace (true);
|
||||
@@ -3926,7 +3945,8 @@ struct MultiItemVariationStore
|
||||
|
||||
bool serialize (hb_serialize_context_t *c,
|
||||
const MultiItemVariationStore *src,
|
||||
const hb_array_t<const hb_inc_bimap_t> &inner_maps)
|
||||
const hb_array_t<const hb_inc_bimap_t> &inner_maps,
|
||||
const hb_map_t *axis_map)
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
if (unlikely (!c->extend_min (this) ||
|
||||
@@ -3947,7 +3967,7 @@ struct MultiItemVariationStore
|
||||
hb_inc_bimap_t region_map;
|
||||
region_map.add_set (®ion_indices);
|
||||
if (unlikely (region_indices.in_error () || region_map.in_error () ||
|
||||
!regions.serialize_serialize (c, &src_regions, region_map)))
|
||||
!regions.serialize_serialize (c, &src_regions, region_map, axis_map)))
|
||||
return_trace (false);
|
||||
|
||||
dataSets.len = set_count;
|
||||
@@ -4739,7 +4759,8 @@ struct Condition
|
||||
|
||||
bool serialize (hb_serialize_context_t *c,
|
||||
const Condition *src,
|
||||
const hb_map_t &varidx_map);
|
||||
const hb_map_t &varidx_map,
|
||||
const hb_map_t *axis_map = nullptr);
|
||||
|
||||
private:
|
||||
lookup_condition_subset_result_t subset_lookup_condition_impl (
|
||||
@@ -4779,7 +4800,8 @@ struct ConditionList
|
||||
bool serialize (hb_serialize_context_t *c,
|
||||
const ConditionList *src,
|
||||
const hb_inc_bimap_t &condition_map,
|
||||
const hb_map_t &varidx_map)
|
||||
const hb_map_t &varidx_map,
|
||||
const hb_map_t *axis_map)
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
if (unlikely (!c->extend_min (this))) return_trace (false);
|
||||
@@ -4790,7 +4812,7 @@ struct ConditionList
|
||||
unsigned old_index = condition_map.backward (i);
|
||||
if (unlikely (old_index >= src->conditions.len ||
|
||||
!conditions[i].serialize_serialize (
|
||||
c, &(src+src->conditions[old_index]), varidx_map)))
|
||||
c, &(src+src->conditions[old_index]), varidx_map, axis_map)))
|
||||
return_trace (false);
|
||||
}
|
||||
return_trace (true);
|
||||
@@ -4851,7 +4873,8 @@ Condition::collect_var_indices (hb_set_t *var_indices, unsigned depth,
|
||||
inline bool
|
||||
Condition::serialize (hb_serialize_context_t *c,
|
||||
const Condition *src,
|
||||
const hb_map_t &varidx_map)
|
||||
const hb_map_t &varidx_map,
|
||||
const hb_map_t *axis_map)
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
switch (src->u.format.v)
|
||||
@@ -4866,7 +4889,22 @@ Condition::serialize (hb_serialize_context_t *c,
|
||||
return_trace (true);
|
||||
}
|
||||
case 1:
|
||||
return_trace (bool (c->embed (&src->u.format1)));
|
||||
{
|
||||
auto *out = c->embed (&src->u.format1);
|
||||
if (unlikely (!out)) return_trace (false);
|
||||
if (axis_map)
|
||||
{
|
||||
if (unlikely (!axis_map->has (out->axisIndex)))
|
||||
{
|
||||
c->err (HB_SERIALIZE_ERROR_OTHER);
|
||||
return_trace (false);
|
||||
}
|
||||
if (unlikely (!c->check_assign (out->axisIndex, axis_map->get (out->axisIndex),
|
||||
HB_SERIALIZE_ERROR_INT_OVERFLOW)))
|
||||
return_trace (false);
|
||||
}
|
||||
return_trace (true);
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
auto *out = c->embed (&src->u.format2);
|
||||
@@ -4888,7 +4926,7 @@ Condition::serialize (hb_serialize_context_t *c,
|
||||
for (unsigned i = 0; i < out->conditions.len; i++)
|
||||
if (unlikely (!out->conditions[i].serialize_serialize (
|
||||
c, &(&src->u.format3+src->u.format3.conditions[i]),
|
||||
varidx_map)))
|
||||
varidx_map, axis_map)))
|
||||
return_trace (false);
|
||||
return_trace (true);
|
||||
}
|
||||
@@ -4902,7 +4940,7 @@ Condition::serialize (hb_serialize_context_t *c,
|
||||
for (unsigned i = 0; i < out->conditions.len; i++)
|
||||
if (unlikely (!out->conditions[i].serialize_serialize (
|
||||
c, &(&src->u.format4+src->u.format4.conditions[i]),
|
||||
varidx_map)))
|
||||
varidx_map, axis_map)))
|
||||
return_trace (false);
|
||||
return_trace (true);
|
||||
}
|
||||
@@ -4912,7 +4950,7 @@ Condition::serialize (hb_serialize_context_t *c,
|
||||
if (unlikely (!out ||
|
||||
!out->condition.serialize_serialize (
|
||||
c, &(&src->u.format5+src->u.format5.condition),
|
||||
varidx_map)))
|
||||
varidx_map, axis_map)))
|
||||
return_trace (false);
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
+18
-12
@@ -583,22 +583,28 @@ normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan)
|
||||
* (its 'pinned' path flattens ALL blends; lift this once
|
||||
* https://github.com/harfbuzz/harfbuzz/pull/4710 lands, porting
|
||||
* fontTools' instantiateCFF2 from
|
||||
* https://github.com/fonttools/fonttools/pull/3506), and VARC passes
|
||||
* through verbatim with explicit fvar axis indices that renumbering
|
||||
* would desynchronize. Such axes stay in fvar as ordinary hidden
|
||||
* pins. */
|
||||
bool detect_self_contained = true;
|
||||
for (hb_tag_t table_tag : { HB_TAG ('C','F','F','2'), HB_TAG ('V','A','R','C') })
|
||||
{
|
||||
hb_blob_t *blob = hb_face_reference_table (face, table_tag);
|
||||
if (hb_blob_get_length (blob))
|
||||
detect_self_contained = false;
|
||||
hb_blob_destroy (blob);
|
||||
}
|
||||
* https://github.com/fonttools/fonttools/pull/3506). Such axes stay
|
||||
* in fvar as ordinary hidden pins. VARC remaps its axis indices and
|
||||
* rejects instancing of axes it references. */
|
||||
hb_blob_t *cff2_blob = hb_face_reference_table (face, HB_TAG ('C','F','F','2'));
|
||||
bool detect_self_contained = !hb_blob_get_length (cff2_blob);
|
||||
hb_blob_destroy (cff2_blob);
|
||||
if (!_compute_avar2_reachable_ranges (plan, axes, avar_table,
|
||||
detect_self_contained))
|
||||
return false;
|
||||
|
||||
#ifndef HB_NO_VAR_COMPOSITES
|
||||
/* VARC overrides can reach coordinates outside the font-level
|
||||
* ranges. Do not cull variation data using those ranges. */
|
||||
if (!plan->drop_tables.has (HB_TAG ('V','A','R','C')))
|
||||
{
|
||||
hb_blob_t *varc_blob = hb_face_reference_table (face, HB_TAG ('V','A','R','C'));
|
||||
if (hb_blob_get_length (varc_blob))
|
||||
plan->avar2_reachable_ranges.reset ();
|
||||
hb_blob_destroy (varc_blob);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Keep all axes in fvar (pinned ones as hidden), EXCEPT self-contained
|
||||
* pinned axes, which are removed entirely. */
|
||||
plan->axes_index_map.reset ();
|
||||
|
||||
@@ -718,6 +718,7 @@ hb_subset_plan_t::hb_subset_plan_t (hb_face_t *face,
|
||||
#ifndef HB_NO_VAR_COMPOSITES
|
||||
if (!user_axes_location.is_empty () &&
|
||||
!input->sets.drop_tables->has (OT::VARC::tableTag) &&
|
||||
input->sets.no_subset_tables->has (OT::VARC::tableTag) &&
|
||||
face->table.VARC->has_data ())
|
||||
{
|
||||
check_success (false);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,68 @@
|
||||
"""Regenerate the fixtures using FontTools with the revised VARC format."""
|
||||
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
|
||||
from fontTools.ttLib import TTFont, newTable
|
||||
from fontTools.ttLib.tables import otTables
|
||||
from fontTools.ttLib.tables._f_v_a_r import Axis
|
||||
from fontTools.ttLib.tables.TupleVariation import TupleVariation
|
||||
|
||||
|
||||
def condition(format, **fields):
|
||||
result = otTables.ConditionTable()
|
||||
result.Format = format
|
||||
result.__dict__.update(fields)
|
||||
return result
|
||||
|
||||
|
||||
directory = Path(__file__).parent / "fonts"
|
||||
font = TTFont(directory / "varc-ac01-conditional.ttf", recalcTimestamp=False)
|
||||
# Load gvar before changing the axis order.
|
||||
variations = font["gvar"].variations
|
||||
for tag in reversed(("DUMY", "COND")):
|
||||
axis = Axis()
|
||||
axis.axisTag = tag
|
||||
axis.minValue, axis.defaultValue, axis.maxValue = -1, 0, 1
|
||||
axis.axisNameID = font["fvar"].axes[0].axisNameID
|
||||
font["fvar"].axes.insert(0, axis)
|
||||
|
||||
varc = font["VARC"].table
|
||||
varc.AxisIndicesList.Item = [[i + 2 for i in indices]
|
||||
for indices in varc.AxisIndicesList.Item]
|
||||
for region in varc.MultiVarStore.SparseVarRegionList.Region:
|
||||
for axis in region.SparseVarRegionAxis:
|
||||
axis.AxisIndex += 2
|
||||
|
||||
# COND is used only by nested conditions; DUMY is absent from VARC.
|
||||
weight_condition = varc.ConditionList.ConditionTable[0]
|
||||
weight_condition.AxisIndex += 2
|
||||
low = condition(1, AxisIndex=1, FilterRangeMinValue=-1, FilterRangeMaxValue=0)
|
||||
middle = condition(1, AxisIndex=1, FilterRangeMinValue=0, FilterRangeMaxValue=0.25)
|
||||
either = condition(4, ConditionTable=[low, middle])
|
||||
negated = condition(5, ConditionTable=either)
|
||||
varc.ConditionList.ConditionTable[0] = condition(
|
||||
3, ConditionTable=[weight_condition, negated])
|
||||
|
||||
# Give the unrelated axis a visible effect in an underlying outline.
|
||||
name = "glyph00003"
|
||||
points = len(font["glyf"][name].getCoordinates(font["glyf"])[0])
|
||||
variations[name].append(TupleVariation(
|
||||
{"DUMY": (0, 1, 1)}, [(20, 0)] * points + [(0, 0)] * 4))
|
||||
# This tent is reached by a VARC override, but not by the font-level
|
||||
# default of the private axis. Font-level avar2 culling must preserve it.
|
||||
variations[name].append(TupleVariation(
|
||||
{"0000": (-1, -0.5, -0.25)}, [(0, 20)] * points + [(0, 0)] * 4))
|
||||
font.save(directory / "varc-unrelated-axis.ttf")
|
||||
|
||||
font = deepcopy(font)
|
||||
for axis in font["fvar"].axes:
|
||||
if axis.axisTag.startswith("000"):
|
||||
axis.flags = 1 # Hidden component axes.
|
||||
avar = font["avar"] = newTable("avar")
|
||||
avar.majorVersion, avar.minorVersion = 2, 0
|
||||
avar.segments = {a.axisTag: {-1: -1, 0: 0, 1: 1} for a in font["fvar"].axes}
|
||||
avar.table = otTables.avar()
|
||||
avar.table.VarIdxMap = None
|
||||
avar.table.VarStore = None
|
||||
font.save(directory / "varc-unrelated-axis-avar2.ttf")
|
||||
+143
-11
@@ -25,6 +25,8 @@
|
||||
#include "hb-test.h"
|
||||
#include "hb-subset-test.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
static void
|
||||
draw_move_to (hb_draw_funcs_t *funcs HB_UNUSED, void *data,
|
||||
hb_draw_state_t *state HB_UNUSED, float x, float y,
|
||||
@@ -94,6 +96,28 @@ static char *
|
||||
draw_unicode (hb_face_t *face, hb_codepoint_t unicode)
|
||||
{ return draw_unicode_at (face, unicode, NULL, 0); }
|
||||
|
||||
static void
|
||||
assert_paths_close (const char *a, const char *b)
|
||||
{
|
||||
/* Baking gvar deltas changes floating-point summation order. */
|
||||
while (*a && *b)
|
||||
{
|
||||
char *a_end, *b_end;
|
||||
double x = g_ascii_strtod (a, &a_end);
|
||||
double y = g_ascii_strtod (b, &b_end);
|
||||
if (a_end != a || b_end != b)
|
||||
{
|
||||
g_assert_true (a_end != a && b_end != b);
|
||||
g_assert_cmpfloat (fabs (x - y), <, 0.001);
|
||||
a = a_end;
|
||||
b = b_end;
|
||||
}
|
||||
else
|
||||
g_assert_cmpint (*a++, ==, *b++);
|
||||
}
|
||||
g_assert_cmpint (*a, ==, *b);
|
||||
}
|
||||
|
||||
static void
|
||||
assert_has_varc (hb_face_t *face, hb_bool_t expected)
|
||||
{
|
||||
@@ -270,19 +294,119 @@ test_subset_varc_retain_gids (void)
|
||||
|
||||
static void
|
||||
test_subset_varc_fails_when_instancing (void)
|
||||
{
|
||||
const char *fonts[] = {
|
||||
"fonts/varc-unrelated-axis.ttf",
|
||||
"fonts/varc-unrelated-axis-avar2.ttf",
|
||||
};
|
||||
const hb_tag_t tags[] = {
|
||||
HB_TAG ('w','g','h','t'), /* MultiVarStore */
|
||||
HB_TAG ('o','p','s','z'), /* MultiVarStore */
|
||||
HB_TAG ('0','0','0','0'), /* Component coordinates */
|
||||
HB_TAG ('C','O','N','D'), /* Nested conditions only */
|
||||
};
|
||||
for (unsigned f = 0; f < G_N_ELEMENTS (fonts); f++)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file (fonts[f]);
|
||||
for (unsigned i = 0; i < G_N_ELEMENTS (tags); i++)
|
||||
for (unsigned restrict_range = 0; restrict_range < 2; restrict_range++)
|
||||
{
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_set_add (hb_subset_input_unicode_set (input), 0xAC01);
|
||||
hb_ot_var_axis_info_t axis;
|
||||
g_assert_true (hb_ot_var_find_axis_info (face, tags[i], &axis));
|
||||
if (restrict_range)
|
||||
g_assert_true (hb_subset_input_set_axis_range (
|
||||
input, face, tags[i], axis.min_value,
|
||||
(axis.default_value + axis.max_value) / 2, axis.default_value));
|
||||
else
|
||||
g_assert_true (hb_subset_input_pin_axis_to_default (input, face, tags[i]));
|
||||
|
||||
g_assert_null (hb_subset_or_fail (face, input));
|
||||
hb_subset_input_destroy (input);
|
||||
}
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_set_add (hb_subset_input_unicode_set (input), 0xAC01);
|
||||
g_assert_true (hb_subset_input_pin_all_axes_to_default (input, face));
|
||||
g_assert_null (hb_subset_or_fail (face, input));
|
||||
hb_subset_input_destroy (input);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_subset_varc_instance_unrelated_axis (void)
|
||||
{
|
||||
const char *fonts[] = {
|
||||
"fonts/varc-unrelated-axis.ttf",
|
||||
"fonts/varc-unrelated-axis-avar2.ttf",
|
||||
};
|
||||
hb_tag_t dummy = HB_TAG ('D','U','M','Y');
|
||||
for (unsigned f = 0; f < G_N_ELEMENTS (fonts); f++)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file (fonts[f]);
|
||||
for (unsigned mode = 0; mode < 3; mode++)
|
||||
{
|
||||
hb_bool_t restrict_range = mode == 1;
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_set_add (hb_subset_input_unicode_set (input), 0xAC01);
|
||||
if (mode == 2)
|
||||
hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_RETAIN_GIDS);
|
||||
if (restrict_range)
|
||||
g_assert_true (hb_subset_input_set_axis_range (input, face, dummy, 0, 1, 0.5f));
|
||||
else
|
||||
g_assert_true (hb_subset_input_pin_axis_location (input, face, dummy, 0.5f));
|
||||
hb_face_t *subset = hb_subset_test_create_subset (face, input);
|
||||
assert_has_varc (subset, true);
|
||||
g_assert_cmpuint (hb_ot_var_get_axis_count (subset), ==,
|
||||
hb_ot_var_get_axis_count (face) - !restrict_range);
|
||||
hb_ot_var_axis_info_t axis;
|
||||
g_assert_cmpint (hb_ot_var_find_axis_info (subset, dummy, &axis), ==, restrict_range);
|
||||
if (restrict_range)
|
||||
{
|
||||
g_assert_cmpfloat (axis.min_value, ==, 0);
|
||||
g_assert_cmpfloat (axis.default_value, ==, 0.5f);
|
||||
g_assert_cmpfloat (axis.max_value, ==, 1);
|
||||
}
|
||||
g_assert_true (hb_ot_var_find_axis_info (subset, HB_TAG ('w','g','h','t'), &axis));
|
||||
g_assert_cmpuint (axis.axis_index, ==, restrict_range ? 2 : 1);
|
||||
|
||||
for (unsigned sample = 0; sample < 8; sample++)
|
||||
{
|
||||
hb_variation_t variations[] = {
|
||||
{dummy, restrict_range && (sample & 1) ? 1.f : 0.5f},
|
||||
{HB_TAG ('w','g','h','t'), sample & 2 ? 840.3f : 356.5f},
|
||||
{HB_TAG ('o','p','s','z'), sample & 1 ? 1.f : 0.f},
|
||||
{HB_TAG ('C','O','N','D'), sample & 4 ? 1.f : 0.f},
|
||||
};
|
||||
char *source_path = draw_unicode_at (face, 0xAC01, variations,
|
||||
G_N_ELEMENTS (variations));
|
||||
char *subset_path = draw_unicode_at (subset, 0xAC01, variations,
|
||||
G_N_ELEMENTS (variations));
|
||||
g_assert_cmpstr (source_path, !=, "");
|
||||
assert_paths_close (subset_path, source_path);
|
||||
g_free (subset_path);
|
||||
g_free (source_path);
|
||||
}
|
||||
hb_face_destroy (subset);
|
||||
}
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_subset_varc_instance_without_varc_glyphs (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/varc-ac00-ac01.ttf");
|
||||
hb_set_t *unicodes = hb_set_create ();
|
||||
hb_set_add (unicodes, 0xAC00);
|
||||
hb_subset_input_t *input = hb_subset_test_create_input (unicodes);
|
||||
hb_set_destroy (unicodes);
|
||||
|
||||
g_assert_true (hb_subset_input_pin_axis_location (input, face,
|
||||
HB_TAG ('w','g','h','t'), 400));
|
||||
hb_face_t *subset = hb_subset_or_fail (face, input);
|
||||
g_assert_null (subset);
|
||||
|
||||
hb_subset_input_destroy (input);
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_set_add (hb_subset_input_glyph_set (input), 0);
|
||||
g_assert_true (hb_subset_input_pin_axis_to_default (
|
||||
input, face, HB_TAG ('w','g','h','t')));
|
||||
hb_face_t *subset = hb_subset_test_create_subset (face, input);
|
||||
assert_has_varc (subset, false);
|
||||
g_assert_cmpuint (hb_ot_var_get_axis_count (subset), ==,
|
||||
hb_ot_var_get_axis_count (face) - 1);
|
||||
hb_face_destroy (subset);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
@@ -333,6 +457,12 @@ test_subset_varc_passthrough_requires_retained_gids (void)
|
||||
assert_has_varc (subset, true);
|
||||
|
||||
hb_face_destroy (subset);
|
||||
input = create_varc_no_subset_input (true);
|
||||
/* Even an unrelated pin cannot renumber axes in a passthrough table. */
|
||||
g_assert_true (hb_subset_input_pin_axis_to_default (
|
||||
input, face, HB_TAG ('0','0','0','5')));
|
||||
g_assert_null (hb_subset_or_fail (face, input));
|
||||
hb_subset_input_destroy (input);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
@@ -347,6 +477,8 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_subset_varc_no_variation_index);
|
||||
hb_test_add (test_subset_varc_retain_gids);
|
||||
hb_test_add (test_subset_varc_fails_when_instancing);
|
||||
hb_test_add (test_subset_varc_instance_unrelated_axis);
|
||||
hb_test_add (test_subset_varc_instance_without_varc_glyphs);
|
||||
hb_test_add (test_subset_varc_can_be_explicitly_dropped_when_instancing);
|
||||
hb_test_add (test_subset_varc_passthrough_requires_retained_gids);
|
||||
return hb_test_run ();
|
||||
|
||||
Reference in new issue
Block a user