text-shaper 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE +6 -1
  2. package/README.md +27 -1
  3. package/dist/font/brotli/context.d.ts +6 -0
  4. package/dist/font/brotli/decode.d.ts +9 -0
  5. package/dist/font/brotli/dictionary.d.ts +11 -0
  6. package/dist/font/brotli/transform.d.ts +12 -0
  7. package/dist/font/font.d.ts +19 -5
  8. package/dist/font/tables/cff.d.ts +4 -0
  9. package/dist/font/tables/gasp.d.ts +54 -0
  10. package/dist/font/tables/gdef.d.ts +3 -0
  11. package/dist/font/tables/glyf.d.ts +2 -0
  12. package/dist/font/tables/hinting.d.ts +38 -0
  13. package/dist/font/woff2.d.ts +8 -0
  14. package/dist/hinting/index.d.ts +9 -0
  15. package/dist/hinting/instructions/arithmetic.d.ts +46 -0
  16. package/dist/hinting/instructions/control-flow.d.ts +26 -0
  17. package/dist/hinting/instructions/delta.d.ts +32 -0
  18. package/dist/hinting/instructions/graphics-state.d.ts +94 -0
  19. package/dist/hinting/instructions/interpolate.d.ts +16 -0
  20. package/dist/hinting/instructions/points.d.ts +76 -0
  21. package/dist/hinting/instructions/stack.d.ts +28 -0
  22. package/dist/hinting/interpreter.d.ts +30 -0
  23. package/dist/hinting/programs.d.ts +88 -0
  24. package/dist/hinting/rounding.d.ts +51 -0
  25. package/dist/hinting/types.d.ts +369 -0
  26. package/dist/index.d.ts +14 -11
  27. package/dist/index.js +10 -8
  28. package/dist/index.js.map +47 -23
  29. package/dist/raster/atlas.d.ts +37 -0
  30. package/dist/raster/cell.d.ts +140 -0
  31. package/dist/raster/fixed-point.d.ts +100 -0
  32. package/dist/raster/gray-raster.d.ts +132 -0
  33. package/dist/raster/lcd-filter.d.ts +44 -0
  34. package/dist/raster/outline-decompose.d.ts +61 -0
  35. package/dist/raster/rasterize.d.ts +36 -0
  36. package/dist/raster/types.d.ts +174 -0
  37. package/dist/render/path.d.ts +17 -2
  38. package/dist/shaper/complex/indic.d.ts +4 -0
  39. package/dist/types.d.ts +4 -0
  40. package/dist/unicode/bidi/brackets.gen.d.ts +5 -0
  41. package/dist/unicode/bidi/char-types.gen.d.ts +25 -0
  42. package/dist/unicode/bidi/mirroring.gen.d.ts +2 -0
  43. package/package.json +41 -14
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025
3
+ Copyright (c) 2025 wiedymi
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,3 +19,8 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
+
23
+ ---
24
+
25
+ Portions of the rasterizer are based on FreeType (https://freetype.org).
26
+ FreeType is copyright (c) 1996-2024 The FreeType Project.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
4
4
  [![GitHub Sponsors](https://img.shields.io/badge/Sponsor-vivy--company-ea4aaa)](https://github.com/sponsors/vivy-company)
5
5
 
6
- Pure TypeScript text shaping engine. A port of [rustybuzz](https://github.com/RazrFalcon/rustybuzz)/[HarfBuzz](https://github.com/harfbuzz/harfbuzz) for the browser and Node.js.
6
+ Pure TypeScript text shaping engine with OpenType layout, TrueType hinting, and FreeType-style rasterization. Works in browsers and Bun/Node.js with zero dependencies.
7
7
 
8
8
  ## Features
9
9
 
@@ -13,6 +13,9 @@ Pure TypeScript text shaping engine. A port of [rustybuzz](https://github.com/Ra
13
13
  - **AAT Support**: morx, kerx, trak tables for Apple fonts
14
14
  - **Color Fonts**: SVG, sbix, CBDT/CBLC tables
15
15
  - **BiDi**: UAX #9 bidirectional text algorithm
16
+ - **Rasterization**: FreeType-style grayscale, LCD subpixel, and monochrome rendering
17
+ - **TrueType Hinting**: Full bytecode interpreter (150+ opcodes)
18
+ - **Texture Atlas**: GPU-ready glyph atlas generation with shelf packing
16
19
  - **Zero Dependencies**: Pure TypeScript, works in browser and Node.js
17
20
 
18
21
  ## Installation
@@ -106,6 +109,26 @@ const svg = shapedTextToSVG(font, glyphBuffer, { fontSize: 48 });
106
109
  - `shapedTextToSVG(font, buffer, options)` - Render shaped text to SVG
107
110
  - `renderShapedText(ctx, font, buffer, options)` - Render to Canvas 2D context
108
111
 
112
+ ### Rasterization
113
+
114
+ ```typescript
115
+ import { Font, rasterizeGlyph, buildAtlas, PixelMode } from "text-shaper";
116
+
117
+ // Rasterize a single glyph
118
+ const glyph = rasterizeGlyph(font, glyphId, 48, {
119
+ pixelMode: PixelMode.Gray, // Gray, Mono, or LCD
120
+ hinting: true, // Enable TrueType hinting
121
+ });
122
+
123
+ // Build a texture atlas for GPU rendering
124
+ const atlas = buildAtlas(font, glyphIds, {
125
+ fontSize: 32,
126
+ padding: 1,
127
+ pixelMode: PixelMode.Gray,
128
+ hinting: true,
129
+ });
130
+ ```
131
+
109
132
  ### Feature Helpers
110
133
 
111
134
  ```typescript
@@ -156,6 +179,9 @@ COLR, CPAL, SVG, sbix, CBDT, CBLC
156
179
  ### Vertical
157
180
  vhea, vmtx, VORG
158
181
 
182
+ ### Hinting
183
+ fpgm, prep, cvt, gasp
184
+
159
185
  ## License
160
186
 
161
187
  [MIT](LICENSE)
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Context lookup tables for Brotli decompression
3
+ * Based on brotli.js reference implementation (Apache 2.0 License)
4
+ */
5
+ export declare const CONTEXT_LOOKUP: Uint8Array<ArrayBuffer>;
6
+ export declare const CONTEXT_LOOKUP_OFFSETS: Uint16Array<ArrayBuffer>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Pure TypeScript Brotli Decompressor
3
+ * Based on the brotli.js reference implementation (MIT License)
4
+ * https://github.com/devongovett/brotli.js
5
+ */
6
+ /**
7
+ * Decompress Brotli-compressed data
8
+ */
9
+ export declare function decompress(data: Uint8Array): Uint8Array;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Brotli static dictionary
3
+ * Based on brotli.js reference implementation (Apache 2.0 License)
4
+ *
5
+ * The dictionary is loaded lazily to avoid bloating the initial bundle.
6
+ */
7
+ export declare const DICTIONARY_OFFSETS_BY_LENGTH: Uint32Array<ArrayBuffer>;
8
+ export declare const DICTIONARY_SIZE_BITS_BY_LENGTH: Uint8Array<ArrayBuffer>;
9
+ export declare const MIN_DICTIONARY_WORD_LENGTH = 4;
10
+ export declare const MAX_DICTIONARY_WORD_LENGTH = 24;
11
+ export declare const DICTIONARY: Uint8Array<ArrayBuffer>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Dictionary word transformations for Brotli decompression
3
+ * Based on brotli.js reference implementation (Apache 2.0 License)
4
+ */
5
+ interface Transform {
6
+ prefix: Uint8Array;
7
+ transform: number;
8
+ suffix: Uint8Array;
9
+ }
10
+ export declare const TRANSFORMS: Transform[];
11
+ export declare function transformDictionaryWord(dst: Uint8Array, idx: number, wordOffset: number, len: number, transformIdx: number, dictionary: Uint8Array): number;
12
+ export {};
@@ -8,7 +8,9 @@ import { type Cff2Table } from "./tables/cff2.ts";
8
8
  import { type CmapTable } from "./tables/cmap.ts";
9
9
  import { type ColrTable } from "./tables/colr.ts";
10
10
  import { type CpalTable } from "./tables/cpal.ts";
11
+ import { type FeatTable } from "./tables/feat.ts";
11
12
  import { type FvarTable } from "./tables/fvar.ts";
13
+ import { type GaspTable } from "./tables/gasp.ts";
12
14
  import { type GdefTable } from "./tables/gdef.ts";
13
15
  import { type Contour, type GlyfTable, type Glyph } from "./tables/glyf.ts";
14
16
  import { type GposTable } from "./tables/gpos.ts";
@@ -16,6 +18,7 @@ import { type GsubTable } from "./tables/gsub.ts";
16
18
  import { type GvarTable } from "./tables/gvar.ts";
17
19
  import { type HeadTable } from "./tables/head.ts";
18
20
  import { type HheaTable } from "./tables/hhea.ts";
21
+ import { type CvtTable, type FpgmTable, type PrepTable } from "./tables/hinting.ts";
19
22
  import { type HmtxTable } from "./tables/hmtx.ts";
20
23
  import { type HvarTable } from "./tables/hvar.ts";
21
24
  import { type JstfTable } from "./tables/jstf.ts";
@@ -30,7 +33,6 @@ import { type NameTable } from "./tables/name.ts";
30
33
  import { type Os2Table } from "./tables/os2.ts";
31
34
  import { type PostTable } from "./tables/post.ts";
32
35
  import { type SbixTable } from "./tables/sbix.ts";
33
- import { type FeatTable } from "./tables/feat.ts";
34
36
  import { type StatTable } from "./tables/stat.ts";
35
37
  import { type SvgTable } from "./tables/svg.ts";
36
38
  import { type TrakTable } from "./tables/trak.ts";
@@ -89,12 +91,18 @@ export declare class Font {
89
91
  private _cbdt;
90
92
  private _cblc;
91
93
  private _feat;
94
+ private _fpgm;
95
+ private _prep;
96
+ private _cvt;
97
+ private _gasp;
92
98
  private constructor();
93
- /** Load font from ArrayBuffer */
99
+ /** Load font from ArrayBuffer (sync - does not support WOFF2) */
94
100
  static load(buffer: ArrayBuffer, options?: FontLoadOptions): Font;
95
- /** Load font from URL (works in browser and Bun) */
101
+ /** Load font from ArrayBuffer with WOFF2 support (async) */
102
+ static loadAsync(buffer: ArrayBuffer, options?: FontLoadOptions): Promise<Font>;
103
+ /** Load font from URL (works in browser and Bun, supports WOFF2) */
96
104
  static fromURL(url: string, options?: FontLoadOptions): Promise<Font>;
97
- /** Load font from file path (Bun only) */
105
+ /** Load font from file path (Bun only, supports WOFF2) */
98
106
  static fromFile(path: string, options?: FontLoadOptions): Promise<Font>;
99
107
  /** Check if font has a specific table */
100
108
  hasTable(tag: Tag): boolean;
@@ -141,6 +149,10 @@ export declare class Font {
141
149
  get cblc(): CblcTable | null;
142
150
  get cbdt(): CbdtTable | null;
143
151
  get feat(): FeatTable | null;
152
+ get fpgm(): FpgmTable | null;
153
+ get prep(): PrepTable | null;
154
+ get cvtTable(): CvtTable | null;
155
+ get gasp(): GaspTable | null;
144
156
  /** Number of glyphs in the font */
145
157
  get numGlyphs(): number;
146
158
  /** Units per em */
@@ -163,6 +175,8 @@ export declare class Font {
163
175
  get hasAATLayout(): boolean;
164
176
  /** Is this a color font? */
165
177
  get isColorFont(): boolean;
178
+ /** Does this font have TrueType hinting? */
179
+ get hasHinting(): boolean;
166
180
  /** Get glyph ID for a Unicode codepoint */
167
181
  glyphId(codepoint: number): GlyphId;
168
182
  /** Get glyph ID for a character */
@@ -173,7 +187,7 @@ export declare class Font {
173
187
  leftSideBearing(glyphId: GlyphId): number;
174
188
  /** List all table tags in the font */
175
189
  listTables(): string[];
176
- /** Get raw glyph data (simple or composite) */
190
+ /** Get raw glyph data (simple or composite) - TrueType only */
177
191
  getGlyph(glyphId: GlyphId): Glyph | null;
178
192
  /** Get flattened contours for a glyph (resolves composites) */
179
193
  getGlyphContours(glyphId: GlyphId): Contour[] | null;
@@ -78,6 +78,10 @@ export interface PrivateDict {
78
78
  }
79
79
  export interface FDDict extends PrivateDict {
80
80
  fontName?: string;
81
+ /** Private dict offset and size [size, offset] */
82
+ private?: [number, number];
83
+ /** Local subroutines for this FD (parsed from private dict subrs offset) */
84
+ localSubrs?: Uint8Array[];
81
85
  }
82
86
  export interface FDSelect {
83
87
  format: number;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * gasp table - Grid-fitting And Scan-conversion Procedure
3
+ *
4
+ * This table controls when grid-fitting (hinting) and anti-aliasing
5
+ * should be applied based on the rendering size (ppem).
6
+ */
7
+ import type { Reader } from "../binary/reader.ts";
8
+ /**
9
+ * Gasp behavior flags
10
+ */
11
+ export declare const GaspFlag: {
12
+ /** Use grid-fitting (hinting) */
13
+ readonly GridFit: 1;
14
+ /** Use gray-scale rendering (anti-aliasing) */
15
+ readonly DoGray: 2;
16
+ /** Use symmetric grid-fitting (ClearType) */
17
+ readonly SymmetricGridFit: 4;
18
+ /** Use symmetric smoothing (ClearType) */
19
+ readonly SymmetricSmoothing: 8;
20
+ };
21
+ /**
22
+ * A ppem range with associated behavior
23
+ */
24
+ export interface GaspRange {
25
+ /** Maximum ppem for this range (inclusive) */
26
+ maxPPEM: number;
27
+ /** Behavior flags for this range */
28
+ behavior: number;
29
+ }
30
+ /**
31
+ * gasp table
32
+ */
33
+ export interface GaspTable {
34
+ /** Version (0 or 1) */
35
+ version: number;
36
+ /** Ranges sorted by maxPPEM */
37
+ ranges: GaspRange[];
38
+ }
39
+ /**
40
+ * Parse gasp table
41
+ */
42
+ export declare function parseGasp(reader: Reader): GaspTable;
43
+ /**
44
+ * Get behavior flags for a specific ppem
45
+ */
46
+ export declare function getGaspBehavior(gasp: GaspTable, ppem: number): number;
47
+ /**
48
+ * Check if grid-fitting should be used
49
+ */
50
+ export declare function shouldGridFit(gasp: GaspTable, ppem: number): boolean;
51
+ /**
52
+ * Check if gray-scale rendering should be used
53
+ */
54
+ export declare function shouldDoGray(gasp: GaspTable, ppem: number): boolean;
@@ -33,6 +33,9 @@ export interface GdefTable {
33
33
  markGlyphSets: MarkGlyphSets | null;
34
34
  }
35
35
  export declare function parseGdef(reader: Reader): GdefTable;
36
+ export declare function parseAttachList(reader: Reader): Map<GlyphId, AttachPoint>;
37
+ export declare function parseLigCaretList(reader: Reader): Map<GlyphId, LigatureCaret>;
38
+ export declare function parseMarkGlyphSets(reader: Reader): MarkGlyphSets;
36
39
  /** Get glyph class from GDEF */
37
40
  export declare function getGlyphClass(gdef: GdefTable | null, glyphId: GlyphId): GlyphClass | 0;
38
41
  /** Check if glyph is a base glyph */
@@ -36,6 +36,8 @@ export interface GlyphPoint {
36
36
  x: number;
37
37
  y: number;
38
38
  onCurve: boolean;
39
+ /** True if this is a cubic bezier control point (CFF fonts) */
40
+ cubic?: boolean;
39
41
  }
40
42
  /** A contour is a closed path of points */
41
43
  export type Contour = GlyphPoint[];
@@ -0,0 +1,38 @@
1
+ import type { Reader } from "../binary/reader.ts";
2
+ /**
3
+ * fpgm table - Font program
4
+ * Contains TrueType instructions to be executed once when the font is loaded
5
+ */
6
+ export interface FpgmTable {
7
+ /** Raw bytecode instructions */
8
+ instructions: Uint8Array;
9
+ }
10
+ /**
11
+ * prep table - CVT program (Control Value Program)
12
+ * Contains TrueType instructions executed whenever the font size or transformation changes
13
+ */
14
+ export interface PrepTable {
15
+ /** Raw bytecode instructions */
16
+ instructions: Uint8Array;
17
+ }
18
+ /**
19
+ * cvt table - Control Value Table
20
+ * Contains values referenced by TrueType instructions for consistent spacing/positioning
21
+ * Values are in FUnits (font design units)
22
+ */
23
+ export interface CvtTable {
24
+ /** Control values (FWORD, i.e., int16 in font units) */
25
+ values: Int16Array;
26
+ }
27
+ /**
28
+ * Parse fpgm table
29
+ */
30
+ export declare function parseFpgm(reader: Reader): FpgmTable;
31
+ /**
32
+ * Parse prep table
33
+ */
34
+ export declare function parsePrep(reader: Reader): PrepTable;
35
+ /**
36
+ * Parse cvt table
37
+ */
38
+ export declare function parseCvt(reader: Reader): CvtTable;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * WOFF2 to SFNT Converter
3
+ *
4
+ * Converts WOFF2 compressed fonts back to raw TTF/OTF format.
5
+ * Reference: https://www.w3.org/TR/WOFF2/
6
+ */
7
+ /** Convert WOFF2 to SFNT */
8
+ export declare function woff2ToSfnt(buffer: ArrayBuffer): Promise<ArrayBuffer>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * TrueType Hinting Module
3
+ *
4
+ * Implements the TrueType bytecode interpreter for grid-fitting.
5
+ */
6
+ export { execute, runCVTProgram, runFontProgram, runGlyphProgram, runProgram, setCodeRange, } from "./interpreter.ts";
7
+ export { createHintingEngine, executeFontProgram, type GlyphOutline, type HintedGlyph, type HintingEngine, hintedToPixels, hintGlyph, loadCVTProgram, loadFontProgram, setSize, } from "./programs.ts";
8
+ export { compensate, parseSuperRound, round, roundDownToGrid, roundOff, roundSuper, roundSuper45, roundToDoubleGrid, roundToGrid, roundToHalfGrid, roundUpToGrid, } from "./rounding.ts";
9
+ export { type CallRecord, CodeRange, createDefaultGraphicsState, createExecContext, createGlyphZone, type ExecContext, type F2Dot14, type F26Dot6, type FunctionDef, type GlyphZone, type GraphicsState, type InstructionDef, Opcode, type Point, RoundMode, TouchFlag, type UnitVector, } from "./types.ts";
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Arithmetic and logic instructions
3
+ */
4
+ import type { ExecContext } from "../types.ts";
5
+ /** ADD - Add top two values */
6
+ export declare function ADD(ctx: ExecContext): void;
7
+ /** SUB - Subtract top two values */
8
+ export declare function SUB(ctx: ExecContext): void;
9
+ /** DIV - Divide (26.6 fixed-point) */
10
+ export declare function DIV(ctx: ExecContext): void;
11
+ /** MUL - Multiply (26.6 fixed-point) */
12
+ export declare function MUL(ctx: ExecContext): void;
13
+ /** ABS - Absolute value */
14
+ export declare function ABS(ctx: ExecContext): void;
15
+ /** NEG - Negate */
16
+ export declare function NEG(ctx: ExecContext): void;
17
+ /** FLOOR - Floor to 26.6 integer (multiple of 64) */
18
+ export declare function FLOOR(ctx: ExecContext): void;
19
+ /** CEILING - Ceiling to 26.6 integer (multiple of 64) */
20
+ export declare function CEILING(ctx: ExecContext): void;
21
+ /** MAX - Maximum of top two */
22
+ export declare function MAX(ctx: ExecContext): void;
23
+ /** MIN - Minimum of top two */
24
+ export declare function MIN(ctx: ExecContext): void;
25
+ /** LT - Less than */
26
+ export declare function LT(ctx: ExecContext): void;
27
+ /** LTEQ - Less than or equal */
28
+ export declare function LTEQ(ctx: ExecContext): void;
29
+ /** GT - Greater than */
30
+ export declare function GT(ctx: ExecContext): void;
31
+ /** GTEQ - Greater than or equal */
32
+ export declare function GTEQ(ctx: ExecContext): void;
33
+ /** EQ - Equal */
34
+ export declare function EQ(ctx: ExecContext): void;
35
+ /** NEQ - Not equal */
36
+ export declare function NEQ(ctx: ExecContext): void;
37
+ /** ODD - Test if odd (after rounding to pixels) */
38
+ export declare function ODD(ctx: ExecContext): void;
39
+ /** EVEN - Test if even (after rounding to pixels) */
40
+ export declare function EVEN(ctx: ExecContext): void;
41
+ /** AND - Logical AND */
42
+ export declare function AND(ctx: ExecContext): void;
43
+ /** OR - Logical OR */
44
+ export declare function OR(ctx: ExecContext): void;
45
+ /** NOT - Logical NOT */
46
+ export declare function NOT(ctx: ExecContext): void;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Control flow instructions
3
+ */
4
+ import type { ExecContext } from "../types.ts";
5
+ /** IF - Conditional branch */
6
+ export declare function IF(ctx: ExecContext): void;
7
+ /** ELSE - Alternative branch */
8
+ export declare function ELSE(ctx: ExecContext): void;
9
+ /** EIF - End IF */
10
+ export declare function EIF(_ctx: ExecContext): void;
11
+ /** JMPR - Jump relative */
12
+ export declare function JMPR(ctx: ExecContext): void;
13
+ /** JROT - Jump relative on true */
14
+ export declare function JROT(ctx: ExecContext): void;
15
+ /** JROF - Jump relative on false */
16
+ export declare function JROF(ctx: ExecContext): void;
17
+ /** FDEF - Define function */
18
+ export declare function FDEF(ctx: ExecContext): void;
19
+ /** ENDF - End function definition */
20
+ export declare function ENDF(ctx: ExecContext): void;
21
+ /** CALL - Call function */
22
+ export declare function CALL(ctx: ExecContext): void;
23
+ /** LOOPCALL - Call function with loop count */
24
+ export declare function LOOPCALL(ctx: ExecContext): void;
25
+ /** IDEF - Define instruction */
26
+ export declare function IDEF(ctx: ExecContext): void;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Delta instructions
3
+ *
4
+ * These instructions allow fine-tuning of point positions and CVT values
5
+ * at specific pixel-per-em (ppem) sizes. This is useful for fixing
6
+ * rendering issues that only appear at certain sizes.
7
+ */
8
+ import type { ExecContext } from "../types.ts";
9
+ /**
10
+ * DELTAP1 - Delta exception point (ppem 0-15 + deltaBase)
11
+ */
12
+ export declare function DELTAP1(ctx: ExecContext): void;
13
+ /**
14
+ * DELTAP2 - Delta exception point (ppem 16-31 + deltaBase)
15
+ */
16
+ export declare function DELTAP2(ctx: ExecContext): void;
17
+ /**
18
+ * DELTAP3 - Delta exception point (ppem 32-47 + deltaBase)
19
+ */
20
+ export declare function DELTAP3(ctx: ExecContext): void;
21
+ /**
22
+ * DELTAC1 - Delta exception CVT (ppem 0-15 + deltaBase)
23
+ */
24
+ export declare function DELTAC1(ctx: ExecContext): void;
25
+ /**
26
+ * DELTAC2 - Delta exception CVT (ppem 16-31 + deltaBase)
27
+ */
28
+ export declare function DELTAC2(ctx: ExecContext): void;
29
+ /**
30
+ * DELTAC3 - Delta exception CVT (ppem 32-47 + deltaBase)
31
+ */
32
+ export declare function DELTAC3(ctx: ExecContext): void;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Graphics state manipulation instructions
3
+ */
4
+ import { type ExecContext } from "../types.ts";
5
+ /** SVTCA - Set vectors to coordinate axis (both projection and freedom) */
6
+ export declare function SVTCA(ctx: ExecContext, axis: 0 | 1): void;
7
+ /** SPVTCA - Set projection vector to coordinate axis */
8
+ export declare function SPVTCA(ctx: ExecContext, axis: 0 | 1): void;
9
+ /** SFVTCA - Set freedom vector to coordinate axis */
10
+ export declare function SFVTCA(ctx: ExecContext, axis: 0 | 1): void;
11
+ /** SPVTL - Set projection vector to line */
12
+ export declare function SPVTL(ctx: ExecContext, perpendicular: boolean): void;
13
+ /** SFVTL - Set freedom vector to line */
14
+ export declare function SFVTL(ctx: ExecContext, perpendicular: boolean): void;
15
+ /** SDPVTL - Set dual projection vector to line (only sets dualVector, not projVector) */
16
+ export declare function SDPVTL(ctx: ExecContext, perpendicular: boolean): void;
17
+ /** SPVFS - Set projection vector from stack */
18
+ export declare function SPVFS(ctx: ExecContext): void;
19
+ /** SFVFS - Set freedom vector from stack */
20
+ export declare function SFVFS(ctx: ExecContext): void;
21
+ /** GPV - Get projection vector */
22
+ export declare function GPV(ctx: ExecContext): void;
23
+ /** GFV - Get freedom vector */
24
+ export declare function GFV(ctx: ExecContext): void;
25
+ /** SFVTPV - Set freedom vector to projection vector */
26
+ export declare function SFVTPV(ctx: ExecContext): void;
27
+ /** SRP0 - Set reference point 0 */
28
+ export declare function SRP0(ctx: ExecContext): void;
29
+ /** SRP1 - Set reference point 1 */
30
+ export declare function SRP1(ctx: ExecContext): void;
31
+ /** SRP2 - Set reference point 2 */
32
+ export declare function SRP2(ctx: ExecContext): void;
33
+ /** SZP0 - Set zone pointer 0 */
34
+ export declare function SZP0(ctx: ExecContext): void;
35
+ /** SZP1 - Set zone pointer 1 */
36
+ export declare function SZP1(ctx: ExecContext): void;
37
+ /** SZP2 - Set zone pointer 2 */
38
+ export declare function SZP2(ctx: ExecContext): void;
39
+ /** SZPS - Set all zone pointers */
40
+ export declare function SZPS(ctx: ExecContext): void;
41
+ /** SLOOP - Set loop counter */
42
+ export declare function SLOOP(ctx: ExecContext): void;
43
+ /** SMD - Set minimum distance */
44
+ export declare function SMD(ctx: ExecContext): void;
45
+ /** SCVTCI - Set control value table cut-in */
46
+ export declare function SCVTCI(ctx: ExecContext): void;
47
+ /** SSWCI - Set single width cut-in */
48
+ export declare function SSWCI(ctx: ExecContext): void;
49
+ /** SSW - Set single width value */
50
+ export declare function SSW(ctx: ExecContext): void;
51
+ /** SDB - Set delta base */
52
+ export declare function SDB(ctx: ExecContext): void;
53
+ /** SDS - Set delta shift */
54
+ export declare function SDS(ctx: ExecContext): void;
55
+ /** RTG - Round to grid */
56
+ export declare function RTG(ctx: ExecContext): void;
57
+ /** RTHG - Round to half grid */
58
+ export declare function RTHG(ctx: ExecContext): void;
59
+ /** RTDG - Round to double grid */
60
+ export declare function RTDG(ctx: ExecContext): void;
61
+ /** RDTG - Round down to grid */
62
+ export declare function RDTG(ctx: ExecContext): void;
63
+ /** RUTG - Round up to grid */
64
+ export declare function RUTG(ctx: ExecContext): void;
65
+ /** ROFF - Rounding off */
66
+ export declare function ROFF(ctx: ExecContext): void;
67
+ /** SROUND - Super round */
68
+ export declare function SROUND(ctx: ExecContext): void;
69
+ /** S45ROUND - Super round 45 degrees */
70
+ export declare function S45ROUND(ctx: ExecContext): void;
71
+ /** FLIPON - Turn auto-flip on */
72
+ export declare function FLIPON(ctx: ExecContext): void;
73
+ /** FLIPOFF - Turn auto-flip off */
74
+ export declare function FLIPOFF(ctx: ExecContext): void;
75
+ /** SCANCTRL - Set scan conversion control */
76
+ export declare function SCANCTRL(ctx: ExecContext): void;
77
+ /** SCANTYPE - Set scan type */
78
+ export declare function SCANTYPE(ctx: ExecContext): void;
79
+ /** INSTCTRL - Set instruction control */
80
+ export declare function INSTCTRL(ctx: ExecContext): void;
81
+ /** GETINFO - Get font engine info */
82
+ export declare function GETINFO(ctx: ExecContext): void;
83
+ /** RS - Read storage */
84
+ export declare function RS(ctx: ExecContext): void;
85
+ /** WS - Write storage */
86
+ export declare function WS(ctx: ExecContext): void;
87
+ /** RCVT - Read CVT value */
88
+ export declare function RCVT(ctx: ExecContext): void;
89
+ /** WCVTP - Write CVT value in pixels */
90
+ export declare function WCVTP(ctx: ExecContext): void;
91
+ /** WCVTF - Write CVT value in font units */
92
+ export declare function WCVTF(ctx: ExecContext): void;
93
+ /** UTP - UnTouch Point */
94
+ export declare function UTP(ctx: ExecContext): void;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * IUP - Interpolate Untouched Points
3
+ *
4
+ * This instruction interpolates all points that haven't been touched
5
+ * by previous hinting instructions. It's typically called near the end
6
+ * of glyph hinting to smooth out the positions of all remaining points.
7
+ */
8
+ import { type ExecContext } from "../types.ts";
9
+ /**
10
+ * Interpolate untouched points in X direction
11
+ */
12
+ export declare function IUP_X(ctx: ExecContext): void;
13
+ /**
14
+ * Interpolate untouched points in Y direction
15
+ */
16
+ export declare function IUP_Y(ctx: ExecContext): void;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Point movement instructions
3
+ *
4
+ * These are the core hinting operations that actually move glyph points.
5
+ */
6
+ import { type ExecContext, type F26Dot6, type GlyphZone, type Point } from "../types.ts";
7
+ /**
8
+ * Project a point onto the projection vector
9
+ */
10
+ export declare function project(ctx: ExecContext, p: Point): F26Dot6;
11
+ /**
12
+ * Project using dual vector (for original positions)
13
+ */
14
+ export declare function dualProject(ctx: ExecContext, p: Point): F26Dot6;
15
+ /**
16
+ * Move a point along the freedom vector
17
+ */
18
+ export declare function movePoint(ctx: ExecContext, zone: GlyphZone, pointIndex: number, distance: F26Dot6): void;
19
+ /**
20
+ * Get current position of a point projected onto projection vector
21
+ */
22
+ export declare function getCurrent(ctx: ExecContext, zone: GlyphZone, pointIndex: number): F26Dot6;
23
+ /**
24
+ * Get original position of a point projected onto dual vector
25
+ */
26
+ export declare function getOriginal(ctx: ExecContext, zone: GlyphZone, pointIndex: number): F26Dot6;
27
+ /**
28
+ * Mark point as touched in the current direction
29
+ */
30
+ export declare function touchPoint(ctx: ExecContext, zone: GlyphZone, pointIndex: number): void;
31
+ /** MDAP - Move Direct Absolute Point */
32
+ export declare function MDAP(ctx: ExecContext, doRound: boolean): void;
33
+ /** MIAP - Move Indirect Absolute Point (uses CVT) */
34
+ export declare function MIAP(ctx: ExecContext, doRound: boolean): void;
35
+ /** MDRP - Move Direct Relative Point */
36
+ export declare function MDRP(ctx: ExecContext, flags: number): void;
37
+ /** MIRP - Move Indirect Relative Point (uses CVT) */
38
+ export declare function MIRP(ctx: ExecContext, flags: number): void;
39
+ /** SHP - Shift Point using reference point */
40
+ export declare function SHP(ctx: ExecContext, useRp1: boolean): void;
41
+ /** SHC - Shift Contour using reference point */
42
+ export declare function SHC(ctx: ExecContext, useRp1: boolean): void;
43
+ /** SHZ - Shift Zone using reference point */
44
+ export declare function SHZ(ctx: ExecContext, useRp1: boolean): void;
45
+ /** SHPIX - Shift Point by Pixel Amount */
46
+ export declare function SHPIX(ctx: ExecContext): void;
47
+ /** IP - Interpolate Point */
48
+ export declare function IP(ctx: ExecContext): void;
49
+ /** ALIGNRP - Align to Reference Point */
50
+ export declare function ALIGNRP(ctx: ExecContext): void;
51
+ /** MSIRP - Move Stack Indirect Relative Point */
52
+ export declare function MSIRP(ctx: ExecContext, setRp0: boolean): void;
53
+ /** ISECT - Move Point to Intersection of two lines */
54
+ export declare function ISECT(ctx: ExecContext): void;
55
+ /** ALIGNPTS - Align two points */
56
+ export declare function ALIGNPTS(ctx: ExecContext): void;
57
+ /** GC - Get Coordinate projected onto projection vector */
58
+ export declare function GC(ctx: ExecContext, useOriginal: boolean): void;
59
+ /** SCFS - Set Coordinate From Stack */
60
+ export declare function SCFS(ctx: ExecContext): void;
61
+ /** MD - Measure Distance between two points */
62
+ export declare function MD(ctx: ExecContext, useOriginal: boolean): void;
63
+ /** MPPEM - Measure Pixels Per EM */
64
+ export declare function MPPEM(ctx: ExecContext): void;
65
+ /** MPS - Measure Point Size */
66
+ export declare function MPS(ctx: ExecContext): void;
67
+ /** FLIPPT - Flip on-curve/off-curve flag */
68
+ export declare function FLIPPT(ctx: ExecContext): void;
69
+ /** FLIPRGON - Set on-curve flag for range */
70
+ export declare function FLIPRGON(ctx: ExecContext): void;
71
+ /** FLIPRGOFF - Clear on-curve flag for range */
72
+ export declare function FLIPRGOFF(ctx: ExecContext): void;
73
+ /** ROUND - Round value */
74
+ export declare function ROUND(ctx: ExecContext, _colorIndex: number): void;
75
+ /** NROUND - No-round (just applies engine compensation) */
76
+ export declare function NROUND(ctx: ExecContext, _colorIndex: number): void;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Stack manipulation instructions
3
+ */
4
+ import type { ExecContext } from "../types.ts";
5
+ /** DUP - Duplicate top of stack */
6
+ export declare function DUP(ctx: ExecContext): void;
7
+ /** POP - Pop top of stack */
8
+ export declare function POP(ctx: ExecContext): void;
9
+ /** CLEAR - Clear the entire stack */
10
+ export declare function CLEAR(ctx: ExecContext): void;
11
+ /** SWAP - Swap top two elements */
12
+ export declare function SWAP(ctx: ExecContext): void;
13
+ /** DEPTH - Push stack depth */
14
+ export declare function DEPTH(ctx: ExecContext): void;
15
+ /** CINDEX - Copy indexed element to top */
16
+ export declare function CINDEX(ctx: ExecContext): void;
17
+ /** MINDEX - Move indexed element to top */
18
+ export declare function MINDEX(ctx: ExecContext): void;
19
+ /** ROLL - Roll top three elements */
20
+ export declare function ROLL(ctx: ExecContext): void;
21
+ /** Push byte(s) from instruction stream */
22
+ export declare function PUSHB(ctx: ExecContext, count: number): void;
23
+ /** Push word(s) from instruction stream */
24
+ export declare function PUSHW(ctx: ExecContext, count: number): void;
25
+ /** NPUSHB - Push N bytes */
26
+ export declare function NPUSHB(ctx: ExecContext): void;
27
+ /** NPUSHW - Push N words */
28
+ export declare function NPUSHW(ctx: ExecContext): void;