|
|
|
|
@ -26,13 +26,27 @@
|
|
|
|
|
namespace Magnum { namespace Text { |
|
|
|
|
|
|
|
|
|
Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size): _size(size) { |
|
|
|
|
/** @todo Use delegating constructor when GCC 4.6 support is dropped */ |
|
|
|
|
create(renderer, fontFile); |
|
|
|
|
#ifndef MAGNUM_TARGET_GLES |
|
|
|
|
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); |
|
|
|
|
#else |
|
|
|
|
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/* Create FreeType font */ |
|
|
|
|
CORRADE_INTERNAL_ASSERT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); |
|
|
|
|
CORRADE_INTERNAL_ASSERT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); |
|
|
|
|
|
|
|
|
|
/* Create Harfbuzz font */ |
|
|
|
|
_hbFont = hb_ft_font_create(_ftFont, nullptr); |
|
|
|
|
|
|
|
|
|
/* Set up the texture */ |
|
|
|
|
_texture.setWrapping(Texture2D::Wrapping::ClampToEdge) |
|
|
|
|
->setMinificationFilter(Texture2D::Filter::LinearInterpolation) |
|
|
|
|
->setMagnificationFilter(Texture2D::Filter::LinearInterpolation); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, const std::string& characters, const Vector2i& atlasSize): _size(size) { |
|
|
|
|
/** @todo Use delegating constructor when GCC 4.6 support is dropped */ |
|
|
|
|
create(renderer, fontFile); |
|
|
|
|
void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { |
|
|
|
|
glyphs.clear(); |
|
|
|
|
|
|
|
|
|
/** @bug Crash when atlas is too small */ |
|
|
|
|
/** @todo Get rid of duplicate characters */ |
|
|
|
|
@ -79,8 +93,8 @@ Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, co
|
|
|
|
|
|
|
|
|
|
/* Save character texture position and texture coordinates for given character index */ |
|
|
|
|
glyphs.insert({charIndices[i], std::make_tuple( |
|
|
|
|
Rectangle::fromSize(Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height())/size, |
|
|
|
|
Vector2(charPositions[i].size())/size), |
|
|
|
|
Rectangle::fromSize(Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height())/_size, |
|
|
|
|
Vector2(charPositions[i].size())/_size), |
|
|
|
|
Rectangle(Vector2(charPositions[i].bottomLeft())/atlasSize, |
|
|
|
|
Vector2(charPositions[i].topRight())/atlasSize) |
|
|
|
|
)}); |
|
|
|
|
@ -94,26 +108,6 @@ Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, co
|
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Font::create(FontRenderer& renderer, const std::string& fontFile) { |
|
|
|
|
#ifndef MAGNUM_TARGET_GLES |
|
|
|
|
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); |
|
|
|
|
#else |
|
|
|
|
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/* Create FreeType font */ |
|
|
|
|
CORRADE_INTERNAL_ASSERT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); |
|
|
|
|
CORRADE_INTERNAL_ASSERT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); |
|
|
|
|
|
|
|
|
|
/* Create Harfbuzz font */ |
|
|
|
|
_hbFont = hb_ft_font_create(_ftFont, nullptr); |
|
|
|
|
|
|
|
|
|
/* Set up the texture */ |
|
|
|
|
_texture.setWrapping(Texture2D::Wrapping::ClampToEdge) |
|
|
|
|
->setMinificationFilter(Texture2D::Filter::LinearInterpolation) |
|
|
|
|
->setMagnificationFilter(Texture2D::Filter::LinearInterpolation); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Font::destroy() { |
|
|
|
|
if(!_ftFont) return; |
|
|
|
|
|
|
|
|
|
|