mirror of https://github.com/axmolengine/axmol.git
Merge pull request #2150 from Weeds/feature-linux-fontcache
[Linux] add cache for font family -> font path mapping
This commit is contained in:
commit
c404e03d26
|
@ -20,6 +20,9 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
// as FcFontMatch is quite an expensive call, cache the results of getFontFile
|
||||
static std::map<std::string, std::string> fontCache;
|
||||
|
||||
struct LineBreakGlyph {
|
||||
FT_UInt glyphIndex;
|
||||
int paintPosition;
|
||||
|
@ -269,6 +272,11 @@ public:
|
|||
std::string getFontFile(const char* family_name) {
|
||||
std::string fontPath = family_name;
|
||||
|
||||
std::map<std::string, std::string>::iterator it = fontCache.find(family_name);
|
||||
if ( it != fontCache.end() ) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
// check if the parameter is a font file shipped with the application
|
||||
std::string lowerCasePath = fontPath;
|
||||
std::transform(lowerCasePath.begin(), lowerCasePath.end(), lowerCasePath.begin(), ::tolower);
|
||||
|
@ -278,6 +286,7 @@ public:
|
|||
FILE *f = fopen(fontPath.c_str(), "r");
|
||||
if ( f ) {
|
||||
fclose(f);
|
||||
fontCache.insert(std::pair<std::string, std::string>(family_name, fontPath));
|
||||
return fontPath;
|
||||
}
|
||||
}
|
||||
|
@ -297,6 +306,7 @@ public:
|
|||
FcPatternDestroy(font);
|
||||
FcPatternDestroy(pattern);
|
||||
|
||||
fontCache.insert(std::pair<std::string, std::string>(family_name, fontPath));
|
||||
return fontPath;
|
||||
}
|
||||
FcPatternDestroy(font);
|
||||
|
|
Loading…
Reference in New Issue