Skip to content

Canvas2D Unicode Browser Labels

easylogic edited this page Oct 10, 2026 · 2 revisions

Canvas2D: bounded single-line Unicode browser labels

User outcome and status

Prepare readable Hangul/CJK and mixed-language diagram labels through the public Canvas2D browser helper. Existing browser-text.ts admits only alphanumeric/printable ASCII; multiline and wrapping are also ASCII. Existing #1011/#1024/#1170/#1186/#1192/#1199 retain their completed original contracts. A fresh all-state Unicode/CJK/international label audit found no matching executable leaf.

Planned new capability, tracked by #1355, parent #664/#660. Canvas selects ready order. Preserve completed native #1335/#1336/#1346/#1347 and their exact evidence; this feature does not depend on their adoption.

Real providers and proposed API

Extend BrowserTextPolicy with an explicit opt-in unicode-single-line policy on existing rasterizeBrowserText. Keep defaults and both old policies unchanged. Reuse the actual native-browser measureText/fillText, copied RGBA asset, Unicode-capable GlyphRun semantic text and Scene29/document-v1. No scene/schema/tree/renderer change, new shaping kernel, font service or download is needed.

Exact name, parent, paths, errors and one flow are frozen by Canvas before code. Proposed ownership: packages/barocss-canvas2d/src/browser-text.ts, narrow public type/docs, and one existing browser-text host plus bounded typed/example/evidence files. Primary combines exports/docs and owns build/receipt; helpers own disjoint library, host and actual-flow files. Integration remains sole serial product/shared/root/lock writer.

Admission and preservation

  • 1..128 ORIGINAL UTF-16 code units, well-formed surrogate pairs, at least one non-whitespace scalar. Refuse unpaired surrogates, C0/C1 controls and U+2028/U+2029; single-line input does not become a multiline/wrapped request.
  • Preserve original code units and scalar-boundary range [0,text.length). No NFC/NFKC rewrite, trimming, case conversion or per-character surrogate slicing.
  • Preserve font declaration length<=256, DPR1..4, finite measured coordinates<=1e6, existing2pixel padding, backing<=1024×256 and1MiB, existing typed own-data/error/refusal semantics and scratch cleanup on success/failure.
  • Host supplies a prepared local system/generic CSS font. Helper remains synchronous. No remote font loading, downloaded files, font registration, async font service or matched-face identity promise.
  • Existing fixed left/alphabetic/LTR paragraph setup and whole-label bitmap layout remain explicit. Browser shaping and fallback are platform behavior; this increment does not implement grapheme editing, IME, bidi controls, complex-script typography, emoji/color-font fidelity or cross-device equality.

Native browser guarantees and actual limits

The HTML Canvas text preparation/drawing algorithm uses the supplied font, direction/alignment/baseline and platform glyph shapes: HTML Standard. Font readiness and actual glyph coverage are different. FontFaceSet.check concerns loaded font availability and later font swapping; it is not a matched typeface/glyph coverage certificate: CSS Font Loading Level3, CSS Fonts fallback.

MeasureText or nonzero alpha alone does not demonstrate a readable intended character. The meaningful actual flow must inspect readable Hangul/CJK output on the named browser/system-font profile and retain the screenshot/metrics. Do not promote that fixture to global font support.

File and editing contract

Existing Scene29/document-v1 stores original semantic text, glyph layout and actual copied atlas bytes. Save those complete accepted values. Fresh Open restores bytes without rerasterization/font loading or inferring the original font/DPR/policy. A later text edit explicitly selects the current host policy/font. Do not claim font declaration or policy is restored when the file does not contain it.

A rejected request keeps prior accepted tree/asset bytes/frame and corrective text draft. One whole-label GlyphRun remains a single selectable node with original range/identity; glyph/transparent-space hit behavior uses existing scene semantics.

One observable completion flow

One affected library build and one actual existing-host flow: prepare 설계 圖面 A1 with opt-in policy and a prepared system font; inspect readable labels/baseline and original text, glyph hits and transparent-space behavior; edit to a second mixed label; refuse malformed surrogate/newline/oversize input with accepted retention. Save once, separate real chooser/Open once into a fresh tree/renderer, compare complete original text/layout/asset bytes without rerasterization; restored edit and owned disposal/listener/scratch cleanup. Include a small ordinary ASCII control to preserve existing default policy, not a repeated whole legacy campaign.

Record actual browser/platform/font declaration, source/native SHA, first failures and affected emitted JS/types/source alignment. Native completion, exact integration and current-root #1254/#674 remain separate. Broad font/device/performance/packed/old-reader/gallery campaigns stay deferred. No new Work, external fonts, publication or schedule change.

Clone this wiki locally