Skip to main content

CmapSubtable

Enum CmapSubtable 

Source
pub enum CmapSubtable {
    Format4 {
        segments: Vec<Segment>,
        glyph_ids: Vec<Vec<u16>>,
    },
    Format12 {
        segments: Vec<Segment>,
    },
}
Expand description

The decoded, owned form of one cmap subtable.

Both modelled formats are segmented coverage: an ascending list of [start, end] ranges whose glyph ids either run consecutively (first_glyph + (cp − start), format 12 and format 4’s idDelta path) or come from an explicit array (format 4’s glyphIndexArray).

Format 4’s glyph-index array is normalised away on decode: a segment that used the array becomes a segment whose glyphs are consecutive only if they genuinely are; otherwise the array values are kept as a per-codepoint table. Both encode back to a spec-valid subtable.

Variants§

§

Format4

Format 4: the BMP segment/delta form.

Fields

§segments: Vec<Segment>

Segments, ascending and non-overlapping.

§glyph_ids: Vec<Vec<u16>>

Explicit glyph ids for format-4 segments that used the glyphIndexArray; entry k belongs to segment k and has end − start + 1 entries (a 0 entry means “not mapped”).

§

Format12

Format 12: segmented coverage, u32 codepoints.

Fields

§segments: Vec<Segment>

Segments, ascending and non-overlapping.

Implementations§

Source§

impl CmapSubtable

Source

pub fn empty_format4() -> Self

An empty format-4 subtable.

Source

pub fn empty_format12() -> Self

An empty format-12 subtable.

Source

pub const fn format(&self) -> u16

The format number this subtable encodes as (4 or 12).

Source

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

Map a codepoint to a glyph. None for “not mapped”: outside the subtable’s plane, in a hole of an explicit glyph array, mapped to glyph 0, or resolving to a glyph id beyond the u16 glyph space.

Source

pub fn codepoints(&self) -> CodePointSet

The mapped codepoints, ascending.

Source

pub fn entries(&self) -> Vec<(u32, GlyphId)>

Every (codepoint, glyph) pair, ascending by codepoint. The inverse of the encode path and what a writer iterates.

Source

pub fn segments(&self) -> &[Segment]

The segments, ascending. Empty for a subtable that maps nothing.

Source

pub fn glyph_arrays(&self) -> &[Vec<u16>]

The explicit glyph-id arrays, one per format-4 segment; an empty inner Vec means the segment is a delta (consecutive-glyph) segment.

Source

pub fn len(&self) -> usize

Number of codepoints that map to a glyph.

Source

pub fn is_empty(&self) -> bool

True when nothing maps.

Source

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

Encode to cmap subtable bytes (no table header, just the subtable).

The output is spec-valid: format 4 ends with the mandatory 0xFFFF terminator segment, and every segment is ascending.

Source

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

Encode as a format-4 subtable.

Source

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

Encode as a format-12 subtable.

Source

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

Decode a subtable from its bytes.

§Errors

ModelError::UnsupportedCmapFormat for anything other than formats 4 and 12; ModelError::Parse when the byte layout is inconsistent.

Source

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

Decode a format-4 subtable.

§Errors

ModelError::Parse when the segment arrays are inconsistent.

Source

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

Decode a format-12 subtable.

§Errors

ModelError::Parse when the group array is inconsistent.

Source

pub fn bmp_entries(&self) -> Vec<(u32, u32)>

The BMP-only entries, ascending — the working set for a format-4 encode, and what a caller checks to decide whether a subtable needs a format-12 companion.

use font_model::{from_entries, GlyphId};

let sub = from_entries(&[(0x41, GlyphId::new(1)), (0x1F600, GlyphId::new(2))], 12);
assert_eq!(sub.bmp_entries(), vec![(0x41, 1)]);

Trait Implementations§

Source§

impl Clone for CmapSubtable

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 CmapSubtable

Source§

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

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

impl Eq for CmapSubtable

Source§

impl PartialEq for CmapSubtable

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 CmapSubtable

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