Skip to main content

Base14Font

Enum Base14Font 

pub enum Base14Font {
Show 14 variants Helvetica, HelveticaBold, HelveticaOblique, HelveticaBoldOblique, TimesRoman, TimesBold, TimesItalic, TimesBoldItalic, Courier, CourierBold, CourierOblique, CourierBoldOblique, Symbol, ZapfDingbats,
}
Expand description

One of the 14 standard PDF fonts every conformant PDF reader ships built in (PDF 1.7 §9.6.2.2).

Variants are listed in the canonical PDF order: the four Helvetica weights, four Times weights, four Courier weights, then Symbol and ZapfDingbats. Self::ALL iterates them in this order.

§Examples

use pdf_base14_metrics::Base14Font;

assert_eq!(Base14Font::ALL.len(), 14);
assert_eq!(Base14Font::Helvetica.pdf_base_name(), "Helvetica");

Variants§

§

Helvetica

Helvetica (regular).

§

HelveticaBold

Helvetica Bold.

§

HelveticaOblique

Helvetica Oblique (regular weight, slanted).

§

HelveticaBoldOblique

Helvetica Bold Oblique.

§

TimesRoman

Times Roman (regular).

§

TimesBold

Times Bold.

§

TimesItalic

Times Italic.

§

TimesBoldItalic

Times Bold Italic.

§

Courier

Courier (regular, monospace).

§

CourierBold

Courier Bold (monospace).

§

CourierOblique

Courier Oblique (monospace, slanted).

§

CourierBoldOblique

Courier Bold Oblique (monospace).

§

Symbol

Adobe Symbol (Greek letters, math operators).

§

ZapfDingbats

ITC Zapf Dingbats (decorative glyphs).

Implementations§

§

impl Base14Font

pub const ALL: [Base14Font; 14]

Every Core 14 face in stable PDF order.

pub fn metrics(self) -> &'static FontMetrics<'static>

Borrows the pre-parsed Adobe AFM metrics for this face.

§Examples
use pdf_base14_metrics::Base14Font;

let metrics = Base14Font::Helvetica.metrics();

assert_eq!(metrics.font_name, "Helvetica");

pub fn pdf_base_name(self) -> &'static str

PDF /BaseFont name per PDF 1.7 §9.6.2.2. These are the exact bytes a conformant PDF writer puts after /BaseFont in a font resource dictionary.

§Examples
use pdf_base14_metrics::Base14Font;

assert_eq!(Base14Font::TimesBoldItalic.pdf_base_name(), "Times-BoldItalic");

pub fn glyph_width(self, name: &str) -> Option<f32>

Width of the glyph with the given PostScript name, in 1/1000 em. Returns None if no such glyph exists in this font.

This is an O(n) linear scan over the font’s character metrics (~315 entries for the Latin faces). Prefer Self::winansi_width when querying by byte; that path goes through a pre-baked O(1) table. For the Latin Core 12 faces, Self::glyph_width_by_name goes through a baked sorted index instead and is O(log n).

§Examples
use pdf_base14_metrics::Base14Font;

assert_eq!(Base14Font::Helvetica.glyph_width("A"), Some(667.0));

pub fn glyph_width_by_name(self, name: &str) -> Option<f32>

Width of the glyph with the given PostScript name, looked up through a baked sorted index. O(log n), allocation-free, safe to call once per character per PDF page in tight loops.

Returns None for Self::Symbol and Self::ZapfDingbats : their AFMs are intentionally unindexed because those faces don’t participate in /Differences-style remapping. Callers that need Symbol/Dingbat widths must use Self::glyph_width.

§Examples
use pdf_base14_metrics::Base14Font;

assert_eq!(Base14Font::Helvetica.glyph_width_by_name("A"), Some(667.0));
assert_eq!(Base14Font::Symbol.glyph_width_by_name("Alpha"), None);

pub fn winansi_width(self, code: u8) -> Option<f32>

Width of the glyph at PDF WinAnsiEncoding byte code, in 1/1000 em. Returns None when:

  • code is unmapped by PDF WinAnsi (control characters 0x00..=0x1F, the gaps 0x7F / 0x81 / 0x8D / 0x8F / 0x90 / 0x9D); or
  • self is Self::Symbol or Self::ZapfDingbats. those fonts do not use WinAnsi (see the crate-level docs).

Implemented as a single [Option<f32>; 256] indexed load per call: the table is baked at build time alongside the font metrics. Hot enough for mos-fonts::text_width to call once per character per typeset paragraph.

§Examples
use pdf_base14_metrics::Base14Font;

assert_eq!(Base14Font::Helvetica.winansi_width(b'A'), Some(667.0));
assert_eq!(Base14Font::Symbol.winansi_width(b'A'), None);

Trait Implementations§

§

impl Clone for Base14Font

§

fn clone(&self) -> Base14Font

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for Base14Font

§

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

Formats the value using the given formatter. Read more
Source§

impl From<Base14Font> for Font

Source§

fn from(f: Base14Font) -> Self

Converts to this type from the input type.
§

impl Hash for Base14Font

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for Base14Font

§

fn eq(&self, other: &Base14Font) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Copy for Base14Font

§

impl Eq for Base14Font

§

impl StructuralPartialEq for Base14Font

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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
§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

§

fn to_owned_table(&self) -> U

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.