diff --git a/src/Text/AbstractFont.cpp b/src/Text/AbstractFont.cpp index aad5e564a..c677e354e 100644 --- a/src/Text/AbstractFont.cpp +++ b/src/Text/AbstractFont.cpp @@ -103,6 +103,18 @@ void AbstractFont::close() { if(isOpened()) doClose(); } +UnsignedInt AbstractFont::glyphId(const char32_t character) { + CORRADE_ASSERT(isOpened(), "Text::AbstractFont::glyphId(): no font opened", 0); + + return doGlyphId(character); +} + +Vector2 AbstractFont::glyphAdvance(const UnsignedInt glyph) { + CORRADE_ASSERT(isOpened(), "Text::AbstractFont::glyphAdvance(): no font opened", {}); + + return doGlyphAdvance(glyph); +} + void AbstractFont::createGlyphCache(GlyphCache* const cache, const std::string& characters) { CORRADE_ASSERT(isOpened(), "Text::AbstractFont::createGlyphCache(): no font opened", ); CORRADE_ASSERT(!characters.empty() || features() & Feature::Enumerable, diff --git a/src/Text/AbstractFont.h b/src/Text/AbstractFont.h index 6b1450bc2..fb5bac9d5 100644 --- a/src/Text/AbstractFont.h +++ b/src/Text/AbstractFont.h @@ -147,6 +147,24 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin { /** @brief Font size */ Float size() const { return _size; } + /** + * @brief Glyph ID for given character + * + * @note This function is not meant to be used in performance-critical + * code, only for font observations and conversions. + */ + UnsignedInt glyphId(char32_t character); + + /** + * @brief Glyph advance + * @param glyph Glyph ID + * + * @note This function is not meant to be used in performance-critical + * code, only for font observations and conversions. + * @see glyphId() + */ + Vector2 glyphAdvance(UnsignedInt glyph); + /** * @brief Create glyph cache for given character set * @param cache Glyph cache instance @@ -210,6 +228,12 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin { /** @brief Implementation for close() */ virtual void doClose() = 0; + /** @brief Implementation for glyphId() */ + virtual UnsignedInt doGlyphId(char32_t character) = 0; + + /** @brief Implementation for glyphAdvance() */ + virtual Vector2 doGlyphAdvance(UnsignedInt glyph) = 0; + /** * @brief Implementation for createGlyphCache() * diff --git a/src/Text/Test/AbstractFontTest.cpp b/src/Text/Test/AbstractFontTest.cpp index ae0c147e9..6d3541c0f 100644 --- a/src/Text/Test/AbstractFontTest.cpp +++ b/src/Text/Test/AbstractFontTest.cpp @@ -59,6 +59,10 @@ class SingleDataFont: public Text::AbstractFont { void doCreateGlyphCache(GlyphCache*, const std::u32string&) override {} + UnsignedInt doGlyphId(char32_t) override { return 0; } + + Vector2 doGlyphAdvance(UnsignedInt) override { return {}; } + AbstractLayouter* doLayout(const GlyphCache*, Float, const std::string&) { return nullptr; }