Skip to main content

subset

Function subset 

Source
pub fn subset(font_bytes: &[u8], gids: &[u16]) -> Result<Subsetted, Error>
Expand description

Subset a font program to gids.

The returned program contains those glyphs and nothing else, renumbered into a contiguous space starting at 0 with .notdef first. Everything PDF-side that named a glyph must be looked up through Subsetted::gid_map.

.notdef (glyph 0) is always included whether or not it was asked for, because a font without it is malformed.

§Errors

Error::Subset when the program cannot be parsed or subsetted — a format the subsetter does not handle (CFF2 without variable-font support), a truncated table directory, or a glyph ID past the end of the font.

let subset = pdfrum_edit::subset(font_bytes, &[3, 7])?;
// Glyph 0 is always kept, so the map holds three entries.
assert_eq!(subset.gid_map.get(0), Some(0));
assert!(subset.bytes.len() < font_bytes.len());