Skip to main content

Crate pdfrum_type1

Crate pdfrum_type1 

Source
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§

FontFile
A Type 1 program as a PDF /FontFile stream: 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.
Type1Font
A parsed Type 1 font program.
Type1Instance
A Multiple-Master font blended at one point in design space.

Enums§

AxisKind
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 lenIV when the Private dictionary does not say.
EEXEC_SEED
Seed for the eexec envelope around the private dictionary.
EEXEC_SKIP
Plaintext bytes eexec discards; fixed by the specification.

Functions§

decrypt
Decrypt cipher with seed, dropping the first skip plaintext bytes.
encrypt
The inverse of decrypt, without the skip: plain is emitted as-is through the cipher.
font_file
Unwrap a Type 1 program into the /FontFile stream a PDF writer stores.
standard_encoding_name
The name a seac component code selects.
unicode_from_glyph_name
The Unicode scalar a glyph name denotes, by the Adobe Glyph List plus the uniXXXX / uXXXXXX conventions.