From 8657017a8f145516435ac6de9aeab87e3bcd0a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 18 Aug 2026 19:46:02 +0200 Subject: [PATCH] Text: don't unconditionally discard glyph X offset with left align. Funnily enough the comment next to the relevant test case said that "Left is the default, thus should result in no shift" AND YET right after there was a shift of -10.0f. Done in the original commit in 568a4205a66da527547e4afd15274bfcd905ae5f (2023) already, and I don't remember what was actually the intent. The glyph offset *is* discarded if GlyphBounds is specified, as that might still make sense in certain contexts. A glyph offset is non-zero usually for combining characters, with regular base characters it's rare. It might however be useful for icon fonts for example, where narrower icons might have an extra offsets to make them visually align with wider icons when put underneath each other and aligned to the left. --- src/Magnum/Text/Renderer.cpp | 3 ++- src/Magnum/Text/Test/RendererTest.cpp | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Magnum/Text/Renderer.cpp b/src/Magnum/Text/Renderer.cpp index 2a927004c..b14feaa52 100644 --- a/src/Magnum/Text/Renderer.cpp +++ b/src/Magnum/Text/Renderer.cpp @@ -1550,7 +1550,8 @@ Range2D alignRenderedLine(const Range2D& lineRectangle, const LayoutDirection di Float alignmentOffsetX; if((UnsignedByte(alignment) & Implementation::AlignmentHorizontal) == Implementation::AlignmentLeft) - alignmentOffsetX = -lineRectangle.left(); + alignmentOffsetX = UnsignedByte(alignment) & Implementation::AlignmentGlyphBounds ? + -lineRectangle.left() : 0.0f; else if((UnsignedByte(alignment) & Implementation::AlignmentHorizontal) == Implementation::AlignmentCenter) { alignmentOffsetX = -lineRectangle.centerX(); /* Integer alignment */ diff --git a/src/Magnum/Text/Test/RendererTest.cpp b/src/Magnum/Text/Test/RendererTest.cpp index 86d7f80d5..5e341ab45 100644 --- a/src/Magnum/Text/Test/RendererTest.cpp +++ b/src/Magnum/Text/Test/RendererTest.cpp @@ -172,13 +172,19 @@ const struct { Alignment alignment; Float offset; } AlignLineData[]{ - /* The vertical alignment and GlyphBounds has no effect here */ - /* Left is the default (0) value, thus should result in no shift */ - {"left", Alignment::BottomLeft, -10.0f}, - {"right", Alignment::LineRightGlyphBounds, -13.5f}, + /* The vertical alignment has no effect here, GlyphBounds only has an + effect on left alignment */ + /* Left is the default (0) value, thus should result in no shift unless + glyph bounds alignment is explicitly requested, in which case the glyph + offset is subtracted */ + {"left", Alignment::BottomLeft, 0.0f}, + {"left, glyph bounds", Alignment::BottomLeftGlyphBounds, -10.0f}, + {"right", Alignment::LineRight, -13.5f}, + {"right, glyph bounds", Alignment::LineRightGlyphBounds, -13.5f}, /* Integral should be handled only for Center */ - {"right, integral", Alignment::MiddleRightGlyphBoundsIntegral, -13.5f}, + {"right, integral", Alignment::MiddleRightIntegral, -13.5f}, {"center", Alignment::TopCenter, -11.75f}, + {"center, glyph bounds", Alignment::TopCenterGlyphBounds, -11.75f}, {"center, integral", Alignment::TopCenterIntegral, -12.0f}, };