From 93a0afdf641af5e28b1ccbdd018034366e8baa91 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Tue, 7 Apr 2026 01:39:35 +0200 Subject: fix: use line-height-based bounds for text elements --- apps/web/src/lib/text/layout.ts | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'apps/web/src/lib/text/layout.ts') diff --git a/apps/web/src/lib/text/layout.ts b/apps/web/src/lib/text/layout.ts index 32d0d80e..75fa7f09 100644 --- a/apps/web/src/lib/text/layout.ts +++ b/apps/web/src/lib/text/layout.ts @@ -54,32 +54,19 @@ export function getMetricDescent({ export function measureTextBlock({ lineMetrics, lineHeightPx, - fallbackFontSize, }: { lineMetrics: TextMetrics[]; lineHeightPx: number; - fallbackFontSize: number; }): TextBlockMeasurement { - let top = Number.POSITIVE_INFINITY; - let bottom = Number.NEGATIVE_INFINITY; let maxWidth = 0; - for (let index = 0; index < lineMetrics.length; index++) { - const metrics = lineMetrics[index]; - const lineY = index * lineHeightPx; - top = Math.min( - top, - lineY - getMetricAscent({ metrics, fallbackFontSize }), - ); - bottom = Math.max( - bottom, - lineY + getMetricDescent({ metrics, fallbackFontSize }), - ); + for (const metrics of lineMetrics) { maxWidth = Math.max(maxWidth, metrics.width); } - const height = bottom - top; - const visualCenterOffset = (top + bottom) / 2; + const lineCount = lineMetrics.length; + const height = lineCount * lineHeightPx; + const visualCenterOffset = ((lineCount - 1) * lineHeightPx) / 2; return { visualCenterOffset, height, maxWidth }; } -- cgit v1.3.1