Browse Source

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.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
0e35c0e761
  1. 17
      src/Magnum/Text/Direction.cpp
  2. 30
      src/Magnum/Text/Direction.h
  3. 10
      src/Magnum/Text/Test/DirectionTest.cpp
  4. 1
      src/Magnum/Text/Text.h

17
src/Magnum/Text/Direction.cpp

@ -47,4 +47,21 @@ Debug& operator<<(Debug& debug, const ShapeDirection value) {
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(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<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
}}

30
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

10
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)

1
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;

Loading…
Cancel
Save