axmol/cocos/2d/CCFontAtlas.h

155 lines
4.6 KiB
C
Raw Normal View History

2013-07-20 01:33:26 +08:00
/****************************************************************************
Copyright (c) 2013 Zynga Inc.
2016-03-24 23:05:22 +08:00
Copyright (c) 2013-2016 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
#include <string>
#include <unordered_map>
2013-07-20 01:33:26 +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;
class Texture2D;
class EventCustom;
class EventListenerCustom;
class FontFreeType;
2013-08-07 05:37:19 +08:00
2013-07-20 01:33:26 +08:00
struct FontLetterDefinition
{
float U;
float V;
float width;
float height;
float offsetX;
float offsetY;
int textureID;
bool validDefinition;
int xAdvance;
2013-07-20 01:33:26 +08:00
};
class CC_DLL FontAtlas : public Ref
2013-07-20 01:33:26 +08:00
{
public:
static const int CacheTextureWidth;
static const int CacheTextureHeight;
static const char* CMD_PURGE_FONTATLAS;
static const char* CMD_RESET_FONTATLAS;
/**
* @js ctor
*/
2013-08-06 08:49:20 +08:00
FontAtlas(Font &theFont);
/**
* @js NA
* @lua NA
*/
virtual ~FontAtlas();
void addLetterDefinition(char16_t utf16Char, const FontLetterDefinition &letterDefinition);
bool getLetterDefinitionForChar(char16_t utf16Char, FontLetterDefinition &letterDefinition);
bool prepareLetterDefinitions(const std::u16string& utf16String);
2014-03-20 11:58:36 +08:00
inline const std::unordered_map<ssize_t, Texture2D*>& getTextures() const{ return _atlasTextures;}
void addTexture(Texture2D *texture, int slot);
float getLineHeight() const { return _lineHeight; }
void setLineHeight(float newHeight);
2013-08-06 07:35:15 +08:00
Texture2D* getTexture(int slot);
const Font* getFont() const { return _font; }
/** listen the event that renderer was recreated on Android/WP8
It only has effect on Android and WP8.
*/
void listenRendererRecreated(EventCustom *event);
2013-07-20 01:33:26 +08:00
/** Removes textures atlas.
It will purge the textures atlas and if multiple texture exist in the FontAtlas.
*/
void purgeTexturesAtlas();
/** 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:
2016-03-24 23:05:22 +08:00
void reset();
2015-11-06 16:36:24 +08:00
void releaseTextures();
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);
Add Label Overflow and wrap option. Squashed commit of the following: commit 7176582def3686f78701f92ead4d0976bccd115d Author: zilongshanren <guanghui8827@126.com> Date: Thu Nov 19 10:30:54 2015 +0800 add char map font test commit 7ea7c251ff549e4a74d5c5c3faa49893fe5defc4 Author: zilongshanren <guanghui8827@126.com> Date: Wed Nov 18 15:00:17 2015 +0800 system font overflow is not supported commit a02fe0c7f94692b95a0bfd6f194a94c4519cee3a Author: zilongshanren <guanghui8827@126.com> Date: Wed Nov 18 11:04:15 2015 +0800 add system font test commit eb098da8b16f485c86929a9b2ba00a64068264e9 Author: zilongshanren <guanghui8827@126.com> Date: Tue Nov 17 10:29:35 2015 +0800 Finish resize height mode commit ca78ba35abdbacc23bf6f8315454ec0a356a6aca Author: zilongshanren <guanghui8827@126.com> Date: Mon Nov 16 11:01:27 2015 +0800 fix wrap issue commit baf1a5e0dc3a08da0a13500aea5afc82017b054a Author: zilongshanren <guanghui8827@126.com> Date: Sat Nov 14 08:28:57 2015 +0800 horizontal shrink still has a issue commit 7e8abc0990cdf299d23c8072c5c1d4aa561bf798 Author: zilongshanren <guanghui8827@126.com> Date: Fri Nov 13 11:42:34 2015 +0800 finish shrink without wrap commit c9c45bd1f304ba00a6f9a274fa5631659a075bc1 Author: zilongshanren <guanghui8827@126.com> Date: Fri Nov 13 10:09:46 2015 +0800 update shrink commit ad82010ea846679e4d1a09f5127be29ae2e6adae Author: zilongshanren <guanghui8827@126.com> Date: Thu Nov 12 17:55:15 2015 +0800 refactor shrink logic commit effc1ee1cd9f06eaa4f46dd5c2a1401f6a285af6 Author: zilongshanren <guanghui8827@126.com> Date: Wed Nov 11 18:25:34 2015 +0800 add resize overflow type commit 194d552adc2a4ba2c439eff969b082556315e0ae Author: zilongshanren <guanghui8827@126.com> Date: Wed Nov 11 11:49:51 2015 +0800 no wrap, shrink is working. commit e2222ef14d5392817bd727895b3c2caec5ce4faf Author: zilongshanren <guanghui8827@126.com> Date: Tue Nov 10 16:16:27 2015 +0800 add overflow type to label. 1. optimize the testcase commit b65e2de4bfb3cb86a0d0cfa118be891a3f9fe858 Author: zilongshanren <guanghui8827@126.com> Date: Mon Nov 9 17:22:34 2015 +0800 finish bmfont wrap by char commit f339ff0309dc9e2ca2871f03f4551d329afce5e1 Author: zilongshanren <guanghui8827@126.com> Date: Mon Nov 9 17:04:51 2015 +0800 finish bmfont wrap by word commit 4c8edc65204a1294ac81315e72f1299acbdf43c0 Author: zilongshanren <guanghui8827@126.com> Date: Mon Nov 9 11:29:21 2015 +0800 add BMFont size support commit 3282481bda9dcb0f88b41f2568f7e5c856af6d53 Author: zilongshanren <guanghui8827@126.com> Date: Mon Nov 9 09:58:01 2015 +0800 add font size support for BMFONT commit 0c8e2a0374983625507a183cb2eb53a0b1709e25 Author: zilongshanren <guanghui8827@126.com> Date: Fri Nov 6 16:36:27 2015 +0800 add toggle wrap option. 1. make hirozontal clamp working commit 19dcd3e80a34c54b20934d08937eb270e689a7db Author: zilongshanren <guanghui8827@126.com> Date: Fri Nov 6 15:12:59 2015 +0800 tweak label layout commit e36a40babf4817ea7e9830614ac7560f2e69c583 Author: zilongshanren <guanghui8827@126.com> Date: Thu Nov 5 11:11:02 2015 +0800 finish the test skeleton commit a144a3a5d388d15c4f37cbfc12563eccabffb8e1 Author: zilongshanren <guanghui8827@126.com> Date: Wed Nov 4 16:38:54 2015 +0800 add setFontSize api to label. 1. add new chinese-english bmfont 2. beautify base test commit b22551c9eb3738fbb1c38ae4a3bfd07a202dcaf0 Author: zilongshanren <guanghui8827@126.com> Date: Wed Nov 4 11:27:18 2015 +0800 add label layout test skeleton
2015-11-19 16:06:13 +08:00
/**
* Scale each font letter by scaleFactor.
*
* @param scaleFactor A float scale factor for scaling font letter info.
*/
void scaleFontLetterDefinition(float scaleFactor);
2014-03-20 11:58:36 +08:00
std::unordered_map<ssize_t, Texture2D*> _atlasTextures;
std::unordered_map<char16_t, FontLetterDefinition> _letterDefinitions;
float _lineHeight;
Font* _font;
FontFreeType* _fontFreeType;
void* _iconv;
2013-07-20 01:33:26 +08:00
// Dynamic GlyphCollection related stuff
int _currentPage;
unsigned char *_currentPageData;
int _currentPageDataSize;
float _currentPageOrigX;
float _currentPageOrigY;
int _letterPadding;
int _letterEdgeExtend;
int _fontAscender;
EventListenerCustom* _rendererRecreatedListener;
bool _antialiasEnabled;
int _currLineHeight;
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__) */