Skip to content

Commit

Permalink
[subset] Add hb_subset_input_keep_everything()
Browse files Browse the repository at this point in the history
Fixes #3998

New API:
+ hb_subset_input_keep_everything()
  • Loading branch information
behdad committed Jan 1, 2023
1 parent d87add4 commit 4a5bd7a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/harfbuzz-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ hb_subset_input_reference
hb_subset_input_destroy
hb_subset_input_set_user_data
hb_subset_input_get_user_data
hb_subset_input_keep_everything
hb_subset_input_set_flags
hb_subset_input_get_flags
hb_subset_input_unicode_set
Expand Down
56 changes: 37 additions & 19 deletions src/hb-subset-input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,42 @@ hb_subset_input_get_user_data (const hb_subset_input_t *input,
return hb_object_get_user_data (input, key);
}

/**
* hb_subset_input_keep_everything:
* @input: a #hb_subset_input_t object
*
* Configure input object to keep everything in the font face.
* That is, all Unicodes, glyphs, names, layout items,
* glyph names, etc.
*
* The input can be tailored afterwards by the caller.
*
* Since: REPLACEME
*/
void
hb_subset_input_keep_everything (hb_subset_input_t *input)
{
const hb_subset_sets_t indices[] = {HB_SUBSET_SETS_UNICODE,
HB_SUBSET_SETS_GLYPH_INDEX,
HB_SUBSET_SETS_NAME_ID,
HB_SUBSET_SETS_NAME_LANG_ID,
HB_SUBSET_SETS_LAYOUT_FEATURE_TAG,
HB_SUBSET_SETS_LAYOUT_SCRIPT_TAG};

for (auto idx : hb_iter (indices))
{
hb_set_t *set = hb_subset_input_set (input, idx);
hb_set_clear (set);
hb_set_invert (set);
}

hb_subset_input_set_flags (input,
HB_SUBSET_FLAGS_NOTDEF_OUTLINE |
HB_SUBSET_FLAGS_GLYPH_NAMES |
HB_SUBSET_FLAGS_RETAIN_GIDS |
HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES);
}

#ifndef HB_NO_VAR
/**
* hb_subset_input_pin_axis_to_default: (skip)
Expand Down Expand Up @@ -482,25 +518,7 @@ hb_subset_preprocess (hb_face_t *source)
if (!input)
return hb_face_reference (source);

const hb_subset_sets_t indices[] = {HB_SUBSET_SETS_UNICODE,
HB_SUBSET_SETS_GLYPH_INDEX,
HB_SUBSET_SETS_NAME_ID,
HB_SUBSET_SETS_NAME_LANG_ID,
HB_SUBSET_SETS_LAYOUT_FEATURE_TAG,
HB_SUBSET_SETS_LAYOUT_SCRIPT_TAG};

for (auto idx : hb_iter (indices))
{
hb_set_t *set = hb_subset_input_set (input, idx);
hb_set_clear (set);
hb_set_invert (set);
}

hb_subset_input_set_flags(input,
HB_SUBSET_FLAGS_NOTDEF_OUTLINE |
HB_SUBSET_FLAGS_GLYPH_NAMES |
HB_SUBSET_FLAGS_RETAIN_GIDS |
HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES);
hb_subset_input_keep_everything (input);

input->attach_accelerator_data = true;

Expand Down
3 changes: 3 additions & 0 deletions src/hb-subset.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ HB_EXTERN void *
hb_subset_input_get_user_data (const hb_subset_input_t *input,
hb_user_data_key_t *key);

HB_EXTERN void
hb_subset_input_keep_everything (hb_subset_input_t *input);

HB_EXTERN hb_set_t *
hb_subset_input_unicode_set (hb_subset_input_t *input);

Expand Down
15 changes: 15 additions & 0 deletions util/hb-subset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,19 @@ parse_name_languages (const char *name,
return true;
}

static gboolean
_keep_everything (const char *name,
const char *arg,
gpointer data,
GError **error G_GNUC_UNUSED)
{
subset_main_t *subset_main = (subset_main_t *) data;

hb_subset_input_keep_everything (subset_main->input);

return true;
}

template <hb_subset_flags_t flag>
static gboolean
set_flag (const char *name,
Expand Down Expand Up @@ -918,6 +931,8 @@ subset_main_t::add_options ()

GOptionEntry flag_entries[] =
{
{"keep-everything", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &_keep_everything,
"Keep everything by default. Options after this can override the operation.", nullptr},
{"no-hinting", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_NO_HINTING>, "Whether to drop hints", nullptr},
{"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},
Expand Down

0 comments on commit 4a5bd7a

Please sign in to comment.