ultra-text 1.0.0 → 1.0.2
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 +267 -962
- package/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker--X1Qpmdp.js} +148 -57
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +69 -26
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +5 -15
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +164 -50
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.d.ts +7 -6
- package/dist/atlas/gpuAtlas.js +206 -247
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +59 -125
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +2 -0
- package/dist/atlas/rasterize.js +104 -144
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +263 -272
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.d.ts +26 -0
- package/dist/dom/DomSlug.js +564 -0
- package/dist/dom/DomSlug.js.map +1 -0
- package/dist/dom/SlugText.d.ts +18 -0
- package/dist/dom/SlugText.js +94 -0
- package/dist/dom/SlugText.js.map +1 -0
- package/dist/dom/Text.js +4 -67
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.d.ts +2 -0
- package/dist/dom/fontCanvas.js +119 -0
- package/dist/dom/fontCanvas.js.map +1 -0
- package/dist/dom/layoutSignature.js +156 -27
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +563 -243
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textHost.d.ts +11 -0
- package/dist/dom/textHost.js +68 -0
- package/dist/dom/textHost.js.map +1 -0
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +13 -4
- package/dist/slug/SlugMaterial.js +82 -12
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +17 -13
- package/dist/slug/coverage.js +195 -222
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -3
- package/dist/slug/preprocessCore.js +149 -95
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +94 -46
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +40 -0
- package/dist/slug/standaloneRuntime.js +175 -0
- package/dist/slug/standaloneRuntime.js.map +1 -0
- package/dist/slug/truetype.d.ts +22 -0
- package/dist/slug/truetype.js +467 -0
- package/dist/slug/truetype.js.map +1 -0
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -0
- package/dist/slug-vanilla.js +13 -0
- package/dist/slug.d.ts +21 -0
- package/dist/slug.js +19 -0
- package/dist/text/GlyphTextMaterial.d.ts +11 -11
- package/dist/text/GlyphTextMaterial.js +102 -33
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +5 -4
- package/dist/text/SdfTextMaterial.js +29 -9
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/types.d.ts +63 -14
- package/dist/vanilla.d.ts +13 -360
- package/dist/vanilla.js +8 -1402
- package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
- package/dist/windfoil/WindfoilMaterial.js +8 -1
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/abortable.d.ts +2 -0
- package/dist/windfoil/abortable.js +26 -0
- package/dist/windfoil/abortable.js.map +1 -0
- package/dist/windfoil/color.js +2 -1
- package/dist/windfoil/color.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +3 -20
- package/dist/windfoil/coverage.js +7 -20
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/emoji.js +1 -1
- package/dist/windfoil/emoji.js.map +1 -1
- package/dist/windfoil/emojiMetrics.js +1 -1
- package/dist/windfoil/emojiMetrics.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +204 -64
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +14 -10
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/layerNormalization.d.ts +1 -1
- package/dist/windfoil/layerNormalization.js +1 -1
- package/dist/windfoil/layerNormalization.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/outlineValidation.d.ts +86 -0
- package/dist/windfoil/outlineValidation.js +65 -0
- package/dist/windfoil/outlineValidation.js.map +1 -0
- package/dist/windfoil/preprocess.js +3 -2
- package/dist/windfoil/preprocess.js.map +1 -1
- package/dist/windfoil/preprocessCore.d.ts +5 -85
- package/dist/windfoil/preprocessCore.js +218 -209
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.js +1 -1
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +5 -2
- package/dist/windfoil/runtime.js +63 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeResources.js +2 -1
- package/dist/windfoil/shapeResources.js.map +1 -1
- package/dist/windfoil/shapes.js +1 -1
- package/dist/windfoil/skirt.d.ts +22 -0
- package/dist/windfoil/skirt.js +20 -0
- package/dist/windfoil/skirt.js.map +1 -0
- package/dist/windfoil/storage.d.ts +62 -4
- package/dist/windfoil/storage.js +143 -28
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +3 -3
- package/dist/windfoil/trace/contours.js +228 -137
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -7
- package/dist/windfoil/trace/fit.js +668 -376
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +60 -35
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +15 -3
- package/dist/windfoil/tracedOutlines.d.ts +37 -1
- package/dist/windfoil/tracedOutlines.js +228 -64
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +60 -11
- package/skills/ultra-text/SKILL.md +114 -0
- package/skills/ultra-text/references/frameworks.md +43 -0
- package/skills/ultra-text/references/three-tsl.md +78 -0
- package/skills/ultra-text/references/vanilla-webgpu.md +96 -0
- package/dist/assets/cpuSdf.worker-Du9o8q4p.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
|
@@ -11,6 +11,68 @@ var ATTRIBUTES = [
|
|
|
11
11
|
"windfoilBand"
|
|
12
12
|
];
|
|
13
13
|
var LAYERED_ATTRIBUTES = [...ATTRIBUTES, "windfoilLayer"];
|
|
14
|
+
var SLOT_RECT = 0;
|
|
15
|
+
var SLOT_CLIP = 1;
|
|
16
|
+
var SLOT_COLOR = 2;
|
|
17
|
+
var SLOT_META = 3;
|
|
18
|
+
var SLOT_BOUNDS = 4;
|
|
19
|
+
var SLOT_BAND = 5;
|
|
20
|
+
var SLOT_LAYER = 6;
|
|
21
|
+
var DIRTY_UNSET = 2147483647;
|
|
22
|
+
var dirtyBounds = /* @__PURE__ */ new Int32Array(14);
|
|
23
|
+
function resetDirtyBounds() {
|
|
24
|
+
for (let slot = 0; slot < 7; slot++) {
|
|
25
|
+
const base = slot * 2;
|
|
26
|
+
dirtyBounds[base] = DIRTY_UNSET;
|
|
27
|
+
dirtyBounds[base + 1] = 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function recordDirty(slot, start, end) {
|
|
31
|
+
const base = slot * 2;
|
|
32
|
+
if (start < dirtyBounds[base]) dirtyBounds[base] = start;
|
|
33
|
+
if (end > dirtyBounds[base + 1]) dirtyBounds[base + 1] = end;
|
|
34
|
+
}
|
|
35
|
+
function flushAttributeUpdate(attribute, dirtyStart, dirtyEnd) {
|
|
36
|
+
if (attribute.version === 0) {
|
|
37
|
+
attribute.needsUpdate = true;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (dirtyEnd <= dirtyStart) return;
|
|
41
|
+
let start = dirtyStart;
|
|
42
|
+
let end = dirtyEnd;
|
|
43
|
+
for (const range of attribute.updateRanges) {
|
|
44
|
+
if (range.count < 0) {
|
|
45
|
+
start = 0;
|
|
46
|
+
end = attribute.array.length;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
if (range.start < start) start = range.start;
|
|
50
|
+
const rangeEnd = range.start + range.count;
|
|
51
|
+
if (rangeEnd > end) end = rangeEnd;
|
|
52
|
+
}
|
|
53
|
+
attribute.clearUpdateRanges();
|
|
54
|
+
attribute.addUpdateRange(start, end - start);
|
|
55
|
+
attribute.needsUpdate = true;
|
|
56
|
+
}
|
|
57
|
+
function writeFloat4(target, offset, a, b, c, d, trackDirty, slot) {
|
|
58
|
+
if (trackDirty) {
|
|
59
|
+
const fa = Math.fround(a);
|
|
60
|
+
const fb = Math.fround(b);
|
|
61
|
+
const fc = Math.fround(c);
|
|
62
|
+
const fd = Math.fround(d);
|
|
63
|
+
if (target[offset] === fa && target[offset + 1] === fb && target[offset + 2] === fc && target[offset + 3] === fd) return;
|
|
64
|
+
target[offset] = fa;
|
|
65
|
+
target[offset + 1] = fb;
|
|
66
|
+
target[offset + 2] = fc;
|
|
67
|
+
target[offset + 3] = fd;
|
|
68
|
+
recordDirty(slot, offset, offset + 4);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
target[offset] = a;
|
|
72
|
+
target[offset + 1] = b;
|
|
73
|
+
target[offset + 2] = c;
|
|
74
|
+
target[offset + 3] = d;
|
|
75
|
+
}
|
|
14
76
|
var scratchRect = [
|
|
15
77
|
0,
|
|
16
78
|
0,
|
|
@@ -34,52 +96,59 @@ function windfoilGlyphRect(glyph, header, bbox = header.bbox) {
|
|
|
34
96
|
0
|
|
35
97
|
]);
|
|
36
98
|
}
|
|
37
|
-
|
|
38
|
-
function writeLayerInstance(glyph, header, layer, index, ordinal, attributes, glyphRect) {
|
|
99
|
+
function writeInstance(glyph, header, layer, index, ordinal, attributes, c0, c1, c2, c3, glyphRect, trackDirty = false) {
|
|
39
100
|
const offset = index * 4;
|
|
40
101
|
const scale = glyph.fontSize / header.unitsPerEm;
|
|
41
102
|
const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale);
|
|
42
103
|
const ox = glyph.originX;
|
|
43
104
|
const lBox = layer.bbox;
|
|
44
105
|
const b0 = lBox[0], b1 = lBox[1], b2 = lBox[2], b3 = lBox[3];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
rects[offset + 2] = ox + b2 * scale;
|
|
49
|
-
rects[offset + 3] = baseline + b3 * scale;
|
|
50
|
-
const clips = attributes.clips, clip = glyph.clip;
|
|
51
|
-
clips[offset] = clip[0];
|
|
52
|
-
clips[offset + 1] = clip[1];
|
|
53
|
-
clips[offset + 2] = clip[2];
|
|
54
|
-
clips[offset + 3] = clip[3];
|
|
55
|
-
const paint = "paintKind" in layer ? layer : null;
|
|
56
|
-
const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color;
|
|
106
|
+
writeFloat4(attributes.rects, offset, ox + b0 * scale, baseline + b1 * scale, ox + b2 * scale, baseline + b3 * scale, trackDirty, SLOT_RECT);
|
|
107
|
+
const clip = glyph.clip;
|
|
108
|
+
writeFloat4(attributes.clips, offset, clip[0], clip[1], clip[2], clip[3], trackDirty, SLOT_CLIP);
|
|
57
109
|
const colors = attributes.colors;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
110
|
+
if (trackDirty) {
|
|
111
|
+
if (colors[offset] !== c0 || colors[offset + 1] !== c1 || colors[offset + 2] !== c2 || colors[offset + 3] !== c3) {
|
|
112
|
+
colors[offset] = c0;
|
|
113
|
+
colors[offset + 1] = c1;
|
|
114
|
+
colors[offset + 2] = c2;
|
|
115
|
+
colors[offset + 3] = c3;
|
|
116
|
+
recordDirty(SLOT_COLOR, offset, offset + 4);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
colors[offset] = c0;
|
|
120
|
+
colors[offset + 1] = c1;
|
|
121
|
+
colors[offset + 2] = c2;
|
|
122
|
+
colors[offset + 3] = c3;
|
|
123
|
+
}
|
|
124
|
+
const metaSizeValue = attributes.metaSize ?? 2;
|
|
125
|
+
const metadata = attributes.metadata;
|
|
126
|
+
if (trackDirty) {
|
|
127
|
+
const mOffset = index * metaSizeValue;
|
|
128
|
+
const seq = Math.fround(glyph.sequence);
|
|
129
|
+
const gz = Math.fround(glyph.z);
|
|
130
|
+
const sw = metaSizeValue === 3 ? Math.fround(glyph.switchEm ?? 0) : 0;
|
|
131
|
+
if (metadata[mOffset] !== seq || metadata[mOffset + 1] !== gz || metaSizeValue === 3 && metadata[mOffset + 2] !== sw) {
|
|
132
|
+
writeMeta(metadata, index, metaSizeValue, glyph);
|
|
133
|
+
recordDirty(SLOT_META, mOffset, mOffset + metaSizeValue);
|
|
134
|
+
}
|
|
135
|
+
} else writeMeta(metadata, index, metaSizeValue, glyph);
|
|
136
|
+
writeFloat4(attributes.bounds, offset, b0, b1, b2, b3, trackDirty, SLOT_BOUNDS);
|
|
137
|
+
writeFloat4(attributes.bands, offset, layer.rowBase, layer.bandCount, layer.bandH, layer.invH, trackDirty, SLOT_BAND);
|
|
73
138
|
const layers = attributes.layers;
|
|
74
139
|
if (layers) {
|
|
140
|
+
const paint = "paintKind" in layer ? layer : null;
|
|
75
141
|
const rect = glyphRect ?? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect);
|
|
76
142
|
const mo = glyph.motionOrigin;
|
|
77
|
-
layers
|
|
78
|
-
layers[offset + 1] = mo ? mo[1] : (rect[1] + rect[3]) / 2;
|
|
79
|
-
layers[offset + 2] = ordinal;
|
|
80
|
-
layers[offset + 3] = paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : paint?.paintKind ?? 0;
|
|
143
|
+
writeFloat4(layers, offset, mo ? mo[0] : (rect[0] + rect[2]) / 2, mo ? mo[1] : (rect[1] + rect[3]) / 2, ordinal, paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : paint?.paintKind ?? 0, trackDirty, SLOT_LAYER);
|
|
81
144
|
}
|
|
82
145
|
}
|
|
146
|
+
/** Shared by text and shape geometry; one layer adds only one vertex attribute. */
|
|
147
|
+
function writeLayerInstance(glyph, header, layer, index, ordinal, attributes, glyphRect, trackDirty = false) {
|
|
148
|
+
const paint = "paintKind" in layer ? layer : null;
|
|
149
|
+
const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color;
|
|
150
|
+
writeInstance(glyph, header, layer, index, ordinal, attributes, byte(rgb[0]), byte(rgb[1]), byte(rgb[2]), byte(glyph.color[3] * (paint ? paint.rgba[3] : 1)), glyphRect, trackDirty);
|
|
151
|
+
}
|
|
83
152
|
function countLayout(snapshot, glyphs, layered) {
|
|
84
153
|
let instances = 0, drawable = 0;
|
|
85
154
|
for (const glyph of snapshot.glyphs) {
|
|
@@ -94,12 +163,20 @@ function countLayout(snapshot, glyphs, layered) {
|
|
|
94
163
|
drawable
|
|
95
164
|
};
|
|
96
165
|
}
|
|
97
|
-
function writeGeometry(snapshot, glyphs, attributes, ordinals) {
|
|
166
|
+
function writeGeometry(snapshot, glyphs, attributes, ordinals, trackDirty = false) {
|
|
98
167
|
let instance = 0, drawable = 0, maxSequence = 0, minZ = 0, maxZ = 0;
|
|
168
|
+
let prevKey;
|
|
169
|
+
let prevHeader;
|
|
170
|
+
let prevColor;
|
|
171
|
+
let pc0 = 0;
|
|
172
|
+
let pc1 = 0;
|
|
173
|
+
let pc2 = 0;
|
|
174
|
+
let pc3 = 0;
|
|
99
175
|
const glyphList = snapshot.glyphs;
|
|
100
176
|
for (let i = 0; i < glyphList.length; i++) {
|
|
101
177
|
const glyph = glyphList[i];
|
|
102
|
-
const
|
|
178
|
+
const key = glyph.glyphKey;
|
|
179
|
+
const header = key === prevKey ? prevHeader : (prevKey = key, prevHeader = glyphs.get(key));
|
|
103
180
|
if (!header?.monotonePieceCount) continue;
|
|
104
181
|
const ordinal = ordinals?.[i] ?? glyph.motionOrigin?.[2] ?? drawable;
|
|
105
182
|
const rect = attributes.layers || attributes.glyphRects ? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect) : void 0;
|
|
@@ -110,14 +187,32 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals) {
|
|
|
110
187
|
attributes.glyphRects[rectOffset + 2] = rect[2];
|
|
111
188
|
attributes.glyphRects[rectOffset + 3] = rect[3];
|
|
112
189
|
}
|
|
113
|
-
if (attributes.layers && header.layers) for (const layer of header.layers) writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect);
|
|
114
|
-
else
|
|
190
|
+
if (attributes.layers && header.layers) for (const layer of header.layers) writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect, trackDirty);
|
|
191
|
+
else {
|
|
192
|
+
const layer = header.layers?.[0] ?? header;
|
|
193
|
+
const paint = "paintKind" in layer ? layer : null;
|
|
194
|
+
if (paint) {
|
|
195
|
+
const rgb = paint.paintKind === 1 ? paint.rgba : glyph.color;
|
|
196
|
+
writeInstance(glyph, header, layer, instance++, ordinal, attributes, byte(rgb[0]), byte(rgb[1]), byte(rgb[2]), byte(glyph.color[3] * paint.rgba[3]), rect, trackDirty);
|
|
197
|
+
} else {
|
|
198
|
+
const color = glyph.color;
|
|
199
|
+
if (color !== prevColor) {
|
|
200
|
+
prevColor = color;
|
|
201
|
+
pc0 = byte(color[0]);
|
|
202
|
+
pc1 = byte(color[1]);
|
|
203
|
+
pc2 = byte(color[2]);
|
|
204
|
+
pc3 = byte(color[3]);
|
|
205
|
+
}
|
|
206
|
+
writeInstance(glyph, header, layer, instance++, ordinal, attributes, pc0, pc1, pc2, pc3, rect, trackDirty);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
115
209
|
drawable++;
|
|
116
210
|
if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
|
|
117
211
|
if (glyph.z < minZ) minZ = glyph.z;
|
|
118
212
|
if (glyph.z > maxZ) maxZ = glyph.z;
|
|
119
213
|
}
|
|
120
214
|
return {
|
|
215
|
+
instances: instance,
|
|
121
216
|
maxSequence,
|
|
122
217
|
minZ,
|
|
123
218
|
maxZ
|
|
@@ -126,67 +221,104 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals) {
|
|
|
126
221
|
/** Ordinary outlines retain the original six instance attributes. */
|
|
127
222
|
function createWindfoilGlyphGeometry(snapshot, glyphs, motionPadding, layered = false, ordinals) {
|
|
128
223
|
layered ||= !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin);
|
|
129
|
-
const { instances: count, drawable } = countLayout(snapshot, glyphs, layered);
|
|
130
224
|
const meta = metaSize(snapshot);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
225
|
+
let count;
|
|
226
|
+
let rects;
|
|
227
|
+
let clips;
|
|
228
|
+
let colors;
|
|
229
|
+
let metadata;
|
|
230
|
+
let bounds;
|
|
231
|
+
let bands;
|
|
232
|
+
let layers;
|
|
233
|
+
let glyphRects;
|
|
234
|
+
if (layered) {
|
|
235
|
+
const counted = countLayout(snapshot, glyphs, true);
|
|
236
|
+
count = counted.instances;
|
|
237
|
+
rects = new Float32Array(count * 4);
|
|
238
|
+
clips = new Float32Array(count * 4);
|
|
239
|
+
colors = new Uint8Array(count * 4);
|
|
240
|
+
metadata = new Float32Array(count * meta);
|
|
241
|
+
bounds = new Float32Array(count * 4);
|
|
242
|
+
bands = new Float32Array(count * 4);
|
|
243
|
+
layers = new Float32Array(count * 4);
|
|
244
|
+
glyphRects = new Float32Array(counted.drawable * 4);
|
|
245
|
+
} else {
|
|
246
|
+
const total = snapshot.glyphs.length;
|
|
247
|
+
count = total;
|
|
248
|
+
rects = new Float32Array(total * 4);
|
|
249
|
+
clips = new Float32Array(total * 4);
|
|
250
|
+
colors = new Uint8Array(total * 4);
|
|
251
|
+
metadata = new Float32Array(total * meta);
|
|
252
|
+
bounds = new Float32Array(total * 4);
|
|
253
|
+
bands = new Float32Array(total * 4);
|
|
254
|
+
}
|
|
255
|
+
const result = writeGeometry(snapshot, glyphs, {
|
|
256
|
+
rects,
|
|
257
|
+
clips,
|
|
258
|
+
colors,
|
|
259
|
+
metadata,
|
|
136
260
|
metaSize: meta,
|
|
137
|
-
bounds
|
|
138
|
-
bands
|
|
139
|
-
...
|
|
140
|
-
layers
|
|
141
|
-
glyphRects
|
|
261
|
+
bounds,
|
|
262
|
+
bands,
|
|
263
|
+
...layers && glyphRects ? {
|
|
264
|
+
layers,
|
|
265
|
+
glyphRects
|
|
142
266
|
} : {}
|
|
143
|
-
};
|
|
144
|
-
|
|
267
|
+
}, ordinals);
|
|
268
|
+
if (!layered && result.instances < count) {
|
|
269
|
+
count = result.instances;
|
|
270
|
+
rects = rects.subarray(0, count * 4);
|
|
271
|
+
clips = clips.subarray(0, count * 4);
|
|
272
|
+
colors = colors.subarray(0, count * 4);
|
|
273
|
+
metadata = metadata.subarray(0, count * meta);
|
|
274
|
+
bounds = bounds.subarray(0, count * 4);
|
|
275
|
+
bands = bands.subarray(0, count * 4);
|
|
276
|
+
}
|
|
145
277
|
const geometry = new InstancedBufferGeometry();
|
|
146
278
|
geometry.name = "ultra-text instanced Windfoil glyph quads";
|
|
147
279
|
setUnitQuad(geometry);
|
|
148
280
|
for (const [name, data, size, normalized] of [
|
|
149
281
|
[
|
|
150
282
|
"sdfRect",
|
|
151
|
-
|
|
283
|
+
rects,
|
|
152
284
|
4,
|
|
153
285
|
false
|
|
154
286
|
],
|
|
155
287
|
[
|
|
156
288
|
"sdfClip",
|
|
157
|
-
|
|
289
|
+
clips,
|
|
158
290
|
4,
|
|
159
291
|
false
|
|
160
292
|
],
|
|
161
293
|
[
|
|
162
294
|
"sdfColor",
|
|
163
|
-
|
|
295
|
+
colors,
|
|
164
296
|
4,
|
|
165
297
|
true
|
|
166
298
|
],
|
|
167
299
|
[
|
|
168
300
|
"sdfMeta",
|
|
169
|
-
|
|
301
|
+
metadata,
|
|
170
302
|
meta,
|
|
171
303
|
false
|
|
172
304
|
],
|
|
173
305
|
[
|
|
174
306
|
"windfoilBounds",
|
|
175
|
-
|
|
307
|
+
bounds,
|
|
176
308
|
4,
|
|
177
309
|
false
|
|
178
310
|
],
|
|
179
311
|
[
|
|
180
312
|
"windfoilBand",
|
|
181
|
-
|
|
313
|
+
bands,
|
|
182
314
|
4,
|
|
183
315
|
false
|
|
184
316
|
]
|
|
185
317
|
]) geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized));
|
|
186
|
-
if (
|
|
187
|
-
geometry.setAttribute("windfoilLayer", new InstancedBufferAttribute(
|
|
188
|
-
geometry.userData[GLYPH_RECTS_KEY] =
|
|
189
|
-
geometry.userData["ultraOwnGlyphRects"] =
|
|
318
|
+
if (layers) {
|
|
319
|
+
geometry.setAttribute("windfoilLayer", new InstancedBufferAttribute(layers, 4));
|
|
320
|
+
geometry.userData[GLYPH_RECTS_KEY] = glyphRects;
|
|
321
|
+
geometry.userData["ultraOwnGlyphRects"] = glyphRects;
|
|
190
322
|
}
|
|
191
323
|
geometry.instanceCount = count;
|
|
192
324
|
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ);
|
|
@@ -212,10 +344,12 @@ function windfoilContentFits(geometry, snapshot, glyphs) {
|
|
|
212
344
|
}
|
|
213
345
|
return instances === geometry.instanceCount && (!layered || geometry.userData["ultraOwnGlyphRects"]?.length === drawable * 4);
|
|
214
346
|
}
|
|
215
|
-
function updateWindfoilGlyphGeometry(geometry, snapshot, glyphs, motionPadding, ordinals) {
|
|
216
|
-
if (!windfoilContentFits(geometry, snapshot, glyphs)) return null;
|
|
347
|
+
function updateWindfoilGlyphGeometry(geometry, snapshot, glyphs, motionPadding, ordinals, checked = false) {
|
|
348
|
+
if (!checked && !windfoilContentFits(geometry, snapshot, glyphs)) return null;
|
|
217
349
|
const array = (name) => geometry.getAttribute(name).array;
|
|
218
350
|
const layer = geometry.getAttribute("windfoilLayer");
|
|
351
|
+
const trackDirty = geometry.getAttribute("sdfRect").version > 0 || geometry.getAttribute("sdfClip").version > 0 || geometry.getAttribute("sdfColor").version > 0 || geometry.getAttribute("sdfMeta").version > 0 || geometry.getAttribute("windfoilBounds").version > 0 || geometry.getAttribute("windfoilBand").version > 0 || (layer?.version ?? 0) > 0;
|
|
352
|
+
if (trackDirty) resetDirtyBounds();
|
|
219
353
|
const result = writeGeometry(snapshot, glyphs, {
|
|
220
354
|
rects: array("sdfRect"),
|
|
221
355
|
clips: array("sdfClip"),
|
|
@@ -228,8 +362,14 @@ function updateWindfoilGlyphGeometry(geometry, snapshot, glyphs, motionPadding,
|
|
|
228
362
|
layers: layer.array,
|
|
229
363
|
glyphRects: geometry.userData["ultraOwnGlyphRects"]
|
|
230
364
|
} : {}
|
|
231
|
-
}, ordinals);
|
|
232
|
-
|
|
365
|
+
}, ordinals, trackDirty);
|
|
366
|
+
const list = layer ? LAYERED_ATTRIBUTES : ATTRIBUTES;
|
|
367
|
+
if (trackDirty) for (let i = 0; i < list.length; i++) {
|
|
368
|
+
const attribute = geometry.getAttribute(list[i]);
|
|
369
|
+
const base = i * 2;
|
|
370
|
+
flushAttributeUpdate(attribute, dirtyBounds[base], dirtyBounds[base + 1]);
|
|
371
|
+
}
|
|
372
|
+
else for (const name of list) geometry.getAttribute(name).needsUpdate = true;
|
|
233
373
|
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ);
|
|
234
374
|
return result.maxSequence;
|
|
235
375
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.js","names":[],"sources":["../../src/windfoil/geometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport { byte, metaSize, setBounds, setUnitQuad, writeMeta } from '../text/geometryUtils.js'\nimport { GLYPH_RECTS_KEY } from '../text/decorations.js'\nimport type { DomLayoutSnapshot, GlyphLayout, WindfoilBoundingBox } from '../types.js'\nimport type { WindfoilGlyphHeader, WindfoilLayerHeader } from './preprocess.js'\n\nconst ATTRIBUTES = [\n 'sdfRect',\n 'sdfClip',\n 'sdfColor',\n 'sdfMeta',\n 'windfoilBounds',\n 'windfoilBand',\n] as const\nconst LAYERED_ATTRIBUTES = [...ATTRIBUTES, 'windfoilLayer'] as const\n\nexport interface MutableWindfoilAttributes {\n readonly rects: Float32Array\n readonly clips: Float32Array\n readonly colors: Uint8Array\n readonly metadata: Float32Array\n /** Components per `sdfMeta` entry; `3` carries the size-switch em. Defaults to `2`. */\n readonly metaSize?: number\n readonly bounds: Float32Array\n readonly bands: Float32Array\n readonly layers?: Float32Array\n readonly glyphRects?: Float32Array\n}\n\nconst scratchRect: [number, number, number, number] = [0, 0, 0, 0]\n\nexport function fillWindfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n out: [number, number, number, number] = scratchRect,\n): [number, number, number, number] {\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n out[0] = glyph.originX + bbox[0] * scale\n out[1] = baseline + bbox[1] * scale\n out[2] = glyph.originX + bbox[2] * scale\n out[3] = baseline + bbox[3] * scale\n return out\n}\n\nexport function windfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n): readonly [number, number, number, number] {\n return fillWindfoilGlyphRect(glyph, header, bbox, [0, 0, 0, 0])\n}\n\n/** Shared by text and shape geometry; one layer adds only one vertex attribute. */\nexport function writeLayerInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n glyphRect?: readonly [number, number, number, number],\n): void {\n const offset = index * 4\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n const ox = glyph.originX\n const lBox = layer.bbox\n const b0 = lBox[0],\n b1 = lBox[1],\n b2 = lBox[2],\n b3 = lBox[3]\n const rects = attributes.rects\n rects[offset] = ox + b0 * scale\n rects[offset + 1] = baseline + b1 * scale\n rects[offset + 2] = ox + b2 * scale\n rects[offset + 3] = baseline + b3 * scale\n const clips = attributes.clips,\n clip = glyph.clip\n clips[offset] = clip[0]\n clips[offset + 1] = clip[1]\n clips[offset + 2] = clip[2]\n clips[offset + 3] = clip[3]\n const paint = 'paintKind' in layer ? layer : null\n const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color\n const colors = attributes.colors\n colors[offset] = byte(rgb[0])\n colors[offset + 1] = byte(rgb[1])\n colors[offset + 2] = byte(rgb[2])\n colors[offset + 3] = byte(glyph.color[3] * (paint ? paint.rgba[3] : 1))\n writeMeta(attributes.metadata, index, attributes.metaSize ?? 2, glyph)\n const bounds = attributes.bounds\n bounds[offset] = b0\n bounds[offset + 1] = b1\n bounds[offset + 2] = b2\n bounds[offset + 3] = b3\n const bands = attributes.bands\n bands[offset] = layer.rowBase\n bands[offset + 1] = layer.bandCount\n bands[offset + 2] = layer.bandH\n bands[offset + 3] = layer.invH\n const layers = attributes.layers\n if (layers) {\n const rect = glyphRect ?? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n const mo = glyph.motionOrigin\n layers[offset] = mo ? mo[0] : (rect[0] + rect[2]) / 2\n layers[offset + 1] = mo ? mo[1] : (rect[1] + rect[3]) / 2\n layers[offset + 2] = ordinal\n layers[offset + 3] =\n paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : (paint?.paintKind ?? 0)\n }\n}\n\nfunction countLayout(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n layered: boolean,\n): { instances: number; drawable: number } {\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? (header.layers?.length ?? 1) : 1\n }\n }\n return { instances, drawable }\n}\n\nfunction writeGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n attributes: MutableWindfoilAttributes,\n ordinals?: Float32Array,\n): { maxSequence: number; minZ: number; maxZ: number } {\n let instance = 0,\n drawable = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0\n const glyphList = snapshot.glyphs\n for (let i = 0; i < glyphList.length; i++) {\n const glyph = glyphList[i]!\n const header = glyphs.get(glyph.glyphKey)\n if (!header?.monotonePieceCount) continue\n const ordinal = ordinals?.[i] ?? glyph.motionOrigin?.[2] ?? drawable\n const rect =\n attributes.layers || attributes.glyphRects\n ? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n : undefined\n if (attributes.glyphRects && rect) {\n const rectOffset = drawable * 4\n attributes.glyphRects[rectOffset] = rect[0]\n attributes.glyphRects[rectOffset + 1] = rect[1]\n attributes.glyphRects[rectOffset + 2] = rect[2]\n attributes.glyphRects[rectOffset + 3] = rect[3]\n }\n if (attributes.layers && header.layers) {\n for (const layer of header.layers) {\n writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect)\n }\n } else {\n writeLayerInstance(\n glyph,\n header,\n header.layers?.[0] ?? header,\n instance++,\n ordinal,\n attributes,\n rect,\n )\n }\n drawable++\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n }\n return { maxSequence, minZ, maxZ }\n}\n\n/** Ordinary outlines retain the original six instance attributes. */\nexport function createWindfoilGlyphGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n layered = false,\n ordinals?: Float32Array,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n layered ||= !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin)\n const { instances: count, drawable } = countLayout(snapshot, glyphs, layered)\n const meta = metaSize(snapshot)\n const mutable: MutableWindfoilAttributes = {\n rects: new Float32Array(count * 4),\n clips: new Float32Array(count * 4),\n colors: new Uint8Array(count * 4),\n metadata: new Float32Array(count * meta),\n metaSize: meta,\n bounds: new Float32Array(count * 4),\n bands: new Float32Array(count * 4),\n ...(layered\n ? {\n layers: new Float32Array(count * 4),\n glyphRects: new Float32Array(drawable * 4),\n }\n : {}),\n }\n const result = writeGeometry(snapshot, glyphs, mutable, ordinals)\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced Windfoil glyph quads'\n setUnitQuad(geometry)\n for (const [name, data, size, normalized] of [\n ['sdfRect', mutable.rects, 4, false],\n ['sdfClip', mutable.clips, 4, false],\n ['sdfColor', mutable.colors, 4, true],\n ['sdfMeta', mutable.metadata, meta, false],\n ['windfoilBounds', mutable.bounds, 4, false],\n ['windfoilBand', mutable.bands, 4, false],\n ] as const)\n geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized))\n if (mutable.layers) {\n geometry.setAttribute('windfoilLayer', new InstancedBufferAttribute(mutable.layers, 4))\n geometry.userData[GLYPH_RECTS_KEY] = mutable.glyphRects\n geometry.userData['ultraOwnGlyphRects'] = mutable.glyphRects\n }\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n return { geometry, maxSequence: result.maxSequence }\n}\n\nexport function windfoilContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n): boolean {\n const layered =\n (geometry.getAttribute('windfoilLayer') as InstancedBufferAttribute | undefined) !== undefined\n const names = layered ? LAYERED_ATTRIBUTES : ATTRIBUTES\n for (const name of names) {\n if (\n (geometry.getAttribute(name) as InstancedBufferAttribute | undefined)?.count !==\n geometry.instanceCount\n )\n return false\n }\n if (\n (geometry.getAttribute('sdfMeta') as InstancedBufferAttribute).itemSize !== metaSize(snapshot)\n )\n return false\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n const layers = header?.layers?.length ?? 1\n if (!layered && (glyph.motionOrigin || layers > 1)) return false\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? layers : 1\n }\n }\n return (\n instances === geometry.instanceCount &&\n (!layered ||\n (geometry.userData['ultraOwnGlyphRects'] as Float32Array | undefined)?.length ===\n drawable * 4)\n )\n}\n\nexport function updateWindfoilGlyphGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n ordinals?: Float32Array,\n): number | null {\n if (!windfoilContentFits(geometry, snapshot, glyphs)) return null\n const array = (name: string): Float32Array => geometry.getAttribute(name).array as Float32Array\n const layer = geometry.getAttribute('windfoilLayer') as InstancedBufferAttribute | undefined\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\n rects: array('sdfRect'),\n clips: array('sdfClip'),\n colors: geometry.getAttribute('sdfColor').array as Uint8Array,\n metadata: array('sdfMeta'),\n metaSize: geometry.getAttribute('sdfMeta').itemSize,\n bounds: array('windfoilBounds'),\n bands: array('windfoilBand'),\n ...(layer\n ? {\n layers: layer.array as Float32Array,\n glyphRects: geometry.userData['ultraOwnGlyphRects'] as Float32Array,\n }\n : {}),\n },\n ordinals,\n )\n for (const name of layer ? LAYERED_ATTRIBUTES : ATTRIBUTES)\n (geometry.getAttribute(name) as InstancedBufferAttribute).needsUpdate = true\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n return result.maxSequence\n}\n"],"mappings":";;;;AAMA,IAAM,aAAa;CACjB;CACA;CACA;CACA;CACA;CACA;AACF;AACA,IAAM,qBAAqB,CAAC,GAAG,YAAY,eAAe;AAe1D,IAAM,cAAgD;CAAC;CAAG;CAAG;CAAG;AAAC;AAEjE,SAAgB,sBACd,OACA,QACA,OAA4B,OAAO,MACnC,MAAwC,aACN;CAClC,MAAM,QAAQ,MAAM,WAAW,OAAO;CACtC,MAAM,WAAW,MAAM,cAAc,MAAM,kBAAkB,CAAC,OAAO,UAAU;CAC/E,IAAI,KAAK,MAAM,UAAU,KAAK,KAAK;CACnC,IAAI,KAAK,WAAW,KAAK,KAAK;CAC9B,IAAI,KAAK,MAAM,UAAU,KAAK,KAAK;CACnC,IAAI,KAAK,WAAW,KAAK,KAAK;CAC9B,OAAO;AACT;AAEA,SAAgB,kB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;GACA,aAAa,UAAU,SAAS;EAClC;CACF;CACA,OACE,cAAc,SAAS,kBACtB,CAAC,WACC,SAAS,SAAS,qBAAqB,EAA+B,WACrE,WAAW;AAEnB;AAEA,SAAgB,4BACd,UACA,UACA,QACA,eACA,UACe;CACf,IAAI,CAAC,oBAAoB,UAAU,UAAU,MAAM,GAAG,OAAO;CAC7D,MAAM,SAAS,SAA+B,SAAS,aAAa,IAAI,CAAC,CAAC;CAC1E,MAAM,QAAQ,SAAS,aAAa,eAAe;CACnD,MAAM,SAAS,cACb,UACA,QACA;EACE,OAAO,MAAM,SAAS;EACtB,OAAO,MAAM,SAAS;EACtB,QAAQ,SAAS,aAAa,UAAU,CAAC,CAAC;EAC1C,UAAU,MAAM,SAAS;EACzB,UAAU,SAAS,aAAa,SAAS,CAAC,CAAC;EAC3C,QAAQ,MAAM,gBAAgB;EAC9B,OAAO,MAAM,cAAc;EAC3B,GAAI,QACA;GACE,QAAQ,MAAM;GACd,YAAY,SAAS,SAAS;EAChC,IACA,CAAC;CACP,GACA,QACF;CACA,KAAK,MAAM,QAAQ,QAAQ,qBAAqB,YAC9C,SAAU,aAAa,IAAI,CAAC,CAA8B,cAAc;CAC1E,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,eAAe,OAAO,MAAM,OAAO,IAAI;CAC5F,OAAO,OAAO;AAChB"}
|
|
1
|
+
{"version":3,"file":"geometry.js","names":[],"sources":["../../src/windfoil/geometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport { byte, metaSize, setBounds, setUnitQuad, writeMeta } from '../text/geometryUtils.js'\nimport { GLYPH_RECTS_KEY } from '../text/decorations.js'\nimport type { DomLayoutSnapshot, GlyphLayout, WindfoilBoundingBox } from '../types.js'\nimport type { WindfoilGlyphHeader, WindfoilLayerHeader } from './preprocess.js'\n\nconst ATTRIBUTES = [\n 'sdfRect',\n 'sdfClip',\n 'sdfColor',\n 'sdfMeta',\n 'windfoilBounds',\n 'windfoilBand',\n] as const\nconst LAYERED_ATTRIBUTES = [...ATTRIBUTES, 'windfoilLayer'] as const\n\nconst SLOT_RECT = 0\nconst SLOT_CLIP = 1\nconst SLOT_COLOR = 2\nconst SLOT_META = 3\nconst SLOT_BOUNDS = 4\nconst SLOT_BAND = 5\nconst SLOT_LAYER = 6\nconst DIRTY_UNSET = 0x7fffffff\nconst dirtyBounds = new Int32Array(14)\n\nfunction resetDirtyBounds(): void {\n for (let slot = 0; slot < 7; slot++) {\n const base = slot * 2\n dirtyBounds[base] = DIRTY_UNSET\n dirtyBounds[base + 1] = 0\n }\n}\n\nfunction recordDirty(slot: number, start: number, end: number): void {\n const base = slot * 2\n if (start < dirtyBounds[base]!) dirtyBounds[base] = start\n if (end > dirtyBounds[base + 1]!) dirtyBounds[base + 1] = end\n}\n\nfunction flushAttributeUpdate(\n attribute: InstancedBufferAttribute,\n dirtyStart: number,\n dirtyEnd: number,\n): void {\n if (attribute.version === 0) {\n attribute.needsUpdate = true\n return\n }\n if (dirtyEnd <= dirtyStart) return\n let start = dirtyStart\n let end = dirtyEnd\n for (const range of attribute.updateRanges) {\n if (range.count < 0) {\n start = 0\n end = attribute.array.length\n break\n }\n if (range.start < start) start = range.start\n const rangeEnd = range.start + range.count\n if (rangeEnd > end) end = rangeEnd\n }\n attribute.clearUpdateRanges()\n attribute.addUpdateRange(start, end - start)\n attribute.needsUpdate = true\n}\n\nfunction writeFloat4(\n target: Float32Array,\n offset: number,\n a: number,\n b: number,\n c: number,\n d: number,\n trackDirty: boolean,\n slot: number,\n): void {\n if (trackDirty) {\n const fa = Math.fround(a)\n const fb = Math.fround(b)\n const fc = Math.fround(c)\n const fd = Math.fround(d)\n if (\n target[offset] === fa &&\n target[offset + 1] === fb &&\n target[offset + 2] === fc &&\n target[offset + 3] === fd\n ) {\n return\n }\n target[offset] = fa\n target[offset + 1] = fb\n target[offset + 2] = fc\n target[offset + 3] = fd\n recordDirty(slot, offset, offset + 4)\n return\n }\n target[offset] = a\n target[offset + 1] = b\n target[offset + 2] = c\n target[offset + 3] = d\n}\n\nexport interface MutableWindfoilAttributes {\n readonly rects: Float32Array\n readonly clips: Float32Array\n readonly colors: Uint8Array\n readonly metadata: Float32Array\n /** Components per `sdfMeta` entry; `3` carries the size-switch em. Defaults to `2`. */\n readonly metaSize?: number\n readonly bounds: Float32Array\n readonly bands: Float32Array\n readonly layers?: Float32Array\n readonly glyphRects?: Float32Array\n}\n\nconst scratchRect: [number, number, number, number] = [0, 0, 0, 0]\n\nexport function fillWindfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n out: [number, number, number, number] = scratchRect,\n): [number, number, number, number] {\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n out[0] = glyph.originX + bbox[0] * scale\n out[1] = baseline + bbox[1] * scale\n out[2] = glyph.originX + bbox[2] * scale\n out[3] = baseline + bbox[3] * scale\n return out\n}\n\nexport function windfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n): readonly [number, number, number, number] {\n return fillWindfoilGlyphRect(glyph, header, bbox, [0, 0, 0, 0])\n}\n\nfunction writeInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n c0: number,\n c1: number,\n c2: number,\n c3: number,\n glyphRect?: readonly [number, number, number, number],\n trackDirty = false,\n): void {\n const offset = index * 4\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n const ox = glyph.originX\n const lBox = layer.bbox\n const b0 = lBox[0],\n b1 = lBox[1],\n b2 = lBox[2],\n b3 = lBox[3]\n writeFloat4(\n attributes.rects,\n offset,\n ox + b0 * scale,\n baseline + b1 * scale,\n ox + b2 * scale,\n baseline + b3 * scale,\n trackDirty,\n SLOT_RECT,\n )\n const clip = glyph.clip\n writeFloat4(attributes.clips, offset, clip[0], clip[1], clip[2], clip[3], trackDirty, SLOT_CLIP)\n const colors = attributes.colors\n if (trackDirty) {\n if (\n colors[offset] !== c0 ||\n colors[offset + 1] !== c1 ||\n colors[offset + 2] !== c2 ||\n colors[offset + 3] !== c3\n ) {\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n recordDirty(SLOT_COLOR, offset, offset + 4)\n }\n } else {\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n }\n const metaSizeValue = attributes.metaSize ?? 2\n const metadata = attributes.metadata\n if (trackDirty) {\n const mOffset = index * metaSizeValue\n const seq = Math.fround(glyph.sequence)\n const gz = Math.fround(glyph.z)\n const sw = metaSizeValue === 3 ? Math.fround(glyph.switchEm ?? 0) : 0\n if (\n metadata[mOffset] !== seq ||\n metadata[mOffset + 1] !== gz ||\n (metaSizeValue === 3 && metadata[mOffset + 2] !== sw)\n ) {\n writeMeta(metadata, index, metaSizeValue, glyph)\n recordDirty(SLOT_META, mOffset, mOffset + metaSizeValue)\n }\n } else {\n writeMeta(metadata, index, metaSizeValue, glyph)\n }\n writeFloat4(attributes.bounds, offset, b0, b1, b2, b3, trackDirty, SLOT_BOUNDS)\n writeFloat4(\n attributes.bands,\n offset,\n layer.rowBase,\n layer.bandCount,\n layer.bandH,\n layer.invH,\n trackDirty,\n SLOT_BAND,\n )\n const layers = attributes.layers\n if (layers) {\n const paint = 'paintKind' in layer ? layer : null\n const rect = glyphRect ?? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n const mo = glyph.motionOrigin\n writeFloat4(\n layers,\n offset,\n mo ? mo[0] : (rect[0] + rect[2]) / 2,\n mo ? mo[1] : (rect[1] + rect[3]) / 2,\n ordinal,\n paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : (paint?.paintKind ?? 0),\n trackDirty,\n SLOT_LAYER,\n )\n }\n}\n\n/** Shared by text and shape geometry; one layer adds only one vertex attribute. */\nexport function writeLayerInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n glyphRect?: readonly [number, number, number, number],\n trackDirty = false,\n): void {\n const paint = 'paintKind' in layer ? layer : null\n const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color\n writeInstance(\n glyph,\n header,\n layer,\n index,\n ordinal,\n attributes,\n byte(rgb[0]),\n byte(rgb[1]),\n byte(rgb[2]),\n byte(glyph.color[3] * (paint ? paint.rgba[3] : 1)),\n glyphRect,\n trackDirty,\n )\n}\n\nfunction countLayout(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n layered: boolean,\n): { instances: number; drawable: number } {\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? (header.layers?.length ?? 1) : 1\n }\n }\n return { instances, drawable }\n}\n\nfunction writeGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n attributes: MutableWindfoilAttributes,\n ordinals?: Float32Array,\n trackDirty = false,\n): { instances: number; maxSequence: number; minZ: number; maxZ: number } {\n let instance = 0,\n drawable = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0\n let prevKey: string | undefined\n let prevHeader: WindfoilGlyphHeader | undefined\n let prevColor: GlyphLayout['color'] | undefined\n let pc0 = 0\n let pc1 = 0\n let pc2 = 0\n let pc3 = 0\n const glyphList = snapshot.glyphs\n for (let i = 0; i < glyphList.length; i++) {\n const glyph = glyphList[i]!\n const key = glyph.glyphKey\n const header = key === prevKey ? prevHeader : ((prevKey = key), (prevHeader = glyphs.get(key)))\n if (!header?.monotonePieceCount) continue\n const ordinal = ordinals?.[i] ?? glyph.motionOrigin?.[2] ?? drawable\n const rect =\n attributes.layers || attributes.glyphRects\n ? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n : undefined\n if (attributes.glyphRects && rect) {\n const rectOffset = drawable * 4\n attributes.glyphRects[rectOffset] = rect[0]\n attributes.glyphRects[rectOffset + 1] = rect[1]\n attributes.glyphRects[rectOffset + 2] = rect[2]\n attributes.glyphRects[rectOffset + 3] = rect[3]\n }\n if (attributes.layers && header.layers) {\n for (const layer of header.layers) {\n writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect, trackDirty)\n }\n } else {\n const layer = header.layers?.[0] ?? header\n const paint = 'paintKind' in layer ? layer : null\n if (paint) {\n const rgb = paint.paintKind === 1 ? paint.rgba : glyph.color\n writeInstance(\n glyph,\n header,\n layer,\n instance++,\n ordinal,\n attributes,\n byte(rgb[0]),\n byte(rgb[1]),\n byte(rgb[2]),\n byte(glyph.color[3] * paint.rgba[3]),\n rect,\n trackDirty,\n )\n } else {\n const color = glyph.color\n if (color !== prevColor) {\n prevColor = color\n pc0 = byte(color[0])\n pc1 = byte(color[1])\n pc2 = byte(color[2])\n pc3 = byte(color[3])\n }\n writeInstance(\n glyph,\n header,\n layer,\n instance++,\n ordinal,\n attributes,\n pc0,\n pc1,\n pc2,\n pc3,\n rect,\n trackDirty,\n )\n }\n }\n drawable++\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n }\n return { instances: instance, maxSequence, minZ, maxZ }\n}\n\n/** Ordinary outlines retain the original six instance attributes. */\nexport function createWindfoilGlyphGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n layered = false,\n ordinals?: Float32Array,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n layered ||= !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin)\n const meta = metaSize(snapshot)\n let count: number\n let rects: Float32Array\n let clips: Float32Array\n let colors: Uint8Array\n let metadata: Float32Array\n let bounds: Float32Array\n let bands: Float32Array\n let layers: Float32Array | undefined\n let glyphRects: Float32Array | undefined\n if (layered) {\n const counted = countLayout(snapshot, glyphs, true)\n count = counted.instances\n rects = new Float32Array(count * 4)\n clips = new Float32Array(count * 4)\n colors = new Uint8Array(count * 4)\n metadata = new Float32Array(count * meta)\n bounds = new Float32Array(count * 4)\n bands = new Float32Array(count * 4)\n layers = new Float32Array(count * 4)\n glyphRects = new Float32Array(counted.drawable * 4)\n } else {\n const total = snapshot.glyphs.length\n count = total\n rects = new Float32Array(total * 4)\n clips = new Float32Array(total * 4)\n colors = new Uint8Array(total * 4)\n metadata = new Float32Array(total * meta)\n bounds = new Float32Array(total * 4)\n bands = new Float32Array(total * 4)\n }\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\n rects,\n clips,\n colors,\n metadata,\n metaSize: meta,\n bounds,\n bands,\n ...(layers && glyphRects ? { layers, glyphRects } : {}),\n },\n ordinals,\n )\n if (!layered && result.instances < count) {\n count = result.instances\n rects = rects.subarray(0, count * 4)\n clips = clips.subarray(0, count * 4)\n colors = colors.subarray(0, count * 4)\n metadata = metadata.subarray(0, count * meta)\n bounds = bounds.subarray(0, count * 4)\n bands = bands.subarray(0, count * 4)\n }\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced Windfoil glyph quads'\n setUnitQuad(geometry)\n for (const [name, data, size, normalized] of [\n ['sdfRect', rects, 4, false],\n ['sdfClip', clips, 4, false],\n ['sdfColor', colors, 4, true],\n ['sdfMeta', metadata, meta, false],\n ['windfoilBounds', bounds, 4, false],\n ['windfoilBand', bands, 4, false],\n ] as const)\n geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized))\n if (layers) {\n geometry.setAttribute('windfoilLayer', new InstancedBufferAttribute(layers, 4))\n geometry.userData[GLYPH_RECTS_KEY] = glyphRects\n geometry.userData['ultraOwnGlyphRects'] = glyphRects\n }\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n return { geometry, maxSequence: result.maxSequence }\n}\n\nexport function windfoilContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n): boolean {\n const layered =\n (geometry.getAttribute('windfoilLayer') as InstancedBufferAttribute | undefined) !== undefined\n const names = layered ? LAYERED_ATTRIBUTES : ATTRIBUTES\n for (const name of names) {\n if (\n (geometry.getAttribute(name) as InstancedBufferAttribute | undefined)?.count !==\n geometry.instanceCount\n )\n return false\n }\n if (\n (geometry.getAttribute('sdfMeta') as InstancedBufferAttribute).itemSize !== metaSize(snapshot)\n )\n return false\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n const layers = header?.layers?.length ?? 1\n if (!layered && (glyph.motionOrigin || layers > 1)) return false\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? layers : 1\n }\n }\n return (\n instances === geometry.instanceCount &&\n (!layered ||\n (geometry.userData['ultraOwnGlyphRects'] as Float32Array | undefined)?.length ===\n drawable * 4)\n )\n}\n\nexport function updateWindfoilGlyphGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n ordinals?: Float32Array,\n checked = false,\n): number | null {\n if (!checked && !windfoilContentFits(geometry, snapshot, glyphs)) return null\n const array = (name: string): Float32Array => geometry.getAttribute(name).array as Float32Array\n const layer = geometry.getAttribute('windfoilLayer') as InstancedBufferAttribute | undefined\n const trackDirty =\n (geometry.getAttribute('sdfRect') as InstancedBufferAttribute).version > 0 ||\n (geometry.getAttribute('sdfClip') as InstancedBufferAttribute).version > 0 ||\n (geometry.getAttribute('sdfColor') as InstancedBufferAttribute).version > 0 ||\n (geometry.getAttribute('sdfMeta') as InstancedBufferAttribute).version > 0 ||\n (geometry.getAttribute('windfoilBounds') as InstancedBufferAttribute).version > 0 ||\n (geometry.getAttribute('windfoilBand') as InstancedBufferAttribute).version > 0 ||\n (layer?.version ?? 0) > 0\n if (trackDirty) resetDirtyBounds()\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\n rects: array('sdfRect'),\n clips: array('sdfClip'),\n colors: geometry.getAttribute('sdfColor').array as Uint8Array,\n metadata: array('sdfMeta'),\n metaSize: geometry.getAttribute('sdfMeta').itemSize,\n bounds: array('windfoilBounds'),\n bands: array('windfoilBand'),\n ...(layer\n ? {\n layers: layer.array as Float32Array,\n glyphRects: geometry.userData['ultraOwnGlyphRects'] as Float32Array,\n }\n : {}),\n },\n ordinals,\n trackDirty,\n )\n const list = layer ? LAYERED_ATTRIBUTES : ATTRIBUTES\n if (trackDirty) {\n for (let i = 0; i < list.length; i++) {\n const attribute = geometry.getAttribute(list[i]!) as InstancedBufferAttribute\n const base = i * 2\n flushAttributeUpdate(attribute, dirtyBounds[base]!, dirtyBounds[base + 1]!)\n }\n } else {\n for (const name of list)\n (geometry.getAttribute(name) as InstancedBufferAttribute).needsUpdate = true\n }\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n return result.maxSequence\n}\n"],"mappings":";;;;AAMA,IAAM,aAAa;CACjB;CACA;CACA;CACA;CACA;CACA;AACF;AACA,IAAM,qBAAqB,CAAC,GAAG,YAAY,eAAe;AAE1D,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,aAAa;AACnB,IAAM,YAAY;AAClB,IAAM,cAAc;AACpB,IAAM,YAAY;AAClB,IAAM,aAAa;AACnB,IAAM,cAAc;AACpB,IAAM,8BAAc,IAAI,WAAW,EAAE;AAErC,SAAS,mBAAyB;CAChC,KAAK,IAAI,OAAO,GAAG,OAAO,GAAG,QAAQ;EACnC,MAAM,OAAO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AEA,KAAK,MAAM,QAAQ,MACjB,SAAU,aAAa,IAAI,CAAC,CAA8B,cAAc;CAE5E,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,eAAe,OAAO,MAAM,OAAO,IAAI;CAC5F,OAAO,OAAO;AAChB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { throwIfAborted } from "./
|
|
1
|
+
import { throwIfAborted } from "./abortable.js";
|
|
2
2
|
import { windfoilCompositeBox } from "./compositeGeometry.js";
|
|
3
3
|
import { floatBits } from "./paint.js";
|
|
4
4
|
/** List-entry flag: the layer covers the whole cell, so its coverage is exactly 1. */
|
|
@@ -89,6 +89,7 @@ var gridBandGen = 0;
|
|
|
89
89
|
var scratchBandLow = /* @__PURE__ */ new Float64Array(64);
|
|
90
90
|
var scratchBandHeight = /* @__PURE__ */ new Float64Array(64);
|
|
91
91
|
var poolPieceC = /* @__PURE__ */ new Int32Array(0);
|
|
92
|
+
var poolPieceMid = /* @__PURE__ */ new Int32Array(0);
|
|
92
93
|
var poolPieceBounds = /* @__PURE__ */ new Float64Array(0);
|
|
93
94
|
var poolPieceLow = /* @__PURE__ */ new Float64Array(0);
|
|
94
95
|
var poolBandPrepared = /* @__PURE__ */ new Int32Array(0);
|
|
@@ -225,10 +226,10 @@ function prepareBand(bandRecord, start, pieceCount, curves) {
|
|
|
225
226
|
scratchBandLow = new Float64Array(capLen);
|
|
226
227
|
scratchBandHeight = new Float64Array(capLen);
|
|
227
228
|
}
|
|
228
|
-
const lowScratch = scratchBandLow, heightScratch = scratchBandHeight, cArr = poolPieceC, boundsArr = poolPieceBounds, shortLow = poolPieceLow;
|
|
229
|
+
const lowScratch = scratchBandLow, heightScratch = scratchBandHeight, cArr = poolPieceC, midArr = poolPieceMid, boundsArr = poolPieceBounds, shortLow = poolPieceLow, bandFloatBase = start * 6, q2FloatBase = bandFloatBase + pieceCount * 4;
|
|
229
230
|
let bottom = Infinity, top = -Infinity, activeCount = 0;
|
|
230
231
|
for (let k = 0; k < pieceCount; k++) {
|
|
231
|
-
const
|
|
232
|
+
const pair = bandFloatBase + k * 4, y0 = curves[pair + 1], y1 = curves[pair + 3], lo = y0 < y1 ? y0 : y1, hi = y0 < y1 ? y1 : y0, h = hi - lo;
|
|
232
233
|
lowScratch[k] = lo;
|
|
233
234
|
heightScratch[k] = h;
|
|
234
235
|
if (h !== 0) activeCount++;
|
|
@@ -268,8 +269,9 @@ function prepareBand(bandRecord, start, pieceCount, curves) {
|
|
|
268
269
|
sortByLow(cArr, shortBase, activeEnd, lowScratch);
|
|
269
270
|
}
|
|
270
271
|
for (let i = start; i < activeEnd; i++) {
|
|
271
|
-
const
|
|
272
|
-
cArr[i] = up ?
|
|
272
|
+
const k = cArr[i], pair = bandFloatBase + k * 4, mid = q2FloatBase + k * 2, px0 = curves[pair], py0 = curves[pair + 1], px1 = curves[mid], px2 = curves[pair + 2], py2 = curves[pair + 3], up = py2 > py0, lo = up ? py0 : py2, i4 = i * 4;
|
|
273
|
+
cArr[i] = up ? pair : ~pair;
|
|
274
|
+
midArr[i] = mid;
|
|
273
275
|
shortLow[i] = lo;
|
|
274
276
|
boundsArr[i4] = lo;
|
|
275
277
|
boundsArr[i4 + 1] = up ? py2 : py0;
|
|
@@ -289,7 +291,7 @@ function classifyLayer(layer, ey0, ex1, ey1, ex0Tol, ex1Tol, ey0Tol, ey1Tol) {
|
|
|
289
291
|
const bx0 = poolLayerBx0[layer], by0 = poolLayerBy0[layer], bx1 = poolLayerBx1[layer], by1Cap = poolLayerBy1Cap[layer];
|
|
290
292
|
if (ey1Tol < by0 || ey0Tol > by1Cap || ex1Tol < bx0 || ex0Tol > bx1) return 0;
|
|
291
293
|
const bands = poolLayerBands[layer], bandH = poolLayerBandH[layer], rowBase = poolLayerRowBase[layer], tol = gridTol, bandGen = gridBandGen, low = bands > 1 ? ey0Tol <= by0 ? 0 : Math.min(bands, Math.floor((ey0Tol - by0) / bandH)) : 0, high = bands > 1 ? ey1Tol >= by1Cap ? bands - 1 : Math.min(bands - 1, Math.floor((ey1Tol - by0) / bandH)) : 0, insideBox = bx0 < ex0Tol && bx1 > ex1Tol && by0 < ey0Tol && by1Cap > ey1Tol;
|
|
292
|
-
const cArr = poolPieceC, boundsArr = poolPieceBounds, shortLow = poolPieceLow, bandPrepared = poolBandPrepared, bandTallEnd = poolBandTallEnd, bandActiveEnd = poolBandActiveEnd, bandTallest = poolBandTallest, curves = gridCurves, rows = gridRows, rowFloats = gridRowFloats;
|
|
294
|
+
const cArr = poolPieceC, midArr = poolPieceMid, boundsArr = poolPieceBounds, shortLow = poolPieceLow, bandPrepared = poolBandPrepared, bandTallEnd = poolBandTallEnd, bandActiveEnd = poolBandActiveEnd, bandTallest = poolBandTallest, curves = gridCurves, rows = gridRows, rowFloats = gridRowFloats;
|
|
293
295
|
let winding = UNSET;
|
|
294
296
|
for (let band = low; band <= high; band++) {
|
|
295
297
|
const s0 = bands > 1 ? Math.max(ey0, by0 + band * bandH - tol) : ey0, s1 = bands > 1 ? Math.min(ey1, by0 + (band + 1) * bandH + tol) : ey1;
|
|
@@ -321,24 +323,24 @@ function classifyLayer(layer, ey0, ex1, ey1, ex0Tol, ex1Tol, ey0Tol, ey1Tol) {
|
|
|
321
323
|
let xh = boundsArr[k4 + 3];
|
|
322
324
|
if (xh >= ex0Tol) {
|
|
323
325
|
if (yl >= s0 && yh <= s1) return 1;
|
|
324
|
-
const
|
|
326
|
+
const pair = cs < 0 ? ~cs : cs, mid = midArr[k], px0 = curves[pair], px2 = curves[pair + 2];
|
|
325
327
|
let a;
|
|
326
328
|
if (yl >= s0) {
|
|
327
329
|
a = sign > 0 ? px0 : px2;
|
|
328
330
|
if (a >= ex0Tol && a <= ex1Tol) return 1;
|
|
329
|
-
const b = at(px0, curves[
|
|
331
|
+
const b = at(px0, curves[mid], px2, solve(curves[pair + 1], curves[mid + 1], curves[pair + 3], s1));
|
|
330
332
|
xl = a < b ? a : b;
|
|
331
333
|
xh = a < b ? b : a;
|
|
332
334
|
if (xh >= ex0Tol && xl <= ex1Tol) return 1;
|
|
333
335
|
} else if (yh <= s1) {
|
|
334
336
|
const b = sign > 0 ? px2 : px0;
|
|
335
337
|
if (b >= ex0Tol && b <= ex1Tol) return 1;
|
|
336
|
-
a = at(px0, curves[
|
|
338
|
+
a = at(px0, curves[mid], px2, solve(curves[pair + 1], curves[mid + 1], curves[pair + 3], s0));
|
|
337
339
|
xl = a < b ? a : b;
|
|
338
340
|
xh = a < b ? b : a;
|
|
339
341
|
if (xh >= ex0Tol && xl <= ex1Tol) return 1;
|
|
340
342
|
} else {
|
|
341
|
-
const px1 = curves[
|
|
343
|
+
const px1 = curves[mid], py0 = curves[pair + 1], py1 = curves[mid + 1], py2 = curves[pair + 3];
|
|
342
344
|
a = at(px0, px1, px2, solve(py0, py1, py2, s0));
|
|
343
345
|
if (a >= ex0Tol && a <= ex1Tol) return 1;
|
|
344
346
|
const b = at(px0, px1, px2, solve(py0, py1, py2, s1));
|
|
@@ -491,6 +493,7 @@ function appendWindfoilLayerGrids(table, glyphs, coverage, opaque, signal, tunin
|
|
|
491
493
|
if (poolPieceC.length < totalPieces) {
|
|
492
494
|
const cap = Math.max(poolPieceC.length * 2, totalPieces);
|
|
493
495
|
poolPieceC = new Int32Array(cap);
|
|
496
|
+
poolPieceMid = new Int32Array(cap);
|
|
494
497
|
poolPieceBounds = new Float64Array(cap * 4);
|
|
495
498
|
poolPieceLow = new Float64Array(cap);
|
|
496
499
|
}
|
|
@@ -658,6 +661,7 @@ function appendWindfoilLayerGrids(table, glyphs, coverage, opaque, signal, tunin
|
|
|
658
661
|
result.set(poolOut.subarray(0, used), table.length);
|
|
659
662
|
if (poolPieceC.length > 262144) {
|
|
660
663
|
poolPieceC = /* @__PURE__ */ new Int32Array(0);
|
|
664
|
+
poolPieceMid = /* @__PURE__ */ new Int32Array(0);
|
|
661
665
|
poolPieceBounds = /* @__PURE__ */ new Float64Array(0);
|
|
662
666
|
poolPieceLow = /* @__PURE__ */ new Float64Array(0);
|
|
663
667
|
}
|