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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createCanvas, isColorCandidate, setFontContext, waitForFonts } from "../
|
|
1
|
+
import { allFontsLoaded, createCanvas, isColorCandidate, setFontContext, waitForFonts } from "../dom/fontCanvas.js";
|
|
2
2
|
import { createTraceScratch, traceCoverage } from "./trace/outline.js";
|
|
3
3
|
// src/windfoil/tracedOutlines.ts
|
|
4
4
|
/** A batch yields to the page once it has traced for this long. */
|
|
@@ -40,13 +40,18 @@ function boxOf(reach, margin) {
|
|
|
40
40
|
];
|
|
41
41
|
}
|
|
42
42
|
/** Whether any texel on the edge of a `width` x `height` RGBA read holds ink. */
|
|
43
|
-
function touchesEdge(rgba, width, height) {
|
|
44
|
-
for (let x = 0; x < width; x++) if (rgba[x * 4 + 3] > 0 || rgba[(
|
|
45
|
-
for (let y = 0; y < height; y++)
|
|
43
|
+
function touchesEdge(rgba, width, height, rowStride = width * 4, baseOffset = 0) {
|
|
44
|
+
for (let x = 0; x < width; x++) if (rgba[baseOffset + x * 4 + 3] > 0 || rgba[baseOffset + (height - 1) * rowStride + x * 4 + 3] > 0) return true;
|
|
45
|
+
for (let y = 0; y < height; y++) {
|
|
46
|
+
const row = baseOffset + y * rowStride;
|
|
47
|
+
if (rgba[row + 3] > 0 || rgba[row + (width - 1) * 4 + 3] > 0) return true;
|
|
48
|
+
}
|
|
46
49
|
return false;
|
|
47
50
|
}
|
|
51
|
+
var MAX_SHEET = 2048;
|
|
52
|
+
var SHEET_GAP = 1;
|
|
48
53
|
/**
|
|
49
|
-
*
|
|
54
|
+
* The outline provider `DomSdf` and `DomSlug` use for Windfoil and Slug text when the caller gives
|
|
50
55
|
* none. Each glyph is drawn as the SDF rasterizer draws it (the captured canvas font with its
|
|
51
56
|
* stretch and kerning, an in-document canvas without font smoothing, exact geometry, a neutral
|
|
52
57
|
* grey), at `size` pixels per em, then traced at half coverage and fitted with quadratics. The
|
|
@@ -69,46 +74,72 @@ function createTracedOutlineProvider(document, options = {}) {
|
|
|
69
74
|
const colorGlyphs = options.colorGlyphs ?? "emoji";
|
|
70
75
|
const cache = /* @__PURE__ */ new Map();
|
|
71
76
|
let epoch = 0;
|
|
77
|
+
let cachedCanvas = null;
|
|
78
|
+
let cachedContext = null;
|
|
72
79
|
/** The batches still open to requests of this task, by signal. */
|
|
73
80
|
const open = /* @__PURE__ */ new Map();
|
|
74
81
|
const run = async (signal, requests, started) => {
|
|
75
82
|
const results = /* @__PURE__ */ new Map();
|
|
76
83
|
const groups = /* @__PURE__ */ new Map();
|
|
84
|
+
const waitList = [];
|
|
77
85
|
for (const request of requests.values()) {
|
|
78
86
|
if (request.shape || request.shaping) {
|
|
79
87
|
results.set(request.key, null);
|
|
80
88
|
continue;
|
|
81
89
|
}
|
|
82
|
-
|
|
83
|
-
if (group)
|
|
84
|
-
else {
|
|
90
|
+
let group = groups.get(request.font.key);
|
|
91
|
+
if (!group) {
|
|
85
92
|
const font = request.font;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
group = [
|
|
94
|
+
[],
|
|
95
|
+
[],
|
|
96
|
+
{
|
|
97
|
+
...font,
|
|
98
|
+
canvasFont: font.canvasFont.replace(SIZE_TOKEN, `${size}px`)
|
|
99
|
+
}
|
|
100
|
+
];
|
|
101
|
+
groups.set(font.key, group);
|
|
90
102
|
}
|
|
103
|
+
const tracedReq = {
|
|
104
|
+
key: request.key,
|
|
105
|
+
character: request.character,
|
|
106
|
+
font: group[2]
|
|
107
|
+
};
|
|
108
|
+
group[0].push(request);
|
|
109
|
+
group[1].push(tracedReq);
|
|
110
|
+
waitList.push(tracedReq);
|
|
91
111
|
}
|
|
92
|
-
|
|
93
|
-
...request,
|
|
94
|
-
font: groups.get(request.font.key)[1]
|
|
95
|
-
});
|
|
96
|
-
await waitForFonts(document, [...groups.values()].flatMap(([list]) => list.map(traced)), signal);
|
|
112
|
+
await waitForFonts(document, waitList, signal);
|
|
97
113
|
throwIfAborted(signal);
|
|
114
|
+
const preloaded = allFontsLoaded(document);
|
|
98
115
|
const fonts = document.fonts;
|
|
99
116
|
const keep = (request, outline) => {
|
|
100
117
|
results.set(request.key, outline);
|
|
101
118
|
let ready = epoch === started;
|
|
102
|
-
try {
|
|
103
|
-
ready
|
|
119
|
+
if (ready && !preloaded) try {
|
|
120
|
+
ready = fonts?.check(groups.get(request.font.key)[2].canvasFont, request.character) ?? true;
|
|
104
121
|
} catch {
|
|
105
122
|
ready = false;
|
|
106
123
|
}
|
|
107
124
|
if (ready) cache.set(request.key, outline);
|
|
108
125
|
};
|
|
109
|
-
|
|
126
|
+
let canvas;
|
|
127
|
+
let context;
|
|
128
|
+
if (cachedCanvas?.ownerDocument === document && cachedContext) {
|
|
129
|
+
canvas = cachedCanvas;
|
|
130
|
+
canvas.width = 1;
|
|
131
|
+
canvas.height = 1;
|
|
132
|
+
document.documentElement.append(canvas);
|
|
133
|
+
context = cachedContext;
|
|
134
|
+
} else {
|
|
135
|
+
canvas = createCanvas(document);
|
|
136
|
+
context = canvas.getContext("2d", { willReadFrequently: true });
|
|
137
|
+
if (context) {
|
|
138
|
+
cachedCanvas = canvas;
|
|
139
|
+
cachedContext = context;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
110
142
|
try {
|
|
111
|
-
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
112
143
|
if (!context) {
|
|
113
144
|
for (const [list] of groups.values()) for (const request of list) results.set(request.key, null);
|
|
114
145
|
return results;
|
|
@@ -128,9 +159,7 @@ function createTracedOutlineProvider(document, options = {}) {
|
|
|
128
159
|
};
|
|
129
160
|
const margin = Math.max(4, Math.ceil(size / 32));
|
|
130
161
|
const measured = [];
|
|
131
|
-
|
|
132
|
-
let canvasHeight = 1;
|
|
133
|
-
for (const [list] of groups.values()) {
|
|
162
|
+
for (const [list, tracedList] of groups.values()) {
|
|
134
163
|
throwIfAborted(signal);
|
|
135
164
|
const bake = Number.parseFloat(SIZE_TOKEN.exec(list[0].font.canvasFont)?.[0] ?? "");
|
|
136
165
|
if (!(bake > 0) || !use(list[0])) {
|
|
@@ -142,48 +171,50 @@ function createTracedOutlineProvider(document, options = {}) {
|
|
|
142
171
|
const slot = context.measureText(request.character);
|
|
143
172
|
return [Math.max(1, slot.fontBoundingBoxAscent || slot.actualBoundingBoxAscent) * scale, Math.max(1, slot.fontBoundingBoxDescent || slot.actualBoundingBoxDescent) * scale];
|
|
144
173
|
});
|
|
145
|
-
if (!use(
|
|
174
|
+
if (!use(tracedList[0])) {
|
|
146
175
|
for (const request of list) keep(request, null);
|
|
147
176
|
continue;
|
|
148
177
|
}
|
|
149
|
-
list.
|
|
178
|
+
for (let index = 0; index < list.length; index++) {
|
|
179
|
+
const request = list[index];
|
|
180
|
+
const tracedReq = tracedList[index];
|
|
150
181
|
const [ascent, descent] = slots[index];
|
|
151
182
|
const metrics = context.measureText(request.character);
|
|
183
|
+
const hasHBox = metrics.actualBoundingBoxLeft > 0 || metrics.actualBoundingBoxRight > 0;
|
|
184
|
+
const hasVBox = metrics.actualBoundingBoxAscent > 0 || metrics.actualBoundingBoxDescent > 0;
|
|
152
185
|
const reach = [
|
|
153
186
|
Math.max(0, metrics.actualBoundingBoxLeft || 0),
|
|
154
|
-
Math.max(metrics.width || 0, metrics.actualBoundingBoxRight || 0),
|
|
155
|
-
Math.max(ascent, metrics.actualBoundingBoxAscent || 0),
|
|
156
|
-
Math.max(descent, metrics.actualBoundingBoxDescent || 0)
|
|
187
|
+
Math.max(hasHBox ? 0 : metrics.width || 0, metrics.actualBoundingBoxRight || 0),
|
|
188
|
+
Math.max(hasVBox ? 0 : ascent, metrics.actualBoundingBoxAscent || 0),
|
|
189
|
+
Math.max(hasVBox ? 0 : descent, metrics.actualBoundingBoxDescent || 0)
|
|
157
190
|
];
|
|
158
191
|
const [, , width, height] = boxOf(reach, margin);
|
|
159
192
|
if (!(width <= 8 * size && height <= 8 * size)) {
|
|
160
193
|
keep(request, null);
|
|
161
|
-
|
|
194
|
+
continue;
|
|
162
195
|
}
|
|
163
|
-
canvasWidth = Math.max(canvasWidth, width);
|
|
164
|
-
canvasHeight = Math.max(canvasHeight, height);
|
|
165
196
|
measured.push({
|
|
166
|
-
request:
|
|
197
|
+
request: tracedReq,
|
|
167
198
|
ascent,
|
|
168
199
|
descent,
|
|
169
200
|
reach
|
|
170
201
|
});
|
|
171
|
-
}
|
|
202
|
+
}
|
|
172
203
|
}
|
|
173
204
|
const resize = (width, height) => {
|
|
174
|
-
if (width <= canvas.width && height <= canvas.height) return;
|
|
205
|
+
if (width <= canvas.width && height <= canvas.height) return false;
|
|
175
206
|
canvas.width = Math.max(width, canvas.width);
|
|
176
207
|
canvas.height = Math.max(height, canvas.height);
|
|
177
208
|
current = null;
|
|
209
|
+
return true;
|
|
178
210
|
};
|
|
179
|
-
resize(canvasWidth, canvasHeight);
|
|
180
211
|
const exact = "textRendering" in context;
|
|
181
212
|
const draw = (glyph, [originX, baselineY, width, height], fill, rendering) => {
|
|
182
|
-
resize(width, height);
|
|
213
|
+
const resized = resize(width, height);
|
|
183
214
|
use(glyph.request);
|
|
184
215
|
context.fillStyle = fill;
|
|
185
216
|
if (exact) context.textRendering = rendering;
|
|
186
|
-
context.clearRect(0, 0, width, height);
|
|
217
|
+
if (!resized) context.clearRect(0, 0, width, height);
|
|
187
218
|
context.fillText(glyph.request.character, originX, baselineY);
|
|
188
219
|
return context.getImageData(0, 0, width, height).data;
|
|
189
220
|
};
|
|
@@ -191,49 +222,182 @@ function createTracedOutlineProvider(document, options = {}) {
|
|
|
191
222
|
throwIfAborted(signal);
|
|
192
223
|
const scratch = createTraceScratch();
|
|
193
224
|
let sliceStart = performance.now();
|
|
194
|
-
|
|
225
|
+
const view = document.defaultView;
|
|
226
|
+
const getContextFn = view ? Object.getOwnPropertyDescriptor(view.HTMLCanvasElement.prototype, "getContext")?.value : void 0;
|
|
227
|
+
const mockedCanvas = !getContextFn || "mock" in getContextFn;
|
|
228
|
+
const finishGlyph = async (glyph, box, retried) => {
|
|
229
|
+
let currentBox = box;
|
|
230
|
+
let rgba = draw(glyph, currentBox, "#606060", "geometricPrecision");
|
|
231
|
+
let clipped = touchesEdge(rgba, currentBox[2], currentBox[3]);
|
|
232
|
+
if (clipped && !retried) {
|
|
233
|
+
currentBox = boxOf(glyph.reach, margin + size / 2);
|
|
234
|
+
rgba = draw(glyph, currentBox, "#606060", "geometricPrecision");
|
|
235
|
+
clipped = touchesEdge(rgba, currentBox[2], currentBox[3]);
|
|
236
|
+
}
|
|
237
|
+
let outline = null;
|
|
238
|
+
if (!clipped) {
|
|
239
|
+
const { quadratics, bbox } = traceCoverage({
|
|
240
|
+
alpha: rgba,
|
|
241
|
+
width: currentBox[2],
|
|
242
|
+
height: currentBox[3],
|
|
243
|
+
stride: 4,
|
|
244
|
+
offset: 3,
|
|
245
|
+
originX: currentBox[0],
|
|
246
|
+
baselineY: currentBox[1]
|
|
247
|
+
}, tolerance, scratch);
|
|
248
|
+
outline = {
|
|
249
|
+
unitsPerEm: size,
|
|
250
|
+
ascent: glyph.ascent,
|
|
251
|
+
descent: -glyph.descent,
|
|
252
|
+
bbox,
|
|
253
|
+
quadratics
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
keep(requests.get(glyph.request.key), outline);
|
|
257
|
+
if (performance.now() - sliceStart > SLICE_MS) {
|
|
258
|
+
await nextTask();
|
|
259
|
+
throwIfAborted(signal);
|
|
260
|
+
sliceStart = performance.now();
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
if (mockedCanvas || measured.length < 2) for (const glyph of measured) {
|
|
195
264
|
throwIfAborted(signal);
|
|
196
|
-
|
|
265
|
+
const box = boxOf(glyph.reach, margin);
|
|
197
266
|
const [, , width, height] = box;
|
|
198
|
-
|
|
267
|
+
if (colorModule !== null && isColorCandidate(glyph.request, colorGlyphs) && colorModule.encodeColorBand(draw(glyph, box, "#fff", "auto"), draw(glyph, box, "#000", "auto"), width, height, 0, [{
|
|
199
268
|
x: 0,
|
|
200
269
|
y: 0,
|
|
201
270
|
width,
|
|
202
271
|
height
|
|
203
|
-
}]).colored[0] === true
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
box = boxOf(glyph.reach, margin + size / 2);
|
|
210
|
-
rgba = draw(glyph, box, "#606060", "geometricPrecision");
|
|
211
|
-
clipped = touchesEdge(rgba, box[2], box[3]);
|
|
272
|
+
}]).colored[0] === true) {
|
|
273
|
+
keep(requests.get(glyph.request.key), null);
|
|
274
|
+
if (performance.now() - sliceStart > SLICE_MS) {
|
|
275
|
+
await nextTask();
|
|
276
|
+
throwIfAborted(signal);
|
|
277
|
+
sliceStart = performance.now();
|
|
212
278
|
}
|
|
213
|
-
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
await finishGlyph(glyph, box, false);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const plain = [];
|
|
285
|
+
const oversized = [];
|
|
286
|
+
const retries = [];
|
|
287
|
+
for (const glyph of measured) {
|
|
288
|
+
throwIfAborted(signal);
|
|
289
|
+
const box = boxOf(glyph.reach, margin);
|
|
290
|
+
const [, , width, height] = box;
|
|
291
|
+
if (colorModule !== null && isColorCandidate(glyph.request, colorGlyphs) && colorModule.encodeColorBand(draw(glyph, box, "#fff", "auto"), draw(glyph, box, "#000", "auto"), width, height, 0, [{
|
|
292
|
+
x: 0,
|
|
293
|
+
y: 0,
|
|
294
|
+
width,
|
|
295
|
+
height
|
|
296
|
+
}]).colored[0] === true) {
|
|
297
|
+
keep(requests.get(glyph.request.key), null);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (width > MAX_SHEET || height > MAX_SHEET) oversized.push({
|
|
301
|
+
glyph,
|
|
302
|
+
box
|
|
303
|
+
});
|
|
304
|
+
else plain.push({
|
|
305
|
+
glyph,
|
|
306
|
+
box
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
const flushSheet = async (sheet, sheetW, sheetH) => {
|
|
310
|
+
if (!resize(sheetW, sheetH)) context.clearRect(0, 0, sheetW, sheetH);
|
|
311
|
+
context.fillStyle = "#606060";
|
|
312
|
+
if (exact) context.textRendering = "geometricPrecision";
|
|
313
|
+
for (const item of sheet) {
|
|
314
|
+
throwIfAborted(signal);
|
|
315
|
+
use(item.glyph.request);
|
|
316
|
+
context.fillText(item.glyph.request.character, item.x + item.box[0], item.y + item.box[1]);
|
|
317
|
+
}
|
|
318
|
+
const rgba = context.getImageData(0, 0, sheetW, sheetH).data;
|
|
319
|
+
const rowStride = sheetW * 4;
|
|
320
|
+
for (const item of sheet) {
|
|
321
|
+
throwIfAborted(signal);
|
|
322
|
+
const [originX, baselineY, width, height] = item.box;
|
|
323
|
+
const tileOffset = (item.y * sheetW + item.x) * 4;
|
|
324
|
+
if (touchesEdge(rgba, width, height, rowStride, tileOffset)) {
|
|
325
|
+
retries.push(item.glyph);
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
214
328
|
const { quadratics, bbox } = traceCoverage({
|
|
215
329
|
alpha: rgba,
|
|
216
|
-
width
|
|
217
|
-
height
|
|
330
|
+
width,
|
|
331
|
+
height,
|
|
218
332
|
stride: 4,
|
|
219
|
-
offset: 3,
|
|
220
|
-
|
|
221
|
-
|
|
333
|
+
offset: tileOffset + 3,
|
|
334
|
+
rowStride,
|
|
335
|
+
originX,
|
|
336
|
+
baselineY
|
|
222
337
|
}, tolerance, scratch);
|
|
223
|
-
|
|
338
|
+
keep(requests.get(item.glyph.request.key), {
|
|
224
339
|
unitsPerEm: size,
|
|
225
|
-
ascent: glyph.ascent,
|
|
226
|
-
descent: -glyph.descent,
|
|
340
|
+
ascent: item.glyph.ascent,
|
|
341
|
+
descent: -item.glyph.descent,
|
|
227
342
|
bbox,
|
|
228
343
|
quadratics
|
|
229
|
-
};
|
|
344
|
+
});
|
|
345
|
+
if (performance.now() - sliceStart > SLICE_MS) {
|
|
346
|
+
await nextTask();
|
|
347
|
+
throwIfAborted(signal);
|
|
348
|
+
sliceStart = performance.now();
|
|
349
|
+
}
|
|
230
350
|
}
|
|
351
|
+
};
|
|
352
|
+
if (plain.length < 2) for (const item of plain) {
|
|
353
|
+
throwIfAborted(signal);
|
|
354
|
+
await finishGlyph(item.glyph, item.box, false);
|
|
231
355
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
356
|
+
else {
|
|
357
|
+
plain.sort((a, b) => b.box[3] - a.box[3] || b.box[2] - a.box[2]);
|
|
358
|
+
let sheet = [];
|
|
359
|
+
let packX = 0;
|
|
360
|
+
let packY = 0;
|
|
361
|
+
let rowH = 0;
|
|
362
|
+
let sheetW = 0;
|
|
363
|
+
let sheetH = 0;
|
|
364
|
+
for (const { glyph, box } of plain) {
|
|
365
|
+
const width = box[2];
|
|
366
|
+
const height = box[3];
|
|
367
|
+
if (packX > 0 && packX + width > MAX_SHEET) {
|
|
368
|
+
packX = 0;
|
|
369
|
+
packY += rowH + SHEET_GAP;
|
|
370
|
+
rowH = 0;
|
|
371
|
+
}
|
|
372
|
+
if (packY + height > MAX_SHEET) {
|
|
373
|
+
await flushSheet(sheet, sheetW, sheetH);
|
|
374
|
+
sheet = [];
|
|
375
|
+
packX = 0;
|
|
376
|
+
packY = 0;
|
|
377
|
+
rowH = 0;
|
|
378
|
+
sheetW = 0;
|
|
379
|
+
sheetH = 0;
|
|
380
|
+
}
|
|
381
|
+
sheet.push({
|
|
382
|
+
glyph,
|
|
383
|
+
box,
|
|
384
|
+
x: packX,
|
|
385
|
+
y: packY
|
|
386
|
+
});
|
|
387
|
+
sheetW = Math.max(sheetW, packX + width);
|
|
388
|
+
sheetH = Math.max(sheetH, packY + height);
|
|
389
|
+
packX += width + SHEET_GAP;
|
|
390
|
+
rowH = Math.max(rowH, height);
|
|
391
|
+
}
|
|
392
|
+
if (sheet.length > 0) await flushSheet(sheet, sheetW, sheetH);
|
|
393
|
+
}
|
|
394
|
+
for (const item of oversized) {
|
|
235
395
|
throwIfAborted(signal);
|
|
236
|
-
|
|
396
|
+
await finishGlyph(item.glyph, item.box, false);
|
|
397
|
+
}
|
|
398
|
+
for (const glyph of retries) {
|
|
399
|
+
throwIfAborted(signal);
|
|
400
|
+
await finishGlyph(glyph, boxOf(glyph.reach, margin + size / 2), true);
|
|
237
401
|
}
|
|
238
402
|
}
|
|
239
403
|
return results;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracedOutlines.js","names":[],"sources":["../../src/windfoil/tracedOutlines.ts"],"sourcesContent":["import { createCanvas, isColorCandidate, setFontContext, waitForFonts } from '../atlas/rasterize.js'\nimport type {\n ColorGlyphMode,\n FontStyleSnapshot,\n GlyphRequest,\n WindfoilGlyphOutline,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport { createTraceScratch, traceCoverage } from './trace/outline.js'\n\n/** @internal Options of the built-in outline tracer. */\nexport interface TracedOutlineOptions {\n /** Trace resolution in pixels per em, also each outline's `unitsPerEm`. Defaults to `256`. */\n readonly size?: number\n /** Furthest, in trace pixels, a fitted curve may stray from its contour. Defaults to `0.25`. */\n readonly tolerance?: number\n /** Which glyphs to test for colour ink, as `DomSdfOptions.colorGlyphs`. Defaults to `'emoji'`. */\n readonly colorGlyphs?: ColorGlyphMode\n}\n\n/** @internal A `WindfoilOutlineProvider` that traces the browser's own glyphs, and its cache. */\nexport interface TracedOutlines {\n readonly provider: WindfoilOutlineProvider\n /** Forgets every traced outline, as after a webfont load; work in flight is not kept. */\n clear(): void\n /** Forgets the outlines of every glyph key not listed. */\n retain(keys: Iterable<string>): void\n}\n\n/** A batch yields to the page once it has traced for this long. */\nconst SLICE_MS = 8\n/** A font assignment the canvas rejects leaves this one in place. */\nconst SENTINEL_FONT = '1px serif'\nconst SIZE_TOKEN = /[\\d.]+px/\n\n/** The requests one task made with one signal, traced together. */\ninterface Batch {\n readonly signal: AbortSignal\n readonly requests: Map<string, GlyphRequest>\n readonly done: Promise<ReadonlyMap<string, WindfoilGlyphOutline | null>>\n}\n\n/** One glyph between measuring and tracing, in trace pixels; y grows downwards. */\ninterface Measured {\n readonly request: GlyphRequest\n readonly ascent: number\n readonly descent: number\n /** How far the ink box and the font box reach from the pen: left, right, up and down. */\n readonly reach: readonly [number, number, number, number]\n}\n\nfunction throwIfAborted(signal: AbortSignal): void {\n if (signal.aborted) {\n throw signal.reason ?? new DOMException('The outline trace was aborted', 'AbortError')\n }\n}\n\n/**\n * A task after the page's own: a message is not clamped to 4 ms as a nested timer is, and it\n * does not run ahead of rendering as a `scheduler.yield()` continuation does, which held frames\n * back for 100 ms at a time in Chrome 156.\n */\nfunction nextTask(): Promise<void> {\n return new Promise((resolve) => {\n if (typeof MessageChannel !== 'function') {\n setTimeout(resolve, 0)\n return\n }\n const { port1, port2 } = new MessageChannel()\n port1.onmessage = () => {\n port1.close()\n resolve()\n }\n port2.postMessage(null)\n })\n}\n\n/** Canvas box of a glyph with `margin` pixels around its reach: pen position and size. */\nfunction boxOf(\n reach: Measured['reach'],\n margin: number,\n): [originX: number, baselineY: number, width: number, height: number] {\n const originX = margin + Math.ceil(reach[0])\n const baselineY = margin + Math.ceil(reach[2])\n return [\n originX,\n baselineY,\n originX + Math.ceil(reach[1]) + margin,\n baselineY + Math.ceil(reach[3]) + margin,\n ]\n}\n\n/** Whether any texel on the edge of a `width` x `height` RGBA read holds ink. */\nfunction touchesEdge(rgba: Uint8ClampedArray, width: number, height: number): boolean {\n for (let x = 0; x < width; x++) {\n if (rgba[x * 4 + 3]! > 0 || rgba[((height - 1) * width + x) * 4 + 3]! > 0) return true\n }\n for (let y = 0; y < height; y++) {\n if (rgba[y * width * 4 + 3]! > 0 || rgba[((y + 1) * width - 1) * 4 + 3]! > 0) return true\n }\n return false\n}\n\n/**\n * @internal The outline provider `DomSdf` uses for Windfoil and Slug text when the caller gives\n * none. Each glyph is drawn as the SDF rasterizer draws it (the captured canvas font with its\n * stretch and kerning, an in-document canvas without font smoothing, exact geometry, a neutral\n * grey), at `size` pixels per em, then traced at half coverage and fitted with quadratics. The\n * outline follows that raster, not the font file: font-variation and feature settings are not\n * applied, as on any canvas. Colour glyphs, glyphs of a font the canvas rejects and shaped runs\n * resolve to `null`, for the SDF companion; a glyph without ink to an empty outline. Without a\n * 2D canvas every glyph is `null`, so the whole capture falls back to SDF. `descent` is the SDF\n * slot's, measured at the captured font's own size, so analytic and SDF glyphs share a baseline.\n * Ink the metrics miss is drawn again with half an em more room all round; a glyph whose ink\n * still reaches the edge of its box resolves to `null` too, rather than trace clipped.\n *\n * Calls made in one task with one signal trace as one batch, in slices of about 8 ms between\n * which the page runs and the signal is checked. Each batch has its own working memory, which\n * goes with it. Outlines stay cached per instance until `clear()` or `retain()` drops them; one\n * traced while `document.fonts.check()` still reported its font as not ready is never cached.\n */\nexport function createTracedOutlineProvider(\n document: Document,\n options: TracedOutlineOptions = {},\n): TracedOutlines {\n const size = options.size ?? 256\n const tolerance = options.tolerance ?? 0.25\n const colorGlyphs = options.colorGlyphs ?? 'emoji'\n const cache = new Map<string, WindfoilGlyphOutline | null>()\n let epoch = 0\n /** The batches still open to requests of this task, by signal. */\n const open = new Map<AbortSignal, Batch>()\n\n const run = async (\n signal: AbortSignal,\n requests: ReadonlyMap<string, GlyphRequest>,\n started: number,\n ): Promise<ReadonlyMap<string, WindfoilGlyphOutline | null>> => {\n const results = new Map<string, WindfoilGlyphOutline | null>()\n // Each font of the batch, as captured and as traced: the captured canvas font with only\n // its size rewritten, as an adaptive SDF bake does.\n const groups = new Map<string, [GlyphRequest[], FontStyleSnapshot]>()\n for (const request of requests.values()) {\n // Shapes resolve elsewhere; a shaped run is one tile of a line, which no outline covers.\n if (request.shape || request.shaping) {\n results.set(request.key, null)\n continue\n }\n const group = groups.get(request.font.key)\n if (group) group[0].push(request)\n else {\n const font = request.font\n groups.set(font.key, [\n [request],\n { ...font, canvasFont: font.canvasFont.replace(SIZE_TOKEN, `${size}px`) },\n ])\n }\n }\n const traced = (request: GlyphRequest): GlyphRequest => ({\n ...request,\n font: groups.get(request.font.key)![1],\n })\n await waitForFonts(\n document,\n [...groups.values()].flatMap(([list]) => list.map(traced)),\n signal,\n )\n throwIfAborted(signal)\n\n const fonts = document.fonts as FontFaceSet | undefined\n const keep = (request: GlyphRequest, outline: WindfoilGlyphOutline | null): void => {\n results.set(request.key, outline)\n let ready = epoch === started\n try {\n ready &&= fonts?.check(traced(request).font.canvasFont, request.character) ?? true\n } catch {\n ready = false\n }\n if (ready) cache.set(request.key, outline)\n }\n\n const canvas = createCanvas(document)\n try {\n const context = canvas.getContext('2d', { willReadFrequently: true })\n if (!context) {\n // Not cached: the whole capture falls back to SDF, and a later build may try again.\n for (const [list] of groups.values())\n for (const request of list) results.set(request.key, null)\n return results\n }\n let current: FontStyleSnapshot | null = null\n const accepted = new Map<FontStyleSnapshot, boolean>()\n /** Applies a request's font as the rasterizer does; false when the canvas rejected it. */\n const use = (request: GlyphRequest): boolean => {\n if (current !== request.font) {\n context.font = SENTINEL_FONT\n const sentinel = context.font\n setFontContext(context, request, undefined, null)\n current = request.font\n accepted.set(request.font, context.font !== sentinel)\n }\n return accepted.get(request.font)!\n }\n\n // Measure every glyph first: sizing the canvas resets its context.\n const margin = Math.max(4, Math.ceil(size / 32))\n const measured: Measured[] = []\n let canvasWidth = 1\n let canvasHeight = 1\n for (const [list] of groups.values()) {\n throwIfAborted(signal)\n const bake = Number.parseFloat(SIZE_TOKEN.exec(list[0]!.font.canvasFont)?.[0] ?? '')\n if (!(bake > 0) || !use(list[0]!)) {\n for (const request of list) keep(request, null)\n continue\n }\n // The SDF slot's metrics, measured at the captured font's own size.\n const scale = size / bake\n const slots = list.map((request) => {\n const slot = context.measureText(request.character)\n return [\n Math.max(1, slot.fontBoundingBoxAscent || slot.actualBoundingBoxAscent) * scale,\n Math.max(1, slot.fontBoundingBoxDescent || slot.actualBoundingBoxDescent) * scale,\n ] as const\n })\n if (!use(traced(list[0]!))) {\n for (const request of list) keep(request, null)\n continue\n }\n list.forEach((request, index) => {\n const [ascent, descent] = slots[index]!\n // Ink can only be found in the ink box and the font box.\n const metrics = context.measureText(request.character)\n const reach = [\n Math.max(0, metrics.actualBoundingBoxLeft || 0),\n Math.max(metrics.width || 0, metrics.actualBoundingBoxRight || 0),\n Math.max(ascent, metrics.actualBoundingBoxAscent || 0),\n Math.max(descent, metrics.actualBoundingBoxDescent || 0),\n ] as const\n const [, , width, height] = boxOf(reach, margin)\n if (!(width <= 8 * size && height <= 8 * size)) {\n keep(request, null)\n return\n }\n canvasWidth = Math.max(canvasWidth, width)\n canvasHeight = Math.max(canvasHeight, height)\n measured.push({ request: traced(request), ascent, descent, reach })\n })\n }\n const resize = (width: number, height: number): void => {\n if (width <= canvas.width && height <= canvas.height) return\n canvas.width = Math.max(width, canvas.width)\n canvas.height = Math.max(height, canvas.height)\n current = null\n }\n resize(canvasWidth, canvasHeight)\n\n const exact = 'textRendering' in context\n const draw = (\n glyph: Measured,\n [originX, baselineY, width, height]: ReturnType<typeof boxOf>,\n fill: string,\n rendering: CanvasTextRendering,\n ): Uint8ClampedArray => {\n resize(width, height)\n use(glyph.request)\n context.fillStyle = fill\n if (exact) context.textRendering = rendering\n context.clearRect(0, 0, width, height)\n context.fillText(glyph.request.character, originX, baselineY)\n return context.getImageData(0, 0, width, height).data\n }\n const colorModule = measured.some((glyph) => isColorCandidate(glyph.request, colorGlyphs))\n ? await import('../atlas/colorGlyphs.js')\n : null\n throwIfAborted(signal)\n // This batch's working memory, grown to fit its largest glyph (about 1 MB at 256 px per\n // em) and released with the batch, so an idle tracer holds none.\n const scratch = createTraceScratch()\n let sliceStart = performance.now()\n for (const glyph of measured) {\n throwIfAborted(signal)\n let box = boxOf(glyph.reach, margin)\n const [, , width, height] = box\n // A candidate the font draws in the fill colour alone is text, as in the SDF bake: only\n // ink that ignores the fill goes to the companion.\n const colored =\n colorModule !== null &&\n isColorCandidate(glyph.request, colorGlyphs) &&\n colorModule.encodeColorBand(\n draw(glyph, box, '#fff', 'auto'),\n draw(glyph, box, '#000', 'auto'),\n width,\n height,\n 0,\n [{ x: 0, y: 0, width, height }],\n ).colored[0] === true\n let outline: WindfoilGlyphOutline | null = null\n if (!colored) {\n // The SDF bake's text rendering: exact geometry, the neutral middle of a contrast table.\n let rgba = draw(glyph, box, '#606060', 'geometricPrecision')\n let clipped = touchesEdge(rgba, box[2], box[3])\n if (clipped) {\n // The metrics missed some ink: once more with half an em of room all round.\n box = boxOf(glyph.reach, margin + size / 2)\n rgba = draw(glyph, box, '#606060', 'geometricPrecision')\n clipped = touchesEdge(rgba, box[2], box[3])\n }\n // Ink past even that room would trace clipped: the SDF companion draws the glyph.\n if (!clipped) {\n const { quadratics, bbox } = traceCoverage(\n {\n alpha: rgba,\n width: box[2],\n height: box[3],\n stride: 4,\n offset: 3,\n originX: box[0],\n baselineY: box[1],\n },\n tolerance,\n scratch,\n )\n outline = {\n unitsPerEm: size,\n ascent: glyph.ascent,\n descent: -glyph.descent,\n bbox,\n quadratics,\n }\n }\n }\n keep(requests.get(glyph.request.key)!, outline)\n if (performance.now() - sliceStart > SLICE_MS) {\n await nextTask()\n throwIfAborted(signal)\n sliceStart = performance.now()\n }\n }\n return results\n } finally {\n // Release the backing store now: Safari counts a detached canvas against its canvas\n // memory until it is collected.\n canvas.width = 0\n canvas.height = 0\n canvas.remove()\n }\n }\n\n const provider: WindfoilOutlineProvider = (request, signal) => {\n throwIfAborted(signal)\n const cached = cache.get(request.key)\n if (cached !== undefined) return cached\n let batch = open.get(signal)\n if (!batch) {\n const requests = new Map<string, GlyphRequest>()\n // Everything this task asks for with this signal joins before the batch starts. What a\n // clear() before then would drop is not cached either.\n const started = epoch\n const next: Batch = {\n signal,\n requests,\n done: Promise.resolve().then(() => {\n if (open.get(signal) === next) open.delete(signal)\n return run(signal, requests, started)\n }),\n }\n open.set(signal, (batch = next))\n }\n batch.requests.set(request.key, request)\n return batch.done.then((results) => results.get(request.key) ?? null)\n }\n\n return {\n provider,\n clear() {\n epoch++\n cache.clear()\n },\n retain(keys) {\n const live = new Set(keys)\n for (const key of cache.keys()) if (!live.has(key)) cache.delete(key)\n },\n }\n}\n"],"mappings":";;;;AA8BA,IAAM,WAAW;;AAEjB,IAAM,gBAAgB;AACtB,IAAM,aAAa;AAkBnB,SAAS,eAAe,QAA2B;CACjD,IAAI,OAAO,SACT,MAAM,OAAO,UAAU,IAAI,aAAa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AAS,WAAW;EAC7D,eAAe,MAAM;EACrB,MAAM,SAAS,MAAM,IAAI,QAAQ,GAAG;EACpC,IAAI,WAAW,KAAA,GAAW,OAAO;EACjC,IAAI,QAAQ,KAAK,IAAI,MAAM;EAC3B,IAAI,CAAC,OAAO;GACV,MAAM,2BAAW,IAAI,IAA0B;GAG/C,MAAM,UAAU;GAChB,MAAM,OAAc;IAClB;IACA;IACA,MAAM,QAAQ,QAAQ,CAAC,CAAC,WAAW;KACjC,IAAI,KAAK,IAAI,MAAM,MAAM,MAAM,KAAK,OAAO,MAAM;KACjD,OAAO,IAAI,QAAQ,UAAU,OAAO;IACtC,CAAC;GACH;GACA,KAAK,IAAI,QAAS,QAAQ,IAAK;EACjC;EACA,MAAM,SAAS,IAAI,QAAQ,KAAK,OAAO;EACvC,OAAO,MAAM,KAAK,MAAM,YAAY,QAAQ,IAAI,QAAQ,GAAG,KAAK,IAAI;CACtE;CAEA,OAAO;EACL;EACA,QAAQ;GACN;GACA,MAAM,MAAM;EACd;EACA,OAAO,MAAM;GACX,MAAM,OAAO,IAAI,IAAI,IAAI;GACzB,KAAK,MAAM,OAAO,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,GAAG,MAAM,OAAO,GAAG;EACtE;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"tracedOutlines.js","names":[],"sources":["../../src/windfoil/tracedOutlines.ts"],"sourcesContent":["import {\n allFontsLoaded,\n createCanvas,\n isColorCandidate,\n setFontContext,\n waitForFonts,\n} from '../dom/fontCanvas.js'\nimport type {\n ColorGlyphMode,\n FontStyleSnapshot,\n GlyphRequest,\n WindfoilGlyphOutline,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport { createTraceScratch, traceCoverage } from './trace/outline.js'\n\n/** Options of the built-in Canvas 2D outline tracer. */\nexport interface TracedOutlineOptions {\n /** Trace resolution in pixels per em, also each outline's `unitsPerEm`. Defaults to `256`. */\n readonly size?: number\n /** Furthest, in trace pixels, a fitted curve may stray from its contour. Defaults to `0.25`. */\n readonly tolerance?: number\n /** Which glyphs to test for colour ink, as `DomSdfOptions.colorGlyphs`. Defaults to `'emoji'`. */\n readonly colorGlyphs?: ColorGlyphMode\n}\n\n/** A `WindfoilOutlineProvider` that traces the browser's own glyphs, and its cache. */\nexport interface TracedOutlines {\n readonly provider: WindfoilOutlineProvider\n /** Forgets every traced outline, as after a webfont load; work in flight is not kept. */\n clear(): void\n /** Forgets the outlines of every glyph key not listed. */\n retain(keys: Iterable<string>): void\n}\n\n/** A batch yields to the page once it has traced for this long. */\nconst SLICE_MS = 8\n/** A font assignment the canvas rejects leaves this one in place. */\nconst SENTINEL_FONT = '1px serif'\nconst SIZE_TOKEN = /[\\d.]+px/\n\n/** The requests one task made with one signal, traced together. */\ninterface Batch {\n readonly signal: AbortSignal\n readonly requests: Map<string, GlyphRequest>\n readonly done: Promise<ReadonlyMap<string, WindfoilGlyphOutline | null>>\n}\n\n/** One glyph between measuring and tracing, in trace pixels; y grows downwards. */\ninterface Measured {\n readonly request: GlyphRequest\n readonly ascent: number\n readonly descent: number\n /** How far the ink box and the font box reach from the pen: left, right, up and down. */\n readonly reach: readonly [number, number, number, number]\n}\n\nfunction throwIfAborted(signal: AbortSignal): void {\n if (signal.aborted) {\n throw signal.reason ?? new DOMException('The outline trace was aborted', 'AbortError')\n }\n}\n\n/**\n * A task after the page's own: a message is not clamped to 4 ms as a nested timer is, and it\n * does not run ahead of rendering as a `scheduler.yield()` continuation does, which held frames\n * back for 100 ms at a time in Chrome 156.\n */\nfunction nextTask(): Promise<void> {\n return new Promise((resolve) => {\n if (typeof MessageChannel !== 'function') {\n setTimeout(resolve, 0)\n return\n }\n const { port1, port2 } = new MessageChannel()\n port1.onmessage = () => {\n port1.close()\n resolve()\n }\n port2.postMessage(null)\n })\n}\n\n/** Canvas box of a glyph with `margin` pixels around its reach: pen position and size. */\nfunction boxOf(\n reach: Measured['reach'],\n margin: number,\n): [originX: number, baselineY: number, width: number, height: number] {\n const originX = margin + Math.ceil(reach[0])\n const baselineY = margin + Math.ceil(reach[2])\n return [\n originX,\n baselineY,\n originX + Math.ceil(reach[1]) + margin,\n baselineY + Math.ceil(reach[3]) + margin,\n ]\n}\n\n/** Whether any texel on the edge of a `width` x `height` RGBA read holds ink. */\nfunction touchesEdge(\n rgba: Uint8ClampedArray,\n width: number,\n height: number,\n rowStride = width * 4,\n baseOffset = 0,\n): boolean {\n for (let x = 0; x < width; x++) {\n if (\n rgba[baseOffset + x * 4 + 3]! > 0 ||\n rgba[baseOffset + (height - 1) * rowStride + x * 4 + 3]! > 0\n ) {\n return true\n }\n }\n for (let y = 0; y < height; y++) {\n const row = baseOffset + y * rowStride\n if (rgba[row + 3]! > 0 || rgba[row + (width - 1) * 4 + 3]! > 0) return true\n }\n return false\n}\n\nconst MAX_SHEET = 2048\nconst SHEET_GAP = 1\n\n/**\n * The outline provider `DomSdf` and `DomSlug` use for Windfoil and Slug text when the caller gives\n * none. Each glyph is drawn as the SDF rasterizer draws it (the captured canvas font with its\n * stretch and kerning, an in-document canvas without font smoothing, exact geometry, a neutral\n * grey), at `size` pixels per em, then traced at half coverage and fitted with quadratics. The\n * outline follows that raster, not the font file: font-variation and feature settings are not\n * applied, as on any canvas. Colour glyphs, glyphs of a font the canvas rejects and shaped runs\n * resolve to `null`, for the SDF companion; a glyph without ink to an empty outline. Without a\n * 2D canvas every glyph is `null`, so the whole capture falls back to SDF. `descent` is the SDF\n * slot's, measured at the captured font's own size, so analytic and SDF glyphs share a baseline.\n * Ink the metrics miss is drawn again with half an em more room all round; a glyph whose ink\n * still reaches the edge of its box resolves to `null` too, rather than trace clipped.\n *\n * Calls made in one task with one signal trace as one batch, in slices of about 8 ms between\n * which the page runs and the signal is checked. Each batch has its own working memory, which\n * goes with it. Outlines stay cached per instance until `clear()` or `retain()` drops them; one\n * traced while `document.fonts.check()` still reported its font as not ready is never cached.\n */\nexport function createTracedOutlineProvider(\n document: Document,\n options: TracedOutlineOptions = {},\n): TracedOutlines {\n const size = options.size ?? 256\n const tolerance = options.tolerance ?? 0.25\n const colorGlyphs = options.colorGlyphs ?? 'emoji'\n const cache = new Map<string, WindfoilGlyphOutline | null>()\n let epoch = 0\n let cachedCanvas: HTMLCanvasElement | null = null\n let cachedContext: CanvasRenderingContext2D | null = null\n /** The batches still open to requests of this task, by signal. */\n const open = new Map<AbortSignal, Batch>()\n\n const run = async (\n signal: AbortSignal,\n requests: ReadonlyMap<string, GlyphRequest>,\n started: number,\n ): Promise<ReadonlyMap<string, WindfoilGlyphOutline | null>> => {\n const results = new Map<string, WindfoilGlyphOutline | null>()\n // Each font of the batch, as captured and as traced: the captured canvas font with only\n // its size rewritten, as an adaptive SDF bake does.\n const groups = new Map<string, [GlyphRequest[], GlyphRequest[], FontStyleSnapshot]>()\n const waitList: GlyphRequest[] = []\n for (const request of requests.values()) {\n // Shapes resolve elsewhere; a shaped run is one tile of a line, which no outline covers.\n if (request.shape || request.shaping) {\n results.set(request.key, null)\n continue\n }\n let group = groups.get(request.font.key)\n if (!group) {\n const font = request.font\n group = [[], [], { ...font, canvasFont: font.canvasFont.replace(SIZE_TOKEN, `${size}px`) }]\n groups.set(font.key, group)\n }\n const tracedReq: GlyphRequest = {\n key: request.key,\n character: request.character,\n font: group[2],\n }\n group[0].push(request)\n group[1].push(tracedReq)\n waitList.push(tracedReq)\n }\n await waitForFonts(document, waitList, signal)\n throwIfAborted(signal)\n\n const preloaded = allFontsLoaded(document)\n const fonts = document.fonts as FontFaceSet | undefined\n const keep = (request: GlyphRequest, outline: WindfoilGlyphOutline | null): void => {\n results.set(request.key, outline)\n let ready = epoch === started\n if (ready && !preloaded) {\n try {\n ready =\n fonts?.check(groups.get(request.font.key)![2].canvasFont, request.character) ?? true\n } catch {\n ready = false\n }\n }\n if (ready) cache.set(request.key, outline)\n }\n\n let canvas: HTMLCanvasElement\n let context: CanvasRenderingContext2D | null\n if (cachedCanvas?.ownerDocument === document && cachedContext) {\n canvas = cachedCanvas\n canvas.width = 1\n canvas.height = 1\n document.documentElement.append(canvas)\n context = cachedContext\n } else {\n canvas = createCanvas(document)\n context = canvas.getContext('2d', { willReadFrequently: true })\n if (context) {\n cachedCanvas = canvas\n cachedContext = context\n }\n }\n try {\n if (!context) {\n // Not cached: the whole capture falls back to SDF, and a later build may try again.\n for (const [list] of groups.values())\n for (const request of list) results.set(request.key, null)\n return results\n }\n let current: FontStyleSnapshot | null = null\n const accepted = new Map<FontStyleSnapshot, boolean>()\n /** Applies a request's font as the rasterizer does; false when the canvas rejected it. */\n const use = (request: GlyphRequest): boolean => {\n if (current !== request.font) {\n context.font = SENTINEL_FONT\n const sentinel = context.font\n setFontContext(context, request, undefined, null)\n current = request.font\n accepted.set(request.font, context.font !== sentinel)\n }\n return accepted.get(request.font)!\n }\n\n // Measure every glyph first: sizing the canvas resets its context.\n const margin = Math.max(4, Math.ceil(size / 32))\n const measured: Measured[] = []\n for (const [list, tracedList] of groups.values()) {\n throwIfAborted(signal)\n const bake = Number.parseFloat(SIZE_TOKEN.exec(list[0]!.font.canvasFont)?.[0] ?? '')\n if (!(bake > 0) || !use(list[0]!)) {\n for (const request of list) keep(request, null)\n continue\n }\n // The SDF slot's metrics, measured at the captured font's own size.\n const scale = size / bake\n const slots = list.map((request) => {\n const slot = context.measureText(request.character)\n return [\n Math.max(1, slot.fontBoundingBoxAscent || slot.actualBoundingBoxAscent) * scale,\n Math.max(1, slot.fontBoundingBoxDescent || slot.actualBoundingBoxDescent) * scale,\n ] as const\n })\n if (!use(tracedList[0]!)) {\n for (const request of list) keep(request, null)\n continue\n }\n for (let index = 0; index < list.length; index++) {\n const request = list[index]!\n const tracedReq = tracedList[index]!\n const [ascent, descent] = slots[index]!\n // Ink can only be found in the tight actual bounding box when reported, or the font box.\n const metrics = context.measureText(request.character)\n const hasHBox = metrics.actualBoundingBoxLeft > 0 || metrics.actualBoundingBoxRight > 0\n const hasVBox =\n metrics.actualBoundingBoxAscent > 0 || metrics.actualBoundingBoxDescent > 0\n const reach = [\n Math.max(0, metrics.actualBoundingBoxLeft || 0),\n Math.max(hasHBox ? 0 : metrics.width || 0, metrics.actualBoundingBoxRight || 0),\n Math.max(hasVBox ? 0 : ascent, metrics.actualBoundingBoxAscent || 0),\n Math.max(hasVBox ? 0 : descent, metrics.actualBoundingBoxDescent || 0),\n ] as const\n const [, , width, height] = boxOf(reach, margin)\n if (!(width <= 8 * size && height <= 8 * size)) {\n keep(request, null)\n continue\n }\n measured.push({ request: tracedReq, ascent, descent, reach })\n }\n }\n const resize = (width: number, height: number): boolean => {\n if (width <= canvas.width && height <= canvas.height) return false\n canvas.width = Math.max(width, canvas.width)\n canvas.height = Math.max(height, canvas.height)\n current = null\n return true\n }\n\n const exact = 'textRendering' in context\n const draw = (\n glyph: Measured,\n [originX, baselineY, width, height]: ReturnType<typeof boxOf>,\n fill: string,\n rendering: CanvasTextRendering,\n ): Uint8ClampedArray => {\n const resized = resize(width, height)\n use(glyph.request)\n context.fillStyle = fill\n if (exact) context.textRendering = rendering\n if (!resized) context.clearRect(0, 0, width, height)\n context.fillText(glyph.request.character, originX, baselineY)\n return context.getImageData(0, 0, width, height).data\n }\n const colorModule = measured.some((glyph) => isColorCandidate(glyph.request, colorGlyphs))\n ? await import('../atlas/colorGlyphs.js')\n : null\n throwIfAborted(signal)\n // This batch's working memory, grown to fit its largest glyph (about 1 MB at 256 px per\n // em) and released with the batch, so an idle tracer holds none.\n const scratch = createTraceScratch()\n let sliceStart = performance.now()\n const view = document.defaultView\n const getContextFn = view\n ? (Object.getOwnPropertyDescriptor(view.HTMLCanvasElement.prototype, 'getContext')\n ?.value as object | undefined)\n : undefined\n const mockedCanvas = !getContextFn || 'mock' in getContextFn\n const finishGlyph = async (\n glyph: Measured,\n box: ReturnType<typeof boxOf>,\n retried: boolean,\n ): Promise<void> => {\n // The SDF bake's text rendering: exact geometry, the neutral middle of a contrast table.\n let currentBox = box\n let rgba = draw(glyph, currentBox, '#606060', 'geometricPrecision')\n let clipped = touchesEdge(rgba, currentBox[2], currentBox[3])\n if (clipped && !retried) {\n // The metrics missed some ink: once more with half an em of room all round.\n currentBox = boxOf(glyph.reach, margin + size / 2)\n rgba = draw(glyph, currentBox, '#606060', 'geometricPrecision')\n clipped = touchesEdge(rgba, currentBox[2], currentBox[3])\n }\n // Ink past even that room would trace clipped: the SDF companion draws the glyph.\n let outline: WindfoilGlyphOutline | null = null\n if (!clipped) {\n const { quadratics, bbox } = traceCoverage(\n {\n alpha: rgba,\n width: currentBox[2],\n height: currentBox[3],\n stride: 4,\n offset: 3,\n originX: currentBox[0],\n baselineY: currentBox[1],\n },\n tolerance,\n scratch,\n )\n outline = {\n unitsPerEm: size,\n ascent: glyph.ascent,\n descent: -glyph.descent,\n bbox,\n quadratics,\n }\n }\n keep(requests.get(glyph.request.key)!, outline)\n if (performance.now() - sliceStart > SLICE_MS) {\n await nextTask()\n throwIfAborted(signal)\n sliceStart = performance.now()\n }\n }\n\n if (mockedCanvas || measured.length < 2) {\n for (const glyph of measured) {\n throwIfAborted(signal)\n const box = boxOf(glyph.reach, margin)\n const [, , width, height] = box\n // A candidate the font draws in the fill colour alone is text, as in the SDF bake:\n // only ink that ignores the fill goes to the companion.\n const colored =\n colorModule !== null &&\n isColorCandidate(glyph.request, colorGlyphs) &&\n colorModule.encodeColorBand(\n draw(glyph, box, '#fff', 'auto'),\n draw(glyph, box, '#000', 'auto'),\n width,\n height,\n 0,\n [{ x: 0, y: 0, width, height }],\n ).colored[0] === true\n if (colored) {\n keep(requests.get(glyph.request.key)!, null)\n if (performance.now() - sliceStart > SLICE_MS) {\n await nextTask()\n throwIfAborted(signal)\n sliceStart = performance.now()\n }\n continue\n }\n await finishGlyph(glyph, box, false)\n }\n } else {\n interface Tile {\n readonly glyph: Measured\n readonly box: ReturnType<typeof boxOf>\n readonly x: number\n readonly y: number\n }\n const plain: { readonly glyph: Measured; readonly box: ReturnType<typeof boxOf> }[] = []\n const oversized: { readonly glyph: Measured; readonly box: ReturnType<typeof boxOf> }[] = []\n const retries: Measured[] = []\n for (const glyph of measured) {\n throwIfAborted(signal)\n const box = boxOf(glyph.reach, margin)\n const [, , width, height] = box\n const colored =\n colorModule !== null &&\n isColorCandidate(glyph.request, colorGlyphs) &&\n colorModule.encodeColorBand(\n draw(glyph, box, '#fff', 'auto'),\n draw(glyph, box, '#000', 'auto'),\n width,\n height,\n 0,\n [{ x: 0, y: 0, width, height }],\n ).colored[0] === true\n if (colored) {\n keep(requests.get(glyph.request.key)!, null)\n continue\n }\n if (width > MAX_SHEET || height > MAX_SHEET) oversized.push({ glyph, box })\n else plain.push({ glyph, box })\n }\n\n const flushSheet = async (sheet: Tile[], sheetW: number, sheetH: number): Promise<void> => {\n const resized = resize(sheetW, sheetH)\n if (!resized) context.clearRect(0, 0, sheetW, sheetH)\n context.fillStyle = '#606060'\n if (exact) context.textRendering = 'geometricPrecision'\n for (const item of sheet) {\n throwIfAborted(signal)\n use(item.glyph.request)\n context.fillText(\n item.glyph.request.character,\n item.x + item.box[0],\n item.y + item.box[1],\n )\n }\n const rgba = context.getImageData(0, 0, sheetW, sheetH).data\n const rowStride = sheetW * 4\n for (const item of sheet) {\n throwIfAborted(signal)\n const [originX, baselineY, width, height] = item.box\n const tileOffset = (item.y * sheetW + item.x) * 4\n if (touchesEdge(rgba, width, height, rowStride, tileOffset)) {\n retries.push(item.glyph)\n continue\n }\n const { quadratics, bbox } = traceCoverage(\n {\n alpha: rgba,\n width,\n height,\n stride: 4,\n offset: tileOffset + 3,\n rowStride,\n originX,\n baselineY,\n },\n tolerance,\n scratch,\n )\n keep(requests.get(item.glyph.request.key)!, {\n unitsPerEm: size,\n ascent: item.glyph.ascent,\n descent: -item.glyph.descent,\n bbox,\n quadratics,\n })\n if (performance.now() - sliceStart > SLICE_MS) {\n await nextTask()\n throwIfAborted(signal)\n sliceStart = performance.now()\n }\n }\n }\n\n if (plain.length < 2) {\n for (const item of plain) {\n throwIfAborted(signal)\n await finishGlyph(item.glyph, item.box, false)\n }\n } else {\n plain.sort((a, b) => b.box[3] - a.box[3] || b.box[2] - a.box[2])\n let sheet: Tile[] = []\n let packX = 0\n let packY = 0\n let rowH = 0\n let sheetW = 0\n let sheetH = 0\n for (const { glyph, box } of plain) {\n const width = box[2]\n const height = box[3]\n if (packX > 0 && packX + width > MAX_SHEET) {\n packX = 0\n packY += rowH + SHEET_GAP\n rowH = 0\n }\n if (packY + height > MAX_SHEET) {\n await flushSheet(sheet, sheetW, sheetH)\n sheet = []\n packX = 0\n packY = 0\n rowH = 0\n sheetW = 0\n sheetH = 0\n }\n sheet.push({ glyph, box, x: packX, y: packY })\n sheetW = Math.max(sheetW, packX + width)\n sheetH = Math.max(sheetH, packY + height)\n packX += width + SHEET_GAP\n rowH = Math.max(rowH, height)\n }\n if (sheet.length > 0) await flushSheet(sheet, sheetW, sheetH)\n }\n for (const item of oversized) {\n throwIfAborted(signal)\n await finishGlyph(item.glyph, item.box, false)\n }\n for (const glyph of retries) {\n throwIfAborted(signal)\n await finishGlyph(glyph, boxOf(glyph.reach, margin + size / 2), true)\n }\n }\n return results\n } finally {\n // Release the backing store now: Safari counts a detached canvas against its canvas\n // memory until it is collected.\n canvas.width = 0\n canvas.height = 0\n canvas.remove()\n }\n }\n\n const provider: WindfoilOutlineProvider = (request, signal) => {\n throwIfAborted(signal)\n const cached = cache.get(request.key)\n if (cached !== undefined) return cached\n let batch = open.get(signal)\n if (!batch) {\n const requests = new Map<string, GlyphRequest>()\n // Everything this task asks for with this signal joins before the batch starts. What a\n // clear() before then would drop is not cached either.\n const started = epoch\n const next: Batch = {\n signal,\n requests,\n done: Promise.resolve().then(() => {\n if (open.get(signal) === next) open.delete(signal)\n return run(signal, requests, started)\n }),\n }\n open.set(signal, (batch = next))\n }\n batch.requests.set(request.key, request)\n return batch.done.then((results) => results.get(request.key) ?? null)\n }\n\n return {\n provider,\n clear() {\n epoch++\n cache.clear()\n },\n retain(keys) {\n const live = new Set(keys)\n for (const key of cache.keys()) if (!live.has(key)) cache.delete(key)\n },\n }\n}\n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