From a558102cc585b443482d4fd4975b25cd9207316e Mon Sep 17 00:00:00 2001 From: vsonnier Date: Sat, 25 Jun 2016 17:41:54 +0200 Subject: [PATCH] Rewrite GLFont loading routine with correct paths computation --- src/util/GLFont.cpp | 56 ++++++++++++++++++++++----------------------- src/util/GLFont.h | 8 ++++++- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/util/GLFont.cpp b/src/util/GLFont.cpp index 8809fce..ae11be9 100644 --- a/src/util/GLFont.cpp +++ b/src/util/GLFont.cpp @@ -139,12 +139,12 @@ int GLFontChar::getIndex() { return index; } -GLFont::GLFont(GLFontSize size, std::wstring fontFileName): +GLFont::GLFont(GLFontSize size, std::wstring defFileName): lineHeight(0), base(0), imageWidth(0), imageHeight(0), loaded(false), texId(0), gcCounter(0) { fontSizeClass = size; - fontFileSource = fontFileName; + fontDefFileSource = defFileName; } GLFont::~GLFont() { @@ -201,44 +201,42 @@ void GLFont::loadFontOnce() { return; } - //relative path with filename where the font is - std::wstring fontFile = fontFileSource; - wxString resourceFolder = RES_FOLDER; -#ifdef WIN32 - resourceFolder = getExePath() + L"/" + resourceFolder; -#endif - //full font file path - wxFileName fontFileName = wxFileName(resourceFolder + L"/" + fontFile); + wxFileName fontDefFileName = wxFileName(resourceFolder + L"/" + fontDefFileSource); - if (!fontFileName.Exists()) { + if (!fontDefFileName.Exists()) { wxFileName exePath = wxFileName(wxStandardPaths::Get().GetExecutablePath()); //Full Path where the fonts are, including file name - fontFileName = wxFileName(exePath.GetPath() + L"/" + fontFile); + fontDefFileName = wxFileName(exePath.GetPath() + L"/"+ fontDefFileSource); - //Dir where the fonts are - resourceFolder = fontFileName.GetPath(); + if (!fontDefFileName.FileExists()) { + std::cout << "Font file " << fontDefFileName.GetFullPath() << " does not exist?" << std::endl; + return; + } + + if (!fontDefFileName.IsFileReadable()) { + std::cout << "Font file " << fontDefFileName.GetFullPath() << " is not readable?" << std::endl; + return; + } + } + else { + + if (!fontDefFileName.IsFileReadable()) { + std::cout << "Font file " << fontDefFileName.GetFullPath() << " is not readable?" << std::endl; + return; + } } - //overwrite with the full path - fontFileSource = fontFileName.GetFullPath(wxPATH_NATIVE).ToStdWstring(); - - if (!fontFileName.FileExists()) { - std::cout << "Font file " << fontFileSource << " does not exist?" << std::endl; - return; - } - - if (!fontFileName.IsFileReadable()) { - std::cout << "Font file " << fontFileSource << " is not readable?" << std::endl; - return; - } + //Re-compute the resource dir. + resourceFolder = fontDefFileName.GetPath(); + std::wstring fontDefFileNamePath = fontDefFileName.GetFullPath(wxPATH_NATIVE).ToStdWstring(); std::wifstream input; - std::string inpFileStr(fontFileSource.begin(), fontFileSource.end()); + std::string inpFileStr(fontDefFileNamePath.begin(), fontDefFileNamePath.end()); input.open(inpFileStr, std::ios::in); std::wstring op; @@ -445,11 +443,11 @@ void GLFont::loadFontOnce() { ofs += 8; } - std::cout << "Loaded font '" << fontName << "' from '" << fontFileSource << "', parsed " << characters.size() << " characters." << std::endl; + std::cout << "Loaded font '" << fontName << "' from '" << imageFile << "', parsed " << characters.size() << " characters." << std::endl; loaded = true; } else { - std::cout << "Error loading font file " << fontFileSource << std::endl; + std::cout << "Error loading font file " << imageFile << std::endl; } input.close(); diff --git a/src/util/GLFont.h b/src/util/GLFont.h index e6a7539..13d5281 100644 --- a/src/util/GLFont.h +++ b/src/util/GLFont.h @@ -159,9 +159,15 @@ private: std::vector gl_vertices; std::vector gl_uv; + //The font name as written in the def file. std::wstring fontName; + + //The full path font PNG filename std::wstring imageFile; - std::wstring fontFileSource; + + //the real path location of the font definition file + std::wstring fontDefFileSource; + GLuint texId; int gcCounter; std::mutex cache_busy;