CCFontAtlasCache.h 3.0 KB

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