From b8bec35a0c38f5f21249e8a956d166a8fa23a412 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 2 Nov 2016 08:39:53 +0000 Subject: [PATCH] TTF: only call FT_Request_Size once after loading. --- src/ttf.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/ttf.cpp b/src/ttf.cpp index 3d3e1f4..f287917 100644 --- a/src/ttf.cpp +++ b/src/ttf.cpp @@ -147,6 +147,25 @@ bool TtfFont::LoadFromFile(FT_Library fontLibrary, bool nameOnly) { if(nameOnly) { FT_Done_Face(fontFace); fontFace = NULL; + return true; + } + + // We always ask Freetype to give us a unit size character. + // It uses fixed point; put the unit size somewhere in the middle of the dynamic + // range of its 26.6 fixed point type, and adjust the factors so that the unit + // matches cap height. + FT_Size_RequestRec sizeRequest; + sizeRequest.type = FT_SIZE_REQUEST_TYPE_REAL_DIM; + sizeRequest.width = 1 << 16; + sizeRequest.height = 1 << 16; + sizeRequest.horiResolution = 128; + sizeRequest.vertResolution = 128; + if(int fterr = FT_Request_Size(fontFace, &sizeRequest)) { + dbp("freetype: cannot set character size: %s", + ft_error_string(fterr)); + FT_Done_Face(fontFace); + fontFace = NULL; + return false; } return true; @@ -235,22 +254,6 @@ void TtfFont::PlotString(const std::string &str, chr, ft_error_string(gid)); } - // We always ask Freetype to give us a unit size character. - // It uses fixed point; put the unit size somewhere in the middle of the dynamic - // range of its 26.6 fixed point type, and adjust the factors so that the unit - // matches cap height. - FT_Size_RequestRec sizeRequest; - sizeRequest.type = FT_SIZE_REQUEST_TYPE_REAL_DIM; - sizeRequest.width = 1 << 16; - sizeRequest.height = 1 << 16; - sizeRequest.horiResolution = 128; - sizeRequest.vertResolution = 128; - if(int fterr = FT_Request_Size(fontFace, &sizeRequest)) { - dbp("freetype: cannot set character size: %s", - ft_error_string(fterr)); - return; - } - /* * Stupid hacks: * - if we want fake-bold, use FT_Outline_Embolden(). This actually looks