Magnum::Text::StbTrueTypeFont class

TrueType font plugin using stb_truetype.

Supports opening fonts of the following formats either from file or from memory location using the stb_truetype library:

  • TrueType fonts (*.ttf)
  • OpenType / Type 2 fonts (*.otf)

This plugin depends on the Text library and is built if WITH_STBTRUETYPEFONT is enabled when building Magnum Plugins and depends on the Text library. To use as a dynamic plugin, you need to load the "StbTrueTypeFont" plugin from MAGNUM_PLUGINS_FONT_DIR. To use as a static plugin or as a dependency of another plugin with CMake, you need to request the StbTrueTypeFont component of the MagnumPlugins package and link to the MagnumPlugins::StbTrueTypeFont target. See Downloading and building plugins, Plugin usage with CMake and Loading and using plugins for more information.

This plugin provides the TrueTypeFont and OpenTypeFont plugins, but please note that this plugin trades the simplicity and portability for various limitations, the most visible being the lack of autohinting. That causes the rendered glyphs looking blurry compared to for example FreeTypeFont and because of that the font properties and sizes don't exactly match properties of fonts opened with FreeTypeFont using the same size.

Base classes

class AbstractFont
Base for font plugins.

Constructors, destructors, conversion operators

StbTrueTypeFont() explicit
Default constructor.
StbTrueTypeFont(PluginManager::AbstractManager& manager, const std::string& plugin) explicit
Plugin manager constructor.

Private functions

auto doFeatures() const override -> Features virtual
Implementation for features()
auto doIsOpened() const override -> bool virtual
Implementation for isOpened()
auto doOpenSingleData(Containers::ArrayView<const char> data, Float size) override -> Metrics virtual
Implementation for openSingleData()
void doClose() override virtual
Implementation for close()
auto doGlyphId(char32_t character) override -> UnsignedInt virtual
Implementation for glyphId()
auto doGlyphAdvance(UnsignedInt glyph) override -> Vector2 virtual
Implementation for glyphAdvance()
void doFillGlyphCache(GlyphCache& cache, const std::u32string& characters) override virtual
Implementation for fillGlyphCache()
auto doLayout(const GlyphCache& cache, Float size, const std::string& text) override -> std::unique_ptr<AbstractLayouter> virtual
Implementation for layout()

Function documentation

Metrics Magnum::Text::StbTrueTypeFont::doOpenSingleData(Containers::ArrayView<const char> data, Float size) override virtual private

Implementation for openSingleData()

Return metrics of opened font on successful opening, zeros otherwise.

void Magnum::Text::StbTrueTypeFont::doFillGlyphCache(GlyphCache& cache, const std::u32string& characters) override virtual private

Implementation for fillGlyphCache()

The string is converted from UTF-8 to UTF-32, unique characters are not removed.