Browse Source

Text: added AbstractFont::glyph{Id,Advance}() accessors.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
8bce85b308
  1. 12
      src/Text/AbstractFont.cpp
  2. 24
      src/Text/AbstractFont.h
  3. 4
      src/Text/Test/AbstractFontTest.cpp

12
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,

24
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()
*

4
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;
}

Loading…
Cancel
Save