Native styled-text surface foundation
Status: internal F08 rendering/layout boundary now connected to schema-47 vertical writing, schema-46 public text paths and schema-45 character ranges, OO commands, Inspector selections, isolated native measurement, REST/recipe data, native persistence and visual SVG output. See CHARACTER_TEXT.md for the public contract. Supported inline styles now reimport through the private native reconstruction boundary described in SVG_CHARACTER_IMPORT.md. Richer SVG graphs, typography/shaping and sustained editor-wide performance remain unfinished. No new plugin permission, account or network operation is introduced.
src/engine/styled-text.ts prepares an immutable, owned ImageBitmap from explicitly positioned visual lines. Each line has an alphabetic baseline, physical alignment, paragraph direction and logical-order spans. Spans inherit a base character format and can override font family, size, color, weight/style, caps, stretch, kerning, spacing and declared variable axes. The input is an internal render DTO, not a public document mutation API.
Normalization snapshots values before asynchronous work, merges adjacent identical resolved formats, preserves Unicode and rejects boundaries splitting a surrogate pair. ASCII tab/CR/form-feed characters receive the existing Canvas space normalization. Callers supply explicit visual lines. Unsupported XML controls/unpaired surrogates reject explicitly instead of changing the stored source text. The existing 10,000 UTF-16-unit text budget covers the complete scene, including line separators. Original font sizes and image/document geometry have no new admission limit.
Width and height describe the caller's pixel work window. The six-value transform maps local text into that window. The preparer neither allocates a document-size image nor silently changes the requested bitmap size; callers remain responsible for viewport/tile allocation. Returned line advances and ink boxes use native SVG local coordinates, before the transform. SVG and Canvas advance APIs have different subpixel precision, including at real style boundaries. They must not be interchanged as exact layout measurements even when their raster pixels match. Native paragraph/layout integration must consume the same geometry as its renderer.
Preparation waits for the SVG image's actual load event before decode() and bitmap capture. In the tested Chromium host, decode() alone resolved before embedded fallback fonts finished loading: both the first canvas draw and direct bitmap capture produced entirely blank text. Waiting for load preserves the independently referenced fallback pixels without a timing delay, animation-frame dependency or extra raster surface. Abort and image-error paths release their listeners and reject; every exit clears the image source.
Native SVG shapes complete logical lines. The implementation never places isolated glyphs to emulate joining or scales a layer to emulate a font. Embedded font files supply whole selected render faces; originals remain owned by the existing font store. Primary axis tags/ranges validate against the first owned family in authored order, and the browser clamps supported fallback axes separately for each face. System fonts remain native to the current host. Installed web faces without a current owned source reject with an embedding instruction; the preparer cannot recover font bytes from a FontFace or substitute an unrelated fallback silently.
Preparation captures the asset-store lifetime, independent font leases and referenced native face state before yielding. Source loss, changed descriptors, cancellation, invalid native CSS, image decoding and bitmap creation failures reject without a returned surface. Every exit removes its private closed-shadow measurement probe and revokes its object URL. Success returns bitmap, readonly metrics, check() and idempotent release(). Callers must check before using the surface and release it afterward. Release closes the bitmap and ends its source leases; native collection still follows live model/history/view references. A captured surface can survive live model edits while its original source remains leased.
This requires a browser SVG/DOM host. Isolated scripts cannot invoke the renderer directly; their awaited public methods request finite native metrics through the private host broker. Final host commands remeasure independently. Omitted-range legacy text retains its Canvas path; headless REST retains explicit estimates and independent sessions. Source ownership and plugin isolation remain intact.
Shared source preparation (F08/F10 groundwork)
Private captureStyledTextPlan now owns normalized chunks, original font
capture, native line metrics and checked serialized markup before bitmap
creation. prepareStyledTextSurface consumes that owner and retains its
existing bitmap contract. The measurement DOM remains checked through native image/bitmap preparation
and retires at the existing raster publication boundary; font leases remain
owned through output checks/release. Optional
captureLinearPaint captures exact authored linear colors and native
addressable-character metadata without introducing spans or reading pixels.
The ordinary bitmap path skips that metadata work and its extra browser
capabilities. Native character indices/boxes are not glyph IDs or paint
primitives. Full float text painting remains gated and required; see
FLOAT_TEXT.md.
Native curve preparation (internal F08 dependency)
Explicit visual lines may carry a private path baseline with cubic points using the existing vector anchor form (x, y, in, out). closed and reverse default to false; signed startOffset and baselineOffset default to zero in local user units. The baseline is captured and deeply frozen before any await. Degenerate/nonfinite paths reject. A scene shares the existing 20,000-anchor vector editing budget across its baselines, independently of document/font dimensions and the caller's bitmap window.
Each baseline becomes a private local SVG fragment. textPath retains whole logical spans, native shaping, physical alignment/direction, exact native spacing and owned fonts. Reversing the curve swaps its cubic handles without reversing Unicode source. Closed reversal keeps the original seam. Start offset is native path distance; baseline offset uses native SVG dy. Each line's x/y translates its entire path, and the scene affine transform maps the result into the requested work window. No caller-supplied SVG, ID, URL or external path reference is accepted.
Metrics retain native advance, local ink including the line translation, and positive finite pathLength, before the scene transform. In the tested host, path-native advances differ from both nominal font units and ordinary straight SVG text measurement; later public reflow must measure the actual path, not substitute those other advances. Empty/overrunning text follows the native SVG renderer; logical source is not truncated or stretched to fit. Separate baselines have private fragment identities. Existing cancellation, font leases, readiness checks, temporary probes, image URLs and bitmap ownership apply through preparation and release.
This preparation DTO is internal, not an alternative public mutation API. Schema-46 TextPath/TextLayer integration now supplies shared commands, native frame origins, precision Inspector controls and persistence/SVG transport. Interactive canvas baseline handles, richer path flow and broader device/viewer/typography/performance acceptance remain required by the complete roadmap. Existing straight text retains its current contract.
Source-indexed paragraph preparation
engine/styled-text-layout.prepareStyledTextParagraph accepts unchanged text, ordered nonoverlapping UTF-16 ranges with character-format patches, a base style, paragraph properties and the same caller-selected pixel work window/transform. It returns the owned surface plus readonly layout frame dimensions and lines with original source bounds, physical alignment, common alphabetic baselines, native SVG advances and per-line heights. Line height uses the largest character size on that line and the paragraph line-height multiplier. Empty lines use the format at their source position. Paragraph spacing, first-line indent, direction, wrapping, forced breaks and inter-word justification use the shared line breaker. Original source and formats remain unchanged.
Source offsets accompany every whole-line measurement. Identical words at different source positions cannot share an advance when their formats differ. Consumed trailing spaces, discretionary hyphens and forced breaks preserve their source identity; a displayed discretionary hyphen takes the original soft hyphen's format. Point text treats Unicode line/paragraph separators as explicit lines. Native SVG and Canvas can choose slightly different wrapping boundaries because their advance precision differs; the new layout uses SVG consistently for measurement and raster output.
Justification adds a derived wordSpacingDelta to each span's authored spacing. Derived gaps may exceed the authoring field's range; they never become authored format values or trigger an arbitrary source-resolution restriction. Native baseline offsets come from matching whole-sample top/alphabetic Canvas measurements, with complete logical lines still shaped by SVG.
The shared breaker now drives synchronous layoutText and cooperative layoutTextAsync through the same measurement requests. The async path snapshots primitive inputs/options before awaiting, yields between bounded measurement batches and rejects cancellation/nonfinite results without publishing partial layout. The native paragraph host captures font ownership before any await, checks it through layout and bitmap publication, removes private measurement probes and transfers an independent lease to the returned surface. A removed probe rejects instead of supplying detached geometry. The private typography broker now exposes native metrics through existing script/plugin grants, without exposing this rendering boundary.
core/text-ranges provides immutable normalization, format overlay/clearing and text-replacement projections for shared commands. Ranges are ordered, nonempty, nonoverlapping and cannot split a surrogate pair. Gaps inherit the base format. Collapsed insertion defaults to the preceding character's format; selected replacement defaults to the first removed character's format. Explicit before/after affinity chooses either side of a boundary. These helpers do not mutate or publish a Document and are not an alternative public mutation API.
Verification and remaining gates are recorded in the dated implementation roadmap in the repository. Probes establish that inline TTF data fonts, including variable instances, can rasterize in this host without taint. The experimental HTML-in-Canvas API is not used. Relevant primary references: SVG text layout, SVG secure processing modes, and the HTML-in-Canvas proposal and availability. These sources describe platform contracts; acceptance is limited to the actual tested browser and fixtures.