hb-subset

hb-subset — Subsets font files.

Functions

Types and Values

Includes

#include <hb-subset.h>

Description

Subsetting reduces the codepoint coverage of font files and removes all data that is no longer needed. A subset input describes the desired subset. The input is provided along with a font to the subsetting operation. Output is a new font file containing only the data specified in the input.

Currently most outline and bitmap tables are supported: glyf, CFF, CFF2, sbix, COLR, and CBDT/CBLC. This also includes fonts with variable outlines via OpenType variations. Notably EBDT/EBLC and SVG are not supported. Layout subsetting is supported only for OpenType Layout tables (GSUB, GPOS, GDEF). Notably subsetting of graphite or AAT tables is not yet supported.

Fonts with graphite or AAT tables may still be subsetted but will likely need to use the retain glyph ids option and configure the subset to pass through the layout tables untouched.

Functions

hb_subset_input_create_or_fail ()

hb_subset_input_t *
hb_subset_input_create_or_fail (void);

Creates a new subset input object.

Returns

New subset input, or NULL if failed. Destroy with hb_subset_input_destroy().

[transfer full]

Since: 1.8.0


hb_subset_input_reference ()

hb_subset_input_t *
hb_subset_input_reference (hb_subset_input_t *input);

Increases the reference count on input .

[skip]

Parameters

input

a hb_subset_input_t object.

 

Returns

input .

Since: 1.8.0


hb_subset_input_destroy ()

void
hb_subset_input_destroy (hb_subset_input_t *input);

Decreases the reference count on input , and if it reaches zero, destroys input , freeing all memory.

Parameters

input

a hb_subset_input_t object.

 

Since: 1.8.0


hb_subset_input_set_user_data ()

hb_bool_t
hb_subset_input_set_user_data (hb_subset_input_t *input,
                               hb_user_data_key_t *key,
                               void *data,
                               hb_destroy_func_t destroy,
                               hb_bool_t replace);

Attaches a user-data key/data pair to the given subset input object.

[skip]

Parameters

input

a hb_subset_input_t object.

 

key

The user-data key to set

 

data

A pointer to the user data

 

destroy

A callback to call when data is not needed anymore.

[nullable]

replace

Whether to replace an existing data with the same key

 

Returns

true if success, false otherwise

Since: 2.9.0


hb_subset_input_get_user_data ()

void *
hb_subset_input_get_user_data (const hb_subset_input_t *input,
                               hb_user_data_key_t *key);

Fetches the user data associated with the specified key, attached to the specified subset input object.

[skip]

Parameters

input

a hb_subset_input_t object.

 

key

The user-data key to query

 

Returns

A pointer to the user data.

[transfer none]

Since: 2.9.0


hb_subset_input_get_flags ()

hb_subset_flags_t
hb_subset_input_get_flags (hb_subset_input_t *input);

Gets all of the subsetting flags in the input object.

Parameters

input

a hb_subset_input_t object.

 

Returns

the subsetting flags bit field.

Since: 2.9.0


hb_subset_input_set_flags ()

void
hb_subset_input_set_flags (hb_subset_input_t *input,
                           unsigned  value);

Sets all of the flags in the input object to the values specified by the bit field.

Parameters

input

a hb_subset_input_t object.

 

value

bit field of flags

 

Since: 2.9.0


hb_subset_input_unicode_set ()

hb_set_t *
hb_subset_input_unicode_set (hb_subset_input_t *input);

Gets the set of Unicode code points to retain, the caller should modify the set as needed.

Parameters

input

a hb_subset_input_t object.

 

Returns

pointer to the hb_set_t of Unicode code points.

[transfer none]

Since: 1.8.0


hb_subset_input_glyph_set ()

hb_set_t *
hb_subset_input_glyph_set (hb_subset_input_t *input);

Gets the set of glyph IDs to retain, the caller should modify the set as needed.

Parameters

input

a hb_subset_input_t object.

 

Returns

pointer to the hb_set_t of glyph IDs.

[transfer none]

Since: 1.8.0


hb_subset_input_set ()

hb_set_t *
hb_subset_input_set (hb_subset_input_t *input,
                     hb_subset_sets_t set_type);

Gets the set of the specified type.

Parameters

input

a hb_subset_input_t object.

 

set_type

a hb_subset_sets_t set type.

 

Returns

pointer to the hb_set_t of the specified type.

[transfer none]

Since: 2.9.1


hb_subset_or_fail ()

hb_face_t *
hb_subset_or_fail (hb_face_t *source,
                   const hb_subset_input_t *input);

Subsets a font according to provided input. Returns nullptr if the subset operation fails.

Parameters

source

font face data to be subset.

 

input

input to use for the subsetting.

 

Since: 2.9.0


hb_subset_plan_create_or_fail ()

hb_subset_plan_t *
hb_subset_plan_create_or_fail (hb_face_t *face,
                               const hb_subset_input_t *input);

Computes a plan for subsetting the supplied face according to a provided input. The plan describes which tables and glyphs should be retained.

Parameters

face

font face to create the plan for.

 

input

a hb_subset_input_t input.

 

Returns

New subset plan. Destroy with hb_subset_plan_destroy(). If there is a failure creating the plan nullptr will be returned.

[transfer full]

Since: 4.0.0


hb_subset_plan_reference ()

hb_subset_plan_t *
hb_subset_plan_reference (hb_subset_plan_t *plan);

Increases the reference count on plan .

[skip]

Parameters

plan

a hb_subset_plan_t object.

 

Returns

plan .

Since: 4.0.0


hb_subset_plan_destroy ()

void
hb_subset_plan_destroy (hb_subset_plan_t *plan);

Decreases the reference count on plan , and if it reaches zero, destroys plan , freeing all memory.

Parameters

plan

a hb_subset_plan_t

 

Since: 4.0.0


hb_subset_plan_set_user_data ()

hb_bool_t
hb_subset_plan_set_user_data (hb_subset_plan_t *plan,
                              hb_user_data_key_t *key,
                              void *data,
                              hb_destroy_func_t destroy,
                              hb_bool_t replace);

Attaches a user-data key/data pair to the given subset plan object.

[skip]

Parameters

plan

a hb_subset_plan_t object.

 

key

The user-data key to set

 

data

A pointer to the user data

 

destroy

A callback to call when data is not needed anymore.

[nullable]

replace

Whether to replace an existing data with the same key

 

Returns

true if success, false otherwise

Since: 4.0.0


hb_subset_plan_get_user_data ()

void *
hb_subset_plan_get_user_data (const hb_subset_plan_t *plan,
                              hb_user_data_key_t *key);

Fetches the user data associated with the specified key, attached to the specified subset plan object.

[skip]

Parameters

plan

a hb_subset_plan_t object.

 

key

The user-data key to query

 

Returns

A pointer to the user data.

[transfer none]

Since: 4.0.0


hb_subset_plan_execute_or_fail ()

hb_face_t *
hb_subset_plan_execute_or_fail (hb_subset_plan_t *plan);

Executes the provided subsetting plan .

Parameters

plan

a subsetting plan.

 

Returns

on success returns a reference to generated font subset. If the subsetting operation fails returns nullptr.

Since: 4.0.0


hb_subset_plan_unicode_to_old_glyph_mapping ()

const hb_map_t *
hb_subset_plan_unicode_to_old_glyph_mapping
                               (const hb_subset_plan_t *plan);

Returns the mapping between codepoints in the original font and the associated glyph id in the original font.

Parameters

plan

a subsetting plan.

 

Returns

A pointer to the hb_map_t of the mapping.

[transfer none]

Since: 4.0.0


hb_subset_plan_new_to_old_glyph_mapping ()

const hb_map_t *
hb_subset_plan_new_to_old_glyph_mapping
                               (const hb_subset_plan_t *plan);

Returns the mapping between glyphs in the subset that will be produced by plan and the glyph in the original font.

Parameters

plan

a subsetting plan.

 

Returns

A pointer to the hb_map_t of the mapping.

[transfer none]

Since: 4.0.0


hb_subset_plan_old_to_new_glyph_mapping ()

const hb_map_t *
hb_subset_plan_old_to_new_glyph_mapping
                               (const hb_subset_plan_t *plan);

Returns the mapping between glyphs in the original font to glyphs in the subset that will be produced by plan

Parameters

plan

a subsetting plan.

 

Returns

A pointer to the hb_map_t of the mapping.

[transfer none]

Since: 4.0.0

Types and Values

enum hb_subset_flags_t

List of boolean properties that can be configured on the subset input.

Members

HB_SUBSET_FLAGS_DEFAULT

all flags at their default value of false.

 

HB_SUBSET_FLAGS_NO_HINTING

If set hinting instructions will be dropped in the produced subset. Otherwise hinting instructions will be retained.

 

HB_SUBSET_FLAGS_RETAIN_GIDS

If set glyph indices will not be modified in the produced subset. If glyphs are dropped their indices will be retained as an empty glyph.

 

HB_SUBSET_FLAGS_DESUBROUTINIZE

If set and subsetting a CFF font the subsetter will attempt to remove subroutines from the CFF glyphs.

 

HB_SUBSET_FLAGS_NAME_LEGACY

If set non-unicode name records will be retained in the subset.

 

HB_SUBSET_FLAGS_SET_OVERLAPS_FLAG

If set the subsetter will set the OVERLAP_SIMPLE flag on each simple glyph.

 

HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED

If set the subsetter will not drop unrecognized tables and instead pass them through untouched.

 

HB_SUBSET_FLAGS_NOTDEF_OUTLINE

If set the notdef glyph outline will be retained in the final subset.

 

HB_SUBSET_FLAGS_GLYPH_NAMES

If set the PS glyph names will be retained in the final subset.

 

HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES

If set then the unicode ranges in OS/2 will not be recalculated.

 

Since: 2.9.0


hb_subset_input_t

typedef struct hb_subset_input_t hb_subset_input_t;

Things that change based on the input. Characters to keep, etc.


enum hb_subset_sets_t

List of sets that can be configured on the subset input.

Members

HB_SUBSET_SETS_GLYPH_INDEX

the set of glyph indexes to retain in the subset.

 

HB_SUBSET_SETS_UNICODE

the set of unicode codepoints to retain in the subset.

 

HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG

the set of table tags which specifies tables that should not be subsetted.

 

HB_SUBSET_SETS_DROP_TABLE_TAG

the set of table tags which specifies tables which will be dropped in the subset.

 

HB_SUBSET_SETS_NAME_ID

the set of name ids that will be retained.

 

HB_SUBSET_SETS_NAME_LANG_ID

the set of name lang ids that will be retained.

 

HB_SUBSET_SETS_LAYOUT_FEATURE_TAG

the set of layout feature tags that will be retained in the subset.

 

Since: 2.9.1


hb_subset_plan_t

typedef struct hb_subset_plan_t hb_subset_plan_t;

Contains information about how the subset operation will be executed. Such as mappings from the old glyph ids to the new ones in the subset.