docxkeun 0.1.3 → 0.2.0
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/CHANGELOG.md +48 -0
- package/README.md +137 -16
- package/dist/api/editor.d.ts +172 -5
- package/dist/api/editor.js +814 -24
- package/dist/api/headers.d.ts +51 -0
- package/dist/api/headers.js +133 -0
- package/dist/api/index.d.ts +5 -1
- package/dist/api/index.js +4 -1
- package/dist/api/lists.d.ts +37 -0
- package/dist/api/lists.js +132 -0
- package/dist/api/parts.js +1 -0
- package/dist/api/positions.js +1 -0
- package/dist/api/revisions.d.ts +61 -0
- package/dist/api/revisions.js +390 -0
- package/dist/api/selection.d.ts +57 -0
- package/dist/api/selection.js +91 -0
- package/dist/charts/color.d.ts +45 -0
- package/dist/charts/color.js +322 -0
- package/dist/charts/format.d.ts +12 -0
- package/dist/charts/format.js +459 -0
- package/dist/charts/index.d.ts +11 -0
- package/dist/charts/index.js +8 -0
- package/dist/charts/model.d.ts +225 -0
- package/dist/charts/model.js +758 -0
- package/dist/charts/outline.d.ts +17 -0
- package/dist/charts/outline.js +214 -0
- package/dist/charts/render.d.ts +20 -0
- package/dist/charts/render.js +1772 -0
- package/dist/drawing/arrows.d.ts +37 -0
- package/dist/drawing/arrows.js +99 -0
- package/dist/drawing/formula.d.ts +40 -0
- package/dist/drawing/formula.js +159 -0
- package/dist/drawing/geometry.d.ts +61 -0
- package/dist/drawing/geometry.js +286 -0
- package/dist/drawing/index.d.ts +12 -0
- package/dist/drawing/index.js +8 -0
- package/dist/drawing/presets.d.ts +72 -0
- package/dist/drawing/presets.js +2874 -0
- package/dist/fonts/shaping/apply.d.ts +94 -0
- package/dist/fonts/shaping/apply.js +349 -0
- package/dist/fonts/shaping/arabic.d.ts +28 -0
- package/dist/fonts/shaping/arabic.js +235 -0
- package/dist/fonts/shaping/buffer.d.ts +53 -0
- package/dist/fonts/shaping/buffer.js +95 -0
- package/dist/fonts/shaping/gdef.d.ts +30 -0
- package/dist/fonts/shaping/gdef.js +66 -0
- package/dist/fonts/shaping/gpos.d.ts +86 -0
- package/dist/fonts/shaping/gpos.js +428 -0
- package/dist/fonts/shaping/gsub.d.ts +65 -0
- package/dist/fonts/shaping/gsub.js +313 -0
- package/dist/fonts/shaping/index.d.ts +32 -0
- package/dist/fonts/shaping/index.js +402 -0
- package/dist/fonts/shaping/indic.d.ts +6 -0
- package/dist/fonts/shaping/indic.js +805 -0
- package/dist/fonts/shaping/layout-common.d.ts +124 -0
- package/dist/fonts/shaping/layout-common.js +349 -0
- package/dist/fonts/shaping/plan.d.ts +87 -0
- package/dist/fonts/shaping/plan.js +152 -0
- package/dist/fonts/shaping/scripts.d.ts +26 -0
- package/dist/fonts/shaping/scripts.js +160 -0
- package/dist/fonts/shaping/shaper.d.ts +23 -0
- package/dist/fonts/shaping/shaper.js +5 -0
- package/dist/fonts/shaping/unicode.d.ts +34 -0
- package/dist/fonts/shaping/unicode.js +138 -0
- package/dist/images/bmp.d.ts +9 -0
- package/dist/images/bmp.js +234 -0
- package/dist/images/gif.d.ts +9 -0
- package/dist/images/gif.js +215 -0
- package/dist/images/index.d.ts +18 -0
- package/dist/images/index.js +63 -0
- package/dist/images/png-encode.d.ts +4 -0
- package/dist/images/png-encode.js +73 -0
- package/dist/images/size.d.ts +10 -0
- package/dist/images/size.js +83 -0
- package/dist/images/tiff.d.ts +14 -0
- package/dist/images/tiff.js +407 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +5 -0
- package/dist/layout/bidi.d.ts +18 -0
- package/dist/layout/bidi.js +71 -0
- package/dist/layout/blocks.d.ts +20 -3
- package/dist/layout/blocks.js +88 -58
- package/dist/layout/cache.d.ts +31 -0
- package/dist/layout/cache.js +38 -0
- package/dist/layout/drawing.d.ts +30 -0
- package/dist/layout/drawing.js +120 -0
- package/dist/layout/engine.d.ts +3 -0
- package/dist/layout/engine.js +218 -11
- package/dist/layout/index.d.ts +1 -0
- package/dist/layout/index.js +1 -0
- package/dist/layout/lines.d.ts +63 -5
- package/dist/layout/lines.js +245 -20
- package/dist/layout/paint.d.ts +25 -3
- package/dist/layout/paint.js +26 -10
- package/dist/layout/shapes.d.ts +7 -0
- package/dist/layout/shapes.js +338 -0
- package/dist/layout/style.d.ts +4 -0
- package/dist/layout/style.js +2 -0
- package/dist/layout/types.d.ts +89 -2
- package/dist/math/boxes.d.ts +88 -0
- package/dist/math/boxes.js +166 -0
- package/dist/math/index.d.ts +29 -0
- package/dist/math/index.js +44 -0
- package/dist/math/layout.d.ts +13 -0
- package/dist/math/layout.js +771 -0
- package/dist/math/linear.d.ts +3 -0
- package/dist/math/linear.js +152 -0
- package/dist/math/omml.d.ts +15 -0
- package/dist/math/omml.js +57 -0
- package/dist/math/paths.d.ts +61 -0
- package/dist/math/paths.js +450 -0
- package/dist/math/symbols.d.ts +49 -0
- package/dist/math/symbols.js +269 -0
- package/dist/math/text.d.ts +53 -0
- package/dist/math/text.js +316 -0
- package/dist/metafile/canvas.d.ts +80 -0
- package/dist/metafile/canvas.js +515 -0
- package/dist/metafile/dib.d.ts +27 -0
- package/dist/metafile/dib.js +300 -0
- package/dist/metafile/emf.d.ts +31 -0
- package/dist/metafile/emf.js +591 -0
- package/dist/metafile/geometry.d.ts +49 -0
- package/dist/metafile/geometry.js +85 -0
- package/dist/metafile/index.d.ts +27 -0
- package/dist/metafile/index.js +34 -0
- package/dist/metafile/reader.d.ts +28 -0
- package/dist/metafile/reader.js +59 -0
- package/dist/metafile/state.d.ts +118 -0
- package/dist/metafile/state.js +172 -0
- package/dist/metafile/text.d.ts +17 -0
- package/dist/metafile/text.js +130 -0
- package/dist/metafile/wmf.d.ts +33 -0
- package/dist/metafile/wmf.js +395 -0
- package/dist/model/content.d.ts +92 -7
- package/dist/model/content.js +251 -17
- package/dist/model/document.d.ts +34 -1
- package/dist/model/document.js +80 -1
- package/dist/model/fields.d.ts +4 -0
- package/dist/model/fields.js +10 -0
- package/dist/model/numbering.d.ts +2 -0
- package/dist/model/numbering.js +22 -0
- package/dist/model/props.d.ts +2 -0
- package/dist/model/props.js +3 -0
- package/dist/opc/index.d.ts +1 -1
- package/dist/opc/package.d.ts +34 -0
- package/dist/opc/package.js +58 -4
- package/dist/pdf/export.js +97 -6
- package/dist/pdf/images.d.ts +7 -0
- package/dist/pdf/images.js +39 -2
- package/dist/render/activity.d.ts +138 -0
- package/dist/render/activity.js +794 -0
- package/dist/render/clipboard.d.ts +29 -0
- package/dist/render/clipboard.js +401 -0
- package/dist/render/comments.d.ts +166 -0
- package/dist/render/comments.js +779 -0
- package/dist/render/context-menu.d.ts +124 -0
- package/dist/render/context-menu.js +525 -0
- package/dist/render/editing.d.ts +146 -5
- package/dist/render/editing.js +678 -53
- package/dist/render/index.d.ts +12 -0
- package/dist/render/index.js +11 -0
- package/dist/render/navigation-panel.d.ts +76 -0
- package/dist/render/navigation-panel.js +431 -0
- package/dist/render/selection.js +5 -0
- package/dist/render/svg.d.ts +4 -6
- package/dist/render/svg.js +69 -7
- package/dist/render/toolbar.d.ts +83 -0
- package/dist/render/toolbar.js +505 -0
- package/dist/render/ui/comment-layout.d.ts +39 -0
- package/dist/render/ui/comment-layout.js +79 -0
- package/dist/render/ui/icons.d.ts +6 -0
- package/dist/render/ui/icons.js +38 -0
- package/dist/render/ui/menu.d.ts +38 -0
- package/dist/render/ui/menu.js +274 -0
- package/dist/render/ui/nav-model.d.ts +11 -0
- package/dist/render/ui/nav-model.js +34 -0
- package/dist/render/ui/overflow.d.ts +5 -0
- package/dist/render/ui/overflow.js +18 -0
- package/dist/render/ui/popover.d.ts +18 -0
- package/dist/render/ui/popover.js +109 -0
- package/dist/render/ui/theme.d.ts +2 -0
- package/dist/render/ui/theme.js +29 -0
- package/dist/render/undo.d.ts +76 -0
- package/dist/render/undo.js +144 -0
- package/dist/render/viewer.d.ts +100 -7
- package/dist/render/viewer.js +302 -92
- package/dist/security/policy.d.ts +3 -0
- package/dist/security/policy.js +6 -2
- package/dist/security/protection.d.ts +1 -0
- package/dist/security/protection.js +1 -1
- package/dist/text/bidi-data.d.ts +53 -0
- package/dist/text/bidi-data.js +318 -0
- package/dist/text/bidi.d.ts +37 -0
- package/dist/text/bidi.js +508 -0
- package/dist/xml/ns.d.ts +5 -0
- package/dist/xml/ns.js +7 -0
- package/package.json +9 -2
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GSUB: glyph substitution lookups. Types 1 single, 2 multiple, 3 alternate (first
|
|
3
|
+
* alternate), 4 ligature, 5 context, 6 chaining context, 7 extension (resolved by
|
|
4
|
+
* LayoutTable) and 8 reverse chaining single. Substitutions edit the buffer in place and
|
|
5
|
+
* keep the glyph-property history (substituted / ligated / multiplied) and ligature
|
|
6
|
+
* component numbers that mark positioning and the Indic final reordering rely on.
|
|
7
|
+
*/
|
|
8
|
+
import { MAX_NESTING, lookupProps } from './apply.js';
|
|
9
|
+
import { cloneInfo, deleteGlyph, isBaseGlyph, isLigature, isMark, ligComp, ligNumComps, mergeClusters, setLigPropsForLigature, setLigPropsForMark, } from './buffer.js';
|
|
10
|
+
import { GlyphProps } from './gdef.js';
|
|
11
|
+
import { classOf, LayoutTable, parseContextual, parseCoverage } from './layout-common.js';
|
|
12
|
+
import { UFlag } from './unicode.js';
|
|
13
|
+
export class Gsub {
|
|
14
|
+
layout;
|
|
15
|
+
lookups = new Map();
|
|
16
|
+
/** Applies one of this table's lookups at a position (also used for nested lookups). */
|
|
17
|
+
dispatch;
|
|
18
|
+
constructor(bytes) {
|
|
19
|
+
this.layout = new LayoutTable(bytes, 7);
|
|
20
|
+
this.dispatch = (ctx, index, i) => {
|
|
21
|
+
const lookup = this.lookup(index);
|
|
22
|
+
if (!lookup)
|
|
23
|
+
return -1;
|
|
24
|
+
ctx.lookupProps = lookup.props;
|
|
25
|
+
for (const st of lookup.subtables) {
|
|
26
|
+
const next = applySubstitution(ctx, st, i);
|
|
27
|
+
if (next >= 0)
|
|
28
|
+
return next;
|
|
29
|
+
}
|
|
30
|
+
return -1;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
lookup(index) {
|
|
34
|
+
const cached = this.lookups.get(index);
|
|
35
|
+
if (cached !== undefined)
|
|
36
|
+
return cached ?? undefined;
|
|
37
|
+
const header = this.layout.lookupHeader(index);
|
|
38
|
+
let lookup = null;
|
|
39
|
+
if (header) {
|
|
40
|
+
const subtables = [];
|
|
41
|
+
for (const st of header.subtables) {
|
|
42
|
+
const parsed = parseSubstitution(this.layout, st.type, st.offset);
|
|
43
|
+
if (parsed)
|
|
44
|
+
subtables.push(parsed);
|
|
45
|
+
}
|
|
46
|
+
lookup = { type: header.type, props: lookupProps(header.flag, header.markFilteringSet), reverse: header.type === 8, subtables };
|
|
47
|
+
}
|
|
48
|
+
this.lookups.set(index, lookup);
|
|
49
|
+
return lookup ?? undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether any of the lookups would substitute exactly this glyph sequence (ignoring its
|
|
53
|
+
* surroundings). The Indic shaper asks this to learn, e.g., whether Ra+Halant forms a reph
|
|
54
|
+
* or a consonant has a below-base form, before deciding the syllable's base.
|
|
55
|
+
*/
|
|
56
|
+
wouldSubstitute(lookupIndices, glyphs, zeroContext) {
|
|
57
|
+
if (!glyphs.length)
|
|
58
|
+
return false;
|
|
59
|
+
for (const index of lookupIndices) {
|
|
60
|
+
const lookup = this.lookup(index);
|
|
61
|
+
if (lookup?.subtables.some((st) => wouldApply(st, glyphs, zeroContext)))
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function parseSubstitution(layout, type, off) {
|
|
68
|
+
const d = layout.data;
|
|
69
|
+
const format = d.u16(off);
|
|
70
|
+
const coverage = () => parseCoverage(d, off + d.u16(off + 2));
|
|
71
|
+
const offsetsAt = (at) => d.u16s(at + 2, d.u16(at));
|
|
72
|
+
const glyphArray = (at) => d.u16s(at + 2, d.u16(at));
|
|
73
|
+
switch (type) {
|
|
74
|
+
case 1:
|
|
75
|
+
if (format === 1)
|
|
76
|
+
return { kind: 'single', coverage: coverage(), delta: d.i16(off + 4), substitutes: [] };
|
|
77
|
+
if (format === 2)
|
|
78
|
+
return { kind: 'single', coverage: coverage(), delta: undefined, substitutes: glyphArray(off + 4) };
|
|
79
|
+
return undefined;
|
|
80
|
+
case 2:
|
|
81
|
+
case 3: {
|
|
82
|
+
if (format !== 1)
|
|
83
|
+
return undefined;
|
|
84
|
+
const lists = offsetsAt(off + 4).map((rel) => glyphArray(off + rel));
|
|
85
|
+
return type === 2 ? { kind: 'multiple', coverage: coverage(), sequences: lists } : { kind: 'alternate', coverage: coverage(), sets: lists };
|
|
86
|
+
}
|
|
87
|
+
case 4: {
|
|
88
|
+
if (format !== 1)
|
|
89
|
+
return undefined;
|
|
90
|
+
const sets = offsetsAt(off + 4).map((rel) => {
|
|
91
|
+
const setOff = off + rel;
|
|
92
|
+
return offsetsAt(setOff).map((lrel) => {
|
|
93
|
+
const l = setOff + lrel;
|
|
94
|
+
return { glyph: d.u16(l), components: d.u16s(l + 4, Math.max(0, d.u16(l + 2) - 1)) };
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return { kind: 'ligature', coverage: coverage(), sets };
|
|
98
|
+
}
|
|
99
|
+
case 5:
|
|
100
|
+
case 6:
|
|
101
|
+
return parseContextual(d, off, type === 6);
|
|
102
|
+
case 8: {
|
|
103
|
+
if (format !== 1)
|
|
104
|
+
return undefined;
|
|
105
|
+
let p = off + 4;
|
|
106
|
+
const covs = (at, count) => d.u16s(at, count).map((o) => parseCoverage(d, off + o));
|
|
107
|
+
const bc = d.u16(p);
|
|
108
|
+
const backtrack = covs(p + 2, bc);
|
|
109
|
+
p += 2 + bc * 2;
|
|
110
|
+
const lc = d.u16(p);
|
|
111
|
+
const lookahead = covs(p + 2, lc);
|
|
112
|
+
p += 2 + lc * 2;
|
|
113
|
+
return { kind: 'reverse', coverage: coverage(), backtrack, lookahead, substitutes: glyphArray(p) };
|
|
114
|
+
}
|
|
115
|
+
default:
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Sets a glyph and updates its class: from GDEF when the font has glyph classes, else from
|
|
121
|
+
* the caller's guess (ligature / base), keeping the substitution history bits.
|
|
122
|
+
*/
|
|
123
|
+
export function replaceGlyph(ctx, info, glyph, classGuess = 0, ligature = false, component = false) {
|
|
124
|
+
let props = info.props | GlyphProps.Substituted;
|
|
125
|
+
if (ligature)
|
|
126
|
+
props = (props | GlyphProps.Ligated) & ~GlyphProps.Multiplied;
|
|
127
|
+
if (component)
|
|
128
|
+
props |= GlyphProps.Multiplied;
|
|
129
|
+
if (ctx.gdef.hasGlyphClasses)
|
|
130
|
+
props = (props & GlyphProps.Preserve) | ctx.gdef.glyphProps(glyph);
|
|
131
|
+
else if (classGuess)
|
|
132
|
+
props = (props & GlyphProps.Preserve) | classGuess;
|
|
133
|
+
info.props = props;
|
|
134
|
+
info.glyph = glyph;
|
|
135
|
+
}
|
|
136
|
+
function applySubstitution(ctx, st, i) {
|
|
137
|
+
const buf = ctx.buffer;
|
|
138
|
+
const info = buf[i];
|
|
139
|
+
const glyph = info.glyph;
|
|
140
|
+
switch (st.kind) {
|
|
141
|
+
case 'single': {
|
|
142
|
+
const ci = st.coverage.get(glyph);
|
|
143
|
+
if (ci === undefined)
|
|
144
|
+
return -1;
|
|
145
|
+
const out = st.delta !== undefined ? (glyph + st.delta) & 0xffff : st.substitutes[ci];
|
|
146
|
+
if (out === undefined)
|
|
147
|
+
return -1;
|
|
148
|
+
replaceGlyph(ctx, info, out);
|
|
149
|
+
return i + 1;
|
|
150
|
+
}
|
|
151
|
+
case 'alternate': {
|
|
152
|
+
const ci = st.coverage.get(glyph);
|
|
153
|
+
const out = ci === undefined ? undefined : st.sets[ci]?.[0];
|
|
154
|
+
if (out === undefined)
|
|
155
|
+
return -1;
|
|
156
|
+
replaceGlyph(ctx, info, out);
|
|
157
|
+
return i + 1;
|
|
158
|
+
}
|
|
159
|
+
case 'multiple': {
|
|
160
|
+
const ci = st.coverage.get(glyph);
|
|
161
|
+
const seq = ci === undefined ? undefined : st.sequences[ci];
|
|
162
|
+
if (!seq)
|
|
163
|
+
return -1;
|
|
164
|
+
if (seq.length === 1) {
|
|
165
|
+
// Not a real multiplication: keep it a plain substitution.
|
|
166
|
+
replaceGlyph(ctx, info, seq[0]);
|
|
167
|
+
return i + 1;
|
|
168
|
+
}
|
|
169
|
+
if (seq.length === 0) {
|
|
170
|
+
// Disallowed by the spec but used by fonts (and honoured by Uniscribe) to delete.
|
|
171
|
+
deleteGlyph(buf, i);
|
|
172
|
+
return i;
|
|
173
|
+
}
|
|
174
|
+
const klass = isLigature(info) ? GlyphProps.BaseGlyph : 0;
|
|
175
|
+
const keepLig = info.ligId !== 0; // still attached to an earlier ligature: leave that be
|
|
176
|
+
const out = seq.map((g, k) => {
|
|
177
|
+
const c = cloneInfo(info);
|
|
178
|
+
if (!keepLig)
|
|
179
|
+
setLigPropsForMark(c, 0, k);
|
|
180
|
+
replaceGlyph(ctx, c, g, klass, false, true);
|
|
181
|
+
return c;
|
|
182
|
+
});
|
|
183
|
+
buf.splice(i, 1, ...out);
|
|
184
|
+
return i + out.length;
|
|
185
|
+
}
|
|
186
|
+
case 'ligature': {
|
|
187
|
+
const ci = st.coverage.get(glyph);
|
|
188
|
+
const set = ci === undefined ? undefined : st.sets[ci];
|
|
189
|
+
if (!set)
|
|
190
|
+
return -1;
|
|
191
|
+
for (const lig of set) {
|
|
192
|
+
if (!lig.components.length) {
|
|
193
|
+
replaceGlyph(ctx, info, lig.glyph);
|
|
194
|
+
return i + 1;
|
|
195
|
+
}
|
|
196
|
+
const match = ctx.matchInput(i, lig.components.length + 1, (g, k) => g.glyph === lig.components[k - 1]);
|
|
197
|
+
if (match)
|
|
198
|
+
return ligate(ctx, match.positions, match.end, lig.glyph, match.totalComponents);
|
|
199
|
+
}
|
|
200
|
+
return -1;
|
|
201
|
+
}
|
|
202
|
+
case 'reverse': {
|
|
203
|
+
// Only applied by the reverse pass itself, never as a nested lookup.
|
|
204
|
+
if (ctx.nestingLeft !== MAX_NESTING)
|
|
205
|
+
return -1;
|
|
206
|
+
const ci = st.coverage.get(glyph);
|
|
207
|
+
const out = ci === undefined ? undefined : st.substitutes[ci];
|
|
208
|
+
if (out === undefined)
|
|
209
|
+
return -1;
|
|
210
|
+
if (ctx.matchBacktrack(i, st.backtrack.length, (g, k) => st.backtrack[k]?.has(g.glyph) ?? false) &&
|
|
211
|
+
ctx.matchLookahead(i, st.lookahead.length, (g, k) => st.lookahead[k]?.has(g.glyph) ?? false)) {
|
|
212
|
+
replaceGlyph(ctx, info, out);
|
|
213
|
+
return i + 1;
|
|
214
|
+
}
|
|
215
|
+
return -1;
|
|
216
|
+
}
|
|
217
|
+
default:
|
|
218
|
+
return ctx.applyContextual(st, i);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Replaces the matched components with the ligature glyph. Marks skipped between components
|
|
223
|
+
* stay (after the ligature) and are renumbered to the component they followed, so GPOS
|
|
224
|
+
* mark-to-ligature can put each on the right part of the ligature.
|
|
225
|
+
*/
|
|
226
|
+
function ligate(ctx, positions, matchEnd, ligGlyph, totalComponents) {
|
|
227
|
+
const buf = ctx.buffer;
|
|
228
|
+
const count = positions.length;
|
|
229
|
+
const first = buf[positions[0]];
|
|
230
|
+
mergeClusters(buf, positions[0], matchEnd);
|
|
231
|
+
// A base + marks ligature stays a base (later marks still attach to it); an all-marks
|
|
232
|
+
// ligature keeps its ligature id so it can still sit on an earlier ligature component.
|
|
233
|
+
let isBaseLigature = isBaseGlyph(first);
|
|
234
|
+
let isMarkLigature = isMark(first);
|
|
235
|
+
for (let k = 1; k < count; k++) {
|
|
236
|
+
if (!isMark(buf[positions[k]])) {
|
|
237
|
+
isBaseLigature = false;
|
|
238
|
+
isMarkLigature = false;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const isLig = !isBaseLigature && !isMarkLigature;
|
|
243
|
+
const klass = isLig ? GlyphProps.Ligature : 0;
|
|
244
|
+
const ligId = isLig ? ctx.allocLigId() : 0;
|
|
245
|
+
let lastLigId = first.ligId;
|
|
246
|
+
let lastNumComps = ligNumComps(first);
|
|
247
|
+
let compsSoFar = lastNumComps;
|
|
248
|
+
if (isLig) {
|
|
249
|
+
setLigPropsForLigature(first, ligId, totalComponents);
|
|
250
|
+
first.uflags &= ~UFlag.NonSpacingMark;
|
|
251
|
+
}
|
|
252
|
+
replaceGlyph(ctx, first, ligGlyph, klass, true);
|
|
253
|
+
for (let k = 1; k < count; k++) {
|
|
254
|
+
if (isLig) {
|
|
255
|
+
for (let j = positions[k - 1] + 1; j < positions[k]; j++) {
|
|
256
|
+
const info = buf[j];
|
|
257
|
+
let thisComp = ligComp(info);
|
|
258
|
+
if (thisComp === 0)
|
|
259
|
+
thisComp = lastNumComps;
|
|
260
|
+
setLigPropsForMark(info, ligId, compsSoFar - lastNumComps + Math.min(thisComp, lastNumComps));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const comp = buf[positions[k]];
|
|
264
|
+
lastLigId = comp.ligId;
|
|
265
|
+
lastNumComps = ligNumComps(comp);
|
|
266
|
+
compsSoFar += lastNumComps;
|
|
267
|
+
}
|
|
268
|
+
if (!isMarkLigature && lastLigId) {
|
|
269
|
+
// Marks that followed the last component (itself a ligature) move to the new ligature.
|
|
270
|
+
for (let j = positions[count - 1] + 1; j < buf.length; j++) {
|
|
271
|
+
const info = buf[j];
|
|
272
|
+
if (info.ligId !== lastLigId)
|
|
273
|
+
break;
|
|
274
|
+
const thisComp = ligComp(info);
|
|
275
|
+
if (!thisComp)
|
|
276
|
+
break;
|
|
277
|
+
setLigPropsForMark(info, ligId, compsSoFar - lastNumComps + Math.min(thisComp, lastNumComps));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
for (let k = count - 1; k >= 1; k--)
|
|
281
|
+
buf.splice(positions[k], 1);
|
|
282
|
+
return positions[count - 1] - (count - 1) + 1;
|
|
283
|
+
}
|
|
284
|
+
function wouldApply(st, glyphs, zeroContext) {
|
|
285
|
+
const g0 = glyphs[0];
|
|
286
|
+
const noContext = (r) => !zeroContext || (!r.backtrack.length && !r.lookahead.length);
|
|
287
|
+
switch (st.kind) {
|
|
288
|
+
case 'single':
|
|
289
|
+
case 'multiple':
|
|
290
|
+
case 'alternate':
|
|
291
|
+
return glyphs.length === 1 && st.coverage.has(g0);
|
|
292
|
+
case 'reverse':
|
|
293
|
+
return glyphs.length === 1 && st.coverage.has(g0) && noContext(st);
|
|
294
|
+
case 'ligature': {
|
|
295
|
+
const ci = st.coverage.get(g0);
|
|
296
|
+
const set = ci === undefined ? undefined : st.sets[ci];
|
|
297
|
+
return !!set?.some((l) => l.components.length + 1 === glyphs.length && l.components.every((c, k) => c === glyphs[k + 1]));
|
|
298
|
+
}
|
|
299
|
+
case 'ctx-glyphs': {
|
|
300
|
+
const ci = st.coverage.get(g0);
|
|
301
|
+
const rules = ci === undefined ? undefined : st.ruleSets[ci];
|
|
302
|
+
return !!rules?.some((r) => noContext(r) && r.input.length + 1 === glyphs.length && r.input.every((v, k) => v === glyphs[k + 1]));
|
|
303
|
+
}
|
|
304
|
+
case 'ctx-classes': {
|
|
305
|
+
if (!st.coverage.has(g0))
|
|
306
|
+
return false;
|
|
307
|
+
const rules = st.ruleSets[classOf(st.inputClasses, g0)];
|
|
308
|
+
return !!rules?.some((r) => noContext(r) && r.input.length + 1 === glyphs.length && r.input.every((v, k) => classOf(st.inputClasses, glyphs[k + 1]) === v));
|
|
309
|
+
}
|
|
310
|
+
case 'ctx-coverage':
|
|
311
|
+
return noContext(st) && st.input.length === glyphs.length && st.input.every((c, k) => c.has(glyphs[k]));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ShapingFont } from './plan.js';
|
|
2
|
+
export { scriptOf, itemizeScripts, type ScriptRun } from './scripts.js';
|
|
3
|
+
export type { ShapingFont } from './plan.js';
|
|
4
|
+
export interface ShapedGlyph {
|
|
5
|
+
glyph: number;
|
|
6
|
+
/** UTF-16 index of the first character of the glyph's cluster. */
|
|
7
|
+
cluster: number;
|
|
8
|
+
/** Advance width in font units (0 for attached marks). */
|
|
9
|
+
advance: number;
|
|
10
|
+
/** Offset from the pen position, in font units (y up). */
|
|
11
|
+
offsetX: number;
|
|
12
|
+
offsetY: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ShapeOptions {
|
|
15
|
+
direction: 'ltr' | 'rtl';
|
|
16
|
+
/** OpenType script tag ('latn', 'arab', 'deva'...); detected from the text when absent. */
|
|
17
|
+
script?: string;
|
|
18
|
+
/** OpenType language system tag ('URD ', 'MAR '...). */
|
|
19
|
+
language?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Turn features on or off by tag: `{ liga: false }` disables standard ligatures (and
|
|
22
|
+
* kern / calt / clig likewise); `{ smcp: true, onum: true }` enables optional ones.
|
|
23
|
+
*/
|
|
24
|
+
features?: Record<string, boolean>;
|
|
25
|
+
}
|
|
26
|
+
/** Whether the font has OpenType layout tables (otherwise shaping is cmap + kern only). */
|
|
27
|
+
export declare function hasOpenTypeLayout(font: ShapingFont): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Shapes `text` (one script, one direction, one font) into glyphs in logical order, with
|
|
30
|
+
* advances and offsets in font units.
|
|
31
|
+
*/
|
|
32
|
+
export declare function shape(font: ShapingFont, text: string, options: ShapeOptions): ShapedGlyph[];
|