Struct SubsetInput

Source
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

Source

pub fn new() -> Result<Self, AllocationError>

Creates a new subset input object.

Source

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.

Source

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());
Source

pub fn glyph_set(&mut self) -> U32Set<'_>

Gets the set of glyph IDs to retain.

The caller should modify the set as needed.

Source

pub fn unicode_set(&mut self) -> CharSet<'_>

Gets the set of Unicode codepoints to retain.

The caller should modify the set as needed.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn subset_font( &self, font: &FontFace<'_>, ) -> Result<FontFace<'static>, SubsettingError>

Subsets a font according to provided input.

Source

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

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for SubsetInput

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.