text-shaper 0.0.1 → 0.1.1
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/LICENSE +6 -1
- package/README.md +27 -1
- package/dist/font/brotli/context.d.ts +6 -0
- package/dist/font/brotli/decode.d.ts +9 -0
- package/dist/font/brotli/dictionary.d.ts +11 -0
- package/dist/font/brotli/transform.d.ts +12 -0
- package/dist/font/font.d.ts +19 -5
- package/dist/font/tables/cff.d.ts +4 -0
- package/dist/font/tables/gasp.d.ts +54 -0
- package/dist/font/tables/gdef.d.ts +3 -0
- package/dist/font/tables/glyf.d.ts +2 -0
- package/dist/font/tables/hinting.d.ts +38 -0
- package/dist/font/woff2.d.ts +8 -0
- package/dist/hinting/index.d.ts +9 -0
- package/dist/hinting/instructions/arithmetic.d.ts +46 -0
- package/dist/hinting/instructions/control-flow.d.ts +26 -0
- package/dist/hinting/instructions/delta.d.ts +32 -0
- package/dist/hinting/instructions/graphics-state.d.ts +94 -0
- package/dist/hinting/instructions/interpolate.d.ts +16 -0
- package/dist/hinting/instructions/points.d.ts +76 -0
- package/dist/hinting/instructions/stack.d.ts +28 -0
- package/dist/hinting/interpreter.d.ts +30 -0
- package/dist/hinting/programs.d.ts +88 -0
- package/dist/hinting/rounding.d.ts +51 -0
- package/dist/hinting/types.d.ts +369 -0
- package/dist/index.d.ts +21 -11
- package/dist/index.js +10 -8
- package/dist/index.js.map +60 -29
- package/dist/raster/atlas.d.ts +37 -0
- package/dist/raster/bbox.d.ts +91 -0
- package/dist/raster/bitmap-utils.d.ts +25 -0
- package/dist/raster/blur.d.ts +27 -0
- package/dist/raster/cell.d.ts +140 -0
- package/dist/raster/fixed-point.d.ts +100 -0
- package/dist/raster/gradient.d.ts +61 -0
- package/dist/raster/gray-raster.d.ts +132 -0
- package/dist/raster/lcd-filter.d.ts +44 -0
- package/dist/raster/outline-decompose.d.ts +61 -0
- package/dist/raster/rasterize.d.ts +43 -0
- package/dist/raster/sdf.d.ts +37 -0
- package/dist/raster/stroker.d.ts +29 -0
- package/dist/raster/synth.d.ts +50 -0
- package/dist/raster/types.d.ts +176 -0
- package/dist/render/path.d.ts +50 -2
- package/dist/shaper/complex/indic.d.ts +4 -0
- package/dist/types.d.ts +4 -0
- package/dist/unicode/bidi/brackets.gen.d.ts +5 -0
- package/dist/unicode/bidi/char-types.gen.d.ts +25 -0
- package/dist/unicode/bidi/mirroring.gen.d.ts +2 -0
- package/package.json +41 -14
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decompose path commands into rasterizer calls
|
|
3
|
+
*/
|
|
4
|
+
import { type GlyphPath } from "../render/path.ts";
|
|
5
|
+
import type { GrayRaster } from "./gray-raster.ts";
|
|
6
|
+
import { FillRule } from "./types.ts";
|
|
7
|
+
/**
|
|
8
|
+
* Outline validation error types (like FreeType's error codes)
|
|
9
|
+
*/
|
|
10
|
+
export declare enum OutlineError {
|
|
11
|
+
Ok = 0,
|
|
12
|
+
InvalidOutline = 1,
|
|
13
|
+
InvalidArgument = 2,
|
|
14
|
+
EmptyOutline = 3
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validation result with error code and message
|
|
18
|
+
*/
|
|
19
|
+
export interface ValidationResult {
|
|
20
|
+
error: OutlineError;
|
|
21
|
+
message?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Validate a GlyphPath before rasterization (like FreeType's outline validation)
|
|
25
|
+
*
|
|
26
|
+
* Checks:
|
|
27
|
+
* - Path is not null/undefined
|
|
28
|
+
* - Commands array exists
|
|
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)
|
|
32
|
+
*/
|
|
33
|
+
export declare function validateOutline(path: GlyphPath | null | undefined, allowEmpty?: boolean): ValidationResult;
|
|
34
|
+
/**
|
|
35
|
+
* Convert a GlyphPath to rasterizer commands
|
|
36
|
+
*
|
|
37
|
+
* @param raster - The rasterizer instance
|
|
38
|
+
* @param path - Path commands to decompose
|
|
39
|
+
* @param scale - Scale factor (font units to pixels)
|
|
40
|
+
* @param offsetX - X offset in pixels
|
|
41
|
+
* @param offsetY - Y offset in pixels
|
|
42
|
+
* @param flipY - Flip Y axis (font coords are Y-up)
|
|
43
|
+
*/
|
|
44
|
+
export declare function decomposePath(raster: GrayRaster, path: GlyphPath, scale: number, offsetX?: number, offsetY?: number, flipY?: boolean): void;
|
|
45
|
+
/**
|
|
46
|
+
* Calculate bounding box of path in pixel coordinates
|
|
47
|
+
*/
|
|
48
|
+
export declare function getPathBounds(path: GlyphPath, scale: number, flipY?: boolean): {
|
|
49
|
+
minX: number;
|
|
50
|
+
minY: number;
|
|
51
|
+
maxX: number;
|
|
52
|
+
maxY: number;
|
|
53
|
+
} | null;
|
|
54
|
+
/**
|
|
55
|
+
* Get fill rule from outline flags (like FreeType's FT_OUTLINE_EVEN_ODD_FILL check)
|
|
56
|
+
*
|
|
57
|
+
* @param path Path with optional flags
|
|
58
|
+
* @param defaultRule Default fill rule if flags not set
|
|
59
|
+
* @returns Fill rule to use
|
|
60
|
+
*/
|
|
61
|
+
export declare function getFillRuleFromFlags(path: GlyphPath | null | undefined, defaultRule?: FillRule): FillRule;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level rasterization API
|
|
3
|
+
*/
|
|
4
|
+
import type { Font } from "../font/font.ts";
|
|
5
|
+
import { type GlyphPath } from "../render/path.ts";
|
|
6
|
+
import type { GlyphId } from "../types.ts";
|
|
7
|
+
import { type Bitmap, PixelMode, type RasterizedGlyph, type RasterizeOptions } from "./types.ts";
|
|
8
|
+
/**
|
|
9
|
+
* Rasterize a glyph path to a bitmap
|
|
10
|
+
*/
|
|
11
|
+
export declare function rasterizePath(path: GlyphPath, options: RasterizeOptions): Bitmap;
|
|
12
|
+
/**
|
|
13
|
+
* Rasterize a glyph from a font
|
|
14
|
+
*/
|
|
15
|
+
export declare function rasterizeGlyph(font: Font, glyphId: GlyphId, fontSize: number, options?: {
|
|
16
|
+
pixelMode?: PixelMode;
|
|
17
|
+
padding?: number;
|
|
18
|
+
/** Use TrueType hinting if available */
|
|
19
|
+
hinting?: boolean;
|
|
20
|
+
}): RasterizedGlyph | null;
|
|
21
|
+
/**
|
|
22
|
+
* Rasterize text string using shaped glyphs
|
|
23
|
+
*/
|
|
24
|
+
export declare function rasterizeText(font: Font, text: string, fontSize: number, options?: {
|
|
25
|
+
pixelMode?: PixelMode;
|
|
26
|
+
padding?: number;
|
|
27
|
+
}): Bitmap | null;
|
|
28
|
+
/**
|
|
29
|
+
* Export bitmap to raw RGBA pixels (for WebGL textures, etc.)
|
|
30
|
+
*/
|
|
31
|
+
export declare function bitmapToRGBA(bitmap: Bitmap): Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Export bitmap to grayscale array
|
|
34
|
+
*/
|
|
35
|
+
export declare function bitmapToGray(bitmap: Bitmap): Uint8Array;
|
|
36
|
+
export { type BBox, evaluateCubic, evaluateQuadratic, getCubicExtrema, getExactBounds, getQuadraticExtrema, } from "./bbox.ts";
|
|
37
|
+
export { blendBitmap, convertBitmap, copyBitmap, emboldenBitmap, resizeBitmap, } from "./bitmap-utils.ts";
|
|
38
|
+
export { blurBitmap, boxBlur, createGaussianKernel, gaussianBlur, } from "./blur.ts";
|
|
39
|
+
export { type ColorStop, createGradientBitmap, type Gradient, interpolateGradient, type LinearGradient, type RadialGradient, rasterizePathWithGradient, } from "./gradient.ts";
|
|
40
|
+
export { renderSdf, type SdfOptions } from "./sdf.ts";
|
|
41
|
+
export { type LineCap, type LineJoin, type StrokerOptions, strokePath, } from "./stroker.ts";
|
|
42
|
+
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";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signed Distance Field (SDF) rasterizer
|
|
3
|
+
*
|
|
4
|
+
* For each pixel, compute the shortest distance to the outline.
|
|
5
|
+
* Positive values are inside the outline, negative are outside.
|
|
6
|
+
* This allows GPU text rendering at any scale.
|
|
7
|
+
*
|
|
8
|
+
* Algorithm:
|
|
9
|
+
* 1. For each pixel center, find the minimum distance to all outline edges
|
|
10
|
+
* 2. Determine sign based on whether point is inside or outside the outline
|
|
11
|
+
* 3. Normalize and encode to 0-255 (128 = on the edge)
|
|
12
|
+
*/
|
|
13
|
+
import type { GlyphPath } from "../render/path.ts";
|
|
14
|
+
import { type Bitmap } from "./types.ts";
|
|
15
|
+
/**
|
|
16
|
+
* Options for SDF rendering
|
|
17
|
+
*/
|
|
18
|
+
export interface SdfOptions {
|
|
19
|
+
/** Width in pixels */
|
|
20
|
+
width: number;
|
|
21
|
+
/** Height in pixels */
|
|
22
|
+
height: number;
|
|
23
|
+
/** Scale factor (font units to pixels) */
|
|
24
|
+
scale: number;
|
|
25
|
+
/** X offset in pixels */
|
|
26
|
+
offsetX?: number;
|
|
27
|
+
/** Y offset in pixels */
|
|
28
|
+
offsetY?: number;
|
|
29
|
+
/** Flip Y axis (font coords are Y-up, bitmap is Y-down) */
|
|
30
|
+
flipY?: boolean;
|
|
31
|
+
/** Spread/radius - how far the distance field extends in pixels (default: 8) */
|
|
32
|
+
spread?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Render a glyph path as a signed distance field
|
|
36
|
+
*/
|
|
37
|
+
export declare function renderSdf(path: GlyphPath, options: SdfOptions): Bitmap;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path Stroker
|
|
3
|
+
*
|
|
4
|
+
* Converts a path outline into a stroked outline that can be filled.
|
|
5
|
+
* Based on FreeType's ftstroke.c algorithm.
|
|
6
|
+
*
|
|
7
|
+
* The stroker generates two borders (inside and outside) by offsetting
|
|
8
|
+
* the original path by half the stroke width in both directions.
|
|
9
|
+
*/
|
|
10
|
+
import type { GlyphPath } from "../render/path.ts";
|
|
11
|
+
/** Line cap styles */
|
|
12
|
+
export type LineCap = "butt" | "round" | "square";
|
|
13
|
+
/** Line join styles */
|
|
14
|
+
export type LineJoin = "miter" | "round" | "bevel";
|
|
15
|
+
/** Stroker options */
|
|
16
|
+
export interface StrokerOptions {
|
|
17
|
+
/** Stroke width in font units */
|
|
18
|
+
width: number;
|
|
19
|
+
/** Line cap style (default: "butt") */
|
|
20
|
+
lineCap?: LineCap;
|
|
21
|
+
/** Line join style (default: "miter") */
|
|
22
|
+
lineJoin?: LineJoin;
|
|
23
|
+
/** Miter limit for miter joins (default: 4) */
|
|
24
|
+
miterLimit?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Stroke a glyph path, producing a new path that represents the stroked outline
|
|
28
|
+
*/
|
|
29
|
+
export declare function strokePath(path: GlyphPath, options: StrokerOptions): GlyphPath;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synthetic Font Effects
|
|
3
|
+
*
|
|
4
|
+
* Provides transformations for creating synthetic bold, italic, and other effects
|
|
5
|
+
* on glyph outlines. These are useful for fonts that don't have native bold/italic
|
|
6
|
+
* variants.
|
|
7
|
+
*/
|
|
8
|
+
import type { GlyphPath } from "../render/path.ts";
|
|
9
|
+
/**
|
|
10
|
+
* Apply oblique (slant/italic) transformation to a path
|
|
11
|
+
*
|
|
12
|
+
* @param path - The glyph path to transform
|
|
13
|
+
* @param slant - Tangent of the slant angle (0.2 = ~12 degrees, typical italic)
|
|
14
|
+
* @returns New path with slant applied
|
|
15
|
+
*
|
|
16
|
+
* Transform: x' = x + y * slant, y' = y
|
|
17
|
+
*/
|
|
18
|
+
export declare function obliquePath(path: GlyphPath, slant: number): GlyphPath;
|
|
19
|
+
/**
|
|
20
|
+
* Apply general 2D affine transformation to a path
|
|
21
|
+
*
|
|
22
|
+
* @param path - The glyph path to transform
|
|
23
|
+
* @param matrix - 2D transformation matrix [a, b, c, d, e, f]
|
|
24
|
+
* @returns New path with transformation applied
|
|
25
|
+
*
|
|
26
|
+
* Transform: x' = a*x + c*y + e, y' = b*x + d*y + f
|
|
27
|
+
*/
|
|
28
|
+
export declare function transformPath(path: GlyphPath, matrix: [number, number, number, number, number, number]): GlyphPath;
|
|
29
|
+
/**
|
|
30
|
+
* Apply horizontal scaling (condensing/expanding) to a path
|
|
31
|
+
*
|
|
32
|
+
* @param path - The glyph path to transform
|
|
33
|
+
* @param factor - Horizontal scale factor (< 1 = narrower, > 1 = wider)
|
|
34
|
+
* @returns New path with horizontal scaling applied
|
|
35
|
+
*
|
|
36
|
+
* Transform: x' = x * factor, y' = y
|
|
37
|
+
*/
|
|
38
|
+
export declare function condensePath(path: GlyphPath, factor: number): GlyphPath;
|
|
39
|
+
/**
|
|
40
|
+
* Embolden (make bolder) a path by offsetting the outline
|
|
41
|
+
*
|
|
42
|
+
* This implementation uses a simplified approach that offsets each contour
|
|
43
|
+
* outward by moving points along the normal direction. For production use,
|
|
44
|
+
* a proper stroking algorithm would be more accurate.
|
|
45
|
+
*
|
|
46
|
+
* @param path - The glyph path to embolden
|
|
47
|
+
* @param strength - Offset strength in font units (positive = bolder, negative = thinner)
|
|
48
|
+
* @returns New path with emboldening applied
|
|
49
|
+
*/
|
|
50
|
+
export declare function emboldenPath(path: GlyphPath, strength: number): GlyphPath;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rasterizer types - FreeType-style bitmap rendering
|
|
3
|
+
*/
|
|
4
|
+
import type { GlyphPath } from "../render/path.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Pixel modes for bitmap output
|
|
7
|
+
*/
|
|
8
|
+
export declare enum PixelMode {
|
|
9
|
+
/** 1-bit per pixel, 8 pixels per byte */
|
|
10
|
+
Mono = 0,
|
|
11
|
+
/** 8-bit grayscale, 1 byte per pixel */
|
|
12
|
+
Gray = 1,
|
|
13
|
+
/** 24-bit LCD subpixel RGB, 3 bytes per pixel */
|
|
14
|
+
LCD = 2,
|
|
15
|
+
/** 24-bit LCD subpixel vertical RGB */
|
|
16
|
+
LCD_V = 3,
|
|
17
|
+
/** 32-bit RGBA, 4 bytes per pixel */
|
|
18
|
+
RGBA = 4
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Fill rule for outline rendering
|
|
22
|
+
*/
|
|
23
|
+
export declare enum FillRule {
|
|
24
|
+
/** Non-zero winding rule (default) */
|
|
25
|
+
NonZero = 0,
|
|
26
|
+
/** Even-odd (alternating) fill rule */
|
|
27
|
+
EvenOdd = 1
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Bitmap buffer for rasterized glyphs
|
|
31
|
+
*/
|
|
32
|
+
export interface Bitmap {
|
|
33
|
+
/** Pixel buffer */
|
|
34
|
+
buffer: Uint8Array;
|
|
35
|
+
/** Width in pixels */
|
|
36
|
+
width: number;
|
|
37
|
+
/** Height in pixels */
|
|
38
|
+
rows: number;
|
|
39
|
+
/** Bytes per row (may include padding) */
|
|
40
|
+
pitch: number;
|
|
41
|
+
/** Pixel format */
|
|
42
|
+
pixelMode: PixelMode;
|
|
43
|
+
/** Number of gray levels (256 for 8-bit) */
|
|
44
|
+
numGrays: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A single horizontal span of pixels (for direct rendering)
|
|
48
|
+
*/
|
|
49
|
+
export interface Span {
|
|
50
|
+
/** X position of span start */
|
|
51
|
+
x: number;
|
|
52
|
+
/** Length in pixels */
|
|
53
|
+
len: number;
|
|
54
|
+
/** Coverage value 0-255 */
|
|
55
|
+
coverage: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Callback for span-based rendering
|
|
59
|
+
* @template T User data type passed through from render call
|
|
60
|
+
*/
|
|
61
|
+
export type SpanFunc<T = void> = (y: number, spans: Span[], userData: T) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Rasterization parameters
|
|
64
|
+
*/
|
|
65
|
+
export interface RasterParams {
|
|
66
|
+
/** Target bitmap (null for span callback mode) */
|
|
67
|
+
target?: Bitmap;
|
|
68
|
+
/** Source outline path */
|
|
69
|
+
source: GlyphPath;
|
|
70
|
+
/** Fill rule */
|
|
71
|
+
fillRule?: FillRule;
|
|
72
|
+
/** Span callback for direct rendering */
|
|
73
|
+
spanFunc?: SpanFunc;
|
|
74
|
+
/** Clip box (in pixels) */
|
|
75
|
+
clipBox?: {
|
|
76
|
+
xMin: number;
|
|
77
|
+
yMin: number;
|
|
78
|
+
xMax: number;
|
|
79
|
+
yMax: number;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Options for rasterizing a glyph
|
|
84
|
+
*/
|
|
85
|
+
export interface RasterizeOptions {
|
|
86
|
+
/** Width in pixels */
|
|
87
|
+
width: number;
|
|
88
|
+
/** Height in pixels */
|
|
89
|
+
height: number;
|
|
90
|
+
/** Scale factor (font units to pixels) */
|
|
91
|
+
scale: number;
|
|
92
|
+
/** X offset in pixels */
|
|
93
|
+
offsetX?: number;
|
|
94
|
+
/** Y offset in pixels */
|
|
95
|
+
offsetY?: number;
|
|
96
|
+
/** Pixel mode */
|
|
97
|
+
pixelMode?: PixelMode;
|
|
98
|
+
/** Fill rule */
|
|
99
|
+
fillRule?: FillRule;
|
|
100
|
+
/** Flip Y axis (font coords are Y-up, bitmap is Y-down) */
|
|
101
|
+
flipY?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Result of glyph rasterization
|
|
105
|
+
*/
|
|
106
|
+
export interface RasterizedGlyph {
|
|
107
|
+
/** Pixel data */
|
|
108
|
+
bitmap: Bitmap;
|
|
109
|
+
/** Bearing X (offset from origin to left edge) */
|
|
110
|
+
bearingX: number;
|
|
111
|
+
/** Bearing Y (offset from origin to top edge) */
|
|
112
|
+
bearingY: number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Glyph metrics for atlas building
|
|
116
|
+
*/
|
|
117
|
+
export interface GlyphMetrics {
|
|
118
|
+
/** Glyph ID */
|
|
119
|
+
glyphId: number;
|
|
120
|
+
/** X position in atlas */
|
|
121
|
+
atlasX: number;
|
|
122
|
+
/** Y position in atlas */
|
|
123
|
+
atlasY: number;
|
|
124
|
+
/** Width in atlas */
|
|
125
|
+
width: number;
|
|
126
|
+
/** Height in atlas */
|
|
127
|
+
height: number;
|
|
128
|
+
/** Bearing X */
|
|
129
|
+
bearingX: number;
|
|
130
|
+
/** Bearing Y */
|
|
131
|
+
bearingY: number;
|
|
132
|
+
/** Horizontal advance */
|
|
133
|
+
advance: number;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Texture atlas containing multiple glyphs
|
|
137
|
+
*/
|
|
138
|
+
export interface GlyphAtlas {
|
|
139
|
+
/** Atlas bitmap */
|
|
140
|
+
bitmap: Bitmap;
|
|
141
|
+
/** Glyph metrics indexed by glyph ID */
|
|
142
|
+
glyphs: Map<number, GlyphMetrics>;
|
|
143
|
+
/** Font size used for rendering */
|
|
144
|
+
fontSize: number;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Options for building a glyph atlas
|
|
148
|
+
*/
|
|
149
|
+
export interface AtlasOptions {
|
|
150
|
+
/** Font size in pixels */
|
|
151
|
+
fontSize: number;
|
|
152
|
+
/** Padding between glyphs */
|
|
153
|
+
padding?: number;
|
|
154
|
+
/** Maximum atlas width */
|
|
155
|
+
maxWidth?: number;
|
|
156
|
+
/** Maximum atlas height */
|
|
157
|
+
maxHeight?: number;
|
|
158
|
+
/** Pixel mode */
|
|
159
|
+
pixelMode?: PixelMode;
|
|
160
|
+
/** Enable hinting */
|
|
161
|
+
hinting?: boolean;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Create an empty bitmap
|
|
165
|
+
*/
|
|
166
|
+
export declare function createBitmap(width: number, height: number, pixelMode?: PixelMode): Bitmap;
|
|
167
|
+
/**
|
|
168
|
+
* Clear a bitmap to zero
|
|
169
|
+
*/
|
|
170
|
+
export declare function clearBitmap(bitmap: Bitmap): void;
|
|
171
|
+
/**
|
|
172
|
+
* Create a bottom-up bitmap (negative pitch)
|
|
173
|
+
* Bottom-up bitmaps have row 0 at the bottom of the image,
|
|
174
|
+
* which matches some graphics APIs (e.g., Windows DIB, OpenGL textures)
|
|
175
|
+
*/
|
|
176
|
+
export declare function createBottomUpBitmap(width: number, height: number, pixelMode?: PixelMode): Bitmap;
|
package/dist/render/path.d.ts
CHANGED
|
@@ -30,6 +30,19 @@ export type PathCommand = {
|
|
|
30
30
|
} | {
|
|
31
31
|
type: "Z";
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Outline flags (like FreeType's FT_OUTLINE_* flags)
|
|
35
|
+
*/
|
|
36
|
+
export declare enum OutlineFlags {
|
|
37
|
+
/** No flags */
|
|
38
|
+
None = 0,
|
|
39
|
+
/** Use even-odd fill rule instead of non-zero winding */
|
|
40
|
+
EvenOddFill = 1,
|
|
41
|
+
/** Outline has been hinted */
|
|
42
|
+
HighPrecision = 2,
|
|
43
|
+
/** Outline is a single stroke (not filled) */
|
|
44
|
+
SinglePass = 4
|
|
45
|
+
}
|
|
33
46
|
/**
|
|
34
47
|
* A glyph path is a series of drawing commands
|
|
35
48
|
*/
|
|
@@ -41,10 +54,12 @@ export interface GlyphPath {
|
|
|
41
54
|
xMax: number;
|
|
42
55
|
yMax: number;
|
|
43
56
|
} | null;
|
|
57
|
+
/** Outline flags (like FreeType's FT_OUTLINE_* flags) */
|
|
58
|
+
flags?: OutlineFlags;
|
|
44
59
|
}
|
|
45
60
|
/**
|
|
46
|
-
* Convert
|
|
47
|
-
* TrueType
|
|
61
|
+
* Convert contours to path commands
|
|
62
|
+
* Handles both TrueType (quadratic Béziers) and CFF (cubic Béziers)
|
|
48
63
|
*/
|
|
49
64
|
export declare function contourToPath(contour: Contour): PathCommand[];
|
|
50
65
|
/**
|
|
@@ -58,6 +73,21 @@ export declare function pathToSVG(path: GlyphPath, options?: {
|
|
|
58
73
|
flipY?: boolean;
|
|
59
74
|
scale?: number;
|
|
60
75
|
}): string;
|
|
76
|
+
/**
|
|
77
|
+
* Render options for stroke/fill
|
|
78
|
+
*/
|
|
79
|
+
export interface RenderOptions {
|
|
80
|
+
flipY?: boolean;
|
|
81
|
+
scale?: number;
|
|
82
|
+
offsetX?: number;
|
|
83
|
+
offsetY?: number;
|
|
84
|
+
fill?: string;
|
|
85
|
+
stroke?: string;
|
|
86
|
+
strokeWidth?: number;
|
|
87
|
+
lineCap?: CanvasLineCap;
|
|
88
|
+
lineJoin?: CanvasLineJoin;
|
|
89
|
+
miterLimit?: number;
|
|
90
|
+
}
|
|
61
91
|
/**
|
|
62
92
|
* Render path commands to a Canvas 2D context
|
|
63
93
|
*/
|
|
@@ -73,6 +103,8 @@ export declare function pathToCanvas(ctx: CanvasRenderingContext2D | Path2D, pat
|
|
|
73
103
|
export declare function glyphToSVG(font: Font, glyphId: GlyphId, options?: {
|
|
74
104
|
fontSize?: number;
|
|
75
105
|
fill?: string;
|
|
106
|
+
stroke?: string;
|
|
107
|
+
strokeWidth?: number;
|
|
76
108
|
}): string | null;
|
|
77
109
|
/**
|
|
78
110
|
* Render shaped text to Canvas
|
|
@@ -89,6 +121,10 @@ export declare function renderShapedText(ctx: CanvasRenderingContext2D, font: Fo
|
|
|
89
121
|
x?: number;
|
|
90
122
|
y?: number;
|
|
91
123
|
fill?: string;
|
|
124
|
+
stroke?: string;
|
|
125
|
+
strokeWidth?: number;
|
|
126
|
+
lineCap?: CanvasLineCap;
|
|
127
|
+
lineJoin?: CanvasLineJoin;
|
|
92
128
|
}): void;
|
|
93
129
|
/**
|
|
94
130
|
* Generate SVG for shaped text
|
|
@@ -96,6 +132,10 @@ export declare function renderShapedText(ctx: CanvasRenderingContext2D, font: Fo
|
|
|
96
132
|
export declare function shapedTextToSVG(font: Font, glyphs: ShapedGlyph[], options?: {
|
|
97
133
|
fontSize?: number;
|
|
98
134
|
fill?: string;
|
|
135
|
+
stroke?: string;
|
|
136
|
+
strokeWidth?: number;
|
|
137
|
+
lineCap?: "butt" | "round" | "square";
|
|
138
|
+
lineJoin?: "miter" | "round" | "bevel";
|
|
99
139
|
}): string;
|
|
100
140
|
/**
|
|
101
141
|
* Convert GlyphBuffer output to ShapedGlyph array
|
|
@@ -113,6 +153,10 @@ export declare function renderShapedTextWithVariation(ctx: CanvasRenderingContex
|
|
|
113
153
|
x?: number;
|
|
114
154
|
y?: number;
|
|
115
155
|
fill?: string;
|
|
156
|
+
stroke?: string;
|
|
157
|
+
strokeWidth?: number;
|
|
158
|
+
lineCap?: CanvasLineCap;
|
|
159
|
+
lineJoin?: CanvasLineJoin;
|
|
116
160
|
}): void;
|
|
117
161
|
/**
|
|
118
162
|
* Generate SVG for shaped text with variable font support
|
|
@@ -120,6 +164,10 @@ export declare function renderShapedTextWithVariation(ctx: CanvasRenderingContex
|
|
|
120
164
|
export declare function shapedTextToSVGWithVariation(font: Font, glyphs: ShapedGlyph[], axisCoords: number[], options?: {
|
|
121
165
|
fontSize?: number;
|
|
122
166
|
fill?: string;
|
|
167
|
+
stroke?: string;
|
|
168
|
+
strokeWidth?: number;
|
|
169
|
+
lineCap?: "butt" | "round" | "square";
|
|
170
|
+
lineJoin?: "miter" | "round" | "bevel";
|
|
123
171
|
}): string;
|
|
124
172
|
/**
|
|
125
173
|
* Calculate the total advance width of shaped text
|
|
@@ -103,6 +103,10 @@ export declare enum MatraPosition {
|
|
|
103
103
|
BelowBase = 2,
|
|
104
104
|
PostBase = 3
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Get matra position based on codepoint
|
|
108
|
+
*/
|
|
109
|
+
export declare function getMatraPosition(cp: number): MatraPosition;
|
|
106
110
|
/**
|
|
107
111
|
* Set up masks and syllable indices for Indic shaping
|
|
108
112
|
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -129,6 +129,10 @@ export declare const Tags: {
|
|
|
129
129
|
readonly vhea: number;
|
|
130
130
|
readonly vmtx: number;
|
|
131
131
|
readonly VORG: number;
|
|
132
|
+
readonly fpgm: number;
|
|
133
|
+
readonly prep: number;
|
|
134
|
+
readonly cvt: number;
|
|
135
|
+
readonly gasp: number;
|
|
132
136
|
};
|
|
133
137
|
export declare const FeatureTags: {
|
|
134
138
|
readonly ccmp: number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
R: string;
|
|
3
|
+
EN: string;
|
|
4
|
+
ES: string;
|
|
5
|
+
ET: string;
|
|
6
|
+
AN: string;
|
|
7
|
+
CS: string;
|
|
8
|
+
B: string;
|
|
9
|
+
S: string;
|
|
10
|
+
WS: string;
|
|
11
|
+
ON: string;
|
|
12
|
+
BN: string;
|
|
13
|
+
NSM: string;
|
|
14
|
+
AL: string;
|
|
15
|
+
LRO: string;
|
|
16
|
+
RLO: string;
|
|
17
|
+
LRE: string;
|
|
18
|
+
RLE: string;
|
|
19
|
+
PDF: string;
|
|
20
|
+
LRI: string;
|
|
21
|
+
RLI: string;
|
|
22
|
+
FSI: string;
|
|
23
|
+
PDI: string;
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "14>1,j>2,t>2,u>2,1a>g,2v3>1,1>1,1ge>1,1wd>1,b>1,1j>1,f>1,ai>3,-2>3,+1,8>1k0,-1jq>1y7,-1y6>1hf,-1he>1h6,-1h5>1ha,-1h8>1qi,-1pu>1,6>3u,-3s>7,6>1,1>1,f>1,1>1,+2,3>1,1>1,+13,4>1,1>1,6>1eo,-1ee>1,3>1mg,-1me>1mk,-1mj>1mi,-1mg>1mi,-1md>1,1>1,+2,1>10k,-103>1,1>1,4>1,5>1,1>1,+10,3>1,1>8,-7>8,+1,-6>7,+1,a>1,1>1,u>1,u6>1,1>1,+5,26>1,1>1,2>1,2>2,8>1,7>1,4>1,1>1,+5,b8>1,1>1,+3,1>3,-2>1,2>1,1>1,+2,c>1,3>1,1>1,+2,h>1,3>1,a>1,1>1,2>1,3>1,1>1,d>1,f>1,3>1,1a>1,1>1,6>1,7>1,13>1,k>1,1>1,+19,4>1,1>1,+2,2>1,1>1,+18,m>1,a>1,1>1,lk>1,1>1,4>1,2>1,f>1,3>1,1>1,+3,db>1,1>1,+3,3>1,1>1,+2,14qm>1,1>1,+1,6>1,4j>1,j>2,t>2,u>2,2>1,+1";
|
|
2
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,18 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "text-shaper",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Pure TypeScript text shaping engine",
|
|
5
|
-
"type": "module",
|
|
3
|
+
"version": "0.1.1",
|
|
6
4
|
"main": "./dist/index.js",
|
|
7
5
|
"module": "./dist/index.js",
|
|
8
|
-
"
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"@biomejs/biome": "2.3.8",
|
|
8
|
+
"@types/bun": "latest",
|
|
9
|
+
"vitepress": "^2.0.0-alpha.15",
|
|
10
|
+
"vitepress-plugin-llms": "^1.9.3"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"typescript": "^5"
|
|
14
|
+
},
|
|
9
15
|
"exports": {
|
|
10
16
|
".": {
|
|
11
17
|
"types": "./dist/index.d.ts",
|
|
12
18
|
"import": "./dist/index.js"
|
|
13
19
|
}
|
|
14
20
|
},
|
|
15
|
-
"
|
|
21
|
+
"description": "Pure TypeScript text shaping engine with OpenType layout, TrueType hinting, and FreeType-style rasterization",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"font",
|
|
27
|
+
"text",
|
|
28
|
+
"shaping",
|
|
29
|
+
"harfbuzz",
|
|
30
|
+
"opentype",
|
|
31
|
+
"truetype",
|
|
32
|
+
"rasterizer",
|
|
33
|
+
"hinting",
|
|
34
|
+
"typography",
|
|
35
|
+
"glyph",
|
|
36
|
+
"freetype",
|
|
37
|
+
"arabic",
|
|
38
|
+
"indic",
|
|
39
|
+
"bidi",
|
|
40
|
+
"variable-fonts",
|
|
41
|
+
"lcd-rendering",
|
|
42
|
+
"texture-atlas"
|
|
43
|
+
],
|
|
44
|
+
"license": "MIT",
|
|
16
45
|
"scripts": {
|
|
17
46
|
"build": "bun build ./src/index.ts --outdir ./dist --target browser --minify --sourcemap=linked",
|
|
18
47
|
"build:prod": "bun build ./src/index.ts --outdir ./dist --target browser --production --sourcemap=external",
|
|
@@ -21,13 +50,11 @@
|
|
|
21
50
|
"typecheck": "tsc --noEmit",
|
|
22
51
|
"lint": "biome check --write --unsafe --max-diagnostics 99999",
|
|
23
52
|
"check": "bun run typecheck && bun run lint",
|
|
24
|
-
"prepublishOnly": "bun run build:prod && bun run build:dts"
|
|
53
|
+
"prepublishOnly": "bun run build:prod && bun run build:dts",
|
|
54
|
+
"docs:dev": "vitepress dev docs",
|
|
55
|
+
"docs:build": "vitepress build docs",
|
|
56
|
+
"docs:preview": "vitepress preview docs"
|
|
25
57
|
},
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
"peerDependencies": {
|
|
31
|
-
"typescript": "^5"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
58
|
+
"type": "module",
|
|
59
|
+
"types": "./dist/index.d.ts"
|
|
60
|
+
}
|