Skip to main content

Cmap

Struct Cmap 

Source
pub struct Cmap { /* private fields */ }
Expand description

A font’s character map: one or more modelled subtables.

Lookup tries the subtables in order and returns the first hit, mirroring the parser’s spec-preference scan while staying in the owned model.

Implementations§

Source§

impl Cmap

Source

pub fn new() -> Self

An empty cmap (nothing maps).

Source

pub fn format4() -> Self

A cmap with one empty format-4 subtable — the minimum every font carries.

Source

pub fn format12() -> Self

A cmap with one empty format-12 subtable.

Source

pub fn subtables(&self) -> &[CmapSubtable]

The subtables, in lookup order.

Source

pub fn subtables_mut(&mut self) -> &mut Vec<CmapSubtable>

The subtables, mutably.

Source

pub fn preferred(&self) -> Option<&CmapSubtable>

The subtable a writer should emit first: format 12 when the font has one (it covers every codepoint), otherwise the first format-4 subtable. None for an empty cmap.

Source

pub fn lookup(&self, cp: u32) -> Option<GlyphId>

Map a codepoint to a glyph across every subtable.

Source

pub fn codepoints(&self) -> CodePointSet

The union of every subtable’s mapped codepoints.

Source

pub fn len(&self) -> usize

Number of subtables.

Source

pub fn is_empty(&self) -> bool

True when the cmap carries no subtable.

Source

pub fn encode(&self) -> Vec<u8> ⓘ

Encode the whole cmap table (header + encoding records + subtables), writing one encoding record per subtable: (3, 1) for format 4 and (3, 10) for format 12.

Source

pub fn decode(data: &[u8]) -> Result<Self, ModelError>

Decode a whole cmap table: header, encoding records, and every subtable they point at.

§Errors

ModelError::Parse when the header or records are inconsistent, or ModelError::UnsupportedCmapFormat for a subtable format outside the modelled set.

Source

pub fn decode_subtable(data: &[u8]) -> Result<CmapSubtable, ModelError>

Decode a standalone subtable (no cmap header) — what CmapSubtable::encode produced.

§Errors

See CmapSubtable::decode.

Source

pub fn subtable_format4() -> CmapSubtable

An empty format-4 subtable, for building.

Source

pub fn subtable_format12() -> CmapSubtable

An empty format-12 subtable, for building.

Source

pub fn validate(&self) -> Result<(), ModelError>

Check the monotonicity invariant across every subtable.

§Errors

ModelError::NonMonotonicCmap naming the subtable index and the two codepoints that broke the ordering.

Trait Implementations§

Source§

impl Clone for Cmap

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 Cmap

Source§

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

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

impl Default for Cmap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Cmap

Source§

impl PartialEq for Cmap

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Cmap

Auto Trait Implementations§

§

impl Freeze for Cmap

§

impl RefUnwindSafe for Cmap

§

impl Send for Cmap

§

impl Sync for Cmap

§

impl Unpin for Cmap

§

impl UnsafeUnpin for Cmap

§

impl UnwindSafe for Cmap

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