pub struct ValueStack<'a> {
values: &'a mut [i32],
len: usize,
pub(super) is_pedantic: bool,
}
Expand description
Value stack for the TrueType interpreter.
This uses a slice as the backing store rather than a Vec
to enable
support for allocation from user buffers.
See https://learn.microsoft.com/en-us/typography/opentype/spec/tt_instructions#managing-the-stack
Fields§
§values: &'a mut [i32]
§len: usize
§is_pedantic: bool
Implementations§
Source§impl<'a> ValueStack<'a>
impl<'a> ValueStack<'a>
pub fn new(values: &'a mut [i32], is_pedantic: bool) -> Self
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the depth of the stack https://learn.microsoft.com/en-us/typography/opentype/spec/tt_instructions#returns-the-depth-of-the-stack
pub fn values(&self) -> &[i32]
pub fn push(&mut self, value: i32) -> Result<(), HintErrorKind>
Sourcepub fn push_inline_operands(
&mut self,
operands: &InlineOperands<'_>,
) -> Result<(), HintErrorKind>
pub fn push_inline_operands( &mut self, operands: &InlineOperands<'_>, ) -> Result<(), HintErrorKind>
Pushes values that have been decoded from the instruction stream onto the stack.
Implements the PUSHB[], PUSHW[], NPUSHB[] and NPUSHW[] instructions.
pub fn peek(&mut self) -> Option<i32>
Sourcepub fn pop(&mut self) -> Result<i32, HintErrorKind>
pub fn pop(&mut self) -> Result<i32, HintErrorKind>
Pops a value from the stack.
Implements the POP[] instruction.
See https://learn.microsoft.com/en-us/typography/opentype/spec/tt_instructions#pop-top-stack-element
Sourcepub fn pop_f26dot6(&mut self) -> Result<F26Dot6, HintErrorKind>
pub fn pop_f26dot6(&mut self) -> Result<F26Dot6, HintErrorKind>
Convenience method for instructions that expect values in 26.6 format.
Sourcepub fn pop_usize(&mut self) -> Result<usize, HintErrorKind>
pub fn pop_usize(&mut self) -> Result<usize, HintErrorKind>
Convenience method for instructions that pop values that are used as an index.
Sourcepub fn pop_count_checked(&mut self) -> Result<usize, HintErrorKind>
pub fn pop_count_checked(&mut self) -> Result<usize, HintErrorKind>
Convenience method for popping a value intended as a count.
When a negative value is encountered, returns an error in pedantic mode or 0 otherwise.
Sourcepub fn apply_unary(
&mut self,
op: impl FnMut(i32) -> Result<i32, HintErrorKind>,
) -> Result<(), HintErrorKind>
pub fn apply_unary( &mut self, op: impl FnMut(i32) -> Result<i32, HintErrorKind>, ) -> Result<(), HintErrorKind>
Applies a unary operation.
Pops a
from the stack and pushes op(a)
.
Sourcepub fn apply_binary(
&mut self,
op: impl FnMut(i32, i32) -> Result<i32, HintErrorKind>,
) -> Result<(), HintErrorKind>
pub fn apply_binary( &mut self, op: impl FnMut(i32, i32) -> Result<i32, HintErrorKind>, ) -> Result<(), HintErrorKind>
Applies a binary operation.
Pops b
and a
from the stack and pushes op(a, b)
.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the entire stack.
Implements the CLEAR[] instruction.
See https://learn.microsoft.com/en-us/typography/opentype/spec/tt_instructions#clear-the-entire-stack
Sourcepub fn dup(&mut self) -> Result<(), HintErrorKind>
pub fn dup(&mut self) -> Result<(), HintErrorKind>
Duplicate top stack element.
Implements the DUP[] instruction.
Sourcepub fn swap(&mut self) -> Result<(), HintErrorKind>
pub fn swap(&mut self) -> Result<(), HintErrorKind>
Swap the top two elements on the stack.
Implements the SWAP[] instruction.
Sourcepub fn copy_index(&mut self) -> Result<(), HintErrorKind>
pub fn copy_index(&mut self) -> Result<(), HintErrorKind>
Copy the indexed element to the top of the stack.
Implements the CINDEX[] instruction.
Sourcepub fn move_index(&mut self) -> Result<(), HintErrorKind>
pub fn move_index(&mut self) -> Result<(), HintErrorKind>
Moves the indexed element to the top of the stack.
Implements the MINDEX[] instruction.
Sourcepub fn roll(&mut self) -> Result<(), HintErrorKind>
pub fn roll(&mut self) -> Result<(), HintErrorKind>
Roll the top three stack elements.
Implements the ROLL[] instruction.