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;
|
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 {
|
struct LineBreakGlyph {
|
||||||
FT_UInt glyphIndex;
|
FT_UInt glyphIndex;
|
||||||
int paintPosition;
|
int paintPosition;
|
||||||
|
@ -269,6 +272,11 @@ public:
|
||||||
std::string getFontFile(const char* family_name) {
|
std::string getFontFile(const char* family_name) {
|
||||||
std::string fontPath = 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
|
// check if the parameter is a font file shipped with the application
|
||||||
std::string lowerCasePath = fontPath;
|
std::string lowerCasePath = fontPath;
|
||||||
std::transform(lowerCasePath.begin(), lowerCasePath.end(), lowerCasePath.begin(), ::tolower);
|
std::transform(lowerCasePath.begin(), lowerCasePath.end(), lowerCasePath.begin(), ::tolower);
|
||||||
|
@ -278,6 +286,7 @@ public:
|
||||||
FILE *f = fopen(fontPath.c_str(), "r");
|
FILE *f = fopen(fontPath.c_str(), "r");
|
||||||
if ( f ) {
|
if ( f ) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
fontCache.insert(std::pair<std::string, std::string>(family_name, fontPath));
|
||||||
return fontPath;
|
return fontPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,6 +306,7 @@ public:
|
||||||
FcPatternDestroy(font);
|
FcPatternDestroy(font);
|
||||||
FcPatternDestroy(pattern);
|
FcPatternDestroy(pattern);
|
||||||
|
|
||||||
|
fontCache.insert(std::pair<std::string, std::string>(family_name, fontPath));
|
||||||
return fontPath;
|
return fontPath;
|
||||||
}
|
}
|
||||||
FcPatternDestroy(font);
|
FcPatternDestroy(font);
|
||||||
|
|
Loading…
Reference in New Issue