text-shaper 0.1.3 → 0.1.5
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 -39
- package/dist/buffer/glyph-buffer.d.ts +2 -2
- package/dist/font/brotli/decode.d.ts +42 -0
- package/dist/font/tables/cff2.d.ts +63 -0
- package/dist/font/tables/gpos.d.ts +15 -0
- package/dist/font/tables/gsub.d.ts +9 -0
- package/dist/index.js +6 -8
- package/dist/raster/msdf.d.ts +12 -0
- package/dist/shaper/shaper.d.ts +128 -1
- package/package.json +2 -2
- package/dist/index.js.map +0 -134
- package/dist/index.test.d.ts +0 -1
- package/dist/perf/benchmark-runner-eksh2b26.js +0 -0
- package/dist/perf/benchmark-runner.html +0 -517
- package/dist/perf/comparison-tests.js +0 -22676
- package/dist/perf/comparison-tests.js.map +0 -111
- package/dist/perf/cpu/cpu-perf.js +0 -21920
- package/dist/perf/cpu/cpu-perf.js.map +0 -108
- package/dist/perf/gpu/webgl-perf.js +0 -470
- package/dist/perf/gpu/webgl-perf.js.map +0 -11
- package/dist/perf/gpu/webgpu-perf.js +0 -442
- package/dist/perf/gpu/webgpu-perf.js.map +0 -11
- package/dist/perf/index.html +0 -258
- package/dist/perf/module-loader.js +0 -18
- package/dist/perf/utils/perf-utils.js +0 -170
- package/dist/perf/utils/perf-utils.js.map +0 -10
- package/dist/typeshaper.js +0 -7
- package/dist/unicode/bidi/brackets.data.d.ts +0 -5
- package/dist/unicode/bidi/char-types.data.d.ts +0 -25
- package/dist/unicode/bidi/mirroring.data.d.ts +0 -2
package/dist/raster/msdf.d.ts
CHANGED
|
@@ -108,6 +108,18 @@ export declare function signedDistanceToCubic(px: number, py: number, p0: Point,
|
|
|
108
108
|
* At sharp corners, adjacent edges get different colors
|
|
109
109
|
*/
|
|
110
110
|
export declare function assignEdgeColors(contours: MsdfEdge[][]): void;
|
|
111
|
+
/**
|
|
112
|
+
* Compute signed distance from point to edge
|
|
113
|
+
*/
|
|
114
|
+
export declare function signedDistanceToEdge(px: number, py: number, edge: MsdfEdge): SignedDistanceResult;
|
|
115
|
+
/**
|
|
116
|
+
* Determine if a point is inside using ray casting (even-odd rule)
|
|
117
|
+
*/
|
|
118
|
+
export declare function isPointInside(px: number, py: number, contours: MsdfEdge[][]): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Flatten an edge to points for inside testing
|
|
121
|
+
*/
|
|
122
|
+
export declare function flattenEdge(edge: MsdfEdge): Point[];
|
|
111
123
|
/**
|
|
112
124
|
* Render a glyph path as a multi-channel signed distance field
|
|
113
125
|
*/
|
package/dist/shaper/shaper.d.ts
CHANGED
|
@@ -2,7 +2,13 @@ import { GlyphBuffer } from "../buffer/glyph-buffer.ts";
|
|
|
2
2
|
import type { UnicodeBuffer } from "../buffer/unicode-buffer.ts";
|
|
3
3
|
import { Face } from "../font/face.ts";
|
|
4
4
|
import type { Font } from "../font/font.ts";
|
|
5
|
-
import { type
|
|
5
|
+
import { type AnyGposLookup, type CursivePosLookup, type MarkBasePosLookup, type MarkLigaturePosLookup, type MarkMarkPosLookup, type PairPosLookup, type SinglePosLookup } from "../font/tables/gpos.ts";
|
|
6
|
+
import type { ChainingContextPosFormat1, ChainingContextPosFormat2, ChainingContextPosFormat3, ChainingContextPosLookup, ContextPosFormat1, ContextPosFormat2, ContextPosFormat3, ContextPosLookup, PosLookupRecord } from "../font/tables/gpos-contextual.ts";
|
|
7
|
+
import { type AlternateSubstLookup, type AnyGsubLookup, type ChainingContextSubstLookup, type ContextSubstLookup, type LigatureSubstLookup, type MultipleSubstLookup, type ReverseChainingSingleSubstLookup, type SingleSubstLookup } from "../font/tables/gsub.ts";
|
|
8
|
+
import type { ChainingContextFormat1, ChainingContextFormat2, ChainingContextFormat3, ContextSubstFormat1, ContextSubstFormat2, ContextSubstFormat3, SequenceLookupRecord } from "../font/tables/gsub-contextual.ts";
|
|
9
|
+
import type { ClassDef } from "../layout/structures/class-def.ts";
|
|
10
|
+
import type { GlyphId } from "../types.ts";
|
|
11
|
+
import { type ShapeFeature, type ShapePlan } from "./shape-plan.ts";
|
|
6
12
|
/**
|
|
7
13
|
* Options for controlling text shaping behavior.
|
|
8
14
|
*/
|
|
@@ -22,6 +28,23 @@ export interface ShapeOptions {
|
|
|
22
28
|
* Use Font for static fonts or when default axis values are acceptable.
|
|
23
29
|
*/
|
|
24
30
|
export type FontLike = Font | Face;
|
|
31
|
+
/**
|
|
32
|
+
* Pre-computed skip markers for efficient glyph skipping in contextual matching.
|
|
33
|
+
* Bit is set to 1 if glyph at that position should be skipped for the given lookup flag.
|
|
34
|
+
*/
|
|
35
|
+
type SkipMarkers = Uint8Array;
|
|
36
|
+
/**
|
|
37
|
+
* Pre-compute skip markers for all glyphs in the buffer.
|
|
38
|
+
* This avoids calling shouldSkipGlyph() repeatedly in tight loops.
|
|
39
|
+
* O(n) one-time cost instead of O(n²) repeated calls.
|
|
40
|
+
*/
|
|
41
|
+
declare function precomputeSkipMarkers(font: Font, buffer: GlyphBuffer, lookupFlag: number): SkipMarkers;
|
|
42
|
+
/**
|
|
43
|
+
* Pre-compute next non-skip index array for O(1) pair lookups.
|
|
44
|
+
* nextNonSkip[i] = index of next non-skipped glyph after i, or -1 if none.
|
|
45
|
+
* Built in reverse for O(n) construction.
|
|
46
|
+
*/
|
|
47
|
+
declare function buildNextNonSkipArray(skip: SkipMarkers, length: number): Int16Array;
|
|
25
48
|
/**
|
|
26
49
|
* Return a GlyphBuffer to the pool for reuse.
|
|
27
50
|
* Call this when done with a buffer from shape() to reduce allocations.
|
|
@@ -74,3 +97,107 @@ export declare function shape(fontLike: FontLike, buffer: UnicodeBuffer, options
|
|
|
74
97
|
* @param options.features - Array of OpenType features to enable/disable (e.g., [{tag: "liga", value: 1}])
|
|
75
98
|
*/
|
|
76
99
|
export declare function shapeInto(fontLike: FontLike, buffer: UnicodeBuffer, glyphBuffer: GlyphBuffer, options?: ShapeOptions): void;
|
|
100
|
+
declare function applyGsubLookup(font: Font, buffer: GlyphBuffer, lookup: AnyGsubLookup, plan: ShapePlan): void;
|
|
101
|
+
declare function applySingleSubstLookup(font: Font, buffer: GlyphBuffer, lookup: SingleSubstLookup): void;
|
|
102
|
+
declare function applyMultipleSubstLookup(font: Font, buffer: GlyphBuffer, lookup: MultipleSubstLookup): void;
|
|
103
|
+
declare function applyAlternateSubstLookup(font: Font, buffer: GlyphBuffer, lookup: AlternateSubstLookup): void;
|
|
104
|
+
declare function applyLigatureSubstLookup(font: Font, buffer: GlyphBuffer, lookup: LigatureSubstLookup): void;
|
|
105
|
+
declare function applyContextSubstLookup(font: Font, buffer: GlyphBuffer, lookup: ContextSubstLookup, plan: ShapePlan): void;
|
|
106
|
+
declare function applyChainingContextSubstLookup(font: Font, buffer: GlyphBuffer, lookup: ChainingContextSubstLookup, plan: ShapePlan): void;
|
|
107
|
+
declare function applyReverseChainingSingleSubstLookup(font: Font, buffer: GlyphBuffer, lookup: ReverseChainingSingleSubstLookup): void;
|
|
108
|
+
/** Match Context Format 1 - glyph-based rules */
|
|
109
|
+
declare function matchContextFormat1(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ContextSubstFormat1, lookupFlag: number): SequenceLookupRecord[] | null;
|
|
110
|
+
/** Match Context Format 2 - class-based rules */
|
|
111
|
+
declare function matchContextFormat2(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ContextSubstFormat2, lookupFlag: number): SequenceLookupRecord[] | null;
|
|
112
|
+
/** Match Context Format 3 - coverage-based */
|
|
113
|
+
declare function matchContextFormat3(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ContextSubstFormat3, lookupFlag: number): boolean;
|
|
114
|
+
/** Match Chaining Context Format 1 - glyph-based rules */
|
|
115
|
+
declare function matchChainingFormat1(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ChainingContextFormat1, lookupFlag: number): SequenceLookupRecord[] | null;
|
|
116
|
+
/** Match Chaining Context Format 2 - class-based rules */
|
|
117
|
+
declare function matchChainingFormat2(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ChainingContextFormat2, lookupFlag: number): SequenceLookupRecord[] | null;
|
|
118
|
+
/** Match Chaining Context Format 3 - coverage-based */
|
|
119
|
+
declare function matchChainingFormat3(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ChainingContextFormat3, lookupFlag: number): boolean;
|
|
120
|
+
declare function applyNestedLookups(_font: Font, buffer: GlyphBuffer, startIndex: number, lookupRecords: Array<{
|
|
121
|
+
sequenceIndex: number;
|
|
122
|
+
lookupListIndex: number;
|
|
123
|
+
}>, plan: ShapePlan): void;
|
|
124
|
+
/**
|
|
125
|
+
* Glyph class cache for efficient repeated lookups during GPOS positioning.
|
|
126
|
+
* Map from GlyphId to GlyphClass (avoids repeated GDEF lookups for same glyph).
|
|
127
|
+
*/
|
|
128
|
+
type GlyphClassCache = Map<GlyphId, number>;
|
|
129
|
+
declare function applyGposLookup(font: Font, buffer: GlyphBuffer, lookup: AnyGposLookup, plan: ShapePlan, glyphClassCache: GlyphClassCache, baseIndexArray: Int16Array, hasMarks: boolean): void;
|
|
130
|
+
declare function applySinglePosLookup(font: Font, buffer: GlyphBuffer, lookup: SinglePosLookup, hasMarks: boolean): void;
|
|
131
|
+
declare function applyPairPosLookup(font: Font, buffer: GlyphBuffer, lookup: PairPosLookup, hasMarks: boolean): void;
|
|
132
|
+
declare function applyCursivePosLookup(font: Font, buffer: GlyphBuffer, lookup: CursivePosLookup, hasMarks: boolean): void;
|
|
133
|
+
declare function applyMarkBasePosLookup(font: Font, buffer: GlyphBuffer, lookup: MarkBasePosLookup, glyphClassCache: GlyphClassCache, baseIndexArray: Int16Array): void;
|
|
134
|
+
declare function applyMarkLigaturePosLookup(font: Font, buffer: GlyphBuffer, lookup: MarkLigaturePosLookup, glyphClassCache: GlyphClassCache, baseIndexArray: Int16Array): void;
|
|
135
|
+
declare function applyMarkMarkPosLookup(font: Font, buffer: GlyphBuffer, lookup: MarkMarkPosLookup, glyphClassCache: GlyphClassCache): void;
|
|
136
|
+
declare function applyContextPosLookup(font: Font, buffer: GlyphBuffer, lookup: ContextPosLookup, plan: ShapePlan, glyphClassCache: GlyphClassCache, baseIndexArray: Int16Array, hasMarks: boolean): void;
|
|
137
|
+
declare function applyChainingContextPosLookup(font: Font, buffer: GlyphBuffer, lookup: ChainingContextPosLookup, plan: ShapePlan, glyphClassCache: GlyphClassCache, baseIndexArray: Int16Array, hasMarks: boolean): void;
|
|
138
|
+
/** Match Context Pos Format 1 - glyph-based rules */
|
|
139
|
+
declare function matchContextPosFormat1(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ContextPosFormat1, lookupFlag: number): PosLookupRecord[] | null;
|
|
140
|
+
/** Match Context Pos Format 2 - class-based rules */
|
|
141
|
+
declare function matchContextPosFormat2(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ContextPosFormat2, lookupFlag: number): PosLookupRecord[] | null;
|
|
142
|
+
/** Match Context Pos Format 3 - coverage-based */
|
|
143
|
+
declare function matchContextPosFormat3(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ContextPosFormat3, lookupFlag: number): boolean;
|
|
144
|
+
/** Match Chaining Context Pos Format 1 - glyph-based rules */
|
|
145
|
+
declare function matchChainingContextPosFormat1(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ChainingContextPosFormat1, lookupFlag: number): PosLookupRecord[] | null;
|
|
146
|
+
/** Match Chaining Context Pos Format 2 - class-based rules */
|
|
147
|
+
declare function matchChainingContextPosFormat2(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ChainingContextPosFormat2, lookupFlag: number): PosLookupRecord[] | null;
|
|
148
|
+
/** Match Chaining Context Pos Format 3 - coverage-based */
|
|
149
|
+
declare function matchChainingContextPosFormat3(font: Font, buffer: GlyphBuffer, startIndex: number, subtable: ChainingContextPosFormat3, lookupFlag: number): boolean;
|
|
150
|
+
/** Apply nested positioning lookups at specific positions */
|
|
151
|
+
declare function applyNestedPosLookups(font: Font, buffer: GlyphBuffer, startIndex: number, lookupRecords: PosLookupRecord[], plan: ShapePlan, glyphClassCache: GlyphClassCache, baseIndexArray: Int16Array, hasMarks: boolean): void;
|
|
152
|
+
/** Match a sequence of specific glyphs forward */
|
|
153
|
+
declare function matchGlyphSequence(font: Font, buffer: GlyphBuffer, startPos: number, glyphs: GlyphId[], lookupFlag: number): boolean;
|
|
154
|
+
/** Match a sequence of specific glyphs backward */
|
|
155
|
+
declare function matchGlyphSequenceBackward(font: Font, buffer: GlyphBuffer, startPos: number, glyphs: GlyphId[], lookupFlag: number): boolean;
|
|
156
|
+
/** Match a sequence of classes forward */
|
|
157
|
+
declare function matchClassSequence(font: Font, buffer: GlyphBuffer, startPos: number, classes: number[], classDef: ClassDef, lookupFlag: number): boolean;
|
|
158
|
+
/** Match a sequence of classes backward */
|
|
159
|
+
declare function matchClassSequenceBackward(font: Font, buffer: GlyphBuffer, startPos: number, classes: number[], classDef: ClassDef, lookupFlag: number): boolean;
|
|
160
|
+
declare function shouldSkipGlyph(font: Font, glyphId: GlyphId, lookupFlag: number): boolean;
|
|
161
|
+
declare function applyMorx(font: Font, buffer: GlyphBuffer): void;
|
|
162
|
+
export declare const __testing: {
|
|
163
|
+
applyGsubLookup: typeof applyGsubLookup;
|
|
164
|
+
applyGposLookup: typeof applyGposLookup;
|
|
165
|
+
applySingleSubstLookup: typeof applySingleSubstLookup;
|
|
166
|
+
applyMultipleSubstLookup: typeof applyMultipleSubstLookup;
|
|
167
|
+
applyAlternateSubstLookup: typeof applyAlternateSubstLookup;
|
|
168
|
+
applyLigatureSubstLookup: typeof applyLigatureSubstLookup;
|
|
169
|
+
applyContextSubstLookup: typeof applyContextSubstLookup;
|
|
170
|
+
applyChainingContextSubstLookup: typeof applyChainingContextSubstLookup;
|
|
171
|
+
applyReverseChainingSingleSubstLookup: typeof applyReverseChainingSingleSubstLookup;
|
|
172
|
+
applySinglePosLookup: typeof applySinglePosLookup;
|
|
173
|
+
applyPairPosLookup: typeof applyPairPosLookup;
|
|
174
|
+
applyCursivePosLookup: typeof applyCursivePosLookup;
|
|
175
|
+
applyMarkBasePosLookup: typeof applyMarkBasePosLookup;
|
|
176
|
+
applyMarkLigaturePosLookup: typeof applyMarkLigaturePosLookup;
|
|
177
|
+
applyMarkMarkPosLookup: typeof applyMarkMarkPosLookup;
|
|
178
|
+
applyContextPosLookup: typeof applyContextPosLookup;
|
|
179
|
+
applyChainingContextPosLookup: typeof applyChainingContextPosLookup;
|
|
180
|
+
matchContextFormat1: typeof matchContextFormat1;
|
|
181
|
+
matchContextFormat2: typeof matchContextFormat2;
|
|
182
|
+
matchContextFormat3: typeof matchContextFormat3;
|
|
183
|
+
matchChainingFormat1: typeof matchChainingFormat1;
|
|
184
|
+
matchChainingFormat2: typeof matchChainingFormat2;
|
|
185
|
+
matchChainingFormat3: typeof matchChainingFormat3;
|
|
186
|
+
matchContextPosFormat1: typeof matchContextPosFormat1;
|
|
187
|
+
matchContextPosFormat2: typeof matchContextPosFormat2;
|
|
188
|
+
matchContextPosFormat3: typeof matchContextPosFormat3;
|
|
189
|
+
matchChainingContextPosFormat1: typeof matchChainingContextPosFormat1;
|
|
190
|
+
matchChainingContextPosFormat2: typeof matchChainingContextPosFormat2;
|
|
191
|
+
matchChainingContextPosFormat3: typeof matchChainingContextPosFormat3;
|
|
192
|
+
matchGlyphSequence: typeof matchGlyphSequence;
|
|
193
|
+
matchGlyphSequenceBackward: typeof matchGlyphSequenceBackward;
|
|
194
|
+
matchClassSequence: typeof matchClassSequence;
|
|
195
|
+
matchClassSequenceBackward: typeof matchClassSequenceBackward;
|
|
196
|
+
shouldSkipGlyph: typeof shouldSkipGlyph;
|
|
197
|
+
precomputeSkipMarkers: typeof precomputeSkipMarkers;
|
|
198
|
+
buildNextNonSkipArray: typeof buildNextNonSkipArray;
|
|
199
|
+
applyNestedLookups: typeof applyNestedLookups;
|
|
200
|
+
applyNestedPosLookups: typeof applyNestedPosLookups;
|
|
201
|
+
applyMorx: typeof applyMorx;
|
|
202
|
+
};
|
|
203
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "text-shaper",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"postinstall": "node scripts/patch-pkg-prebuilds.js",
|
|
51
51
|
"bench": "bun test ./bench/ --timeout 120000",
|
|
52
52
|
"build": "bun build ./src/index.ts --outdir ./dist --target browser --minify --sourcemap=linked",
|
|
53
|
-
"build:prod": "bun build ./src/index.ts --outdir ./dist --target browser --production
|
|
53
|
+
"build:prod": "bun build ./src/index.ts --outdir ./dist --target browser --production",
|
|
54
54
|
"build:analyze": "bun build ./src/index.ts --outdir ./dist --target browser --minify --metafile=./dist/meta.json",
|
|
55
55
|
"build:dts": "tsc -p tsconfig.build.json",
|
|
56
56
|
"typecheck": "tsc --noEmit",
|