mirror of https://github.com/axmolengine/axmol.git
refine
This commit is contained in:
parent
a93cbe8a32
commit
c3a8cabe5d
|
@ -34,6 +34,7 @@
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
std::unordered_map<std::string, FontAtlas *> FontAtlasCache::_atlasMap;
|
std::unordered_map<std::string, FontAtlas *> FontAtlasCache::_atlasMap;
|
||||||
|
#define ATLAS_MAP_KEY_BUFFER 255
|
||||||
|
|
||||||
void FontAtlasCache::purgeCachedData()
|
void FontAtlasCache::purgeCachedData()
|
||||||
{
|
{
|
||||||
|
@ -53,11 +54,13 @@ FontAtlas* FontAtlasCache::getFontAtlasTTF(const _ttfConfig* config)
|
||||||
useDistanceField = false;
|
useDistanceField = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char tmp[300];
|
char tmp[ATLAS_MAP_KEY_BUFFER];
|
||||||
if (useDistanceField) {
|
if (useDistanceField) {
|
||||||
sprintf(tmp, "%s distance field %f %d",config->fontFilePath.c_str(), config->fontSize, config->outlineSize);
|
snprintf(tmp, ATLAS_MAP_KEY_BUFFER, "df %.2f %d %s", config->fontSize, config->outlineSize,
|
||||||
|
config->fontFilePath.c_str());
|
||||||
} else {
|
} else {
|
||||||
sprintf(tmp, "%s %f %d",config->fontFilePath.c_str(), config->fontSize, config->outlineSize);
|
snprintf(tmp, ATLAS_MAP_KEY_BUFFER, "%.2f %d %s", config->fontSize, config->outlineSize,
|
||||||
|
config->fontFilePath.c_str());
|
||||||
}
|
}
|
||||||
std::string atlasName = tmp;
|
std::string atlasName = tmp;
|
||||||
|
|
||||||
|
@ -88,8 +91,8 @@ FontAtlas* FontAtlasCache::getFontAtlasTTF(const _ttfConfig* config)
|
||||||
|
|
||||||
FontAtlas* FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName, const Vec2& imageOffset /* = Vec2::ZERO */)
|
FontAtlas* FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName, const Vec2& imageOffset /* = Vec2::ZERO */)
|
||||||
{
|
{
|
||||||
char tmp[255];
|
char tmp[ATLAS_MAP_KEY_BUFFER];
|
||||||
sprintf(tmp, "%s %f %f", fontFileName.c_str(), imageOffset.x, imageOffset.y);
|
snprintf(tmp, ATLAS_MAP_KEY_BUFFER, "%.2f %.2f %s", imageOffset.x, imageOffset.y, fontFileName.c_str());
|
||||||
std::string atlasName = tmp;
|
std::string atlasName = tmp;
|
||||||
|
|
||||||
auto it = _atlasMap.find(atlasName);
|
auto it = _atlasMap.find(atlasName);
|
||||||
|
@ -176,8 +179,8 @@ FontAtlas* FontAtlasCache::getFontAtlasCharMap(Texture2D* texture, int itemWidth
|
||||||
|
|
||||||
FontAtlas* FontAtlasCache::getFontAtlasCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
FontAtlas* FontAtlasCache::getFontAtlasCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
|
||||||
{
|
{
|
||||||
char tmp[255];
|
char tmp[ATLAS_MAP_KEY_BUFFER];
|
||||||
snprintf(tmp,250,"name:%s_%d_%d_%d",charMapFile.c_str(),itemWidth,itemHeight,startCharMap);
|
snprintf(tmp, ATLAS_MAP_KEY_BUFFER, "%d %d %d %s", itemWidth, itemHeight, startCharMap, charMapFile.c_str());
|
||||||
std::string atlasName = tmp;
|
std::string atlasName = tmp;
|
||||||
|
|
||||||
auto it = _atlasMap.find(atlasName);
|
auto it = _atlasMap.find(atlasName);
|
||||||
|
@ -229,8 +232,8 @@ bool FontAtlasCache::releaseFontAtlas(FontAtlas *atlas)
|
||||||
|
|
||||||
void FontAtlasCache::reloadFontAtlasFNT(const std::string& fontFileName, const Vec2& imageOffset/* = Vec2::ZERO*/)
|
void FontAtlasCache::reloadFontAtlasFNT(const std::string& fontFileName, const Vec2& imageOffset/* = Vec2::ZERO*/)
|
||||||
{
|
{
|
||||||
char tmp[255];
|
char tmp[ATLAS_MAP_KEY_BUFFER];
|
||||||
sprintf(tmp, "%s %f %f", fontFileName.c_str(), imageOffset.x, imageOffset.y);
|
snprintf(tmp, ATLAS_MAP_KEY_BUFFER, "%.2f %.2f %s", imageOffset.x, imageOffset.y, fontFileName.c_str());
|
||||||
std::string atlasName = tmp;
|
std::string atlasName = tmp;
|
||||||
|
|
||||||
auto it = _atlasMap.find(atlasName);
|
auto it = _atlasMap.find(atlasName);
|
||||||
|
|
Loading…
Reference in New Issue