@@ -88,22 +88,53 @@ FontAtlas* FontAtlasCache::getFontAtlasTTF(const _ttfConfig* config)
88
88
return nullptr ;
89
89
}
90
90
91
- FontAtlas* FontAtlasCache::getFontAtlasFNT (const std::string& fontFileName, const Vec2& imageOffset /* = Vec2::ZERO */ )
91
+ FontAtlas* FontAtlasCache::getFontAtlasFNT (const std::string& fontFileName)
92
92
{
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.
94
125
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 );
96
127
std::string atlasName (keyPrefix);
97
128
atlasName += realFontFilename;
98
129
99
- auto it = _atlasMap.find (atlasName);
130
+ const auto it = _atlasMap.find (atlasName);
100
131
if ( it == _atlasMap.end () )
101
132
{
102
- auto font = FontFNT::create (realFontFilename, imageOffset );
133
+ const auto font = FontFNT::create (realFontFilename, imageRect, imageRotated );
103
134
104
135
if (font)
105
136
{
106
- auto tempAtlas = font->createFontAtlas ();
137
+ const auto tempAtlas = font->createFontAtlas ();
107
138
if (tempAtlas)
108
139
{
109
140
_atlasMap[atlasName] = tempAtlas;
@@ -117,9 +148,14 @@ FontAtlas* FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName, cons
117
148
return nullptr ;
118
149
}
119
150
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
+
120
156
FontAtlas* FontAtlasCache::getFontAtlasCharMap (const std::string& plistFile)
121
157
{
122
- std::string atlasName = plistFile;
158
+ const std::string& atlasName = plistFile;
123
159
124
160
auto it = _atlasMap.find (atlasName);
125
161
if ( it == _atlasMap.end () )
@@ -220,10 +256,10 @@ bool FontAtlasCache::releaseFontAtlas(FontAtlas *atlas)
220
256
return false ;
221
257
}
222
258
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 )
224
260
{
225
261
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 );
227
263
std::string atlasName (keyPrefix);
228
264
atlasName += fontFileName;
229
265
@@ -234,7 +270,7 @@ void FontAtlasCache::reloadFontAtlasFNT(const std::string& fontFileName, const V
234
270
_atlasMap.erase (it);
235
271
}
236
272
FontFNT::reloadBMFontResource (fontFileName);
237
- auto font = FontFNT::create (fontFileName, imageOffset );
273
+ auto font = FontFNT::create (fontFileName, imageRect, imageRotated );
238
274
if (font)
239
275
{
240
276
auto tempAtlas = font->createFontAtlas ();
@@ -243,7 +279,11 @@ void FontAtlasCache::reloadFontAtlasFNT(const std::string& fontFileName, const V
243
279
_atlasMap[atlasName] = tempAtlas;
244
280
}
245
281
}
282
+ }
246
283
284
+ void FontAtlasCache::reloadFontAtlasFNT (const std::string& fontFileName, const Vec2& imageOffset)
285
+ {
286
+ reloadFontAtlasFNT (fontFileName, Rect (imageOffset.x , imageOffset.y , 0 , 0 ), false );
247
287
}
248
288
249
289
void FontAtlasCache::unloadFontAtlasTTF (const std::string& fontFileName)
0 commit comments