diff --git a/src/she/common/freetype_font.cpp b/src/she/common/freetype_font.cpp index 574b9a5c5..d0c60b5c4 100644 --- a/src/she/common/freetype_font.cpp +++ b/src/she/common/freetype_font.cpp @@ -17,8 +17,10 @@ namespace she { -FreeTypeFont::FreeTypeFont(const char* filename, int height) - : m_face(m_ft.open(filename)) +FreeTypeFont::FreeTypeFont(ft::Lib& lib, + const char* filename, + const int height) + : m_face(lib.open(filename)) { if (m_face.isValid()) m_face.setSize(height); @@ -73,9 +75,11 @@ bool FreeTypeFont::hasCodePoint(int codepoint) const return m_face.hasCodePoint(codepoint); } -FreeTypeFont* loadFreeTypeFont(const char* filename, int height) +FreeTypeFont* load_free_type_font(ft::Lib& lib, + const char* filename, + const int height) { - FreeTypeFont* font = new FreeTypeFont(filename, height); + FreeTypeFont* font = new FreeTypeFont(lib, filename, height); if (!font->isValid()) { delete font; font = nullptr; diff --git a/src/she/common/freetype_font.h b/src/she/common/freetype_font.h index 17a07fae8..6759451aa 100644 --- a/src/she/common/freetype_font.h +++ b/src/she/common/freetype_font.h @@ -19,7 +19,9 @@ namespace she { public: typedef ft::Face Face; - FreeTypeFont(const char* filename, int height); + FreeTypeFont(ft::Lib& lib, + const char* filename, + const int height); ~FreeTypeFont(); bool isValid() const; @@ -35,11 +37,12 @@ namespace she { Face& face() { return m_face; } private: - mutable ft::Lib m_ft; mutable Face m_face; }; - FreeTypeFont* loadFreeTypeFont(const char* filename, int height); + FreeTypeFont* load_free_type_font(ft::Lib& lib, + const char* filename, + const int height); } // namespace she diff --git a/src/she/common/system.h b/src/she/common/system.h index ad9d9ba18..2bbd97431 100644 --- a/src/she/common/system.h +++ b/src/she/common/system.h @@ -1,5 +1,5 @@ // SHE library -// Copyright (C) 2012-2016 David Capello +// Copyright (C) 2012-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -18,6 +18,8 @@ #include "she/native_dialogs.h" #endif +#include "base/unique_ptr.h" +#include "ft/lib.h" #include "she/common/freetype_font.h" #include "she/common/sprite_sheet_font.h" #include "she/system.h" @@ -75,7 +77,9 @@ public: } Font* loadTrueTypeFont(const char* filename, int height) override { - return loadFreeTypeFont(filename, height); + if (!m_ft) + m_ft.reset(new ft::Lib()); + return load_free_type_font(*m_ft.get(), filename, height); } KeyModifiers keyModifiers() override { @@ -99,6 +103,7 @@ public: private: NativeDialogs* m_nativeDialogs; + base::UniquePtr m_ft; }; } // namespace she