text-shaper 0.1.2 → 0.1.3
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.
- package/README.md +1 -0
- package/dist/aat/state-machine.d.ts +18 -6
- package/dist/buffer/glyph-buffer.d.ts +35 -1
- package/dist/buffer/unicode-buffer.d.ts +2 -0
- package/dist/fluent/bitmap-builder.d.ts +146 -0
- package/dist/fluent/index.d.ts +102 -0
- package/dist/fluent/path-builder.d.ts +230 -0
- package/dist/fluent/pipe.d.ts +200 -0
- package/dist/fluent/types.d.ts +93 -0
- package/dist/font/face.d.ts +2 -0
- package/dist/font/font.d.ts +14 -0
- package/dist/font/tables/cff.d.ts +3 -1
- package/dist/font/tables/colr.d.ts +4 -1
- package/dist/font/tables/fvar.d.ts +3 -1
- package/dist/font/tables/glyf.d.ts +13 -0
- package/dist/font/tables/gpos.d.ts +9 -1
- package/dist/font/tables/gsub.d.ts +11 -0
- package/dist/font/tables/gvar.d.ts +10 -1
- package/dist/font/tables/head.d.ts +5 -0
- package/dist/font/tables/hhea.d.ts +5 -0
- package/dist/font/tables/loca.d.ts +3 -0
- package/dist/font/tables/maxp.d.ts +5 -0
- package/dist/font/tables/name.d.ts +5 -0
- package/dist/font/tables/os2.d.ts +5 -0
- package/dist/font/tables/post.d.ts +5 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +12 -10
- package/dist/index.js.map +104 -98
- package/dist/layout/justify.d.ts +15 -2
- package/dist/layout/structures/class-def.d.ts +61 -8
- package/dist/layout/structures/coverage.d.ts +57 -10
- package/dist/layout/structures/device.d.ts +26 -5
- package/dist/layout/structures/layout-common.d.ts +18 -3
- package/dist/layout/structures/set-digest.d.ts +59 -0
- package/dist/raster/asymmetric-stroke.d.ts +9 -5
- package/dist/raster/bitmap-utils.d.ts +67 -0
- package/dist/raster/blur.d.ts +11 -0
- package/dist/raster/cascade-blur.d.ts +9 -10
- package/dist/raster/cell.d.ts +24 -0
- package/dist/raster/fixed-point.d.ts +1 -1
- package/dist/raster/gradient.d.ts +15 -0
- package/dist/raster/gray-raster.d.ts +7 -1
- package/dist/raster/lcd-filter.d.ts +15 -0
- package/dist/raster/msdf.d.ts +15 -5
- package/dist/raster/outline-decompose.d.ts +16 -17
- package/dist/raster/rasterize.d.ts +19 -2
- package/dist/raster/sdf.d.ts +3 -0
- package/dist/raster/stroker.d.ts +3 -0
- package/dist/raster/types.d.ts +9 -0
- package/dist/render/path.d.ts +56 -1
- package/dist/shaper/complex/arabic.d.ts +1 -0
- package/dist/shaper/shape-plan.d.ts +11 -8
- package/dist/shaper/shaper.d.ts +61 -3
- package/dist/unicode/bidi/brackets.d.ts +15 -0
- package/dist/unicode/bidi/char-types.d.ts +4 -0
- package/dist/unicode/bidi/embedding-levels.d.ts +3 -0
- package/dist/unicode/bidi/mirroring.d.ts +10 -0
- package/dist/unicode/bidi/reordering.d.ts +15 -0
- package/dist/unicode/normalize.d.ts +23 -0
- package/dist/unicode/script.d.ts +17 -0
- package/dist/unicode/segmentation.d.ts +18 -0
- package/package.json +11 -2
|
@@ -35,10 +35,25 @@ export declare enum LcdMode {
|
|
|
35
35
|
* 1. Render at 3x horizontal resolution
|
|
36
36
|
* 2. Apply FIR filter to reduce color fringing
|
|
37
37
|
* 3. Output RGB values per pixel
|
|
38
|
+
*
|
|
39
|
+
* @param path Glyph path to rasterize
|
|
40
|
+
* @param width Width in pixels
|
|
41
|
+
* @param height Height in pixels
|
|
42
|
+
* @param scale Scale factor from font units to pixels
|
|
43
|
+
* @param offsetX X offset in pixels
|
|
44
|
+
* @param offsetY Y offset in pixels
|
|
45
|
+
* @param mode LCD subpixel mode (RGB, BGR, RGB_V, BGR_V)
|
|
46
|
+
* @param filterWeights FIR filter coefficients for reducing color fringing
|
|
47
|
+
* @returns Bitmap with LCD subpixel data (3 bytes per pixel)
|
|
38
48
|
*/
|
|
39
49
|
export declare function rasterizeLcd(path: GlyphPath, width: number, height: number, scale: number, offsetX: number, offsetY: number, mode?: LcdMode, filterWeights?: number[]): Bitmap;
|
|
40
50
|
/**
|
|
41
51
|
* Convert LCD bitmap to RGBA for display
|
|
42
52
|
* Uses gamma-corrected blending against a background color
|
|
53
|
+
*
|
|
54
|
+
* @param lcd LCD bitmap to convert
|
|
55
|
+
* @param bgColor Background color as RGB (0-255 each)
|
|
56
|
+
* @param fgColor Foreground color as RGB (0-255 each)
|
|
57
|
+
* @returns RGBA pixel array (4 bytes per pixel)
|
|
43
58
|
*/
|
|
44
59
|
export declare function lcdToRGBA(lcd: Bitmap, bgColor?: [number, number, number], fgColor?: [number, number, number]): Uint8Array;
|
package/dist/raster/msdf.d.ts
CHANGED
|
@@ -29,27 +29,36 @@ export interface Point {
|
|
|
29
29
|
*/
|
|
30
30
|
export type EdgeColor = 0 | 1 | 2;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Bounding box for edge culling
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
interface EdgeBounds {
|
|
35
|
+
minX: number;
|
|
36
|
+
maxX: number;
|
|
37
|
+
minY: number;
|
|
38
|
+
maxY: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* An edge with color assignment and bounding box
|
|
42
|
+
*/
|
|
43
|
+
export type MsdfEdge = ({
|
|
35
44
|
type: "line";
|
|
36
45
|
p0: Point;
|
|
37
46
|
p1: Point;
|
|
38
47
|
color: EdgeColor;
|
|
39
|
-
} | {
|
|
48
|
+
} & EdgeBounds) | ({
|
|
40
49
|
type: "quadratic";
|
|
41
50
|
p0: Point;
|
|
42
51
|
p1: Point;
|
|
43
52
|
p2: Point;
|
|
44
53
|
color: EdgeColor;
|
|
45
|
-
} | {
|
|
54
|
+
} & EdgeBounds) | ({
|
|
46
55
|
type: "cubic";
|
|
47
56
|
p0: Point;
|
|
48
57
|
p1: Point;
|
|
49
58
|
p2: Point;
|
|
50
59
|
p3: Point;
|
|
51
60
|
color: EdgeColor;
|
|
52
|
-
};
|
|
61
|
+
} & EdgeBounds);
|
|
53
62
|
/**
|
|
54
63
|
* Signed distance result with parameter t
|
|
55
64
|
*/
|
|
@@ -123,3 +132,4 @@ export declare function msdfAtlasToRGB(atlas: GlyphAtlas): Uint8Array;
|
|
|
123
132
|
* Export MSDF atlas as RGBA texture data
|
|
124
133
|
*/
|
|
125
134
|
export declare function msdfAtlasToRGBA(atlas: GlyphAtlas): Uint8Array;
|
|
135
|
+
export {};
|
|
@@ -22,28 +22,28 @@ export interface ValidationResult {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Validate a GlyphPath before rasterization (like FreeType's outline validation)
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* - Path is not empty (unless allowEmpty is true)
|
|
30
|
-
* - Command structure is valid
|
|
31
|
-
* - Contours are properly closed (start with M, end with Z)
|
|
25
|
+
* Checks: path existence, command structure validity, and proper contour closure
|
|
26
|
+
* @param path Glyph path to validate
|
|
27
|
+
* @param allowEmpty Whether empty paths are considered valid (default: true)
|
|
28
|
+
* @returns Validation result with error code and optional message
|
|
32
29
|
*/
|
|
33
30
|
export declare function validateOutline(path: GlyphPath | null | undefined, allowEmpty?: boolean): ValidationResult;
|
|
34
31
|
/**
|
|
35
32
|
* Convert a GlyphPath to rasterizer commands
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @param flipY - Flip Y axis (font coords are Y-up)
|
|
33
|
+
* @param raster The rasterizer instance to receive commands
|
|
34
|
+
* @param path Path commands to decompose
|
|
35
|
+
* @param scale Scale factor (font units to pixels)
|
|
36
|
+
* @param offsetX X offset in pixels (default: 0)
|
|
37
|
+
* @param offsetY Y offset in pixels (default: 0)
|
|
38
|
+
* @param flipY Flip Y axis - font coords are Y-up, bitmap is Y-down (default: true)
|
|
43
39
|
*/
|
|
44
40
|
export declare function decomposePath(raster: GrayRaster, path: GlyphPath, scale: number, offsetX?: number, offsetY?: number, flipY?: boolean): void;
|
|
45
41
|
/**
|
|
46
42
|
* Calculate bounding box of path in pixel coordinates
|
|
43
|
+
* @param path Glyph path to measure
|
|
44
|
+
* @param scale Scale factor (font units to pixels)
|
|
45
|
+
* @param flipY Flip Y axis for bitmap coordinates (default: true)
|
|
46
|
+
* @returns Bounding box in pixel coordinates, or null if path has no bounds
|
|
47
47
|
*/
|
|
48
48
|
export declare function getPathBounds(path: GlyphPath, scale: number, flipY?: boolean): {
|
|
49
49
|
minX: number;
|
|
@@ -53,9 +53,8 @@ export declare function getPathBounds(path: GlyphPath, scale: number, flipY?: bo
|
|
|
53
53
|
} | null;
|
|
54
54
|
/**
|
|
55
55
|
* Get fill rule from outline flags (like FreeType's FT_OUTLINE_EVEN_ODD_FILL check)
|
|
56
|
-
*
|
|
57
56
|
* @param path Path with optional flags
|
|
58
|
-
* @param defaultRule Default fill rule if flags not set
|
|
59
|
-
* @returns Fill rule to use
|
|
57
|
+
* @param defaultRule Default fill rule if flags not set (default: NonZero)
|
|
58
|
+
* @returns Fill rule to use for rendering
|
|
60
59
|
*/
|
|
61
60
|
export declare function getFillRuleFromFlags(path: GlyphPath | null | undefined, defaultRule?: FillRule): FillRule;
|
|
@@ -7,10 +7,18 @@ import type { GlyphId } from "../types.ts";
|
|
|
7
7
|
import { type Bitmap, PixelMode, type RasterizedGlyph, type RasterizeOptions } from "./types.ts";
|
|
8
8
|
/**
|
|
9
9
|
* Rasterize a glyph path to a bitmap
|
|
10
|
+
* @param path Glyph path to rasterize
|
|
11
|
+
* @param options Rasterization options including dimensions, scale, and pixel mode
|
|
12
|
+
* @returns Rendered bitmap of the glyph
|
|
10
13
|
*/
|
|
11
14
|
export declare function rasterizePath(path: GlyphPath, options: RasterizeOptions): Bitmap;
|
|
12
15
|
/**
|
|
13
16
|
* Rasterize a glyph from a font
|
|
17
|
+
* @param font Font containing the glyph
|
|
18
|
+
* @param glyphId ID of the glyph to rasterize
|
|
19
|
+
* @param fontSize Font size in pixels
|
|
20
|
+
* @param options Optional rendering settings (pixel mode, padding, hinting)
|
|
21
|
+
* @returns Rasterized glyph with bitmap and bearing information, or null if glyph is empty
|
|
14
22
|
*/
|
|
15
23
|
export declare function rasterizeGlyph(font: Font, glyphId: GlyphId, fontSize: number, options?: {
|
|
16
24
|
pixelMode?: PixelMode;
|
|
@@ -20,6 +28,11 @@ export declare function rasterizeGlyph(font: Font, glyphId: GlyphId, fontSize: n
|
|
|
20
28
|
}): RasterizedGlyph | null;
|
|
21
29
|
/**
|
|
22
30
|
* Rasterize text string using shaped glyphs
|
|
31
|
+
* @param font Font to use for rendering
|
|
32
|
+
* @param text Text string to rasterize
|
|
33
|
+
* @param fontSize Font size in pixels
|
|
34
|
+
* @param options Optional rendering settings (pixel mode, padding)
|
|
35
|
+
* @returns Bitmap containing rendered text, or null if no glyphs
|
|
23
36
|
*/
|
|
24
37
|
export declare function rasterizeText(font: Font, text: string, fontSize: number, options?: {
|
|
25
38
|
pixelMode?: PixelMode;
|
|
@@ -27,17 +40,21 @@ export declare function rasterizeText(font: Font, text: string, fontSize: number
|
|
|
27
40
|
}): Bitmap | null;
|
|
28
41
|
/**
|
|
29
42
|
* Export bitmap to raw RGBA pixels (for WebGL textures, etc.)
|
|
43
|
+
* @param bitmap Source bitmap to convert
|
|
44
|
+
* @returns RGBA pixel array (4 bytes per pixel)
|
|
30
45
|
*/
|
|
31
46
|
export declare function bitmapToRGBA(bitmap: Bitmap): Uint8Array;
|
|
32
47
|
/**
|
|
33
48
|
* Export bitmap to grayscale array
|
|
49
|
+
* @param bitmap Source bitmap to convert
|
|
50
|
+
* @returns Grayscale pixel array (1 byte per pixel)
|
|
34
51
|
*/
|
|
35
52
|
export declare function bitmapToGray(bitmap: Bitmap): Uint8Array;
|
|
36
53
|
export { type BBox, evaluateCubic, evaluateQuadratic, getCubicExtrema, getExactBounds, getQuadraticExtrema, } from "./bbox.ts";
|
|
37
|
-
export { blendBitmap, convertBitmap, copyBitmap, emboldenBitmap, resizeBitmap, } from "./bitmap-utils.ts";
|
|
54
|
+
export { blendBitmap, convertBitmap, copyBitmap, emboldenBitmap, resizeBitmap, resizeBitmapBilinear, } from "./bitmap-utils.ts";
|
|
38
55
|
export { blurBitmap, boxBlur, createGaussianKernel, gaussianBlur, } from "./blur.ts";
|
|
39
56
|
export { type ColorStop, createGradientBitmap, type Gradient, interpolateGradient, type LinearGradient, type RadialGradient, rasterizePathWithGradient, } from "./gradient.ts";
|
|
40
57
|
export { renderSdf, type SdfOptions } from "./sdf.ts";
|
|
41
58
|
export { type LineCap, type LineJoin, type StrokerOptions, strokePath, } from "./stroker.ts";
|
|
42
59
|
export { condensePath, emboldenPath, obliquePath, transformPath, } from "./synth.ts";
|
|
43
|
-
export { type Bitmap, clearBitmap, createBitmap, FillRule, PixelMode, type RasterizedGlyph, type RasterizeOptions, type Span, } from "./types.ts";
|
|
60
|
+
export { type Bitmap, clearBitmap, createBitmap, createBottomUpBitmap, FillRule, PixelMode, type RasterizedGlyph, type RasterizeOptions, type Span, } from "./types.ts";
|
package/dist/raster/sdf.d.ts
CHANGED
|
@@ -33,5 +33,8 @@ export interface SdfOptions {
|
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Render a glyph path as a signed distance field
|
|
36
|
+
* @param path Glyph path to render
|
|
37
|
+
* @param options SDF rendering options (dimensions, scale, spread)
|
|
38
|
+
* @returns Grayscale bitmap with signed distance field (128 = on edge, 255 = inside, 0 = outside)
|
|
36
39
|
*/
|
|
37
40
|
export declare function renderSdf(path: GlyphPath, options: SdfOptions): Bitmap;
|
package/dist/raster/stroker.d.ts
CHANGED
|
@@ -25,5 +25,8 @@ export interface StrokerOptions {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Stroke a glyph path, producing a new path that represents the stroked outline
|
|
28
|
+
* @param path Input glyph path to stroke
|
|
29
|
+
* @param options Stroke parameters (width, cap style, join style, miter limit)
|
|
30
|
+
* @returns New path representing the stroked outline that can be filled
|
|
28
31
|
*/
|
|
29
32
|
export declare function strokePath(path: GlyphPath, options: StrokerOptions): GlyphPath;
|
package/dist/raster/types.d.ts
CHANGED
|
@@ -177,15 +177,24 @@ export interface MsdfAtlasOptions {
|
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* Create an empty bitmap
|
|
180
|
+
* @param width Width in pixels
|
|
181
|
+
* @param height Height in pixels
|
|
182
|
+
* @param pixelMode Pixel format (default: Gray)
|
|
183
|
+
* @returns Empty bitmap with the specified dimensions and format
|
|
180
184
|
*/
|
|
181
185
|
export declare function createBitmap(width: number, height: number, pixelMode?: PixelMode): Bitmap;
|
|
182
186
|
/**
|
|
183
187
|
* Clear a bitmap to zero
|
|
188
|
+
* @param bitmap Bitmap to clear
|
|
184
189
|
*/
|
|
185
190
|
export declare function clearBitmap(bitmap: Bitmap): void;
|
|
186
191
|
/**
|
|
187
192
|
* Create a bottom-up bitmap (negative pitch)
|
|
188
193
|
* Bottom-up bitmaps have row 0 at the bottom of the image,
|
|
189
194
|
* which matches some graphics APIs (e.g., Windows DIB, OpenGL textures)
|
|
195
|
+
* @param width Width in pixels
|
|
196
|
+
* @param height Height in pixels
|
|
197
|
+
* @param pixelMode Pixel format (default: Gray)
|
|
198
|
+
* @returns Bottom-up bitmap with row 0 at the bottom
|
|
190
199
|
*/
|
|
191
200
|
export declare function createBottomUpBitmap(width: number, height: number, pixelMode?: PixelMode): Bitmap;
|
package/dist/render/path.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { GlyphBuffer } from "../buffer/glyph-buffer.ts";
|
|
|
2
2
|
import type { Font } from "../font/font.ts";
|
|
3
3
|
import type { Contour } from "../font/tables/glyf.ts";
|
|
4
4
|
import type { GlyphId } from "../types.ts";
|
|
5
|
+
import { type Matrix2D, type Matrix3x3 } from "./outline-transform.ts";
|
|
5
6
|
/**
|
|
6
7
|
* Path command types for glyph rendering
|
|
7
8
|
*/
|
|
@@ -63,11 +64,12 @@ export interface GlyphPath {
|
|
|
63
64
|
*/
|
|
64
65
|
export declare function contourToPath(contour: Contour): PathCommand[];
|
|
65
66
|
/**
|
|
66
|
-
* Get path
|
|
67
|
+
* Get cached glyph path, computing and caching if not already cached
|
|
67
68
|
*/
|
|
68
69
|
export declare function getGlyphPath(font: Font, glyphId: GlyphId): GlyphPath | null;
|
|
69
70
|
/**
|
|
70
71
|
* Convert path commands to SVG path data string
|
|
72
|
+
* Uses Math.round for ~40% faster string generation
|
|
71
73
|
*/
|
|
72
74
|
export declare function pathToSVG(path: GlyphPath, options?: {
|
|
73
75
|
flipY?: boolean;
|
|
@@ -125,6 +127,10 @@ export declare function renderShapedText(ctx: CanvasRenderingContext2D, font: Fo
|
|
|
125
127
|
strokeWidth?: number;
|
|
126
128
|
lineCap?: CanvasLineCap;
|
|
127
129
|
lineJoin?: CanvasLineJoin;
|
|
130
|
+
/** 2D affine matrix to apply to glyph coordinates */
|
|
131
|
+
matrix?: Matrix2D;
|
|
132
|
+
/** 3D perspective matrix to apply to glyph coordinates (takes precedence over matrix) */
|
|
133
|
+
matrix3D?: Matrix3x3;
|
|
128
134
|
}): void;
|
|
129
135
|
/**
|
|
130
136
|
* Generate SVG for shaped text
|
|
@@ -136,6 +142,12 @@ export declare function shapedTextToSVG(font: Font, glyphs: ShapedGlyph[], optio
|
|
|
136
142
|
strokeWidth?: number;
|
|
137
143
|
lineCap?: "butt" | "round" | "square";
|
|
138
144
|
lineJoin?: "miter" | "round" | "bevel";
|
|
145
|
+
/** 2D affine matrix to apply to glyph coordinates */
|
|
146
|
+
matrix?: Matrix2D;
|
|
147
|
+
/** 3D perspective matrix to apply to glyph coordinates (takes precedence over matrix) */
|
|
148
|
+
matrix3D?: Matrix3x3;
|
|
149
|
+
/** If true, use native SVG transform attribute instead of transforming path data (2D only) */
|
|
150
|
+
useNativeTransform?: boolean;
|
|
139
151
|
}): string;
|
|
140
152
|
/**
|
|
141
153
|
* Convert GlyphBuffer output to ShapedGlyph array
|
|
@@ -182,3 +194,46 @@ export declare function createPath2D(path: GlyphPath, options?: {
|
|
|
182
194
|
offsetX?: number;
|
|
183
195
|
offsetY?: number;
|
|
184
196
|
}): Path2D;
|
|
197
|
+
/**
|
|
198
|
+
* Render path to canvas with 2D affine matrix transformation applied to coordinates
|
|
199
|
+
* The matrix transforms each point before drawing
|
|
200
|
+
*/
|
|
201
|
+
export declare function pathToCanvasWithMatrix(ctx: CanvasRenderingContext2D | Path2D, path: GlyphPath, matrix: Matrix2D, options?: {
|
|
202
|
+
flipY?: boolean;
|
|
203
|
+
}): void;
|
|
204
|
+
/**
|
|
205
|
+
* Convert path to SVG with 2D affine matrix transformation applied to coordinates
|
|
206
|
+
*/
|
|
207
|
+
export declare function pathToSVGWithMatrix(path: GlyphPath, matrix: Matrix2D, options?: {
|
|
208
|
+
flipY?: boolean;
|
|
209
|
+
}): string;
|
|
210
|
+
/**
|
|
211
|
+
* Render path to canvas with 3D perspective matrix transformation
|
|
212
|
+
* Uses homogeneous coordinates for perspective projection
|
|
213
|
+
*/
|
|
214
|
+
export declare function pathToCanvasWithMatrix3D(ctx: CanvasRenderingContext2D | Path2D, path: GlyphPath, matrix: Matrix3x3, options?: {
|
|
215
|
+
flipY?: boolean;
|
|
216
|
+
}): void;
|
|
217
|
+
/**
|
|
218
|
+
* Convert path to SVG with 3D perspective matrix transformation
|
|
219
|
+
* Uses homogeneous coordinates for perspective projection
|
|
220
|
+
*/
|
|
221
|
+
export declare function pathToSVGWithMatrix3D(path: GlyphPath, matrix: Matrix3x3, options?: {
|
|
222
|
+
flipY?: boolean;
|
|
223
|
+
}): string;
|
|
224
|
+
/**
|
|
225
|
+
* Apply 2D affine matrix to canvas context using native transform
|
|
226
|
+
* Use ctx.save() before and ctx.restore() after to preserve context state
|
|
227
|
+
*/
|
|
228
|
+
export declare function applyMatrixToContext(ctx: CanvasRenderingContext2D, matrix: Matrix2D): void;
|
|
229
|
+
/**
|
|
230
|
+
* Convert 2D affine matrix to SVG transform attribute string
|
|
231
|
+
* Returns a string like "matrix(a, b, c, d, tx, ty)"
|
|
232
|
+
*/
|
|
233
|
+
export declare function matrixToSVGTransform(matrix: Matrix2D): string;
|
|
234
|
+
/**
|
|
235
|
+
* Direct SVG serialization with transform applied in single pass
|
|
236
|
+
* Avoids creating intermediate PathCommand arrays
|
|
237
|
+
* Uses Math.round for ~40% faster string generation
|
|
238
|
+
*/
|
|
239
|
+
export declare function pathToSVGDirect(path: GlyphPath, scale: number, offsetX: number, offsetY: number): string;
|
|
@@ -56,5 +56,6 @@ export declare function analyzeJoining(infos: GlyphInfo[]): JoiningAction[];
|
|
|
56
56
|
export declare function getFeatureForAction(action: JoiningAction): string | null;
|
|
57
57
|
/**
|
|
58
58
|
* Set the feature mask for each glyph based on joining analysis
|
|
59
|
+
* Inlined for performance - avoids intermediate array allocation
|
|
59
60
|
*/
|
|
60
61
|
export declare function setupArabicMasks(infos: GlyphInfo[]): void;
|
|
@@ -7,21 +7,24 @@ export interface ShapeFeature {
|
|
|
7
7
|
tag: Tag;
|
|
8
8
|
enabled: boolean;
|
|
9
9
|
}
|
|
10
|
+
/** Lookup entry with index */
|
|
11
|
+
export interface LookupEntry<T> {
|
|
12
|
+
index: number;
|
|
13
|
+
lookup: T;
|
|
14
|
+
}
|
|
10
15
|
/** Collected lookups for shaping */
|
|
11
16
|
export interface ShapePlan {
|
|
12
17
|
script: Tag;
|
|
13
18
|
language: Tag | null;
|
|
14
19
|
direction: "ltr" | "rtl";
|
|
15
20
|
/** GSUB lookups to apply, in order */
|
|
16
|
-
gsubLookups:
|
|
17
|
-
index: number;
|
|
18
|
-
lookup: AnyGsubLookup;
|
|
19
|
-
}>;
|
|
21
|
+
gsubLookups: LookupEntry<AnyGsubLookup>[];
|
|
20
22
|
/** GPOS lookups to apply, in order */
|
|
21
|
-
gposLookups:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
gposLookups: LookupEntry<AnyGposLookup>[];
|
|
24
|
+
/** Fast O(1) lookup by index for nested GSUB lookups */
|
|
25
|
+
gsubLookupMap: Map<number, LookupEntry<AnyGsubLookup>>;
|
|
26
|
+
/** Fast O(1) lookup by index for nested GPOS lookups */
|
|
27
|
+
gposLookupMap: Map<number, LookupEntry<AnyGposLookup>>;
|
|
25
28
|
}
|
|
26
29
|
/** Get or create a cached shape plan */
|
|
27
30
|
export declare function getOrCreateShapePlan(font: Font, script: string, language: string | null, direction: "ltr" | "rtl", userFeatures?: ShapeFeature[], axisCoords?: number[] | null): ShapePlan;
|
package/dist/shaper/shaper.d.ts
CHANGED
|
@@ -3,16 +3,74 @@ import type { UnicodeBuffer } from "../buffer/unicode-buffer.ts";
|
|
|
3
3
|
import { Face } from "../font/face.ts";
|
|
4
4
|
import type { Font } from "../font/font.ts";
|
|
5
5
|
import { type ShapeFeature } from "./shape-plan.ts";
|
|
6
|
+
/**
|
|
7
|
+
* Options for controlling text shaping behavior.
|
|
8
|
+
*/
|
|
6
9
|
export interface ShapeOptions {
|
|
10
|
+
/** ISO 15924 script tag (e.g., "arab", "deva", "latn"). Defaults to buffer.script or "latn" */
|
|
7
11
|
script?: string;
|
|
12
|
+
/** BCP 47 language tag (e.g., "en", "ar-SA", "hi-IN"). Defaults to buffer.language or null */
|
|
8
13
|
language?: string | null;
|
|
14
|
+
/** Text direction: "ltr" (left-to-right) or "rtl" (right-to-left). Defaults to "ltr" */
|
|
9
15
|
direction?: "ltr" | "rtl";
|
|
16
|
+
/** Array of OpenType features to apply (e.g., [{tag: "liga", value: 1}, {tag: "kern", value: 0}]) */
|
|
10
17
|
features?: ShapeFeature[];
|
|
11
18
|
}
|
|
12
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Union type accepting either Font or Face instances.
|
|
21
|
+
* Use Face for variable fonts to provide axis coordinates for feature variations.
|
|
22
|
+
* Use Font for static fonts or when default axis values are acceptable.
|
|
23
|
+
*/
|
|
13
24
|
export type FontLike = Font | Face;
|
|
14
25
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
26
|
+
* Return a GlyphBuffer to the pool for reuse.
|
|
27
|
+
* Call this when done with a buffer from shape() to reduce allocations.
|
|
28
|
+
* The pool has a maximum size, so buffers beyond that limit will be discarded.
|
|
29
|
+
*
|
|
30
|
+
* @param buffer - The GlyphBuffer to return to the pool
|
|
31
|
+
*/
|
|
32
|
+
export declare function releaseBuffer(buffer: GlyphBuffer): void;
|
|
33
|
+
/**
|
|
34
|
+
* Shape text using OpenType features and complex script processing.
|
|
35
|
+
*
|
|
36
|
+
* Text shaping is the process of converting Unicode text into positioned glyphs for rendering.
|
|
37
|
+
* This involves:
|
|
38
|
+
* - Mapping characters to glyphs via the font's cmap table
|
|
39
|
+
* - Applying OpenType GSUB substitutions (ligatures, contextual forms, etc.)
|
|
40
|
+
* - Positioning glyphs via GPOS or fallback kerning/mark positioning
|
|
41
|
+
* - Complex script analysis (Arabic joining, Indic reordering, etc.)
|
|
42
|
+
* - Applying OpenType features (liga, kern, calt, etc.)
|
|
43
|
+
*
|
|
44
|
+
* The function returns a pooled GlyphBuffer for efficiency. Call releaseBuffer() when done
|
|
45
|
+
* to return it to the pool for reuse.
|
|
46
|
+
*
|
|
47
|
+
* @param fontLike - Font or Face instance (Face for variable fonts with axis coordinates)
|
|
48
|
+
* @param buffer - UnicodeBuffer containing the input text and metadata (script, language, direction)
|
|
49
|
+
* @param options - Optional shaping parameters
|
|
50
|
+
* @param options.script - ISO 15924 script tag (e.g., "arab", "deva"), defaults to buffer.script or "latn"
|
|
51
|
+
* @param options.language - BCP 47 language tag (e.g., "en", "ar-SA"), defaults to buffer.language or null
|
|
52
|
+
* @param options.direction - Text direction "ltr" or "rtl", defaults to "ltr"
|
|
53
|
+
* @param options.features - Array of OpenType features to enable/disable (e.g., [{tag: "liga", value: 1}])
|
|
54
|
+
* @returns GlyphBuffer containing shaped glyphs with positions and metadata
|
|
17
55
|
*/
|
|
18
56
|
export declare function shape(fontLike: FontLike, buffer: UnicodeBuffer, options?: ShapeOptions): GlyphBuffer;
|
|
57
|
+
/**
|
|
58
|
+
* Shape text into an existing GlyphBuffer (zero-allocation hot path).
|
|
59
|
+
*
|
|
60
|
+
* This is a performance-optimized version of shape() that reuses an existing GlyphBuffer
|
|
61
|
+
* instead of allocating a new one. Use this for maximum performance when shaping repeatedly,
|
|
62
|
+
* such as in animation loops or batch text processing.
|
|
63
|
+
*
|
|
64
|
+
* The provided GlyphBuffer will be reset and filled with the shaped output. This avoids
|
|
65
|
+
* allocations from the buffer pool and gives you full control over buffer lifecycle.
|
|
66
|
+
*
|
|
67
|
+
* @param fontLike - Font or Face instance (Face for variable fonts with axis coordinates)
|
|
68
|
+
* @param buffer - UnicodeBuffer containing the input text and metadata (script, language, direction)
|
|
69
|
+
* @param glyphBuffer - Existing GlyphBuffer to fill with shaped output (will be reset)
|
|
70
|
+
* @param options - Optional shaping parameters
|
|
71
|
+
* @param options.script - ISO 15924 script tag (e.g., "arab", "deva"), defaults to buffer.script or "latn"
|
|
72
|
+
* @param options.language - BCP 47 language tag (e.g., "en", "ar-SA"), defaults to buffer.language or null
|
|
73
|
+
* @param options.direction - Text direction "ltr" or "rtl", defaults to "ltr"
|
|
74
|
+
* @param options.features - Array of OpenType features to enable/disable (e.g., [{tag: "liga", value: 1}])
|
|
75
|
+
*/
|
|
76
|
+
export declare function shapeInto(fontLike: FontLike, buffer: UnicodeBuffer, glyphBuffer: GlyphBuffer, options?: ShapeOptions): void;
|
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
* Bidi bracket pair functions
|
|
3
3
|
* Port of bidi-js brackets.js
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get the closing bracket character for an opening bracket
|
|
7
|
+
* @param char Opening bracket character
|
|
8
|
+
* @returns Corresponding closing bracket character, or null if not an opening bracket
|
|
9
|
+
*/
|
|
5
10
|
export declare function openingToClosingBracket(char: string): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Get the opening bracket character for a closing bracket
|
|
13
|
+
* @param char Closing bracket character
|
|
14
|
+
* @returns Corresponding opening bracket character, or null if not a closing bracket
|
|
15
|
+
*/
|
|
6
16
|
export declare function closingToOpeningBracket(char: string): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Get the canonical bracket character for a bracket
|
|
19
|
+
* @param char Bracket character
|
|
20
|
+
* @returns Canonical form of the bracket character, or null if not applicable
|
|
21
|
+
*/
|
|
7
22
|
export declare function getCanonicalBracket(char: string): string | null;
|
|
@@ -11,9 +11,13 @@ export declare const BN_LIKE_TYPES: number;
|
|
|
11
11
|
export declare const TRAILING_TYPES: number;
|
|
12
12
|
/**
|
|
13
13
|
* Get the bidi character type for a character
|
|
14
|
+
* @param char Character to check
|
|
15
|
+
* @returns Bidi character type as a bitmask
|
|
14
16
|
*/
|
|
15
17
|
export declare function getBidiCharType(char: string): number;
|
|
16
18
|
/**
|
|
17
19
|
* Get the name of a bidi character type
|
|
20
|
+
* @param char Character to check
|
|
21
|
+
* @returns Bidi character type name (e.g., "L", "R", "EN", "AN", etc.)
|
|
18
22
|
*/
|
|
19
23
|
export declare function getBidiCharTypeName(char: string): string;
|
|
@@ -14,5 +14,8 @@ export interface EmbeddingLevelsResult {
|
|
|
14
14
|
* This function applies the Bidirectional Algorithm to a string, returning the resolved embedding levels
|
|
15
15
|
* in a single Uint8Array plus a list of objects holding each paragraph's start and end indices and resolved
|
|
16
16
|
* base embedding level.
|
|
17
|
+
* @param string Text string to process
|
|
18
|
+
* @param baseDirection Base text direction: "ltr", "rtl", or "auto"
|
|
19
|
+
* @returns Object containing embedding levels array and paragraph information
|
|
17
20
|
*/
|
|
18
21
|
export declare function getEmbeddingLevels(string: string, baseDirection?: "ltr" | "rtl" | "auto"): EmbeddingLevelsResult;
|
|
@@ -2,9 +2,19 @@
|
|
|
2
2
|
* Bidi character mirroring
|
|
3
3
|
* Port of bidi-js mirroring.js
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get the mirrored version of a character for BiDi display
|
|
7
|
+
* @param char Character to mirror
|
|
8
|
+
* @returns Mirrored character, or null if character has no mirror
|
|
9
|
+
*/
|
|
5
10
|
export declare function getMirroredCharacter(char: string): string | null;
|
|
6
11
|
/**
|
|
7
12
|
* Given a string and its resolved embedding levels, build a map of indices to replacement chars
|
|
8
13
|
* for any characters in right-to-left segments that have defined mirrored characters.
|
|
14
|
+
* @param string Text string to process
|
|
15
|
+
* @param embeddingLevels Resolved embedding levels from getEmbeddingLevels
|
|
16
|
+
* @param start Start index (defaults to 0)
|
|
17
|
+
* @param end End index (defaults to string length - 1)
|
|
18
|
+
* @returns Map of character indices to their mirrored replacements
|
|
9
19
|
*/
|
|
10
20
|
export declare function getMirroredCharactersMap(string: string, embeddingLevels: Uint8Array, start?: number, end?: number): Map<number, string>;
|
|
@@ -6,13 +6,28 @@ import type { EmbeddingLevelsResult } from "./embedding-levels.ts";
|
|
|
6
6
|
/**
|
|
7
7
|
* Given a start and end denoting a single line within a string, and a set of precalculated
|
|
8
8
|
* bidi embedding levels, produce a list of segments whose ordering should be flipped, in sequence.
|
|
9
|
+
* @param string Text string to process
|
|
10
|
+
* @param embeddingLevelsResult Result from getEmbeddingLevels
|
|
11
|
+
* @param start Start index (defaults to 0)
|
|
12
|
+
* @param end End index (defaults to string length - 1)
|
|
13
|
+
* @returns Array of segment ranges [start, end] to be reversed
|
|
9
14
|
*/
|
|
10
15
|
export declare function getReorderSegments(string: string, embeddingLevelsResult: EmbeddingLevelsResult, start?: number, end?: number): Array<[number, number]>;
|
|
11
16
|
/**
|
|
12
17
|
* Get the reordered string with bidi segments reversed
|
|
18
|
+
* @param string Text string to reorder
|
|
19
|
+
* @param embedLevelsResult Result from getEmbeddingLevels
|
|
20
|
+
* @param start Start index (defaults to 0)
|
|
21
|
+
* @param end End index (defaults to string length - 1)
|
|
22
|
+
* @returns Reordered string with BiDi applied
|
|
13
23
|
*/
|
|
14
24
|
export declare function getReorderedString(string: string, embedLevelsResult: EmbeddingLevelsResult, start?: number, end?: number): string;
|
|
15
25
|
/**
|
|
16
26
|
* Get an array with character indices in their new bidi order
|
|
27
|
+
* @param string Text string to process
|
|
28
|
+
* @param embedLevelsResult Result from getEmbeddingLevels
|
|
29
|
+
* @param start Start index (defaults to 0)
|
|
30
|
+
* @param end End index (defaults to string length - 1)
|
|
31
|
+
* @returns Array mapping new positions to original character indices
|
|
17
32
|
*/
|
|
18
33
|
export declare function getReorderedIndices(string: string, embedLevelsResult: EmbeddingLevelsResult, start?: number, end?: number): number[];
|
|
@@ -15,22 +15,45 @@ export declare enum NormalizationMode {
|
|
|
15
15
|
/**
|
|
16
16
|
* Canonical Combining Class (ccc) for combining marks
|
|
17
17
|
* Based on Unicode 15.0
|
|
18
|
+
*
|
|
19
|
+
* Optimized with early-exit for common non-combining ranges:
|
|
20
|
+
* - Basic Latin (0000-007F)
|
|
21
|
+
* - Latin-1 Supplement (0080-00FF)
|
|
22
|
+
* - Latin Extended-A/B (0100-024F)
|
|
23
|
+
* - IPA Extensions (0250-02AF)
|
|
24
|
+
* - Spacing Modifier Letters (02B0-02FF) - most are spacing
|
|
25
|
+
* - Greek and Coptic (0370-03FF) - base chars only
|
|
26
|
+
* - Cyrillic (0400-04FF)
|
|
27
|
+
* - Cyrillic Supplement (0500-052F)
|
|
28
|
+
* - CJK ranges (3000+)
|
|
29
|
+
* - Hangul (AC00-D7AF)
|
|
30
|
+
* @param cp Unicode codepoint to check
|
|
31
|
+
* @returns Canonical combining class (0 for non-combining characters, 1-255 for combining marks)
|
|
18
32
|
*/
|
|
19
33
|
export declare function getCombiningClass(cp: number): number;
|
|
20
34
|
/**
|
|
21
35
|
* Reorder combining marks according to canonical combining class
|
|
36
|
+
* @param infos Array of glyph information objects (modified in place)
|
|
22
37
|
*/
|
|
23
38
|
export declare function reorderMarks(infos: GlyphInfo[]): void;
|
|
24
39
|
/**
|
|
25
40
|
* Decompose a codepoint if it has a canonical decomposition
|
|
41
|
+
* @param cp Unicode codepoint to decompose
|
|
42
|
+
* @returns Array of decomposed codepoints, or null if character has no decomposition
|
|
26
43
|
*/
|
|
27
44
|
export declare function decompose(cp: number): number[] | null;
|
|
28
45
|
/**
|
|
29
46
|
* Try to compose a base character with a combining mark
|
|
30
47
|
* Returns the composed character or null if no composition exists
|
|
48
|
+
* @param base Base character codepoint
|
|
49
|
+
* @param combining Combining mark codepoint
|
|
50
|
+
* @returns Composed character codepoint, or null if no composition exists
|
|
31
51
|
*/
|
|
32
52
|
export declare function tryCompose(base: number, combining: number): number | null;
|
|
33
53
|
/**
|
|
34
54
|
* Apply normalization to glyph infos
|
|
55
|
+
* @param infos Array of glyph information objects
|
|
56
|
+
* @param mode Normalization mode (None, Decompose, Compose, or Auto)
|
|
57
|
+
* @returns Normalized array of glyph information objects
|
|
35
58
|
*/
|
|
36
59
|
export declare function normalize(infos: GlyphInfo[], mode: NormalizationMode): GlyphInfo[];
|
package/dist/unicode/script.d.ts
CHANGED
|
@@ -173,19 +173,28 @@ export declare enum Script {
|
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
175
|
* Get script for a codepoint using binary search
|
|
176
|
+
* @param cp Unicode codepoint to check
|
|
177
|
+
* @returns The script for the given codepoint
|
|
176
178
|
*/
|
|
177
179
|
export declare function getScript(cp: number): Script;
|
|
178
180
|
/**
|
|
179
181
|
* Get script for a string (returns the dominant non-Common/Inherited script)
|
|
182
|
+
* @param text Text string to analyze
|
|
183
|
+
* @returns The dominant script found in the text (most frequent non-Common/Inherited script)
|
|
180
184
|
*/
|
|
181
185
|
export declare function detectScript(text: string): Script;
|
|
182
186
|
/**
|
|
183
187
|
* Get all scripts present in text
|
|
188
|
+
* @param text Text string to analyze
|
|
189
|
+
* @returns Array of all scripts found in the text
|
|
184
190
|
*/
|
|
185
191
|
export declare function getScripts(text: string): Script[];
|
|
186
192
|
/**
|
|
187
193
|
* Check if text contains only characters from a specific script
|
|
188
194
|
* (Common and Inherited are allowed)
|
|
195
|
+
* @param text Text string to check
|
|
196
|
+
* @param script Script to check against
|
|
197
|
+
* @returns True if text contains only characters from the specified script (plus Common/Inherited)
|
|
189
198
|
*/
|
|
190
199
|
export declare function isScript(text: string, script: Script): boolean;
|
|
191
200
|
/**
|
|
@@ -199,17 +208,25 @@ export interface ScriptRun {
|
|
|
199
208
|
}
|
|
200
209
|
/**
|
|
201
210
|
* Split text into script runs
|
|
211
|
+
* @param text Text string to split
|
|
212
|
+
* @returns Array of script runs, where each run is a contiguous sequence of characters with the same script
|
|
202
213
|
*/
|
|
203
214
|
export declare function getScriptRuns(text: string): ScriptRun[];
|
|
204
215
|
/**
|
|
205
216
|
* Get OpenType script tag for a Unicode script
|
|
217
|
+
* @param script Unicode script to convert
|
|
218
|
+
* @returns OpenType script tag (4-character string like "latn", "arab", etc.)
|
|
206
219
|
*/
|
|
207
220
|
export declare function getScriptTag(script: Script): string;
|
|
208
221
|
/**
|
|
209
222
|
* Check if a script requires complex shaping
|
|
223
|
+
* @param script Script to check
|
|
224
|
+
* @returns True if the script requires complex shaping (e.g., Arabic, Devanagari, Thai)
|
|
210
225
|
*/
|
|
211
226
|
export declare function isComplexScript(script: Script): boolean;
|
|
212
227
|
/**
|
|
213
228
|
* Get script direction (LTR or RTL)
|
|
229
|
+
* @param script Script to check
|
|
230
|
+
* @returns Direction of the script: "ltr" for left-to-right or "rtl" for right-to-left
|
|
214
231
|
*/
|
|
215
232
|
export declare function getScriptDirection(script: Script): "ltr" | "rtl";
|