Skip to main content

Font

Enum Font 

Source
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).

Fields

§encoding: Encoding

Code → character table.

§

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

§encoding: Encoding

Code → character table.

§program: Rc<Program>

The parsed program, shared with the clones of this font.

§names: HashMap<char, Vec<u8>>

Character → glyph name, for the names the library can resolve.

§

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

§encoding: Encoding

Code → character table, for the (rare) simple CFF font.

§data: Vec<u8>

The program as sfnt bytes.

§cid_to_gid: Vec<(u16, u16)>

CID → glyph id from the CFF charset, empty when the font is not CID-keyed.

§names: HashMap<char, u16>

A simple (non-CID) CFF font selects its glyphs by name: the charset names each glyph, and a code reaches one through the encoding’s character. A bare CFF carries no cmap, so this is the only route to its outlines.

§cache: Rc<RefCell<Cache>>

Parsed answers, shared by clones.

§

TrueType

An embedded TrueType program.

Fields

§encoding: Encoding

Code → character table.

§data: Vec<u8>

The font program, still compressed in the PDF sense is not our business: this is the decoded /FontFile2.

§has_cmap: bool

Whether the program carries a cmap table at all: when it does not, a simple font’s code is the glyph id.

§has_mac_cmap: bool

Whether a Macintosh Roman (1,0) subtable is present, which is the one a writer’s own codes can be looked up in when the Unicode map is absent.

§cache: Rc<RefCell<Cache>>

Parsed answers, shared by clones.

Implementations§

Source§

impl Font

Source

pub fn builtin(encoding: Encoding) -> Self

The built-in fallback with an encoding.

Source

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.

Source

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.

Source

pub fn true_type(encoding: Encoding, data: Vec<u8>) -> Option<Self>

An embedded TrueType program, rejected when it cannot be parsed.

Source

pub fn glyph(&self, code: u8) -> Option<Glyph>

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.

Source

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.

Source

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.

Source

pub fn advance(&self, code: u8) -> f64

The advance of a code in em units, falling back to the built-in metric.

Source

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.

Trait Implementations§

Source§

impl Clone for Font

Source§

fn clone(&self) -> Self

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 Font

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Font

§

impl !Send for Font

§

impl !Sync for Font

§

impl !UnwindSafe for Font

§

impl Forget for Font

§

impl Freeze for Font

§

impl Move for Font

§

impl Unpin for Font

§

impl UnsafeUnpin for Font

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> Same for T

Source§

type Output = T

Should always be Self
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.