@weasel-js/font 1.6.1 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-QDTJ3CPE.js → chunk-RYN4NYX4.js} +582 -38
- package/dist/chunk-RYN4NYX4.js.map +1 -0
- package/dist/index.d.ts +34 -18
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/dist/{test-seams-BpiGqWz-.d.ts → test-seams-Df2Zqwk8.d.ts} +372 -95
- package/dist/test-seams.d.ts +2 -1
- package/dist/test-seams.js +1 -1
- package/package.json +2 -1
- package/dist/chunk-QDTJ3CPE.js.map +0 -1
|
@@ -1,82 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* BmFont JSON types and parser for the MSDF atlas format produced by
|
|
3
|
-
* msdf-bmfont-xml. The parser builds accelerator maps (charMap, kerningMap)
|
|
4
|
-
* for O(1) glyph and kerning lookup during layout.
|
|
5
|
-
*/
|
|
6
|
-
interface BmFontInfo {
|
|
7
|
-
face: string;
|
|
8
|
-
size: number;
|
|
9
|
-
}
|
|
10
|
-
/** Font-wide vertical metrics and the atlas page dimensions, in pixels. */
|
|
11
|
-
interface BmFontCommon {
|
|
12
|
-
lineHeight: number;
|
|
13
|
-
base: number;
|
|
14
|
-
scaleW: number;
|
|
15
|
-
scaleH: number;
|
|
16
|
-
}
|
|
17
|
-
/** One glyph: where it sits in the atlas page (`x`/`y`/`width`/`height`),
|
|
18
|
-
* where to draw it relative to the pen (`xoffset`/`yoffset`), and how far the
|
|
19
|
-
* pen then advances. */
|
|
20
|
-
interface BmFontChar {
|
|
21
|
-
id: number;
|
|
22
|
-
x: number;
|
|
23
|
-
y: number;
|
|
24
|
-
width: number;
|
|
25
|
-
height: number;
|
|
26
|
-
xoffset: number;
|
|
27
|
-
yoffset: number;
|
|
28
|
-
xadvance: number;
|
|
29
|
-
page: number;
|
|
30
|
-
}
|
|
31
|
-
/** A kerning pair: `amount` px to add to the advance when `second` follows
|
|
32
|
-
* `first`. Codepoints, not glyph indices. */
|
|
33
|
-
interface BmFontKerning {
|
|
34
|
-
first: number;
|
|
35
|
-
second: number;
|
|
36
|
-
amount: number;
|
|
37
|
-
}
|
|
38
|
-
/** A parsed MSDF atlas: the BmFont record plus the `charMap` / `kerningMap`
|
|
39
|
-
* accelerators layout reads per glyph. */
|
|
40
|
-
interface BmFont {
|
|
41
|
-
info: BmFontInfo;
|
|
42
|
-
common: BmFontCommon;
|
|
43
|
-
chars: BmFontChar[];
|
|
44
|
-
kernings: BmFontKerning[];
|
|
45
|
-
charMap: Map<number, BmFontChar>;
|
|
46
|
-
kerningMap: Map<number, Map<number, number>>;
|
|
47
|
-
}
|
|
48
|
-
/** Two-glyph fixture for unit tests. */
|
|
49
|
-
declare const FIXTURE_FONT: {
|
|
50
|
-
info: {
|
|
51
|
-
face: string;
|
|
52
|
-
size: number;
|
|
53
|
-
};
|
|
54
|
-
common: {
|
|
55
|
-
lineHeight: number;
|
|
56
|
-
base: number;
|
|
57
|
-
scaleW: number;
|
|
58
|
-
scaleH: number;
|
|
59
|
-
};
|
|
60
|
-
chars: {
|
|
61
|
-
id: number;
|
|
62
|
-
x: number;
|
|
63
|
-
y: number;
|
|
64
|
-
width: number;
|
|
65
|
-
height: number;
|
|
66
|
-
xoffset: number;
|
|
67
|
-
yoffset: number;
|
|
68
|
-
xadvance: number;
|
|
69
|
-
page: number;
|
|
70
|
-
}[];
|
|
71
|
-
kernings: {
|
|
72
|
-
first: number;
|
|
73
|
-
second: number;
|
|
74
|
-
amount: number;
|
|
75
|
-
}[];
|
|
76
|
-
};
|
|
77
|
-
/** Validate a BmFont JSON document and build its lookup maps. Throws with the
|
|
78
|
-
* missing or malformed field named. */
|
|
79
|
-
declare function parseBmFont(raw: unknown): BmFont;
|
|
1
|
+
import { Reflection } from '@weasel-js/registry';
|
|
80
2
|
|
|
81
3
|
/**
|
|
82
4
|
* The style axis of a font variant, one declaration for the whole stack.
|
|
@@ -145,7 +67,7 @@ interface GlyphTextureSink {
|
|
|
145
67
|
* mip levels blend across glyph rects).
|
|
146
68
|
*/
|
|
147
69
|
|
|
148
|
-
interface FaceMetrics {
|
|
70
|
+
interface FaceMetrics$1 {
|
|
149
71
|
ascent: number;
|
|
150
72
|
descent: number;
|
|
151
73
|
}
|
|
@@ -158,7 +80,7 @@ interface RasterizedGlyph {
|
|
|
158
80
|
advance: number;
|
|
159
81
|
}
|
|
160
82
|
interface GlyphRasterizer {
|
|
161
|
-
faceMetrics(family: string, weight: number, style: FontStyle): FaceMetrics;
|
|
83
|
+
faceMetrics(family: string, weight: number, style: FontStyle): FaceMetrics$1;
|
|
162
84
|
rasterize(family: string, weight: number, style: FontStyle, codepoint: number): RasterizedGlyph;
|
|
163
85
|
}
|
|
164
86
|
|
|
@@ -297,6 +219,7 @@ declare function _resetDynamicFontsForTests(): void;
|
|
|
297
219
|
* parse happens once per glyph, and core caches the *tessellation*, not the
|
|
298
220
|
* text.
|
|
299
221
|
*/
|
|
222
|
+
|
|
300
223
|
/** A parsed font face, viewed only as a source of glyph outlines. See the
|
|
301
224
|
* module comment for the em-space contract `glyphD` returns. */
|
|
302
225
|
interface OutlineFace {
|
|
@@ -307,11 +230,16 @@ interface OutlineFace {
|
|
|
307
230
|
* Distance from the line top to the baseline, in em units — the outline
|
|
308
231
|
* tier's analogue of a `BmFont`'s `common.base`.
|
|
309
232
|
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
233
|
+
* The default parser reports `faceMetrics.ascent`, the ascent a browser
|
|
234
|
+
* sets the face with, so a face used for metrics puts text on the same
|
|
235
|
+
* baseline as an atlas of the same font and as the DOM edit overlay.
|
|
313
236
|
*/
|
|
314
237
|
ascender: number;
|
|
238
|
+
/** The face's decoration and script metrics, derived with
|
|
239
|
+
* `faceMetricsFromTables` so they match an atlas baked from the same
|
|
240
|
+
* font. Optional: a custom parser that omits it leaves layout on its
|
|
241
|
+
* defaults. */
|
|
242
|
+
faceMetrics?: FaceMetrics;
|
|
315
243
|
/**
|
|
316
244
|
* Em-space SVG path data for `cp`, or `null` when this face has no glyph
|
|
317
245
|
* for the codepoint *or* the glyph has no contours (a space). Both answers
|
|
@@ -356,10 +284,24 @@ interface FontVariant {
|
|
|
356
284
|
weight?: number;
|
|
357
285
|
style?: FontStyle;
|
|
358
286
|
}
|
|
287
|
+
/** One family's registered faces, keyed `${weight}|${style}`. */
|
|
288
|
+
type FontFamilyFaces = ReadonlyMap<string, FontEntry>;
|
|
289
|
+
/** Every registered family and its faces, in registration order. `listFonts`
|
|
290
|
+
* is the same set shaped for a font picker. */
|
|
291
|
+
declare const fontRegistry: Reflection<FontFamilyFaces>;
|
|
359
292
|
/** Test helper. Do not call from product code. */
|
|
360
293
|
declare function _resetFontRegistryForTests(): void;
|
|
361
294
|
/** Exact lookup — does NOT walk the fallback chain. Use `resolveFontVariant` for that. */
|
|
362
295
|
declare function getFont(family: string, weight?: number, style?: FontStyle): FontEntry | null;
|
|
296
|
+
/**
|
|
297
|
+
* The decoration and script metrics of an exact `(family, weight, style)` —
|
|
298
|
+
* the atlas's when one is registered, else a loaded outline face's. Like
|
|
299
|
+
* {@link getFont}, it walks no fallback chain and enrolls no canvas font,
|
|
300
|
+
* which suits a caller holding a CSS font name rather than a layout result.
|
|
301
|
+
* An idle outline face starts loading, as it would for layout.
|
|
302
|
+
* A run already resolved for layout reads `faceMetricsOf(result)` instead.
|
|
303
|
+
*/
|
|
304
|
+
declare function faceMetricsFor(family: string, weight?: number, style?: FontStyle): FaceMetrics | undefined;
|
|
363
305
|
/** One family in the registry and the variants registered for it — what a
|
|
364
306
|
* font picker can honestly offer. */
|
|
365
307
|
interface RegisteredFont {
|
|
@@ -376,11 +318,72 @@ interface RegisteredFont {
|
|
|
376
318
|
*/
|
|
377
319
|
declare function listFonts(): readonly RegisteredFont[];
|
|
378
320
|
/**
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
321
|
+
* The weights `family` has a real face for, on the atlas tier or the outline
|
|
322
|
+
* tier, in either style — what a weight picker can honestly offer. Ascending
|
|
323
|
+
* and deduplicated; empty for a family nothing registered. An outline face
|
|
324
|
+
* whose load failed is left out. The canvas tier is not consulted: it
|
|
325
|
+
* rasterizes whatever weight it is asked for, so it has no list to report.
|
|
326
|
+
*/
|
|
327
|
+
declare function listFontWeights(family: string): readonly number[];
|
|
328
|
+
/** Options for {@link registerFont}. */
|
|
329
|
+
interface RegisterFontOptions {
|
|
330
|
+
/**
|
|
331
|
+
* Fetch nothing until text first resolves this face. Layout treats the face
|
|
332
|
+
* as pending from registration on, so a run set in it lays out as nothing —
|
|
333
|
+
* never in a fallback face's metrics — and relays out when the atlas lands.
|
|
334
|
+
* The returned promise settles with that load, so it never settles for a
|
|
335
|
+
* face no text uses.
|
|
336
|
+
*/
|
|
337
|
+
lazy?: boolean;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Register a baked MSDF atlas and its metrics as one variant of `family`.
|
|
341
|
+
* Resolves once the face is usable; re-registering a variant that is already
|
|
342
|
+
* present is a no-op.
|
|
343
|
+
*
|
|
344
|
+
* Eager by default: both files are fetched now. With `{ lazy: true }` they are
|
|
345
|
+
* fetched the first time text asks for the family, which keeps the atlas off
|
|
346
|
+
* the critical path of anything that draws no text.
|
|
347
|
+
*/
|
|
348
|
+
declare function registerFont(family: string, variant: FontVariant, metricsUrl: string, atlasUrl: string, opts?: RegisterFontOptions): Promise<void>;
|
|
349
|
+
/** One face text is set in, the way a render asks for it — what
|
|
350
|
+
* {@link warmFonts} takes to load that face and nothing else. Weight
|
|
351
|
+
* defaults to 400 and style to `'normal'`. */
|
|
352
|
+
interface FontRequest {
|
|
353
|
+
family: string;
|
|
354
|
+
weight?: number;
|
|
355
|
+
style?: FontStyle;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Load registered atlases ahead of their first use, so a synchronous render —
|
|
359
|
+
* `renderSceneToPixels`, an export, a print — draws text set in a lazily
|
|
360
|
+
* registered face rather than nothing. With no list, loads every family
|
|
361
|
+
* `registerFont` was called for.
|
|
362
|
+
*
|
|
363
|
+
* A family name loads every variant registered for it. A {@link FontRequest}
|
|
364
|
+
* loads what resolving that one variant would draw with: the exact variant
|
|
365
|
+
* when one was registered, otherwise every variant of the family, since the
|
|
366
|
+
* within-family chain may land on any; the family the `'substitute'` policy
|
|
367
|
+
* would draw instead when the requested one has no atlas; and the variant's
|
|
368
|
+
* outline face when one is registered.
|
|
369
|
+
*
|
|
370
|
+
* Starts each lazily declared variant and joins any fetch already running.
|
|
371
|
+
* Resolves once they have all landed; a registered variant counts as loaded.
|
|
372
|
+
* Rejects when a load fails, or for a family name `registerFont` never saw —
|
|
373
|
+
* a request for such a family is not an error, since the canvas and outline
|
|
374
|
+
* tiers serve families no atlas was registered for.
|
|
382
375
|
*/
|
|
383
|
-
declare function
|
|
376
|
+
declare function warmFonts(fonts?: readonly (string | FontRequest)[]): Promise<void>;
|
|
377
|
+
/**
|
|
378
|
+
* Could a registration that has not landed yet still serve this request?
|
|
379
|
+
* True while any `registerFont` for the family is fetching — the within-family
|
|
380
|
+
* chain may resolve to whichever variant it brings — or while an outline face
|
|
381
|
+
* registered for this exact variant has not finished loading.
|
|
382
|
+
*
|
|
383
|
+
* A face that resolves to nothing right now is either missing or merely late;
|
|
384
|
+
* this tells the two apart, so "not registered" is reported only when it is.
|
|
385
|
+
*/
|
|
386
|
+
declare function fontPending(family: string, weight?: number, style?: FontStyle): boolean;
|
|
384
387
|
/**
|
|
385
388
|
* Ensure the atlas for `(family, weight, style)` is uploaded to
|
|
386
389
|
* `textureCache`. Cache key is `${family}|${weight}|${style}` so each
|
|
@@ -472,6 +475,206 @@ declare function resolveFontVariant(family: string, weight: number, style: FontS
|
|
|
472
475
|
*/
|
|
473
476
|
declare function resolveGlyphFallback(family: string, weight: number, style: FontStyle): ResolveResult | null;
|
|
474
477
|
|
|
478
|
+
/**
|
|
479
|
+
* The line, decoration and script metrics a font states for itself, in the
|
|
480
|
+
* kit's units: em fractions, with a rule's `offset` measured *down* from the
|
|
481
|
+
* baseline to its top edge (y grows down) and a script's `shift` positive
|
|
482
|
+
* for a rise.
|
|
483
|
+
*
|
|
484
|
+
* Both glyph tiers carry the same record — an atlas bakes it into its JSON,
|
|
485
|
+
* a parsed face reads it off the font's tables — and both derive it through
|
|
486
|
+
* {@link faceMetricsFromTables}, so one font yields one set of numbers
|
|
487
|
+
* whichever tier ends up serving a run.
|
|
488
|
+
*/
|
|
489
|
+
|
|
490
|
+
/** One rule: the top edge's distance below the baseline, and its weight. */
|
|
491
|
+
interface FaceRuleMetrics {
|
|
492
|
+
readonly offset: number;
|
|
493
|
+
readonly thickness: number;
|
|
494
|
+
}
|
|
495
|
+
/** One script preset: `size` scales the inherited font size, `shift` raises
|
|
496
|
+
* (positive) or lowers (negative) the baseline, in inherited ems. */
|
|
497
|
+
interface FaceScriptMetrics {
|
|
498
|
+
readonly size: number;
|
|
499
|
+
readonly shift: number;
|
|
500
|
+
}
|
|
501
|
+
/** What a face says about its line, rules, scripts and letter heights.
|
|
502
|
+
* Every field is optional: a font may carry some of these tables and not
|
|
503
|
+
* others. */
|
|
504
|
+
interface FaceMetrics {
|
|
505
|
+
/** Baseline to the top of the face's line box, in ems — the ascent a
|
|
506
|
+
* browser sets this face with. See {@link verticalMetricsFromTables}. */
|
|
507
|
+
readonly ascent?: number;
|
|
508
|
+
/** Baseline to the bottom of the face's line box, in ems, positive
|
|
509
|
+
* downward. Present exactly when `ascent` is. */
|
|
510
|
+
readonly descent?: number;
|
|
511
|
+
readonly underline?: FaceRuleMetrics;
|
|
512
|
+
readonly strikethrough?: FaceRuleMetrics;
|
|
513
|
+
readonly superscript?: FaceScriptMetrics;
|
|
514
|
+
readonly subscript?: FaceScriptMetrics;
|
|
515
|
+
/** Height of a flat lowercase letter above the baseline, in ems
|
|
516
|
+
* (`OS/2.sxHeight`). */
|
|
517
|
+
readonly xHeight?: number;
|
|
518
|
+
/** Height of a flat capital above the baseline, in ems
|
|
519
|
+
* (`OS/2.sCapHeight`). */
|
|
520
|
+
readonly capHeight?: number;
|
|
521
|
+
}
|
|
522
|
+
/** The table fields {@link faceMetricsFromTables} reads, in font units, as
|
|
523
|
+
* the OpenType `post` and `OS/2` tables state them. */
|
|
524
|
+
interface FaceMetricTables {
|
|
525
|
+
unitsPerEm: number;
|
|
526
|
+
hhea?: {
|
|
527
|
+
ascender?: number;
|
|
528
|
+
descender?: number;
|
|
529
|
+
};
|
|
530
|
+
post?: {
|
|
531
|
+
underlinePosition?: number;
|
|
532
|
+
underlineThickness?: number;
|
|
533
|
+
};
|
|
534
|
+
os2?: {
|
|
535
|
+
fsSelection?: number;
|
|
536
|
+
sTypoAscender?: number;
|
|
537
|
+
sTypoDescender?: number;
|
|
538
|
+
usWinAscent?: number;
|
|
539
|
+
usWinDescent?: number;
|
|
540
|
+
yStrikeoutPosition?: number;
|
|
541
|
+
yStrikeoutSize?: number;
|
|
542
|
+
ySuperscriptYSize?: number;
|
|
543
|
+
ySuperscriptYOffset?: number;
|
|
544
|
+
ySubscriptYSize?: number;
|
|
545
|
+
ySubscriptYOffset?: number;
|
|
546
|
+
sxHeight?: number;
|
|
547
|
+
sCapHeight?: number;
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* The ascent and descent a browser sets this face with, in ems, descent
|
|
552
|
+
* positive downward.
|
|
553
|
+
*
|
|
554
|
+
* The OpenType rule: `OS/2` `sTypoAscender`/`sTypoDescender` when the font
|
|
555
|
+
* sets `USE_TYPO_METRICS`, otherwise `hhea`. It is the browser's rule rather
|
|
556
|
+
* than a typographer's because the DOM edit overlay stands in for the canvas
|
|
557
|
+
* and can only ever get the browser's numbers. Firefox, and every engine on
|
|
558
|
+
* Linux, follow it; Chromium and WebKit on macOS read `hhea` even when the
|
|
559
|
+
* flag is set, and the overlay's measured baseline correction absorbs the
|
|
560
|
+
* difference there. `verticalMetrics.browser.test.ts` pins both.
|
|
561
|
+
*
|
|
562
|
+
* Falls back to the typo pair, then the win pair, when `hhea` is absent or
|
|
563
|
+
* zero.
|
|
564
|
+
*/
|
|
565
|
+
declare function verticalMetricsFromTables(t: FaceMetricTables): {
|
|
566
|
+
ascent: number;
|
|
567
|
+
descent: number;
|
|
568
|
+
} | undefined;
|
|
569
|
+
/**
|
|
570
|
+
* Convert raw table values to {@link FaceMetrics}.
|
|
571
|
+
*
|
|
572
|
+
* `post.underlinePosition` and `OS/2.yStrikeoutPosition` are the rule's top
|
|
573
|
+
* edge, positive above the baseline. `ySubscriptYOffset` is positive
|
|
574
|
+
* *downward*, unlike its superscript twin. A zero weight or size is a font
|
|
575
|
+
* that left the field blank, not one asking for an invisible rule, so that
|
|
576
|
+
* entry is dropped and the caller's default applies — which is also how an
|
|
577
|
+
* `OS/2` table older than version 2 reads, since it has no heights at all.
|
|
578
|
+
*/
|
|
579
|
+
declare function faceMetricsFromTables(t: FaceMetricTables): FaceMetrics | undefined;
|
|
580
|
+
/**
|
|
581
|
+
* The face metrics behind a resolved run — the outline face's on the outline
|
|
582
|
+
* tier, the atlas's on the atlas tier. The canvas tier rasterizes through
|
|
583
|
+
* `CanvasRenderingContext2D`, which exposes no font tables, so it has none
|
|
584
|
+
* and callers fall back to their defaults.
|
|
585
|
+
*/
|
|
586
|
+
declare function faceMetricsOf(result: ResolveResult): FaceMetrics | undefined;
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* BmFont JSON types and parser for the MSDF atlas format produced by
|
|
590
|
+
* msdf-bmfont-xml. The parser builds accelerator maps (charMap, kerningMap)
|
|
591
|
+
* for O(1) glyph and kerning lookup during layout.
|
|
592
|
+
*/
|
|
593
|
+
|
|
594
|
+
interface BmFontInfo {
|
|
595
|
+
face: string;
|
|
596
|
+
size: number;
|
|
597
|
+
}
|
|
598
|
+
/** Font-wide vertical metrics and the atlas page dimensions, in pixels. */
|
|
599
|
+
interface BmFontCommon {
|
|
600
|
+
lineHeight: number;
|
|
601
|
+
base: number;
|
|
602
|
+
scaleW: number;
|
|
603
|
+
scaleH: number;
|
|
604
|
+
}
|
|
605
|
+
/** One glyph: where it sits in the atlas page (`x`/`y`/`width`/`height`),
|
|
606
|
+
* where to draw it relative to the pen (`xoffset`/`yoffset`), and how far the
|
|
607
|
+
* pen then advances. */
|
|
608
|
+
interface BmFontChar {
|
|
609
|
+
id: number;
|
|
610
|
+
x: number;
|
|
611
|
+
y: number;
|
|
612
|
+
width: number;
|
|
613
|
+
height: number;
|
|
614
|
+
xoffset: number;
|
|
615
|
+
yoffset: number;
|
|
616
|
+
xadvance: number;
|
|
617
|
+
page: number;
|
|
618
|
+
}
|
|
619
|
+
/** A kerning pair: `amount` px to add to the advance when `second` follows
|
|
620
|
+
* `first`. Codepoints, not glyph indices. */
|
|
621
|
+
interface BmFontKerning {
|
|
622
|
+
first: number;
|
|
623
|
+
second: number;
|
|
624
|
+
amount: number;
|
|
625
|
+
}
|
|
626
|
+
/** A parsed MSDF atlas: the BmFont record plus the `charMap` / `kerningMap`
|
|
627
|
+
* accelerators layout reads per glyph. */
|
|
628
|
+
interface BmFont {
|
|
629
|
+
info: BmFontInfo;
|
|
630
|
+
common: BmFontCommon;
|
|
631
|
+
chars: BmFontChar[];
|
|
632
|
+
kernings: BmFontKerning[];
|
|
633
|
+
charMap: Map<number, BmFontChar>;
|
|
634
|
+
kerningMap: Map<number, Map<number, number>>;
|
|
635
|
+
/** The font's own decoration and script metrics, when the bake recorded
|
|
636
|
+
* them. Not part of the BMFont format: `gen-font` adds it as a top-level
|
|
637
|
+
* `faceMetrics` block, and an atlas without one leaves layout on its
|
|
638
|
+
* defaults. */
|
|
639
|
+
faceMetrics?: FaceMetrics;
|
|
640
|
+
/** Atlas texels over which the distance field runs from 0 to 1, edge at
|
|
641
|
+
* 0.5 — msdf-bmfont-xml's `distanceField.distanceRange`. Absent when the
|
|
642
|
+
* file does not record it. */
|
|
643
|
+
distanceRange?: number;
|
|
644
|
+
}
|
|
645
|
+
/** Two-glyph fixture for unit tests. */
|
|
646
|
+
declare const FIXTURE_FONT: {
|
|
647
|
+
info: {
|
|
648
|
+
face: string;
|
|
649
|
+
size: number;
|
|
650
|
+
};
|
|
651
|
+
common: {
|
|
652
|
+
lineHeight: number;
|
|
653
|
+
base: number;
|
|
654
|
+
scaleW: number;
|
|
655
|
+
scaleH: number;
|
|
656
|
+
};
|
|
657
|
+
chars: {
|
|
658
|
+
id: number;
|
|
659
|
+
x: number;
|
|
660
|
+
y: number;
|
|
661
|
+
width: number;
|
|
662
|
+
height: number;
|
|
663
|
+
xoffset: number;
|
|
664
|
+
yoffset: number;
|
|
665
|
+
xadvance: number;
|
|
666
|
+
page: number;
|
|
667
|
+
}[];
|
|
668
|
+
kernings: {
|
|
669
|
+
first: number;
|
|
670
|
+
second: number;
|
|
671
|
+
amount: number;
|
|
672
|
+
}[];
|
|
673
|
+
};
|
|
674
|
+
/** Validate a BmFont JSON document and build its lookup maps. Throws with the
|
|
675
|
+
* missing or malformed field named. */
|
|
676
|
+
declare function parseBmFont(raw: unknown): BmFont;
|
|
677
|
+
|
|
475
678
|
/**
|
|
476
679
|
* Cross-family fallback policy. The per-family chain in `resolveFontVariant`
|
|
477
680
|
* (weight → style → synthetic) has always been rich; what was missing is what
|
|
@@ -504,6 +707,57 @@ declare function getDefaultFontFamily(): string | null;
|
|
|
504
707
|
/** Test helper. Do not call from product code. */
|
|
505
708
|
declare function _resetFallbackForTests(): void;
|
|
506
709
|
|
|
710
|
+
/**
|
|
711
|
+
* The face the canvas draws, handed to DOM text.
|
|
712
|
+
*
|
|
713
|
+
* A family name means one thing to the registry and another to CSS: the kit
|
|
714
|
+
* may draw `sans-serif` from a baked Inter atlas while a `font-family:
|
|
715
|
+
* sans-serif` in the page resolves to Helvetica. Anything the DOM sets in
|
|
716
|
+
* place of canvas text — the text edit overlay above all — asks here instead
|
|
717
|
+
* of writing the name through. The answer names a private `FontFace` loaded
|
|
718
|
+
* from the family's registered font file, with the family itself as fallback
|
|
719
|
+
* while that loads.
|
|
720
|
+
*
|
|
721
|
+
* The font file is the one `registerFontOutlines` holds; that registry is the
|
|
722
|
+
* kit's record of which faces have real bytes behind them. An atlas-only
|
|
723
|
+
* family has none, so the DOM gets the browser's own face for the name and a
|
|
724
|
+
* one-time warning says which registration would fix it.
|
|
725
|
+
*/
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* The CSS `font-family` value that sets DOM text in the face the canvas draws
|
|
729
|
+
* for `family` at this variant.
|
|
730
|
+
*
|
|
731
|
+
* - A family the canvas draws through the browser (`registerCanvasFont`, or
|
|
732
|
+
* the `'canvas'` fallback policy) comes back unchanged: the DOM already
|
|
733
|
+
* resolves the name to the same face.
|
|
734
|
+
* - A family drawn from a baked atlas or from outlines comes back as a private
|
|
735
|
+
* face built from its `registerFontOutlines` file — every registered weight
|
|
736
|
+
* and style of it, so the browser picks and synthesizes within the family
|
|
737
|
+
* the way the canvas does — followed by `family` as the fallback.
|
|
738
|
+
* - Under the `'substitute'` policy, the face is the substitute's.
|
|
739
|
+
*
|
|
740
|
+
* Starts loading the face on first call and never waits for it; ask
|
|
741
|
+
* {@link cssFontFamilyLoading} for that. A face whose bytes arrived earlier —
|
|
742
|
+
* passed to `registerFontOutlines` as an `ArrayBuffer`, or read for the canvas
|
|
743
|
+
* — was built when they did. Outside a browser, `family` comes back unchanged.
|
|
744
|
+
*/
|
|
745
|
+
declare function cssFontFamily(family: string, variant?: FontVariant): string;
|
|
746
|
+
/**
|
|
747
|
+
* The load still in flight for the face {@link cssFontFamily} names for
|
|
748
|
+
* `family` at this variant, or `null` when there is nothing to wait for: it
|
|
749
|
+
* has loaded or failed, or the DOM uses `family` as it stands. Waits on the
|
|
750
|
+
* variant's own face when one is registered and on the whole family
|
|
751
|
+
* otherwise, since the browser then picks among them. Starts the load like
|
|
752
|
+
* `cssFontFamily` does, and never rejects.
|
|
753
|
+
*
|
|
754
|
+
* `null` rather than a settled promise, so a caller whose face is loaded goes
|
|
755
|
+
* on in the same task instead of a microtask later.
|
|
756
|
+
*/
|
|
757
|
+
declare function cssFontFamilyLoading(family: string, variant?: FontVariant): Promise<void> | null;
|
|
758
|
+
/** @internal Test seam — module state. */
|
|
759
|
+
declare function _resetDomFacesForTests(): void;
|
|
760
|
+
|
|
507
761
|
/**
|
|
508
762
|
* The outline tier's registry: which faces have real font bytes behind them,
|
|
509
763
|
* and what a given glyph looks like.
|
|
@@ -574,9 +828,26 @@ interface OutlineFontOptions {
|
|
|
574
828
|
/** Override the default opentype.js parser. Mostly a test seam; also the
|
|
575
829
|
* hook for a consumer who already has a font parser in their bundle. */
|
|
576
830
|
parser?: OutlineParser;
|
|
831
|
+
/**
|
|
832
|
+
* The `@font-face` `src` that gives DOM text this face — what the text edit
|
|
833
|
+
* overlay sets its glyphs in, so they match the canvas's. Defaults to
|
|
834
|
+
* `url(…)` of a URL source and to the bytes themselves otherwise; a face
|
|
835
|
+
* whose bytes the browser cannot load directly, such as one member of a
|
|
836
|
+
* `.ttc`, names it here instead (`local("Helvetica-Bold")`).
|
|
837
|
+
*/
|
|
838
|
+
cssSrc?: string;
|
|
577
839
|
}
|
|
578
840
|
/** Load state of one registered face. */
|
|
579
841
|
type OutlineStatus = 'idle' | 'loading' | 'ready' | 'failed';
|
|
842
|
+
/** One registered outline face and its load state. */
|
|
843
|
+
interface OutlineFaceInfo {
|
|
844
|
+
readonly family: string;
|
|
845
|
+
readonly weight: number;
|
|
846
|
+
readonly style: FontStyle;
|
|
847
|
+
readonly status: OutlineStatus;
|
|
848
|
+
}
|
|
849
|
+
/** Every registered outline face, keyed `family|weight|style`. */
|
|
850
|
+
declare const fontOutlineRegistry: Reflection<OutlineFaceInfo>;
|
|
580
851
|
/**
|
|
581
852
|
* Register font file bytes for one face, so text set in it can render from
|
|
582
853
|
* outlines above the size threshold.
|
|
@@ -606,12 +877,7 @@ declare function hasFontOutlines(family: string, weight?: number, style?: FontSt
|
|
|
606
877
|
declare function outlineStatus(family: string, weight?: number, style?: FontStyle): OutlineStatus | null;
|
|
607
878
|
/** Every registered outline face and its load state — the enumeration a
|
|
608
879
|
* debug overlay or font picker needs, mirroring `listFonts`. */
|
|
609
|
-
declare function listFontOutlines(): readonly
|
|
610
|
-
family: string;
|
|
611
|
-
weight: number;
|
|
612
|
-
style: FontStyle;
|
|
613
|
-
status: OutlineStatus;
|
|
614
|
-
}[];
|
|
880
|
+
declare function listFontOutlines(): readonly OutlineFaceInfo[];
|
|
615
881
|
/**
|
|
616
882
|
* Em-space SVG path data for one glyph of a registered outline face, or `null`
|
|
617
883
|
* when there is nothing to draw.
|
|
@@ -637,7 +903,18 @@ declare function glyphOutline(family: string, weight: number, style: FontStyle,
|
|
|
637
903
|
* frame after the bytes land.
|
|
638
904
|
*/
|
|
639
905
|
declare function outlineMetrics(family: string, weight: number, style: FontStyle): OutlineFace | null;
|
|
906
|
+
/**
|
|
907
|
+
* Load a registered face's bytes now and resolve with its settled status:
|
|
908
|
+
* `'ready'`, `'failed'`, or `null` when nothing is registered for the
|
|
909
|
+
* variant. Never rejects — a failed load is a status, the same one
|
|
910
|
+
* `outlineStatus` reports.
|
|
911
|
+
*
|
|
912
|
+
* The per-frame readers start a load and answer `null` until it lands, which
|
|
913
|
+
* suits a renderer and nothing that needs the geometry in one go: converting
|
|
914
|
+
* text to paths awaits this first.
|
|
915
|
+
*/
|
|
916
|
+
declare function loadFontOutlines(family: string, variant?: OutlineVariant): Promise<OutlineStatus | null>;
|
|
640
917
|
/** @internal Test seam — registry and warn-once keys are module state. */
|
|
641
918
|
declare function _resetFontOutlinesForTests(): void;
|
|
642
919
|
|
|
643
|
-
export {
|
|
920
|
+
export { outlineStatus as $, faceMetricsFor as A, type BmFont as B, type CanvasFontEntry as C, DEFAULT_BAKE_BUDGET as D, faceMetricsFromTables as E, type FontStyle as F, type GlyphTextureSink as G, faceMetricsOf as H, fontOutlineRegistry as I, fontPending as J, fontRegistry as K, getDefaultFontFamily as L, getFont as M, getFontFallbackPolicy as N, type OutlineFace as O, glyphOutline as P, hasFontOutlines as Q, type RegisterFontOptions as R, isCanvasFont as S, type TexSource as T, listCanvasFonts as U, listFontOutlines as V, listFontWeights as W, listFonts as X, loadFontOutlines as Y, markAllFontsNotUploaded as Z, outlineMetrics as _, type BmFontChar as a, parseBmFont as a0, registerCanvasFont as a1, registerFont as a2, registerFontOutlines as a3, resetBakeBudget as a4, resolveFontVariant as a5, resolveGlyphFallback as a6, setDefaultFontFamily as a7, setFontFallbackPolicy as a8, syncDynamicPageTexture as a9, textureCacheKey as aa, unregisterCanvasFont as ab, unregisterFontOutlines as ac, verticalMetricsFromTables as ad, warmFonts as ae, __setGlyphRasterizerForTests as af, _getPagesForTests as ag, _resetDomFacesForTests as ah, _resetDynamicFontsForTests as ai, _resetFallbackForTests as aj, _resetFontOutlinesForTests as ak, _resetFontRegistryForTests as al, type BmFontCommon as b, type BmFontInfo as c, type BmFontKerning as d, FIXTURE_FONT as e, type FaceMetricTables as f, type FaceMetrics as g, type FaceRuleMetrics as h, type FaceScriptMetrics as i, type FontEntry as j, type FontFallbackPolicy as k, type FontFamilyFaces as l, type FontRequest as m, type FontVariant as n, type OutlineFaceInfo as o, type OutlineFontOptions as p, type OutlineParser as q, type OutlineSource as r, type OutlineStatus as s, type OutlineVariant as t, type RegisteredFont as u, type ResolveResult as v, cssFontFamily as w, cssFontFamilyLoading as x, dynamicPageTextureId as y, ensureFontTexture as z };
|
package/dist/test-seams.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { af as __setGlyphRasterizerForTests, ag as _getPagesForTests, ah as _resetDomFacesForTests, ai as _resetDynamicFontsForTests, aj as _resetFallbackForTests, ak as _resetFontOutlinesForTests, al as _resetFontRegistryForTests } from './test-seams-Df2Zqwk8.js';
|
|
2
|
+
import '@weasel-js/registry';
|
package/dist/test-seams.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { __setGlyphRasterizerForTests, _getPagesForTests, _resetDynamicFontsForTests, _resetFallbackForTests, _resetFontOutlinesForTests, _resetFontRegistryForTests } from './chunk-
|
|
1
|
+
export { __setGlyphRasterizerForTests, _getPagesForTests, _resetDomFacesForTests, _resetDynamicFontsForTests, _resetFallbackForTests, _resetFontOutlinesForTests, _resetFontRegistryForTests } from './chunk-RYN4NYX4.js';
|
|
2
2
|
//# sourceMappingURL=test-seams.js.map
|
|
3
3
|
//# sourceMappingURL=test-seams.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasel-js/font",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "MSDF font atlases, glyph metrics, and runtime glyph rasterization for @weasel-js/core. Registry, kerning-aware glyph layout, and the SDF text shader source.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"provenance": true
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
+
"@weasel-js/registry": "1.7.1",
|
|
49
50
|
"opentype.js": "2.0.0"
|
|
50
51
|
}
|
|
51
52
|
}
|