From 7da5cfbaae2f60fbf51f818ba7a01af5d018c3c0 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 7 May 2016 04:20:06 +0000 Subject: [PATCH] Don't hold all existing system fonts open. On Windows, this exhausts file descriptors and everything (e.g. opening and saving files) breaks. --- src/ttf.cpp | 11 ++++++++++- src/ttf.h | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ttf.cpp b/src/ttf.cpp index 2de0cad3..da9d2276 100644 --- a/src/ttf.cpp +++ b/src/ttf.cpp @@ -88,6 +88,7 @@ void TtfFontList::PlotString(const std::string &font, const std::string &str, [&](const TtfFont &tf) { return tf.FontFileBaseName() == font; }); if(!str.empty() && tf != &l.elem[l.n]) { + tf->LoadFromFile(fontLibrary, /*nameOnly=*/false); tf->PlotString(str, sbl, origin, u, v); } else { // No text or no font; so draw a big X for an error marker. @@ -116,7 +117,7 @@ std::string TtfFont::FontFileBaseName() const { // the letter shapes, and about the mappings that determine which glyph goes // with which character. //----------------------------------------------------------------------------- -bool TtfFont::LoadFromFile(FT_Library fontLibrary) { +bool TtfFont::LoadFromFile(FT_Library fontLibrary, bool nameOnly) { FT_Open_Args args = {}; args.flags = FT_OPEN_PATHNAME; args.pathname = &fontFile[0]; // FT_String is char* for historical reasons @@ -139,6 +140,12 @@ bool TtfFont::LoadFromFile(FT_Library fontLibrary) { name = std::string(fontFace->family_name) + " (" + std::string(fontFace->style_name) + ")"; + + if(nameOnly) { + FT_Done_Face(fontFace); + fontFace = NULL; + } + return true; } @@ -211,6 +218,8 @@ static const FT_Outline_Funcs outline_funcs = { void TtfFont::PlotString(const std::string &str, SBezierList *sbl, Vector origin, Vector u, Vector v) { + if(fontFace == NULL) oops(); + FT_Pos dx = 0; for(char32_t chr : ReadUTF8(str)) { uint32_t gid = FT_Get_Char_Index(fontFace, chr); diff --git a/src/ttf.h b/src/ttf.h index e7234be0..fb26ab95 100644 --- a/src/ttf.h +++ b/src/ttf.h @@ -16,7 +16,7 @@ public: FT_FaceRec_ *fontFace; std::string FontFileBaseName() const; - bool LoadFromFile(FT_LibraryRec_ *fontLibrary); + bool LoadFromFile(FT_LibraryRec_ *fontLibrary, bool nameOnly = true); void PlotString(const std::string &str, SBezierList *sbl, Vector origin, Vector u, Vector v);