diff --git a/doc/changelog.dox b/doc/changelog.dox index 50fa8dbb6..cd2033401 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -782,6 +782,8 @@ See also: - Added @ref Text::AbstractFont::glyphCount() and @relativeref{Text::AbstractFont,glyphSize()} - Added @ref Text::Renderer::fontSize() +- Added @ref Text::Alignment::TopCenterIntegral, which is also needed in + order to prevent aligning pixel-perfect fonts to fractional positions @subsubsection changelog-latest-changes-trade Trade library diff --git a/src/Magnum/Text/Alignment.h b/src/Magnum/Text/Alignment.h index 97acf4325..7bcc70302 100644 --- a/src/Magnum/Text/Alignment.h +++ b/src/Magnum/Text/Alignment.h @@ -52,6 +52,12 @@ namespace Implementation { /** @brief Text rendering alignment +The `*Integer` values are meant to be used for pixel-perfect fonts that always +have glyph sizes, advances and other metrics whole pixels, and need to be +positioned on whole pixels as well in order to avoid making them blurry. These +are only needed for `*Middle` and `*Center` alignments as they may result in +the bounding rectangle to have odd dimensions, which would then result in +half-pixel shifts when divided by 2. @see @ref Renderer::render(), @ref Renderer::Renderer() */ enum class Alignment: UnsignedByte { @@ -92,7 +98,11 @@ enum class Alignment: UnsignedByte { /** Text start and top is at origin */ TopLeft = Implementation::AlignmentTop|Implementation::AlignmentLeft, - /** Text center and top is at origin */ + /** + * Text center and top is at origin + * + * @see @ref Alignment::TopCenterIntegral + */ TopCenter = Implementation::AlignmentTop|Implementation::AlignmentCenter, /** Text end and top is at origin */ @@ -124,7 +134,16 @@ enum class Alignment: UnsignedByte { * * @see @ref Alignment::MiddleRight */ - MiddleRightIntegral = Implementation::AlignmentMiddle|Implementation::AlignmentRight|Implementation::AlignmentIntegral + MiddleRightIntegral = Implementation::AlignmentMiddle|Implementation::AlignmentRight|Implementation::AlignmentIntegral, + + /** + * Text center and line is at origin and alignment offset is integral + * + * @see @ref Alignment::TopCenter + * @m_since_latest + */ + TopCenterIntegral = Implementation::AlignmentTop|Implementation::AlignmentCenter|Implementation::AlignmentIntegral, + }; }} diff --git a/src/Magnum/Text/Test/RendererGLTest.cpp b/src/Magnum/Text/Test/RendererGLTest.cpp index b3f663623..f9f686f17 100644 --- a/src/Magnum/Text/Test/RendererGLTest.cpp +++ b/src/Magnum/Text/Test/RendererGLTest.cpp @@ -60,6 +60,9 @@ const struct { /** @todo for all these, the initial glyph offset is first subtracted and only then the shift by either half or full size is performed, does that make sense? why is not done for the LineLeft case, then? */ + {"top center, integral", Alignment::TopCenterIntegral, + /* The Y shift is rounded to whole units */ + {-5.5f - 2.5f, -7.5f - 3.5f}}, {"top left", Alignment::TopLeft, {0.0f, -7.0f - 3.5f}}, {"top right", Alignment::TopRight,