A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(text): encode font paths without identity collisions
yhh9f216ad0788b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0f365d201..d0e2b12f5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Project font identities preserve complete asset paths.** Reversible, CSS-safe UTF-16 encoding replaces the short path hash, separating same-named files, supplementary characters and escape boundaries without retaining a name registry. Loading a second font no longer overwrites another asset's browser family. Internal family strings change; derive them through `familyNameFor` rather than persisting generated names. Asset references and runtime font handles keep their existing interface.+- **Missing-glyph warning history follows the bounded cache.** Diagnostic suppression retires when a family no longer has non-drawable glyphs in the 4096-entry CPU cache, preventing historical font names from accumulating. Cached-character queries keep their existing fast path, partial retirement and nested rasterization preserve reference counts, and cleanup releases the history. Unsupported-character warnings no longer claim the entire font cannot draw.- **Automation projection settings persist across editor state changes.** Programmatic perspective changes update the same state used by the editor toggle, so choosing a tool or changing display preferences no longer restores the previous projection. Repeating an unchanged setting avoids UI notifications while reapplying it to the engine; scene cameras remain unedited.diff --git a/sdk/src/ui/text/font-registry.ts b/sdk/src/ui/text/font-registry.tsindex 108cbce5f..7b4e4520d 100644--- a/sdk/src/ui/text/font-registry.ts+++ b/sdk/src/ui/text/font-registry.ts@@ -40,10 +40,14 @@ const byPath = new Map<string, number>();export function familyNameFor(path: string): string {const stem = (path.split('/').pop() ?? path).replace(/\.[^.]+$/, '');const safe = stem.replace(/[^A-Za-z0-9_-]+/g, '-').replace(/^-+|-+$/g, '') || 'font';- // The path suffix keeps two same-named fonts in different folders apart —- // a family name is a global key in every platform's text stack.- const tag = Math.abs([...path].reduce((h, c) => (h * 31 + c.charCodeAt(0)) | 0, 0)).toString(36);- return `es-${safe}-${tag}`;+ // ASCII uses two hex digits; other UTF-16 units use a distinct marker plus+ // four digits. The reversible suffix preserves paths without a shared registry.+ let tag = '';+ for (let i = 0; i < path.length; i++) {+ const code = path.charCodeAt(i);+ tag += code < 128 ? code.toString(16).padStart(2, '0') : `z${code.toString(16).padStart(4, '0')}`;+ }+ return `es-${safe}-${tag || '0'}`;}/**diff --git a/sdk/tests/font-registry.test.ts b/sdk/tests/font-registry.test.tsindex 00ae43344..d5775d58f 100644--- a/sdk/tests/font-registry.test.ts+++ b/sdk/tests/font-registry.test.ts@@ -13,6 +13,32 @@ import {beforeEach(() => resetProjectFonts());describe('familyNameFor', () => {+ it('keeps every UTF-16 unit distinct even under CSS case-insensitive matching', () => {+ const names = new Set<string>();+ for (let code = 0; code <= 0xffff; code++) {+ names.add(familyNameFor(`assets/${String.fromCharCode(code)}/Body.ttf`).toLowerCase());+ }+ expect(names.size).toBe(65536);+ });++ it.each([+ ['assets/Aa/Body.ttf', 'assets/BB/Body.ttf'],+ ['assets/🙂/Body.ttf', 'assets/🙃/Body.ttf'],+ ['assets/AA/Body.ttf', 'assets/B!/Body.ttf'],+ ])('separates colliding path identities %s and %s', (a, b) => {+ expect(familyNameFor(a)).not.toBe(familyNameFor(b));+ });++ it('preserves UTF-16 identity and ASCII escape boundaries without a registry', () => {+ const paths = ['', '\u0000', 'assets/z0080/Body.ttf', 'assets/\u0080/Body.ttf',+ `assets/${String.fromCharCode(0xd800)}/Body.ttf`, `assets/${String.fromCharCode(0xd801)}/Body.ttf`];+ const names = paths.map(familyNameFor);+ expect(new Set(names).size).toBe(paths.length);+ for (const name of names) expect(name).toMatch(/^es-[A-Za-z0-9_-]+$/);+ resetProjectFonts();+ expect(paths.map(familyNameFor)).toEqual(names);+ });+it('derives a CSS-safe family from the file stem', () => {expect(familyNameFor('assets/fonts/PassionOne-Regular.ttf')).toMatch(/^es-PassionOne-Regular-[0-9a-z]+$/);});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex abcaed944..13ec719a8 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(text): encode font paths without identity collisions':+ { note: 'Project font identities preserve complete asset paths.' },'fix(text): retire missing-glyph warnings with cached entries':{ note: 'Missing-glyph warning history follows the bounded cache.' },'test(editor): verify projection resets to 2D after gestures':