Expand description
§pdfrum-type1
Type 1 font programs (ISO 32000-1 §9.6.2): PFA and PFB containers, the
eexec and charstring encryptions, the Type 1 charstring interpreter, and
Multiple Master interpolation. This crate exists because Fontations does not
read the format — CFF and TrueType stay in
skrifa, and only the one format nothing
else handles lands here.
use pdfrum_common::{Diagnostics, Limits};
use pdfrum_type1::Type1Font;
let font = Type1Font::parse(pfb, &Limits::default(), &mut Diagnostics::default()).ok()?;
let gid = font.name_to_gid("A")?;
let (outline, advance) = font.outline(gid)?;
let _ = (font.units_per_em(), font.font_matrix(), outline, advance);A Type 1 font is name-addressed, not index-addressed: its charstrings are a
dictionary keyed by glyph name, and the /Encoding array maps a byte to a
name rather than to a glyph number. Gid here is this crate’s own stable
numbering over that dictionary, so Type1Font::code_to_gid,
Type1Font::name_to_gid and Type1Font::unicode_to_gid are three
routes into one space — and Type1Font::glyph_name goes back, which is
what makes a /Differences encoding resolvable at all.
Outlines are in font units, 1000 per em by convention but read from the
/FontMatrix rather than assumed (Type1Font::units_per_em,
Type1Font::font_matrix). Multiple Master fonts are not interpolated on
parse: Type1Font::mm_axes reports the design axes and
Type1Font::instantiate borrows an instance at a coordinate, so one parsed
font serves every weight a document asks for.
Part of pdfrum. #![forbid(unsafe_code)].
MIT OR Apache-2.0
Structs§
- Font
File - A Type 1 program as a PDF
/FontFilestream: the bytes to store, and the ISO 32000-1 §9.9 table 127 lengths that partition them. - Gid
- A glyph index into a
Type1Font’s/CharStrings, in declaration order. - Glyph
- One interpreted glyph.
- MmAxis
- One design axis, in the design units a caller thinks in.
- Type1
Font - A parsed Type 1 font program.
- Type1
Instance - A Multiple-Master font blended at one point in design space.
Enums§
- Axis
Kind - What a design axis controls. Type 1 names these with PostScript literals; only the two the Foxit faces use have dedicated variants.
- Container
- Which wrapper the bytes turned out to be in. Reported so callers (and tests) can tell a genuine PFA from a bare program that merely parses like one.
- Encoding
- The font’s built-in character-code → glyph-name mapping.
- Error
- Why a Type 1 font program could not be read.
Constants§
- CHARSTRING_
SEED - Seed for an individual charstring or subroutine.
- DEFAULT_
LEN_ IV - Default
lenIVwhen the Private dictionary does not say. - EEXEC_
SEED - Seed for the
eexecenvelope around the private dictionary. - EEXEC_
SKIP - Plaintext bytes
eexecdiscards; fixed by the specification.
Functions§
- decrypt
- Decrypt
cipherwithseed, dropping the firstskipplaintext bytes. - encrypt
- The inverse of
decrypt, without the skip:plainis emitted as-is through the cipher. - font_
file - Unwrap a Type 1 program into the
/FontFilestream a PDF writer stores. - standard_
encoding_ name - The name a
seaccomponent code selects. - unicode_
from_ glyph_ name - The Unicode scalar a glyph name denotes, by the Adobe Glyph List plus the
uniXXXX/uXXXXXXconventions.