From 4fea3efbd3e2948cf2593821b27a445c6d9a9d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Nov 2013 00:03:28 +0100 Subject: [PATCH] Text: fixed alignment. The original code assumed that the text bounds lower left corner is always at origin. It is now not the case with multi-line text. All tests now pass again. --- src/Text/Renderer.cpp | 10 ++++------ src/Text/Test/RendererGLTest.cpp | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Text/Renderer.cpp b/src/Text/Renderer.cpp index 4ccad7675..fb25201d2 100644 --- a/src/Text/Renderer.cpp +++ b/src/Text/Renderer.cpp @@ -123,12 +123,11 @@ std::tuple, Rectangle> renderVerticesInternal(AbstractFont& /** @todo What about top-down text? */ /* Horizontally align the rendered line */ - const Float renderedWidth = lineRectangle.width(); Float alignmentOffsetX = 0.0f; if((UnsignedByte(alignment) & Implementation::AlignmentHorizontal) == Implementation::AlignmentCenter) - alignmentOffsetX = -renderedWidth*0.5f; + alignmentOffsetX = -lineRectangle.left()-lineRectangle.width()*0.5f; else if((UnsignedByte(alignment) & Implementation::AlignmentHorizontal) == Implementation::AlignmentRight) - alignmentOffsetX = -renderedWidth; + alignmentOffsetX = -lineRectangle.right(); /* Integer alignment */ if(UnsignedByte(alignment) & Implementation::AlignmentIntegral) @@ -152,12 +151,11 @@ std::tuple, Rectangle> renderVerticesInternal(AbstractFont& pos != std::string::npos); /* Vertically align the rendered text */ - const Float renderedHeight = rectangle.height(); Float alignmentOffsetY = 0.0f; if((UnsignedByte(alignment) & Implementation::AlignmentVertical) == Implementation::AlignmentMiddle) - alignmentOffsetY = -renderedHeight*0.5f; + alignmentOffsetY = -rectangle.bottom()-rectangle.height()*0.5f; else if((UnsignedByte(alignment) & Implementation::AlignmentVertical) == Implementation::AlignmentTop) - alignmentOffsetY = -renderedHeight; + alignmentOffsetY = -rectangle.top(); /* Integer alignment */ if(UnsignedByte(alignment) & Implementation::AlignmentIntegral) diff --git a/src/Text/Test/RendererGLTest.cpp b/src/Text/Test/RendererGLTest.cpp index fef145817..4e6115a7e 100644 --- a/src/Text/Test/RendererGLTest.cpp +++ b/src/Text/Test/RendererGLTest.cpp @@ -94,8 +94,8 @@ void RendererGLTest::renderData() { CORRADE_COMPARE(textureCoordinates.size(), 12); CORRADE_COMPARE(indices.size(), 18); - /* Alignment offset */ - const Vector2 offset{-5.0f, -1.0f}; + /* Alignment offset. Y would be -0.25f if it wasn't integral */ + const Vector2 offset{-5.0f, 0.0f}; /* Bounds */ CORRADE_COMPARE(bounds, Rectangle({0.0f, -0.5f}, {5.0f, 1.0f}).translated(offset)); @@ -173,7 +173,7 @@ void RendererGLTest::renderMesh() { MAGNUM_VERIFY_NO_ERROR(); /* Alignment offset */ - const Vector2 offset{-2.5f, -1.5f}; + const Vector2 offset{-2.5f, -1.0f}; /* Bounds */ CORRADE_COMPARE(bounds, Rectangle({0.0f, -0.5f}, {5.0f, 1.0f}).translated(offset));