Browse Source

Text: rename Direction to ShapeDirection, move to a dedicated header.

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
Vladimír Vondruš 3 years ago
parent
commit
8950085c97
  1. 3
      doc/snippets/MagnumText.cpp
  2. 29
      src/Magnum/Text/AbstractShaper.cpp
  3. 90
      src/Magnum/Text/AbstractShaper.h
  4. 4
      src/Magnum/Text/CMakeLists.txt
  5. 50
      src/Magnum/Text/Direction.cpp
  6. 90
      src/Magnum/Text/Direction.h
  7. 39
      src/Magnum/Text/Test/AbstractShaperTest.cpp
  8. 2
      src/Magnum/Text/Test/CMakeLists.txt
  9. 52
      src/Magnum/Text/Test/DirectionTest.cpp
  10. 1
      src/Magnum/Text/Text.h

3
doc/snippets/MagnumText.cpp

@ -51,6 +51,7 @@
#include "Magnum/Text/AbstractFontConverter.h" #include "Magnum/Text/AbstractFontConverter.h"
#include "Magnum/Text/AbstractGlyphCache.h" #include "Magnum/Text/AbstractGlyphCache.h"
#include "Magnum/Text/AbstractShaper.h" #include "Magnum/Text/AbstractShaper.h"
#include "Magnum/Text/Direction.h"
#include "Magnum/Text/Feature.h" #include "Magnum/Text/Feature.h"
#include "Magnum/Text/Script.h" #include "Magnum/Text/Script.h"
#include "Magnum/TextureTools/Atlas.h" #include "Magnum/TextureTools/Atlas.h"
@ -266,7 +267,7 @@ Containers::Pointer<Text::AbstractShaper> shaper = font->createShaper();
/* Set text properties and shape it */ /* Set text properties and shape it */
shaper->setScript(Text::Script::Latin); shaper->setScript(Text::Script::Latin);
shaper->setDirection(Text::Direction::LeftToRight); shaper->setDirection(Text::ShapeDirection::LeftToRight);
shaper->setLanguage("en"); shaper->setLanguage("en");
shaper->shape("Hello, world!"); shaper->shape("Hello, world!");

29
src/Magnum/Text/AbstractShaper.cpp

@ -28,28 +28,11 @@
#include <Corrade/Containers/StridedArrayView.h> #include <Corrade/Containers/StridedArrayView.h>
#include <Corrade/Containers/StringView.h> #include <Corrade/Containers/StringView.h>
#include "Magnum/Text/Direction.h"
#include "Magnum/Text/Script.h" #include "Magnum/Text/Script.h"
namespace Magnum { namespace Text { namespace Magnum { namespace Text {
Debug& operator<<(Debug& debug, const Direction value) {
debug << "Text::Direction" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case Direction::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 << ")";
}
AbstractShaper::AbstractShaper(AbstractFont& font): _font(font), _glyphCount{0} {} AbstractShaper::AbstractShaper(AbstractFont& font): _font(font), _glyphCount{0} {}
AbstractShaper::AbstractShaper(AbstractShaper&&) noexcept = default; AbstractShaper::AbstractShaper(AbstractShaper&&) noexcept = default;
@ -70,11 +53,11 @@ bool AbstractShaper::setLanguage(const Containers::StringView language) {
bool AbstractShaper::doSetLanguage(Containers::StringView) { return false; } bool AbstractShaper::doSetLanguage(Containers::StringView) { return false; }
bool AbstractShaper::setDirection(const Direction direction) { bool AbstractShaper::setDirection(const ShapeDirection direction) {
return doSetDirection(direction); return doSetDirection(direction);
} }
bool AbstractShaper::doSetDirection(Direction) { return false; } bool AbstractShaper::doSetDirection(ShapeDirection) { return false; }
UnsignedInt AbstractShaper::shape(const Containers::StringView text, const UnsignedInt begin, const UnsignedInt end, const Containers::ArrayView<const FeatureRange> features) { UnsignedInt AbstractShaper::shape(const Containers::StringView text, const UnsignedInt begin, const UnsignedInt end, const Containers::ArrayView<const FeatureRange> features) {
CORRADE_ASSERT((end == ~UnsignedInt{} && begin <= text.size()) || CORRADE_ASSERT((end == ~UnsignedInt{} && begin <= text.size()) ||
@ -124,11 +107,13 @@ Containers::StringView AbstractShaper::language() const {
Containers::StringView AbstractShaper::doLanguage() const { return {}; } Containers::StringView AbstractShaper::doLanguage() const { return {}; }
Direction AbstractShaper::direction() const { ShapeDirection AbstractShaper::direction() const {
return doDirection(); return doDirection();
} }
Direction AbstractShaper::doDirection() const { return Direction::Unspecified; } ShapeDirection AbstractShaper::doDirection() const {
return ShapeDirection::Unspecified;
}
void AbstractShaper::glyphsInto(const Containers::StridedArrayView1D<UnsignedInt>& ids, const Containers::StridedArrayView1D<Vector2>& offsets, const Containers::StridedArrayView1D<Vector2>& advances) const { void AbstractShaper::glyphsInto(const Containers::StridedArrayView1D<UnsignedInt>& ids, const Containers::StridedArrayView1D<Vector2>& offsets, const Containers::StridedArrayView1D<Vector2>& advances) const {
CORRADE_ASSERT(ids.size() == _glyphCount && offsets.size() == _glyphCount && advances.size() == _glyphCount, CORRADE_ASSERT(ids.size() == _glyphCount && offsets.size() == _glyphCount && advances.size() == _glyphCount,

90
src/Magnum/Text/AbstractShaper.h

@ -26,7 +26,7 @@
*/ */
/** @file /** @file
* @brief Class @ref Magnum::Text::AbstractShaper, @ref Magnum::Text::FeatureRange, enum @ref Magnum::Text::Direction * @brief Class @ref Magnum::Text::AbstractShaper, @ref Magnum::Text::FeatureRange
* @m_since_latest * @m_since_latest
*/ */
@ -39,55 +39,6 @@
namespace Magnum { namespace Text { namespace Magnum { namespace Text {
/**
@brief Direction a text is shaped in
@m_since_latest
@see @ref AbstractShaper::setDirection(), @ref AbstractShaper::direction()
*/
enum class Direction: 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{Direction} */
MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, Direction value);
/** /**
@brief OpenType feature for a text range @brief OpenType feature for a text range
@m_since_latest @m_since_latest
@ -321,14 +272,14 @@ class MAGNUM_TEXT_EXPORT AbstractShaper {
bool setLanguage(Containers::StringView language); bool setLanguage(Containers::StringView language);
/** /**
* @brief Set text direction * @brief Set direction the text is meant to be shaped in
* *
* The direction is used for all following @ref shape() calls. If not * The direction is used for all following @ref shape() calls. If not
* called at all or if explicitly set to @ref Direction::Unspecified, * called at all or if explicitly set to
* the @ref AbstractFont plugin may attempt to guess the direction from * @ref ShapeDirection::Unspecified, the @ref AbstractFont plugin may
* the input text. The actual direction used for shaping (if any) is * attempt to guess the direction from the input text. The actual
* queryable with @ref direction() const after @ref shape() has been * direction used for shaping (if any) is queryable with
* called. * @ref direction() const after @ref shape() has been called.
* *
* Returns @cpp true @ce if the plugin supports setting a language and * Returns @cpp true @ce if the plugin supports setting a language and
* the language is supported, @cpp false @ce otherwise, in which case * the language is supported, @cpp false @ce otherwise, in which case
@ -336,7 +287,7 @@ class MAGNUM_TEXT_EXPORT AbstractShaper {
* particular font plugin for more information. * particular font plugin for more information.
* @see @ref setScript(), @ref setLanguage() * @see @ref setScript(), @ref setLanguage()
*/ */
bool setDirection(Direction direction); bool setDirection(ShapeDirection direction);
/** /**
* @brief Shape a text * @brief Shape a text
@ -436,14 +387,14 @@ class MAGNUM_TEXT_EXPORT AbstractShaper {
Containers::StringView language() const; Containers::StringView language() const;
/** /**
* @brief Language used for the last @ref shape() call * @brief Shape direction used for the last @ref shape() call
* *
* May return @ref Direction::Unspecified if @ref shape() hasn't been * May return @ref ShapeDirection::Unspecified if @ref shape() hasn't
* called yet or if the @ref AbstractFont doesn't implement any * been called yet or if the @ref AbstractFont doesn't implement any
* script-specific behavior. * script-specific behavior.
* @see @ref setDirection(), @ref script(), @ref language() * @see @ref setDirection(), @ref script(), @ref language()
*/ */
Direction direction() const; ShapeDirection direction() const;
/** /**
* @brief Retrieve glyph information * @brief Retrieve glyph information
@ -458,11 +409,12 @@ class MAGNUM_TEXT_EXPORT AbstractShaper {
* relative to current cursor (which is then further offset for the * relative to current cursor (which is then further offset for the
* particular glyph rectangle returned from the glyph cache) and * particular glyph rectangle returned from the glyph cache) and
* @p advances specify in which direction to move the cursor for the * @p advances specify in which direction to move the cursor for the
* next glyph. For @ref direction() being @ref Direction::LeftToRight * next glyph. For @ref direction() being
* or @relativeref{Direction,RightToLeft} Y components of @p advances * @ref ShapeDirection::LeftToRight or
* are @cpp 0.0f @ce, for @relativeref{Direction,TopToBottom} or * @relativeref{ShapeDirection,RightToLeft} Y components of @p advances
* @relativeref{Direction,BottomToTop} X components of @p advances are * are @cpp 0.0f @ce, for @relativeref{ShapeDirection,TopToBottom} or
* @cpp 0.0f @ce. * @relativeref{ShapeDirection,BottomToTop} X components of @p advances
* are @cpp 0.0f @ce.
* @see @ref direction() * @see @ref direction()
*/ */
void glyphsInto(const Containers::StridedArrayView1D<UnsignedInt>& ids, const Containers::StridedArrayView1D<Vector2>& offsets, const Containers::StridedArrayView1D<Vector2>& advances) const; void glyphsInto(const Containers::StridedArrayView1D<UnsignedInt>& ids, const Containers::StridedArrayView1D<Vector2>& offsets, const Containers::StridedArrayView1D<Vector2>& advances) const;
@ -487,7 +439,7 @@ class MAGNUM_TEXT_EXPORT AbstractShaper {
* *
* Default implementation does nothing and returns @cpp false @ce. * Default implementation does nothing and returns @cpp false @ce.
*/ */
virtual bool doSetDirection(Direction direction); virtual bool doSetDirection(ShapeDirection direction);
/** /**
* @brief Implemenation for @ref shape() * @brief Implemenation for @ref shape()
@ -516,9 +468,9 @@ class MAGNUM_TEXT_EXPORT AbstractShaper {
/** /**
* @brief Implemenation for @ref direction() * @brief Implemenation for @ref direction()
* *
* Default implementation returns @ref Direction::Unspecified. * Default implementation returns @ref ShapeDirection::Unspecified.
*/ */
virtual Direction doDirection() const; virtual ShapeDirection doDirection() const;
/** /**
* @brief Implemenation for @ref glyphsInto() * @brief Implemenation for @ref glyphsInto()

4
src/Magnum/Text/CMakeLists.txt

@ -30,7 +30,8 @@ set(CMAKE_FOLDER "Magnum/Text")
find_package(Corrade REQUIRED PluginManager) find_package(Corrade REQUIRED PluginManager)
# Files shared between main library and unit test library # Files shared between main library and unit test library
set(MagnumText_SRCS ) set(MagnumText_SRCS
Direction.cpp)
# Files compiled with different flags for main library and unit test library # Files compiled with different flags for main library and unit test library
set(MagnumText_GracefulAssert_SRCS set(MagnumText_GracefulAssert_SRCS
@ -47,6 +48,7 @@ set(MagnumText_HEADERS
AbstractGlyphCache.h AbstractGlyphCache.h
AbstractShaper.h AbstractShaper.h
Alignment.h Alignment.h
Direction.h
Feature.h Feature.h
Script.h Script.h
Text.h Text.h

50
src/Magnum/Text/Direction.cpp

@ -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 << ")";
}
}}

90
src/Magnum/Text/Direction.h

@ -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

39
src/Magnum/Text/Test/AbstractShaperTest.cpp

@ -33,6 +33,7 @@
#include "Magnum/Math/Vector2.h" #include "Magnum/Math/Vector2.h"
#include "Magnum/Text/AbstractShaper.h" #include "Magnum/Text/AbstractShaper.h"
#include "Magnum/Text/Direction.h"
#include "Magnum/Text/Feature.h" #include "Magnum/Text/Feature.h"
#include "Magnum/Text/Script.h" #include "Magnum/Text/Script.h"
@ -41,8 +42,6 @@ namespace Magnum { namespace Text { namespace Test { namespace {
struct AbstractShaperTest: TestSuite::Tester { struct AbstractShaperTest: TestSuite::Tester {
explicit AbstractShaperTest(); explicit AbstractShaperTest();
void debugDirection();
void featureRangeConstruct(); void featureRangeConstruct();
void featureRangeConstructBeginEnd(); void featureRangeConstructBeginEnd();
@ -73,9 +72,7 @@ struct AbstractShaperTest: TestSuite::Tester {
}; };
AbstractShaperTest::AbstractShaperTest() { AbstractShaperTest::AbstractShaperTest() {
addTests({&AbstractShaperTest::debugDirection, addTests({&AbstractShaperTest::featureRangeConstruct,
&AbstractShaperTest::featureRangeConstruct,
&AbstractShaperTest::featureRangeConstructBeginEnd, &AbstractShaperTest::featureRangeConstructBeginEnd,
&AbstractShaperTest::construct, &AbstractShaperTest::construct,
@ -103,12 +100,6 @@ AbstractShaperTest::AbstractShaperTest() {
&AbstractShaperTest::glyphsIntoInvalidViewSizes}); &AbstractShaperTest::glyphsIntoInvalidViewSizes});
} }
void AbstractShaperTest::debugDirection() {
std::ostringstream out;
Debug{&out} << Direction::RightToLeft << Direction(0xab);
CORRADE_COMPARE(out.str(), "Text::Direction::RightToLeft Text::Direction(0xab)\n");
}
void AbstractShaperTest::featureRangeConstruct() { void AbstractShaperTest::featureRangeConstruct() {
FeatureRange a{Feature::Kerning}; FeatureRange a{Feature::Kerning};
FeatureRange b{Feature::StandardLigatures, false}; FeatureRange b{Feature::StandardLigatures, false};
@ -281,8 +272,8 @@ void AbstractShaperTest::setDirection() {
struct: AbstractShaper { struct: AbstractShaper {
using AbstractShaper::AbstractShaper; using AbstractShaper::AbstractShaper;
bool doSetDirection(Direction direction) override { bool doSetDirection(ShapeDirection direction) override {
CORRADE_COMPARE(direction, Direction::BottomToTop); CORRADE_COMPARE(direction, ShapeDirection::BottomToTop);
called = true; called = true;
return true; return true;
} }
@ -293,13 +284,13 @@ void AbstractShaperTest::setDirection() {
bool called = false; bool called = false;
} shaper{FakeFont}; } shaper{FakeFont};
CORRADE_VERIFY(shaper.setDirection(Direction::BottomToTop)); CORRADE_VERIFY(shaper.setDirection(ShapeDirection::BottomToTop));
CORRADE_VERIFY(shaper.called); CORRADE_VERIFY(shaper.called);
} }
void AbstractShaperTest::setDirectionNotImplemented() { void AbstractShaperTest::setDirectionNotImplemented() {
DummyShaper shaper{FakeFont}; DummyShaper shaper{FakeFont};
CORRADE_VERIFY(!shaper.setDirection(Direction::BottomToTop)); CORRADE_VERIFY(!shaper.setDirection(ShapeDirection::BottomToTop));
} }
void AbstractShaperTest::shape() { void AbstractShaperTest::shape() {
@ -331,8 +322,8 @@ void AbstractShaperTest::shape() {
return "eh-UH"; return "eh-UH";
} }
Direction doDirection() const override { ShapeDirection doDirection() const override {
return Direction::BottomToTop; return ShapeDirection::BottomToTop;
} }
void doGlyphsInto(const Containers::StridedArrayView1D<UnsignedInt>& ids, const Containers::StridedArrayView1D<Vector2>& offsets, const Containers::StridedArrayView1D<Vector2>& advances) const override { void doGlyphsInto(const Containers::StridedArrayView1D<UnsignedInt>& ids, const Containers::StridedArrayView1D<Vector2>& offsets, const Containers::StridedArrayView1D<Vector2>& advances) const override {
@ -355,7 +346,7 @@ void AbstractShaperTest::shape() {
CORRADE_COMPARE(shaper.glyphCount(), 0); CORRADE_COMPARE(shaper.glyphCount(), 0);
CORRADE_COMPARE(shaper.script(), Script::LinearA); CORRADE_COMPARE(shaper.script(), Script::LinearA);
CORRADE_COMPARE(shaper.language(), "eh-UH"); CORRADE_COMPARE(shaper.language(), "eh-UH");
CORRADE_COMPARE(shaper.direction(), Direction::BottomToTop); CORRADE_COMPARE(shaper.direction(), ShapeDirection::BottomToTop);
/* Shaping fills glyph count. A real implementation would then return /* Shaping fills glyph count. A real implementation would then return
(different) detected script/language/direction values, for example. */ (different) detected script/language/direction values, for example. */
@ -367,7 +358,7 @@ void AbstractShaperTest::shape() {
CORRADE_COMPARE(shaper.glyphCount(), 24); CORRADE_COMPARE(shaper.glyphCount(), 24);
CORRADE_COMPARE(shaper.script(), Script::LinearA); CORRADE_COMPARE(shaper.script(), Script::LinearA);
CORRADE_COMPARE(shaper.language(), "eh-UH"); CORRADE_COMPARE(shaper.language(), "eh-UH");
CORRADE_COMPARE(shaper.direction(), Direction::BottomToTop); CORRADE_COMPARE(shaper.direction(), ShapeDirection::BottomToTop);
UnsignedInt ids[24]; UnsignedInt ids[24];
Vector2 offsets[24]; Vector2 offsets[24];
@ -485,7 +476,7 @@ void AbstractShaperTest::shapeScriptLanguageDirectionNotImplemented() {
/* Initially it won't call into any of the implementations */ /* Initially it won't call into any of the implementations */
CORRADE_COMPARE(shaper.script(), Script::Unspecified); CORRADE_COMPARE(shaper.script(), Script::Unspecified);
CORRADE_COMPARE(shaper.language(), ""); CORRADE_COMPARE(shaper.language(), "");
CORRADE_COMPARE(shaper.direction(), Direction::Unspecified); CORRADE_COMPARE(shaper.direction(), ShapeDirection::Unspecified);
CORRADE_COMPARE(shaper.shape("some text"), 24); CORRADE_COMPARE(shaper.shape("some text"), 24);
@ -493,7 +484,7 @@ void AbstractShaperTest::shapeScriptLanguageDirectionNotImplemented() {
values as if shape() wouldn't be called at all */ values as if shape() wouldn't be called at all */
CORRADE_COMPARE(shaper.script(), Script::Unspecified); CORRADE_COMPARE(shaper.script(), Script::Unspecified);
CORRADE_COMPARE(shaper.language(), ""); CORRADE_COMPARE(shaper.language(), "");
CORRADE_COMPARE(shaper.direction(), Direction::Unspecified); CORRADE_COMPARE(shaper.direction(), ShapeDirection::Unspecified);
} }
void AbstractShaperTest::shapeZeroGlyphs() { void AbstractShaperTest::shapeZeroGlyphs() {
@ -512,8 +503,8 @@ void AbstractShaperTest::shapeZeroGlyphs() {
return "eh-UH"; return "eh-UH";
} }
Direction doDirection() const override { ShapeDirection doDirection() const override {
return Direction::BottomToTop; return ShapeDirection::BottomToTop;
} }
void doGlyphsInto(const Containers::StridedArrayView1D<UnsignedInt>&, const Containers::StridedArrayView1D<Vector2>&, const Containers::StridedArrayView1D<Vector2>&) const override {} void doGlyphsInto(const Containers::StridedArrayView1D<UnsignedInt>&, const Containers::StridedArrayView1D<Vector2>&, const Containers::StridedArrayView1D<Vector2>&) const override {}
@ -528,7 +519,7 @@ void AbstractShaperTest::shapeZeroGlyphs() {
CORRADE_COMPARE(shaper.glyphCount(), 0); CORRADE_COMPARE(shaper.glyphCount(), 0);
CORRADE_COMPARE(shaper.script(), Script::LinearA); CORRADE_COMPARE(shaper.script(), Script::LinearA);
CORRADE_COMPARE(shaper.language(), "eh-UH"); CORRADE_COMPARE(shaper.language(), "eh-UH");
CORRADE_COMPARE(shaper.direction(), Direction::BottomToTop); CORRADE_COMPARE(shaper.direction(), ShapeDirection::BottomToTop);
} }
void AbstractShaperTest::shapeBeginEndOutOfRange() { void AbstractShaperTest::shapeBeginEndOutOfRange() {

2
src/Magnum/Text/Test/CMakeLists.txt

@ -77,6 +77,8 @@ endif()
corrade_add_test(TextAbstractShaperTest AbstractShaperTest.cpp corrade_add_test(TextAbstractShaperTest AbstractShaperTest.cpp
LIBRARIES MagnumTextTestLib) LIBRARIES MagnumTextTestLib)
corrade_add_test(TextDirectionTest DirectionTest.cpp LIBRARIES MagnumText)
corrade_add_test(TextFeatureTest FeatureTest.cpp LIBRARIES MagnumTextTestLib) corrade_add_test(TextFeatureTest FeatureTest.cpp LIBRARIES MagnumTextTestLib)
corrade_add_test(TextScriptTest ScriptTest.cpp LIBRARIES MagnumTextTestLib) corrade_add_test(TextScriptTest ScriptTest.cpp LIBRARIES MagnumTextTestLib)

52
src/Magnum/Text/Test/DirectionTest.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š <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)

1
src/Magnum/Text/Text.h

@ -42,6 +42,7 @@ class AbstractLayouter;
class AbstractShaper; class AbstractShaper;
enum class Alignment: UnsignedByte; enum class Alignment: UnsignedByte;
enum class ShapeDirection: UnsignedByte;
class AbstractGlyphCache; class AbstractGlyphCache;

Loading…
Cancel
Save