diff --git a/text/font_mgr.cpp b/text/font_mgr.cpp index 9fb57d9ea..1668e0b00 100644 --- a/text/font_mgr.cpp +++ b/text/font_mgr.cpp @@ -39,12 +39,12 @@ FontRef FontMgr::loadSpriteSheetFont(const char* filename, int scale) return font; } -FontRef FontMgr::loadTrueTypeFont(const char* filename, int height) +FontRef FontMgr::loadTrueTypeFont(const char* filename, float size) { #if LAF_FREETYPE if (!m_ft) m_ft.reset(new ft::Lib()); - return FreeTypeFont::LoadFont(*m_ft.get(), filename, height); + return FreeTypeFont::LoadFont(*m_ft.get(), filename, size); #else return nullptr; #endif diff --git a/text/font_mgr.h b/text/font_mgr.h index 2a6f6a99d..064a348b0 100644 --- a/text/font_mgr.h +++ b/text/font_mgr.h @@ -23,7 +23,7 @@ namespace text { static FontMgrRef Make(); FontRef loadSpriteSheetFont(const char* filename, int scale); - FontRef loadTrueTypeFont(const char* filename, int height); + virtual FontRef loadTrueTypeFont(const char* filename, float size); virtual FontRef makeFont(const TypefaceRef& typeface) = 0; virtual FontRef makeFont(const TypefaceRef& typeface, float size) = 0; diff --git a/text/skia_font_mgr.cpp b/text/skia_font_mgr.cpp index 238d7d5d9..8e95a5805 100644 --- a/text/skia_font_mgr.cpp +++ b/text/skia_font_mgr.cpp @@ -109,6 +109,19 @@ SkiaFontMgr::~SkiaFontMgr() { } +FontRef SkiaFontMgr::loadTrueTypeFont(const char* filename, float size) +{ + // Use the native impl from Skia to load the font file + sk_sp face = m_skFontMgr->makeFromFile(filename); + if (!face) { + // In other case try the FreeType impl + return FontMgr::loadTrueTypeFont(filename, size); + } + + SkFont skFont(face, size); + return base::make_ref(skFont); +} + FontRef SkiaFontMgr::defaultFont(float size) const { sk_sp face = diff --git a/text/skia_font_mgr.h b/text/skia_font_mgr.h index d3169dfc6..9862fe449 100644 --- a/text/skia_font_mgr.h +++ b/text/skia_font_mgr.h @@ -51,6 +51,8 @@ class SkiaFontMgr : public FontMgr { SkiaFontMgr(); ~SkiaFontMgr(); + FontRef loadTrueTypeFont(const char* filename, float size) override; + FontRef defaultFont(float size) const override; FontRef makeFont(const TypefaceRef& typeface) override; FontRef makeFont(const TypefaceRef& typeface, float size) override;