module

TT

Constants

ARGS_ARE_WORDS = 1_u16

Composite glyph flags (ttgload.c).

ARGS_ARE_XY_VALUES = 2_u16
CODERANGE_CVT = 2
CODERANGE_FONT = 1
CODERANGE_GLYPH = 3
CODERANGE_NONE = 0

Code range tags.

CURVE_TAG_ON = 1_u8

FT_CURVE_TAG_* (ftimage.h).

CURVE_TAG_TOUCH_BOTH = 24_u8
CURVE_TAG_TOUCH_X = 8_u8
CURVE_TAG_TOUCH_Y = 16_u8
ERR_BAD_ARGUMENT = 4608 + 132
ERR_CODE_OVERFLOW = 4608 + 131
ERR_DEBUG_OPCODE = 4608 + 135
ERR_DEF_IN_GLYF_BYTECODE = 4608 + 156
ERR_DIVIDE_BY_ZERO = 4608 + 133
ERR_ENDF_IN_EXEC_STREAM = 4608 + 136
ERR_EXECUTION_TOO_LONG = 4608 + 139
ERR_INVALID_CODERANGE = 4608 + 138
ERR_INVALID_OPCODE = 4608 + 128

FT error codes as produced by FT_THROW with FT_Mod_Err_TrueType = 0x1200.

ERR_INVALID_REFERENCE = 4608 + 134
ERR_NESTED_DEFS = 4608 + 137
ERR_STACK_OVERFLOW = 4608 + 130
ERR_TOO_FEW_ARGUMENTS = 4608 + 129
ERR_TOO_MANY_FUNCTION_DEFS = 4608 + 140
ERR_TOO_MANY_INSTRUCTION_DEFS = 4608 + 141
FT_GASP_DOGRAY = 2
FT_GASP_GRIDFIT = 1

FT_GASP flags used by tt_face_get_cleartype_policy.

FT_GASP_SYMMETRIC_GRIDFIT = 4
FT_GASP_SYMMETRIC_SMOOTHING = 8
GX_TC_TUPLE_COUNT_MASK = 4095
GX_TC_TUPLES_SHARE_POINT_NUMBERS = 32768

TupleCount flags of the `gvar' table (GX_TupleCountFlags).

GX_TI_EMBEDDED_TUPLE_COORD = 32768

TupleIndex flags of the gvar'/cvar' tables (GX_TupleIndexFlags).

GX_TI_INTERMEDIATE_TUPLE = 16384
GX_TI_PRIVATE_POINT_NUMBERS = 8192
GX_TI_TUPLE_INDEX_MASK = 4095
INTERPRETER_VERSION_35 = 35

Interpreter versions (FT_TT_INTERPRETER_VERSION_xx).

INTERPRETER_VERSION_40 = 40
MORE_COMPONENTS = 32_u16
MOVE_FUNC_GENERIC = 0
MOVE_FUNC_X = 1
MOVE_FUNC_Y = 2
ON_CURVE_POINT = 1_u8

Simple glyph flag bits (ttgload.c).

OPCODE_LENGTH = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 3, 5, 7, 9, 11, 13, 15, 17, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] of Int8

opcode_length[256], verbatim from ttinterp.c (-1 for NPUSHB, -2 for NPUSHW).

OPCOUNT_ENABLED = ENV["TT_OPCOUNT"]? == "1"

Opcode frequency counter for profiling (prints on context GC... run end is impractical here; read via ExecContext.opcode_counts). TT_OPCOUNT=1.

OVERLAP_COMPOUND = 1024_u16
POP_PUSH_COUNT = [0, 0, 0, 0, 0, 0, 32, 32, 32, 32, 32, 32, 2, 2, 0, 80, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 16, 0, 16, 16, 16, 16, 18, 16, 0, 34, 1, 17, 16, 32, 0, 16, 32, 16, 16, 0, 16, 16, 0, 0, 0, 0, 16, 16, 16, 16, 16, 0, 32, 32, 0, 0, 32, 32, 0, 0, 32, 17, 32, 17, 17, 17, 32, 33, 33, 1, 1, 0, 0, 16, 33, 33, 33, 33, 33, 33, 17, 17, 16, 0, 33, 33, 17, 16, 16, 16, 33, 33, 33, 33, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 32, 16, 16, 16, 16, 16, 16, 16, 32, 32, 0, 0, 0, 0, 16, 16, 0, 32, 32, 0, 0, 16, 32, 32, 17, 16, 51, 33, 33, 16, 32, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32] of UInt8

Pop_Push_Count[256]: (pops << 4) | pushes, verbatim from ttinterp.c.

PROJECT_FUNC_GENERIC = 0
PROJECT_FUNC_X = 1
PROJECT_FUNC_Y = 2
RENDER_MODE_LCD = 3
RENDER_MODE_LCD_V = 4
RENDER_MODE_LIGHT = 1
RENDER_MODE_MONO = 2
RENDER_MODE_NORMAL = 0

FT_Render_Mode constants (only the equality tests matter).

REPEAT_FLAG = 8_u8
ROUND_DOWN_TO_GRID = 3
ROUND_FUNC_DOWN = 4
ROUND_FUNC_NONE = 0

Selector values of the current rounding/projection/move function pointers (the C func_round, func_project, ... fields).

ROUND_FUNC_SUPER = 6
ROUND_FUNC_SUPER_45 = 7
ROUND_FUNC_TO_DOUBLE = 3
ROUND_FUNC_TO_GRID = 1
ROUND_FUNC_TO_HALF = 2
ROUND_FUNC_UP = 5
ROUND_OFF = 5
ROUND_SUPER = 6
ROUND_SUPER_45 = 7
ROUND_TO_DOUBLE_GRID = 2
ROUND_TO_GRID = 1
ROUND_TO_HALF_GRID = 0

Rounding state constants (ttinterp.h).

ROUND_UP_TO_GRID = 4
ROUND_XY_TO_GRID = 4_u16
SAME_X = 16_u8
SAME_Y = 32_u8
SCALED_COMPONENT_OFFSET = 2048_u16
TRACE_ENABLED = ENV["TT_TRACE"]? == "1"

Per-instruction trace to STDERR, mirroring the C interpreter's FT_DEBUG_LEVEL_TRACE dump (opcode + top-of-stack). Enable with TT_TRACE=1.

TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES = 1000000_u64
USE_MY_METRICS = 512_u16
VMError = ExecutionError

Dedicated interceptable name for "the font's TrueType bytecode crashed the VM": the same class as ExecutionError, so existing rescues keep working — rescue ex : TT::VMError reads as intent.

WE_HAVE_A_2X2 = 128_u16
WE_HAVE_A_SCALE = 8_u16
WE_HAVE_AN_XY_SCALE = 64_u16
WE_HAVE_INSTR = 256_u16
WOFF2_FLAGS_TRANSFORM = 1_u32 << 8

Flag bit marking a table as transformed (sfwoff2.h).

WOFF2_KNOWN_TAGS = ["cmap", "head", "hhea", "hmtx", "maxp", "name", "OS/2", "post", "cvt ", "fpgm", "glyf", "loca", "prep", "CFF ", "VORG", "EBDT", "EBLC", "gasp", "hdmx", "kern", "LTSH", "PCLT", "VDMX", "vhea", "vmtx", "BASE", "GDEF", "GPOS", "GSUB", "EBSC", "JSTF", "MATH", "CBDT", "CBLC", "COLR", "CPAL", "SVG ", "sbix", "acnt", "avar", "bdat", "bloc", "bsln", "cvar", "fdsc", "feat", "fmtx", "fvar", "gvar", "hsty", "just", "lcar", "mort", "morx", "opbd", "prop", "trak", "Zapf", "Silf", "Glat", "Gloc", "Feat", "Sill"].map do |s| ((((s.byte_at(0)).to_u32 << 24) | ((s.byte_at(1)).to_u32 << 16)) | ((s.byte_at(2)).to_u32 << 8)) | (s.byte_at(3)) end

WOFF2 known table tags, in the order given by the spec's table directory format (woff2tags.c). The flag byte's low 6 bits index it.

WOFF2_MAX_SFNT_SIZE = 1_u32 << 26

An arbitrary, heuristic size limit (67MByte) for expanded WOFF2 data.

WOFF2_OVERLAP_SIMPLE = 64_u8

`OVERLAP_SIMPLE' simple-glyph flag (glyf spec bit 6).

WOFF2_TAG_GLYF = 1735162214_u32
WOFF2_TAG_HEAD = 1751474532_u32
WOFF2_TAG_HHEA = 1751672161_u32
WOFF2_TAG_HMTX = 1752003704_u32
WOFF2_TAG_LOCA = 1819239265_u32
WOFF2_TAG_MAXP = 1835104368_u32
WOFF2_TAG_TTCF = 1952670566_u32
X_POSITIVE = 16_u8
X_SHORT_VECTOR = 2_u8
Y_POSITIVE = 32_u8
Y_SHORT_VECTOR = 4_u8

Class methods

ttcf_face_offset(data : Bytes, face_index : Int32 = 0) : Int32 | Nil

A bare TrueType/OpenType collection ('ttcf' magic): return the byte offset of face `face_index''s SFNT inside the buffer, or nil for anything that is not a collection. Table offsets inside a member face are relative to the START OF THE FILE (shared table data), so callers must keep the whole buffer and add this base — slicing would corrupt every table offset.

Source
unwrap_woff(data : Bytes, face_index : Int32 = 0) : Bytes

Unwrap a WOFF1 wrapper into a plain SFNT buffer (the port of FreeType's woff_open_font', sfnt/wofffnt.c): each table is either stored raw (compLength == origLength) or zlib-compressed; the result is a reconstructed SFNT with the original flavor, a fresh table directory and the tables re-padded to 4-byte alignment. WOFF2 ('wOF2' magic) is unwrapped through the brotli decoder (see tt/woff2.cr). Bare collections ('ttcf') are returned as-is — they are handled through ttcf_face_offset'/`Font#@base' instead (slicing would corrupt their file-relative table offsets). Any other input is returned as-is.

Source
unwrap_woff2(data : Bytes, face_index : Int32 = 0) : Bytes

Unwrap a WOFF2 font into a plain SFNT buffer. face_index' selects a face when the WOFF2 wraps a collection ('ttcf' flavor). Port of woff2_open_font' (sfwoff2.c).

Source

Nested types