Struct read_fonts::tables::postscript::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.