diff --git a/source/graphics/Font.cpp b/source/graphics/Font.cpp index 65b69ed557..600238ced9 100644 --- a/source/graphics/Font.cpp +++ b/source/graphics/Font.cpp @@ -369,7 +369,7 @@ const CFont::GlyphData* CFont::ExtractAndGenerateGlyph(u16 codepoint) } m_IsDirty = true; - CVector2D offset{0,0}; + CVector2D offset{0.0f, 0.0f}; const FT_Render_Mode renderMode{FT_RENDER_MODE_NORMAL}; @@ -536,7 +536,7 @@ void CFont::BlendGlyphBitmapToTextureRGBA(const FT_Bitmap& bitmap, int targetX, u8* tempDstRow{dstRow + x * m_TextureFormatStride}; u8 alpha{srcRow[x]}; - const float srcAlpha{m_StrokeWidth > 0 ? (*m_GammaCorrectionLUT)[alpha] : alpha/255.0f}; + const float srcAlpha{m_StrokeWidth > 0 ? m_GammaCorrectionLUT[alpha] : alpha/255.0f}; const float dstAlpha{tempDstRow[3] / 255.0f}; const float outAlpha{srcAlpha + dstAlpha * (1.0f - srcAlpha)}; diff --git a/source/graphics/Font.h b/source/graphics/Font.h index cc8c865449..8232902cf9 100644 --- a/source/graphics/Font.h +++ b/source/graphics/Font.h @@ -46,7 +46,7 @@ namespace Renderer::Backend::Sampler { struct Desc; } class CFont { public: - CFont(FT_Library library, std::shared_ptr> gammaCorrection) : m_FreeType{library}, m_GammaCorrectionLUT{gammaCorrection} {}; + CFont(FT_Library library, const std::array& gammaCorrection) : m_FreeType{library}, m_GammaCorrectionLUT{gammaCorrection} {} ~CFont() = default; NONCOPYABLE(CFont); @@ -112,11 +112,15 @@ public: CTexturePtr GetTexture() const { return m_Texture; } void UploadTextureAtlasToGPU(); const GlyphData* GetGlyph(u16 i); + private: - static void ftFaceDeleter(FT_Face face) { + static void ftFaceDeleter(FT_Face face) + { FT_Done_Face(face); } - static void ftStrokerDeleter(FT_Stroker stroker) { + + static void ftStrokerDeleter(FT_Stroker stroker) + { FT_Stroker_Done(stroker); } @@ -173,7 +177,7 @@ private: float m_FontSize{0.0f}; std::string m_FontName; - std::shared_ptr> m_GammaCorrectionLUT{nullptr}; + const std::array& m_GammaCorrectionLUT; FT_Library m_FreeType; std::vector> m_FontsData; diff --git a/source/graphics/FontManager.cpp b/source/graphics/FontManager.cpp index d81238c5c9..9a981fbb7f 100644 --- a/source/graphics/FontManager.cpp +++ b/source/graphics/FontManager.cpp @@ -43,8 +43,11 @@ #include #include -namespace { -struct FontSpec { +namespace +{ + +struct FontSpec +{ std::string type; bool bold{false}; bool italic{false}; @@ -103,7 +106,7 @@ CFontManager::CFontManager() throw std::runtime_error{"Failed to initialize FreeType " + std::to_string(error)}; m_FreeType.reset(lib); - m_GammaCorrectionLUT = std::make_shared>(); + m_GammaCorrectionLUT = std::make_unique>(); std::generate(m_GammaCorrectionLUT->begin(), m_GammaCorrectionLUT->end(), [i = 0]() mutable { return std::pow((i++) / 255.0f, 1.0f / GAMMA_CORRECTION); @@ -189,7 +192,7 @@ std::shared_ptr CFontManager::LoadFont(CStrIntern fontName, CStrIntern lo }() }; - std::shared_ptr font{std::make_shared(this->m_FreeType.get(), m_GammaCorrectionLUT)}; + std::shared_ptr font{std::make_shared(this->m_FreeType.get(), *m_GammaCorrectionLUT)}; if (!font->SetFontParams(localeFontName.string(), fontSpec.size, fontSpec.stroke ? 1.0f : 0.0f, guiScale)) { diff --git a/source/graphics/FontManager.h b/source/graphics/FontManager.h index 65c5a7ae89..cee47f905d 100644 --- a/source/graphics/FontManager.h +++ b/source/graphics/FontManager.h @@ -44,12 +44,14 @@ public: void UploadTexturesAtlasToGPU(); private: - static void ftLibraryDeleter(FT_Library library) { + static void ftLibraryDeleter(FT_Library library) + { FT_Done_FreeType(library); } + std::unique_ptr m_FreeType{nullptr, &ftLibraryDeleter}; - std::shared_ptr> m_GammaCorrectionLUT; + std::unique_ptr> m_GammaCorrectionLUT; using FontsMap = std::unordered_map>; FontsMap m_Fonts;