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
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Rasterizer types - FreeType-style bitmap rendering
3
+ */
4
+ import type { GlyphPath } from "../render/path.ts";
5
+ /**
6
+ * Pixel modes for bitmap output
7
+ */
8
+ export declare enum PixelMode {
9
+ /** 1-bit per pixel, 8 pixels per byte */
10
+ Mono = 0,
11
+ /** 8-bit grayscale, 1 byte per pixel */
12
+ Gray = 1,
13
+ /** 24-bit LCD subpixel RGB, 3 bytes per pixel */
14
+ LCD = 2,
15
+ /** 24-bit LCD subpixel vertical RGB */
16
+ LCD_V = 3
17
+ }
18
+ /**
19
+ * Fill rule for outline rendering
20
+ */
21
+ export declare enum FillRule {
22
+ /** Non-zero winding rule (default) */
23
+ NonZero = 0,
24
+ /** Even-odd (alternating) fill rule */
25
+ EvenOdd = 1
26
+ }
27
+ /**
28
+ * Bitmap buffer for rasterized glyphs
29
+ */
30
+ export interface Bitmap {
31
+ /** Pixel buffer */
32
+ buffer: Uint8Array;
33
+ /** Width in pixels */
34
+ width: number;
35
+ /** Height in pixels */
36
+ rows: number;
37
+ /** Bytes per row (may include padding) */
38
+ pitch: number;
39
+ /** Pixel format */
40
+ pixelMode: PixelMode;
41
+ /** Number of gray levels (256 for 8-bit) */
42
+ numGrays: number;
43
+ }
44
+ /**
45
+ * A single horizontal span of pixels (for direct rendering)
46
+ */
47
+ export interface Span {
48
+ /** X position of span start */
49
+ x: number;
50
+ /** Length in pixels */
51
+ len: number;
52
+ /** Coverage value 0-255 */
53
+ coverage: number;
54
+ }
55
+ /**
56
+ * Callback for span-based rendering
57
+ * @template T User data type passed through from render call
58
+ */
59
+ export type SpanFunc<T = void> = (y: number, spans: Span[], userData: T) => void;
60
+ /**
61
+ * Rasterization parameters
62
+ */
63
+ export interface RasterParams {
64
+ /** Target bitmap (null for span callback mode) */
65
+ target?: Bitmap;
66
+ /** Source outline path */
67
+ source: GlyphPath;
68
+ /** Fill rule */
69
+ fillRule?: FillRule;
70
+ /** Span callback for direct rendering */
71
+ spanFunc?: SpanFunc;
72
+ /** Clip box (in pixels) */
73
+ clipBox?: {
74
+ xMin: number;
75
+ yMin: number;
76
+ xMax: number;
77
+ yMax: number;
78
+ };
79
+ }
80
+ /**
81
+ * Options for rasterizing a glyph
82
+ */
83
+ export interface RasterizeOptions {
84
+ /** Width in pixels */
85
+ width: number;
86
+ /** Height in pixels */
87
+ height: number;
88
+ /** Scale factor (font units to pixels) */
89
+ scale: number;
90
+ /** X offset in pixels */
91
+ offsetX?: number;
92
+ /** Y offset in pixels */
93
+ offsetY?: number;
94
+ /** Pixel mode */
95
+ pixelMode?: PixelMode;
96
+ /** Fill rule */
97
+ fillRule?: FillRule;
98
+ /** Flip Y axis (font coords are Y-up, bitmap is Y-down) */
99
+ flipY?: boolean;
100
+ }
101
+ /**
102
+ * Result of glyph rasterization
103
+ */
104
+ export interface RasterizedGlyph {
105
+ /** Pixel data */
106
+ bitmap: Bitmap;
107
+ /** Bearing X (offset from origin to left edge) */
108
+ bearingX: number;
109
+ /** Bearing Y (offset from origin to top edge) */
110
+ bearingY: number;
111
+ }
112
+ /**
113
+ * Glyph metrics for atlas building
114
+ */
115
+ export interface GlyphMetrics {
116
+ /** Glyph ID */
117
+ glyphId: number;
118
+ /** X position in atlas */
119
+ atlasX: number;
120
+ /** Y position in atlas */
121
+ atlasY: number;
122
+ /** Width in atlas */
123
+ width: number;
124
+ /** Height in atlas */
125
+ height: number;
126
+ /** Bearing X */
127
+ bearingX: number;
128
+ /** Bearing Y */
129
+ bearingY: number;
130
+ /** Horizontal advance */
131
+ advance: number;
132
+ }
133
+ /**
134
+ * Texture atlas containing multiple glyphs
135
+ */
136
+ export interface GlyphAtlas {
137
+ /** Atlas bitmap */
138
+ bitmap: Bitmap;
139
+ /** Glyph metrics indexed by glyph ID */
140
+ glyphs: Map<number, GlyphMetrics>;
141
+ /** Font size used for rendering */
142
+ fontSize: number;
143
+ }
144
+ /**
145
+ * Options for building a glyph atlas
146
+ */
147
+ export interface AtlasOptions {
148
+ /** Font size in pixels */
149
+ fontSize: number;
150
+ /** Padding between glyphs */
151
+ padding?: number;
152
+ /** Maximum atlas width */
153
+ maxWidth?: number;
154
+ /** Maximum atlas height */
155
+ maxHeight?: number;
156
+ /** Pixel mode */
157
+ pixelMode?: PixelMode;
158
+ /** Enable hinting */
159
+ hinting?: boolean;
160
+ }
161
+ /**
162
+ * Create an empty bitmap
163
+ */
164
+ export declare function createBitmap(width: number, height: number, pixelMode?: PixelMode): Bitmap;
165
+ /**
166
+ * Clear a bitmap to zero
167
+ */
168
+ export declare function clearBitmap(bitmap: Bitmap): void;
169
+ /**
170
+ * Create a bottom-up bitmap (negative pitch)
171
+ * Bottom-up bitmaps have row 0 at the bottom of the image,
172
+ * which matches some graphics APIs (e.g., Windows DIB, OpenGL textures)
173
+ */
174
+ export declare function createBottomUpBitmap(width: number, height: number, pixelMode?: PixelMode): Bitmap;
@@ -30,6 +30,19 @@ export type PathCommand = {
30
30
  } | {
31
31
  type: "Z";
32
32
  };
33
+ /**
34
+ * Outline flags (like FreeType's FT_OUTLINE_* flags)
35
+ */
36
+ export declare enum OutlineFlags {
37
+ /** No flags */
38
+ None = 0,
39
+ /** Use even-odd fill rule instead of non-zero winding */
40
+ EvenOddFill = 1,
41
+ /** Outline has been hinted */
42
+ HighPrecision = 2,
43
+ /** Outline is a single stroke (not filled) */
44
+ SinglePass = 4
45
+ }
33
46
  /**
34
47
  * A glyph path is a series of drawing commands
35
48
  */
@@ -41,10 +54,12 @@ export interface GlyphPath {
41
54
  xMax: number;
42
55
  yMax: number;
43
56
  } | null;
57
+ /** Outline flags (like FreeType's FT_OUTLINE_* flags) */
58
+ flags?: OutlineFlags;
44
59
  }
45
60
  /**
46
- * Convert TrueType contours to path commands
47
- * TrueType uses quadratic Bézier curves with on-curve and off-curve points
61
+ * Convert contours to path commands
62
+ * Handles both TrueType (quadratic Béziers) and CFF (cubic Béziers)
48
63
  */
49
64
  export declare function contourToPath(contour: Contour): PathCommand[];
50
65
  /**
@@ -103,6 +103,10 @@ export declare enum MatraPosition {
103
103
  BelowBase = 2,
104
104
  PostBase = 3
105
105
  }
106
+ /**
107
+ * Get matra position based on codepoint
108
+ */
109
+ export declare function getMatraPosition(cp: number): MatraPosition;
106
110
  /**
107
111
  * Set up masks and syllable indices for Indic shaping
108
112
  */
package/dist/types.d.ts CHANGED
@@ -129,6 +129,10 @@ export declare const Tags: {
129
129
  readonly vhea: number;
130
130
  readonly vmtx: number;
131
131
  readonly VORG: number;
132
+ readonly fpgm: number;
133
+ readonly prep: number;
134
+ readonly cvt: number;
135
+ readonly gasp: number;
132
136
  };
133
137
  export declare const FeatureTags: {
134
138
  readonly ccmp: number;
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ pairs: string;
3
+ canonical: string;
4
+ };
5
+ export default _default;
@@ -0,0 +1,25 @@
1
+ declare const _default: {
2
+ R: string;
3
+ EN: string;
4
+ ES: string;
5
+ ET: string;
6
+ AN: string;
7
+ CS: string;
8
+ B: string;
9
+ S: string;
10
+ WS: string;
11
+ ON: string;
12
+ BN: string;
13
+ NSM: string;
14
+ AL: string;
15
+ LRO: string;
16
+ RLO: string;
17
+ LRE: string;
18
+ RLE: string;
19
+ PDF: string;
20
+ LRI: string;
21
+ RLI: string;
22
+ FSI: string;
23
+ PDI: string;
24
+ };
25
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: "14>1,j>2,t>2,u>2,1a>g,2v3>1,1>1,1ge>1,1wd>1,b>1,1j>1,f>1,ai>3,-2>3,+1,8>1k0,-1jq>1y7,-1y6>1hf,-1he>1h6,-1h5>1ha,-1h8>1qi,-1pu>1,6>3u,-3s>7,6>1,1>1,f>1,1>1,+2,3>1,1>1,+13,4>1,1>1,6>1eo,-1ee>1,3>1mg,-1me>1mk,-1mj>1mi,-1mg>1mi,-1md>1,1>1,+2,1>10k,-103>1,1>1,4>1,5>1,1>1,+10,3>1,1>8,-7>8,+1,-6>7,+1,a>1,1>1,u>1,u6>1,1>1,+5,26>1,1>1,2>1,2>2,8>1,7>1,4>1,1>1,+5,b8>1,1>1,+3,1>3,-2>1,2>1,1>1,+2,c>1,3>1,1>1,+2,h>1,3>1,a>1,1>1,2>1,3>1,1>1,d>1,f>1,3>1,1a>1,1>1,6>1,7>1,13>1,k>1,1>1,+19,4>1,1>1,+2,2>1,1>1,+18,m>1,a>1,1>1,lk>1,1>1,4>1,2>1,f>1,3>1,1>1,+3,db>1,1>1,+3,3>1,1>1,+2,14qm>1,1>1,+1,6>1,4j>1,j>2,t>2,u>2,2>1,+1";
2
+ export default _default;
package/package.json CHANGED
@@ -1,18 +1,47 @@
1
1
  {
2
2
  "name": "text-shaper",
3
- "version": "0.0.1",
4
- "description": "Pure TypeScript text shaping engine",
5
- "type": "module",
3
+ "version": "0.1.0",
6
4
  "main": "./dist/index.js",
7
5
  "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
6
+ "devDependencies": {
7
+ "@biomejs/biome": "2.3.8",
8
+ "@types/bun": "latest",
9
+ "vitepress": "^2.0.0-alpha.15",
10
+ "vitepress-plugin-llms": "^1.9.3"
11
+ },
12
+ "peerDependencies": {
13
+ "typescript": "^5"
14
+ },
9
15
  "exports": {
10
16
  ".": {
11
17
  "types": "./dist/index.d.ts",
12
18
  "import": "./dist/index.js"
13
19
  }
14
20
  },
15
- "files": ["dist"],
21
+ "description": "Pure TypeScript text shaping engine with OpenType layout, TrueType hinting, and FreeType-style rasterization",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "keywords": [
26
+ "font",
27
+ "text",
28
+ "shaping",
29
+ "harfbuzz",
30
+ "opentype",
31
+ "truetype",
32
+ "rasterizer",
33
+ "hinting",
34
+ "typography",
35
+ "glyph",
36
+ "freetype",
37
+ "arabic",
38
+ "indic",
39
+ "bidi",
40
+ "variable-fonts",
41
+ "lcd-rendering",
42
+ "texture-atlas"
43
+ ],
44
+ "license": "MIT",
16
45
  "scripts": {
17
46
  "build": "bun build ./src/index.ts --outdir ./dist --target browser --minify --sourcemap=linked",
18
47
  "build:prod": "bun build ./src/index.ts --outdir ./dist --target browser --production --sourcemap=external",
@@ -21,13 +50,11 @@
21
50
  "typecheck": "tsc --noEmit",
22
51
  "lint": "biome check --write --unsafe --max-diagnostics 99999",
23
52
  "check": "bun run typecheck && bun run lint",
24
- "prepublishOnly": "bun run build:prod && bun run build:dts"
53
+ "prepublishOnly": "bun run build:prod && bun run build:dts",
54
+ "docs:dev": "vitepress dev docs",
55
+ "docs:build": "vitepress build docs",
56
+ "docs:preview": "vitepress preview docs"
25
57
  },
26
- "devDependencies": {
27
- "@biomejs/biome": "2.3.8",
28
- "@types/bun": "latest"
29
- },
30
- "peerDependencies": {
31
- "typescript": "^5"
32
- }
33
- }
58
+ "type": "module",
59
+ "types": "./dist/index.d.ts"
60
+ }