From 68600e704dce613e82319a2f4634ba2cf32cc000 Mon Sep 17 00:00:00 2001 From: Chris Lorenzo Date: Sat, 23 May 2026 18:51:06 -0400 Subject: [PATCH] Revert "feat(text): expose trimmedHeight on text nodes (#30)" This reverts commit 965999b282851938f0a73ccd288acbf32350e2c7. --- src/common/CommonTypes.ts | 5 ----- src/core/CoreTextNode.ts | 22 ------------------- src/core/text-rendering/CanvasTextRenderer.ts | 9 -------- src/core/text-rendering/SdfTextRenderer.ts | 13 ----------- src/core/text-rendering/TextRenderer.ts | 20 ----------------- 5 files changed, 69 deletions(-) diff --git a/src/common/CommonTypes.ts b/src/common/CommonTypes.ts index 71a9867..b77f998 100644 --- a/src/common/CommonTypes.ts +++ b/src/common/CommonTypes.ts @@ -23,11 +23,6 @@ export interface Dimensions { export type NodeTextLoadedPayload = { type: 'text'; dimensions: Dimensions; - /** - * Visible glyph extent — from the first line's cap-top to the last - * line's descender bottom. See `CoreTextNode.trimmedHeight`. - */ - trimmedHeight: number; }; /** diff --git a/src/core/CoreTextNode.ts b/src/core/CoreTextNode.ts index eb347d4..0fe5b2d 100644 --- a/src/core/CoreTextNode.ts +++ b/src/core/CoreTextNode.ts @@ -65,7 +65,6 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps { private _renderInfo: TextRenderInfo = { width: 0, height: 0, - trimmedHeight: 0, }; private _type: 'sdf' | 'canvas' = 'sdf'; // Default to SDF renderer @@ -290,7 +289,6 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps { w: this._renderInfo.width, h: this._renderInfo.height, }, - trimmedHeight: this._renderInfo.trimmedHeight, } satisfies NodeTextLoadedPayload); }; @@ -595,24 +593,4 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps { get renderInfo(): TextRenderInfo { return this._renderInfo; } - - /** - * Visible glyph extent — from the first line's cap-top to the last - * line's descender bottom. Excludes half-leading and the slack above - * the cap-top inside the font's ascender. - * - * @remarks - * Useful with flex `alignItems: 'center'` (or any layout that aligns - * by node `h`) to optically center the glyphs rather than the - * lineHeightPx line-box. Listen for `loaded` and apply with: - * - * ```ts - * text.once('loaded', (n, p) => { text.h = p.trimmedHeight; }); - * ``` - * - * Zero before the text loads or for empty strings. - */ - get trimmedHeight(): number { - return this._renderInfo.trimmedHeight; - } } diff --git a/src/core/text-rendering/CanvasTextRenderer.ts b/src/core/text-rendering/CanvasTextRenderer.ts index 40bbf70..ec1c4ca 100644 --- a/src/core/text-rendering/CanvasTextRenderer.ts +++ b/src/core/text-rendering/CanvasTextRenderer.ts @@ -87,7 +87,6 @@ const renderText = (props: CoreTextNodeProps): TextRenderInfo => { return { width: 0, height: 0, - trimmedHeight: 0, }; } @@ -192,18 +191,10 @@ const renderText = (props: CoreTextNodeProps): TextRenderInfo => { if (canvas.width > 0 && canvas.height > 0) { imageData = context.getImageData(0, 0, canvasW, canvasH); } - // Cap-top of first line to descender bottom of last line. - // descender is negative in NormalizedFontMetrics. - const trimmedHeight = - lineAmount > 0 - ? metrics.capHeight - metrics.descender + (lineAmount - 1) * lineHeightPx - : 0; - return { imageData, width: effectiveWidth, height: effectiveHeight, - trimmedHeight, remainingLines, hasRemainingText, }; diff --git a/src/core/text-rendering/SdfTextRenderer.ts b/src/core/text-rendering/SdfTextRenderer.ts index 2638666..bcfd4cc 100644 --- a/src/core/text-rendering/SdfTextRenderer.ts +++ b/src/core/text-rendering/SdfTextRenderer.ts @@ -52,7 +52,6 @@ const renderText = (props: CoreTextNodeProps): TextRenderInfo => { return { width: 0, height: 0, - trimmedHeight: 0, }; } @@ -64,7 +63,6 @@ const renderText = (props: CoreTextNodeProps): TextRenderInfo => { hasRemainingText: false, width: layout.width, height: layout.height, - trimmedHeight: layout.trimmedHeight, layout, }; } @@ -76,7 +74,6 @@ const renderText = (props: CoreTextNodeProps): TextRenderInfo => { return { width: 0, height: 0, - trimmedHeight: 0, }; } @@ -90,7 +87,6 @@ const renderText = (props: CoreTextNodeProps): TextRenderInfo => { hasRemainingText: false, width: layout.width, height: layout.height, - trimmedHeight: layout.trimmedHeight, layout, }; }; @@ -349,21 +345,12 @@ const generateTextLayout = ( } } - // Cap-top of first line to descender bottom of last line. - // descender is negative in NormalizedFontMetrics, so subtracting it - // adds the descender depth. Zero when there are no rendered lines. - const trimmedHeight = - lineAmount > 0 - ? metrics.capHeight - metrics.descender + (lineAmount - 1) * lineHeightPx - : 0; - // Convert final dimensions to pixel space for the layout return { glyphs, distanceRange: fontScale * fontData.distanceField.distanceRange, width: effectiveWidth * fontScale, height: effectiveHeight, - trimmedHeight, fontScale: fontScale, lineHeight: lineHeightPx, fontFamily, diff --git a/src/core/text-rendering/TextRenderer.ts b/src/core/text-rendering/TextRenderer.ts index 7c3337b..8a00ab8 100644 --- a/src/core/text-rendering/TextRenderer.ts +++ b/src/core/text-rendering/TextRenderer.ts @@ -320,11 +320,6 @@ export interface TextLayout { * Total text height */ height: number; - /** - * Trimmed text height — cap-top of the first line to descender bottom - * of the last line. See `TextRenderInfo.trimmedHeight`. - */ - trimmedHeight: number; /** * Font scale factor */ @@ -421,21 +416,6 @@ export interface TextRenderProps { export interface TextRenderInfo { width: number; height: number; - /** - * Height of the visible glyph extent — from the first line's cap-top to - * the last line's descender bottom. Excludes half-leading and the slack - * between the font's ascender and cap-top. - * - * @remarks - * Formula: `capHeight − descender + (lines − 1) × lineHeightPx` - * (descender is negative in font metrics, so subtracting it adds the - * descender depth). For empty text, this is 0. - * - * Use this when you want flex `alignItems: 'center'` (or any layout - * that aligns by node `h`) to optically center the visible glyphs. - * Set `node.h = node.trimmedHeight` after the `loaded` event. - */ - trimmedHeight: number; hasRemainingText?: boolean; remainingLines?: number; imageData?: ImageData | null; // Image data for Canvas Text Renderer