pub struct SubsetInput(/* private fields */);
Expand description
A description of how a font should be subset.
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.
Implementations§
Source§impl SubsetInput
impl SubsetInput
Sourcepub fn new() -> Result<Self, AllocationError>
pub fn new() -> Result<Self, AllocationError>
Creates a new subset input object.
Sourcepub fn keep_everything(&mut self)
pub fn keep_everything(&mut self)
Configures 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.
Sourcepub fn flags(&mut self) -> FlagRef<'_>
pub fn flags(&mut self) -> FlagRef<'_>
Gets a proxy for modifying flags.
§Example
let mut subset = SubsetInput::new()?;
subset.flags().retain_glyph_names();
assert_eq!(*subset.flags(), *Flags::default().retain_glyph_names());
*subset.flags() = Flags::default();
assert_eq!(*subset.flags(), Flags::default());
Sourcepub fn glyph_set(&mut self) -> U32Set<'_>
pub fn glyph_set(&mut self) -> U32Set<'_>
Gets the set of glyph IDs to retain.
The caller should modify the set as needed.
Sourcepub fn unicode_set(&mut self) -> CharSet<'_>
pub fn unicode_set(&mut self) -> CharSet<'_>
Gets the set of Unicode codepoints to retain.
The caller should modify the set as needed.
Sourcepub fn no_subset_table_tag_set(&mut self) -> TagSet<'_>
pub fn no_subset_table_tag_set(&mut self) -> TagSet<'_>
Gets the set of table tags which specifies tables that should not be subsetted.
The caller should modify the set as needed.
Sourcepub fn drop_table_tag_set(&mut self) -> TagSet<'_>
pub fn drop_table_tag_set(&mut self) -> TagSet<'_>
Gets the set of table tags which specifies tables which will be dropped in the subset.
The caller should modify the set as needed.
Sourcepub fn name_id_set(&mut self) -> U32Set<'_>
pub fn name_id_set(&mut self) -> U32Set<'_>
Gets the set of name ids that will be retained.
The caller should modify the set as needed.
Sourcepub fn name_lang_id_set(&mut self) -> U32Set<'_>
pub fn name_lang_id_set(&mut self) -> U32Set<'_>
Gets the set of name lang ids that will be retained.
The caller should modify the set as needed.
Sourcepub fn layout_feature_tag_set(&mut self) -> TagSet<'_>
pub fn layout_feature_tag_set(&mut self) -> TagSet<'_>
Gets the set of layout feature tags that will be retained in the subset.
The caller should modify the set as needed.
Sourcepub fn layout_script_tag_set(&mut self) -> TagSet<'_>
pub fn layout_script_tag_set(&mut self) -> TagSet<'_>
Gets the set of layout script tags that will be retained in the subset.
Defaults to all tags. The caller should modify the set as needed.
Sourcepub fn old_to_new_glyph_mapping(&mut self) -> Map<'_, u32, u32>
pub fn old_to_new_glyph_mapping(&mut self) -> Map<'_, u32, u32>
Returns a map which can be used to provide an explicit mapping from old to new glyph id’s in the produced subset. The caller should populate the map as desired. If this map is left empty then glyph ids will be automatically mapped to new values by the subsetter. If populated, the mapping must be unique. That is no two original glyph ids can be mapped to the same new id. Additionally, if a mapping is provided then the retain gids option cannot be enabled.
Any glyphs that are retained in the subset which are not specified in this mapping will be assigned glyph ids after the highest glyph id in the mapping.
Note: this will accept and apply non-monotonic mappings, however this may result in unsorted Coverage tables. Such fonts may not work for all use cases (for example ots will reject unsorted coverage tables). So it’s recommended, if possible, to supply a monotonic mapping.
Sourcepub fn subset_font(
&self,
font: &FontFace<'_>,
) -> Result<FontFace<'static>, SubsettingError>
pub fn subset_font( &self, font: &FontFace<'_>, ) -> Result<FontFace<'static>, SubsettingError>
Subsets a font according to provided input.
Sourcepub fn plan<'f>(
&self,
font: &'f FontFace<'_>,
) -> Result<SubsetPlan<'f, '_>, SubsettingError>
pub fn plan<'f>( &self, font: &'f FontFace<'_>, ) -> Result<SubsetPlan<'f, '_>, SubsettingError>
Computes a plan for subsetting the supplied face according to a provided input.
The plan describes which tables and glyphs should be retained.
Source§impl SubsetInput
impl SubsetInput
Sourcepub fn into_raw(self) -> *mut hb_subset_input_t
pub fn into_raw(self) -> *mut hb_subset_input_t
Converts the subset input into raw sys::hb_subset_input_t
pointer.
This method transfers the ownership of the subset input to the caller. It is up to the caller to call
sys::hb_subset_input_destroy
to free the pointer, or call Self::from_raw
to convert it back into
SubsetInput
.
Sourcepub fn as_raw(&self) -> *mut hb_subset_input_t
pub fn as_raw(&self) -> *mut hb_subset_input_t
Exposes the raw inner pointer without transferring the ownership.
Unlike Self::into_raw
, this method does not transfer the ownership of the pointer to the caller.
Sourcepub unsafe fn from_raw(subset: *mut hb_subset_input_t) -> Self
pub unsafe fn from_raw(subset: *mut hb_subset_input_t) -> Self
Constructs a subset input from raw sys::hb_subset_input_t
pointer.
§Safety
The given subset
pointer must either be constructed by some Harfbuzz function, or be returned from
Self::into_raw
.