2013-07-26 08:58:13 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 Zynga Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2013-07-26 08:58:13 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "2d/CCFont.h"
|
|
|
|
#include "base/ccUTF8.h"
|
2013-08-02 05:36:34 +08:00
|
|
|
|
2013-07-26 08:58:13 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-08-06 06:11:07 +08:00
|
|
|
const char * Font::_glyphASCII = "\"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ ";
|
2013-08-02 05:36:34 +08:00
|
|
|
|
2013-08-06 06:11:07 +08:00
|
|
|
const char * Font::_glyphNEHE = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ";
|
2013-08-02 05:36:34 +08:00
|
|
|
|
|
|
|
|
2013-12-13 12:42:15 +08:00
|
|
|
Font::Font() :
|
|
|
|
_usedGlyphs(GlyphCollection::ASCII)
|
|
|
|
, _customGlyphs(nullptr)
|
2013-08-06 06:11:07 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
const char * Font::getGlyphCollection(GlyphCollection glyphs) const
|
2013-08-02 05:36:34 +08:00
|
|
|
{
|
|
|
|
switch (glyphs)
|
|
|
|
{
|
|
|
|
case GlyphCollection::NEHE:
|
2013-08-06 06:11:07 +08:00
|
|
|
return _glyphNEHE;
|
2013-08-02 05:36:34 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GlyphCollection::ASCII:
|
2013-08-06 06:11:07 +08:00
|
|
|
return _glyphASCII;
|
2013-08-02 05:36:34 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 06:11:07 +08:00
|
|
|
void Font::setCurrentGlyphCollection(GlyphCollection glyphs, const char *customGlyphs)
|
2013-08-02 05:36:34 +08:00
|
|
|
{
|
2013-08-06 06:11:07 +08:00
|
|
|
if (_customGlyphs)
|
|
|
|
delete [] _customGlyphs;
|
2013-08-02 05:36:34 +08:00
|
|
|
|
2013-08-06 06:11:07 +08:00
|
|
|
switch (glyphs)
|
2013-08-02 05:36:34 +08:00
|
|
|
{
|
2013-08-06 06:11:07 +08:00
|
|
|
case GlyphCollection::NEHE:
|
|
|
|
_customGlyphs = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GlyphCollection::ASCII:
|
|
|
|
_customGlyphs = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-10-29 20:25:03 +08:00
|
|
|
if (customGlyphs)
|
|
|
|
{
|
2013-11-05 08:31:36 +08:00
|
|
|
size_t lenght = strlen(customGlyphs);
|
2013-10-29 20:25:03 +08:00
|
|
|
_customGlyphs = new char [lenght + 2];
|
|
|
|
memcpy(_customGlyphs, customGlyphs, lenght);
|
|
|
|
|
|
|
|
_customGlyphs[lenght] = 0;
|
|
|
|
_customGlyphs[lenght+1] = 0;
|
|
|
|
}
|
2013-08-06 06:11:07 +08:00
|
|
|
|
|
|
|
break;
|
2013-08-02 05:36:34 +08:00
|
|
|
}
|
2014-01-27 13:53:57 +08:00
|
|
|
_usedGlyphs = glyphs;
|
2013-08-06 06:11:07 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
const char * Font::getCurrentGlyphCollection() const
|
2013-08-06 06:11:07 +08:00
|
|
|
{
|
|
|
|
if (_customGlyphs)
|
2013-08-15 03:37:59 +08:00
|
|
|
{
|
2013-08-06 06:11:07 +08:00
|
|
|
return _customGlyphs;
|
2013-08-15 03:37:59 +08:00
|
|
|
}
|
2013-08-02 05:36:34 +08:00
|
|
|
else
|
|
|
|
{
|
2013-08-06 06:11:07 +08:00
|
|
|
return getGlyphCollection(_usedGlyphs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-26 08:58:13 +08:00
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
|