-
Notifications
You must be signed in to change notification settings - Fork 2
fix(text): route external raster kinds around the Worker font-bake plan #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0d93370
fix(text): route external raster kinds around the Worker font-bake plan
thejustinwalsh 221c8eb
fix(benchmarks): price the external-raster routing growth into the co…
thejustinwalsh 58e54de
fix(benchmarks): price the routing growth into the three-runtime ceil…
thejustinwalsh 20bbefe
merge: carry the external runtime bake across the glyph package rename
thejustinwalsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/glyph-example-raster/tests/runtime-bake-routing.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { mkdtemp, readFile, rm } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
|
|
||
| import { createTextRuntime, type RuntimeFontBakeRequest } from '@pmndrs/text'; | ||
| import { bakeFont } from '@pmndrs/text/bake'; | ||
| import { workerRasterKinds } from '@pmndrs/text/runtime-bake'; | ||
| import { afterEach, test } from 'vitest'; | ||
|
|
||
| import { glyphExample } from '../src/index.js'; | ||
|
|
||
| const fixtureDirectory = new URL('../../../apps/benchmarks/fixtures/fonts/inter-v4.1/', import.meta.url); | ||
| const shaperWasmUrl = new URL('../../text/dist/text_shaper.wasm', import.meta.url); | ||
|
|
||
| const cleanups: (() => Promise<void>)[] = []; | ||
| afterEach(async () => { | ||
| while (cleanups.length > 0) await cleanups.pop()?.(); | ||
| }); | ||
|
|
||
| /** | ||
| * The published external contract, end to end: an external technique's raster | ||
| * never rides the Worker font-bake plan and instead bakes host-side through | ||
| * the baker its own declaration names. The stub stands in for the Worker and | ||
| * enforces its real contract by rejecting any kind outside the declared set; | ||
| * it returns a core artifact baked from the same source so the host-side | ||
| * attachment passes the provenance check. | ||
| */ | ||
| test('the example technique bakes host-side while the Worker plan stays first-party', async () => { | ||
| const source = await readFile(new URL('Inter-Regular.ttf', fixtureDirectory)); | ||
| const outputRoot = await mkdtemp(join(tmpdir(), 'glyph-example-routing-')); | ||
| cleanups.push(() => rm(outputRoot, { recursive: true, force: true })); | ||
| const stubOutput = join(outputRoot, 'Inter-Regular.font.glb'); | ||
| await bakeFont({ | ||
| input: new URL('Inter-Regular.ttf', fixtureDirectory), | ||
| output: stubOutput, | ||
| font: { fontFaceIndex: 0 }, | ||
| }); | ||
| const artifact = await readFile(stubOutput); | ||
|
|
||
| const runtime = await createTextRuntime({ wasm: await readFile(shaperWasmUrl) }); | ||
| cleanups.push(async () => runtime.dispose()); | ||
| const requests: RuntimeFontBakeRequest[] = []; | ||
| const runtimeBake = async (request: RuntimeFontBakeRequest) => { | ||
| for (const raster of request.rasters ?? []) { | ||
| if (!workerRasterKinds.includes(raster.kind)) { | ||
| throw new Error(`runtime font baker does not support raster kind ${raster.kind}`); | ||
| } | ||
| } | ||
| requests.push(request); | ||
| return new Uint8Array(artifact.buffer.slice(artifact.byteOffset, artifact.byteOffset + artifact.byteLength)); | ||
| }; | ||
|
|
||
| const [example] = await runtime.loadFont({ | ||
| input: { | ||
| source: `data:font/ttf;base64,${source.toString('base64')}`, | ||
| runtimeBake, | ||
| }, | ||
| rasters: [{ technique: glyphExample, options: { paletteSeed: 17, inset: 0.1 } }], | ||
| }); | ||
|
|
||
| assert.equal(requests.length, 1, 'the source load bakes its core through the Worker path once'); | ||
| assert.deepEqual( | ||
| (requests[0]?.rasters ?? []).map(({ kind }) => kind), | ||
| [], | ||
| 'the Worker plan carries no external kinds', | ||
| ); | ||
| assert.equal(example.technique, glyphExample); | ||
| assert.ok(example.data, 'the external raster decodes from its host-baked artifact'); | ||
| example.dispose(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete. Holding two versions of baking routing still.