From 0e35c0e761478038018fe5925360fd0bcf9ac166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 19 Oct 2023 13:17:11 +0200 Subject: [PATCH] Text: add a LayoutDirection enum. To be used as a placeholder argument in the reworked renderer APIs. No intention to deal with the complexities of this right now, just taking it to not have to deprecate & replace the API when this feature actually gets implemented. --- src/Magnum/Text/Direction.cpp | 17 +++++++++++++++ src/Magnum/Text/Direction.h | 30 ++++++++++++++++++++++++-- src/Magnum/Text/Test/DirectionTest.cpp | 10 ++++++++- src/Magnum/Text/Text.h | 1 + 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/Magnum/Text/Direction.cpp b/src/Magnum/Text/Direction.cpp index 9726db042..73e39d54f 100644 --- a/src/Magnum/Text/Direction.cpp +++ b/src/Magnum/Text/Direction.cpp @@ -47,4 +47,21 @@ Debug& operator<<(Debug& debug, const ShapeDirection value) { return debug << "(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; } +Debug& operator<<(Debug& debug, const LayoutDirection value) { + debug << "Text::LayoutDirection" << Debug::nospace; + + switch(value) { + /* LCOV_EXCL_START */ + #define _c(v) case LayoutDirection::v: return debug << "::" #v; + _c(Unspecified) + _c(HorizontalTopToBottom) + _c(VerticalLeftToRight) + _c(VerticalRightToLeft) + #undef _c + /* LCOV_EXCL_STOP */ + } + + return debug << "(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; +} + }} diff --git a/src/Magnum/Text/Direction.h b/src/Magnum/Text/Direction.h index c4413161c..24cc5333b 100644 --- a/src/Magnum/Text/Direction.h +++ b/src/Magnum/Text/Direction.h @@ -26,7 +26,7 @@ */ /** @file - * @brief Enum @ref Magnum::Text::ShapeDirection + * @brief Enum @ref Magnum::Text::ShapeDirection, @ref Magnum::Text::LayoutDirection * @m_since_latest */ @@ -40,7 +40,8 @@ namespace Magnum { namespace Text { @brief Direction a text is shaped in @m_since_latest -@see @ref AbstractShaper::setDirection(), @ref AbstractShaper::direction() +@see @ref AbstractShaper::setDirection(), @ref AbstractShaper::direction(), + @ref LayoutDirection */ enum class ShapeDirection: UnsignedByte { /** @@ -85,6 +86,31 @@ enum class ShapeDirection: UnsignedByte { /** @debugoperatorenum{ShapeDirection} */ MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, ShapeDirection value); +/** +@brief Direction a text is laid out in +@m_since_latest + +@see @ref ShapeDirection +*/ +enum class LayoutDirection: UnsignedByte { + Unspecified = 0, + + /** Horizontal text with lines advancing from top to bottom */ + HorizontalTopToBottom = 1, + + /* There's no HorizontalBottomToTop, as apparently no scripts use that. Not + even the CSS writing-mode property has it, so why should I. */ + + /** Vertical text with lines advancing from left to right */ + VerticalLeftToRight, + + /** Vertical text with lines advancing from right to left */ + VerticalRightToLeft +}; + +/** @debugoperatorenum{LayoutDirection} */ +MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, LayoutDirection value); + }} #endif diff --git a/src/Magnum/Text/Test/DirectionTest.cpp b/src/Magnum/Text/Test/DirectionTest.cpp index 2266ea3e3..bf0ea2e0a 100644 --- a/src/Magnum/Text/Test/DirectionTest.cpp +++ b/src/Magnum/Text/Test/DirectionTest.cpp @@ -35,10 +35,12 @@ struct DirectionTest: TestSuite::Tester { explicit DirectionTest(); void debugShape(); + void debugLayout(); }; DirectionTest::DirectionTest() { - addTests({&DirectionTest::debugShape}); + addTests({&DirectionTest::debugShape, + &DirectionTest::debugLayout}); } void DirectionTest::debugShape() { @@ -47,6 +49,12 @@ void DirectionTest::debugShape() { CORRADE_COMPARE(out.str(), "Text::ShapeDirection::RightToLeft Text::ShapeDirection(0xab)\n"); } +void DirectionTest::debugLayout() { + std::ostringstream out; + Debug{&out} << LayoutDirection::VerticalRightToLeft << LayoutDirection(0xab); + CORRADE_COMPARE(out.str(), "Text::LayoutDirection::VerticalRightToLeft Text::LayoutDirection(0xab)\n"); +} + }}}} CORRADE_TEST_MAIN(Magnum::Text::Test::DirectionTest) diff --git a/src/Magnum/Text/Text.h b/src/Magnum/Text/Text.h index bbfdcc5bd..53db68d7f 100644 --- a/src/Magnum/Text/Text.h +++ b/src/Magnum/Text/Text.h @@ -43,6 +43,7 @@ class AbstractShaper; enum class Alignment: UnsignedByte; enum class ShapeDirection: UnsignedByte; +enum class LayoutDirection: UnsignedByte; class AbstractGlyphCache;