axmol/cocos2dx/label_nodes/CCFontAtlas.cpp

95 lines
1.7 KiB
C++
Raw Normal View History

2013-07-20 01:33:26 +08:00
//
// CCFontAtlas.cpp
// cocos2d_libs
//
// Created by Carlo Morgantini on 7/18/13.
//
//
#include "cocos2d.h"
#include "CCFontAtlas.h"
#include "CCFont.h"
2013-07-20 01:33:26 +08:00
NS_CC_BEGIN
2013-08-02 08:08:57 +08:00
FontAtlas::FontAtlas(Font &theFont) : _font(theFont)
{
2013-08-02 08:08:57 +08:00
_font.retain();
}
FontAtlas::~FontAtlas()
{
2013-08-02 08:08:57 +08:00
_font.release();
relaseTextures();
}
void FontAtlas::relaseTextures()
{
for( auto &item: _atlasTextures)
{
if ( item.second )
item.second->release();
}
_atlasTextures.clear();
}
void FontAtlas::addLetterDefinition(const FontLetterDefinition &letterDefinition)
2013-07-20 01:33:26 +08:00
{
_fontLetterDefinitions[letterDefinition.letteCharUTF16] = letterDefinition;
}
bool FontAtlas::getLetterDefinitionForChar(unsigned short letteCharUTF16, FontLetterDefinition &outDefinition)
2013-07-20 01:33:26 +08:00
{
auto outIterator = _fontLetterDefinitions.find(letteCharUTF16);
if (outIterator != _fontLetterDefinitions.end())
{
outDefinition = (*outIterator).second;
return true;
}
else
{
return false;
}
2013-07-20 01:33:26 +08:00
}
void FontAtlas::addTexture(Texture2D *pTexture, int slot)
{
pTexture->retain();
2013-07-20 01:33:26 +08:00
_atlasTextures[slot] = pTexture;
}
Texture2D * FontAtlas::getTexture(int slot)
{
return _atlasTextures[slot];
}
float FontAtlas::getCommonLineHeight()
{
return _commonLineHeight;
}
void FontAtlas::setCommonLineHeight(float newHeight)
{
_commonLineHeight = newHeight;
}
unsigned short int * FontAtlas::getUTF16Text(const char *pText, int &outNumLetters)
{
unsigned short* utf16String = cc_utf8_to_utf16(pText);
if(!utf16String)
return 0;
outNumLetters = cc_wcslen(utf16String);
return utf16String;
}
2013-08-02 08:08:57 +08:00
Font & FontAtlas::getFont()
{
return _font;
}
2013-07-20 01:33:26 +08:00
NS_CC_END