pub struct Type1Font { /* private fields */ }Expand description
A parsed Type 1 font program.
A record, not an engine: the fields below are everything the program said, and every method is a pure function of them. Outlines are computed on demand and not cached here — the caller’s glyph cache owns that, keyed by the instantiation as well as the glyph.
Implementations§
Source§impl Type1Font
impl Type1Font
Sourcepub fn parse(
bytes: &[u8],
limits: &Limits,
diags: &mut Diagnostics,
) -> Result<Self, Error>
pub fn parse( bytes: &[u8], limits: &Limits, diags: &mut Diagnostics, ) -> Result<Self, Error>
Parse a font program: sniff PFB/PFA/bare, decrypt eexec, read the
cleartext and private dictionaries.
/Length1, /Length2 and /Length3 from the font descriptor are
deliberately not a parameter. PDFium ignores them, because they are
wrong often enough that trusting them loses more fonts than it saves,
and the container is self-describing anyway.
§Errors
Error::Empty for no bytes, Error::PfbSegment for a PFB whose
first segment header is unusable, Error::NoEexec when no private
section can be found, and Error::NoCharStrings when the program
declares no glyphs.
Sourcepub fn units_per_em(&self) -> u16
pub fn units_per_em(&self) -> u16
Design units per em, derived from the /FontMatrix — a matrix of
0.001 means 1000 units per em.
Rounded to the nearest integer and floored at 1, because a rasterizer dividing by this must never divide by zero and a font declaring a degenerate matrix is not worth refusing over.
Sourcepub fn font_matrix(&self) -> Affine
pub fn font_matrix(&self) -> Affine
The /FontMatrix: font units to text space.
Sourcepub fn bbox(&self) -> Rect
pub fn bbox(&self) -> Rect
The declared /FontBBox, in font units. Rect::ZERO when the program
declared none — callers derive one from the glyphs in that case.
Sourcepub fn num_glyphs(&self) -> u32
pub fn num_glyphs(&self) -> u32
Number of glyphs in /CharStrings.
Sourcepub fn is_fixed_pitch(&self) -> bool
pub fn is_fixed_pitch(&self) -> bool
Whether the program declared /isFixedPitch true.
Sourcepub fn italic_angle(&self) -> f32
pub fn italic_angle(&self) -> f32
/ItalicAngle, in degrees counter-clockwise from vertical (so an
oblique face reports a negative value).
Sourcepub fn postscript_name(&self) -> Option<&str>
pub fn postscript_name(&self) -> Option<&str>
/FontName — the PostScript name.
Sourcepub fn family_name(&self) -> Option<&str>
pub fn family_name(&self) -> Option<&str>
/FamilyName from /FontInfo.
Sourcepub fn code_to_gid(&self, code: u8) -> Option<Gid>
pub fn code_to_gid(&self, code: u8) -> Option<Gid>
Character code to glyph, through the built-in encoding.
Sourcepub fn unicode_to_gid(&self, ch: char) -> Option<Gid>
pub fn unicode_to_gid(&self, ch: char) -> Option<Gid>
Unicode scalar to glyph, through the Adobe-Glyph-List charmap synthesized from the glyph names.
Sourcepub fn unicode_pairs(&self) -> impl Iterator<Item = (char, Gid)> + '_
pub fn unicode_pairs(&self) -> impl Iterator<Item = (char, Gid)> + '_
Every Unicode scalar the synthesized charmap maps, in arbitrary order.
Sourcepub fn name_to_gid(&self, name: &str) -> Option<Gid>
pub fn name_to_gid(&self, name: &str) -> Option<Gid>
Glyph name to glyph.
Sourcepub fn glyph_name(&self, gid: Gid) -> Option<&str>
pub fn glyph_name(&self, gid: Gid) -> Option<&str>
The name a glyph was declared under.
Sourcepub fn has_glyph_names(&self) -> bool
pub fn has_glyph_names(&self) -> bool
Always true: Type 1 identifies glyphs by name, so every glyph has one.
Sourcepub fn glyph_names(&self) -> impl Iterator<Item = (Gid, &str)>
pub fn glyph_names(&self) -> impl Iterator<Item = (Gid, &str)>
Every (glyph name, glyph) pair, in glyph order.
Sourcepub fn outline(&self, gid: Gid) -> Option<(BezPath, f32)>
pub fn outline(&self, gid: Gid) -> Option<(BezPath, f32)>
The unscaled outline in font units, and the advance width hsbw/sbw
declared.
The outline is not transformed by the /FontMatrix; a caller that
wants text-space coordinates applies font_matrix
itself, which is what pdfrum-font does so it can compose the matrix
with the text matrix in one step.
For a Multiple-Master font this uses the weight vector the program
shipped with — instantiate is how a caller asks
for a different one.
Sourcepub fn outline_with_diagnostics(
&self,
gid: Gid,
diags: &mut Diagnostics,
) -> Option<(BezPath, f32)>
pub fn outline_with_diagnostics( &self, gid: Gid, diags: &mut Diagnostics, ) -> Option<(BezPath, f32)>
outline, recording an interpretation failure.
The outline comes back either way; the diagnostic says whether it is the whole glyph or as much of it as the charstring allowed.
Sourcepub fn glyph_bounds(&self, gid: Gid) -> Option<Rect>
pub fn glyph_bounds(&self, gid: Gid) -> Option<Rect>
The glyph’s bounding box in font units, or None for an empty glyph
(a space) as well as for a glyph that does not exist.
Sourcepub fn mm_axes(&self) -> Option<&[MmAxis]>
pub fn mm_axes(&self) -> Option<&[MmAxis]>
The Multiple-Master design axes, or None for an ordinary font.
let font = Type1Font::parse(pfb, &Default::default(), &mut Diagnostics::default()).ok()?;
for axis in font.mm_axes()? {
assert!(axis.min <= axis.default && axis.default <= axis.max);
}Sourcepub fn instantiate(&self, coords: &[f32]) -> Option<Type1Instance<'_>>
pub fn instantiate(&self, coords: &[f32]) -> Option<Type1Instance<'_>>
Instantiate at design coordinates — one per axis, in
mm_axes order.
Coordinates outside an axis’s range clamp to it, and a short list
leaves the remaining axes at their defaults. Returns None for a font
with no Multiple-Master declaration, which is how a caller tells “this
face cannot vary” from “it varied to the value you asked for”.
Sourcepub fn default_weight_vector(&self) -> &[f32]
pub fn default_weight_vector(&self) -> &[f32]
The weight vector the program shipped with, or an empty slice for a non-Multiple-Master font.