@@ -88,22 +88,53 @@ FontAtlas* FontAtlasCache::getFontAtlasTTF(const _ttfConfig* config)
8888 return nullptr ;
8989}
9090
91- FontAtlas* FontAtlasCache::getFontAtlasFNT (const std::string& fontFileName, const Vec2& imageOffset /* = Vec2::ZERO */ )
91+ FontAtlas* FontAtlasCache::getFontAtlasFNT (const std::string& fontFileName)
9292{
93- auto realFontFilename = FileUtils::getInstance ()->getNewFilename (fontFileName); // resolves real file path, to prevent storing multiple atlases for the same file.
93+ return getFontAtlasFNT (fontFileName, Rect::ZERO, false );
94+ }
95+
96+ FontAtlas* FontAtlasCache::getFontAtlasFNT (const std::string& fontFileName, const std::string& subTextureKey)
97+ {
98+ const auto realFontFilename = FileUtils::getInstance ()->getNewFilename (fontFileName); // resolves real file path, to prevent storing multiple atlases for the same file.
99+ std::string atlasName = subTextureKey + " " + realFontFilename;
100+
101+ const auto it = _atlasMap.find (atlasName);
102+ if (it == _atlasMap.end ())
103+ {
104+ const auto font = FontFNT::create (realFontFilename, subTextureKey);
105+
106+ if (font)
107+ {
108+ const auto tempAtlas = font->createFontAtlas ();
109+ if (tempAtlas)
110+ {
111+ _atlasMap[atlasName] = tempAtlas;
112+ return _atlasMap[atlasName];
113+ }
114+ }
115+ }
116+ else
117+ return it->second ;
118+
119+ return nullptr ;
120+ }
121+
122+ FontAtlas* FontAtlasCache::getFontAtlasFNT (const std::string& fontFileName, const Rect& imageRect, bool imageRotated)
123+ {
124+ const auto realFontFilename = FileUtils::getInstance ()->getNewFilename (fontFileName); // resolves real file path, to prevent storing multiple atlases for the same file.
94125 char keyPrefix[ATLAS_MAP_KEY_PREFIX_BUFFER_SIZE];
95- snprintf (keyPrefix, ATLAS_MAP_KEY_PREFIX_BUFFER_SIZE, " %.2f %.2f " , imageOffset. x , imageOffset .y );
126+ snprintf (keyPrefix, ATLAS_MAP_KEY_PREFIX_BUFFER_SIZE, " %.2f %.2f " , imageRect. origin . x , imageRect. origin .y );
96127 std::string atlasName (keyPrefix);
97128 atlasName += realFontFilename;
98129
99- auto it = _atlasMap.find (atlasName);
130+ const auto it = _atlasMap.find (atlasName);
100131 if ( it == _atlasMap.end () )
101132 {
102- auto font = FontFNT::create (realFontFilename, imageOffset );
133+ const auto font = FontFNT::create (realFontFilename, imageRect, imageRotated );
103134
104135 if (font)
105136 {
106- auto tempAtlas = font->createFontAtlas ();
137+ const auto tempAtlas = font->createFontAtlas ();
107138 if (tempAtlas)
108139 {
109140 _atlasMap[atlasName] = tempAtlas;
@@ -117,9 +148,14 @@ FontAtlas* FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName, cons
117148 return nullptr ;
118149}
119150
151+ FontAtlas* FontAtlasCache::getFontAtlasFNT (const std::string& fontFileName, const Vec2& imageOffset)
152+ {
153+ return getFontAtlasFNT (fontFileName, Rect (imageOffset.x , imageOffset.y , 0 , 0 ), false );
154+ }
155+
120156FontAtlas* FontAtlasCache::getFontAtlasCharMap (const std::string& plistFile)
121157{
122- std::string atlasName = plistFile;
158+ const std::string& atlasName = plistFile;
123159
124160 auto it = _atlasMap.find (atlasName);
125161 if ( it == _atlasMap.end () )
@@ -220,10 +256,10 @@ bool FontAtlasCache::releaseFontAtlas(FontAtlas *atlas)
220256 return false ;
221257}
222258
223- void FontAtlasCache::reloadFontAtlasFNT (const std::string& fontFileName, const Vec2& imageOffset /* = Vec2::ZERO */ )
259+ void FontAtlasCache::reloadFontAtlasFNT (const std::string& fontFileName, const Rect& imageRect, bool imageRotated )
224260{
225261 char keyPrefix[ATLAS_MAP_KEY_PREFIX_BUFFER_SIZE];
226- snprintf (keyPrefix, ATLAS_MAP_KEY_PREFIX_BUFFER_SIZE, " %.2f %.2f " , imageOffset. x , imageOffset .y );
262+ snprintf (keyPrefix, ATLAS_MAP_KEY_PREFIX_BUFFER_SIZE, " %.2f %.2f " , imageRect. origin . x , imageRect. origin .y );
227263 std::string atlasName (keyPrefix);
228264 atlasName += fontFileName;
229265
@@ -234,7 +270,7 @@ void FontAtlasCache::reloadFontAtlasFNT(const std::string& fontFileName, const V
234270 _atlasMap.erase (it);
235271 }
236272 FontFNT::reloadBMFontResource (fontFileName);
237- auto font = FontFNT::create (fontFileName, imageOffset );
273+ auto font = FontFNT::create (fontFileName, imageRect, imageRotated );
238274 if (font)
239275 {
240276 auto tempAtlas = font->createFontAtlas ();
@@ -243,7 +279,11 @@ void FontAtlasCache::reloadFontAtlasFNT(const std::string& fontFileName, const V
243279 _atlasMap[atlasName] = tempAtlas;
244280 }
245281 }
282+ }
246283
284+ void FontAtlasCache::reloadFontAtlasFNT (const std::string& fontFileName, const Vec2& imageOffset)
285+ {
286+ reloadFontAtlasFNT (fontFileName, Rect (imageOffset.x , imageOffset.y , 0 , 0 ), false );
247287}
248288
249289void FontAtlasCache::unloadFontAtlasTTF (const std::string& fontFileName)
0 commit comments