mirror of https://github.com/mosra/magnum.git
Browse Source
Because there's going to be LayoutDirection as well, for controlling how line progression happens. Because nothing in text rendering is simple.pull/168/head
10 changed files with 243 additions and 117 deletions
@ -0,0 +1,50 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||||
|
2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Direction.h" |
||||||
|
|
||||||
|
#include <Corrade/Utility/Debug.h> |
||||||
|
|
||||||
|
namespace Magnum { namespace Text { |
||||||
|
|
||||||
|
Debug& operator<<(Debug& debug, const ShapeDirection value) { |
||||||
|
debug << "Text::ShapeDirection" << Debug::nospace; |
||||||
|
|
||||||
|
switch(value) { |
||||||
|
/* LCOV_EXCL_START */ |
||||||
|
#define _c(v) case ShapeDirection::v: return debug << "::" #v; |
||||||
|
_c(Unspecified) |
||||||
|
_c(LeftToRight) |
||||||
|
_c(RightToLeft) |
||||||
|
_c(TopToBottom) |
||||||
|
_c(BottomToTop) |
||||||
|
#undef _c |
||||||
|
/* LCOV_EXCL_STOP */ |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")"; |
||||||
|
} |
||||||
|
|
||||||
|
}} |
||||||
@ -0,0 +1,90 @@ |
|||||||
|
#ifndef Magnum_Text_Direction_h |
||||||
|
#define Magnum_Text_Direction_h |
||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||||
|
2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Enum @ref Magnum::Text::ShapeDirection |
||||||
|
* @m_since_latest |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum/Magnum.h" |
||||||
|
#include "Magnum/Text/Text.h" |
||||||
|
#include "Magnum/Text/visibility.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Text { |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Direction a text is shaped in |
||||||
|
@m_since_latest |
||||||
|
|
||||||
|
@see @ref AbstractShaper::setDirection(), @ref AbstractShaper::direction() |
||||||
|
*/ |
||||||
|
enum class ShapeDirection: UnsignedByte { |
||||||
|
/**
|
||||||
|
* Unspecified. When set in @ref AbstractShaper::setDirection(), makes the |
||||||
|
* shaping rely on direction autodetection implemented in a particular |
||||||
|
* @ref AbstractFont plugin (if any). When returned from |
||||||
|
* @ref AbstractShaper::direction() after a successful |
||||||
|
* @ref AbstractShaper::shape() call, it means a particular |
||||||
|
* @ref AbstractFont plugin doesn't implement any script-specific behavior. |
||||||
|
*/ |
||||||
|
Unspecified = 0, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Left to right. When returned from @ref AbstractShaper::direction(), |
||||||
|
* the @p advances filled by @ref AbstractShaper::glyphsInto() are |
||||||
|
* guaranteed to have their Y components @cpp 0.0f @ce. |
||||||
|
*/ |
||||||
|
LeftToRight = 1, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Right to left. When returned from @ref AbstractShaper::direction(), |
||||||
|
* the @p advances filled by @ref AbstractShaper::glyphsInto() are |
||||||
|
* guaranteed to have their Y components @cpp 0.0f @ce. |
||||||
|
*/ |
||||||
|
RightToLeft, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Top to bottom. When returned from @ref AbstractShaper::direction(), |
||||||
|
* the @p advances filled by @ref AbstractShaper::glyphsInto() are |
||||||
|
* guaranteed to have their X components @cpp 0.0f @ce. |
||||||
|
*/ |
||||||
|
TopToBottom, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Bottom to top. When returned from @ref AbstractShaper::direction(), |
||||||
|
* the @p advances filled by @ref AbstractShaper::glyphsInto() are |
||||||
|
* guaranteed to have their X components @cpp 0.0f @ce. |
||||||
|
*/ |
||||||
|
BottomToTop |
||||||
|
}; |
||||||
|
|
||||||
|
/** @debugoperatorenum{ShapeDirection} */ |
||||||
|
MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, ShapeDirection value); |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,52 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||||
|
2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <sstream> |
||||||
|
#include <Corrade/TestSuite/Tester.h> |
||||||
|
#include <Corrade/Utility/DebugStl.h> /** @todo remove once Debug is stream-free */ |
||||||
|
|
||||||
|
#include "Magnum/Text/Direction.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Text { namespace Test { namespace { |
||||||
|
|
||||||
|
struct DirectionTest: TestSuite::Tester { |
||||||
|
explicit DirectionTest(); |
||||||
|
|
||||||
|
void debugShape(); |
||||||
|
}; |
||||||
|
|
||||||
|
DirectionTest::DirectionTest() { |
||||||
|
addTests({&DirectionTest::debugShape}); |
||||||
|
} |
||||||
|
|
||||||
|
void DirectionTest::debugShape() { |
||||||
|
std::ostringstream out; |
||||||
|
Debug{&out} << ShapeDirection::RightToLeft << ShapeDirection(0xab); |
||||||
|
CORRADE_COMPARE(out.str(), "Text::ShapeDirection::RightToLeft Text::ShapeDirection(0xab)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
}}}} |
||||||
|
|
||||||
|
CORRADE_TEST_MAIN(Magnum::Text::Test::DirectionTest) |
||||||
Loading…
Reference in new issue