Framework

Spatial text

bedform/Spatial/Text supplies an explicitly selected, text-only surface for Spatial.Renderer. Importing it creates no primitives, timers or subscriptions. Compose its Commit, Update and Dispose methods with another surface when a root also needs non-text visuals.

import { TextPrimitive, system, world } from "@minecraft/server";
import * as Renderer from "bedform/Spatial/Renderer";
import * as Text from "bedform/Spatial/Text";
import type { Dimension, DimensionLocation } from "@minecraft/server";

const Surface = Text.CreateSurface({
    Dimension: id => world.getDimension(id),
    CreateText: (location, value) =>
        new TextPrimitive(location as DimensionLocation, value) as unknown as Text.Primitive,
    AddText: (primitive, dimension) => world.primitiveShapesManager.addText(
        primitive as unknown as TextPrimitive, dimension as Dimension)
});
const Runtime = Renderer.Start({
    World: world, System: system, Native: { TextPrimitive }, Surface
});
// CreateRoot and Render use the ordinary spatial React components.
// Await Runtime.Dispose() to release every private presentation.

The experimental native ABI is injected explicitly. Each audience lease registers its own primitives, with visibleTo configured before addText. Every location includes its dimension. Each outer Text's committed visual line gets one fixed-rotation primitive; inline Text nodes contribute color runs to those lines. Depth testing is enabled, both backface flags are disabled, and backgrounds are transparent. The primitive uses the committed paint depth along the View's +Z normal, including separation for overlapping equal-layer items. Yaw is +F normalized to (-180, 180], where F is the direction from the readable side toward the View. The spatial orientation still needs real-client verification.

Layout and presentation share the encoded lines, wrapping and measured anchors. Line starts compensate for whole-pixel client rounding. TextAlign moves the anchor for start, center and end alignment. Each visual line gets its own native anchor, with the font-switch advance accounted for in the position. The renderer transmits the encoded label without adding trailing padding glyphs. For Mojangles, the native anchor is half a layout pixel below the line top. For Legacy, it is 2.5 layout pixels below the line top. These offsets compensate for the ink appearing below the native anchor and use each visual line's resolved font, including Unicode fallback lines. BlocksPerLargePixel is approximately 0.0266, estimated from the Windows client by comparing stock large and fine lines with Canvas rulers. Native scale derives from this value and the View's pixels-per-block setting.

Set Font with the frozen TextFont record from bedform/Spatial/Components or bedform/Spatial/Text. Nested Text inherits Font, Fallback and FallbackScope. It may repeat the inherited values and set its own Color.

  • TextFont.Mojangles selects the fine Unicode font and is the default outside Button and TabButton. Lines with large-font characters and no stock fine-font trigger get a blank U+2065 at both ends. These cells select the fine font while balancing their advances around the line's center. Canvas private-use glyphs alone did not switch fonts in WidgetDemo.
  • TextFont.Legacy uses the classic, larger-pixel Mojangles font wherever possible. It is the default for Text labels inside Button and TabButton. Set Font={TextFont.Mojangles} on a label to select the fine font. The default Fallback="Mojangles" switches affected visual lines. Set FallbackScope="Text" to switch every line when any character is unsupported.
  • TextFont.Ten maps printable ASCII through Canvas's packed U+E922–U+E966 catalogue and maps lowercase to the corresponding capitals. The default Mojangles fallback keeps unsupported characters inline and uses fine-font advances for them. Ten uses 16-pixel cell pitch plus LineGap, with up to 42 characters per line. Its rounded anchor uses the measured advance. Ten strips color codes and reports explicit Color values.

Legacy and Ten also accept Fallback="Omit", Fallback={{ Replace: "?" }}, a callback, and Fallback="Error". Fixed replacements must be supported by the selected font. A callback receives the unsupported character, its zero-based UTF-16 index within the original source line, and the complete source line. Unsupported characters in its result are omitted. The runtime sends omissions, replacements and ignored colors to OnError with phase "diagnostic" and identifies the originating widget View and Text. The "Error" policy reaches the nearest React error boundary through the render guard.

The Ten stand-ins and custom PUA advances come from the authoritative Canvas catalogue. Using this surface marks a surviving bundle as requiring the shared Canvas packs. ToLegacyGlyphs from bedform/Spatial/Text opts into Canvas stand-ins for Symbols for Legacy Computing. PUA font ink is baked dark gray. Canvas's white glyph particle textures accept arbitrary RGB/RGBA tints.

The outer Text's native color can be arbitrary RGB/RGBA. Each React root starts with the dark theme. ThemeProvider accepts "light", "dark" or the corresponding resolved value from bedform/Spatial/ThemeMode. An explicit selection starts from that palette. Omit theme to inherit the enclosing tokens, and pass Tokens to override specific colors or spacing for that subtree. These updates preserve descendant state. Both stock foregrounds use #4D4D4D, including §r resets. An explicit Text Color takes precedence over the foreground token. Nested Text colors use the nearest Bedrock § palette color and must share the outer alpha. Canvas font glyphs retain their baked #4D4D4D ink under all provider palettes and Text Color values. Use Canvas glyph particles for arbitrary RGB/RGBA glyph tint, including partial opacity. CreateSurface can resolve an outer color per viewer on each update. Returning undefined restores the committed color and retains the native line handle. Default Callout headings, ItemStack quantities above one, and Canvas PUA characters in Text use the same line renderer. A count sits at the bottom-right of the stack's content box and is clipped to that box and its ScrollView. Callout headings default to the kind's accent and callout body Text to the theme's callout foreground (#4D4D4D light, #E0E0E0 dark). Baked glyph-page ink stays dark gray, so PUA glyphs read poorly on dark callouts.

Color codes and §r have no width. Unknown codes and U+0000 are rejected during layout, before presentation. §k, §l and §o require an explicit Measure override accepting responsibility for their widths. Measure receives substituted content and the selected font. The renderer removes color codes and the internal switch before measuring and preserves width-changing codes. Byte wrapping counts the final transmitted codes and switch, including continued color state, against 128 UTF-8 bytes. Wrapping preserves Unicode code points and explicit empty lines. Right-to-left text draws in stored order; the renderer performs no bidirectional reordering.

TextPrimitive exposes no rectangular scissor. A ScrollView line intersecting an edge is omitted in full, including from text hit-testing; it becomes visible again when scrolling admits the complete line. This is conservative line clipping, rather than native partial-glyph clipping. Other controls retain their own policy and pointer admission rules.

Unchanged content causes no setText calls. Static placement gets one resend five native ticks later; a content change cancels that resend. Removed/hidden/clipped lines release their handles, and the enclosing renderer owns rollback and cleanup if native allocation or configuration fails.

Test/SpatialText.test.mts covers encoding, final byte budgets, alignment, private registration, updates/resends, clipping, yaw, themes and root isolation. The installed consumer qualification imports the public subpath in both JSX modes. Addon/BedformCanvas/Test/Native/Text.mts exercises actual native constructor, registration, flags, rotation and depth, arbitrary RGB, audience, byte-wrapped writes, resend and removal through the fixed-path Canvas BDS runner. It also passes default and explicit glyph particle tints through a native MolangVariableMap to a private particle spawn. Native results do not establish client appearance, font-switch invisibility, alpha, PUA tint fidelity, clipping appearance or pixel-to-block calibration.

Recorded server evidence is in spatial-text-native.results.json, using BDS 1.26.63.1 build 53340801. Explicit alpha was retained by the native API; its appearance still requires a client check.

For isolated text qualification, run node --import tsx Addon/BedformCanvas/Tool/Native.mts --text-only from the root. This skips the independent widget-actor probe while retaining Canvas's common lifetime/restart checks. Results mark SpatialTextAcceptance separately and do not claim full Canvas native acceptance when that option is selected.