[limits] Resolve work-budget conflicts with main

Merge main's active-glyph fast paths and precomputed ClassDef caches
with the dependency and GSUB closure budgets. Charge the fast paths
for the glyphs they visit and the class caches for their ClassDef
scans, preserving both the optimizations and the work limits.

The full Meson suite passes with experimental APIs enabled (300 tests)
and with the default configuration (281 tests). Also syntax-checked
hb-ot-layout.cc with HB_NO_BEYOND_64K.

Assisted-by: Codex
This commit is contained in:
Behdad Esfahbod committed 2026-11-10 19:31:06 -06:00
commit 0eaceda537
49 files changed
+2468 -324

No files matched your search

+111
View File
@@ -182,6 +182,116 @@ test_vorg_versions (void)
#endif
static hb_face_t *
create_gsub_v1_2_face (void)
{
/* A version 1.2 GSUB that keeps its lists behind the 16-bit offsets
* and has a FeatureVariations table. */
static const char GSUB_data[] = {
0, 1, 0, 2, /* version 1.2 */
0, 26, /* scriptList */
0, 46, /* featureList */
0, 62, /* lookupList */
0, 0, 0, 108, /* featureVars */
0, 0, 0, 0, /* scriptList2 */
0, 0, 0, 0, /* featureList2 */
0, 0, 0, 0, /* lookupList2 */
/* ScriptList */
0, 1, 'D', 'F', 'L', 'T', 0, 8, /* one script at 8 */
0, 4, 0, 0, /* defaultLangSys at 4, no LangSys records */
0, 0, 0xFF, 0xFF, 0, 1, 0, 0, /* no required feature, feature 0 */
/* FeatureList */
0, 1, 'c', 'c', 'm', 'p', 0, 8, /* one feature at 8 */
0, 0, 0, 2, 0, 0, 0, 1, /* lookups 0 and 1 */
/* LookupList */
0, 2, 0, 6, 0, 26, /* two 16-bit lookup offsets */
0, 1, 0, 0, 0, 1, 0, 8, /* SingleSubst, one subtable at 8 */
0, 1, 0, 6, 0, 1, /* format 1, coverage at 6, delta +1 */
0, 1, 0, 1, 0, 1, /* coverage: glyph 1 */
0, 1, 0, 0, 0, 1, 0, 8, /* SingleSubst, one subtable at 8 */
0, 1, 0, 6, 0, 2, /* format 1, coverage at 6, delta +2 */
0, 1, 0, 1, 0, 2, /* coverage: glyph 2 */
/* FeatureVariations */
0, 1, 0, 0, /* version 1.0 */
0, 0, 0, 1, /* one record */
0, 0, 0, 16, 0, 0, 0, 30, /* conditionSet at 16, substitutions at 30 */
0, 1, 0, 0, 0, 6, /* one condition at 6 */
0, 1, 0, 0, 0x20, 0, 0x40, 0, /* axis 0 in [0.5, 1.0] */
0, 1, 0, 0, 0, 1, /* one substitution record */
0, 0, 0, 0, 0, 12, /* feature 0, alternate Feature at 12 */
0, 0, 0, 1, 0, 0, /* lookup 0 only */
};
static const char FVAR_data[] = {
0, 1, 0, 0, /* version 1.0 */
0, 16, 0, 2, 0, 1, 0, 20, /* one axis at 16, axisSize 20 */
0, 0, 0, 8, /* no instances */
'w', 'g', 'h', 't',
0, 100, 0, 0, /* minValue 100 */
1, 0x90, 0, 0, /* defaultValue 400 */
3, 0x84, 0, 0, /* maxValue 900 */
0, 0, 1, 0, /* flags, axisNameID */
};
static const char MAXP_data[] = {
0, 0, 0x50, 0, /* version 0.5 */
0, 5, /* numGlyphs */
};
hb_face_t *face = hb_face_builder_create ();
HB_FACE_ADD_TABLE (face, "GSUB", GSUB_data);
HB_FACE_ADD_TABLE (face, "fvar", FVAR_data);
HB_FACE_ADD_TABLE (face, "maxp", MAXP_data);
return face;
}
static void
check_gsub_v1_2_lookup (hb_face_t *face, unsigned lookup_index,
hb_codepoint_t glyph, hb_codepoint_t expected)
{
unsigned count = 1;
hb_codepoint_t alternate = HB_CODEPOINT_INVALID;
g_assert_cmpuint (hb_ot_layout_lookup_get_glyph_alternates (face, lookup_index, glyph,
0, &count, &alternate),
==, 1);
g_assert_cmpuint (alternate, ==, expected);
}
static void
check_gsub_v1_2 (hb_face_t *face, hb_codepoint_t last_glyph, hb_bool_t has_feature_variations)
{
int coords[] = {0x4000}; /* wght 900 */
unsigned index;
g_assert_cmpuint (hb_ot_layout_table_get_lookup_count (face, HB_OT_TAG_GSUB), ==, 2);
check_gsub_v1_2_lookup (face, 0, 1, 2);
check_gsub_v1_2_lookup (face, 1, 2, last_glyph);
g_assert_cmpint (hb_ot_layout_table_find_feature_variations (face, HB_OT_TAG_GSUB,
coords, 1, &index),
==, has_feature_variations);
}
static void
test_gsub_v1_2_subset (void)
{
hb_face_t *face = create_gsub_v1_2_face ();
check_gsub_v1_2 (face, 4, TRUE);
/* Glyph 1 closes over 2 and 4; 4 is renumbered to 3. */
hb_set_t *glyphs = hb_set_create ();
hb_set_add (glyphs, 1);
hb_face_t *subset = hb_subset_test_create_subset (
face, hb_subset_test_create_input_from_glyphs (glyphs));
check_gsub_v1_2 (subset, 3, TRUE);
hb_face_destroy (subset);
/* Pinning the only axis drops the FeatureVariations. */
hb_subset_input_t *input = hb_subset_test_create_input_from_glyphs (glyphs);
g_assert_true (hb_subset_input_pin_axis_to_default (input, face, HB_TAG ('w','g','h','t')));
subset = hb_subset_test_create_subset (face, input);
check_gsub_v1_2 (subset, 3, FALSE);
hb_face_destroy (subset);
hb_set_destroy (glyphs);
hb_face_destroy (face);
}
int
main (int argc, char **argv)
{
@@ -191,6 +301,7 @@ main (int argc, char **argv)
hb_test_add (test_colr_paint_glyph2);
hb_test_add (test_vorg_versions);
#endif
hb_test_add (test_gsub_v1_2_subset);
return hb_test_run ();
}
+102
View File
@@ -481,6 +481,107 @@ test_ot_layout_lookup_collect_glyphs_qahiri (void)
hb_set_destroy (output);
}
static uint8_t *
put16 (uint8_t *p, unsigned v)
{
*p++ = (uint8_t) (v >> 8);
*p++ = (uint8_t) v;
return p;
}
static void
test_ot_layout_lookup_collect_glyphs_shared_class_rules (void)
{
/* A ContextSubstFormat2 whose RuleSet offsets all point at one RuleSet,
* whose Rule offsets all point at one Rule with 64 class values, over a
* 65535-entry ClassDef. The ClassDef must be walked once per subtable,
* not once per class value of every Rule visited; the latter takes
* about a minute. */
enum { RULESETS = 16, RULES = 1000, CLASSES = 64, GLYPHS = 65535 };
unsigned rule_len = 4 + 2 * CLASSES;
unsigned ruleset_len = 2 + 2 * RULES + rule_len;
unsigned coverage_len = 6;
unsigned classdef_len = 6 + 2 * GLYPHS;
unsigned ruleset_offset = 8 + 2 * RULESETS;
unsigned coverage_offset = ruleset_offset + ruleset_len;
unsigned classdef_offset = coverage_offset + coverage_len;
unsigned gsub_len = 10 + 2 + 2 + 4 + 8 + classdef_offset + classdef_len;
uint8_t *gsub = g_malloc0 (gsub_len);
uint8_t *p = gsub;
/* GSUB header, empty ScriptList and FeatureList, LookupList with one lookup. */
p = put16 (p, 1); p = put16 (p, 0);
p = put16 (p, 10); p = put16 (p, 12); p = put16 (p, 14);
p = put16 (p, 0);
p = put16 (p, 0);
p = put16 (p, 1); p = put16 (p, 4);
/* Lookup: type 5 (Context), one subtable right after. */
p = put16 (p, 5); p = put16 (p, 0); p = put16 (p, 1); p = put16 (p, 8);
/* ContextSubstFormat2 */
p = put16 (p, 2); p = put16 (p, coverage_offset); p = put16 (p, classdef_offset);
p = put16 (p, RULESETS);
for (unsigned i = 0; i < RULESETS; i++)
p = put16 (p, ruleset_offset);
/* RuleSet */
p = put16 (p, RULES);
for (unsigned i = 0; i < RULES; i++)
p = put16 (p, 2 + 2 * RULES);
/* Rule: classes 1 and 2, alternating. */
p = put16 (p, CLASSES + 1); p = put16 (p, 0);
for (unsigned i = 0; i < CLASSES; i++)
p = put16 (p, 1 + (i & 1));
/* Coverage: glyph 1. */
p = put16 (p, 1); p = put16 (p, 1); p = put16 (p, 1);
/* ClassDefFormat1: glyph i has class i % 3. */
p = put16 (p, 1); p = put16 (p, 0); p = put16 (p, GLYPHS);
for (unsigned i = 0; i < GLYPHS; i++)
p = put16 (p, i % 3);
g_assert_cmpuint (p - gsub, ==, gsub_len);
hb_blob_t *blob = hb_blob_create_or_fail ((const char *) gsub, gsub_len,
HB_MEMORY_MODE_WRITABLE, gsub, g_free);
hb_face_t *builder = hb_face_builder_create ();
hb_face_builder_add_table (builder, HB_OT_TAG_GSUB, blob);
hb_blob_destroy (blob);
blob = hb_face_reference_blob (builder);
hb_face_destroy (builder);
hb_face_t *face = hb_face_create (blob, 0);
hb_blob_destroy (blob);
hb_set_t *before = hb_set_create();
hb_set_t *input = hb_set_create();
hb_set_t *after = hb_set_create();
hb_set_t *output = hb_set_create();
hb_codepoint_t g = HB_SET_VALUE_INVALID;
g_assert_cmpuint (1, ==, hb_ot_layout_table_get_lookup_count (face, HB_OT_TAG_GSUB));
BEGIN(HB_OT_TAG_GSUB, 0);
g_assert_cmpuint (0, ==, hb_set_get_population (before));
/* Glyph 1 from the coverage, and every glyph of class 1 or 2. */
g_assert_cmpuint (2 * (GLYPHS / 3), ==, hb_set_get_population (input));
g = HB_SET_VALUE_INVALID;
g_assert_true (hb_set_next (input, &g));
g_assert_cmpuint (1, ==, g);
g_assert_true (hb_set_next (input, &g));
g_assert_cmpuint (2, ==, g);
g_assert_true (hb_set_next (input, &g));
g_assert_cmpuint (4, ==, g);
g_assert_false (hb_set_has (input, 0));
g_assert_true (hb_set_has (input, GLYPHS - 1));
g_assert_cmpuint (0, ==, hb_set_get_population (after));
g_assert_cmpuint (0, ==, hb_set_get_population (output));
END();
hb_face_destroy (face);
hb_set_destroy (before);
hb_set_destroy (input);
hb_set_destroy (after);
hb_set_destroy (output);
}
int
main (int argc, char **argv)
{
@@ -488,5 +589,6 @@ main (int argc, char **argv)
hb_test_add (test_ot_layout_lookup_collect_glyphs_source_sans);
hb_test_add (test_ot_layout_lookup_collect_glyphs_noto_nastaliq);
hb_test_add (test_ot_layout_lookup_collect_glyphs_qahiri);
hb_test_add (test_ot_layout_lookup_collect_glyphs_shared_class_rules);
return hb_test_run ();
}
+112
View File
@@ -684,6 +684,117 @@ test_depend_varc (void)
hb_face_destroy (face);
}
/* A GSUB face whose features have no lookups of their own. Feature 0 is 'aaaa',
* the others are 'bbbb', and the default LangSys lists all but the last. Every
* FeatureVariations record uses the same FeatureTableSubstitution, which gives
* lookup 0 (glyph 1 -> 2) to feature 0 and lookup 1 (glyph 3 -> 4) to the last
* feature; its other records are for a feature that does not exist. */
static hb_face_t *
create_feature_variations_face (unsigned num_features,
unsigned num_records,
unsigned num_substitutions)
{
unsigned lookup_list_offset = 14;
unsigned script_list_offset = lookup_list_offset + 6 + 2 * 20;
unsigned feature_list_offset = script_list_offset + 18 + (num_features - 1) * 2;
unsigned variations_offset = feature_list_offset + 2 + num_features * 6 + 4;
unsigned substitutions_size = 6 + num_substitutions * 6;
unsigned gsub_size = variations_offset + 8 + num_records * 8 + substitutions_size + 2 * 6;
unsigned char *gsub = (unsigned char *) g_malloc0 (gsub_size);
unsigned char *p = gsub;
unsigned char maxp[6] = {0x00, 0x00, 0x50, 0x00, 0x00, 0x05};
hb_face_t *face = hb_face_builder_create ();
hb_blob_t *blob;
#define PUT16(v) (*p++ = (unsigned char) ((v) >> 8), *p++ = (unsigned char) (v))
#define PUT32(v) (PUT16 ((v) >> 16), PUT16 (v))
PUT16 (1); PUT16 (1); /* version */
PUT16 (script_list_offset);
PUT16 (feature_list_offset);
PUT16 (lookup_list_offset);
PUT32 (variations_offset);
PUT16 (2); PUT16 (6); PUT16 (6 + 20); /* lookupCount, lookupOffsets */
for (unsigned i = 0; i < 2; i++)
{
PUT16 (1); PUT16 (0); PUT16 (1); PUT16 (8); /* type, flag, subTableCount, offset */
PUT16 (1); PUT16 (6); PUT16 (1); /* SingleSubst format, coverage, deltaGlyphID */
PUT16 (1); PUT16 (1); PUT16 (1 + 2 * i); /* Coverage format, glyphCount, glyph */
}
PUT16 (1); PUT32 (HB_TAG ('D','F','L','T')); PUT16 (8); /* scriptCount, record */
PUT16 (4); PUT16 (0); /* defaultLangSys, langSysCount */
PUT16 (0); PUT16 (0xFFFF); PUT16 (num_features - 1); /* lookupOrder, required, count */
for (unsigned i = 0; i < num_features - 1; i++)
PUT16 (i);
PUT16 (num_features);
for (unsigned i = 0; i < num_features; i++)
{
PUT32 (i ? HB_TAG ('b','b','b','b') : HB_TAG ('a','a','a','a'));
PUT16 (2 + num_features * 6);
}
PUT16 (0); PUT16 (0); /* featureParams, lookupIndexCount */
PUT16 (1); PUT16 (0); /* version */
PUT32 (num_records);
for (unsigned i = 0; i < num_records; i++)
{
PUT32 (0); /* conditionSet */
PUT32 (8 + num_records * 8); /* featureTableSubstitution */
}
PUT16 (1); PUT16 (0); /* version */
PUT16 (num_substitutions);
PUT16 (0); PUT32 (substitutions_size);
PUT16 (num_features - 1); PUT32 (substitutions_size + 6);
for (unsigned i = 2; i < num_substitutions; i++)
{
PUT16 (0xFFFF); PUT32 (0);
}
for (unsigned i = 0; i < 2; i++)
{
PUT16 (0); PUT16 (1); PUT16 (i); /* featureParams, lookupIndexCount, lookup */
}
g_assert_true (p == gsub + gsub_size);
#undef PUT32
#undef PUT16
blob = hb_blob_create ((const char *) gsub, gsub_size,
HB_MEMORY_MODE_READONLY, gsub, g_free);
g_assert_true (hb_face_builder_add_table (face, HB_TAG ('G','S','U','B'), blob));
hb_blob_destroy (blob);
blob = hb_blob_create ((const char *) maxp, sizeof (maxp),
HB_MEMORY_MODE_DUPLICATE, NULL, NULL);
g_assert_true (hb_face_builder_add_table (face, HB_TAG ('m','a','x','p'), blob));
hb_blob_destroy (blob);
return face;
}
/* Lookups of substitute features get the tag of the feature they replace, in
* one pass over the FeatureVariations table. */
static void
test_depend_feature_variations (void)
{
/* 8,000 x 40,000 x 90 steps if every record is searched for every feature. */
hb_face_t *face = create_feature_variations_face (8000, 40000, 90);
hb_subset_depend_t *depend = hb_subset_depend_from_face_or_fail (face);
hb_tag_t tag;
g_assert_nonnull (depend);
tag = HB_TAG ('a','a','a','a');
g_assert_true (find_dependency (depend, 1, 2, HB_OT_TAG_GSUB, &tag, NULL));
tag = HB_TAG ('b','b','b','b');
g_assert_false (find_dependency (depend, 1, 2, HB_OT_TAG_GSUB, &tag, NULL));
/* No script reaches the last feature. */
g_assert_false (find_dependency (depend, 3, 4, HB_OT_TAG_GSUB, NULL, NULL));
hb_subset_depend_destroy (depend);
hb_face_destroy (face);
}
#ifndef HB_NO_BEYOND_64K
/* ContextSubst format 6 (beyond-64k) uses 24-bit Coverage offsets.
* Lookup 0 matches glyphs 1 2 and calls lookup 1 (SingleSubst 2 -> 3)
@@ -813,6 +924,7 @@ main (int argc, char **argv)
hb_test_add (test_depend_math);
hb_test_add (test_depend_varc);
hb_test_add (test_depend_gsub_formats);
hb_test_add (test_depend_feature_variations);
#ifndef HB_NO_BEYOND_64K
hb_test_add (test_depend_context_format6);
hb_test_add (test_depend_gsub_context_set_glyphs);
+141
View File
@@ -105,6 +105,61 @@ test_ot_layout_gdef_1_4_offset2 (void)
hb_face_destroy (face);
}
static void
test_ot_layout_lookups_substitute_closure_context_format4 (void)
{
/* Lookup 0 is a SequenceContextFormat4 (24-bit glyph ids) with the
* single rule "1 2", applying lookup 1 at position 1. Lookup 1 is a
* SingleSubst 2 -> 3. Closing over {1, 2} must add glyph 3. */
const char gsub[] = {
0x00, 0x01, 0x00, 0x00, /* version 1.0 */
0x00, 0x0A, /* scriptListOffset */
0x00, 0x0C, /* featureListOffset */
0x00, 0x0E, /* lookupListOffset */
0x00, 0x00, /* ScriptList: no scripts */
0x00, 0x00, /* FeatureList: no features */
0x00, 0x02, 0x00, 0x06, 0x00, 0x2F, /* LookupList: two lookups */
0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, /* Lookup 0: type 5, one subtable */
0x00, 0x04, /* SequenceContextFormat4 */
0x00, 0x00, 0x00, 0x0C, /* coverageOffset */
0x00, 0x00, 0x01, /* ruleSetCount */
0x00, 0x00, 0x12, /* ruleSetOffsets[0] */
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, /* Coverage format 1, glyph 1 */
0x00, 0x01, 0x00, 0x04, /* RuleSet: one rule */
0x00, 0x02, 0x00, 0x01, /* Rule: inputCount 2, lookupCount 1 */
0x00, 0x00, 0x02, /* input[1] = glyph 2 */
0x00, 0x01, 0x00, 0x01, /* LookupRecord: sequenceIndex 1, lookup 1 */
0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, /* Lookup 1: type 1, one subtable */
0x00, 0x01, 0x00, 0x06, 0x00, 0x01, /* SingleSubstFormat1, delta +1 */
0x00, 0x01, 0x00, 0x01, 0x00, 0x02, /* Coverage format 1, glyph 2 */
};
const char maxp[] = {0x00, 0x00, 0x50, 0x00, 0x00, 0x04}; /* version 0.5, 4 glyphs */
hb_face_t *face = hb_face_builder_create ();
hb_blob_t *blob = hb_blob_create (gsub, sizeof (gsub),
HB_MEMORY_MODE_READONLY, NULL, NULL);
hb_set_t *lookups = hb_set_create ();
hb_set_t *glyphs = hb_set_create ();
g_assert_true (hb_face_builder_add_table (face, HB_OT_TAG_GSUB, blob));
hb_blob_destroy (blob);
blob = hb_blob_create (maxp, sizeof (maxp),
HB_MEMORY_MODE_READONLY, NULL, NULL);
g_assert_true (hb_face_builder_add_table (face, HB_TAG ('m','a','x','p'), blob));
hb_blob_destroy (blob);
hb_set_add (lookups, 0);
hb_set_add (glyphs, 1);
hb_set_add (glyphs, 2);
hb_ot_layout_lookups_substitute_closure (face, lookups, glyphs);
g_assert_true (hb_set_has (glyphs, 3));
g_assert_cmpuint (hb_set_get_population (glyphs), ==, 3);
hb_set_destroy (glyphs);
hb_set_destroy (lookups);
hb_face_destroy (face);
}
#endif
static void
@@ -440,6 +495,90 @@ test_ot_layout_collect_lookup_variations (void)
}
#endif
static char *
write_be16 (char *p, unsigned v)
{
*p++ = (char) (v >> 8);
*p++ = (char) v;
return p;
}
static void
test_ot_layout_lookups_substitute_closure_large_coverage_one (unsigned lookup_type)
{
/* Lookup 0 is a ContextSubst covering NUM_GLYPHS glyphs; every rule recurses
* into lookup 1, a MultipleSubst or AlternateSubst covering the same glyphs
* and mapping each to OUT1 and OUT2. Closure visits lookup 1 once per glyph
* with a single active glyph, so the cost of a visit must not scale with the
* size of lookup 1's coverage. */
enum { NUM_GLYPHS = 16000, OUT1 = NUM_GLYPHS + 1, OUT2 = NUM_GLYPHS + 2 };
const unsigned context_len = 6 + 2 * NUM_GLYPHS + 4 + 8 + 10;
const unsigned subst_len = 6 + 2 * NUM_GLYPHS + 6 + 10;
const unsigned gsub_len = 10 + 6 + 16 + context_len + subst_len;
char *gsub = g_malloc0 (gsub_len);
char *p = gsub;
unsigned i;
p = write_be16 (p, 1); p = write_be16 (p, 0); /* version 1.0 */
p = write_be16 (p, 0); p = write_be16 (p, 0); /* no ScriptList, no FeatureList */
p = write_be16 (p, 10); /* LookupList */
p = write_be16 (p, 2); /* lookupCount */
p = write_be16 (p, 6); p = write_be16 (p, 14); /* Lookup offsets */
p = write_be16 (p, 5); p = write_be16 (p, 0); /* ContextSubst, no flags */
p = write_be16 (p, 1); p = write_be16 (p, 16); /* one subtable */
p = write_be16 (p, lookup_type); p = write_be16 (p, 0);
p = write_be16 (p, 1); p = write_be16 (p, 8 + context_len);
/* ContextSubstFormat1: all rule sets share one rule applying lookup 1 at 0. */
p = write_be16 (p, 1); p = write_be16 (p, context_len - 10);
p = write_be16 (p, NUM_GLYPHS);
for (i = 0; i < NUM_GLYPHS; i++)
p = write_be16 (p, 6 + 2 * NUM_GLYPHS);
p = write_be16 (p, 1); p = write_be16 (p, 4); /* RuleSet */
p = write_be16 (p, 1); p = write_be16 (p, 1); /* Rule: glyphCount, lookupCount */
p = write_be16 (p, 0); p = write_be16 (p, 1); /* SequenceLookupRecord */
p = write_be16 (p, 2); p = write_be16 (p, 1); /* CoverageFormat2, one range */
p = write_be16 (p, 1); p = write_be16 (p, NUM_GLYPHS); p = write_be16 (p, 0);
/* MultipleSubstFormat1 / AlternateSubstFormat1: all glyphs share one
* Sequence / AlternateSet. */
p = write_be16 (p, 1); p = write_be16 (p, subst_len - 10);
p = write_be16 (p, NUM_GLYPHS);
for (i = 0; i < NUM_GLYPHS; i++)
p = write_be16 (p, 6 + 2 * NUM_GLYPHS);
p = write_be16 (p, 2); p = write_be16 (p, OUT1); p = write_be16 (p, OUT2);
p = write_be16 (p, 2); p = write_be16 (p, 1); /* CoverageFormat2, one range */
p = write_be16 (p, 1); p = write_be16 (p, NUM_GLYPHS); p = write_be16 (p, 0);
g_assert_cmpuint (p - gsub, ==, gsub_len);
hb_face_t *face = hb_face_builder_create ();
hb_blob_t *blob = hb_blob_create (gsub, gsub_len, HB_MEMORY_MODE_READONLY, NULL, NULL);
g_assert_true (hb_face_builder_add_table (face, HB_OT_TAG_GSUB, blob));
hb_blob_destroy (blob);
hb_face_set_glyph_count (face, OUT2 + 1);
hb_set_t *glyphs = hb_set_create ();
hb_set_add_range (glyphs, 1, NUM_GLYPHS);
hb_ot_layout_lookups_substitute_closure (face, NULL, glyphs);
g_assert_cmpuint (hb_set_get_population (glyphs), ==, NUM_GLYPHS + 2);
g_assert_true (hb_set_has (glyphs, OUT1));
g_assert_true (hb_set_has (glyphs, OUT2));
hb_set_destroy (glyphs);
hb_face_destroy (face);
g_free (gsub);
}
static void
test_ot_layout_lookups_substitute_closure_large_coverage (void)
{
test_ot_layout_lookups_substitute_closure_large_coverage_one (2); /* MultipleSubst */
test_ot_layout_lookups_substitute_closure_large_coverage_one (3); /* AlternateSubst */
}
int
main (int argc, char **argv)
{
@@ -449,6 +588,7 @@ main (int argc, char **argv)
#endif
#ifndef HB_NO_BEYOND_64K
hb_test_add (test_ot_layout_gdef_1_4_offset2);
hb_test_add (test_ot_layout_lookups_substitute_closure_context_format4);
#endif
hb_test_add (test_ot_layout_table_get_script_tags);
hb_test_add (test_ot_layout_table_find_script);
@@ -459,5 +599,6 @@ main (int argc, char **argv)
#ifndef HB_NO_VAR
hb_test_add (test_ot_layout_collect_lookup_variations);
#endif
hb_test_add (test_ot_layout_lookups_substitute_closure_large_coverage);
return hb_test_run ();
}
+269
View File
@@ -916,6 +916,272 @@ test_subset_custom_glyph_mapping (void)
hb_face_destroy (source);
}
static hb_face_t *
_face_copy_tables (hb_face_t *source)
{
hb_face_t *face = hb_face_builder_create ();
hb_tag_t tags[32];
unsigned offset = 0;
while (true)
{
unsigned count = G_N_ELEMENTS (tags);
hb_face_get_table_tags (source, offset, &count, tags);
if (!count) break;
for (unsigned i = 0; i < count; i++)
{
hb_blob_t *blob = hb_face_reference_table (source, tags[i]);
hb_face_builder_add_table (face, tags[i], blob);
hb_blob_destroy (blob);
}
offset += count;
}
return face;
}
static hb_face_t *
_face_with_table (hb_face_t *source, hb_tag_t tag, const void *data, unsigned length)
{
hb_face_t *face = _face_copy_tables (source);
hb_blob_t *blob = hb_blob_create_or_fail ((const char *) data, length,
HB_MEMORY_MODE_READONLY, NULL, NULL);
hb_face_builder_add_table (face, tag, blob);
hb_blob_destroy (blob);
return face;
}
static hb_face_t *
_face_with_name_table_and_wws (hb_face_t *source,
const void *name_data, unsigned name_length,
bool wws)
{
hb_face_t *face = _face_copy_tables (source);
hb_blob_t *name_blob = hb_blob_create_or_fail ((const char *) name_data,
name_length,
HB_MEMORY_MODE_READONLY,
NULL, NULL);
g_assert_nonnull (name_blob);
hb_face_builder_add_table (face, HB_TAG ('n','a','m','e'), name_blob);
hb_blob_destroy (name_blob);
hb_blob_t *os2 = hb_face_reference_table (source, HB_TAG ('O','S','/','2'));
hb_blob_t *os2_copy = hb_blob_copy_writable_or_fail (os2);
hb_blob_destroy (os2);
g_assert_nonnull (os2_copy);
unsigned length;
char *data = (char *) hb_blob_get_data_writable (os2_copy, &length);
g_assert_cmpuint (length, >=, 64);
/* fsSelection is at offset 62 in OS/2 version 0 and later. */
uint16_t fs_selection = ((uint8_t) data[62] << 8) | (uint8_t) data[63];
if (wws)
fs_selection |= 1u << 8;
else
fs_selection &= ~(1u << 8);
data[62] = fs_selection >> 8;
data[63] = fs_selection;
hb_face_builder_add_table (face, HB_TAG ('O','S','/','2'), os2_copy);
hb_blob_destroy (os2_copy);
return face;
}
static hb_blob_t *
_blob_with_checksum (uint32_t checksum, unsigned length)
{
char *data = (char *) g_malloc0 (length ? length : 1);
if (length >= 4)
{
data[0] = checksum >> 24;
data[1] = checksum >> 16;
data[2] = checksum >> 8;
data[3] = checksum;
}
return hb_blob_create_or_fail (data, length, HB_MEMORY_MODE_WRITABLE,
data, g_free);
}
static void
test_subset_no_hinting_ignored_for_hint_dependent_font (void)
{
#ifndef HB_NO_NAME
/* Minimal name table with Font Family = "MingLiU". */
static const unsigned char name_table[] = {
0x00, 0x00, 0x00, 0x01, 0x00, 0x12,
0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x01, 0x00, 0x0E, 0x00, 0x00,
0x00, 0x4D, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67,
0x00, 0x4C, 0x00, 0x69, 0x00, 0x55,
};
/* "HuaTianKaiTi" followed by U+4F53. FreeType reads the non-ASCII
* character as `?`, matching the list entry "HuaTianKaiTi?". */
static const unsigned char name_table_question[] = {
0x00, 0x00, 0x00, 0x01, 0x00, 0x12,
0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x01, 0x00, 0x1A, 0x00, 0x00,
0x00, 0x48, 0x00, 0x75, 0x00, 0x61, 0x00, 0x54,
0x00, 0x69, 0x00, 0x61, 0x00, 0x6E, 0x00, 0x4B,
0x00, 0x61, 0x00, 0x69, 0x00, 0x54, 0x00, 0x69,
0x4F, 0x53,
};
static const hb_tag_t hint_tags[] = {
HB_TAG ('c','v','t',' '),
HB_TAG ('f','p','g','m'),
HB_TAG ('p','r','e','p'),
};
hb_face_t *source = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face = _face_with_table (source, HB_TAG ('n','a','m','e'),
name_table, sizeof (name_table));
hb_face_t *face_question = _face_with_table (source, HB_TAG ('n','a','m','e'),
name_table_question,
sizeof (name_table_question));
hb_set_t *codepoints = hb_set_create ();
hb_set_add (codepoints, 'a');
for (unsigned i = 0; i < 3; i++)
{
bool hint_dependent = i != 0;
hb_face_t *target = i == 0 ? source : i == 1 ? face : face_question;
hb_subset_input_t *input = hb_subset_test_create_input (codepoints);
hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_NO_HINTING);
hb_face_t *subset = hb_subset_or_fail (target, input);
g_assert_nonnull (subset);
for (unsigned j = 0; j < G_N_ELEMENTS (hint_tags); j++)
{
hb_blob_t *blob = hb_face_reference_table (subset, hint_tags[j]);
g_assert_true (!!hb_blob_get_length (blob) == hint_dependent);
hb_blob_destroy (blob);
}
hb_face_destroy (subset);
hb_subset_input_destroy (input);
}
hb_set_destroy (codepoints);
hb_face_destroy (face_question);
hb_face_destroy (face);
hb_face_destroy (source);
#endif
}
static void
test_subset_no_hinting_hint_dependent_wws_family (void)
{
#ifndef HB_NO_NAME
/* Font Family = "NotTricky", Typographic Family = "MingLiU", and
* WWS Family = "NotTricky". With the OS/2 WWS bit set FreeType
* picks the typographic family and keeps hints; with it clear it
* picks the WWS family and must not fall through to the typographic
* one. */
static const unsigned char name_table[] = {
0x00, 0x00, 0x00, 0x03, 0x00, 0x2A,
0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00,
0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x10, 0x00, 0x0E, 0x00, 0x12,
0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x15, 0x00, 0x12, 0x00, 0x20,
0x00, 0x4E, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x54, 0x00, 0x72, 0x00, 0x69,
0x00, 0x63, 0x00, 0x6B, 0x00, 0x79, 0x00, 0x4D, 0x00, 0x69, 0x00, 0x6E,
0x00, 0x67, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x55, 0x00, 0x4E, 0x00, 0x6F,
0x00, 0x74, 0x00, 0x54, 0x00, 0x72, 0x00, 0x69, 0x00, 0x63, 0x00, 0x6B,
0x00, 0x79,
};
static const hb_tag_t hint_tags[] = {
HB_TAG ('c','v','t',' '),
HB_TAG ('f','p','g','m'),
HB_TAG ('p','r','e','p'),
};
hb_face_t *source = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *wws = _face_with_name_table_and_wws (source, name_table,
sizeof (name_table), true);
hb_face_t *no_wws = _face_with_name_table_and_wws (source, name_table,
sizeof (name_table), false);
hb_set_t *codepoints = hb_set_create ();
hb_set_add (codepoints, 'a');
for (unsigned i = 0; i < 2; i++)
{
bool hint_dependent = i == 0;
hb_face_t *target = i == 0 ? wws : no_wws;
hb_subset_input_t *input = hb_subset_test_create_input (codepoints);
hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_NO_HINTING);
hb_face_t *subset = hb_subset_or_fail (target, input);
g_assert_nonnull (subset);
for (unsigned j = 0; j < G_N_ELEMENTS (hint_tags); j++)
{
hb_blob_t *blob = hb_face_reference_table (subset, hint_tags[j]);
g_assert_true (!!hb_blob_get_length (blob) == hint_dependent);
hb_blob_destroy (blob);
}
hb_face_destroy (subset);
hb_subset_input_destroy (input);
}
hb_set_destroy (codepoints);
hb_face_destroy (no_wws);
hb_face_destroy (wws);
hb_face_destroy (source);
#endif
}
static void
test_subset_no_hinting_ignored_for_hint_dependent_ids (void)
{
static const struct {
hb_tag_t tag;
uint32_t checksum;
unsigned length;
} ids[] = {
{HB_TAG ('c','v','t',' '), 0x05BCF058, 0x000002E4},
{HB_TAG ('f','p','g','m'), 0x28233BF1, 0x000087C4},
{HB_TAG ('p','r','e','p'), 0xA344A1EA, 0x000001E1},
};
static const hb_tag_t hint_tags[] = {
HB_TAG ('c','v','t',' '),
HB_TAG ('f','p','g','m'),
HB_TAG ('p','r','e','p'),
};
hb_face_t *source = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face = _face_copy_tables (source);
for (unsigned i = 0; i < G_N_ELEMENTS (ids); i++)
{
hb_blob_t *blob = _blob_with_checksum (ids[i].checksum, ids[i].length);
hb_face_builder_add_table (face, ids[i].tag, blob);
hb_blob_destroy (blob);
}
hb_set_t *codepoints = hb_set_create ();
hb_set_add (codepoints, 'a');
hb_subset_input_t *input = hb_subset_test_create_input (codepoints);
hb_set_destroy (codepoints);
hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_NO_HINTING);
hb_face_t *subset = hb_subset_or_fail (face, input);
g_assert_nonnull (subset);
for (unsigned i = 0; i < G_N_ELEMENTS (hint_tags); i++)
{
hb_blob_t *blob = hb_face_reference_table (subset, hint_tags[i]);
g_assert_cmpuint (hb_blob_get_length (blob), >, 0);
hb_blob_destroy (blob);
}
hb_face_destroy (subset);
hb_subset_input_destroy (input);
hb_face_destroy (face);
hb_face_destroy (source);
}
static hb_blob_t*
_copy_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data)
{
@@ -1554,6 +1820,9 @@ main (int argc, char **argv)
hb_test_add (test_subset_non_glyph_layout_table_does_not_retain_gids);
#endif
hb_test_add (test_subset_custom_glyph_mapping);
hb_test_add (test_subset_no_hinting_ignored_for_hint_dependent_font);
hb_test_add (test_subset_no_hinting_hint_dependent_wws_family);
hb_test_add (test_subset_no_hinting_ignored_for_hint_dependent_ids);
hb_test_add (test_subset_sanitized_table_cache);
#if !defined(HB_NO_OT_LAYOUT) && !defined(HB_NO_OT_LAYOUT_BLOCKLIST)
hb_test_add (test_subset_gdef_blocklist);