pub enum Font {
Builtin {
encoding: Encoding,
},
Type1 {
encoding: Encoding,
program: Rc<Program>,
names: HashMap<char, Vec<u8>>,
},
Cff {
encoding: Encoding,
data: Vec<u8>,
cid_to_gid: Vec<(u16, u16)>,
names: HashMap<char, u16>,
cache: Rc<RefCell<Cache>>,
},
TrueType {
encoding: Encoding,
data: Vec<u8>,
has_cmap: bool,
has_mac_cmap: bool,
cache: Rc<RefCell<Cache>>,
},
}Expand description
A resolved font ready to place glyphs.
Variants§
Builtin
The built-in fallback: a 5×7 bitmap alphabet, used when the document carries no usable font program (all of the base-14 cases).
Type1
An embedded Type 1 program (/FontFile), whose glyphs are charstrings
(crate::type1). A simple font’s code reaches a glyph through its
encoding’s name, so the program is indexed by the character each name
stands for.
Fields
Cff
An embedded CFF program, wrapped so the outlines come out of the same code path as TrueType. CID-keyed fonts select glyphs through their charset, not by using the CID as a glyph id.
Fields
cid_to_gid: Vec<(u16, u16)>CID → glyph id from the CFF charset, empty when the font is not CID-keyed.
TrueType
An embedded TrueType program.
Fields
data: Vec<u8>The font program, still compressed in the PDF sense is not our
business: this is the decoded /FontFile2.
has_cmap: boolWhether the program carries a cmap table at all: when it does not,
a simple font’s code is the glyph id.
Implementations§
Source§impl Font
impl Font
Sourcepub fn cff(encoding: Encoding, data: Vec<u8>) -> Option<Self>
pub fn cff(encoding: Encoding, data: Vec<u8>) -> Option<Self>
An embedded CFF program, bare or already wrapped in OpenType.
/CIDFontType0C and /Type1C programs are a CFF table with no container;
they are wrapped here so the same outline code reads them.
Sourcepub fn type1(encoding: Encoding, program: Program) -> Option<Self>
pub fn type1(encoding: Encoding, program: Program) -> Option<Self>
A Type 1 program, indexed by the character each glyph name stands for.
None when the program has no usable glyphs, which is what makes the
caller fall back rather than draw nothing.
Sourcepub fn true_type(encoding: Encoding, data: Vec<u8>) -> Option<Self>
pub fn true_type(encoding: Encoding, data: Vec<u8>) -> Option<Self>
An embedded TrueType program, rejected when it cannot be parsed.
Sourcepub fn character(&self, code: u8) -> Option<char>
pub fn character(&self, code: u8) -> Option<char>
The outline and advance for a byte code, or None when there is no
glyph for it.
A simple font’s code goes through its encoding to a character, and the
character through the program’s cmap to a glyph id. A program with no
cmap table at all cannot be consulted that way, and the files that
lack one mean the code is the glyph id — pdf.js’s
TrueType_without_cmap.pdf is the case, and refusing to guess drew a
blank page while reporting nothing at all.
The character a code stands for, in this font’s encoding.
What a text layer needs: a code with no character is a glyph the page shows but no reader can quote, and it stays a box with no text.
pub fn glyph(&self, code: u8) -> Option<Glyph>
Sourcepub fn has_glyph_names(&self) -> bool
pub fn has_glyph_names(&self) -> bool
Whether glyphs are selectable at all — the name map of a simple CFF, a
cmap of a TrueType program.
Sourcepub fn has_character_map(&self) -> bool
pub fn has_character_map(&self) -> bool
Whether this font has a character map at all.
A simple TrueType program with none cannot be decoded from its codes, so the caller reports the page instead of drawing an empty one.
Sourcepub fn advance(&self, code: u8) -> f64
pub fn advance(&self, code: u8) -> f64
The advance of a code in em units, falling back to the built-in metric.
Sourcepub fn glyph_by_id(&self, id: u16) -> Option<Glyph>
pub fn glyph_by_id(&self, id: u16) -> Option<Glyph>
The outline for a glyph id, which is how composite (Type 0) fonts select
glyphs: a CID maps to an id through /CIDToGIDMap, not through a cmap.
The built-in bitmap alphabet has no glyph ids, so it has no answer here.