From 57adfac002fe52b2095b65f5efaa11bd5fa7d57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Mar 2013 15:15:46 +0100 Subject: [PATCH] Text: moved font size to abstract base. --- src/Text/AbstractFont.cpp | 4 +++- src/Text/AbstractFont.h | 8 +++++++- src/Text/FreeTypeFont.cpp | 8 ++++---- src/Text/FreeTypeFont.h | 6 ------ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Text/AbstractFont.cpp b/src/Text/AbstractFont.cpp index 31214e636..049341ab9 100644 --- a/src/Text/AbstractFont.cpp +++ b/src/Text/AbstractFont.cpp @@ -26,10 +26,12 @@ namespace Magnum { namespace Text { -AbstractFont::AbstractFont() {} +AbstractFont::AbstractFont(Float size): _size(size) {} + AbstractFont::~AbstractFont() {} AbstractLayouter::AbstractLayouter(): _glyphCount(0) {} + AbstractLayouter::~AbstractLayouter() {} }} diff --git a/src/Text/AbstractFont.h b/src/Text/AbstractFont.h index 33456bfc4..cedfef2c9 100644 --- a/src/Text/AbstractFont.h +++ b/src/Text/AbstractFont.h @@ -48,9 +48,12 @@ class MAGNUM_TEXT_EXPORT AbstractFont { AbstractFont& operator=(const AbstractFont&&) = delete; public: - explicit AbstractFont(); + explicit AbstractFont(Float size); virtual ~AbstractFont() = 0; + /** @brief Font size */ + inline Float size() const { return _size; } + /** * @brief Create glyph cache for given character set * @param cache Glyph cache instance @@ -69,6 +72,9 @@ class MAGNUM_TEXT_EXPORT AbstractFont { * @see createGlyphCache() */ virtual AbstractLayouter* layout(const GlyphCache* const cache, const Float size, const std::string& text) = 0; + + private: + Float _size; }; /** diff --git a/src/Text/FreeTypeFont.cpp b/src/Text/FreeTypeFont.cpp index d60d86f90..ba01446c9 100644 --- a/src/Text/FreeTypeFont.cpp +++ b/src/Text/FreeTypeFont.cpp @@ -62,14 +62,14 @@ FreeTypeFontRenderer::~FreeTypeFontRenderer() { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Done_FreeType(_library) == 0); } -FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size): _size(size) { +FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size): AbstractFont(size) { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); - CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(_ftFont, 0, size*64, 100, 100) == 0); } -FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size): _size(size) { +FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size): AbstractFont(size) { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Memory_Face(renderer.library(), data, dataSize, 0, &_ftFont) == 0); - CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(_ftFont, 0, size*64, 100, 100) == 0); } void FreeTypeFont::createGlyphCache(GlyphCache* const cache, const std::string& characters) { diff --git a/src/Text/FreeTypeFont.h b/src/Text/FreeTypeFont.h index faa4f1d50..e6d52c176 100644 --- a/src/Text/FreeTypeFont.h +++ b/src/Text/FreeTypeFont.h @@ -102,9 +102,6 @@ class MAGNUM_TEXT_EXPORT FreeTypeFont: public AbstractFont { ~FreeTypeFont(); - /** @brief Font size */ - inline Float size() const { return _size; } - /** @brief FreeType font handle */ inline FT_Face font() { return _ftFont; } @@ -117,9 +114,6 @@ class MAGNUM_TEXT_EXPORT FreeTypeFont: public AbstractFont { protected: #endif FT_Face _ftFont; - - private: - Float _size; }; }}