mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 23:41:03 +01:00
[subset] Add HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET
When set and subsetting a CID-keyed CFF font, the output charset is written as identity: CID = new GID.
This commit is contained in:
1 parent
884f5a7991
commit
f3dea1e602
5 files changed
+70
-7
No files matched your search
+15
-7
@@ -529,7 +529,7 @@ struct cff1_subset_plan
|
||||
if (it->first == 0) it++;
|
||||
auto _ = *it;
|
||||
bool not_is_cid = !acc.is_CID ();
|
||||
bool skip = !not_is_cid && glyph_to_sid_map;
|
||||
bool skip = !not_is_cid && glyph_to_sid_map && !identity_charset;
|
||||
if (not_is_cid)
|
||||
sidmap.alloc (num_glyphs);
|
||||
for (hb_codepoint_t glyph = 1; glyph < num_glyphs; glyph++)
|
||||
@@ -545,12 +545,18 @@ struct cff1_subset_plan
|
||||
/* Retain the SID for the old missing glyph ID */
|
||||
old_glyph = glyph;
|
||||
}
|
||||
unsigned sid = glyph_to_sid_map ?
|
||||
glyph_to_sid_map->arrayZ[old_glyph].code :
|
||||
acc.glyph_to_sid (old_glyph, &glyph_to_sid_cache);
|
||||
unsigned sid;
|
||||
if (identity_charset)
|
||||
sid = glyph;
|
||||
else
|
||||
{
|
||||
sid = glyph_to_sid_map ?
|
||||
glyph_to_sid_map->arrayZ[old_glyph].code :
|
||||
acc.glyph_to_sid (old_glyph, &glyph_to_sid_cache);
|
||||
|
||||
if (not_is_cid)
|
||||
sid = sidmap.add (sid);
|
||||
if (not_is_cid)
|
||||
sid = sidmap.add (sid);
|
||||
}
|
||||
|
||||
if (sid != last_sid + 1)
|
||||
subset_charset_ranges.push (code_pair_t {sid, glyph});
|
||||
@@ -621,6 +627,7 @@ struct cff1_subset_plan
|
||||
orig_fdcount = acc.fdCount;
|
||||
drop_hints = plan->flags & HB_SUBSET_FLAGS_NO_HINTING;
|
||||
desubroutinize = plan->flags & HB_SUBSET_FLAGS_DESUBROUTINIZE;
|
||||
identity_charset = (plan->flags & HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET) && acc.is_CID ();
|
||||
|
||||
#ifdef HB_EXPERIMENTAL_API
|
||||
min_charstrings_off_size = (plan->flags & HB_SUBSET_FLAGS_IFTB_REQUIREMENTS) ? 4 : 0;
|
||||
@@ -628,7 +635,7 @@ struct cff1_subset_plan
|
||||
min_charstrings_off_size = 0;
|
||||
#endif
|
||||
|
||||
subset_charset = !acc.is_predef_charset ();
|
||||
subset_charset = !acc.is_predef_charset () || identity_charset;
|
||||
if (!subset_charset)
|
||||
/* check whether the subset renumbers any glyph IDs */
|
||||
for (const auto &_ : plan->new_to_old_gid_list)
|
||||
@@ -786,6 +793,7 @@ struct cff1_subset_plan
|
||||
unsigned int topDictModSIDs[name_dict_values_t::ValCount];
|
||||
|
||||
bool desubroutinize = false;
|
||||
bool identity_charset = false;
|
||||
|
||||
unsigned min_charstrings_off_size = 0;
|
||||
};
|
||||
|
||||
@@ -87,6 +87,9 @@ typedef struct hb_subset_plan_t hb_subset_plan_t;
|
||||
* @HB_SUBSET_FLAGS_DOWNGRADE_CFF2: If set and instantiating a variable font
|
||||
* with all axes pinned, convert the output CFF2 table to CFF1. This enables
|
||||
* compatibility with older renderers that don't support CFF2. Since: 13.0.0
|
||||
* @HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET: If set and subsetting a CID-keyed CFF
|
||||
* font, the output CFF charset will use sequential identity CIDs (CID = new
|
||||
* GID) rather than preserving the original CIDs. XSince: REPLACEME
|
||||
*
|
||||
* List of boolean properties that can be configured on the subset input.
|
||||
*
|
||||
@@ -111,6 +114,7 @@ typedef enum { /*< flags >*/
|
||||
HB_SUBSET_FLAGS_RETAIN_NUM_GLYPHS = 0x00002000u,
|
||||
#endif
|
||||
HB_SUBSET_FLAGS_DOWNGRADE_CFF2 = 0x00004000u,
|
||||
HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET = 0x00008000u,
|
||||
} hb_subset_flags_t;
|
||||
|
||||
/**
|
||||
|
||||
Binary file not shown.
@@ -336,6 +336,54 @@ test_subset_cff1_j_retaingids (void)
|
||||
hb_face_destroy (face_41_4c2e);
|
||||
}
|
||||
|
||||
static void
|
||||
test_subset_cff1_identity_charset (void)
|
||||
{
|
||||
/* The flag has no effect on a name-keyed font, so this is the same output
|
||||
* as test_subset_cff1(). */
|
||||
hb_face_t *face_abc = hb_test_open_font_file ("fonts/SourceSansPro-Regular.abc.otf");
|
||||
hb_face_t *face_ac = hb_test_open_font_file ("fonts/SourceSansPro-Regular.ac.otf");
|
||||
|
||||
hb_set_t *codepoints = hb_set_create ();
|
||||
hb_subset_input_t *input;
|
||||
hb_face_t *face_abc_subset;
|
||||
hb_set_add (codepoints, 'a');
|
||||
hb_set_add (codepoints, 'c');
|
||||
input = hb_subset_test_create_input (codepoints);
|
||||
hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET);
|
||||
face_abc_subset = hb_subset_test_create_subset (face_abc, input);
|
||||
hb_set_destroy (codepoints);
|
||||
|
||||
hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('C','F','F',' '));
|
||||
|
||||
hb_face_destroy (face_abc_subset);
|
||||
hb_face_destroy (face_abc);
|
||||
hb_face_destroy (face_ac);
|
||||
}
|
||||
|
||||
static void
|
||||
test_subset_cff1_j_identity_charset (void)
|
||||
{
|
||||
hb_face_t *face_41_3041_4c2e = hb_test_open_font_file ("fonts/SourceHanSans-Regular.41,3041,4C2E.otf");
|
||||
hb_face_t *face_41_4c2e = hb_test_open_font_file ("fonts/SourceHanSans-Regular.41,4C2E.identity.otf");
|
||||
|
||||
hb_set_t *codepoints = hb_set_create ();
|
||||
hb_subset_input_t *input;
|
||||
hb_face_t *face_41_3041_4c2e_subset;
|
||||
hb_set_add (codepoints, 0x41);
|
||||
hb_set_add (codepoints, 0x4C2E);
|
||||
input = hb_subset_test_create_input (codepoints);
|
||||
hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET);
|
||||
face_41_3041_4c2e_subset = hb_subset_test_create_subset (face_41_3041_4c2e, input);
|
||||
hb_set_destroy (codepoints);
|
||||
|
||||
hb_subset_test_check (face_41_4c2e, face_41_3041_4c2e_subset, HB_TAG ('C','F','F',' '));
|
||||
|
||||
hb_face_destroy (face_41_3041_4c2e_subset);
|
||||
hb_face_destroy (face_41_3041_4c2e);
|
||||
hb_face_destroy (face_41_4c2e);
|
||||
}
|
||||
|
||||
#ifdef HB_EXPERIMENTAL_API
|
||||
static void
|
||||
test_subset_cff1_iftb_requirements (void)
|
||||
@@ -383,6 +431,8 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_subset_cff1_dotsection);
|
||||
hb_test_add (test_subset_cff1_retaingids);
|
||||
hb_test_add (test_subset_cff1_j_retaingids);
|
||||
hb_test_add (test_subset_cff1_identity_charset);
|
||||
hb_test_add (test_subset_cff1_j_identity_charset);
|
||||
|
||||
#ifdef HB_EXPERIMENTAL_API
|
||||
hb_test_add (test_subset_cff1_iftb_requirements);
|
||||
|
||||
@@ -981,6 +981,7 @@ subset_main_t::add_options ()
|
||||
{"retain-gids", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_RETAIN_GIDS>, "If set don't renumber glyph ids in the subset.", nullptr},
|
||||
{"desubroutinize", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_DESUBROUTINIZE>, "Remove CFF/CFF2 use of subroutines", nullptr},
|
||||
{"downgrade-cff2", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_DOWNGRADE_CFF2>, "Convert instantiated variable fonts from CFF2 to CFF1", nullptr},
|
||||
{"cff-identity-charset", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET>, "Emit identity CFF charset (CID = new GID) for CID-keyed CFF", nullptr},
|
||||
{"name-legacy", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_NAME_LEGACY>, "Keep legacy (non-Unicode) 'name' table entries", nullptr},
|
||||
{"set-overlaps-flag", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_SET_OVERLAPS_FLAG>, "Set the overlaps flag on each glyph.", nullptr},
|
||||
{"notdef-outline", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_NOTDEF_OUTLINE>, "Keep the outline of \'.notdef\' glyph", nullptr},
|
||||
|
||||
Reference in new issue
Block a user