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.
Files changed (64) hide show
  1. package/README.md +413 -38
  2. package/dist/aat/state-machine.d.ts +18 -6
  3. package/dist/buffer/glyph-buffer.d.ts +35 -1
  4. package/dist/buffer/unicode-buffer.d.ts +2 -0
  5. package/dist/fluent/bitmap-builder.d.ts +146 -0
  6. package/dist/fluent/index.d.ts +102 -0
  7. package/dist/fluent/path-builder.d.ts +230 -0
  8. package/dist/fluent/pipe.d.ts +200 -0
  9. package/dist/fluent/types.d.ts +93 -0
  10. package/dist/font/brotli/decode.d.ts +42 -0
  11. package/dist/font/face.d.ts +2 -0
  12. package/dist/font/font.d.ts +14 -0
  13. package/dist/font/tables/cff.d.ts +3 -1
  14. package/dist/font/tables/cff2.d.ts +63 -0
  15. package/dist/font/tables/colr.d.ts +4 -1
  16. package/dist/font/tables/fvar.d.ts +3 -1
  17. package/dist/font/tables/glyf.d.ts +13 -0
  18. package/dist/font/tables/gpos.d.ts +24 -1
  19. package/dist/font/tables/gsub.d.ts +20 -0
  20. package/dist/font/tables/gvar.d.ts +10 -1
  21. package/dist/font/tables/head.d.ts +5 -0
  22. package/dist/font/tables/hhea.d.ts +5 -0
  23. package/dist/font/tables/loca.d.ts +3 -0
  24. package/dist/font/tables/maxp.d.ts +5 -0
  25. package/dist/font/tables/name.d.ts +5 -0
  26. package/dist/font/tables/os2.d.ts +5 -0
  27. package/dist/font/tables/post.d.ts +5 -0
  28. package/dist/index.d.ts +5 -3
  29. package/dist/index.js +12 -10
  30. package/dist/index.js.map +105 -99
  31. package/dist/layout/justify.d.ts +15 -2
  32. package/dist/layout/structures/class-def.d.ts +61 -8
  33. package/dist/layout/structures/coverage.d.ts +57 -10
  34. package/dist/layout/structures/device.d.ts +26 -5
  35. package/dist/layout/structures/layout-common.d.ts +18 -3
  36. package/dist/layout/structures/set-digest.d.ts +59 -0
  37. package/dist/raster/asymmetric-stroke.d.ts +9 -5
  38. package/dist/raster/bitmap-utils.d.ts +67 -0
  39. package/dist/raster/blur.d.ts +11 -0
  40. package/dist/raster/cascade-blur.d.ts +9 -10
  41. package/dist/raster/cell.d.ts +24 -0
  42. package/dist/raster/fixed-point.d.ts +1 -1
  43. package/dist/raster/gradient.d.ts +15 -0
  44. package/dist/raster/gray-raster.d.ts +7 -1
  45. package/dist/raster/lcd-filter.d.ts +15 -0
  46. package/dist/raster/msdf.d.ts +27 -5
  47. package/dist/raster/outline-decompose.d.ts +16 -17
  48. package/dist/raster/rasterize.d.ts +19 -2
  49. package/dist/raster/sdf.d.ts +3 -0
  50. package/dist/raster/stroker.d.ts +3 -0
  51. package/dist/raster/types.d.ts +9 -0
  52. package/dist/render/path.d.ts +56 -1
  53. package/dist/shaper/complex/arabic.d.ts +1 -0
  54. package/dist/shaper/shape-plan.d.ts +11 -8
  55. package/dist/shaper/shaper.d.ts +189 -4
  56. package/dist/unicode/bidi/brackets.d.ts +15 -0
  57. package/dist/unicode/bidi/char-types.d.ts +4 -0
  58. package/dist/unicode/bidi/embedding-levels.d.ts +3 -0
  59. package/dist/unicode/bidi/mirroring.d.ts +10 -0
  60. package/dist/unicode/bidi/reordering.d.ts +15 -0
  61. package/dist/unicode/normalize.d.ts +23 -0
  62. package/dist/unicode/script.d.ts +17 -0
  63. package/dist/unicode/segmentation.d.ts +18 -0
  64. package/package.json +11 -2
@@ -64,10 +64,16 @@ export interface JustifyAdjustment {
64
64
  }
65
65
  /**
66
66
  * Calculate current line width from glyph buffer
67
+ * @param buffer - The glyph buffer to measure
68
+ * @returns Total line width in font units (sum of all xAdvance values)
67
69
  */
68
70
  export declare function calculateLineWidth(buffer: GlyphBuffer): number;
69
71
  /**
70
72
  * Justify a shaped glyph buffer to fit a target width
73
+ * @param font - The font containing JSTF and glyph metrics
74
+ * @param buffer - The shaped glyph buffer to justify (modified in place)
75
+ * @param options - Justification options including target width and mode
76
+ * @returns Result containing success status, final width, and applied adjustments
71
77
  */
72
78
  export declare function justify(font: Font, buffer: GlyphBuffer, options: JustifyOptions): JustifyResult;
73
79
  /**
@@ -78,11 +84,18 @@ export interface LineBreakResult {
78
84
  breakPoints: number[];
79
85
  }
80
86
  /**
81
- * Break shaped text into lines at a given width
82
- * Uses simple greedy algorithm
87
+ * Break shaped text into lines at a given width using simple greedy algorithm
88
+ * @param buffer - The shaped glyph buffer to break into lines
89
+ * @param maxWidth - Maximum line width in font units
90
+ * @param spaceGlyph - Optional glyph ID of space character for word boundary detection
91
+ * @returns Object containing array of line buffers and break point indices
83
92
  */
84
93
  export declare function breakIntoLines(buffer: GlyphBuffer, maxWidth: number, spaceGlyph?: GlyphId): LineBreakResult;
85
94
  /**
86
95
  * Justify all lines in a paragraph to the same width
96
+ * @param font - The font containing JSTF and glyph metrics
97
+ * @param lines - Array of glyph buffers representing lines (modified in place)
98
+ * @param options - Justification options including target width and mode
99
+ * @returns Array of justification results, one per line
87
100
  */
88
101
  export declare function justifyParagraph(font: Font, lines: GlyphBuffer[], options: JustifyOptions): JustifyResult[];
@@ -1,15 +1,68 @@
1
1
  import type { Reader } from "../../font/binary/reader.ts";
2
- import type { GlyphId } from "../../types.ts";
3
- /** Class Definition table - maps glyph IDs to class values */
4
- export interface ClassDef {
5
- /** Get class for a glyph ID (returns 0 if not defined) */
2
+ import type { GlyphId, uint16 } from "../../types.ts";
3
+ /** Class range record for Format 2 */
4
+ interface ClassRangeRecord {
5
+ startGlyphId: GlyphId;
6
+ endGlyphId: GlyphId;
7
+ classValue: uint16;
8
+ }
9
+ /**
10
+ * Class Definition table - maps glyph IDs to class values.
11
+ *
12
+ * IMPORTANT: This is a unified class (not interface + implementations) to ensure
13
+ * monomorphic call sites in V8. Polymorphic calls can be 7-8x slower!
14
+ */
15
+ export declare class ClassDef {
16
+ private readonly startGlyphId;
17
+ private readonly classValueArray;
18
+ private readonly ranges;
19
+ private readonly glyphMap;
20
+ private readonly isEmpty;
21
+ private constructor();
22
+ /**
23
+ * Create an empty ClassDef
24
+ * @returns Empty ClassDef instance where all glyphs return class 0
25
+ */
26
+ static empty(): ClassDef;
27
+ /**
28
+ * Create Format 1 ClassDef (array of class values)
29
+ * @param startGlyphId - First glyph ID in the range
30
+ * @param classValueArray - Array of class values indexed by (glyphId - startGlyphId)
31
+ * @returns ClassDef instance using array lookup
32
+ */
33
+ static format1(startGlyphId: GlyphId, classValueArray: Uint16Array): ClassDef;
34
+ /**
35
+ * Create Format 2 ClassDef (ranges)
36
+ * @param ranges - Array of range records mapping glyph ranges to class values
37
+ * @returns ClassDef instance using hash map (for small tables) or binary search (for large tables)
38
+ */
39
+ static format2(ranges: ClassRangeRecord[]): ClassDef;
40
+ /**
41
+ * Get class for a glyph ID
42
+ * @param glyphId - The glyph ID to look up
43
+ * @returns Class value for the glyph, or 0 if not defined
44
+ */
6
45
  get(glyphId: GlyphId): number;
7
- /** Get all glyphs in a specific class */
46
+ /**
47
+ * Get all glyphs in a specific class
48
+ * @param classValue - The class value to search for
49
+ * @returns Array of all glyph IDs assigned to this class
50
+ */
8
51
  glyphsInClass(classValue: number): GlyphId[];
9
52
  }
10
- /** Singleton empty ClassDef */
53
+ /** Singleton empty ClassDef for external use */
11
54
  export declare const EMPTY_CLASS_DEF: ClassDef;
12
- /** Parse a Class Definition table */
55
+ /**
56
+ * Parse a Class Definition table from binary data
57
+ * @param reader - Binary reader positioned at class definition table start
58
+ * @returns Parsed ClassDef instance (Format 1 or Format 2)
59
+ */
13
60
  export declare function parseClassDef(reader: Reader): ClassDef;
14
- /** Parse ClassDef from offset, or return empty if offset is 0 */
61
+ /**
62
+ * Parse ClassDef from offset, or return empty if offset is 0
63
+ * @param reader - Binary reader positioned at parent table
64
+ * @param offset - Offset from reader's current position to class definition table
65
+ * @returns Parsed ClassDef instance, or empty ClassDef if offset is 0
66
+ */
15
67
  export declare function parseClassDefAt(reader: Reader, offset: number): ClassDef;
68
+ export {};
@@ -1,17 +1,64 @@
1
1
  import type { Reader } from "../../font/binary/reader.ts";
2
- import type { GlyphId } from "../../types.ts";
3
- /** Coverage table - maps glyph IDs to coverage indices */
4
- export interface Coverage {
5
- /** Get coverage index for a glyph ID, or null if not covered */
2
+ import type { GlyphId, uint16 } from "../../types.ts";
3
+ /** Range record for Format 2 */
4
+ interface RangeRecord {
5
+ startGlyphId: GlyphId;
6
+ endGlyphId: GlyphId;
7
+ startCoverageIndex: uint16;
8
+ }
9
+ /**
10
+ * Coverage table - maps glyph IDs to coverage indices.
11
+ *
12
+ * IMPORTANT: This is a unified class (not interface + implementations) to ensure
13
+ * monomorphic call sites in V8. Polymorphic calls can be 7-8x slower!
14
+ */
15
+ export declare class Coverage {
16
+ private readonly glyphMap;
17
+ private readonly ranges;
18
+ private readonly glyphArray;
19
+ readonly size: number;
20
+ private constructor();
21
+ /**
22
+ * Create Format 1 coverage (individual glyphs)
23
+ * @param glyphArray - Array of glyph IDs to cover
24
+ * @returns Coverage instance using hash map for O(1) lookup
25
+ */
26
+ static format1(glyphArray: Uint16Array): Coverage;
27
+ /**
28
+ * Create Format 2 coverage (ranges)
29
+ * @param ranges - Array of range records defining covered glyph ranges
30
+ * @returns Coverage instance using binary search for range lookup
31
+ */
32
+ static format2(ranges: RangeRecord[]): Coverage;
33
+ /**
34
+ * Get coverage index for a glyph ID
35
+ * @param glyphId - The glyph ID to look up
36
+ * @returns Coverage index (0-based) if glyph is covered, null otherwise
37
+ */
6
38
  get(glyphId: GlyphId): number | null;
7
- /** Check if glyph is covered */
39
+ /**
40
+ * Check if glyph is covered
41
+ * @param glyphId - The glyph ID to check
42
+ * @returns True if the glyph is in this coverage table
43
+ */
8
44
  covers(glyphId: GlyphId): boolean;
9
- /** Get all covered glyph IDs */
45
+ /**
46
+ * Get all covered glyph IDs
47
+ * @returns Array of all glyph IDs in this coverage table
48
+ */
10
49
  glyphs(): GlyphId[];
11
- /** Number of covered glyphs */
12
- readonly size: number;
13
50
  }
14
- /** Parse a Coverage table */
51
+ /**
52
+ * Parse a Coverage table from binary data
53
+ * @param reader - Binary reader positioned at coverage table start
54
+ * @returns Parsed coverage instance (Format 1 or Format 2)
55
+ */
15
56
  export declare function parseCoverage(reader: Reader): Coverage;
16
- /** Parse Coverage from offset (creates sub-reader) */
57
+ /**
58
+ * Parse Coverage from offset (creates sub-reader)
59
+ * @param reader - Binary reader positioned at parent table
60
+ * @param offset - Offset from reader's current position to coverage table
61
+ * @returns Parsed coverage instance
62
+ */
17
63
  export declare function parseCoverageAt(reader: Reader, offset: number): Coverage;
64
+ export {};
@@ -18,20 +18,38 @@ export interface VariationIndexTable {
18
18
  }
19
19
  /** Combined type - can be either Device or VariationIndex */
20
20
  export type DeviceOrVariationIndex = DeviceTable | VariationIndexTable;
21
- /** Check if this is a VariationIndex table */
21
+ /**
22
+ * Check if this is a VariationIndex table
23
+ * @param table - The device or variation index table to check
24
+ * @returns True if the table is a VariationIndex table, false if it's a Device table
25
+ */
22
26
  export declare function isVariationIndexTable(table: DeviceOrVariationIndex): table is VariationIndexTable;
23
- /** Parse Device or VariationIndex table at offset */
27
+ /**
28
+ * Parse Device or VariationIndex table at offset
29
+ * @param reader - Binary reader positioned at the parent table
30
+ * @param offset - Offset from reader's current position to the device table
31
+ * @returns Parsed device or variation index table, or null if offset is 0
32
+ */
24
33
  export declare function parseDeviceAt(reader: Reader, offset: number): DeviceOrVariationIndex | null;
25
- /** Parse Device or VariationIndex table */
34
+ /**
35
+ * Parse Device or VariationIndex table
36
+ * @param reader - Binary reader positioned at the device table start
37
+ * @returns Parsed device or variation index table
38
+ */
26
39
  export declare function parseDevice(reader: Reader): DeviceOrVariationIndex;
27
40
  /**
28
41
  * Get delta adjustment for a specific PPEM size
29
- * Returns 0 if the size is outside the table's range
42
+ * @param device - The device table to query
43
+ * @param ppem - Pixels per em size to get delta for
44
+ * @returns Delta adjustment value, or 0 if PPEM is outside the table's range
30
45
  */
31
46
  export declare function getDeviceDelta(device: DeviceTable, ppem: number): int16;
32
47
  /**
33
48
  * Apply Device table adjustment to a value
34
- * For variable fonts, this would need ItemVariationStore lookup instead
49
+ * @param device - The device or variation index table, or null
50
+ * @param value - The base value to adjust
51
+ * @param ppem - Pixels per em size for device table lookup
52
+ * @returns Adjusted value (for Device tables) or unchanged value (for VariationIndex tables or null)
35
53
  */
36
54
  export declare function applyDeviceAdjustment(device: DeviceOrVariationIndex | null, value: number, ppem: number): number;
37
55
  /**
@@ -49,6 +67,9 @@ export interface ResolvedValueRecord {
49
67
  }
50
68
  /**
51
69
  * Apply all Device adjustments to a resolved value record
70
+ * @param record - The value record containing placement and advance values with device tables
71
+ * @param ppem - Pixels per em size for device table lookups
72
+ * @returns Object containing adjusted xPlacement, yPlacement, xAdvance, and yAdvance values
52
73
  */
53
74
  export declare function applyDeviceAdjustments(record: ResolvedValueRecord, ppem: number): {
54
75
  xPlacement: number;
@@ -69,9 +69,24 @@ export declare function parseScriptList(reader: Reader): ScriptList;
69
69
  export declare function parseFeatureList(reader: Reader): FeatureList;
70
70
  /** Parse lookup headers (does not parse subtables) */
71
71
  export declare function parseLookupHeaders(reader: Reader): LookupHeader[];
72
- /** Find script in script list */
72
+ /**
73
+ * Find script in script list by tag
74
+ * @param scriptList - The script list to search
75
+ * @param scriptTag - The script tag to find (e.g., 'latn', 'arab')
76
+ * @returns The script table if found, null otherwise
77
+ */
73
78
  export declare function findScript(scriptList: ScriptList, scriptTag: Tag): Script | null;
74
- /** Find language system in script */
79
+ /**
80
+ * Find language system in script by tag
81
+ * @param script - The script table to search
82
+ * @param langSysTag - The language system tag to find (e.g., 'ENG', 'ARA'), or null for default
83
+ * @returns The language system table if found, or the default language system if langSysTag is null or not found
84
+ */
75
85
  export declare function findLangSys(script: Script, langSysTag: Tag | null): LangSys | null;
76
- /** Get feature by index */
86
+ /**
87
+ * Get feature by index from feature list
88
+ * @param featureList - The feature list to retrieve from
89
+ * @param index - The zero-based feature index
90
+ * @returns The feature record at the specified index, or null if index is out of bounds
91
+ */
77
92
  export declare function getFeature(featureList: FeatureList, index: number): FeatureRecord | null;
@@ -0,0 +1,59 @@
1
+ import type { GlyphId } from "../../types.ts";
2
+ import type { Coverage } from "./coverage.ts";
3
+ /**
4
+ * Set Digest - A Bloom filter for fast O(1) glyph membership rejection.
5
+ *
6
+ * Uses three 64-bit masks with different bit shifts (0, 4, 9) to minimize
7
+ * false positives. This is the same technique used by HarfBuzz/rustybuzz.
8
+ *
9
+ * The digest allows us to quickly reject glyphs that are definitely NOT
10
+ * in a lookup's coverage without doing expensive Coverage table lookups.
11
+ */
12
+ export declare class SetDigest {
13
+ private mask0;
14
+ private mask1;
15
+ private mask2;
16
+ /**
17
+ * Add a single glyph to the digest
18
+ * @param glyphId - The glyph ID to add
19
+ */
20
+ add(glyphId: GlyphId): void;
21
+ /**
22
+ * Add a range of glyphs to the digest
23
+ * @param start - Start glyph ID (inclusive)
24
+ * @param end - End glyph ID (inclusive)
25
+ */
26
+ addRange(start: GlyphId, end: GlyphId): void;
27
+ /**
28
+ * Fast check if glyph MAY be in the set
29
+ * @param glyphId - The glyph ID to check
30
+ * @returns False if glyph is definitely NOT in the set, true if glyph MAY be in the set (false positives possible)
31
+ */
32
+ mayHave(glyphId: GlyphId): boolean;
33
+ /**
34
+ * Add all glyphs from a Coverage table to this digest
35
+ * @param coverage - The coverage table containing glyphs to add
36
+ */
37
+ addCoverage(coverage: Coverage): void;
38
+ /**
39
+ * Check if this digest MAY intersect with another digest
40
+ * @param other - The other digest to check intersection with
41
+ * @returns False if there is definitely NO overlap, true if there MAY be overlap (false positives possible)
42
+ */
43
+ mayIntersect(other: SetDigest): boolean;
44
+ /**
45
+ * Get raw masks for external comparison
46
+ * @returns Object containing the three internal mask values
47
+ */
48
+ getMasks(): {
49
+ mask0: number;
50
+ mask1: number;
51
+ mask2: number;
52
+ };
53
+ }
54
+ /**
55
+ * Create a SetDigest from multiple Coverage tables (for a lookup with multiple subtables)
56
+ * @param coverages - Array of coverage tables to combine into a single digest
57
+ * @returns A new SetDigest containing all glyphs from all coverage tables
58
+ */
59
+ export declare function createLookupDigest(coverages: Coverage[]): SetDigest;
@@ -30,14 +30,11 @@ export interface AsymmetricStrokeOptions {
30
30
  }
31
31
  /**
32
32
  * Stroke a path with asymmetric X/Y borders
33
- *
33
+ * For filled text with border: combine outer outline with original fill,
34
+ * or use outer outline alone for hollow border effect
34
35
  * @param path Input path to stroke
35
36
  * @param options Stroke options including xBorder and yBorder
36
37
  * @returns Two paths: outer (positive offset) and inner (negative offset)
37
- *
38
- * For filled text with border:
39
- * - Combine outer outline with original fill
40
- * - Or use outer outline alone for hollow border effect
41
38
  */
42
39
  export declare function strokeAsymmetric(path: GlyphPath, options: AsymmetricStrokeOptions): {
43
40
  outer: GlyphPath;
@@ -46,10 +43,17 @@ export declare function strokeAsymmetric(path: GlyphPath, options: AsymmetricStr
46
43
  /**
47
44
  * Create a combined stroke path (both inner and outer as single path)
48
45
  * This creates a ring/donut shape that can be filled
46
+ * @param path Input path to stroke
47
+ * @param options Stroke options including xBorder and yBorder
48
+ * @returns Single path containing both outer and inner borders as a fillable ring
49
49
  */
50
50
  export declare function strokeAsymmetricCombined(path: GlyphPath, options: AsymmetricStrokeOptions): GlyphPath;
51
51
  /**
52
52
  * Stroke with uniform border (convenience function)
53
+ * @param path Input path to stroke
54
+ * @param border Border width in font units (applied to both X and Y)
55
+ * @param options Additional stroke options (precision, line join, miter limit)
56
+ * @returns Two paths: outer and inner borders
53
57
  */
54
58
  export declare function strokeUniform(path: GlyphPath, border: number, options?: Omit<AsymmetricStrokeOptions, "xBorder" | "yBorder">): {
55
59
  outer: GlyphPath;
@@ -5,73 +5,140 @@ import { type Bitmap, PixelMode } from "./types.ts";
5
5
  /**
6
6
  * Embolden a bitmap by dilating pixel values
7
7
  * Makes text bolder by spreading coverage in x and y directions
8
+ * @param bitmap Source bitmap to embolden
9
+ * @param xStrength Horizontal dilation strength in pixels
10
+ * @param yStrength Vertical dilation strength in pixels
11
+ * @returns New bitmap with emboldened content
8
12
  */
9
13
  export declare function emboldenBitmap(bitmap: Bitmap, xStrength: number, yStrength: number): Bitmap;
10
14
  /**
11
15
  * Convert bitmap between pixel modes
16
+ * @param bitmap Source bitmap to convert
17
+ * @param targetMode Target pixel format
18
+ * @returns New bitmap in the target format
12
19
  */
13
20
  export declare function convertBitmap(bitmap: Bitmap, targetMode: PixelMode): Bitmap;
14
21
  /**
15
22
  * Alpha blend src bitmap onto dst bitmap at position (x, y)
23
+ * @param dst Destination bitmap to blend onto (modified in place)
24
+ * @param src Source bitmap to blend
25
+ * @param x X position in destination
26
+ * @param y Y position in destination
27
+ * @param opacity Blend opacity from 0 to 1
16
28
  */
17
29
  export declare function blendBitmap(dst: Bitmap, src: Bitmap, x: number, y: number, opacity: number): void;
18
30
  /**
19
31
  * Create a deep copy of a bitmap
32
+ * @param bitmap Bitmap to copy
33
+ * @returns New bitmap with copied data
20
34
  */
21
35
  export declare function copyBitmap(bitmap: Bitmap): Bitmap;
22
36
  /**
23
37
  * Resize bitmap using nearest-neighbor interpolation
38
+ * @param bitmap Source bitmap to resize
39
+ * @param newWidth Target width in pixels
40
+ * @param newHeight Target height in pixels
41
+ * @returns New bitmap resized to target dimensions
24
42
  */
25
43
  export declare function resizeBitmap(bitmap: Bitmap, newWidth: number, newHeight: number): Bitmap;
44
+ /**
45
+ * Resize bitmap using bilinear interpolation
46
+ * Produces smoother results than nearest-neighbor, ideal for downsampling
47
+ * @param bitmap Source bitmap to resize
48
+ * @param newWidth Target width in pixels
49
+ * @param newHeight Target height in pixels
50
+ * @returns New bitmap resized with smooth interpolation
51
+ */
52
+ export declare function resizeBitmapBilinear(bitmap: Bitmap, newWidth: number, newHeight: number): Bitmap;
26
53
  /**
27
54
  * Add two bitmaps together (additive blend)
28
55
  * Result: dst = clamp(dst + src, 0, 255)
29
56
  * Used for combining glyph with shadow/glow
57
+ * @param dst Destination bitmap (modified in place)
58
+ * @param src Source bitmap to add
59
+ * @param srcX X offset of source in destination (default: 0)
60
+ * @param srcY Y offset of source in destination (default: 0)
30
61
  */
31
62
  export declare function addBitmaps(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void;
32
63
  /**
33
64
  * Multiply two bitmaps (multiplicative blend)
34
65
  * Result: dst = (dst * src) / 255
35
66
  * Used for masking operations
67
+ * @param dst Destination bitmap (modified in place)
68
+ * @param src Source bitmap to multiply
69
+ * @param srcX X offset of source in destination (default: 0)
70
+ * @param srcY Y offset of source in destination (default: 0)
36
71
  */
37
72
  export declare function mulBitmaps(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void;
38
73
  /**
39
74
  * Subtract src from dst (subtractive blend)
40
75
  * Result: dst = clamp(dst - src, 0, 255)
41
76
  * Used for outline effects
77
+ * @param dst Destination bitmap (modified in place)
78
+ * @param src Source bitmap to subtract
79
+ * @param srcX X offset of source in destination (default: 0)
80
+ * @param srcY Y offset of source in destination (default: 0)
42
81
  */
43
82
  export declare function subBitmaps(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void;
44
83
  /**
45
84
  * Alpha composite src over dst using src as alpha
46
85
  * Result: dst = src + dst * (1 - src/255)
47
86
  * Standard Porter-Duff "over" operation
87
+ * @param dst Destination bitmap (modified in place)
88
+ * @param src Source bitmap to composite
89
+ * @param srcX X offset of source in destination (default: 0)
90
+ * @param srcY Y offset of source in destination (default: 0)
48
91
  */
49
92
  export declare function compositeBitmaps(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void;
50
93
  /**
51
94
  * Shift bitmap position by integer offset
52
95
  * Creates a new bitmap with the content shifted
96
+ * @param bitmap Source bitmap to shift
97
+ * @param shiftX Horizontal shift in pixels
98
+ * @param shiftY Vertical shift in pixels
99
+ * @returns New bitmap with shifted content
53
100
  */
54
101
  export declare function shiftBitmap(bitmap: Bitmap, shiftX: number, shiftY: number): Bitmap;
55
102
  /**
56
103
  * Fix outline bitmap by removing glyph interior
57
104
  * Used when you want only the border, not the filled shape
58
105
  * Result: outline = outline - glyph (where glyph coverage > threshold)
106
+ * @param outlineBitmap Outline bitmap to fix (modified in place)
107
+ * @param glyphBitmap Glyph bitmap containing filled shape
108
+ * @param glyphX X position of glyph in outline (default: 0)
109
+ * @param glyphY Y position of glyph in outline (default: 0)
110
+ * @param threshold Coverage threshold for removal (default: 128)
59
111
  */
60
112
  export declare function fixOutline(outlineBitmap: Bitmap, glyphBitmap: Bitmap, glyphX?: number, glyphY?: number, threshold?: number): void;
61
113
  /**
62
114
  * Maximum blend: take the maximum of two bitmaps
63
115
  * Result: dst = max(dst, src)
64
116
  * Used for combining multiple layers
117
+ * @param dst Destination bitmap (modified in place)
118
+ * @param src Source bitmap to compare
119
+ * @param srcX X offset of source in destination (default: 0)
120
+ * @param srcY Y offset of source in destination (default: 0)
65
121
  */
66
122
  export declare function maxBitmaps(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void;
67
123
  /**
68
124
  * Create a padded copy of a bitmap with extra space around edges
69
125
  * Useful before blur operations to prevent edge artifacts
126
+ * @param bitmap Source bitmap to pad
127
+ * @param padLeft Left padding in pixels
128
+ * @param padTop Top padding in pixels
129
+ * @param padRight Right padding in pixels
130
+ * @param padBottom Bottom padding in pixels
131
+ * @returns New bitmap with padding added
70
132
  */
71
133
  export declare function padBitmap(bitmap: Bitmap, padLeft: number, padTop: number, padRight: number, padBottom: number): Bitmap;
72
134
  /**
73
135
  * Create an expanded bitmap that can contain both dst and src
74
136
  * Returns the expanded bitmap and the offsets for both original bitmaps
137
+ * @param dst Destination bitmap
138
+ * @param src Source bitmap to fit
139
+ * @param srcX X position of source relative to destination
140
+ * @param srcY Y position of source relative to destination
141
+ * @returns Expanded bitmap and offset positions for both original bitmaps
75
142
  */
76
143
  export declare function expandToFit(dst: Bitmap, src: Bitmap, srcX: number, srcY: number): {
77
144
  expanded: Bitmap;
@@ -5,16 +5,27 @@ import { type Bitmap } from "./types.ts";
5
5
  /**
6
6
  * Generate 1D Gaussian kernel
7
7
  * Uses Gaussian function: exp(-x²/(2σ²))
8
+ *
9
+ * @param radius Blur radius (sigma value)
10
+ * @returns Normalized Gaussian kernel weights
8
11
  */
9
12
  export declare function createGaussianKernel(radius: number): Float32Array;
10
13
  /**
11
14
  * Gaussian blur implementation using separable 2-pass algorithm
12
15
  * Modifies bitmap in-place and returns it
16
+ *
17
+ * @param bitmap Bitmap to blur (modified in-place)
18
+ * @param radius Blur radius in pixels
19
+ * @returns The same bitmap after blur is applied
13
20
  */
14
21
  export declare function gaussianBlur(bitmap: Bitmap, radius: number): Bitmap;
15
22
  /**
16
23
  * Box blur using running sum for O(1) per pixel
17
24
  * Modifies bitmap in-place and returns it
25
+ *
26
+ * @param bitmap Bitmap to blur (modified in-place)
27
+ * @param radius Blur radius in pixels
28
+ * @returns The same bitmap after blur is applied
18
29
  */
19
30
  export declare function boxBlur(bitmap: Bitmap, radius: number): Bitmap;
20
31
  /**
@@ -17,29 +17,28 @@
17
17
  import { type Bitmap } from "./types.ts";
18
18
  /**
19
19
  * Cascade Gaussian blur with asymmetric X/Y radii
20
- *
21
- * @param bitmap Input bitmap
22
- * @param radiusX Blur radius along X axis
23
- * @param radiusY Blur radius along Y axis (defaults to radiusX)
20
+ * High-performance blur using pyramid scaling for large radii
21
+ * @param bitmap Input bitmap to blur
22
+ * @param radiusX Blur radius along X axis in pixels
23
+ * @param radiusY Blur radius along Y axis in pixels (defaults to radiusX)
24
24
  * @returns New bitmap with blur applied (dimensions may change)
25
25
  */
26
26
  export declare function cascadeBlur(bitmap: Bitmap, radiusX: number, radiusY?: number): Bitmap;
27
27
  /**
28
28
  * Fast Gaussian blur using cascade algorithm
29
29
  * This is the recommended blur function for large radii (> 3 pixels)
30
- *
31
- * @param bitmap Input bitmap
30
+ * @param bitmap Input bitmap to blur
32
31
  * @param radius Blur radius in pixels
33
32
  * @returns New bitmap with blur applied (dimensions may change)
34
33
  */
35
34
  export declare function fastGaussianBlur(bitmap: Bitmap, radius: number): Bitmap;
36
35
  /**
37
36
  * Adaptive blur that chooses the best algorithm based on radius
38
- * - For small radii (≤ 3): uses simple separable Gaussian (more precise)
39
- * - For large radii (> 3): uses cascade algorithm (faster)
40
- *
41
- * @param bitmap Input bitmap
37
+ * For small radii (≤ 3): uses simple separable Gaussian (more precise)
38
+ * For large radii (> 3): uses cascade algorithm (faster)
39
+ * @param bitmap Input bitmap to blur
42
40
  * @param radiusX Horizontal blur radius in pixels
43
41
  * @param radiusY Vertical blur radius in pixels (defaults to radiusX)
42
+ * @returns Blurred bitmap using the optimal algorithm
44
43
  */
45
44
  export declare function adaptiveBlur(bitmap: Bitmap, radiusX: number, radiusY?: number): Bitmap;
@@ -110,6 +110,30 @@ export declare class CellBuffer {
110
110
  y: number;
111
111
  cells: Cell[];
112
112
  }>;
113
+ /**
114
+ * Iterate scanlines directly without allocating cell arrays
115
+ * Returns first cell index for each row, caller walks linked list via pool
116
+ */
117
+ iterateScanlines(): Generator<{
118
+ y: number;
119
+ firstCellIndex: number;
120
+ }>;
121
+ /**
122
+ * Get the cell pool for direct access during sweep
123
+ */
124
+ getPool(): Cell[];
125
+ /**
126
+ * Get the null cell index (sentinel value)
127
+ */
128
+ getNullIndex(): number;
129
+ /**
130
+ * Get ycells array for direct iteration (avoids generator overhead)
131
+ */
132
+ getYCells(): number[];
133
+ /**
134
+ * Get band minimum Y for coordinate calculation
135
+ */
136
+ getBandMinY(): number;
113
137
  /**
114
138
  * Iterate cells for a single row (for band sweep)
115
139
  */
@@ -57,7 +57,7 @@ export declare function upscale(x: number): number;
57
57
  export declare function downscale(x: number): number;
58
58
  /**
59
59
  * Multiply two fixed-point numbers and divide, avoiding overflow
60
- * Computes (a * b) / c with 64-bit intermediate precision
60
+ * Computes (a * b) / c with 64-bit intermediate precision when needed
61
61
  */
62
62
  export declare function mulDiv(a: number, b: number, c: number): number;
63
63
  /**
@@ -48,14 +48,29 @@ export interface RadialGradient {
48
48
  export type Gradient = LinearGradient | RadialGradient;
49
49
  /**
50
50
  * Get color at position in gradient
51
+ *
52
+ * @param gradient Linear or radial gradient definition
53
+ * @param x X coordinate
54
+ * @param y Y coordinate
55
+ * @returns RGBA color at position (0-255 each)
51
56
  */
52
57
  export declare function interpolateGradient(gradient: Gradient, x: number, y: number): [number, number, number, number];
53
58
  /**
54
59
  * Create a bitmap filled with gradient (no path)
60
+ *
61
+ * @param width Width in pixels
62
+ * @param height Height in pixels
63
+ * @param gradient Linear or radial gradient definition
64
+ * @returns RGBA bitmap filled with gradient
55
65
  */
56
66
  export declare function createGradientBitmap(width: number, height: number, gradient: Gradient): Bitmap;
57
67
  /**
58
68
  * Rasterize path with gradient fill
59
69
  * First rasterizes path to get coverage mask, then fills with gradient
70
+ *
71
+ * @param path Glyph path to rasterize
72
+ * @param gradient Linear or radial gradient definition
73
+ * @param options Rasterization options (width, height, scale, etc.)
74
+ * @returns RGBA bitmap with gradient-filled path
60
75
  */
61
76
  export declare function rasterizePathWithGradient(path: GlyphPath, gradient: Gradient, options: RasterizeOptions): Bitmap;
@@ -67,9 +67,15 @@ export declare class GrayRaster {
67
67
  */
68
68
  private mulDiv;
69
69
  /**
70
- * Draw a quadratic Bezier curve using simple parametric sampling
70
+ * Draw a quadratic Bezier curve using adaptive subdivision
71
+ * Uses flatness test to minimize line segments at small font sizes
71
72
  */
72
73
  conicTo(cx: number, cy: number, toX: number, toY: number): void;
74
+ /**
75
+ * Recursive quadratic subdivision with flatness test
76
+ * Uses FreeType-style flatness: check if control point is within threshold of chord
77
+ */
78
+ private subdivConic;
73
79
  /**
74
80
  * Draw a cubic Bezier curve
75
81
  */