Struct ValueStack

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

Source

pub fn new(values: &'a mut [i32], is_pedantic: bool) -> Self

Source

pub fn len(&self) -> usize

Source

pub fn values(&self) -> &[i32]

Source

pub fn push(&mut self, value: i32) -> Result<(), HintErrorKind>

Source

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.

See https://learn.microsoft.com/en-us/typography/opentype/spec/tt_instructions#pushing-data-onto-the-interpreter-stack

Source

pub fn peek(&mut self) -> Option<i32>

Source

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

Source

pub fn pop_f26dot6(&mut self) -> Result<F26Dot6, HintErrorKind>

Convenience method for instructions that expect values in 26.6 format.

Source

pub fn pop_usize(&mut self) -> Result<usize, HintErrorKind>

Convenience method for instructions that pop values that are used as an index.

Source

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.

Source

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

Source

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

Source

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

Source

pub fn dup(&mut self) -> Result<(), HintErrorKind>

Duplicate top stack element.

Implements the DUP[] instruction.

See https://learn.microsoft.com/en-us/typography/opentype/spec/tt_instructions#duplicate-top-stack-element

Source

pub fn swap(&mut self) -> Result<(), HintErrorKind>

Swap the top two elements on the stack.

Implements the SWAP[] instruction.

See https://learn.microsoft.com/en-us/typography/opentype/spec/tt_instructions#swap-the-top-two-elements-on-the-stack

Source

pub fn copy_index(&mut self) -> Result<(), HintErrorKind>

Copy the indexed element to the top of the stack.

Implements the CINDEX[] instruction.

See https://learn.microsoft.com/en-us/typography/opentype/spec/tt_instructions#copy-the-indexed-element-to-the-top-of-the-stack

Source

pub fn move_index(&mut self) -> Result<(), HintErrorKind>

Moves the indexed element to the top of the stack.

Implements the MINDEX[] instruction.

See https://learn.microsoft.com/en-us/typography/opentype/spec/tt_instructions#move-the-indexed-element-to-the-top-of-the-stack

Source

pub fn roll(&mut self) -> Result<(), HintErrorKind>

Roll the top three stack elements.

Implements the ROLL[] instruction.

See https://learn.microsoft.com/en-us/typography/opentype/spec/tt_instructions#roll-the-top-three-stack-elements

Auto Trait Implementations§

§

impl<'a> Freeze for ValueStack<'a>

§

impl<'a> RefUnwindSafe for ValueStack<'a>

§

impl<'a> Send for ValueStack<'a>

§

impl<'a> Sync for ValueStack<'a>

§

impl<'a> Unpin for ValueStack<'a>

§

impl<'a> !UnwindSafe for ValueStack<'a>

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.