text-shaper 0.1.1 → 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 +12 -5
- package/dist/index.js +12 -10
- package/dist/index.js.map +104 -93
- 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/perf/benchmark-runner-eksh2b26.js +0 -0
- package/dist/perf/benchmark-runner.html +517 -0
- package/dist/perf/comparison-tests.js +22676 -0
- package/dist/perf/comparison-tests.js.map +111 -0
- package/dist/perf/cpu/cpu-perf.js +21920 -0
- package/dist/perf/cpu/cpu-perf.js.map +108 -0
- package/dist/perf/gpu/webgl-perf.js +470 -0
- package/dist/perf/gpu/webgl-perf.js.map +11 -0
- package/dist/perf/gpu/webgpu-perf.js +442 -0
- package/dist/perf/gpu/webgpu-perf.js.map +11 -0
- package/dist/perf/index.html +258 -0
- package/dist/perf/module-loader.js +18 -0
- package/dist/perf/utils/perf-utils.js +170 -0
- package/dist/perf/utils/perf-utils.js.map +10 -0
- package/dist/raster/asymmetric-stroke.d.ts +61 -0
- package/dist/raster/bitmap-utils.d.ts +124 -0
- package/dist/raster/blur.d.ts +11 -0
- package/dist/raster/cascade-blur.d.ts +44 -0
- 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 +135 -0
- 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 +24 -0
- package/dist/render/outline-transform.d.ts +169 -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 +12 -3
package/README.md
CHANGED
|
@@ -12,23 +12,35 @@ export interface StateMachineContext {
|
|
|
12
12
|
stack: number[];
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Get class for a glyph
|
|
15
|
+
* Get the class value for a glyph from the class table
|
|
16
|
+
* @param classTable - The class lookup table
|
|
17
|
+
* @param glyphId - The glyph ID to look up
|
|
18
|
+
* @returns The class value, or CLASS_OUT_OF_BOUNDS if the glyph is not in the table
|
|
16
19
|
*/
|
|
17
20
|
export declare function getGlyphClass(classTable: ClassTable, glyphId: GlyphId): number;
|
|
18
21
|
/**
|
|
19
|
-
* Process rearrangement subtable
|
|
20
|
-
*
|
|
22
|
+
* Process rearrangement subtable to reorder glyphs based on state machine rules
|
|
23
|
+
* @param subtable - The rearrangement subtable containing state machine and rules
|
|
24
|
+
* @param infos - Array of glyph infos to be reordered in place
|
|
21
25
|
*/
|
|
22
26
|
export declare function processRearrangement(subtable: MorxRearrangementSubtable, infos: GlyphInfo[]): void;
|
|
23
27
|
/**
|
|
24
|
-
* Process contextual substitution subtable
|
|
28
|
+
* Process contextual substitution subtable to replace glyphs based on context
|
|
29
|
+
* @param subtable - The contextual subtable containing state machine and substitution tables
|
|
30
|
+
* @param infos - Array of glyph infos to be modified in place with contextual substitutions
|
|
25
31
|
*/
|
|
26
32
|
export declare function processContextual(subtable: MorxContextualSubtable, infos: GlyphInfo[]): void;
|
|
27
33
|
/**
|
|
28
|
-
* Process ligature subtable
|
|
34
|
+
* Process ligature subtable to combine multiple glyphs into ligatures
|
|
35
|
+
* @param subtable - The ligature subtable containing state machine, actions, and component tables
|
|
36
|
+
* @param infos - Array of glyph infos to process
|
|
37
|
+
* @returns New array of glyph infos with ligatures applied and component glyphs removed
|
|
29
38
|
*/
|
|
30
39
|
export declare function processLigature(subtable: MorxLigatureSubtable, infos: GlyphInfo[]): GlyphInfo[];
|
|
31
40
|
/**
|
|
32
|
-
* Process insertion subtable
|
|
41
|
+
* Process insertion subtable to insert additional glyphs before or after existing glyphs
|
|
42
|
+
* @param subtable - The insertion subtable containing state machine and insertion glyph table
|
|
43
|
+
* @param infos - Array of glyph infos to process
|
|
44
|
+
* @returns New array of glyph infos with inserted glyphs added at specified positions
|
|
33
45
|
*/
|
|
34
46
|
export declare function processInsertion(subtable: MorxInsertionSubtable, infos: GlyphInfo[]): GlyphInfo[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Font } from "../font/font.ts";
|
|
1
2
|
import { Direction, type GlyphId, type GlyphInfo, type GlyphPosition } from "../types.ts";
|
|
2
3
|
/**
|
|
3
4
|
* Output buffer containing shaped glyphs.
|
|
@@ -14,10 +15,29 @@ export declare class GlyphBuffer {
|
|
|
14
15
|
infos: GlyphInfo[];
|
|
15
16
|
/** Glyph position array */
|
|
16
17
|
positions: GlyphPosition[];
|
|
17
|
-
/**
|
|
18
|
+
/** Deleted glyph markers for deferred removal */
|
|
19
|
+
private _deleted;
|
|
20
|
+
/** Count of deleted glyphs pending compaction */
|
|
21
|
+
private _deletedCount;
|
|
22
|
+
/** Pre-allocated info pool for reuse */
|
|
23
|
+
private _infoPool;
|
|
24
|
+
/** Pre-allocated position pool for reuse */
|
|
25
|
+
private _posPool;
|
|
26
|
+
/** Create buffer with pre-allocated capacity (lazy object creation) */
|
|
18
27
|
static withCapacity(capacity: number): GlyphBuffer;
|
|
28
|
+
/** Hint for initial capacity (used for lazy allocation) */
|
|
29
|
+
private _capacity;
|
|
19
30
|
/** Number of glyphs */
|
|
20
31
|
get length(): number;
|
|
32
|
+
/** Reset buffer for reuse - reuses existing object pool */
|
|
33
|
+
reset(): void;
|
|
34
|
+
/** Initialize from codepoints, reusing pooled objects when possible */
|
|
35
|
+
initFromCodepoints(codepoints: ArrayLike<number>, clusters: ArrayLike<number>, getGlyphId: (codepoint: number) => number): void;
|
|
36
|
+
/**
|
|
37
|
+
* Initialize from codepoints with direct font access (no closure).
|
|
38
|
+
* This is faster than initFromCodepoints for hot paths.
|
|
39
|
+
*/
|
|
40
|
+
initFromCodepointsWithFont(codepoints: ArrayLike<number>, clusters: ArrayLike<number>, font: Font): void;
|
|
21
41
|
/** Initialize from glyph infos (positions zeroed) */
|
|
22
42
|
initFromInfos(infos: GlyphInfo[]): void;
|
|
23
43
|
/** Set advance width for a glyph */
|
|
@@ -30,6 +50,20 @@ export declare class GlyphBuffer {
|
|
|
30
50
|
insertGlyph(index: number, info: GlyphInfo, position: GlyphPosition): void;
|
|
31
51
|
/** Remove glyphs in range [start, end) */
|
|
32
52
|
removeRange(start: number, end: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Mark a glyph for deferred deletion. Much faster than removeRange for
|
|
55
|
+
* multiple deletions - call compact() once at end of GSUB phase.
|
|
56
|
+
*/
|
|
57
|
+
markDeleted(index: number): void;
|
|
58
|
+
/** Check if a glyph is marked for deletion */
|
|
59
|
+
isDeleted(index: number): boolean;
|
|
60
|
+
/** Returns true if there are pending deletions */
|
|
61
|
+
hasPendingDeletions(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Compact buffer by removing all marked-for-deletion glyphs in a single O(n) pass.
|
|
64
|
+
* Call this after GSUB phase.
|
|
65
|
+
*/
|
|
66
|
+
compact(): void;
|
|
33
67
|
/** Merge clusters from start to end (inclusive) */
|
|
34
68
|
mergeClusters(start: number, end: number): void;
|
|
35
69
|
/** Reverse glyph order (for RTL) */
|
|
@@ -19,6 +19,8 @@ export declare class UnicodeBuffer {
|
|
|
19
19
|
postContext: number[];
|
|
20
20
|
/** Add a string to the buffer */
|
|
21
21
|
addStr(text: string, startCluster?: number): this;
|
|
22
|
+
/** Append to existing buffer (slower path) */
|
|
23
|
+
private _addStrAppend;
|
|
22
24
|
/** Add codepoints directly */
|
|
23
25
|
addCodepoints(codepoints: number[], startCluster?: number): this;
|
|
24
26
|
/** Add a single codepoint */
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BitmapBuilder: Fluent builder for raster bitmap operations
|
|
3
|
+
*
|
|
4
|
+
* All operations are eager (applied immediately) and return new builder instances
|
|
5
|
+
*/
|
|
6
|
+
import { type Gradient } from "../raster/gradient.ts";
|
|
7
|
+
import { type Bitmap, PixelMode, type RasterizedGlyph } from "../raster/types.ts";
|
|
8
|
+
/**
|
|
9
|
+
* BitmapBuilder provides a fluent interface for bitmap manipulations
|
|
10
|
+
*/
|
|
11
|
+
export declare class BitmapBuilder {
|
|
12
|
+
private readonly _bitmap;
|
|
13
|
+
private readonly _bearingX;
|
|
14
|
+
private readonly _bearingY;
|
|
15
|
+
private constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Create from existing bitmap
|
|
18
|
+
*/
|
|
19
|
+
static fromBitmap(bitmap: Bitmap): BitmapBuilder;
|
|
20
|
+
/**
|
|
21
|
+
* Create from existing bitmap with bearing info
|
|
22
|
+
*/
|
|
23
|
+
static fromBitmapWithBearing(bitmap: Bitmap, bearingX: number, bearingY: number): BitmapBuilder;
|
|
24
|
+
/**
|
|
25
|
+
* Create from rasterized glyph result
|
|
26
|
+
*/
|
|
27
|
+
static fromRasterizedGlyph(glyph: RasterizedGlyph): BitmapBuilder;
|
|
28
|
+
/**
|
|
29
|
+
* Create empty bitmap
|
|
30
|
+
*/
|
|
31
|
+
static create(width: number, height: number, pixelMode?: PixelMode): BitmapBuilder;
|
|
32
|
+
/**
|
|
33
|
+
* Create gradient bitmap
|
|
34
|
+
*/
|
|
35
|
+
static fromGradient(width: number, height: number, gradient: Gradient): BitmapBuilder;
|
|
36
|
+
/**
|
|
37
|
+
* Gaussian blur
|
|
38
|
+
*/
|
|
39
|
+
blur(radius: number): BitmapBuilder;
|
|
40
|
+
/**
|
|
41
|
+
* Box blur (faster, less smooth)
|
|
42
|
+
*/
|
|
43
|
+
boxBlur(radius: number): BitmapBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* Cascade blur (fast for large radii, O(1) per pixel)
|
|
46
|
+
*/
|
|
47
|
+
cascadeBlur(radiusX: number, radiusY?: number): BitmapBuilder;
|
|
48
|
+
/**
|
|
49
|
+
* Adaptive blur (auto-selects best algorithm based on radius)
|
|
50
|
+
*/
|
|
51
|
+
adaptiveBlur(radiusX: number, radiusY?: number): BitmapBuilder;
|
|
52
|
+
/**
|
|
53
|
+
* Fast Gaussian blur using cascade algorithm
|
|
54
|
+
* Recommended for large radii (> 3 pixels)
|
|
55
|
+
*/
|
|
56
|
+
fastBlur(radius: number): BitmapBuilder;
|
|
57
|
+
/**
|
|
58
|
+
* Embolden (dilate) bitmap
|
|
59
|
+
*/
|
|
60
|
+
embolden(xStrength: number, yStrength?: number): BitmapBuilder;
|
|
61
|
+
/**
|
|
62
|
+
* Shift bitmap position
|
|
63
|
+
*/
|
|
64
|
+
shift(dx: number, dy: number): BitmapBuilder;
|
|
65
|
+
/**
|
|
66
|
+
* Resize with nearest-neighbor interpolation
|
|
67
|
+
*/
|
|
68
|
+
resize(width: number, height: number): BitmapBuilder;
|
|
69
|
+
/**
|
|
70
|
+
* Resize with bilinear interpolation (smoother, better for downsampling)
|
|
71
|
+
*/
|
|
72
|
+
resizeBilinear(width: number, height: number): BitmapBuilder;
|
|
73
|
+
/**
|
|
74
|
+
* Pad bitmap with empty space
|
|
75
|
+
*/
|
|
76
|
+
pad(left: number, top: number, right: number, bottom: number): BitmapBuilder;
|
|
77
|
+
pad(all: number): BitmapBuilder;
|
|
78
|
+
/**
|
|
79
|
+
* Alpha blend another bitmap onto this one at position
|
|
80
|
+
*/
|
|
81
|
+
blend(other: BitmapBuilder | Bitmap, x: number, y: number, opacity?: number): BitmapBuilder;
|
|
82
|
+
/**
|
|
83
|
+
* Composite another bitmap using Porter-Duff "over" operation
|
|
84
|
+
*/
|
|
85
|
+
composite(other: BitmapBuilder | Bitmap, x?: number, y?: number): BitmapBuilder;
|
|
86
|
+
/**
|
|
87
|
+
* Additive blend: result = clamp(this + other, 0, 255)
|
|
88
|
+
*/
|
|
89
|
+
add(other: BitmapBuilder | Bitmap, x?: number, y?: number): BitmapBuilder;
|
|
90
|
+
/**
|
|
91
|
+
* Subtractive blend: result = clamp(this - other, 0, 255)
|
|
92
|
+
*/
|
|
93
|
+
subtract(other: BitmapBuilder | Bitmap, x?: number, y?: number): BitmapBuilder;
|
|
94
|
+
/**
|
|
95
|
+
* Multiplicative blend: result = (this * other) / 255
|
|
96
|
+
*/
|
|
97
|
+
multiply(other: BitmapBuilder | Bitmap, x?: number, y?: number): BitmapBuilder;
|
|
98
|
+
/**
|
|
99
|
+
* Maximum blend: result = max(this, other)
|
|
100
|
+
*/
|
|
101
|
+
max(other: BitmapBuilder | Bitmap, x?: number, y?: number): BitmapBuilder;
|
|
102
|
+
/**
|
|
103
|
+
* Convert to different pixel mode
|
|
104
|
+
*/
|
|
105
|
+
convert(targetMode: PixelMode): BitmapBuilder;
|
|
106
|
+
/**
|
|
107
|
+
* Get RGBA pixel array (for canvas ImageData, WebGL textures)
|
|
108
|
+
*/
|
|
109
|
+
toRGBA(): Uint8Array;
|
|
110
|
+
/**
|
|
111
|
+
* Get grayscale array
|
|
112
|
+
*/
|
|
113
|
+
toGray(): Uint8Array;
|
|
114
|
+
/**
|
|
115
|
+
* Get raw bitmap (cloned)
|
|
116
|
+
*/
|
|
117
|
+
toBitmap(): Bitmap;
|
|
118
|
+
/**
|
|
119
|
+
* Get bitmap with bearing info
|
|
120
|
+
*/
|
|
121
|
+
toRasterizedGlyph(): RasterizedGlyph;
|
|
122
|
+
/**
|
|
123
|
+
* Clone this builder
|
|
124
|
+
*/
|
|
125
|
+
clone(): BitmapBuilder;
|
|
126
|
+
/**
|
|
127
|
+
* Get bitmap width
|
|
128
|
+
*/
|
|
129
|
+
get width(): number;
|
|
130
|
+
/**
|
|
131
|
+
* Get bitmap height (rows)
|
|
132
|
+
*/
|
|
133
|
+
get height(): number;
|
|
134
|
+
/**
|
|
135
|
+
* Get pixel mode
|
|
136
|
+
*/
|
|
137
|
+
get pixelMode(): PixelMode;
|
|
138
|
+
/**
|
|
139
|
+
* Get horizontal bearing
|
|
140
|
+
*/
|
|
141
|
+
get bearingX(): number;
|
|
142
|
+
/**
|
|
143
|
+
* Get vertical bearing
|
|
144
|
+
*/
|
|
145
|
+
get bearingY(): number;
|
|
146
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent API for transform and rendering operations
|
|
3
|
+
*
|
|
4
|
+
* Provides two styles of composition:
|
|
5
|
+
* 1. Builder pattern: glyph(font, id).scale(2).blur(5).toRGBA()
|
|
6
|
+
* 2. Pipe pattern: pipe(path, scale(2), rasterize(...), blur(5), toRGBA)
|
|
7
|
+
*/
|
|
8
|
+
import type { Font } from "../font/font.ts";
|
|
9
|
+
import { atlasToAlpha, atlasToRGBA, buildAsciiAtlas, buildAtlas, buildStringAtlas, getGlyphUV } from "../raster/atlas.ts";
|
|
10
|
+
import { buildMsdfAsciiAtlas, buildMsdfAtlas, buildMsdfStringAtlas, msdfAtlasToRGB, msdfAtlasToRGBA } from "../raster/msdf.ts";
|
|
11
|
+
import { rasterizeGlyph, rasterizeText } from "../raster/rasterize.ts";
|
|
12
|
+
import type { AtlasOptions, Bitmap, GlyphAtlas, MsdfAtlasOptions } from "../raster/types.ts";
|
|
13
|
+
import type { GlyphPath } from "../render/path.ts";
|
|
14
|
+
import { renderShapedText, renderShapedTextWithVariation, shapedTextToSVG, shapedTextToSVGWithVariation } from "../render/path.ts";
|
|
15
|
+
import type { GlyphId } from "../types.ts";
|
|
16
|
+
import { BitmapBuilder } from "./bitmap-builder.ts";
|
|
17
|
+
import { PathBuilder } from "./path-builder.ts";
|
|
18
|
+
export { BitmapBuilder } from "./bitmap-builder.ts";
|
|
19
|
+
export { PathBuilder } from "./path-builder.ts";
|
|
20
|
+
export type { AutoRasterOptions, CanvasOptions, RasterOptions, SVGElementOptions, SVGOptions, TransformState, } from "./types.ts";
|
|
21
|
+
/**
|
|
22
|
+
* Create PathBuilder from a font glyph
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const rgba = glyph(font, glyphId)
|
|
27
|
+
* ?.scale(2)
|
|
28
|
+
* .rotateDeg(15)
|
|
29
|
+
* .rasterizeAuto({ padding: 2 })
|
|
30
|
+
* .blur(5)
|
|
31
|
+
* .toRGBA();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function glyph(font: Font, glyphId: GlyphId): PathBuilder | null;
|
|
35
|
+
/**
|
|
36
|
+
* Create PathBuilder from a character in a font
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const rgba = char(font, "A")
|
|
41
|
+
* ?.scale(2)
|
|
42
|
+
* .rasterizeAuto()
|
|
43
|
+
* .toRGBA();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function char(font: Font, character: string): PathBuilder | null;
|
|
47
|
+
/**
|
|
48
|
+
* Create PathBuilder from a font glyph with variable font coordinates
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const rgba = glyphVar(font, glyphId, [400, 100]) // weight=400, width=100
|
|
53
|
+
* ?.scale(2)
|
|
54
|
+
* .rasterizeAuto()
|
|
55
|
+
* .toRGBA();
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function glyphVar(font: Font, glyphId: GlyphId, axisCoords: number[]): PathBuilder | null;
|
|
59
|
+
/**
|
|
60
|
+
* Wrap an existing GlyphPath in a PathBuilder
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const existingPath = getGlyphPath(font, glyphId);
|
|
65
|
+
* const rgba = path(existingPath)
|
|
66
|
+
* .scale(2)
|
|
67
|
+
* .rasterizeAuto()
|
|
68
|
+
* .toRGBA();
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function path(p: GlyphPath): PathBuilder;
|
|
72
|
+
/**
|
|
73
|
+
* Wrap an existing Bitmap in a BitmapBuilder
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const existingBitmap = rasterizePath(path, options);
|
|
78
|
+
* const rgba = bitmap(existingBitmap)
|
|
79
|
+
* .blur(5)
|
|
80
|
+
* .toRGBA();
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function bitmap(b: Bitmap): BitmapBuilder;
|
|
84
|
+
/**
|
|
85
|
+
* Combine multiple PathBuilders into one
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const h = glyph(font, hGlyphId)?.translate(0, 0);
|
|
90
|
+
* const i = glyph(font, iGlyphId)?.translate(100, 0);
|
|
91
|
+
* if (h && i) {
|
|
92
|
+
* const combined = combine(h, i).scale(2).rasterizeAuto().toRGBA();
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function combine(...paths: PathBuilder[]): PathBuilder;
|
|
97
|
+
export { adaptiveBlur, blur, boxBlur, cascadeBlur, clone, combinePaths, condensePath, convert, copy, embolden, emboldenPath, fastBlur, fromGlyph, italic, matrix, obliquePath, pad, perspective, pipe, rasterize, rasterizeAuto, rasterizeWithGradient, renderMsdf, renderSdf, resize, resizeBilinear, rotate, rotateDeg, scale, shear, shift, strokeAsymmetric, strokeAsymmetricCombined, strokePath, toGray, toRGBA, toSVG, translate, } from "./pipe.ts";
|
|
98
|
+
export { buildAtlas, buildAsciiAtlas, buildStringAtlas, atlasToRGBA, atlasToAlpha, getGlyphUV, };
|
|
99
|
+
export { buildMsdfAtlas, buildMsdfAsciiAtlas, buildMsdfStringAtlas, msdfAtlasToRGB, msdfAtlasToRGBA, };
|
|
100
|
+
export { rasterizeGlyph, rasterizeText };
|
|
101
|
+
export { renderShapedText, shapedTextToSVG, renderShapedTextWithVariation, shapedTextToSVGWithVariation, };
|
|
102
|
+
export type { AtlasOptions, GlyphAtlas, MsdfAtlasOptions };
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PathBuilder: Fluent builder for vector path operations
|
|
3
|
+
*
|
|
4
|
+
* Transforms are lazy by default - accumulated as matrix until rasterization or .apply()
|
|
5
|
+
*/
|
|
6
|
+
import type { Font } from "../font/font.ts";
|
|
7
|
+
import { type AsymmetricStrokeOptions } from "../raster/asymmetric-stroke.ts";
|
|
8
|
+
import type { Gradient } from "../raster/gradient.ts";
|
|
9
|
+
import { type MsdfOptions } from "../raster/msdf.ts";
|
|
10
|
+
import { type SdfOptions } from "../raster/sdf.ts";
|
|
11
|
+
import { type LineCap, type LineJoin, type StrokerOptions } from "../raster/stroker.ts";
|
|
12
|
+
import { type Matrix2D, type Matrix3x3 } from "../render/outline-transform.ts";
|
|
13
|
+
import { type GlyphPath } from "../render/path.ts";
|
|
14
|
+
import type { GlyphId } from "../types.ts";
|
|
15
|
+
import { BitmapBuilder } from "./bitmap-builder.ts";
|
|
16
|
+
import type { AutoRasterOptions, CanvasOptions, RasterOptions, SVGElementOptions, SVGOptions } from "./types.ts";
|
|
17
|
+
/**
|
|
18
|
+
* PathBuilder provides a fluent interface for path transformations and rendering
|
|
19
|
+
*/
|
|
20
|
+
export declare class PathBuilder {
|
|
21
|
+
private readonly _path;
|
|
22
|
+
private readonly _transform;
|
|
23
|
+
private readonly _font;
|
|
24
|
+
private constructor();
|
|
25
|
+
/**
|
|
26
|
+
* Create PathBuilder from a font glyph
|
|
27
|
+
*/
|
|
28
|
+
static fromGlyph(font: Font, glyphId: GlyphId): PathBuilder | null;
|
|
29
|
+
/**
|
|
30
|
+
* Create PathBuilder from a font glyph with variable font coordinates
|
|
31
|
+
*/
|
|
32
|
+
static fromGlyphWithVariation(font: Font, glyphId: GlyphId, axisCoords: number[]): PathBuilder | null;
|
|
33
|
+
/**
|
|
34
|
+
* Create PathBuilder from an existing GlyphPath
|
|
35
|
+
*/
|
|
36
|
+
static fromPath(path: GlyphPath): PathBuilder;
|
|
37
|
+
/**
|
|
38
|
+
* Combine multiple PathBuilders into one
|
|
39
|
+
*/
|
|
40
|
+
static combine(...builders: PathBuilder[]): PathBuilder;
|
|
41
|
+
/**
|
|
42
|
+
* Scale uniformly or non-uniformly
|
|
43
|
+
*/
|
|
44
|
+
scale(sx: number, sy?: number): PathBuilder;
|
|
45
|
+
/**
|
|
46
|
+
* Translate by offset
|
|
47
|
+
*/
|
|
48
|
+
translate(dx: number, dy: number): PathBuilder;
|
|
49
|
+
/**
|
|
50
|
+
* Rotate by angle in radians around origin
|
|
51
|
+
*/
|
|
52
|
+
rotate(angle: number): PathBuilder;
|
|
53
|
+
/**
|
|
54
|
+
* Rotate by angle in degrees around origin
|
|
55
|
+
*/
|
|
56
|
+
rotateDeg(angleDeg: number): PathBuilder;
|
|
57
|
+
/**
|
|
58
|
+
* Shear/skew transformation
|
|
59
|
+
*/
|
|
60
|
+
shear(shearX: number, shearY: number): PathBuilder;
|
|
61
|
+
/**
|
|
62
|
+
* Apply italic slant (angle in degrees, typically 12-15 for italic)
|
|
63
|
+
*/
|
|
64
|
+
italic(angleDeg: number): PathBuilder;
|
|
65
|
+
/**
|
|
66
|
+
* Apply custom 2D affine matrix
|
|
67
|
+
*/
|
|
68
|
+
matrix(m: Matrix2D): PathBuilder;
|
|
69
|
+
/**
|
|
70
|
+
* Reset transform to identity
|
|
71
|
+
*/
|
|
72
|
+
resetTransform(): PathBuilder;
|
|
73
|
+
/**
|
|
74
|
+
* Apply 3x3 perspective matrix
|
|
75
|
+
*/
|
|
76
|
+
perspective(m: Matrix3x3): PathBuilder;
|
|
77
|
+
/**
|
|
78
|
+
* Create perspective with vanishing point
|
|
79
|
+
*/
|
|
80
|
+
perspectiveVanish(vanishingPointX: number, vanishingPointY: number, strength: number): PathBuilder;
|
|
81
|
+
/**
|
|
82
|
+
* Force application of pending transforms
|
|
83
|
+
* Returns new PathBuilder with transforms applied and reset
|
|
84
|
+
*/
|
|
85
|
+
apply(): PathBuilder;
|
|
86
|
+
/**
|
|
87
|
+
* Synthetic bold/embolden
|
|
88
|
+
*/
|
|
89
|
+
embolden(strength: number): PathBuilder;
|
|
90
|
+
/**
|
|
91
|
+
* Horizontal condensing (factor < 1) or expansion (factor > 1)
|
|
92
|
+
*/
|
|
93
|
+
condense(factor: number): PathBuilder;
|
|
94
|
+
/**
|
|
95
|
+
* Oblique/slant transformation
|
|
96
|
+
*/
|
|
97
|
+
oblique(slant: number): PathBuilder;
|
|
98
|
+
/**
|
|
99
|
+
* Convert to stroked outline
|
|
100
|
+
*/
|
|
101
|
+
stroke(options: StrokerOptions): PathBuilder;
|
|
102
|
+
stroke(width: number, cap?: LineCap, join?: LineJoin): PathBuilder;
|
|
103
|
+
/**
|
|
104
|
+
* Asymmetric stroke with independent X/Y border widths
|
|
105
|
+
* Returns outer and inner paths
|
|
106
|
+
*/
|
|
107
|
+
strokeAsymmetric(options: AsymmetricStrokeOptions): {
|
|
108
|
+
outer: PathBuilder;
|
|
109
|
+
inner: PathBuilder;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Asymmetric stroke combined (both inner and outer as single fillable path)
|
|
113
|
+
*/
|
|
114
|
+
strokeAsymmetricCombined(options: AsymmetricStrokeOptions): PathBuilder;
|
|
115
|
+
/**
|
|
116
|
+
* Get control box (bounding box of control points)
|
|
117
|
+
* Note: Returns bounds AFTER applying transforms
|
|
118
|
+
*/
|
|
119
|
+
controlBox(): {
|
|
120
|
+
xMin: number;
|
|
121
|
+
yMin: number;
|
|
122
|
+
xMax: number;
|
|
123
|
+
yMax: number;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Get tight bounds (exact bounds considering curve extrema)
|
|
127
|
+
* Note: Returns bounds AFTER applying transforms
|
|
128
|
+
*/
|
|
129
|
+
tightBounds(): {
|
|
130
|
+
xMin: number;
|
|
131
|
+
yMin: number;
|
|
132
|
+
xMax: number;
|
|
133
|
+
yMax: number;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Get the accumulated 2D transform matrix
|
|
137
|
+
*/
|
|
138
|
+
getTransformMatrix(): Matrix2D;
|
|
139
|
+
/**
|
|
140
|
+
* Get the accumulated 3D transform matrix (if any)
|
|
141
|
+
*/
|
|
142
|
+
getTransformMatrix3D(): Matrix3x3 | null;
|
|
143
|
+
/**
|
|
144
|
+
* Rasterize to bitmap with explicit size
|
|
145
|
+
*/
|
|
146
|
+
rasterize(options: RasterOptions): BitmapBuilder;
|
|
147
|
+
/**
|
|
148
|
+
* Rasterize with auto-computed size from bounds
|
|
149
|
+
*/
|
|
150
|
+
rasterizeAuto(options?: AutoRasterOptions): BitmapBuilder;
|
|
151
|
+
/**
|
|
152
|
+
* Rasterize with gradient fill
|
|
153
|
+
*/
|
|
154
|
+
rasterizeWithGradient(gradient: Gradient, options: RasterOptions): BitmapBuilder;
|
|
155
|
+
/**
|
|
156
|
+
* Render as Signed Distance Field (SDF)
|
|
157
|
+
* Useful for GPU text rendering at any scale
|
|
158
|
+
*/
|
|
159
|
+
toSdf(options: SdfOptions): BitmapBuilder;
|
|
160
|
+
/**
|
|
161
|
+
* Render as SDF with auto-computed size from bounds
|
|
162
|
+
*/
|
|
163
|
+
toSdfAuto(options?: {
|
|
164
|
+
padding?: number;
|
|
165
|
+
scale?: number;
|
|
166
|
+
spread?: number;
|
|
167
|
+
flipY?: boolean;
|
|
168
|
+
}): BitmapBuilder;
|
|
169
|
+
/**
|
|
170
|
+
* Render as Multi-channel Signed Distance Field (MSDF)
|
|
171
|
+
* Better quality than SDF for sharp corners
|
|
172
|
+
*/
|
|
173
|
+
toMsdf(options: MsdfOptions): BitmapBuilder;
|
|
174
|
+
/**
|
|
175
|
+
* Render as MSDF with auto-computed size from bounds
|
|
176
|
+
*/
|
|
177
|
+
toMsdfAuto(options?: {
|
|
178
|
+
padding?: number;
|
|
179
|
+
scale?: number;
|
|
180
|
+
spread?: number;
|
|
181
|
+
flipY?: boolean;
|
|
182
|
+
}): BitmapBuilder;
|
|
183
|
+
/**
|
|
184
|
+
* Convert to SVG path data string
|
|
185
|
+
*/
|
|
186
|
+
toSVG(options?: SVGOptions): string;
|
|
187
|
+
/**
|
|
188
|
+
* Convert to full SVG element string
|
|
189
|
+
*/
|
|
190
|
+
toSVGElement(options?: SVGElementOptions): string;
|
|
191
|
+
/**
|
|
192
|
+
* Render to canvas context
|
|
193
|
+
*/
|
|
194
|
+
toCanvas(ctx: CanvasRenderingContext2D, options?: CanvasOptions): void;
|
|
195
|
+
/**
|
|
196
|
+
* Get Path2D object for canvas
|
|
197
|
+
*/
|
|
198
|
+
toPath2D(options?: {
|
|
199
|
+
flipY?: boolean;
|
|
200
|
+
scale?: number;
|
|
201
|
+
}): Path2D;
|
|
202
|
+
/**
|
|
203
|
+
* Extract the raw GlyphPath (with transforms applied)
|
|
204
|
+
*/
|
|
205
|
+
toPath(): GlyphPath;
|
|
206
|
+
/**
|
|
207
|
+
* Clone this builder
|
|
208
|
+
*/
|
|
209
|
+
clone(): PathBuilder;
|
|
210
|
+
/**
|
|
211
|
+
* Apply accumulated transforms to path
|
|
212
|
+
*/
|
|
213
|
+
private applyTransformToPath;
|
|
214
|
+
/**
|
|
215
|
+
* Check if there's any non-identity transform
|
|
216
|
+
*/
|
|
217
|
+
private hasTransform;
|
|
218
|
+
/**
|
|
219
|
+
* Check if 2D matrix is non-identity
|
|
220
|
+
*/
|
|
221
|
+
private hasTransform2D;
|
|
222
|
+
/**
|
|
223
|
+
* Combine accumulated 2D transform with render options
|
|
224
|
+
*/
|
|
225
|
+
private combinedMatrix2D;
|
|
226
|
+
/**
|
|
227
|
+
* Combine accumulated transforms into 3x3 matrix with render options
|
|
228
|
+
*/
|
|
229
|
+
private combinedMatrix3D;
|
|
230
|
+
}
|