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
impl Stack
pub fn new() -> Self
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn verify_exact_len(&self, len: usize) -> Result<(), Error>
pub fn verify_at_least_len(&self, len: usize) -> Result<(), Error>
Sourcepub fn len_is_odd(&self) -> bool
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.
pub fn clear(&mut self)
Sourcepub fn reverse(&mut self)
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.
pub fn push(&mut self, number: impl Into<Number>) -> Result<(), Error>
Sourcepub fn get_i32(&self, index: usize) -> Result<i32, Error>
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.
Sourcepub fn get_fixed(&self, index: usize) -> Result<Fixed, Error>
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.
Sourcepub fn pop_i32(&mut self) -> Result<i32, Error>
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.
Sourcepub fn pop_fixed(&mut self) -> Result<Fixed, Error>
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.
Sourcepub fn fixed_values(&self) -> impl Iterator<Item = Fixed> + '_
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.
Sourcepub fn fixed_array<const N: usize>(
&self,
first_index: usize,
) -> Result<[Fixed; N], Error>
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
.
Sourcepub fn number_values(&self) -> impl Iterator<Item = Number> + '_
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.
Sourcepub fn apply_delta_prefix_sum(&mut self)
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
Sourcepub fn apply_blend(&mut self, blend_state: &BlendState<'_>) -> Result<(), Error>
pub fn apply_blend(&mut self, blend_state: &BlendState<'_>) -> Result<(), Error>
Apply the blend
operator.