Browse Source

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
568a4205a6 (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.
next
Vladimír Vondruš 1 month ago
parent
commit
8657017a8f
  1. 3
      src/Magnum/Text/Renderer.cpp
  2. 16
      src/Magnum/Text/Test/RendererTest.cpp

3
src/Magnum/Text/Renderer.cpp

@ -1550,7 +1550,8 @@ Range2D alignRenderedLine(const Range2D& lineRectangle, const LayoutDirection di
Float alignmentOffsetX; Float alignmentOffsetX;
if((UnsignedByte(alignment) & Implementation::AlignmentHorizontal) == Implementation::AlignmentLeft) 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) { else if((UnsignedByte(alignment) & Implementation::AlignmentHorizontal) == Implementation::AlignmentCenter) {
alignmentOffsetX = -lineRectangle.centerX(); alignmentOffsetX = -lineRectangle.centerX();
/* Integer alignment */ /* Integer alignment */

16
src/Magnum/Text/Test/RendererTest.cpp

@ -172,13 +172,19 @@ const struct {
Alignment alignment; Alignment alignment;
Float offset; Float offset;
} AlignLineData[]{ } AlignLineData[]{
/* The vertical alignment and GlyphBounds has no effect here */ /* The vertical alignment has no effect here, GlyphBounds only has an
/* Left is the default (0) value, thus should result in no shift */ effect on left alignment */
{"left", Alignment::BottomLeft, -10.0f}, /* Left is the default (0) value, thus should result in no shift unless
{"right", Alignment::LineRightGlyphBounds, -13.5f}, 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 */ /* 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", Alignment::TopCenter, -11.75f},
{"center, glyph bounds", Alignment::TopCenterGlyphBounds, -11.75f},
{"center, integral", Alignment::TopCenterIntegral, -12.0f}, {"center, integral", Alignment::TopCenterIntegral, -12.0f},
}; };

Loading…
Cancel
Save