mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-09-03 05:37:55 -04:00
Rewrite GLFont loading routine with correct paths computation
This commit is contained in:
parent
f2f8b311ef
commit
a558102cc5
@ -139,12 +139,12 @@ int GLFontChar::getIndex() {
|
|||||||
return index;
|
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) {
|
lineHeight(0), base(0), imageWidth(0), imageHeight(0), loaded(false), texId(0), gcCounter(0) {
|
||||||
|
|
||||||
fontSizeClass = size;
|
fontSizeClass = size;
|
||||||
|
|
||||||
fontFileSource = fontFileName;
|
fontDefFileSource = defFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFont::~GLFont() {
|
GLFont::~GLFont() {
|
||||||
@ -201,44 +201,42 @@ void GLFont::loadFontOnce() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//relative path with filename where the font is
|
|
||||||
std::wstring fontFile = fontFileSource;
|
|
||||||
|
|
||||||
wxString resourceFolder = RES_FOLDER;
|
wxString resourceFolder = RES_FOLDER;
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
resourceFolder = getExePath() + L"/" + resourceFolder;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//full font file path
|
//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());
|
wxFileName exePath = wxFileName(wxStandardPaths::Get().GetExecutablePath());
|
||||||
|
|
||||||
//Full Path where the fonts are, including file name
|
//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
|
if (!fontDefFileName.FileExists()) {
|
||||||
resourceFolder = fontFileName.GetPath();
|
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
|
//Re-compute the resource dir.
|
||||||
fontFileSource = fontFileName.GetFullPath(wxPATH_NATIVE).ToStdWstring();
|
resourceFolder = fontDefFileName.GetPath();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
std::wstring fontDefFileNamePath = fontDefFileName.GetFullPath(wxPATH_NATIVE).ToStdWstring();
|
||||||
|
|
||||||
std::wifstream input;
|
std::wifstream input;
|
||||||
std::string inpFileStr(fontFileSource.begin(), fontFileSource.end());
|
std::string inpFileStr(fontDefFileNamePath.begin(), fontDefFileNamePath.end());
|
||||||
input.open(inpFileStr, std::ios::in);
|
input.open(inpFileStr, std::ios::in);
|
||||||
|
|
||||||
std::wstring op;
|
std::wstring op;
|
||||||
@ -445,11 +443,11 @@ void GLFont::loadFontOnce() {
|
|||||||
ofs += 8;
|
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;
|
loaded = true;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Error loading font file " << fontFileSource << std::endl;
|
std::cout << "Error loading font file " << imageFile << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.close();
|
input.close();
|
||||||
|
@ -159,9 +159,15 @@ private:
|
|||||||
std::vector<float> gl_vertices;
|
std::vector<float> gl_vertices;
|
||||||
std::vector<float> gl_uv;
|
std::vector<float> gl_uv;
|
||||||
|
|
||||||
|
//The font name as written in the def file.
|
||||||
std::wstring fontName;
|
std::wstring fontName;
|
||||||
|
|
||||||
|
//The full path font PNG filename
|
||||||
std::wstring imageFile;
|
std::wstring imageFile;
|
||||||
std::wstring fontFileSource;
|
|
||||||
|
//the real path location of the font definition file
|
||||||
|
std::wstring fontDefFileSource;
|
||||||
|
|
||||||
GLuint texId;
|
GLuint texId;
|
||||||
int gcCounter;
|
int gcCounter;
|
||||||
std::mutex cache_busy;
|
std::mutex cache_busy;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user