From 695dc1d041abe2759a981d99b68ed2b4f1f3e73e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 28 Oct 2023 20:25:35 +0200 Subject: [PATCH] Text: debug output for Alignment. --- src/Magnum/Text/Alignment.cpp | 81 ++++++++++++++++++++++++++ src/Magnum/Text/Alignment.h | 6 +- src/Magnum/Text/CMakeLists.txt | 1 + src/Magnum/Text/Test/AlignmentTest.cpp | 52 +++++++++++++++++ src/Magnum/Text/Test/CMakeLists.txt | 1 + 5 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/Magnum/Text/Alignment.cpp create mode 100644 src/Magnum/Text/Test/AlignmentTest.cpp diff --git a/src/Magnum/Text/Alignment.cpp b/src/Magnum/Text/Alignment.cpp new file mode 100644 index 000000000..d648018f1 --- /dev/null +++ b/src/Magnum/Text/Alignment.cpp @@ -0,0 +1,81 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020, 2021, 2022, 2023 Vladimír Vondruš + + 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 "Alignment.h" + +#include + +namespace Magnum { namespace Text { + +Debug& operator<<(Debug& debug, const Alignment value) { + debug << "Text::Alignment" << Debug::nospace; + + switch(value) { + /* LCOV_EXCL_START */ + #define _c(v) case Alignment::v: return debug << "::" #v; + _c(LineLeft) + _c(LineLeftGlyphBounds) + _c(LineCenter) + _c(LineCenterIntegral) + _c(LineCenterGlyphBounds) + _c(LineCenterGlyphBoundsIntegral) + _c(LineRight) + _c(LineRightGlyphBounds) + _c(BottomLeft) + _c(BottomLeftGlyphBounds) + _c(BottomCenter) + _c(BottomCenterIntegral) + _c(BottomCenterGlyphBounds) + _c(BottomCenterGlyphBoundsIntegral) + _c(BottomRight) + _c(BottomRightGlyphBounds) + _c(MiddleLeft) + _c(MiddleLeftIntegral) + _c(MiddleLeftGlyphBounds) + _c(MiddleLeftGlyphBoundsIntegral) + _c(MiddleCenter) + _c(MiddleCenterIntegral) + _c(MiddleCenterGlyphBounds) + _c(MiddleCenterGlyphBoundsIntegral) + _c(MiddleRight) + _c(MiddleRightIntegral) + _c(MiddleRightGlyphBounds) + _c(MiddleRightGlyphBoundsIntegral) + _c(TopLeft) + _c(TopLeftGlyphBounds) + _c(TopCenter) + _c(TopCenterIntegral) + _c(TopCenterGlyphBounds) + _c(TopCenterGlyphBoundsIntegral) + _c(TopRight) + _c(TopRightGlyphBounds) + #undef _c + /* LCOV_EXCL_STOP */ + } + + return debug << "(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; +} + +}} diff --git a/src/Magnum/Text/Alignment.h b/src/Magnum/Text/Alignment.h index 73f5b89d2..834c664c4 100644 --- a/src/Magnum/Text/Alignment.h +++ b/src/Magnum/Text/Alignment.h @@ -29,7 +29,8 @@ * @brief Enum @ref Magnum::Text::Alignment */ -#include "Magnum/Types.h" +#include "Magnum/Magnum.h" +#include "Magnum/Text/visibility.h" namespace Magnum { namespace Text { @@ -370,6 +371,9 @@ enum class Alignment: UnsignedByte { TopRightGlyphBounds = TopRight|Implementation::AlignmentGlyphBounds, }; +/** @debugoperatorenum{Alignment} */ +MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, Alignment value); + }} #endif diff --git a/src/Magnum/Text/CMakeLists.txt b/src/Magnum/Text/CMakeLists.txt index 7071783e2..6e593b9f6 100644 --- a/src/Magnum/Text/CMakeLists.txt +++ b/src/Magnum/Text/CMakeLists.txt @@ -31,6 +31,7 @@ find_package(Corrade REQUIRED PluginManager) # Files shared between main library and unit test library set(MagnumText_SRCS + Alignment.cpp Direction.cpp) # Files compiled with different flags for main library and unit test library diff --git a/src/Magnum/Text/Test/AlignmentTest.cpp b/src/Magnum/Text/Test/AlignmentTest.cpp new file mode 100644 index 000000000..68605cfb6 --- /dev/null +++ b/src/Magnum/Text/Test/AlignmentTest.cpp @@ -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š + + 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 +#include +#include /** @todo remove once Debug is stream-free */ + +#include "Magnum/Text/Alignment.h" + +namespace Magnum { namespace Text { namespace Test { namespace { + +struct AlignmentTest: TestSuite::Tester { + explicit AlignmentTest(); + + void debug(); +}; + +AlignmentTest::AlignmentTest() { + addTests({&AlignmentTest::debug}); +} + +void AlignmentTest::debug() { + std::ostringstream out; + Debug{&out} << Alignment::MiddleRightGlyphBounds << Alignment(0xab); + CORRADE_COMPARE(out.str(), "Text::Alignment::MiddleRightGlyphBounds Text::Alignment(0xab)\n"); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::Text::Test::AlignmentTest) diff --git a/src/Magnum/Text/Test/CMakeLists.txt b/src/Magnum/Text/Test/CMakeLists.txt index 6e4986b74..94983e43e 100644 --- a/src/Magnum/Text/Test/CMakeLists.txt +++ b/src/Magnum/Text/Test/CMakeLists.txt @@ -77,6 +77,7 @@ endif() corrade_add_test(TextAbstractShaperTest AbstractShaperTest.cpp LIBRARIES MagnumTextTestLib) +corrade_add_test(TextAlignmentTest AlignmentTest.cpp LIBRARIES MagnumText) corrade_add_test(TextDirectionTest DirectionTest.cpp LIBRARIES MagnumText) corrade_add_test(TextFeatureTest FeatureTest.cpp LIBRARIES MagnumTextTestLib) corrade_add_test(TextRendererTest RendererTest.cpp LIBRARIES MagnumTextTestLib)