2013-07-20 01:33:26 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 Zynga Inc.
|
2015-03-24 14:12:58 +08:00
|
|
|
Copyright (c) 2013-2015 Chukong Technologies Inc.
|
2013-07-20 01:33:26 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2015-03-24 20:23:51 +08:00
|
|
|
|
2013-07-20 01:33:26 +08:00
|
|
|
#ifndef _CCFontAtlas_h_
|
|
|
|
#define _CCFontAtlas_h_
|
|
|
|
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @cond DO_NOT_SHOW
|
|
|
|
|
2014-05-08 11:12:59 +08:00
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
2013-07-20 01:33:26 +08:00
|
|
|
|
2014-09-10 08:17:07 +08:00
|
|
|
#include "platform/CCPlatformMacros.h"
|
2014-09-10 07:50:02 +08:00
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "platform/CCStdC.h" // ssize_t on windows
|
|
|
|
|
2013-07-20 01:33:26 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-08-07 05:37:19 +08:00
|
|
|
class Font;
|
2014-01-17 13:35:58 +08:00
|
|
|
class Texture2D;
|
2014-03-14 14:59:26 +08:00
|
|
|
class EventCustom;
|
|
|
|
class EventListenerCustom;
|
2015-07-28 16:28:32 +08:00
|
|
|
class FontFreeType;
|
2013-08-07 05:37:19 +08:00
|
|
|
|
2013-07-20 01:33:26 +08:00
|
|
|
struct FontLetterDefinition
|
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
float U;
|
|
|
|
float V;
|
|
|
|
float width;
|
|
|
|
float height;
|
|
|
|
float offsetX;
|
|
|
|
float offsetY;
|
|
|
|
int textureID;
|
|
|
|
bool validDefinition;
|
2014-01-21 17:55:49 +08:00
|
|
|
int xAdvance;
|
2013-07-20 01:33:26 +08:00
|
|
|
};
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
class CC_DLL FontAtlas : public Ref
|
2013-07-20 01:33:26 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-03-05 15:54:40 +08:00
|
|
|
static const int CacheTextureWidth;
|
|
|
|
static const int CacheTextureHeight;
|
2015-01-21 21:58:18 +08:00
|
|
|
static const char* CMD_PURGE_FONTATLAS;
|
|
|
|
static const char* CMD_RESET_FONTATLAS;
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-08-06 08:49:20 +08:00
|
|
|
FontAtlas(Font &theFont);
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-25 01:22:46 +08:00
|
|
|
virtual ~FontAtlas();
|
|
|
|
|
2015-07-24 18:38:45 +08:00
|
|
|
void addLetterDefinition(char16_t utf16Char, const FontLetterDefinition &letterDefinition);
|
|
|
|
bool getLetterDefinitionForChar(char16_t utf16Char, FontLetterDefinition &letterDefinition);
|
2013-07-25 01:22:46 +08:00
|
|
|
|
2014-05-08 11:12:59 +08:00
|
|
|
bool prepareLetterDefinitions(const std::u16string& utf16String);
|
2013-10-29 20:25:03 +08:00
|
|
|
|
2014-03-20 11:58:36 +08:00
|
|
|
inline const std::unordered_map<ssize_t, Texture2D*>& getTextures() const{ return _atlasTextures;}
|
2014-03-05 16:51:16 +08:00
|
|
|
void addTexture(Texture2D *texture, int slot);
|
2015-07-24 18:38:45 +08:00
|
|
|
float getLineHeight() const { return _lineHeight; }
|
|
|
|
void setLineHeight(float newHeight);
|
2013-08-06 07:35:15 +08:00
|
|
|
|
2014-03-05 16:51:16 +08:00
|
|
|
Texture2D* getTexture(int slot);
|
2015-07-24 18:38:45 +08:00
|
|
|
const Font* getFont() const { return _font; }
|
2014-03-14 14:59:26 +08:00
|
|
|
|
2014-07-09 23:03:04 +08:00
|
|
|
/** listen the event that renderer was recreated on Android/WP8
|
|
|
|
It only has effect on Android and WP8.
|
2014-03-14 14:59:26 +08:00
|
|
|
*/
|
2014-07-09 23:03:04 +08:00
|
|
|
void listenRendererRecreated(EventCustom *event);
|
2013-07-20 01:33:26 +08:00
|
|
|
|
2014-03-14 14:59:26 +08:00
|
|
|
/** Removes textures atlas.
|
|
|
|
It will purge the textures atlas and if multiple texture exist in the FontAtlas.
|
|
|
|
*/
|
|
|
|
void purgeTexturesAtlas();
|
|
|
|
|
2014-03-27 15:35:51 +08:00
|
|
|
/** sets font texture parameters:
|
|
|
|
- GL_TEXTURE_MIN_FILTER = GL_LINEAR
|
|
|
|
- GL_TEXTURE_MAG_FILTER = GL_LINEAR
|
|
|
|
*/
|
|
|
|
void setAntiAliasTexParameters();
|
|
|
|
|
|
|
|
/** sets font texture parameters:
|
|
|
|
- GL_TEXTURE_MIN_FILTER = GL_NEAREST
|
|
|
|
- GL_TEXTURE_MAG_FILTER = GL_NEAREST
|
|
|
|
*/
|
|
|
|
void setAliasTexParameters();
|
|
|
|
|
2014-11-15 05:07:34 +08:00
|
|
|
protected:
|
2013-07-25 01:22:46 +08:00
|
|
|
void relaseTextures();
|
2015-07-28 16:28:32 +08:00
|
|
|
|
|
|
|
void findNewCharacters(const std::u16string& u16Text, std::unordered_map<unsigned short, unsigned short>& charCodeMap);
|
|
|
|
|
|
|
|
void conversionU16TOGB2312(const std::u16string& u16Text, std::unordered_map<unsigned short, unsigned short>& charCodeMap);
|
|
|
|
|
2014-03-20 11:58:36 +08:00
|
|
|
std::unordered_map<ssize_t, Texture2D*> _atlasTextures;
|
2015-07-24 18:38:45 +08:00
|
|
|
std::unordered_map<char16_t, FontLetterDefinition> _letterDefinitions;
|
|
|
|
float _lineHeight;
|
|
|
|
Font* _font;
|
2015-07-28 16:28:32 +08:00
|
|
|
FontFreeType* _fontFreeType;
|
|
|
|
void* _iconv;
|
2013-07-20 01:33:26 +08:00
|
|
|
|
2013-10-29 20:25:03 +08:00
|
|
|
// Dynamic GlyphCollection related stuff
|
2013-11-07 09:05:13 +08:00
|
|
|
int _currentPage;
|
|
|
|
unsigned char *_currentPageData;
|
|
|
|
int _currentPageDataSize;
|
|
|
|
float _currentPageOrigX;
|
|
|
|
float _currentPageOrigY;
|
2015-07-30 16:24:47 +08:00
|
|
|
int _letterPadding;
|
|
|
|
int _letterEdgeExtend;
|
2014-03-07 11:42:13 +08:00
|
|
|
|
|
|
|
int _fontAscender;
|
2014-07-09 23:03:04 +08:00
|
|
|
EventListenerCustom* _rendererRecreatedListener;
|
2014-03-27 15:35:51 +08:00
|
|
|
bool _antialiasEnabled;
|
2015-07-03 18:08:32 +08:00
|
|
|
int _currLineHeight;
|
2015-07-24 18:38:45 +08:00
|
|
|
|
|
|
|
friend class Label;
|
2013-07-20 01:33:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @endcond
|
2013-07-20 01:33:26 +08:00
|
|
|
#endif /* defined(__cocos2d_libs__CCFontAtlas__) */
|