[subset] Add one ttf file with fvar/STAT tables to integration test

Ignore gvar/MVAR/HVAR table
add support for --nameIDs=* option
This commit is contained in:
Qunxin Liu 2019-05-14 13:55:11 -07:00 committed by Garret Rieger
parent a03ed95e7d
commit 993d81b9c5
75 changed files with 50 additions and 18 deletions

View File

@ -863,6 +863,7 @@ struct cmap
if (unlikely (!CmapSubtableFormat4::create_sub_table_plan (plan, &cmap_plan->format4_segments)))
return false;
if (!find_subtable (12)) return true;
return CmapSubtableFormat12::create_sub_table_plan (plan, &cmap_plan->format12_groups);
}
@ -881,8 +882,7 @@ struct cmap
table->version = 0;
if (unlikely (!table->encodingRecord.serialize (&c, /* numTables */ 3)))
return false;
if (unlikely (!table->encodingRecord.serialize (&c, /* numTables */ cmap_subset_plan.format12_groups ? 3 : 2))) return false;
// TODO(grieger): Convert the below to a for loop
@ -897,9 +897,12 @@ struct cmap
format4_plat3_rec.encodingID = 1; // Unicode BMP
// Format 12 Encoding Record
EncodingRecord &format12_rec = table->encodingRecord[2];
format12_rec.platformID = 3; // Windows
format12_rec.encodingID = 10; // Unicode UCS-4
if (cmap_subset_plan.format12_groups)
{
EncodingRecord &format12_rec = table->encodingRecord[2];
format12_rec.platformID = 3; // Windows
format12_rec.encodingID = 10; // Unicode UCS-4
}
// Write out format 4 sub table
{
@ -913,7 +916,9 @@ struct cmap
}
// Write out format 12 sub table.
if (cmap_subset_plan.format12_groups)
{
EncodingRecord &format12_rec = table->encodingRecord[2];
CmapSubtable &subtable = format12_rec.subtable.serialize (&c, table);
subtable.u.format = 12;
@ -1154,6 +1159,18 @@ struct cmap
return &(this+result.subtable);
}
bool find_subtable (unsigned format) const
{
auto it =
+ hb_iter (encodingRecord)
| hb_map (&EncodingRecord::subtable)
| hb_map (hb_add (this))
| hb_filter ([&] (const CmapSubtable& _) { return _.u.format == format; })
;
return it.len ();
}
public:
bool sanitize (hb_sanitize_context_t *c) const

View File

@ -289,7 +289,7 @@ struct STAT
;
+ get_axis_value_offsets ()
| hb_map (hb_add (this))
| hb_map (hb_add (&(this + offsetToAxisValueOffsets)))
| hb_map (&AxisValue::get_value_name_id)
| hb_sink (nameids_to_retain)
;

View File

@ -45,6 +45,7 @@ hb_subset_input_create_or_fail ()
input->unicodes = hb_set_create ();
input->glyphs = hb_set_create ();
input->name_ids = hb_set_create ();
hb_set_add_range (input->name_ids, 0, 6);
input->drop_tables = hb_set_create ();
input->drop_hints = false;
input->desubroutinize = false;

View File

@ -234,12 +234,8 @@ hb_subset_plan_create (hb_face_t *face,
plan->retain_gids = input->retain_gids;
plan->unicodes = hb_set_create ();
plan->name_ids = hb_set_reference (input->name_ids);
plan->drop_tables = hb_set_reference (input->drop_tables);
/* TODO Clean this up... */
if (hb_set_is_empty (plan->name_ids))
hb_set_add_range (plan->name_ids, 0, 0x7FFF);
_nameid_closure (face, plan->name_ids);
plan->drop_tables = hb_set_reference (input->drop_tables);
plan->source = hb_face_reference (face);
plan->dest = hb_face_builder_create ();

View File

@ -70,7 +70,7 @@ hb_subset_test_create_input_from_nameids (const hb_set_t *name_ids)
{
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
hb_set_t * input_name_ids = hb_subset_input_nameid_set (input);
hb_set_union (input_name_ids, name_ids);
hb_set_set (input_name_ids, name_ids);
return input;
}

Binary file not shown.

View File

@ -1,5 +1,6 @@
FONTS:
Roboto-Regular.abc.ttf
Comfortaa-Regular-new.ttf
PROFILES:
default.txt

View File

@ -20,11 +20,10 @@ def usage():
def generate_expected_output(input_file, unicodes, profile_flags, output_path):
args = ["fonttools", "subset", input_file]
args.extend(["--notdef-outline",
"--name-IDs=*",
"--name-languages=*",
"--name-legacy",
"--drop-tables+=DSIG,GPOS,GSUB,GDEF",
"--layout-features=*",
"--drop-tables+=DSIG,GPOS,GSUB,GDEF,gvar,avar,MVAR,HVAR",
"--unicodes=%s" % unicodes,
"--output-file=%s" % output_path])
args.extend(profile_flags)

View File

@ -66,7 +66,8 @@ def run_test(test, should_check_ots):
cli_args = [hb_subset,
"--font-file=" + test.font_path,
"--output-file=" + out_file,
"--unicodes=%s" % test.unicodes ()]
"--unicodes=%s" % test.unicodes (),
"--drop-tables+=DSIG,GPOS,GSUB,GDEF,gvar,avar,MVAR,HVAR"]
cli_args.extend (test.get_profile_flags ())
print (' '.join (cli_args))
_, return_code = cmd (cli_args)

View File

@ -29,7 +29,7 @@
#include "hb-subset-input.hh"
static gboolean
parse_nameids (const char *name G_GNUC_UNUSED,
parse_nameids (const char *name,
const char *arg,
gpointer data,
GError **error G_GNUC_UNUSED)
@ -37,7 +37,19 @@ parse_nameids (const char *name G_GNUC_UNUSED,
subset_options_t *subset_opts = (subset_options_t *) data;
hb_set_t *name_ids = subset_opts->input->name_ids;
hb_set_clear (name_ids);
char last_name_char = name[strlen (name) - 1];
if (last_name_char != '+' && last_name_char != '-')
hb_set_clear (name_ids);
if (0 == strcmp (arg, "*"))
{
if (last_name_char == '-')
hb_set_del_range (name_ids, 0, 0x7FFF);
else
hb_set_add_range (name_ids, 0, 0x7FFF);
return true;
}
char *s = (char *) arg;
char *p;
@ -59,7 +71,12 @@ parse_nameids (const char *name G_GNUC_UNUSED,
return false;
}
hb_set_add (name_ids, u);
if (last_name_char != '-')
{
hb_set_add (name_ids, u);
} else {
hb_set_del (name_ids, u);
}
s = p;
}