text-shaper 0.1.2 → 0.1.4
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 +413 -38
- 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/brotli/decode.d.ts +42 -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/cff2.d.ts +63 -0
- 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 +24 -1
- package/dist/font/tables/gsub.d.ts +20 -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 +105 -99
- 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 +27 -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 +189 -4
- 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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipe-style functional utilities for composing transforms and rendering
|
|
3
|
+
*
|
|
4
|
+
* Provides an alternative to the builder pattern for users who prefer
|
|
5
|
+
* functional composition.
|
|
6
|
+
*/
|
|
7
|
+
import type { Font } from "../font/font.ts";
|
|
8
|
+
import { type AsymmetricStrokeOptions } from "../raster/asymmetric-stroke.ts";
|
|
9
|
+
import type { Gradient } from "../raster/gradient.ts";
|
|
10
|
+
import { type MsdfOptions } from "../raster/msdf.ts";
|
|
11
|
+
import { type SdfOptions } from "../raster/sdf.ts";
|
|
12
|
+
import type { LineCap, LineJoin, StrokerOptions } from "../raster/stroker.ts";
|
|
13
|
+
import type { Bitmap, PixelMode, RasterizeOptions } from "../raster/types.ts";
|
|
14
|
+
import type { Matrix2D, Matrix3x3 } from "../render/outline-transform.ts";
|
|
15
|
+
import type { GlyphPath } from "../render/path.ts";
|
|
16
|
+
import type { GlyphId } from "../types.ts";
|
|
17
|
+
/**
|
|
18
|
+
* Compose functions left-to-right
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const result = pipe(
|
|
23
|
+
* getGlyphPath(font, glyphId),
|
|
24
|
+
* scale(2, 2),
|
|
25
|
+
* rotate(Math.PI / 4),
|
|
26
|
+
* rasterize({ width: 100, height: 100 }),
|
|
27
|
+
* blur(5),
|
|
28
|
+
* toRGBA
|
|
29
|
+
* );
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function pipe<A>(a: A): A;
|
|
33
|
+
export declare function pipe<A, B>(a: A, ab: (a: A) => B): B;
|
|
34
|
+
export declare function pipe<A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C;
|
|
35
|
+
export declare function pipe<A, B, C, D>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D;
|
|
36
|
+
export declare function pipe<A, B, C, D, E>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): E;
|
|
37
|
+
export declare function pipe<A, B, C, D, E, F>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): F;
|
|
38
|
+
export declare function pipe<A, B, C, D, E, F, G>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): G;
|
|
39
|
+
export declare function pipe<A, B, C, D, E, F, G, H>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H): H;
|
|
40
|
+
/**
|
|
41
|
+
* Get glyph path from font (for use with pipe)
|
|
42
|
+
*/
|
|
43
|
+
export declare function fromGlyph(font: Font, glyphId: GlyphId): GlyphPath | null;
|
|
44
|
+
/**
|
|
45
|
+
* Scale path uniformly or non-uniformly
|
|
46
|
+
*/
|
|
47
|
+
export declare function scale(sx: number, sy?: number): (path: GlyphPath) => GlyphPath;
|
|
48
|
+
/**
|
|
49
|
+
* Translate path by offset
|
|
50
|
+
*/
|
|
51
|
+
export declare function translate(dx: number, dy: number): (path: GlyphPath) => GlyphPath;
|
|
52
|
+
/**
|
|
53
|
+
* Rotate path by angle in radians
|
|
54
|
+
*/
|
|
55
|
+
export declare function rotate(angle: number): (path: GlyphPath) => GlyphPath;
|
|
56
|
+
/**
|
|
57
|
+
* Rotate path by angle in degrees
|
|
58
|
+
*/
|
|
59
|
+
export declare function rotateDeg(angleDeg: number): (path: GlyphPath) => GlyphPath;
|
|
60
|
+
/**
|
|
61
|
+
* Shear/skew path
|
|
62
|
+
*/
|
|
63
|
+
export declare function shear(shearX: number, shearY: number): (path: GlyphPath) => GlyphPath;
|
|
64
|
+
/**
|
|
65
|
+
* Apply italic slant (angle in degrees)
|
|
66
|
+
*/
|
|
67
|
+
export declare function italic(angleDeg: number): (path: GlyphPath) => GlyphPath;
|
|
68
|
+
/**
|
|
69
|
+
* Apply custom 2D affine matrix
|
|
70
|
+
*/
|
|
71
|
+
export declare function matrix(m: Matrix2D): (path: GlyphPath) => GlyphPath;
|
|
72
|
+
/**
|
|
73
|
+
* Apply 3D perspective matrix
|
|
74
|
+
*/
|
|
75
|
+
export declare function perspective(m: Matrix3x3): (path: GlyphPath) => GlyphPath;
|
|
76
|
+
/**
|
|
77
|
+
* Embolden path
|
|
78
|
+
*/
|
|
79
|
+
export declare function emboldenPath(strength: number): (path: GlyphPath) => GlyphPath;
|
|
80
|
+
/**
|
|
81
|
+
* Condense/expand path horizontally
|
|
82
|
+
*/
|
|
83
|
+
export declare function condensePath(factor: number): (path: GlyphPath) => GlyphPath;
|
|
84
|
+
/**
|
|
85
|
+
* Apply oblique/slant to path
|
|
86
|
+
*/
|
|
87
|
+
export declare function obliquePath(slant: number): (path: GlyphPath) => GlyphPath;
|
|
88
|
+
/**
|
|
89
|
+
* Stroke path to create outline
|
|
90
|
+
*/
|
|
91
|
+
export declare function strokePath(options: StrokerOptions): (path: GlyphPath) => GlyphPath;
|
|
92
|
+
export declare function strokePath(width: number, cap?: LineCap, join?: LineJoin): (path: GlyphPath) => GlyphPath;
|
|
93
|
+
/**
|
|
94
|
+
* Clone path
|
|
95
|
+
*/
|
|
96
|
+
export declare function clone(): (path: GlyphPath) => GlyphPath;
|
|
97
|
+
/**
|
|
98
|
+
* Combine multiple paths
|
|
99
|
+
*/
|
|
100
|
+
export declare function combinePaths(paths: GlyphPath[]): GlyphPath;
|
|
101
|
+
/**
|
|
102
|
+
* Asymmetric stroke with independent X/Y border widths
|
|
103
|
+
*/
|
|
104
|
+
export declare function strokeAsymmetric(options: AsymmetricStrokeOptions): (path: GlyphPath) => {
|
|
105
|
+
outer: GlyphPath;
|
|
106
|
+
inner: GlyphPath;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Asymmetric stroke combined (both inner and outer as single fillable path)
|
|
110
|
+
*/
|
|
111
|
+
export declare function strokeAsymmetricCombined(options: AsymmetricStrokeOptions): (path: GlyphPath) => GlyphPath;
|
|
112
|
+
/**
|
|
113
|
+
* Rasterize path to bitmap
|
|
114
|
+
*/
|
|
115
|
+
export declare function rasterize(options: RasterizeOptions): (path: GlyphPath) => Bitmap;
|
|
116
|
+
/**
|
|
117
|
+
* Rasterize with auto-computed size from bounds
|
|
118
|
+
*/
|
|
119
|
+
export declare function rasterizeAuto(options?: {
|
|
120
|
+
padding?: number;
|
|
121
|
+
scale?: number;
|
|
122
|
+
pixelMode?: PixelMode;
|
|
123
|
+
}): (path: GlyphPath) => Bitmap;
|
|
124
|
+
/**
|
|
125
|
+
* Rasterize with gradient fill
|
|
126
|
+
*/
|
|
127
|
+
export declare function rasterizeWithGradient(gradient: Gradient, options: RasterizeOptions): (path: GlyphPath) => Bitmap;
|
|
128
|
+
/**
|
|
129
|
+
* Render path as Signed Distance Field
|
|
130
|
+
*/
|
|
131
|
+
export declare function renderSdf(options: SdfOptions): (path: GlyphPath) => Bitmap;
|
|
132
|
+
/**
|
|
133
|
+
* Render path as Multi-channel Signed Distance Field
|
|
134
|
+
*/
|
|
135
|
+
export declare function renderMsdf(options: MsdfOptions): (path: GlyphPath) => Bitmap;
|
|
136
|
+
/**
|
|
137
|
+
* Gaussian blur bitmap
|
|
138
|
+
*/
|
|
139
|
+
export declare function blur(radius: number): (bitmap: Bitmap) => Bitmap;
|
|
140
|
+
/**
|
|
141
|
+
* Box blur bitmap
|
|
142
|
+
*/
|
|
143
|
+
export declare function boxBlur(radius: number): (bitmap: Bitmap) => Bitmap;
|
|
144
|
+
/**
|
|
145
|
+
* Cascade blur (fast for large radii)
|
|
146
|
+
*/
|
|
147
|
+
export declare function cascadeBlur(radiusX: number, radiusY?: number): (bitmap: Bitmap) => Bitmap;
|
|
148
|
+
/**
|
|
149
|
+
* Adaptive blur (auto-selects best algorithm)
|
|
150
|
+
*/
|
|
151
|
+
export declare function adaptiveBlur(radiusX: number, radiusY?: number): (bitmap: Bitmap) => Bitmap;
|
|
152
|
+
/**
|
|
153
|
+
* Fast Gaussian blur using cascade algorithm
|
|
154
|
+
* Recommended for large radii (> 3 pixels)
|
|
155
|
+
*/
|
|
156
|
+
export declare function fastBlur(radius: number): (bitmap: Bitmap) => Bitmap;
|
|
157
|
+
/**
|
|
158
|
+
* Embolden bitmap operator
|
|
159
|
+
*/
|
|
160
|
+
export declare function embolden(xStrength: number, yStrength?: number): (bitmap: Bitmap) => Bitmap;
|
|
161
|
+
/**
|
|
162
|
+
* Shift bitmap position
|
|
163
|
+
*/
|
|
164
|
+
export declare function shift(dx: number, dy: number): (bitmap: Bitmap) => Bitmap;
|
|
165
|
+
/**
|
|
166
|
+
* Resize bitmap with nearest-neighbor
|
|
167
|
+
*/
|
|
168
|
+
export declare function resize(width: number, height: number): (bitmap: Bitmap) => Bitmap;
|
|
169
|
+
/**
|
|
170
|
+
* Resize bitmap with bilinear interpolation
|
|
171
|
+
*/
|
|
172
|
+
export declare function resizeBilinear(width: number, height: number): (bitmap: Bitmap) => Bitmap;
|
|
173
|
+
/**
|
|
174
|
+
* Pad bitmap
|
|
175
|
+
*/
|
|
176
|
+
export declare function pad(left: number, top: number, right: number, bottom: number): (bitmap: Bitmap) => Bitmap;
|
|
177
|
+
export declare function pad(all: number): (bitmap: Bitmap) => Bitmap;
|
|
178
|
+
/**
|
|
179
|
+
* Convert bitmap to different pixel mode
|
|
180
|
+
*/
|
|
181
|
+
export declare function convert(targetMode: PixelMode): (bitmap: Bitmap) => Bitmap;
|
|
182
|
+
/**
|
|
183
|
+
* Convert bitmap to RGBA array
|
|
184
|
+
*/
|
|
185
|
+
export declare function toRGBA(bitmap: Bitmap): Uint8Array;
|
|
186
|
+
/**
|
|
187
|
+
* Convert bitmap to grayscale array
|
|
188
|
+
*/
|
|
189
|
+
export declare function toGray(bitmap: Bitmap): Uint8Array;
|
|
190
|
+
/**
|
|
191
|
+
* Convert path to SVG string
|
|
192
|
+
*/
|
|
193
|
+
export declare function toSVG(options?: {
|
|
194
|
+
flipY?: boolean;
|
|
195
|
+
scale?: number;
|
|
196
|
+
}): (path: GlyphPath) => string;
|
|
197
|
+
/**
|
|
198
|
+
* Copy bitmap
|
|
199
|
+
*/
|
|
200
|
+
export declare function copy(bitmap: Bitmap): Bitmap;
|