Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
FC0a: ui/text/text passes (SSIM 0.9909): FontFeatures on a Text or a TextSpan (FontFeatureTag's OpenType tags, as CSS's font-feature-settings, which Blitz gives parley). The parity host has a default_font feature of its own, on, since Bevy's examples ask cfg(feature = "default_font") of the crate they're built in. FPS shows 60.00 (the host steps by 1/60 s); pixel probes of the animated text's colour and the FPS digits tell a doubled clock and 59.99 from the real port
shinyobjectz9027f9d1e513
diff --git a/bench/bevy-parity/Cargo.toml b/bench/bevy-parity/Cargo.tomlindex 648d3b71..f3808512 100644--- a/bench/bevy-parity/Cargo.toml+++ b/bench/bevy-parity/Cargo.toml@@ -20,3 +20,9 @@ chacha20 = { version = "0.10.0", default-features = false, features = ["rng"] }# used by the ported examples, which build.rs copies in through include! where cargo-shear doesn't look[package.metadata.cargo-shear]ignored = ["argh", "rand", "chacha20"]++# Bevy's examples ask cfg(feature = "default_font") of the crate they're built in: in Bevy's repo that's bevy's own+# feature, on by default; here the host's, so it has one, on (ui/text/text builds only its default-font branch)+[features]+default = ["default_font"]+default_font = []diff --git a/bench/bevy-parity/examples.list b/bench/bevy-parity/examples.listindex b2bfce94..e907fd3b 100644--- a/bench/bevy-parity/examples.list+++ b/bench/bevy-parity/examples.list@@ -80,3 +80,4 @@ ui/ui_scalingui/layout/anchor_layoutui/layout/size_constraintsui/scroll_and_overflow/overflow_transform+ui/text/textdiff --git a/bench/bevy-parity/runs.tsv b/bench/bevy-parity/runs.tsvindex 1e795b4d..edf31a3c 100644--- a/bench/bevy-parity/runs.tsv+++ b/bench/bevy-parity/runs.tsv@@ -79,3 +79,4 @@ ui/ui_scaling - 10ui/layout/anchor_layout - 10ui/layout/size_constraints - 10ui/scroll_and_overflow/overflow_transform - 10+ui/text/text - 10diff --git a/docs/bevy-parity.md b/docs/bevy-parity.mdindex 5b32612e..82946500 100644--- a/docs/bevy-parity.md+++ b/docs/bevy-parity.md@@ -4,7 +4,7 @@ Bevy v0.20.0's examples against their raea TSX ports (docs/control.feature FC0a)don't edit. An example passes when every probed frame passes pixels (SSIM 0.98 and no 32 px tile off by more than 24 of 255) and cost (batch keys andframe time at most 1.25x the example's). Wall time is one machine's, measured in the same run.-Examples: **438**, ported **80**, passing **76**, excluded **16** (docs/bevy-parity/excluded.tsv), left **346**.+Examples: **438**, ported **81**, passing **77**, excluded **16** (docs/bevy-parity/excluded.tsv), left **345**.raea's frame ms is its update's plus the time React takes to step a frame for its 3D (step), which the exampledoesn't pay.@@ -136,6 +136,7 @@ doesn't pay.| ui/layout/anchor_layout | 10 | 0.997421 | 9 | 0 / 0 | 468 / 492 | 5 / 7 | 1 / 1 | 33.145 / 1.417 = 1.417 + 0 | yes | || ui/layout/size_constraints | 10 | 0.991466 | 19 | 0 / 0 | 608 / 492 | 5 / 7 | 1 / 1 | 31.358 / 0.993 = 0.993 + 0 | yes | || ui/scroll_and_overflow/overflow_transform | 10 | 0.995397 | 12 | 0 / 0 | 447 / 492 | 5 / 7 | 1 / 1 | 41.134 / 1.724 = 1.724 + 0 | yes | |+| ui/text/text | 10 | 0.990913 | 8 | 0 / 0 | 459 / 492 | 5 / 7 | 1 / 1 | 34.947 / 1.446 = 1.446 + 0 | yes | |## Excludeddiff --git a/docs/bevy-parity/results.jsonl b/docs/bevy-parity/results.jsonlindex 83d3495d..3a3a8024 100644--- a/docs/bevy-parity/results.jsonl+++ b/docs/bevy-parity/results.jsonl@@ -123,3 +123,4 @@{"example":"ui/layout/anchor_layout","frame":10,"ssim":0.997421,"tile":9,"bevy":{"batch_keys":0,"entities":468,"extents":[],"frame":10,"frame_ms":33.145,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.417,"step_ms":null,"cost_ms":1.417},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"ui/layout/size_constraints","frame":10,"ssim":0.991466,"tile":19,"bevy":{"batch_keys":0,"entities":608,"extents":[],"frame":10,"frame_ms":31.358,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":0.993,"step_ms":null,"cost_ms":0.993},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"ui/scroll_and_overflow/overflow_transform","frame":10,"ssim":0.995397,"tile":12,"bevy":{"batch_keys":0,"entities":447,"extents":[],"frame":10,"frame_ms":41.134,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.724,"step_ms":null,"cost_ms":1.724},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"ui/text/text","frame":10,"ssim":0.990913,"tile":8,"bevy":{"batch_keys":0,"entities":459,"extents":[],"frame":10,"frame_ms":34.947,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.446,"step_ms":null,"cost_ms":1.446},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}diff --git a/sdk/raea/bench/bevy-parity/ui/text/text.tsx b/sdk/raea/bench/bevy-parity/ui/text/text.tsxnew file mode 100644index 00000000..f63eeda7--- /dev/null+++ b/sdk/raea/bench/bevy-parity/ui/text/text.tsx@@ -0,0 +1,57 @@+// Bevy v0.20.0 examples/ui/text/text.rs in raea's TSX: "hello\nbevy!" underlined, centred, in FiraSans-Bold at 20vh+// with the default TextShadow, 5 px in from the bottom right, its colour a sine of Bevy's elapsed time per channel;+// "FPS: " (42 px FiraSans-Bold) with the smoothed frame rate in a 33 px gold FiraMono-Medium span; at the top right+// (5 px in, a 12 px margin) "Opentype features:" in 32 px EB Garamond and seven 24 px rows, each a title and a sample+// with one OpenType feature on (small caps, ligatures, fractions, superscript, subscript, oldstyle and lining figures);+// and the default font's sentence at the bottom left. The parity host steps Bevy by 1/60 s, so the smoothed rate is+// 60.00 (FPS below). Bevy's Camera2d over the default clear colour is the layered <Canvas3D>. In Bevy's+// default 1280 x 720 window.+import { AbsoluteFill, Composition, registerRoot, staticFile, useCurrentFrame } from "raea";+import { Canvas3D } from "raea/3d";+import { FontFeatureTag, Node, Text, TextShadow, TextSpan, UiRect, px } from "raea/ui";+import { Srgba } from "raea/color";++const FIRA_BOLD = staticFile("fonts/FiraSans-Bold.ttf");+const GARAMOND = staticFile("fonts/EBGaramond12-Regular.otf");+// FrameTimeDiagnosticsPlugin's smoothed rate over 1/60 s steps+const FPS = "60.00";+const ROWS: [string, string, string][] = [+ ["Smallcaps: ", FontFeatureTag.SMALL_CAPS, "Hello World"],+ ["Ligatures: ", FontFeatureTag.STANDARD_LIGATURES, "fi fl ff ffi ffl"],+ ["Fractions: ", FontFeatureTag.FRACTIONS, "12/134"],+ ["Superscript: ", FontFeatureTag.SUPERSCRIPT, "Up here!"],+ ["Subscript: ", FontFeatureTag.SUBSCRIPT, "Down here!"],+ ["Oldstyle figures: ", FontFeatureTag.OLDSTYLE_FIGURES, "1234567890"],+ ["Lining figures: ", FontFeatureTag.LINING_FIGURES, "1234567890"],+];++// Time::elapsed_secs at frame f: f steps of 1/60 s, summed in f32+function elapsedAt(f: number): number {+ let t = 0;+ for (let k = 1; k <= f; k++) t = Math.fround(t + Math.fround(16_666_667e-9));+ return t;+}++function Shot() {+ const t = elapsedAt(useCurrentFrame());+ const wave = (k: number) => Math.sin(k * t) / 2 + 0.5;+ return (+ <AbsoluteFill>+ <Canvas3D layered clearColor="rgb(43, 44, 47)" />+ <Text underline font={FIRA_BOLD} font_size={{ Vh: 20 }} shadow={TextShadow.default()} justify="Center" color={new Srgba(wave(1.25), wave(0.75), wave(0.5))} position_type="Absolute" bottom={px(5)} right={px(5)}>{"hello\nbevy!"}</Text>+ <Text font={FIRA_BOLD} font_size={{ Px: 42 }}>+ FPS: <TextSpan font={staticFile("fonts/FiraMono-Medium.ttf")} font_size={{ Px: 33 }} color={new Srgba(1, 215 / 255, 0)}>{FPS}</TextSpan>+ </Text>+ <Text margin={UiRect.all(px(12))} position_type="Absolute" top={px(5)} right={px(5)} font={GARAMOND} font_size={{ Px: 32 }}>+ {"Opentype features:\n"}+ {ROWS.flatMap(([title, feature, sample]) => [+ <TextSpan key={`${title}t`} font={GARAMOND} font_size={{ Px: 24 }}>{title}</TextSpan>,+ <TextSpan key={`${title}s`} font={GARAMOND} font_size={{ Px: 24 }} font_features={{ [feature]: 1 }}>{`${sample}\n`}</TextSpan>,+ ])}+ </Text>+ <Text position_type="Absolute" bottom={px(5)} left={px(15)}>From an &str into a Text with the default font!</Text>+ </AbsoluteFill>+ );+}++registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);diff --git a/sdk/raea/conformance/ui.test.tsx b/sdk/raea/conformance/ui.test.tsxindex 6b965eb4..9e92662e 100644--- a/sdk/raea/conformance/ui.test.tsx+++ b/sdk/raea/conformance/ui.test.tsx@@ -1,7 +1,7 @@// docs/control.feature FC0a: bevy_ui's Node, Text and TextSpan on the page, with Bevy's defaults, values and blend// (ui/styling/transparency_ui, ui/layout/fixed_node).import { describe, expect, test } from "bun:test";-import { AngularColorStop, GhostNode, Viewport, UiTargetCamera, UiRect as GradRect, FontSource, GridPlacement, GridTrack, RepeatedGridTrack, ColorStop, ConicGradient, LinearGradient, RadialGradient, UiPosition, BorderRadius, CornerRadius, FontVariationTag, ImageNode, InlineImage, ImagePlugin, Node, TextureAtlasLayout, Overflow, OverflowClipMargin, Text, TextShadow, Text2d, UiScale, TextSpan, UiRect, auto, percent, px, vw } from "raea/ui";+import { AngularColorStop, FontFeatureTag, GhostNode, Viewport, UiTargetCamera, UiRect as GradRect, FontSource, GridPlacement, GridTrack, RepeatedGridTrack, ColorStop, ConicGradient, LinearGradient, RadialGradient, UiPosition, BorderRadius, CornerRadius, FontVariationTag, ImageNode, InlineImage, ImagePlugin, Node, TextureAtlasLayout, Overflow, OverflowClipMargin, Text, TextShadow, Text2d, UiScale, TextSpan, UiRect, auto, percent, px, vw } from "raea/ui";import { LinearRgba, Srgba } from "raea/color";import { Canvas3D } from "raea/3d";import { renderFrame } from "../src/test";@@ -122,6 +122,13 @@ describe("ImageNode, Underline and Strikethrough", () => {expect(() => html(<Text font_variations={{ wg: 300 }}>a</Text>)).toThrow(/four characters/);expect(() => html(<Text font_variations={{ wght: NaN }}>a</Text>)).toThrow(/is a number/);});+ test("FontFeatures turn OpenType features on by tag, on a Text or a TextSpan; a bad tag or value is refused", () => {+ expect(html(<Text font_features={{ [FontFeatureTag.SMALL_CAPS]: 1, [FontFeatureTag.FRACTIONS]: 1 }}>a</Text>)).toContain("font-feature-settings:"smcp" 1, "frac" 1");+ expect(html(<Text>a<TextSpan font_features={{ [FontFeatureTag.OLDSTYLE_FIGURES]: 1 }}>1</TextSpan></Text>)).toMatch(/<span style="[^"]*font-feature-settings:"onum" 1[^"]*">1<\/span>/);+ expect(html(<Text>a</Text>)).not.toContain("font-feature-settings");+ expect(() => html(<Text font_features={{ sc: 1 }}>a</Text>)).toThrow(/four characters/);+ expect(() => html(<Text font_features={{ smcp: 0.5 }}>a</Text>)).toThrow(/whole number/);+ });test("a TextSpan's TextBackgroundColor is a box behind its run, in its own colour", () => {expect(html(<Text><TextSpan text_background_color={new Srgba(1, 0, 0)}>a</TextSpan></Text>)).toMatch(/<span style="[^"]*background-color:rgba\(255, 0, 0, 1\)[^"]*">a<\/span>/);expect(html(<Text><TextSpan>a</TextSpan></Text>)).not.toContain("background-color");diff --git a/sdk/raea/src/ui.ts b/sdk/raea/src/ui.tsindex 44338061..a3d28304 100644--- a/sdk/raea/src/ui.ts+++ b/sdk/raea/src/ui.ts@@ -10,3 +10,4 @@ export { Node, GhostNode, Text, TextSpan, TextShadow, Text2d, UiScale, Viewport,export { LinearGradient, RadialGradient, ConicGradient, ColorStop, AngularColorStop, UiPosition, type Gradient, type RadialGradientShape, type InterpolationColorSpace } from "@raea/render/bevy3d";export { GridTrack, RepeatedGridTrack, GridPlacement, type GridTrackRepetition, type GridAutoFlow, type MinTrackSizingFunction, type MaxTrackSizingFunction, FontSource, type GenericFontFamily } from "@raea/render/bevy3d";export { Rot2, Val2, UiTransform, BoxShadow, type ShadowStyle } from "@raea/render/bevy3d";+export { FontFeatureTag } from "@raea/render/bevy3d";diff --git a/sdk/render/src/bevy3d.tsx b/sdk/render/src/bevy3d.tsxindex ce0b1cd3..44ed90ed 100644--- a/sdk/render/src/bevy3d.tsx+++ b/sdk/render/src/bevy3d.tsx@@ -34,4 +34,5 @@ export { px, percent, vw, vh, vmin, vmax, auto, UiRect, BorderRadius, CornerRadiexport { LinearGradient, RadialGradient, ConicGradient, ColorStop, AngularColorStop, UiPosition, type Gradient, type RadialGradientShape, type InterpolationColorSpace } from "./bevy3d/ui-gradient";export { GridTrack, RepeatedGridTrack, GridPlacement, type GridTrackRepetition, type GridAutoFlow, type MinTrackSizingFunction, type MaxTrackSizingFunction } from "./bevy3d/ui-grid";export { Rot2, Val2, UiTransform, BoxShadow, type ShadowStyle } from "./bevy3d/ui-transform";+export { FontFeatureTag } from "./bevy3d/ui-features";export { FontSource, type GenericFontFamily } from "./bevy3d/ui-font";diff --git a/sdk/render/src/bevy3d/ui-features.ts b/sdk/render/src/bevy3d/ui-features.tsnew file mode 100644index 00000000..c95e313f--- /dev/null+++ b/sdk/render/src/bevy3d/ui-features.ts@@ -0,0 +1,23 @@+// bevy_text's FontFeatures (OpenType features by their four-letter tag, each on with 1 or a variant's index) as CSS's+// font-feature-settings, which Blitz gives parley as bevy_text gives it.++/** bevy_text's FontFeatureTag: the registered OpenType features' tags. @bevy bevy_text::FontFeatureTag */+export const FontFeatureTag = {+ STANDARD_LIGATURES: "liga", CONTEXTUAL_LIGATURES: "clig", DISCRETIONARY_LIGATURES: "dlig", CONTEXTUAL_ALTERNATES: "calt",+ STYLISTIC_ALTERNATES: "salt", SMALL_CAPS: "smcp", CAPS_TO_SMALL_CAPS: "c2sc", SWASH: "swsh", TITLING_ALTERNATES: "titl",+ FRACTIONS: "frac", ORDINALS: "ordn", SLASHED_ZERO: "zero", SUPERSCRIPT: "sups", SUBSCRIPT: "subs",+ OLDSTYLE_FIGURES: "onum", LINING_FIGURES: "lnum", PROPORTIONAL_FIGURES: "pnum", TABULAR_FIGURES: "tnum",+ WEIGHT: "wght", WIDTH: "wdth", SLANT: "slnt",+} as const;++/** FontFeatures as CSS's font-feature-settings, or undefined when it has none. */+export function featuresCss(who: string, f: Record<string, number> | undefined): string | undefined {+ if (f === undefined) return undefined;+ if (!f || typeof f !== "object") throw new TypeError(`${who}: font_features is { [FontFeatureTag.SMALL_CAPS]: 1 }, got ${JSON.stringify(f)}`);+ const all = Object.entries(f).map(([tag, n]) => {+ if (!/^[\x20-\x7e]{4}$/.test(tag)) throw new TypeError(`${who}: a font feature's tag is four characters ("smcp"), got ${JSON.stringify(tag)}`);+ if (!Number.isInteger(n) || n < 0) throw new TypeError(`${who}: font feature ${tag} is a whole number at least 0 (1 is on), got ${n}`);+ return `"${tag}" ${n}`;+ });+ return all.length ? all.join(", ") : undefined;+}diff --git a/sdk/render/src/bevy3d/ui.tsx b/sdk/render/src/bevy3d/ui.tsxindex 0715c3f9..8a453562 100644--- a/sdk/render/src/bevy3d/ui.tsx+++ b/sdk/render/src/bevy3d/ui.tsx@@ -13,6 +13,7 @@ import { LinearRgba, type Srgba } from "./colors";import { gradientsCss, gradientsOpaque, type Gradient } from "./ui-gradient";import { gridCss, type GridAutoFlow, type GridPlacement, type GridTrack, type RepeatedGridTrack } from "./ui-grid";import { shadowCss, transformCss, type BoxShadow, type UiTransform } from "./ui-transform";+import { featuresCss } from "./ui-features";import type { TransformValue } from "./core";import { eulerOf } from "../3d/model";import { useVideoConfig } from "@raea/app/clock";@@ -219,6 +220,8 @@ export interface TextStyleProps {line_height?: { Px: number } | { RelativeToFont: number };/** FontVariations: a variable font's axes by their four-letter tag, { [FontVariationTag.WEIGHT]: 300 } */font_variations?: Record<string, number>;+ /** FontFeatures: OpenType features by their four-letter tag, 1 to turn one on, { [FontFeatureTag.SMALL_CAPS]: 1 } */+ font_features?: Record<string, number>;/** LetterSpacing: { Px } or { Rem } (of bevy_text's 20 px rem) after every glyph (none by default) */letter_spacing?: { Px: number } | { Rem: number };}@@ -314,6 +317,8 @@ export function textCss(who: string, p: TextStyleProps, back?: Backdrop): { css:};const variations = variationsCss(who, p.font_variations);if (variations) css.fontVariationSettings = variations;+ const features = featuresCss(who, p.font_features);+ if (features) css.fontFeatureSettings = features;const ls = p.letter_spacing;if (ls !== undefined) {const [k, v] = Object.entries(ls)[0] ?? [];@@ -332,10 +337,10 @@ const BREAK: Record<NonNullable<TextProps["linebreak"]>, CSSProperties> = {/** Bevy's UI text: a Node whose content is its string and its <TextSpan> children, in its TextFont, TextColor,* TextLayout and LineHeight (Bevy's defaults when left out). @bevy bevy_ui::widget::text::Text */-export function Text({ children, font, font_size, weight, style, color, line_height, font_variations, letter_spacing, justify, linebreak, shadow, underline, strikethrough, underline_color, strikethrough_color, text_background_color, ...node }: TextProps) {+export function Text({ children, font, font_size, weight, style, color, line_height, font_variations, font_features, letter_spacing, justify, linebreak, shadow, underline, strikethrough, underline_color, strikethrough_color, text_background_color, ...node }: TextProps) {const ui = useContext(InUi);const n = nodeCss("Text", node, ui?.back);- const t = textCss("Text", { font, font_size, weight, style, color, line_height, font_variations, letter_spacing }, n.back);+ const t = textCss("Text", { font, font_size, weight, style, color, line_height, font_variations, font_features, letter_spacing }, n.back);if (justify !== undefined && !["Left", "Center", "Right", "Justified", "Start", "End"].includes(justify)) throw new TypeError(`Text: justify is Left, Center, Right, Justified, Start or End, got ${JSON.stringify(justify)}`);if (linebreak !== undefined && !(linebreak in BREAK)) throw new TypeError(`Text: linebreak is WordBoundary, AnyCharacter, WordOrCharacter or NoWrap, got ${JSON.stringify(linebreak)}`);const textAlign = { Left: "left", Center: "center", Right: "right", Justified: "justify", Start: "start", End: "end" }[justify ?? "Left"] as CSSProperties["textAlign"];