Use the same FT library reference on all loadTrueTypeFont() calls

This commit is contained in:
David Capello 2017-08-22 13:00:49 -03:00
parent e392934afc
commit 7fb7db9542
3 changed files with 21 additions and 9 deletions

View File

@ -17,8 +17,10 @@
namespace she { namespace she {
FreeTypeFont::FreeTypeFont(const char* filename, int height) FreeTypeFont::FreeTypeFont(ft::Lib& lib,
: m_face(m_ft.open(filename)) const char* filename,
const int height)
: m_face(lib.open(filename))
{ {
if (m_face.isValid()) if (m_face.isValid())
m_face.setSize(height); m_face.setSize(height);
@ -73,9 +75,11 @@ bool FreeTypeFont::hasCodePoint(int codepoint) const
return m_face.hasCodePoint(codepoint); 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()) { if (!font->isValid()) {
delete font; delete font;
font = nullptr; font = nullptr;

View File

@ -19,7 +19,9 @@ namespace she {
public: public:
typedef ft::Face Face; typedef ft::Face Face;
FreeTypeFont(const char* filename, int height); FreeTypeFont(ft::Lib& lib,
const char* filename,
const int height);
~FreeTypeFont(); ~FreeTypeFont();
bool isValid() const; bool isValid() const;
@ -35,11 +37,12 @@ namespace she {
Face& face() { return m_face; } Face& face() { return m_face; }
private: private:
mutable ft::Lib m_ft;
mutable Face m_face; 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 } // namespace she

View File

@ -1,5 +1,5 @@
// SHE library // 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. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -18,6 +18,8 @@
#include "she/native_dialogs.h" #include "she/native_dialogs.h"
#endif #endif
#include "base/unique_ptr.h"
#include "ft/lib.h"
#include "she/common/freetype_font.h" #include "she/common/freetype_font.h"
#include "she/common/sprite_sheet_font.h" #include "she/common/sprite_sheet_font.h"
#include "she/system.h" #include "she/system.h"
@ -75,7 +77,9 @@ public:
} }
Font* loadTrueTypeFont(const char* filename, int height) override { 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 { KeyModifiers keyModifiers() override {
@ -99,6 +103,7 @@ public:
private: private:
NativeDialogs* m_nativeDialogs; NativeDialogs* m_nativeDialogs;
base::UniquePtr<ft::Lib> m_ft;
}; };
} // namespace she } // namespace she