@flighthq/bitmapfont 0.5.1-next.815.cc08b93 → 0.5.1-next.903.f434bc2
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 +2 -2
- package/dist/bitmapFont.d.ts +2 -1
- package/dist/bitmapFont.d.ts.map +1 -1
- package/dist/bitmapFont.js +43 -40
- package/dist/bitmapFont.js.map +1 -1
- package/dist/bitmapFontGlyphSource.d.ts +2 -1
- package/dist/bitmapFontGlyphSource.d.ts.map +1 -1
- package/dist/bitmapFontGlyphSource.js +28 -25
- package/dist/bitmapFontGlyphSource.js.map +1 -1
- package/dist/contract.d.ts +2 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +2 -0
- package/dist/contract.js.map +1 -1
- package/package.json +6 -6
- package/src/bitmapFontFromGlyphAtlas.test.ts +16 -12
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/bitmapfont`. The `@f
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/bitmapfont@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/bitmapfont@0.5.1-next.903.f434bc2](https://github.com/flighthq/flight/tree/f434bc233778d75aeea61995df3a8cfaec459a85/packages/bitmapfont)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/f434bc233778d75aeea61995df3a8cfaec459a85/LICENSE.md)
|
package/dist/bitmapFont.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BitmapFont, BitmapFontData, BitmapFontKerningPair, GlyphEntry, GlyphMetrics, TextureAtlas } from '@flighthq/types/contract';
|
|
1
|
+
import type { BitmapFont, BitmapFontData, BitmapFontKerningPair, EntityConstruction, GlyphEntry, GlyphMetrics, TextureAtlas } from '@flighthq/types/contract';
|
|
2
2
|
export declare function createBitmapFont(data: Readonly<BitmapFontData>): BitmapFont;
|
|
3
3
|
export declare function getBitmapFontGlyph(font: Readonly<BitmapFont>, codepoint: number): GlyphEntry | null;
|
|
4
4
|
export declare function getBitmapFontKerning(font: Readonly<BitmapFont>, left: number, right: number): number;
|
|
@@ -6,6 +6,7 @@ export declare function getBitmapFontMetrics(font: Readonly<BitmapFont>): Readon
|
|
|
6
6
|
export declare function getBitmapFontPage(font: Readonly<BitmapFont>, page?: number): TextureAtlas | null;
|
|
7
7
|
export declare function getBitmapFontPages(font: Readonly<BitmapFont>): readonly TextureAtlas[];
|
|
8
8
|
export declare function hasBitmapFontGlyph(font: Readonly<BitmapFont>, codepoint: number): boolean;
|
|
9
|
+
export declare function initializeBitmapFont(out: EntityConstruction<BitmapFont>, data: Readonly<BitmapFontData>): void;
|
|
9
10
|
export declare function packBitmapFontKerningKey(left: number, right: number): number;
|
|
10
11
|
export declare function setBitmapFontGuard(guard: ((reason: string, codepoint: number, page: number) => void) | null): void;
|
|
11
12
|
export declare function unpackBitmapFontKerningKey(key: number, out: BitmapFontKerningPair): BitmapFontKerningPair;
|
package/dist/bitmapFont.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitmapFont.d.ts","sourceRoot":"","sources":["../src/bitmapFont.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,UAAU,EACV,YAAY,EACZ,YAAY,EACb,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"bitmapFont.d.ts","sourceRoot":"","sources":["../src/bitmapFont.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,YAAY,EACb,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,gBAA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/dist/bitmapFont.js
CHANGED
|
@@ -1,44 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// Builds an immutable static bitmap font from plain data: the glyph list becomes a
|
|
3
|
-
// `codepoint → GlyphEntry` map, the kerning pairs become a `left * 0x110000 + right → amount` map, and
|
|
4
|
-
// the page-indexed atlas list, line metrics, and encoding (default `raster`) are carried as-is. Each
|
|
5
|
-
// glyph's `page` (default 0) indexes `data.pages`; an out-of-range page is clamped to 0 so the glyph
|
|
6
|
-
// is still placed (on the primary page) rather than dropped — a bad page index is a source-data
|
|
7
|
-
// defect the font should survive, not a reason to lose a glyph. Nothing mutates the font after this
|
|
8
|
-
// call — it is the static counterpart to the growing `@flighthq/glyphatlas`.
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
9
2
|
export function createBitmapFont(data) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const page = glyph.page ?? 0;
|
|
14
|
-
glyphs.set(glyph.codepoint, {
|
|
15
|
-
advance: glyph.advance,
|
|
16
|
-
bearingX: glyph.bearingX,
|
|
17
|
-
bearingY: glyph.bearingY,
|
|
18
|
-
height: glyph.height,
|
|
19
|
-
page: resolveBitmapFontGlyphPage(glyph.codepoint, page, pageCount),
|
|
20
|
-
width: glyph.width,
|
|
21
|
-
x: glyph.x,
|
|
22
|
-
y: glyph.y,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
const kerning = new Map();
|
|
26
|
-
if (data.kerning !== undefined) {
|
|
27
|
-
for (const pair of data.kerning) {
|
|
28
|
-
kerning.set(packBitmapFontKerningKey(pair.left, pair.right), pair.amount);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return createEntity({
|
|
32
|
-
encoding: data.encoding ?? 'raster',
|
|
33
|
-
glyphs,
|
|
34
|
-
kerning,
|
|
35
|
-
metrics: {
|
|
36
|
-
ascent: data.metrics.ascent,
|
|
37
|
-
descent: data.metrics.descent,
|
|
38
|
-
lineGap: data.metrics.lineGap,
|
|
39
|
-
},
|
|
40
|
-
pages: data.pages.slice(),
|
|
41
|
-
});
|
|
3
|
+
const out = allocateEntity();
|
|
4
|
+
initializeBitmapFont(out, data);
|
|
5
|
+
return finishEntity(out);
|
|
42
6
|
}
|
|
43
7
|
// The glyph entry (atlas rectangle + advance + bearing) for a codepoint, or `null` when the font
|
|
44
8
|
// carries no glyph for it. A pure map lookup — the static counterpart to glyphatlas's rasterize-on-miss.
|
|
@@ -72,6 +36,45 @@ export function getBitmapFontPages(font) {
|
|
|
72
36
|
export function hasBitmapFontGlyph(font, codepoint) {
|
|
73
37
|
return font.glyphs.has(codepoint);
|
|
74
38
|
}
|
|
39
|
+
// Builds an immutable static bitmap font from plain data: the glyph list becomes a
|
|
40
|
+
// `codepoint → GlyphEntry` map, the kerning pairs become a `left * 0x110000 + right → amount` map, and
|
|
41
|
+
// the page-indexed atlas list, line metrics, and encoding (default `raster`) are carried as-is. Each
|
|
42
|
+
// glyph's `page` (default 0) indexes `data.pages`; an out-of-range page is clamped to 0 so the glyph
|
|
43
|
+
// is still placed (on the primary page) rather than dropped — a bad page index is a source-data
|
|
44
|
+
// defect the font should survive, not a reason to lose a glyph. Nothing mutates the font after this
|
|
45
|
+
// call — it is the static counterpart to the growing `@flighthq/glyphatlas`.
|
|
46
|
+
export function initializeBitmapFont(out, data) {
|
|
47
|
+
const pageCount = data.pages.length;
|
|
48
|
+
const glyphs = new Map();
|
|
49
|
+
for (const glyph of data.glyphs) {
|
|
50
|
+
const page = glyph.page ?? 0;
|
|
51
|
+
glyphs.set(glyph.codepoint, {
|
|
52
|
+
advance: glyph.advance,
|
|
53
|
+
bearingX: glyph.bearingX,
|
|
54
|
+
bearingY: glyph.bearingY,
|
|
55
|
+
height: glyph.height,
|
|
56
|
+
page: resolveBitmapFontGlyphPage(glyph.codepoint, page, pageCount),
|
|
57
|
+
width: glyph.width,
|
|
58
|
+
x: glyph.x,
|
|
59
|
+
y: glyph.y,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const kerning = new Map();
|
|
63
|
+
if (data.kerning !== undefined) {
|
|
64
|
+
for (const pair of data.kerning) {
|
|
65
|
+
kerning.set(packBitmapFontKerningKey(pair.left, pair.right), pair.amount);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
out.encoding = data.encoding ?? 'raster';
|
|
69
|
+
out.glyphs = glyphs;
|
|
70
|
+
out.kerning = kerning;
|
|
71
|
+
out.metrics = {
|
|
72
|
+
ascent: data.metrics.ascent,
|
|
73
|
+
descent: data.metrics.descent,
|
|
74
|
+
lineGap: data.metrics.lineGap,
|
|
75
|
+
};
|
|
76
|
+
out.pages = data.pages.slice();
|
|
77
|
+
}
|
|
75
78
|
// Packs an adjacent glyph pair into the single-number kerning-map key `left * 0x110000 + right`. The
|
|
76
79
|
// inverse is `unpackBitmapFontKerningKey`; the two are one primitive and must move together.
|
|
77
80
|
//
|
package/dist/bitmapFont.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitmapFont.js","sourceRoot":"","sources":["../src/bitmapFont.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"bitmapFont.js","sourceRoot":"","sources":["../src/bitmapFont.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAWzE,MAAM,UAAU,gBAAgB,CAAC,IAA8B;IAC7D,MAAM,GAAG,GAAG,cAAc,EAAc,CAAC;IACzC,oBAAoB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAChC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,iGAAiG;AACjG,yGAAyG;AACzG,MAAM,UAAU,kBAAkB,CAAC,IAA0B,EAAE,SAAiB;IAC9E,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC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vG,uGAAuG;AACvG,sGAAsG;AACtG,6FAA6F;AAC7F,EAAE;AACF,kGAAkG;AAClG,sGAAsG;AACtG,sGAAsG;AACtG,kGAAkG;AAClG,MAAM,UAAU,wBAAwB,CAAC,IAAY,EAAE,KAAa;IAClE,OAAO,IAAI,GAAG,uBAAuB,GAAG,KAAK,CAAC;AAChD,CAAC;AAED,qGAAqG;AACrG,2FAA2F;AAC3F,gGAAgG;AAChG,MAAM,UAAU,kBAAkB,CAAC,KAAyE;IAC1G,MAAM,GAAG,KAAK,CAAC;AACjB,CAAC;AAED,2FAA2F;AAC3F,wGAAwG;AACxG,mGAAmG;AACnG,yFAAyF;AACzF,EAAE;AACF,kGAAkG;AAClG,qEAAqE;AACrE,MAAM,UAAU,0BAA0B,CAAC,GAAW,EAAE,GAA0B;IAChF,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,uBAAuB,CAAC,CAAC;IACrD,GAAG,CAAC,KAAK,GAAG,GAAG,GAAG,uBAAuB,CAAC;IAC1C,OAAO,GAAG,CAAC;AACb,CAAC;AAED,sGAAsG;AACtG,yGAAyG;AACzG,sGAAsG;AACtG,qFAAqF;AACrF,SAAS,0BAA0B,CAAC,SAAiB,EAAE,IAAY,EAAE,SAAiB;IACpF,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,GAAG,SAAS;QAAE,OAAO,IAAI,CAAC;IAC/C,MAAM,EAAE,CAAC,mBAAmB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/C,OAAO,CAAC,CAAC;AACX,CAAC;AAED,kGAAkG;AAClG,MAAM,uBAAuB,GAAG,QAAQ,CAAC;AAEzC,IAAI,MAAM,GAAuE,IAAI,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { BitmapFont, Entity, GlyphSource } from '@flighthq/types/contract';
|
|
1
|
+
import type { BitmapFont, Entity, GlyphSource, EntityConstruction } from '@flighthq/types/contract';
|
|
2
2
|
export declare function createGlyphSourceFromBitmapFont(font: Readonly<BitmapFont>): GlyphSource & Entity;
|
|
3
|
+
export declare function initializeGlyphSourceFromBitmapFont(out: EntityConstruction<GlyphSource>, font: Readonly<BitmapFont>): void;
|
|
3
4
|
//# sourceMappingURL=bitmapFontGlyphSource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitmapFontGlyphSource.d.ts","sourceRoot":"","sources":["../src/bitmapFontGlyphSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"bitmapFontGlyphSource.d.ts","sourceRoot":"","sources":["../src/bitmapFontGlyphSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAIpG,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,WAAW,GAAG,MAAM,CAIhG;AAMD,wBAAgB,mCAAmC,CACjD,GAAG,EAAE,kBAAkB,CAAC,WAAW,CAAC,EACpC,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,GACzB,IAAI,CAsBN"}
|
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import { getBitmapFontGlyph, getBitmapFontKerning, getBitmapFontMetrics } from './bitmapFont';
|
|
3
|
+
export function createGlyphSourceFromBitmapFont(font) {
|
|
4
|
+
const out = allocateEntity();
|
|
5
|
+
initializeGlyphSourceFromBitmapFont(out, font);
|
|
6
|
+
return finishEntity(out);
|
|
7
|
+
}
|
|
3
8
|
// Adapts a `BitmapFont` into the `GlyphSource` seam a text renderer consumes, binding the font's pure
|
|
4
9
|
// lookups into the method object. `getGlyphEntry` is the static map lookup (no side effects) — the
|
|
5
10
|
// static counterpart to `@flighthq/glyphatlas`'s `createGlyphSourceFromGlyphAtlas`, whose
|
|
6
11
|
// `getGlyphEntry` rasterizes on miss. A renderer holds either behind the one seam without knowing which.
|
|
7
|
-
export function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
});
|
|
12
|
+
export function initializeGlyphSourceFromBitmapFont(out, font) {
|
|
13
|
+
out.getGlyphAtlasImage = (page = 0) => {
|
|
14
|
+
// Each page's atlas image, indexed by the glyph's `page`. An out-of-range page (or a page whose
|
|
15
|
+
// atlas carries no image yet) yields null — the renderer skips glyphs it cannot sample.
|
|
16
|
+
const texture = font.pages[page]?.texture;
|
|
17
|
+
return texture?.dimension === '2d' ? texture.source : null;
|
|
18
|
+
};
|
|
19
|
+
out.getGlyphEntry = (codepoint) => {
|
|
20
|
+
return getBitmapFontGlyph(font, codepoint);
|
|
21
|
+
};
|
|
22
|
+
out.getGlyphKerning = (left, right) => {
|
|
23
|
+
return getBitmapFontKerning(font, left, right);
|
|
24
|
+
};
|
|
25
|
+
out.getGlyphLayoutVersion = () => {
|
|
26
|
+
// A pre-baked font never relocates a glyph — its pages are authored, not packed at runtime — so
|
|
27
|
+
// the placement revision is a constant and a consumer that bakes these rects never re-bakes.
|
|
28
|
+
// This is the whole reason the seam reports a number rather than the consumer polling rects.
|
|
29
|
+
return 0;
|
|
30
|
+
};
|
|
31
|
+
out.getGlyphMetrics = () => {
|
|
32
|
+
return getBitmapFontMetrics(font);
|
|
33
|
+
};
|
|
31
34
|
}
|
|
32
35
|
//# sourceMappingURL=bitmapFontGlyphSource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitmapFontGlyphSource.js","sourceRoot":"","sources":["../src/bitmapFontGlyphSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"bitmapFontGlyphSource.js","sourceRoot":"","sources":["../src/bitmapFontGlyphSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAE9F,MAAM,UAAU,+BAA+B,CAAC,IAA0B;IACxE,MAAM,GAAG,GAAG,cAAc,EAAe,CAAC;IAC1C,mCAAmC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC/C,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,sGAAsG;AACtG,mGAAmG;AACnG,0FAA0F;AAC1F,yGAAyG;AACzG,MAAM,UAAU,mCAAmC,CACjD,GAAoC,EACpC,IAA0B;IAE1B,GAAG,CAAC,kBAAkB,GAAG,CAAC,IAAI,GAAG,CAAC,EAAE,EAAE;QACpC,gGAAgG;QAChG,wFAAwF;QACxF,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAC1C,OAAO,OAAO,EAAE,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7D,CAAC,CAAC;IACF,GAAG,CAAC,aAAa,GAAG,CAAC,SAAS,EAAE,EAAE;QAChC,OAAO,kBAAkB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC7C,CAAC,CAAC;IACF,GAAG,CAAC,eAAe,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACpC,OAAO,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC,CAAC;IACF,GAAG,CAAC,qBAAqB,GAAG,GAAG,EAAE;QAC/B,gGAAgG;QAChG,6FAA6F;QAC7F,6FAA6F;QAC7F,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;IACF,GAAG,CAAC,eAAe,GAAG,GAAG,EAAE;QACzB,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/contract.d.ts
CHANGED
|
@@ -4,4 +4,6 @@ export * from './bitmapFontGlyphSource';
|
|
|
4
4
|
export * from './enableBitmapFontGuards';
|
|
5
5
|
export * from './explainBitmapFontGlyph';
|
|
6
6
|
export * from './summarizeBitmapFont';
|
|
7
|
+
export { initializeGlyphSourceFromBitmapFont } from './bitmapFontGlyphSource';
|
|
8
|
+
export { initializeBitmapFont } from './bitmapFont';
|
|
7
9
|
//# sourceMappingURL=contract.d.ts.map
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -4,4 +4,6 @@ export * from './bitmapFontGlyphSource';
|
|
|
4
4
|
export * from './enableBitmapFontGuards';
|
|
5
5
|
export * from './explainBitmapFontGlyph';
|
|
6
6
|
export * from './summarizeBitmapFont';
|
|
7
|
+
export { initializeGlyphSourceFromBitmapFont } from './bitmapFontGlyphSource';
|
|
8
|
+
export { initializeBitmapFont } from './bitmapFont';
|
|
7
9
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/bitmapfont",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.903.f434bc2",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.5.1-next.
|
|
42
|
-
"@flighthq/log": "0.5.1-next.
|
|
43
|
-
"@flighthq/texture": "0.5.1-next.
|
|
44
|
-
"@flighthq/textureatlas": "0.5.1-next.
|
|
45
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/entity": "0.5.1-next.903.f434bc2",
|
|
42
|
+
"@flighthq/log": "0.5.1-next.903.f434bc2",
|
|
43
|
+
"@flighthq/texture": "0.5.1-next.903.f434bc2",
|
|
44
|
+
"@flighthq/textureatlas": "0.5.1-next.903.f434bc2",
|
|
45
|
+
"@flighthq/types": "0.5.1-next.903.f434bc2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@flighthq/glyphatlas": "*",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createGlyphAtlas, getGlyphAtlasEntry
|
|
1
|
+
import { createGlyphAtlas, getGlyphAtlasEntry } from '@flighthq/glyphatlas/contract';
|
|
2
2
|
import type { GlyphRasterizerBackend } from '@flighthq/types/contract';
|
|
3
|
-
import {
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
4
|
|
|
5
5
|
import { getBitmapFontGlyph, getBitmapFontMetrics } from './bitmapFont';
|
|
6
6
|
import { createBitmapFontFromGlyphAtlas } from './bitmapFontFromGlyphAtlas';
|
|
@@ -20,11 +20,14 @@ function backendProducing(width: number, height: number): GlyphRasterizerBackend
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
describe('createBitmapFontFromGlyphAtlas', () => {
|
|
23
|
-
afterEach(() => setGlyphRasterizerBackend(null));
|
|
24
|
-
|
|
25
23
|
function bakedFromTwoGlyphs() {
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const atlas = createGlyphAtlas({
|
|
25
|
+
fontFamily: 'mock',
|
|
26
|
+
fontSize: 16,
|
|
27
|
+
height: 64,
|
|
28
|
+
rasterizerBackend: backendProducing(8, 8),
|
|
29
|
+
width: 64,
|
|
30
|
+
});
|
|
28
31
|
getGlyphAtlasEntry(atlas, 65);
|
|
29
32
|
getGlyphAtlasEntry(atlas, 66);
|
|
30
33
|
return { atlas, font: createBitmapFontFromGlyphAtlas(atlas) };
|
|
@@ -50,8 +53,6 @@ describe('createBitmapFontFromGlyphAtlas', () => {
|
|
|
50
53
|
expect(getBitmapFontMetrics(font)).toEqual({ ascent: 12, descent: 3, lineGap: 1 });
|
|
51
54
|
});
|
|
52
55
|
|
|
53
|
-
// The page is CPU-only: the atlas bitmap is already a valid texture source under the flat model, so
|
|
54
|
-
// baking needs no GPU work and no readback.
|
|
55
56
|
it('builds a single page whose texture is sourced from the atlas bitmap', () => {
|
|
56
57
|
const { atlas, font } = bakedFromTwoGlyphs();
|
|
57
58
|
|
|
@@ -59,8 +60,6 @@ describe('createBitmapFontFromGlyphAtlas', () => {
|
|
|
59
60
|
expect(font.pages[0]!.texture!.source).toBe(atlas.runtime.bitmap);
|
|
60
61
|
});
|
|
61
62
|
|
|
62
|
-
// A bake is a snapshot. Rasterizing more glyphs into the source atlas afterwards must not reach the
|
|
63
|
-
// font, or "bake" would just be another view of a live cache.
|
|
64
63
|
it('does not gain glyphs rasterized into the atlas after the bake', () => {
|
|
65
64
|
const { atlas, font } = bakedFromTwoGlyphs();
|
|
66
65
|
|
|
@@ -70,8 +69,13 @@ describe('createBitmapFontFromGlyphAtlas', () => {
|
|
|
70
69
|
});
|
|
71
70
|
|
|
72
71
|
it('bakes an empty atlas to a font with no glyphs rather than failing', () => {
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
const atlas = createGlyphAtlas({
|
|
73
|
+
fontFamily: 'mock',
|
|
74
|
+
fontSize: 16,
|
|
75
|
+
height: 64,
|
|
76
|
+
rasterizerBackend: backendProducing(8, 8),
|
|
77
|
+
width: 64,
|
|
78
|
+
});
|
|
75
79
|
|
|
76
80
|
const font = createBitmapFontFromGlyphAtlas(atlas);
|
|
77
81
|
|