2013-07-20 01:33:26 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 Zynga Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 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.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef _CCFontAtlas_h_
|
|
|
|
#define _CCFontAtlas_h_
|
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
#include <unordered_map>
|
2014-01-17 13:35:58 +08:00
|
|
|
#include "CCPlatformMacros.h"
|
|
|
|
#include "CCObject.h"
|
2013-07-20 01:33:26 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-08-07 05:37:19 +08:00
|
|
|
//fwd
|
|
|
|
class Font;
|
2014-01-17 13:35:58 +08:00
|
|
|
class Texture2D;
|
2013-08-07 05:37:19 +08:00
|
|
|
|
2013-07-20 01:33:26 +08:00
|
|
|
struct FontLetterDefinition
|
|
|
|
{
|
|
|
|
unsigned short letteCharUTF16;
|
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
|
|
|
};
|
|
|
|
|
2013-07-25 01:22:46 +08:00
|
|
|
class CC_DLL FontAtlas : public Object
|
2013-07-20 01:33:26 +08:00
|
|
|
{
|
|
|
|
public:
|
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();
|
|
|
|
|
2013-08-06 08:49:20 +08:00
|
|
|
void addLetterDefinition(const FontLetterDefinition &letterDefinition);
|
|
|
|
bool getLetterDefinitionForChar(unsigned short letteCharUTF16, FontLetterDefinition &outDefinition);
|
2013-07-25 01:22:46 +08:00
|
|
|
|
2013-10-29 20:25:03 +08:00
|
|
|
bool prepareLetterDefinitions(unsigned short *utf16String);
|
|
|
|
|
2013-08-06 08:49:20 +08:00
|
|
|
void addTexture(Texture2D &texture, int slot);
|
2013-09-13 11:46:46 +08:00
|
|
|
float getCommonLineHeight() const;
|
2013-07-25 01:22:46 +08:00
|
|
|
void setCommonLineHeight(float newHeight);
|
2013-08-06 07:35:15 +08:00
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
Texture2D& getTexture(int slot);
|
|
|
|
const Font* getFont() const;
|
2013-07-20 01:33:26 +08:00
|
|
|
|
|
|
|
private:
|
2013-10-29 20:25:03 +08:00
|
|
|
|
2013-07-25 01:22:46 +08:00
|
|
|
void relaseTextures();
|
2013-11-07 09:05:13 +08:00
|
|
|
std::unordered_map<int, Texture2D*> _atlasTextures;
|
|
|
|
std::unordered_map<unsigned short, FontLetterDefinition> _fontLetterDefinitions;
|
|
|
|
float _commonLineHeight;
|
|
|
|
Font * _font;
|
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;
|
|
|
|
float _currentPageLineHeight;
|
|
|
|
float _letterPadding;
|
2013-12-13 12:42:15 +08:00
|
|
|
bool _makeDistanceMap;
|
2013-07-20 01:33:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* defined(__cocos2d_libs__CCFontAtlas__) */
|