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(ui): preserve rich text shadow and outline colors
yhh16a39e8f1f0d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f1475836f..ac8d97ef2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Rich-text colors no longer recolor shadows and outlines.** Effect passes use their authored color and alpha on both bitmap and SDF atlases, including blurred shadows. The fill retains per-run colors, and inherited UI opacity continues to fade every pass.+- **UI text effects follow inherited opacity.** Parent transparency now fades text shadows, outlines and explicit rich-text colors together with the fill. Opacity changes invalidate cached batches, and fully transparent subtrees skip glyph layout and submission until they become visible again.- **Release websites wait for mirrored download metadata.** Documentation deployment starts after the release mirror completes and rejects a latest.json version that differs from the site build, preventing a freshly published page from reverting its version label and download sizes to the previous release.diff --git a/sdk/src/ui/text/layout.ts b/sdk/src/ui/text/layout.tsindex 7c14df889..aa70a97cc 100644--- a/sdk/src/ui/text/layout.ts+++ b/sdk/src/ui/text/layout.ts@@ -103,11 +103,9 @@ export interface GlyphVertexData {}/**- * Build interleaved vertices (x,y,u,v,r,g,b,a) + indices for a set of laid-out- * glyphs (typically the subset that shares one atlas page).- * Atlas v0 (top) maps to the screen-top corner, v1 (bottom) to screen-bottom,- * so the quad samples the glyph upright. `originX/Y` offsets all glyphs (e.g. to- * place the text by its UINode-resolved box origin).+ * Build interleaved glyph vertices and indices, with atlas v0 at screen-top.+ * `originX/Y` positions the batch inside its text box. Disable per-glyph colors+ * when recoloring shadow and outline passes.*/export function buildGlyphVertices(glyphs: readonly LaidGlyph[],@@ -115,6 +113,7 @@ export function buildGlyphVertices(originX = 0,originY = 0,sdfBias = 0,+ useGlyphColors = true,): GlyphVertexData {const n = glyphs.length;const vertices = new Float32Array(n * 4 * TEXT_VERTEX_FLOATS);@@ -122,7 +121,7 @@ export function buildGlyphVertices(for (let i = 0; i < n; i++) {const gl = glyphs[i];- const [r, g, b, a] = gl.color ?? color; // per-glyph color (rich text) falls back to the batch color+ const [r, g, b, a] = (useGlyphColors ? gl.color : undefined) ?? color;const x0 = gl.x0 + originX, x1 = gl.x1 + originX;const y0 = gl.y0 + originY, y1 = gl.y1 + originY;const vo = i * 4 * TEXT_VERTEX_FLOATS;diff --git a/sdk/src/ui/text/text-renderer.ts b/sdk/src/ui/text/text-renderer.tsindex bd7533b27..0ea9e2870 100644--- a/sdk/src/ui/text/text-renderer.ts+++ b/sdk/src/ui/text/text-renderer.ts@@ -213,9 +213,9 @@ export function drawTextWith(atlas: GlyphAtlas, sink: GlyphBatchSink, p: DrawTex// Emit the glyph set once per page, recolored + offset. All passes are SDF// glyphs in the same atlas/layer, so they batch and draw in submit order —// shadow + outline first (behind), fill last (on top).- const emitPass = (color: RGBA, dx: number, dy: number, bias = 0): void => {+ const emitPass = (color: RGBA, dx: number, dy: number, bias = 0, useGlyphColors = false): void => {for (const [pageId, glyphs] of byPage) {- const { vertices, indices } = buildGlyphVertices(glyphs, color, baseX + dx, originY + dy, bias);+ const { vertices, indices } = buildGlyphVertices(glyphs, color, baseX + dx, originY + dy, bias, useGlyphColors);if (opacity !== 1) {for (let i = 7; i < vertices.length; i += TEXT_VERTEX_FLOATS) vertices[i] *= opacity;}@@ -249,7 +249,7 @@ export function drawTextWith(atlas: GlyphAtlas, sink: GlyphBatchSink, p: DrawTexelse for (const [ox, oy] of OUTLINE_OFFSETS) emitPass(p.outline.color, ox * w, oy * w);}// Fill (on top).- emitPass(p.color, 0, 0);+ emitPass(p.color, 0, 0, 0, true);}export interface TextRendererOptions extends CanvasGlyphRasterizerOptions {diff --git a/sdk/tests/ui-text-renderer.test.ts b/sdk/tests/ui-text-renderer.test.tsindex 1caaccd17..87c29be7b 100644--- a/sdk/tests/ui-text-renderer.test.ts+++ b/sdk/tests/ui-text-renderer.test.ts@@ -14,10 +14,10 @@ import {import { drawTextWith, signatureOf, tapAlpha } from '../src/ui/text/text-renderer';import type { DrawTextParams } from '../src/ui/text/text-renderer';-function makeAtlas(pageSize: number): GlyphAtlas {+function makeAtlas(pageSize: number, spread = 6): GlyphAtlas {const rasterizer: GlyphRasterizer = {renderSize: 48,- spread: 6,+ spread,rasterize: (cp: number): RasterGlyph | null => {if (cp === 32) return { pixels: new Uint8Array(0), width: 0, height: 0, advance: 12, bearingX: 0, bearingY: 0 };return { pixels: new Uint8Array(10 * 12 * 4), width: 10, height: 12, advance: 11, bearingX: 1, bearingY: 10 };@@ -29,6 +29,37 @@ function makeAtlas(pageSize: number): GlyphAtlas {}describe('REARCH_GUI P1.3b: drawTextWith', () => {+ it('keeps rich fill colors out of shadow and outline passes on both atlas modes', () => {+ for (const spread of [0, 6]) {+ for (const blur of [0, 2]) {+ const sink = vi.fn();+ drawTextWith(makeAtlas(1024, spread), sink, {+ text: '<color=#ff000080>A</color>B', richText: true,+ fontFamily: 'Arial', fontSizePx: 24, color: [1, 1, 1, 1], opacity: 0.5,+ shadow: { color: [0, 0, 0, 0.6], dx: 2, dy: 2, blur },+ outline: { color: [0, 1, 0, 0.4], width: 1 },+ });+ const shadows = blur > 0 ? 9 : 1;+ const outlines = spread > 0 ? 1 : 8;+ expect(sink).toHaveBeenCalledTimes(shadows + outlines + 1);+ for (let batch = 0; batch < shadows + outlines; ++batch) {+ const vertices = sink.mock.calls[batch][0] as Float32Array;+ const shadow = batch < shadows;+ const alpha = shadow ? tapAlpha(0.6, shadows) * 0.5 : 0.2;+ for (let i = 4; i < vertices.length; i += TEXT_VERTEX_FLOATS) {+ expect(Array.from(vertices.subarray(i, i + 3))).toEqual(shadow ? [0, 0, 0] : [0, 1, 0]);+ expect(vertices[i + 3]).toBeCloseTo(alpha);+ }+ }+ const fill = sink.mock.calls[shadows + outlines][0] as Float32Array;+ expect(Array.from(fill.subarray(4, 7))).toEqual([1, 0, 0]);+ expect(fill[7]).toBeCloseTo(128 / 255 * 0.5);+ expect(Array.from(fill.subarray(4 * TEXT_VERTEX_FLOATS + 4, 4 * TEXT_VERTEX_FLOATS + 7))).toEqual([1, 1, 1]);+ expect(fill[4 * TEXT_VERTEX_FLOATS + 7]).toBeCloseTo(0.5);+ }+ }+ });+it('applies inherited opacity to explicit rich colors and invalidates cached geometry', () => {const atlas = makeAtlas(1024);const sink = vi.fn();diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex d633b0854..3b6b6358c 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(ui): preserve rich text shadow and outline colors':+ { note: 'Rich-text colors no longer recolor shadows and outlines.' },'fix(ui): apply inherited opacity to all text passes':{ note: 'UI text effects follow inherited opacity.' },'test(renderer): cover clip recovery between camera passes':