CCFontAtlasCache.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /****************************************************************************
  2. Copyright (c) 2013 Zynga Inc.
  3. Copyright (c) 2013-2017 Chukong Technologies Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef _CCFontAtlasCache_h_
  22. #define _CCFontAtlasCache_h_
  23. /// @cond DO_NOT_SHOW
  24. #include <unordered_map>
  25. #include "base/ccTypes.h"
  26. NS_CC_BEGIN
  27. class FontAtlas;
  28. class Texture2D;
  29. struct _ttfConfig;
  30. class CC_DLL FontAtlasCache
  31. {
  32. public:
  33. static FontAtlas* getFontAtlasTTF(const _ttfConfig* config);
  34. static FontAtlas* getFontAtlasFNT(const std::string& fontFileName, const Vec2& imageOffset = Vec2::ZERO);
  35. static FontAtlas* getFontAtlasCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
  36. static FontAtlas* getFontAtlasCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
  37. static FontAtlas* getFontAtlasCharMap(const std::string& plistFile);
  38. static bool releaseFontAtlas(FontAtlas *atlas);
  39. /** Removes cached data.
  40. It will purge the textures atlas and if multiple texture exist in one FontAtlas.
  41. */
  42. static void purgeCachedData();
  43. /** Release current FNT texture and reload it.
  44. CAUTION : All component use this font texture should be reset font name, though the file name is same!
  45. otherwise, it will cause program crash!
  46. */
  47. static void reloadFontAtlasFNT(const std::string& fontFileName, const Vec2& imageOffset = Vec2::ZERO);
  48. /** Unload all texture atlas texture create by special file name.
  49. CAUTION : All component use this font texture should be reset font name, though the file name is same!
  50. otherwise, it will cause program crash!
  51. */
  52. static void unloadFontAtlasTTF(const std::string& fontFileName);
  53. private:
  54. static std::unordered_map<std::string, FontAtlas *> _atlasMap;
  55. };
  56. NS_CC_END
  57. /// @endcond
  58. #endif