Skip to main content

Type1Font

Struct Type1Font 

Source
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

Source

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.

Source

pub fn container(&self) -> Container

Which wrapper the program arrived in.

Source

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.

Source

pub fn font_matrix(&self) -> Affine

The /FontMatrix: font units to text space.

Source

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.

Source

pub fn num_glyphs(&self) -> u32

Number of glyphs in /CharStrings.

Source

pub fn is_fixed_pitch(&self) -> bool

Whether the program declared /isFixedPitch true.

Source

pub fn italic_angle(&self) -> f32

/ItalicAngle, in degrees counter-clockwise from vertical (so an oblique face reports a negative value).

Source

pub fn postscript_name(&self) -> Option<&str>

/FontName — the PostScript name.

Source

pub fn full_name(&self) -> Option<&str>

/FullName from /FontInfo.

Source

pub fn family_name(&self) -> Option<&str>

/FamilyName from /FontInfo.

Source

pub fn encoding(&self) -> &Encoding

The font’s built-in /Encoding vector.

Source

pub fn code_to_gid(&self, code: u8) -> Option<Gid>

Character code to glyph, through the built-in encoding.

Source

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.

Source

pub fn unicode_pairs(&self) -> impl Iterator<Item = (char, Gid)> + '_

Every Unicode scalar the synthesized charmap maps, in arbitrary order.

Source

pub fn name_to_gid(&self, name: &str) -> Option<Gid>

Glyph name to glyph.

Source

pub fn glyph_name(&self, gid: Gid) -> Option<&str>

The name a glyph was declared under.

Source

pub fn has_glyph_names(&self) -> bool

Always true: Type 1 identifies glyphs by name, so every glyph has one.

Source

pub fn glyph_names(&self) -> impl Iterator<Item = (Gid, &str)>

Every (glyph name, glyph) pair, in glyph order.

Source

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.

Source

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.

Source

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.

Source

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

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”.

Source

pub fn default_weight_vector(&self) -> &[f32]

The weight vector the program shipped with, or an empty slice for a non-Multiple-Master font.

Trait Implementations§

Source§

impl Clone for Type1Font

Source§

fn clone(&self) -> Type1Font

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Type1Font

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.