Files
harfbuzz/test/api/test-subset-cmap.c
T
Behdad EsfahbodandClaude Opus 4.8 60bd82dcb4 [subset] Bound cmap per-record unicode set collection
When rewriting cmap, the subsetter built one hb_set_t of covered code
points per encoding record. SubtableUnicodesCache keyed those sets by
the record's own offset and collected each with num_glyphs = UINT_MAX,
so a font with many records sharing one full-range format 12 subtable
built one ~1.1M-code-point set per record: ~41 s of CPU, or ~2.1 GB of
memory for a 96 KB input, with nothing but the record count (bounded
only by the sanitizer) limiting the work.

Three changes bound it, all matching how nearby cmap code already works:

 1. Key cached_unicodes by record->subtable, so records sharing a
    subtable share one set (both set_for overloads).
 2. Give the cache a num_glyphs member and collect with it instead of
    UINT_MAX, as the cmap accelerator already does for
    hb_face_collect_unicodes; cmap::serialize fills it from
    plan->source->get_num_glyphs() and create_filled_cache() takes it
    as a parameter, passed as face->get_num_glyphs() for
    hb_subset_preprocess.
 3. Process only the first encoding record of each (platformID,
    encodingID) pair in both cmap::serialize and create_filled_cache
    (variation-selector records exempt). Lookup already sees one record
    per pair and EncodingRecord::copy links later records of a format to
    the first serialized subtable, so this bounds both the number of
    sets built and the _can_drop walk regardless of how many records a
    malformed font repeats, independent of whether they share a subtable.

No public API or ABI change. Output is unchanged for well-formed fonts:
the plan's unicodes are already restricted to gids below num_glyphs, and
valid fonts never repeat a (platformID, encodingID) pair. The attached
reproducer's hostile fonts drop from ~41 s / 2.1 GB to ~0 s / 12 MiB
with byte-identical output.

Adds test_subset_cmap_shared_subtable_many_records and
test_subset_cmap_repeated_encoding_records to
test/api/test-subset-cmap.c.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-FSXRDPBT.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-08 14:36:19 -06:00

545 lines
19 KiB
C

/*
* Copyright © 2018 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Google Author(s): Roderick Sheeter
*/
#include "hb-test.h"
#include "hb-subset-test.h"
/* Unit tests for cmap subsetting */
static void
test_subset_cmap (void)
{
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_abc_subset;
hb_set_add (codepoints, 97);
hb_set_add (codepoints, 99);
face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('c','m','a','p'));
hb_face_destroy (face_abc_subset);
hb_face_destroy (face_abc);
hb_face_destroy (face_ac);
}
static void
check_default_uvs_range_limit (unsigned int format)
{
static const char maxp_data[] = {0, 0, 0x50, 0, 3, 1};
char cmap_data[] = {
0, 0, 0, 2, /* cmap header */
0, 0, 0, 5, 0, 0, 0, 48, /* UVS encoding record */
0, 3, 0, 10, 0, 0, 0, 20, /* nominal encoding record */
0, 12, 0, 0, 0, 0, 0, 28, /* format 12 header */
0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0x10, 0, 0, 0, 0x12, (char) 0xFF, 0, 0, 0, 1,
0, 14, 0, 0, 0, 37, 0, 0, 0, 1, /* format 14 or 15 header */
0, (char) 0xFE, 0, 0, 0, 0, 21, 0, 0, 0, 0,
0, 0, 0, 3, /* three adjacent 256-codepoint ranges */
0, 0x10, 0, (char) 0xFF,
0, 0x11, 0, (char) 0xFF,
0, 0x12, 0, (char) 0xFF,
};
cmap_data[49] = format;
hb_face_t *face = hb_face_builder_create ();
HB_FACE_ADD_TABLE (face, "maxp", maxp_data);
HB_FACE_ADD_TABLE (face, "cmap", cmap_data);
const unsigned int counts[] = {1, 255, 256, 257, 512, 513, 768};
for (unsigned int i = 0; i < G_N_ELEMENTS (counts); i++)
{
hb_set_t *codepoints = hb_set_create ();
hb_set_add_range (codepoints, 0x1000, 0x1000 + counts[i] - 1);
hb_set_add (codepoints, 0xFE00);
hb_face_t *subset = hb_subset_test_create_subset (
face, hb_subset_test_create_input (codepoints));
hb_set_clear (codepoints);
hb_face_collect_variation_unicodes (subset, 0xFE00, codepoints);
g_assert_cmpuint (hb_set_get_population (codepoints), ==, counts[i]);
hb_font_t *font = hb_font_create (subset);
hb_codepoint_t glyph;
g_assert_true (hb_font_get_variation_glyph (font, 0x1000 + counts[i] - 1,
0xFE00, &glyph));
g_assert_cmpuint (glyph, ==, counts[i]);
hb_font_destroy (font);
hb_set_destroy (codepoints);
hb_face_destroy (subset);
}
hb_face_destroy (face);
}
static void
test_subset_cmap_default_uvs_range_limit (void)
{
check_default_uvs_range_limit (14);
}
#ifndef HB_NO_BEYOND_64K
static void
test_subset_cmap15_default_uvs_range_limit (void)
{
check_default_uvs_range_limit (15);
}
#endif
static void
test_subset_cmap_non_consecutive_glyphs (void)
{
hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.D7,D8,D9,DA,DE.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_subset;
hb_set_add (codepoints, 0xD7);
hb_set_add (codepoints, 0xD8);
hb_set_add (codepoints, 0xD9);
hb_set_add (codepoints, 0xDA);
hb_set_add (codepoints, 0xDE);
face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_subset_test_check (face, face_subset, HB_TAG ('c','m','a','p'));
hb_face_destroy (face_subset);
hb_face_destroy (face);
}
static void
test_subset_cmap_noop (void)
{
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_set_t *codepoints = hb_set_create();
hb_face_t *face_abc_subset;
hb_set_add (codepoints, 97);
hb_set_add (codepoints, 98);
hb_set_add (codepoints, 99);
face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('c','m','a','p'));
hb_face_destroy (face_abc_subset);
hb_face_destroy (face_abc);
}
static void
test_subset_cmap4_no_exceeding_maximum_codepoint (void)
{
hb_face_t *face_origin = hb_test_open_font_file ("fonts/Mplus1p-Regular.ttf");
hb_face_t *face_expected = hb_test_open_font_file ("fonts/Mplus1p-Regular-cmap4-testing.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_subset;
hb_set_add (codepoints, 0x20);
hb_set_add (codepoints, 0x21);
hb_set_add (codepoints, 0x1d542);
hb_set_add (codepoints, 0x201a2);
face_subset = hb_subset_test_create_subset (face_origin, hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_subset_test_check (face_expected, face_subset, HB_TAG ('c','m','a','p'));
hb_face_destroy (face_subset);
hb_face_destroy (face_expected);
hb_face_destroy (face_origin);
}
static void
test_subset_cmap_empty_tables (void)
{
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_empty = hb_test_open_font_file ("fonts/Roboto-Regular.empty.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_abc_subset;
hb_set_add (codepoints, 100);
hb_set_add (codepoints, 101);
face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_subset_test_check (face_empty, face_abc_subset, HB_TAG ('c','m','a','p'));
hb_face_destroy (face_abc_subset);
hb_face_destroy (face_abc);
hb_face_destroy (face_empty);
}
static void
test_subset_cmap_noto_color_emoji_noop (void)
{
hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.cmap.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_subset;
hb_set_add (codepoints, 0x38);
hb_set_add (codepoints, 0x39);
hb_set_add (codepoints, 0xAE);
hb_set_add (codepoints, 0x2049);
hb_set_add (codepoints, 0x20E3);
hb_set_add (codepoints, 0xfe0f);
face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_subset_test_check (face, face_subset, HB_TAG ('c','m','a','p'));
hb_face_destroy (face_subset);
hb_face_destroy (face);
}
static void
test_subset_cmap_noto_color_emoji_non_consecutive_glyphs (void)
{
hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.cmap.ttf");
hb_face_t *face_expected = hb_test_open_font_file ("fonts/NotoColorEmoji.cmap.38,AE,2049.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_subset;
hb_set_add (codepoints, 0x38);
hb_set_add (codepoints, 0xAE);
hb_set_add (codepoints, 0x2049);
hb_set_add (codepoints, 0xfe0f);
face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_subset_test_check (face_expected, face_subset, HB_TAG ('c','m','a','p'));
hb_face_destroy (face_subset);
hb_face_destroy (face_expected);
hb_face_destroy (face);
}
static void
test_subset_DMAP (void)
{
const char maxp_data[] = {
0, 0, 0x50, 0, 0, 7,
};
const char cmap_data[] = {
0, 0, 0, 2, /* cmap header */
0, 3, 0, 10, 0, 0, 0, 20, /* encoding records */
0, 0, 0, 5, 0, 0, 0, 48,
0, 12, 0, 0, 0, 0, 0, 28, /* format 12 header */
0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 'A', 0, 0, 0, 'B', 0, 0, 0, 1, /* format 12 group */
0, 14, 0, 0, 0, 40, 0, 0, 0, 1, /* format 14 header */
0, 0xFE, 0x0F, 0, 0, 0, 0, 0, 0, 0, 21, /* variation selector */
0, 0, 0, 3, /* non-default UVS count */
0, 0, 'A', 0, 3,
0, 0, 'B', 0, 3,
0, 0, 'C', 0, 3,
};
const char dmap_data[] = {
0, 0, 0, 2, /* DMAP header */
0, 3, 0, 10, 0, 0, 0, 20, /* encoding records */
0, 0, 0, 5, 0, 0, 0, 60,
0, 12, 0, 0, 0, 0, 0, 40, /* format 12 header */
0, 0, 0, 0, 0, 0, 0, 2,
0, 0, 0, 'A', 0, 0, 0, 'A', 0, 0, 0, 4, /* format 12 groups */
0, 0, 0, 'C', 0, 0, 0, 'C', 0, 0, 0, 5,
0, 14, 0, 0, 0, 38, 0, 0, 0, 1, /* format 14 header */
0, 0xFE, 0x0F, 0, 0, 0, 21, 0, 0, 0, 29, /* variation selector */
0, 0, 0, 1, 0, 0, 'B', 0, /* default UVS */
0, 0, 0, 1, 0, 0, 'A', 0, 6, /* non-default UVS */
};
hb_face_t *face = hb_face_builder_create ();
HB_FACE_ADD_TABLE (face, "maxp", maxp_data);
HB_FACE_ADD_TABLE (face, "cmap", cmap_data);
HB_FACE_ADD_TABLE (face, "DMAP", dmap_data);
hb_font_t *font = hb_font_create (face);
hb_codepoint_t glyph;
g_assert_true (hb_font_get_nominal_glyph (font, 'A', &glyph));
g_assert_cmpuint (glyph, ==, 4);
g_assert_true (hb_font_get_nominal_glyph (font, 'B', &glyph));
g_assert_cmpuint (glyph, ==, 2);
g_assert_true (hb_font_get_nominal_glyph (font, 'C', &glyph));
g_assert_cmpuint (glyph, ==, 5);
const hb_codepoint_t unicodes[] = {'A', 'B', 'C'};
hb_codepoint_t glyphs[3];
g_assert_cmpuint (hb_font_get_nominal_glyphs (font, 3,
unicodes, sizeof (unicodes[0]),
glyphs, sizeof (glyphs[0])), ==, 3);
g_assert_cmpuint (glyphs[0], ==, 4);
g_assert_cmpuint (glyphs[1], ==, 2);
g_assert_cmpuint (glyphs[2], ==, 5);
g_assert_true (hb_font_get_variation_glyph (font, 'A', 0xFE0F, &glyph));
g_assert_cmpuint (glyph, ==, 6);
g_assert_true (hb_font_get_variation_glyph (font, 'B', 0xFE0F, &glyph));
g_assert_cmpuint (glyph, ==, 2);
g_assert_true (hb_font_get_variation_glyph (font, 'C', 0xFE0F, &glyph));
g_assert_cmpuint (glyph, ==, 3);
hb_font_destroy (font);
hb_set_t *set = hb_set_create ();
hb_map_t *mapping = hb_map_create ();
hb_face_collect_nominal_glyph_mapping (face, mapping, set);
g_assert_cmpuint (hb_set_get_population (set), ==, 3);
g_assert_cmpuint (hb_map_get (mapping, 'A'), ==, 4);
g_assert_cmpuint (hb_map_get (mapping, 'B'), ==, 2);
g_assert_cmpuint (hb_map_get (mapping, 'C'), ==, 5);
hb_map_destroy (mapping);
hb_set_clear (set);
hb_face_collect_variation_selectors (face, set);
g_assert_true (hb_set_has (set, 0xFE0F));
hb_set_clear (set);
hb_face_collect_variation_unicodes (face, 0xFE0F, set);
g_assert_cmpuint (hb_set_get_population (set), ==, 3);
g_assert_true (hb_set_has (set, 'A'));
g_assert_true (hb_set_has (set, 'B'));
g_assert_true (hb_set_has (set, 'C'));
hb_set_destroy (set);
hb_set_t *codepoints = hb_set_create ();
hb_set_add (codepoints, 'A');
hb_set_add (codepoints, 'B');
hb_set_add (codepoints, 'C');
hb_set_add (codepoints, 0xFE0F);
hb_face_t *subset = hb_subset_test_create_subset (face,
hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_blob_t *dmap = hb_face_reference_table (subset, HB_TAG ('D','M','A','P'));
g_assert_cmpuint (hb_blob_get_length (dmap), >, 0);
hb_blob_destroy (dmap);
font = hb_font_create (subset);
g_assert_true (hb_font_get_nominal_glyph (font, 'A', &glyph));
g_assert_cmpuint (glyph, ==, 3);
g_assert_true (hb_font_get_nominal_glyph (font, 'B', &glyph));
g_assert_cmpuint (glyph, ==, 1);
g_assert_true (hb_font_get_nominal_glyph (font, 'C', &glyph));
g_assert_cmpuint (glyph, ==, 4);
g_assert_true (hb_font_get_variation_glyph (font, 'A', 0xFE0F, &glyph));
g_assert_cmpuint (glyph, ==, 5);
g_assert_true (hb_font_get_variation_glyph (font, 'B', 0xFE0F, &glyph));
g_assert_cmpuint (glyph, ==, 1);
g_assert_true (hb_font_get_variation_glyph (font, 'C', 0xFE0F, &glyph));
g_assert_cmpuint (glyph, ==, 2);
hb_font_destroy (font);
hb_face_destroy (subset);
hb_face_destroy (face);
}
/* Many encoding records sharing one format 12 subtable whose group spans
* all of Unicode: the subsetter must collect the subtable once, and only
* up to the font's glyph count, instead of once per record. */
static void
test_subset_cmap_shared_subtable_many_records (void)
{
const unsigned num_records = 4000;
const char maxp_data[] = {
0, 0, 0x50, 0, 0, 3,
};
unsigned cmap_len = 4 + 8 * num_records + 16 + 12;
char *cmap_data = calloc (1, cmap_len);
g_assert_nonnull (cmap_data);
char *p = cmap_data;
*p++ = 0; *p++ = 0; /* version */
*p++ = num_records >> 8; *p++ = num_records & 0xFF; /* numTables */
unsigned subtable_offset = 4 + 8 * num_records;
for (unsigned i = 0; i < num_records; i++)
{
*p++ = 0; *p++ = 3; *p++ = 0; *p++ = 10; /* platform 3, encoding 10 */
*p++ = subtable_offset >> 24; *p++ = subtable_offset >> 16;
*p++ = subtable_offset >> 8; *p++ = subtable_offset;
}
const char subtable[] = {
0, 12, 0, 0, 0, 0, 0, 28, /* format 12 header */
0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 'A', 0, 0x10, 0xFF, 0xFF, 0, 0, 0, 1, /* U+0041..U+10FFFF -> 1... */
};
memcpy (p, subtable, sizeof (subtable));
hb_face_t *face = hb_face_builder_create ();
HB_FACE_ADD_TABLE (face, "maxp", maxp_data);
hb_blob_t *cmap_blob = hb_blob_create_or_fail (cmap_data, cmap_len,
HB_MEMORY_MODE_WRITABLE,
cmap_data, free);
hb_face_builder_add_table (face, HB_TAG ('c','m','a','p'), cmap_blob);
hb_blob_destroy (cmap_blob);
hb_set_t *codepoints = hb_set_create ();
hb_set_add (codepoints, 'A');
hb_face_t *subset = hb_subset_test_create_subset (face,
hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_font_t *font = hb_font_create (subset);
hb_codepoint_t glyph;
g_assert_true (hb_font_get_nominal_glyph (font, 'A', &glyph));
g_assert_cmpuint (glyph, ==, 1);
g_assert_false (hb_font_get_nominal_glyph (font, 'B', &glyph));
hb_font_destroy (font);
hb_face_destroy (subset);
hb_face_destroy (face);
}
/* Several encoding records that repeat one (platformID, encodingID) pair,
* two sharing a subtable and one with its own copy: the subset must keep
* only the first record of the pair, so the output cmap has a single
* encoding record and still maps the retained code point. */
static void
test_subset_cmap_repeated_encoding_records (void)
{
const char maxp_data[] = {
0, 0, 0x50, 0, 0, 3,
};
const char cmap_data[] = {
0, 0, 0, 3, /* version, numTables = 3 */
0, 3, 0, 10, 0, 0, 0, 28, /* (3,10) -> subtable A */
0, 3, 0, 10, 0, 0, 0, 28, /* (3,10) -> subtable A */
0, 3, 0, 10, 0, 0, 0, 56, /* (3,10) -> subtable B */
/* subtable A at 28 */
0, 12, 0, 0, 0, 0, 0, 28,
0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 'A', 0, 0x10, 0xFF, 0xFF, 0, 0, 0, 1,
/* subtable B at 56 */
0, 12, 0, 0, 0, 0, 0, 28,
0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 'A', 0, 0x10, 0xFF, 0xFF, 0, 0, 0, 1,
};
hb_face_t *face = hb_face_builder_create ();
HB_FACE_ADD_TABLE (face, "maxp", maxp_data);
HB_FACE_ADD_TABLE (face, "cmap", cmap_data);
hb_set_t *codepoints = hb_set_create ();
hb_set_add (codepoints, 'A');
hb_face_t *subset = hb_subset_test_create_subset (face,
hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_blob_t *out = hb_face_reference_table (subset, HB_TAG ('c','m','a','p'));
unsigned out_len = 0;
const char *out_data = hb_blob_get_data (out, &out_len);
g_assert_cmpuint (out_len, >=, 4);
unsigned num_tables = ((unsigned char) out_data[2] << 8) | (unsigned char) out_data[3];
g_assert_cmpuint (num_tables, ==, 1);
hb_blob_destroy (out);
hb_font_t *font = hb_font_create (subset);
hb_codepoint_t glyph;
g_assert_true (hb_font_get_nominal_glyph (font, 'A', &glyph));
g_assert_cmpuint (glyph, ==, 1);
hb_font_destroy (font);
hb_face_destroy (subset);
hb_face_destroy (face);
}
#ifndef HB_NO_BEYOND_64K
static void
test_subset_cmap_format15 (void)
{
const char MAXP_data[] = "\x00\x00\x50\x00\x01\x00\x02";
const char cmap_data[] = {
0, 0, 0, 3, /* cmap header */
0, 0, 0, 4, 0, 0, 0, 28, /* encoding records */
0, 0, 0, 5, 0, 0, 0, 56,
0, 0, 0, 5, 0, 0, 0, 86,
0, 12, 0, 0, 0, 0, 0, 28, /* format 12 header */
0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 'A', 0, 0, 0, 'A', 0, 1, 0, 1, /* format 12 group */
0, 14, 0, 0, 0, 30, 0, 0, 0, 1, /* format 14 header */
0, 0xFE, 0x0F, 0, 0, 0, 0, 0, 0, 0, 21, /* variation selector */
0, 0, 0, 1, 0, 0, 'A', 0, 2, /* non-default UVS */
0, 15, 0, 0, 0, 31, 0, 0, 0, 1, /* format 15 header */
0, 0xFE, 0x0F, 0, 0, 0, 0, 0, 0, 0, 21, /* variation selector */
0, 0, 0, 1, 0, 0, 'A', 1, 0, 1, /* non-default UVS */
};
hb_face_t *face = hb_face_builder_create ();
HB_FACE_ADD_TABLE (face, "MAXP", MAXP_data);
HB_FACE_ADD_TABLE (face, "cmap", cmap_data);
hb_font_t *font = hb_font_create (face);
hb_codepoint_t glyph;
g_assert_true (hb_font_get_variation_glyph (font, 'A', 0xFE0F, &glyph));
g_assert_cmpuint (glyph, ==, 0x10001);
hb_font_destroy (font);
hb_set_t *set = hb_set_create ();
hb_face_collect_variation_selectors (face, set);
g_assert_true (hb_set_has (set, 0xFE0F));
hb_set_clear (set);
hb_face_collect_variation_unicodes (face, 0xFE0F, set);
g_assert_true (hb_set_has (set, 'A'));
hb_set_destroy (set);
hb_set_t *codepoints = hb_set_create ();
hb_set_add (codepoints, 'A');
hb_set_add (codepoints, 0xFE0F);
hb_face_t *subset = hb_subset_test_create_subset (face,
hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
font = hb_font_create (subset);
g_assert_true (hb_font_get_variation_glyph (font, 'A', 0xFE0F, &glyph));
g_assert_cmpuint (glyph, ==, 2);
hb_font_destroy (font);
hb_face_destroy (subset);
hb_face_destroy (face);
}
#endif
// TODO(rsheeter) test cmap to no codepoints
int
main (int argc, char **argv)
{
hb_test_init (&argc, &argv);
hb_test_add (test_subset_cmap);
hb_test_add (test_subset_cmap_noop);
hb_test_add (test_subset_cmap_default_uvs_range_limit);
hb_test_add (test_subset_cmap_non_consecutive_glyphs);
hb_test_add (test_subset_cmap4_no_exceeding_maximum_codepoint);
hb_test_add (test_subset_cmap_empty_tables);
hb_test_add (test_subset_cmap_noto_color_emoji_noop);
hb_test_add (test_subset_cmap_noto_color_emoji_non_consecutive_glyphs);
hb_test_add (test_subset_DMAP);
hb_test_add (test_subset_cmap_shared_subtable_many_records);
hb_test_add (test_subset_cmap_repeated_encoding_records);
#ifndef HB_NO_BEYOND_64K
hb_test_add (test_subset_cmap_format15);
hb_test_add (test_subset_cmap15_default_uvs_range_limit);
#endif
return hb_test_run();
}