read_fonts::tables::postscript

Struct Stack

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

Operand stack for DICTs and charstrings.

The operand stack can contain either 32-bit integers or 16.16 fixed point values. The type is known when pushing to the stack and the expected type is also known (based on the operator) when reading from the stack, so the conversion is performed on demand at read time.

Storing the entries as an enum would require 8 bytes each and since these objects are created on the stack, we reduce the required size by storing the entries in parallel arrays holding the raw 32-bit value and a flag that tracks which values are fixed point.

Implementations§

Source§

impl Stack

Source

pub fn new() -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn verify_exact_len(&self, len: usize) -> Result<(), Error>

Source

pub fn verify_at_least_len(&self, len: usize) -> Result<(), Error>

Source

pub fn len_is_odd(&self) -> bool

Returns true if the number of elements on the stack is odd.

Used for processing some charstring operators where an odd count represents the presence of the glyph advance width at the bottom of the stack.

Source

pub fn clear(&mut self)

Source

pub fn reverse(&mut self)

Reverse the order of all elements on the stack.

Some charstring operators are simpler to process on a reversed stack.

Source

pub fn push(&mut self, number: impl Into<Number>) -> Result<(), Error>

Source

pub fn get_i32(&self, index: usize) -> Result<i32, Error>

Returns the 32-bit integer at the given index on the stack.

Will return an error if the value at that index was not pushed as an integer.

Source

pub fn get_fixed(&self, index: usize) -> Result<Fixed, Error>

Returns the 16.16 fixed point value at the given index on the stack.

If the value was pushed as an integer, it will be automatically converted to 16.16 fixed point.

Source

pub fn pop_i32(&mut self) -> Result<i32, Error>

Pops a 32-bit integer from the top of stack.

Will return an error if the top value on the stack was not pushed as an integer.

Source

pub fn pop_fixed(&mut self) -> Result<Fixed, Error>

Pops a 16.16 fixed point value from the top of the stack.

If the value was pushed as an integer, it will be automatically converted to 16.16 fixed point.

Source

pub fn fixed_values(&self) -> impl Iterator<Item = Fixed> + '_

Returns an iterator yielding all elements on the stack as 16.16 fixed point values.

Used to read array style DICT entries such as blue values, font matrix and font bounding box.

Source

pub fn fixed_array<const N: usize>( &self, first_index: usize, ) -> Result<[Fixed; N], Error>

Returns an array of N 16.16 fixed point values starting at first_index.

Source

pub fn number_values(&self) -> impl Iterator<Item = Number> + '_

Returns an iterator yielding all elements on the stack as number values.

This is useful for capturing the current state of the stack.

Source

pub fn apply_delta_prefix_sum(&mut self)

Apply a prefix sum to decode delta-encoded numbers.

“The second and subsequent numbers in a delta are encoded as the difference between successive values.”

Roughly equivalent to the FreeType logic at https://gitlab.freedesktop.org/freetype/freetype/-/blob/57617782464411201ce7bbc93b086c1b4d7d84a5/src/cff/cffparse.c#L1431

See https://learn.microsoft.com/en-us/typography/opentype/spec/cff2#table-6-operand-types

Source

pub fn apply_blend(&mut self, blend_state: &BlendState<'_>) -> Result<(), Error>

Trait Implementations§

Source§

impl Default for Stack

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Stack

§

impl RefUnwindSafe for Stack

§

impl Send for Stack

§

impl Sync for Stack

§

impl Unpin for Stack

§

impl UnwindSafe for Stack

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