2013-07-25 01:22:46 +08:00
|
|
|
//
|
|
|
|
// CCFontAtlasFactory.cpp
|
|
|
|
// cocos2d_libs
|
|
|
|
//
|
|
|
|
// Created by Carlo Morgantini on 7/23/13.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "CCFontAtlasFactory.h"
|
2013-07-26 08:58:13 +08:00
|
|
|
#include "CCFontFNT.h"
|
2013-07-25 01:22:46 +08:00
|
|
|
|
|
|
|
// carloX this NEEDS to be changed
|
|
|
|
#include "CCLabelBMFont.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-07-30 04:43:23 +08:00
|
|
|
static const char *glyphASCII = "\"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ ";
|
2013-07-26 08:58:13 +08:00
|
|
|
|
2013-07-30 04:43:23 +08:00
|
|
|
static const char *glyphNEHE = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ";
|
2013-07-25 01:22:46 +08:00
|
|
|
|
|
|
|
|
2013-07-31 07:41:26 +08:00
|
|
|
FontAtlas * FontAtlasFactory::createAtlasFromTTF(const char* tttFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs)
|
2013-07-25 01:22:46 +08:00
|
|
|
{
|
2013-07-31 07:41:26 +08:00
|
|
|
FontDefinitionTTF *def = 0;
|
|
|
|
if ( (glyphs == GlyphCollection::NEHE) || (glyphs == GlyphCollection::ASCII) )
|
|
|
|
{
|
|
|
|
def = FontDefinitionTTF::create(tttFilePath, fontSize, getGlyphCollection(glyphs));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( glyphs == GlyphCollection::DYNAMIC )
|
|
|
|
{
|
|
|
|
log("ERROR: GlyphCollection::DYNAMIC is not supported yet!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !customGlyphs )
|
|
|
|
{
|
|
|
|
log("ERROR: GlyphCollection::CUSTOM used but no input glyphs provided!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
def = FontDefinitionTTF::create(tttFilePath, fontSize, customGlyphs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 01:22:46 +08:00
|
|
|
if(!def)
|
2013-07-25 08:21:51 +08:00
|
|
|
return nullptr;
|
2013-07-25 01:22:46 +08:00
|
|
|
|
|
|
|
// create the font atlas from the font definition
|
|
|
|
FontAtlas *tempAtlas = def->createFontAtlas();
|
|
|
|
|
|
|
|
// release the font definition, we don't need it anymore
|
|
|
|
def->release();
|
|
|
|
|
|
|
|
// return the atlas
|
|
|
|
return tempAtlas;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontAtlas * FontAtlasFactory::createAtlasFromFNT(const char* fntFilePath)
|
|
|
|
{
|
2013-08-02 05:36:34 +08:00
|
|
|
Font *pFont = Font::createWithFNT(fntFilePath);
|
2013-07-26 08:58:13 +08:00
|
|
|
|
2013-08-02 05:36:34 +08:00
|
|
|
if(pFont)
|
|
|
|
return pFont->createFontAtlas();
|
2013-07-26 08:58:13 +08:00
|
|
|
else
|
2013-08-02 05:36:34 +08:00
|
|
|
return nullptr;
|
2013-07-25 01:22:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char * FontAtlasFactory::getGlyphCollection(GlyphCollection glyphs)
|
|
|
|
{
|
|
|
|
switch (glyphs)
|
|
|
|
{
|
|
|
|
case GlyphCollection::NEHE:
|
2013-07-27 02:58:18 +08:00
|
|
|
return glyphNEHE;
|
2013-07-25 01:22:46 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GlyphCollection::ASCII:
|
2013-07-27 02:58:18 +08:00
|
|
|
return glyphASCII;
|
2013-07-25 01:22:46 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|