Skip to content

Commit

Permalink
[skrifa] tthint: instruction dispatch (#774)
Browse files Browse the repository at this point in the history
Based on #773, uses the decoder in that PR to handle dispatch to the currently implemented instructions.

No tests in this one. Will add in a later PR when more functionality has landed.

* review feedback

- add limit for total number of instructions executed (same as FT)
- don't return count from Engine::run()

* review changes from #773

- move bytecode to glyf module
- replace negation with abs()
- make DecodeError a unit-like struct

In addition, replace byte to Opcode table with a match expression.
  • Loading branch information
dfrg authored Feb 8, 2024
1 parent 60298ad commit 9521536
Show file tree
Hide file tree
Showing 12 changed files with 510 additions and 278 deletions.
1 change: 0 additions & 1 deletion read-fonts/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub mod post;
pub mod postscript;
pub mod sbix;
pub mod stat;
pub mod truetype;
pub mod variations;
pub mod vhea;
pub mod vmtx;
Expand Down
2 changes: 2 additions & 0 deletions read-fonts/src/tables/glyf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! The [glyf (Glyph Data)](https://docs.microsoft.com/en-us/typography/opentype/spec/glyf) table

pub mod bytecode;

use std::fmt;
use types::{F26Dot6, Pen, Point};

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{InlineOperands, Instruction, Opcode};
/// An error returned by [`Decoder::decode`] if the end of the bytecode
/// stream is reached unexpectedly.
#[derive(Copy, Clone, Debug)]
pub struct DecodeError(());
pub struct DecodeError;

impl std::fmt::Display for DecodeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down Expand Up @@ -43,8 +43,8 @@ impl<'a> Decoder<'a> {
// of inline operands and |opcode_len| is the size of each operand.
// <https://gitlab.freedesktop.org/freetype/freetype/-/blob/57617782464411201ce7bbc93b086c1b4d7d84a5/src/truetype/ttinterp.c#L7046>
if opcode_len < 0 {
let inline_count = *self.bytecode.get(self.pc + 1).ok_or(DecodeError(()))?;
opcode_len = -opcode_len * inline_count as i32 + 2;
let inline_count = *self.bytecode.get(self.pc + 1).ok_or(DecodeError)?;
opcode_len = opcode_len.abs() * inline_count as i32 + 2;
count_len = 1;
}
let opcode_len = opcode_len as usize;
Expand All @@ -58,7 +58,7 @@ impl<'a> Decoder<'a> {
inline_operands.bytes = self
.bytecode
.get(inline_start..inline_start + inline_size)
.ok_or(DecodeError(()))?;
.ok_or(DecodeError)?;
inline_operands.is_words = opcode.is_push_words();
}
self.pc += opcode_len;
Expand Down
Loading

0 comments on commit 9521536

Please sign in to comment.