text-shaper 0.0.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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +161 -0
  3. package/dist/aat/state-machine.d.ts +34 -0
  4. package/dist/buffer/glyph-buffer.d.ts +55 -0
  5. package/dist/buffer/unicode-buffer.d.ts +51 -0
  6. package/dist/font/binary/reader.d.ts +72 -0
  7. package/dist/font/face.d.ts +65 -0
  8. package/dist/font/font.d.ts +189 -0
  9. package/dist/font/tables/avar.d.ts +36 -0
  10. package/dist/font/tables/base.d.ts +79 -0
  11. package/dist/font/tables/cbdt.d.ts +120 -0
  12. package/dist/font/tables/cff-charstring.d.ts +16 -0
  13. package/dist/font/tables/cff.d.ts +93 -0
  14. package/dist/font/tables/cff2.d.ts +85 -0
  15. package/dist/font/tables/cmap.d.ts +81 -0
  16. package/dist/font/tables/colr.d.ts +278 -0
  17. package/dist/font/tables/cpal.d.ts +46 -0
  18. package/dist/font/tables/feat.d.ts +359 -0
  19. package/dist/font/tables/fvar.d.ts +77 -0
  20. package/dist/font/tables/gdef.d.ts +45 -0
  21. package/dist/font/tables/glyf.d.ts +118 -0
  22. package/dist/font/tables/gpos-contextual.d.ts +88 -0
  23. package/dist/font/tables/gpos-mark.d.ts +95 -0
  24. package/dist/font/tables/gpos.d.ts +137 -0
  25. package/dist/font/tables/gsub-contextual.d.ts +88 -0
  26. package/dist/font/tables/gsub.d.ts +107 -0
  27. package/dist/font/tables/gvar.d.ts +56 -0
  28. package/dist/font/tables/head.d.ts +47 -0
  29. package/dist/font/tables/hhea.d.ts +24 -0
  30. package/dist/font/tables/hmtx.d.ts +23 -0
  31. package/dist/font/tables/hvar.d.ts +77 -0
  32. package/dist/font/tables/jstf.d.ts +97 -0
  33. package/dist/font/tables/kern.d.ts +44 -0
  34. package/dist/font/tables/kerx.d.ts +108 -0
  35. package/dist/font/tables/loca.d.ts +31 -0
  36. package/dist/font/tables/math.d.ts +168 -0
  37. package/dist/font/tables/maxp.d.ts +27 -0
  38. package/dist/font/tables/morx.d.ts +142 -0
  39. package/dist/font/tables/mvar.d.ts +99 -0
  40. package/dist/font/tables/name.d.ts +75 -0
  41. package/dist/font/tables/os2.d.ts +102 -0
  42. package/dist/font/tables/post.d.ts +25 -0
  43. package/dist/font/tables/sbix.d.ts +65 -0
  44. package/dist/font/tables/sfnt.d.ts +20 -0
  45. package/dist/font/tables/stat.d.ts +115 -0
  46. package/dist/font/tables/svg.d.ts +40 -0
  47. package/dist/font/tables/trak.d.ts +43 -0
  48. package/dist/font/tables/vhea.d.ts +41 -0
  49. package/dist/font/tables/vmtx.d.ts +35 -0
  50. package/dist/font/tables/vorg.d.ts +33 -0
  51. package/dist/font/tables/vvar.d.ts +36 -0
  52. package/dist/index.d.ts +80 -0
  53. package/dist/index.js +9 -0
  54. package/dist/index.js.map +92 -0
  55. package/dist/index.test.d.ts +1 -0
  56. package/dist/layout/justify.d.ts +88 -0
  57. package/dist/layout/structures/class-def.d.ts +15 -0
  58. package/dist/layout/structures/coverage.d.ts +17 -0
  59. package/dist/layout/structures/device.d.ts +58 -0
  60. package/dist/layout/structures/feature-variations.d.ts +82 -0
  61. package/dist/layout/structures/layout-common.d.ts +77 -0
  62. package/dist/render/path.d.ts +136 -0
  63. package/dist/shaper/complex/arabic.d.ts +60 -0
  64. package/dist/shaper/complex/ethiopic.d.ts +70 -0
  65. package/dist/shaper/complex/georgian.d.ts +69 -0
  66. package/dist/shaper/complex/hangul.d.ts +64 -0
  67. package/dist/shaper/complex/hebrew.d.ts +28 -0
  68. package/dist/shaper/complex/indic.d.ts +117 -0
  69. package/dist/shaper/complex/khmer.d.ts +48 -0
  70. package/dist/shaper/complex/mongolian.d.ts +89 -0
  71. package/dist/shaper/complex/myanmar.d.ts +47 -0
  72. package/dist/shaper/complex/syriac.d.ts +80 -0
  73. package/dist/shaper/complex/thai-lao.d.ts +42 -0
  74. package/dist/shaper/complex/tibetan.d.ts +57 -0
  75. package/dist/shaper/complex/use.d.ts +80 -0
  76. package/dist/shaper/fallback.d.ts +16 -0
  77. package/dist/shaper/features.d.ts +189 -0
  78. package/dist/shaper/shape-plan.d.ts +29 -0
  79. package/dist/shaper/shaper.d.ts +18 -0
  80. package/dist/types.d.ts +153 -0
  81. package/dist/typeshaper.js +7 -0
  82. package/dist/unicode/bidi/brackets.d.ts +7 -0
  83. package/dist/unicode/bidi/brackets.data.d.ts +5 -0
  84. package/dist/unicode/bidi/char-types.d.ts +19 -0
  85. package/dist/unicode/bidi/char-types.data.d.ts +25 -0
  86. package/dist/unicode/bidi/embedding-levels.d.ts +18 -0
  87. package/dist/unicode/bidi/index.d.ts +9 -0
  88. package/dist/unicode/bidi/mirroring.d.ts +10 -0
  89. package/dist/unicode/bidi/mirroring.data.d.ts +2 -0
  90. package/dist/unicode/bidi/parse-character-map.d.ts +8 -0
  91. package/dist/unicode/bidi/reordering.d.ts +18 -0
  92. package/dist/unicode/bidi.d.ts +93 -0
  93. package/dist/unicode/line-break.d.ts +113 -0
  94. package/dist/unicode/normalize.d.ts +36 -0
  95. package/dist/unicode/script.d.ts +215 -0
  96. package/dist/unicode/segmentation.d.ts +104 -0
  97. package/package.json +33 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,88 @@
1
+ import { GlyphBuffer } from "../buffer/glyph-buffer.ts";
2
+ import type { Font } from "../font/font.ts";
3
+ import type { GlyphId, Tag } from "../types.ts";
4
+ /**
5
+ * Justification mode
6
+ */
7
+ export declare enum JustifyMode {
8
+ /** Shrink text to fit */
9
+ Shrink = "shrink",
10
+ /** Extend text to fit */
11
+ Extend = "extend",
12
+ /** Auto-select based on delta */
13
+ Auto = "auto"
14
+ }
15
+ /**
16
+ * Justification options
17
+ */
18
+ export interface JustifyOptions {
19
+ /** Target line width */
20
+ targetWidth: number;
21
+ /** Script tag */
22
+ script?: Tag;
23
+ /** Language tag */
24
+ language?: Tag;
25
+ /** Justification mode */
26
+ mode?: JustifyMode;
27
+ /** Maximum priority level to use (0-based) */
28
+ maxPriority?: number;
29
+ /** Enable Kashida insertion for Arabic */
30
+ enableKashida?: boolean;
31
+ /** Minimum word spacing factor (default: 0.8) */
32
+ minWordSpacingFactor?: number;
33
+ /** Maximum word spacing factor (default: 1.5) */
34
+ maxWordSpacingFactor?: number;
35
+ /** Enable inter-character spacing adjustment */
36
+ enableLetterSpacing?: boolean;
37
+ /** Maximum letter spacing in font units */
38
+ maxLetterSpacing?: number;
39
+ }
40
+ /**
41
+ * Justification result
42
+ */
43
+ export interface JustifyResult {
44
+ /** Whether justification succeeded */
45
+ success: boolean;
46
+ /** Final line width after justification */
47
+ finalWidth: number;
48
+ /** Delta from target (positive = too wide, negative = too narrow) */
49
+ delta: number;
50
+ /** Priority level used */
51
+ priorityLevel: number;
52
+ /** Adjustments applied */
53
+ adjustments: JustifyAdjustment[];
54
+ }
55
+ /**
56
+ * Individual justification adjustment
57
+ */
58
+ export interface JustifyAdjustment {
59
+ type: "spacing" | "kashida" | "lookup";
60
+ /** Glyph indices affected */
61
+ glyphIndices: number[];
62
+ /** Adjustment value */
63
+ value: number;
64
+ }
65
+ /**
66
+ * Calculate current line width from glyph buffer
67
+ */
68
+ export declare function calculateLineWidth(buffer: GlyphBuffer): number;
69
+ /**
70
+ * Justify a shaped glyph buffer to fit a target width
71
+ */
72
+ export declare function justify(font: Font, buffer: GlyphBuffer, options: JustifyOptions): JustifyResult;
73
+ /**
74
+ * Simple line breaking for multi-line text
75
+ */
76
+ export interface LineBreakResult {
77
+ lines: GlyphBuffer[];
78
+ breakPoints: number[];
79
+ }
80
+ /**
81
+ * Break shaped text into lines at a given width
82
+ * Uses simple greedy algorithm
83
+ */
84
+ export declare function breakIntoLines(buffer: GlyphBuffer, maxWidth: number, spaceGlyph?: GlyphId): LineBreakResult;
85
+ /**
86
+ * Justify all lines in a paragraph to the same width
87
+ */
88
+ export declare function justifyParagraph(font: Font, lines: GlyphBuffer[], options: JustifyOptions): JustifyResult[];
@@ -0,0 +1,15 @@
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) */
6
+ get(glyphId: GlyphId): number;
7
+ /** Get all glyphs in a specific class */
8
+ glyphsInClass(classValue: number): GlyphId[];
9
+ }
10
+ /** Singleton empty ClassDef */
11
+ export declare const EMPTY_CLASS_DEF: ClassDef;
12
+ /** Parse a Class Definition table */
13
+ export declare function parseClassDef(reader: Reader): ClassDef;
14
+ /** Parse ClassDef from offset, or return empty if offset is 0 */
15
+ export declare function parseClassDefAt(reader: Reader, offset: number): ClassDef;
@@ -0,0 +1,17 @@
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 */
6
+ get(glyphId: GlyphId): number | null;
7
+ /** Check if glyph is covered */
8
+ covers(glyphId: GlyphId): boolean;
9
+ /** Get all covered glyph IDs */
10
+ glyphs(): GlyphId[];
11
+ /** Number of covered glyphs */
12
+ readonly size: number;
13
+ }
14
+ /** Parse a Coverage table */
15
+ export declare function parseCoverage(reader: Reader): Coverage;
16
+ /** Parse Coverage from offset (creates sub-reader) */
17
+ export declare function parseCoverageAt(reader: Reader, offset: number): Coverage;
@@ -0,0 +1,58 @@
1
+ import type { Reader } from "../../font/binary/reader.ts";
2
+ import type { int16, uint16 } from "../../types.ts";
3
+ /**
4
+ * Device table - pixel-level adjustments for different PPEM sizes
5
+ * Used in GPOS for fine-tuning positioning at specific sizes
6
+ */
7
+ export interface DeviceTable {
8
+ startSize: uint16;
9
+ endSize: uint16;
10
+ deltaFormat: uint16;
11
+ /** Delta values indexed by (ppem - startSize) */
12
+ deltaValues: int16[];
13
+ }
14
+ /** VariationIndex table for variable fonts (shares format with Device) */
15
+ export interface VariationIndexTable {
16
+ deltaSetOuterIndex: uint16;
17
+ deltaSetInnerIndex: uint16;
18
+ }
19
+ /** Combined type - can be either Device or VariationIndex */
20
+ export type DeviceOrVariationIndex = DeviceTable | VariationIndexTable;
21
+ /** Check if this is a VariationIndex table */
22
+ export declare function isVariationIndexTable(table: DeviceOrVariationIndex): table is VariationIndexTable;
23
+ /** Parse Device or VariationIndex table at offset */
24
+ export declare function parseDeviceAt(reader: Reader, offset: number): DeviceOrVariationIndex | null;
25
+ /** Parse Device or VariationIndex table */
26
+ export declare function parseDevice(reader: Reader): DeviceOrVariationIndex;
27
+ /**
28
+ * Get delta adjustment for a specific PPEM size
29
+ * Returns 0 if the size is outside the table's range
30
+ */
31
+ export declare function getDeviceDelta(device: DeviceTable, ppem: number): int16;
32
+ /**
33
+ * Apply Device table adjustment to a value
34
+ * For variable fonts, this would need ItemVariationStore lookup instead
35
+ */
36
+ export declare function applyDeviceAdjustment(device: DeviceOrVariationIndex | null, value: number, ppem: number): number;
37
+ /**
38
+ * Parsed value record with resolved Device tables
39
+ */
40
+ export interface ResolvedValueRecord {
41
+ xPlacement: number;
42
+ yPlacement: number;
43
+ xAdvance: number;
44
+ yAdvance: number;
45
+ xPlaDevice: DeviceOrVariationIndex | null;
46
+ yPlaDevice: DeviceOrVariationIndex | null;
47
+ xAdvDevice: DeviceOrVariationIndex | null;
48
+ yAdvDevice: DeviceOrVariationIndex | null;
49
+ }
50
+ /**
51
+ * Apply all Device adjustments to a resolved value record
52
+ */
53
+ export declare function applyDeviceAdjustments(record: ResolvedValueRecord, ppem: number): {
54
+ xPlacement: number;
55
+ yPlacement: number;
56
+ xAdvance: number;
57
+ yAdvance: number;
58
+ };
@@ -0,0 +1,82 @@
1
+ import type { Reader } from "../../font/binary/reader.ts";
2
+ import type { Tag, uint16 } from "../../types.ts";
3
+ /**
4
+ * FeatureVariations table
5
+ * Allows different feature substitutions based on variation axis coordinates
6
+ * Used in GSUB/GPOS for variable fonts
7
+ */
8
+ export interface FeatureVariations {
9
+ majorVersion: number;
10
+ minorVersion: number;
11
+ featureVariationRecords: FeatureVariationRecord[];
12
+ }
13
+ /**
14
+ * Feature variation record
15
+ * Contains a condition set and feature substitutions to apply when conditions are met
16
+ */
17
+ export interface FeatureVariationRecord {
18
+ conditionSet: ConditionSet;
19
+ featureTableSubstitution: FeatureTableSubstitution;
20
+ }
21
+ /**
22
+ * Condition set - all conditions must be met
23
+ */
24
+ export interface ConditionSet {
25
+ conditions: Condition[];
26
+ }
27
+ /**
28
+ * Single axis condition
29
+ */
30
+ export interface Condition {
31
+ format: number;
32
+ axisIndex: uint16;
33
+ filterRangeMinValue: number;
34
+ filterRangeMaxValue: number;
35
+ }
36
+ /**
37
+ * Feature table substitution
38
+ * Maps feature indices to replacement feature tables
39
+ */
40
+ export interface FeatureTableSubstitution {
41
+ majorVersion: number;
42
+ minorVersion: number;
43
+ substitutions: FeatureSubstitutionRecord[];
44
+ }
45
+ /**
46
+ * Single feature substitution record
47
+ */
48
+ export interface FeatureSubstitutionRecord {
49
+ featureIndex: uint16;
50
+ alternateFeature: AlternateFeature;
51
+ }
52
+ /**
53
+ * Alternate feature table
54
+ */
55
+ export interface AlternateFeature {
56
+ featureParamsOffset: uint16;
57
+ lookupListIndices: uint16[];
58
+ }
59
+ /**
60
+ * Parse FeatureVariations table
61
+ */
62
+ export declare function parseFeatureVariations(reader: Reader): FeatureVariations;
63
+ /**
64
+ * Evaluate condition set against axis coordinates
65
+ * Returns true if all conditions are met
66
+ */
67
+ export declare function evaluateConditionSet(conditionSet: ConditionSet, axisCoords: number[]): boolean;
68
+ /**
69
+ * Find matching feature variation record for given axis coordinates
70
+ * Returns the first matching record, or null if none match
71
+ */
72
+ export declare function findMatchingFeatureVariation(featureVariations: FeatureVariations, axisCoords: number[]): FeatureVariationRecord | null;
73
+ /**
74
+ * Get substituted lookup list indices for a feature
75
+ * Returns the original lookups if no substitution applies
76
+ */
77
+ export declare function getSubstitutedLookups(featureVariations: FeatureVariations | null, featureIndex: number, originalLookups: uint16[], axisCoords: number[] | null): uint16[];
78
+ /**
79
+ * Apply feature variations to a feature list
80
+ * Returns a modified feature list with substituted lookup indices
81
+ */
82
+ export declare function applyFeatureVariations(featureVariations: FeatureVariations | null, featureLookups: Map<Tag, uint16[]>, featureIndices: Map<Tag, number>, axisCoords: number[] | null): Map<Tag, uint16[]>;
@@ -0,0 +1,77 @@
1
+ import type { Reader } from "../../font/binary/reader.ts";
2
+ import type { Tag, uint16 } from "../../types.ts";
3
+ /** Language system record */
4
+ export interface LangSysRecord {
5
+ langSysTag: Tag;
6
+ langSys: LangSys;
7
+ }
8
+ /** Language system table */
9
+ export interface LangSys {
10
+ /** Required feature index (0xFFFF if none) */
11
+ requiredFeatureIndex: uint16;
12
+ /** Feature indices */
13
+ featureIndices: uint16[];
14
+ }
15
+ /** Script record */
16
+ export interface ScriptRecord {
17
+ scriptTag: Tag;
18
+ script: Script;
19
+ }
20
+ /** Script table */
21
+ export interface Script {
22
+ /** Default language system (may be null) */
23
+ defaultLangSys: LangSys | null;
24
+ /** Language system records */
25
+ langSysRecords: LangSysRecord[];
26
+ }
27
+ /** Script list table */
28
+ export interface ScriptList {
29
+ scripts: ScriptRecord[];
30
+ }
31
+ /** Feature record */
32
+ export interface FeatureRecord {
33
+ featureTag: Tag;
34
+ feature: Feature;
35
+ }
36
+ /** Feature table */
37
+ export interface Feature {
38
+ /** Feature parameters offset (usually 0) */
39
+ featureParamsOffset: uint16;
40
+ /** Lookup indices */
41
+ lookupListIndices: uint16[];
42
+ }
43
+ /** Feature list table */
44
+ export interface FeatureList {
45
+ features: FeatureRecord[];
46
+ }
47
+ /** Lookup table header */
48
+ export interface LookupHeader {
49
+ lookupType: uint16;
50
+ lookupFlag: uint16;
51
+ subtableOffsets: uint16[];
52
+ /** Mark filtering set (if UseMarkFilteringSet flag is set) */
53
+ markFilteringSet?: uint16;
54
+ }
55
+ /** Lookup flags */
56
+ export declare const LookupFlag: {
57
+ readonly RightToLeft: 1;
58
+ readonly IgnoreBaseGlyphs: 2;
59
+ readonly IgnoreLigatures: 4;
60
+ readonly IgnoreMarks: 8;
61
+ readonly UseMarkFilteringSet: 16;
62
+ readonly MarkAttachmentTypeMask: 65280;
63
+ };
64
+ /** Extract mark attachment type from lookup flag */
65
+ export declare function getMarkAttachmentType(lookupFlag: uint16): number;
66
+ /** Parse ScriptList */
67
+ export declare function parseScriptList(reader: Reader): ScriptList;
68
+ /** Parse FeatureList */
69
+ export declare function parseFeatureList(reader: Reader): FeatureList;
70
+ /** Parse lookup headers (does not parse subtables) */
71
+ export declare function parseLookupHeaders(reader: Reader): LookupHeader[];
72
+ /** Find script in script list */
73
+ export declare function findScript(scriptList: ScriptList, scriptTag: Tag): Script | null;
74
+ /** Find language system in script */
75
+ export declare function findLangSys(script: Script, langSysTag: Tag | null): LangSys | null;
76
+ /** Get feature by index */
77
+ export declare function getFeature(featureList: FeatureList, index: number): FeatureRecord | null;
@@ -0,0 +1,136 @@
1
+ import type { GlyphBuffer } from "../buffer/glyph-buffer.ts";
2
+ import type { Font } from "../font/font.ts";
3
+ import type { Contour } from "../font/tables/glyf.ts";
4
+ import type { GlyphId } from "../types.ts";
5
+ /**
6
+ * Path command types for glyph rendering
7
+ */
8
+ export type PathCommand = {
9
+ type: "M";
10
+ x: number;
11
+ y: number;
12
+ } | {
13
+ type: "L";
14
+ x: number;
15
+ y: number;
16
+ } | {
17
+ type: "Q";
18
+ x1: number;
19
+ y1: number;
20
+ x: number;
21
+ y: number;
22
+ } | {
23
+ type: "C";
24
+ x1: number;
25
+ y1: number;
26
+ x2: number;
27
+ y2: number;
28
+ x: number;
29
+ y: number;
30
+ } | {
31
+ type: "Z";
32
+ };
33
+ /**
34
+ * A glyph path is a series of drawing commands
35
+ */
36
+ export interface GlyphPath {
37
+ commands: PathCommand[];
38
+ bounds: {
39
+ xMin: number;
40
+ yMin: number;
41
+ xMax: number;
42
+ yMax: number;
43
+ } | null;
44
+ }
45
+ /**
46
+ * Convert TrueType contours to path commands
47
+ * TrueType uses quadratic Bézier curves with on-curve and off-curve points
48
+ */
49
+ export declare function contourToPath(contour: Contour): PathCommand[];
50
+ /**
51
+ * Get path commands for a glyph
52
+ */
53
+ export declare function getGlyphPath(font: Font, glyphId: GlyphId): GlyphPath | null;
54
+ /**
55
+ * Convert path commands to SVG path data string
56
+ */
57
+ export declare function pathToSVG(path: GlyphPath, options?: {
58
+ flipY?: boolean;
59
+ scale?: number;
60
+ }): string;
61
+ /**
62
+ * Render path commands to a Canvas 2D context
63
+ */
64
+ export declare function pathToCanvas(ctx: CanvasRenderingContext2D | Path2D, path: GlyphPath, options?: {
65
+ flipY?: boolean;
66
+ scale?: number;
67
+ offsetX?: number;
68
+ offsetY?: number;
69
+ }): void;
70
+ /**
71
+ * Generate an SVG element for a glyph
72
+ */
73
+ export declare function glyphToSVG(font: Font, glyphId: GlyphId, options?: {
74
+ fontSize?: number;
75
+ fill?: string;
76
+ }): string | null;
77
+ /**
78
+ * Render shaped text to Canvas
79
+ */
80
+ export interface ShapedGlyph {
81
+ glyphId: GlyphId;
82
+ xOffset: number;
83
+ yOffset: number;
84
+ xAdvance: number;
85
+ yAdvance: number;
86
+ }
87
+ export declare function renderShapedText(ctx: CanvasRenderingContext2D, font: Font, glyphs: ShapedGlyph[], options?: {
88
+ fontSize?: number;
89
+ x?: number;
90
+ y?: number;
91
+ fill?: string;
92
+ }): void;
93
+ /**
94
+ * Generate SVG for shaped text
95
+ */
96
+ export declare function shapedTextToSVG(font: Font, glyphs: ShapedGlyph[], options?: {
97
+ fontSize?: number;
98
+ fill?: string;
99
+ }): string;
100
+ /**
101
+ * Convert GlyphBuffer output to ShapedGlyph array
102
+ */
103
+ export declare function glyphBufferToShapedGlyphs(buffer: GlyphBuffer): ShapedGlyph[];
104
+ /**
105
+ * Get glyph path with variable font variation applied
106
+ */
107
+ export declare function getGlyphPathWithVariation(font: Font, glyphId: GlyphId, axisCoords: number[]): GlyphPath | null;
108
+ /**
109
+ * Render shaped text with variable font support
110
+ */
111
+ export declare function renderShapedTextWithVariation(ctx: CanvasRenderingContext2D, font: Font, glyphs: ShapedGlyph[], axisCoords: number[], options?: {
112
+ fontSize?: number;
113
+ x?: number;
114
+ y?: number;
115
+ fill?: string;
116
+ }): void;
117
+ /**
118
+ * Generate SVG for shaped text with variable font support
119
+ */
120
+ export declare function shapedTextToSVGWithVariation(font: Font, glyphs: ShapedGlyph[], axisCoords: number[], options?: {
121
+ fontSize?: number;
122
+ fill?: string;
123
+ }): string;
124
+ /**
125
+ * Calculate the total advance width of shaped text
126
+ */
127
+ export declare function getTextWidth(glyphs: ShapedGlyph[], font: Font, fontSize: number): number;
128
+ /**
129
+ * Create a Path2D object from glyph path
130
+ */
131
+ export declare function createPath2D(path: GlyphPath, options?: {
132
+ flipY?: boolean;
133
+ scale?: number;
134
+ offsetX?: number;
135
+ offsetY?: number;
136
+ }): Path2D;
@@ -0,0 +1,60 @@
1
+ import type { GlyphInfo } from "../../types.ts";
2
+ /**
3
+ * Arabic joining types from Unicode
4
+ */
5
+ export declare enum ArabicJoiningType {
6
+ NonJoining = "U",// Non_Joining
7
+ RightJoining = "R",// Right_Joining (joins on the right)
8
+ DualJoining = "D",// Dual_Joining (joins on both sides)
9
+ JoinCausing = "C",// Join_Causing (like TATWEEL)
10
+ LeftJoining = "L",// Left_Joining (rare)
11
+ Transparent = "T"
12
+ }
13
+ /**
14
+ * Action to take for each glyph based on context
15
+ */
16
+ export declare enum JoiningAction {
17
+ None = 0,
18
+ Isol = 1,// Isolated form
19
+ Fina = 2,// Final form
20
+ Medi = 3,// Medial form
21
+ Init = 4
22
+ }
23
+ /**
24
+ * Arabic joining group for specific shaping behavior
25
+ */
26
+ export declare enum ArabicJoiningGroup {
27
+ None = 0,
28
+ Alaph = 1,
29
+ DalathRish = 2
30
+ }
31
+ /**
32
+ * Per-glyph info for Arabic shaping
33
+ */
34
+ export interface ArabicGlyphData {
35
+ joiningType: ArabicJoiningType;
36
+ joiningGroup: ArabicJoiningGroup;
37
+ action: JoiningAction;
38
+ }
39
+ /**
40
+ * Check if a codepoint is in Arabic script range
41
+ */
42
+ export declare function isArabic(cp: number): boolean;
43
+ /**
44
+ * Get the joining type for a codepoint
45
+ * Based on Unicode Arabic Shaping data
46
+ */
47
+ export declare function getJoiningType(cp: number): ArabicJoiningType;
48
+ /**
49
+ * Analyze joining for a sequence of glyphs.
50
+ * Returns the action to take for each glyph.
51
+ */
52
+ export declare function analyzeJoining(infos: GlyphInfo[]): JoiningAction[];
53
+ /**
54
+ * Get the feature tag for a joining action
55
+ */
56
+ export declare function getFeatureForAction(action: JoiningAction): string | null;
57
+ /**
58
+ * Set the feature mask for each glyph based on joining analysis
59
+ */
60
+ export declare function setupArabicMasks(infos: GlyphInfo[]): void;
@@ -0,0 +1,70 @@
1
+ import type { GlyphInfo } from "../../types.ts";
2
+ /**
3
+ * Ethiopic shaper
4
+ * Handles Ethiopic/Ge'ez script
5
+ *
6
+ * Ethiopic is an abugida (alphasyllabary) where:
7
+ * - Base consonants have inherent vowel 'a'
8
+ * - Vowels modify the base consonant shape
9
+ * - No joining behavior (unlike Arabic)
10
+ * - Left-to-right direction
11
+ *
12
+ * Key features:
13
+ * - Syllable-based writing (CV or CVC)
14
+ * - Labialization marks (W modifier)
15
+ * - Extended character sets for various languages
16
+ */
17
+ /**
18
+ * Ethiopic character categories
19
+ */
20
+ export declare enum EthiopicCategory {
21
+ Other = 0,
22
+ Syllable = 1,// Main syllabic characters (consonant + vowel)
23
+ Digit = 2,// Ethiopic digits
24
+ Punctuation = 3,// Ethiopic punctuation
25
+ Modifier = 4,// Combining marks
26
+ ToneMark = 5
27
+ }
28
+ /**
29
+ * Get Ethiopic category for codepoint
30
+ */
31
+ export declare function getEthiopicCategory(cp: number): EthiopicCategory;
32
+ /**
33
+ * Check if codepoint is an Ethiopic syllable
34
+ */
35
+ export declare function isEthiopicSyllable(cp: number): boolean;
36
+ /**
37
+ * Get the vowel form of an Ethiopic syllable (0-7)
38
+ * 0 = First form (inherent ä or a)
39
+ * 1 = Second form (u)
40
+ * 2 = Third form (i)
41
+ * 3 = Fourth form (a)
42
+ * 4 = Fifth form (e)
43
+ * 5 = Sixth form (ə or no vowel)
44
+ * 6 = Seventh form (o)
45
+ * 7 = Eighth form (wa) - labialized
46
+ */
47
+ export declare function getEthiopicVowelForm(cp: number): number;
48
+ /**
49
+ * Ethiopic feature masks
50
+ */
51
+ export declare const EthiopicFeatureMask: {
52
+ readonly ccmp: 1;
53
+ readonly locl: 2;
54
+ readonly calt: 4;
55
+ readonly liga: 8;
56
+ readonly ss01: 16;
57
+ readonly ss02: 32;
58
+ };
59
+ /**
60
+ * Set up masks for Ethiopic shaping
61
+ */
62
+ export declare function setupEthiopicMasks(infos: GlyphInfo[]): void;
63
+ /**
64
+ * Get default Ethiopic features in order
65
+ */
66
+ export declare function getEthiopicFeatures(): string[];
67
+ /**
68
+ * Check if script uses Ethiopic shaper
69
+ */
70
+ export declare function usesEthiopic(script: string): boolean;
@@ -0,0 +1,69 @@
1
+ import type { GlyphInfo } from "../../types.ts";
2
+ /**
3
+ * Georgian shaper
4
+ * Handles Georgian script (Mkhedruli, Asomtavruli, Nuskhuri)
5
+ *
6
+ * Georgian is relatively simple compared to other complex scripts:
7
+ * - No complex reordering
8
+ * - No joining behavior
9
+ * - Case transformations (Mkhedruli lowercase, Mtavruli uppercase)
10
+ * - Historical scripts (Asomtavruli, Nuskhuri)
11
+ *
12
+ * Main complexity:
13
+ * - Mtavruli (uppercase) added in Unicode 11.0
14
+ * - Stylistic variants between scripts
15
+ * - Small caps via 'smcp' feature
16
+ */
17
+ /**
18
+ * Georgian character categories
19
+ */
20
+ export declare enum GeorgianCategory {
21
+ Other = 0,
22
+ Mkhedruli = 1,// Modern lowercase (10D0-10FA, 10FC, 10FD-10FF)
23
+ Mtavruli = 2,// Modern uppercase (1C90-1CBA, 1CBD-1CBF)
24
+ Asomtavruli = 3,// Old Church uppercase (10A0-10C5, 10C7, 10CD)
25
+ Nuskhuri = 4,// Old Church lowercase (2D00-2D25, 2D27, 2D2D)
26
+ Modifier = 5,// Modifiers (10FB)
27
+ Punctuation = 6,// Punctuation (10FB)
28
+ Digit = 7,// Digits (using Latin digits with Georgian)
29
+ Letter = 8
30
+ }
31
+ /**
32
+ * Get Georgian category for codepoint
33
+ */
34
+ export declare function getGeorgianCategory(cp: number): GeorgianCategory;
35
+ /**
36
+ * Check if character is a Georgian letter
37
+ */
38
+ export declare function isGeorgianLetter(cp: number): boolean;
39
+ /**
40
+ * Georgian case mapping (Mkhedruli <-> Mtavruli)
41
+ * Returns the corresponding uppercase/lowercase codepoint, or 0 if none
42
+ */
43
+ export declare function georgianToUpper(cp: number): number;
44
+ export declare function georgianToLower(cp: number): number;
45
+ /**
46
+ * Georgian feature masks
47
+ */
48
+ export declare const GeorgianFeatureMask: {
49
+ readonly ccmp: 1;
50
+ readonly locl: 2;
51
+ readonly calt: 4;
52
+ readonly liga: 8;
53
+ readonly smcp: 16;
54
+ readonly c2sc: 32;
55
+ readonly case_: 64;
56
+ readonly cpsp: 128;
57
+ };
58
+ /**
59
+ * Set up masks for Georgian shaping
60
+ */
61
+ export declare function setupGeorgianMasks(infos: GlyphInfo[]): void;
62
+ /**
63
+ * Get default Georgian features in order
64
+ */
65
+ export declare function getGeorgianFeatures(): string[];
66
+ /**
67
+ * Check if script uses Georgian shaper
68
+ */
69
+ export declare function usesGeorgian(script: string): boolean;