mirror of https://github.com/axmolengine/axmol.git
Fix comment typo and do clang-format [skip ci]
This commit is contained in:
parent
0e2ade1350
commit
beb593a22a
|
@ -13,6 +13,8 @@ IndentWidth: 4
|
|||
# Keep lines under 120 columns long.
|
||||
ColumnLimit: 120
|
||||
|
||||
SortIncludes: false
|
||||
|
||||
# Always break before braces
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
|
|
|
@ -40,29 +40,38 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
FT_Library FontFreeType::_FTlibrary;
|
||||
bool FontFreeType::_FTInitialized = false;
|
||||
bool FontFreeType::_streamParsingEnabled = false;
|
||||
bool FontFreeType::_doNativeBytecodeHinting = true;
|
||||
const int FontFreeType::DistanceMapSpread = 3;
|
||||
|
||||
const char* FontFreeType::_glyphASCII = "\"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ ";
|
||||
const char* FontFreeType::_glyphNEHE = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ";
|
||||
const char* FontFreeType::_glyphASCII =
|
||||
"\"!#$%&'()*+,-./"
|
||||
"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
|
||||
"¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ ";
|
||||
const char* FontFreeType::_glyphNEHE =
|
||||
"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ";
|
||||
|
||||
typedef struct _DataRef
|
||||
{
|
||||
Data data;
|
||||
unsigned int referenceCount;
|
||||
}DataRef;
|
||||
} DataRef;
|
||||
|
||||
static std::unordered_map<std::string, DataRef> s_cacheFontData;
|
||||
|
||||
// ------ freetype2 stream parsing support ---
|
||||
static unsigned long ft_stream_read_callback(FT_Stream stream, unsigned long offset, unsigned char* buf, unsigned long size) {
|
||||
static unsigned long ft_stream_read_callback(FT_Stream stream,
|
||||
unsigned long offset,
|
||||
unsigned char* buf,
|
||||
unsigned long size)
|
||||
{
|
||||
auto fd = (FileStream*)stream->descriptor.pointer;
|
||||
if (!fd) return 1;
|
||||
if (!size && offset >= stream->size) return 1;
|
||||
if (!fd)
|
||||
return 1;
|
||||
if (!size && offset >= stream->size)
|
||||
return 1;
|
||||
|
||||
if (stream->pos != offset)
|
||||
fd->seek(offset, SEEK_SET);
|
||||
|
@ -73,16 +82,22 @@ static unsigned long ft_stream_read_callback(FT_Stream stream, unsigned long off
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void ft_stream_close_callback(FT_Stream stream) {
|
||||
static void ft_stream_close_callback(FT_Stream stream)
|
||||
{
|
||||
const auto* fd = (FileStream*)stream->descriptor.pointer;
|
||||
delete fd;
|
||||
stream->size = 0;
|
||||
stream->descriptor.pointer = nullptr;
|
||||
}
|
||||
|
||||
FontFreeType * FontFreeType::create(const std::string &fontName, float fontSize, GlyphCollection glyphs, const char *customGlyphs,bool distanceFieldEnabled /* = false */,float outline /* = 0 */)
|
||||
FontFreeType* FontFreeType::create(const std::string& fontName,
|
||||
float fontSize,
|
||||
GlyphCollection glyphs,
|
||||
const char* customGlyphs,
|
||||
bool distanceFieldEnabled /* = false */,
|
||||
float outline /* = 0 */)
|
||||
{
|
||||
FontFreeType *tempFont = new (std::nothrow) FontFreeType(distanceFieldEnabled,outline);
|
||||
FontFreeType* tempFont = new (std::nothrow) FontFreeType(distanceFieldEnabled, outline);
|
||||
|
||||
if (!tempFont)
|
||||
return nullptr;
|
||||
|
@ -103,7 +118,7 @@ bool FontFreeType::initFreeType()
|
|||
if (_FTInitialized == false)
|
||||
{
|
||||
// begin freetype
|
||||
if (FT_Init_FreeType( &_FTlibrary ))
|
||||
if (FT_Init_FreeType(&_FTlibrary))
|
||||
return false;
|
||||
|
||||
_FTInitialized = true;
|
||||
|
@ -154,13 +169,14 @@ FontFreeType::FontFreeType(bool distanceFieldEnabled /* = false */, float outlin
|
|||
}
|
||||
// clang-format on
|
||||
|
||||
bool FontFreeType::createFontObject(const std::string &fontName, float fontSize)
|
||||
bool FontFreeType::createFontObject(const std::string& fontName, float fontSize)
|
||||
{
|
||||
FT_Face face;
|
||||
// save font name locally
|
||||
_fontName = fontName;
|
||||
|
||||
if (!_streamParsingEnabled) {
|
||||
if (!_streamParsingEnabled)
|
||||
{
|
||||
auto it = s_cacheFontData.find(fontName);
|
||||
if (it != s_cacheFontData.end())
|
||||
{
|
||||
|
@ -177,12 +193,15 @@ bool FontFreeType::createFontObject(const std::string &fontName, float fontSize)
|
|||
}
|
||||
}
|
||||
|
||||
if (FT_New_Memory_Face(getFTLibrary(), s_cacheFontData[fontName].data.getBytes(), s_cacheFontData[fontName].data.getSize(), 0, &face))
|
||||
if (FT_New_Memory_Face(getFTLibrary(), s_cacheFontData[fontName].data.getBytes(),
|
||||
s_cacheFontData[fontName].data.getSize(), 0, &face))
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
auto fullPath = FileUtils::getInstance()->fullPathForFilename(fontName);
|
||||
if (fullPath.empty()) return false;
|
||||
if (fullPath.empty())
|
||||
return false;
|
||||
|
||||
auto fs = FileUtils::getInstance()->openFileStream(fullPath, FileStream::Mode::READ).release();
|
||||
if (!fs)
|
||||
|
@ -196,7 +215,7 @@ bool FontFreeType::createFontObject(const std::string &fontName, float fontSize)
|
|||
fts->size = fs->size();
|
||||
fts->descriptor.pointer = fs;
|
||||
|
||||
FT_Open_Args args = { 0 };
|
||||
FT_Open_Args args = {0};
|
||||
args.flags = FT_OPEN_STREAM;
|
||||
args.stream = fts.get();
|
||||
|
||||
|
@ -240,9 +259,9 @@ bool FontFreeType::createFontObject(const std::string &fontName, float fontSize)
|
|||
_fontRef = face;
|
||||
|
||||
// Notes:
|
||||
// a. Since freetype 2.8.1 the tt matrics not sync to size_matrics, see the function 'tt_size_request' in truetype/ttdriver.c
|
||||
// b. The TT spec always asks for ROUND, not FLOOR or CEIL, see also the function 'tt_size_reset' in
|
||||
// truetype/ttobjs.c
|
||||
// a. Since freetype 2.8.1 the TT matrics isn't sync to size_matrics, see the function 'tt_size_request' in
|
||||
// truetype/ttdriver.c b. The TT spec always asks for ROUND, not FLOOR or CEIL, see also the function
|
||||
// 'tt_size_reset' in truetype/ttobjs.c
|
||||
// ** Please see description of FT_Size_Metrics_ in freetype.h about this solution
|
||||
auto& size_metrics = _fontRef->size->metrics;
|
||||
if (_doNativeBytecodeHinting && !strcmp(FT_Get_Font_Format(face), "TrueType"))
|
||||
|
@ -287,7 +306,7 @@ FontFreeType::~FontFreeType()
|
|||
}
|
||||
}
|
||||
|
||||
FontAtlas * FontFreeType::createFontAtlas()
|
||||
FontAtlas* FontFreeType::createFontAtlas()
|
||||
{
|
||||
if (_fontAtlas == nullptr)
|
||||
{
|
||||
|
@ -300,13 +319,13 @@ FontAtlas * FontFreeType::createFontAtlas()
|
|||
_fontAtlas->prepareLetterDefinitions(utf32);
|
||||
}
|
||||
}
|
||||
// this->autorelease();
|
||||
// this->autorelease();
|
||||
}
|
||||
|
||||
return _fontAtlas;
|
||||
}
|
||||
|
||||
int * FontFreeType::getHorizontalKerningForTextUTF32(const std::u32string& text, int &outNumLetters) const
|
||||
int* FontFreeType::getHorizontalKerningForTextUTF32(const std::u32string& text, int& outNumLetters) const
|
||||
{
|
||||
if (!_fontRef)
|
||||
return nullptr;
|
||||
|
@ -316,17 +335,17 @@ int * FontFreeType::getHorizontalKerningForTextUTF32(const std::u32string& text,
|
|||
if (!outNumLetters)
|
||||
return nullptr;
|
||||
|
||||
int *sizes = new (std::nothrow) int[outNumLetters];
|
||||
int* sizes = new (std::nothrow) int[outNumLetters];
|
||||
if (!sizes)
|
||||
return nullptr;
|
||||
memset(sizes,0,outNumLetters * sizeof(int));
|
||||
memset(sizes, 0, outNumLetters * sizeof(int));
|
||||
|
||||
bool hasKerning = FT_HAS_KERNING( _fontRef ) != 0;
|
||||
bool hasKerning = FT_HAS_KERNING(_fontRef) != 0;
|
||||
if (hasKerning)
|
||||
{
|
||||
for (int c = 1; c < outNumLetters; ++c)
|
||||
{
|
||||
sizes[c] = getHorizontalKerningForChars(text[c-1], text[c]);
|
||||
sizes[c] = getHorizontalKerningForChars(text[c - 1], text[c]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -349,7 +368,7 @@ int FontFreeType::getHorizontalKerningForChars(uint64_t firstChar, uint64_t sec
|
|||
|
||||
FT_Vector kerning;
|
||||
|
||||
if (FT_Get_Kerning( _fontRef, glyphIndex1, glyphIndex2, FT_KERNING_DEFAULT, &kerning))
|
||||
if (FT_Get_Kerning(_fontRef, glyphIndex1, glyphIndex2, FT_KERNING_DEFAULT, &kerning))
|
||||
return 0;
|
||||
|
||||
return (static_cast<int>(kerning.x >> 6));
|
||||
|
@ -368,7 +387,11 @@ const char* FontFreeType::getFontFamily() const
|
|||
return _fontRef->family_name;
|
||||
}
|
||||
|
||||
unsigned char* FontFreeType::getGlyphBitmap(uint64_t theChar, long &outWidth, long &outHeight, Rect &outRect,int &xAdvance)
|
||||
unsigned char* FontFreeType::getGlyphBitmap(uint64_t theChar,
|
||||
long& outWidth,
|
||||
long& outHeight,
|
||||
Rect& outRect,
|
||||
int& xAdvance)
|
||||
{
|
||||
bool invalidChar = true;
|
||||
unsigned char* ret = nullptr;
|
||||
|
@ -380,19 +403,22 @@ unsigned char* FontFreeType::getGlyphBitmap(uint64_t theChar, long &outWidth, lo
|
|||
|
||||
// @remark: glyph_index=0 means
|
||||
auto glyph_index = FT_Get_Char_Index(_fontRef, static_cast<FT_ULong>(theChar));
|
||||
if (FT_Load_Glyph(_fontRef, glyph_index, _distanceFieldEnabled ?
|
||||
(FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT) :
|
||||
(FT_LOAD_RENDER | FT_LOAD_NO_AUTOHINT)))
|
||||
if (FT_Load_Glyph(_fontRef, glyph_index,
|
||||
_distanceFieldEnabled ? (FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT)
|
||||
: (FT_LOAD_RENDER | FT_LOAD_NO_AUTOHINT)))
|
||||
break;
|
||||
|
||||
#if defined(_DEBUG)
|
||||
if (glyph_index == 0) {
|
||||
if (glyph_index == 0)
|
||||
{
|
||||
std::u32string charUTF32(1, theChar);
|
||||
std::string charUTF8;
|
||||
cocos2d::StringUtils::UTF32ToUTF8(charUTF32, charUTF8);
|
||||
|
||||
if (charUTF8 == "\n") charUTF8 = "\\n";
|
||||
cocos2d::log("The font face: %s doesn't contains char: <%s>", _fontRef->charmap->face->family_name, charUTF8.c_str());
|
||||
if (charUTF8 == "\n")
|
||||
charUTF8 = "\\n";
|
||||
cocos2d::log("The font face: %s doesn't contains char: <%s>", _fontRef->charmap->face->family_name,
|
||||
charUTF8.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -411,14 +437,14 @@ unsigned char* FontFreeType::getGlyphBitmap(uint64_t theChar, long &outWidth, lo
|
|||
if (_outlineSize > 0 && outWidth > 0 && outHeight > 0)
|
||||
{
|
||||
auto copyBitmap = new (std::nothrow) unsigned char[outWidth * outHeight];
|
||||
memcpy(copyBitmap,ret,outWidth * outHeight * sizeof(unsigned char));
|
||||
memcpy(copyBitmap, ret, outWidth * outHeight * sizeof(unsigned char));
|
||||
|
||||
FT_BBox bbox;
|
||||
auto outlineBitmap = getGlyphBitmapWithOutline(theChar,bbox);
|
||||
if(outlineBitmap == nullptr)
|
||||
auto outlineBitmap = getGlyphBitmapWithOutline(theChar, bbox);
|
||||
if (outlineBitmap == nullptr)
|
||||
{
|
||||
ret = nullptr;
|
||||
delete [] copyBitmap;
|
||||
delete[] copyBitmap;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -442,7 +468,7 @@ unsigned char* FontFreeType::getGlyphBitmap(uint64_t theChar, long &outWidth, lo
|
|||
outRect.origin.x = (float)blendImageMinX;
|
||||
outRect.origin.y = -blendImageMaxY + _outlineSize;
|
||||
|
||||
unsigned char *blendImage = nullptr;
|
||||
unsigned char* blendImage = nullptr;
|
||||
if (blendWidth > 0 && blendHeight > 0)
|
||||
{
|
||||
FT_Pos index, index2;
|
||||
|
@ -480,8 +506,8 @@ unsigned char* FontFreeType::getGlyphBitmap(uint64_t theChar, long &outWidth, lo
|
|||
outWidth = blendWidth;
|
||||
outHeight = blendHeight;
|
||||
|
||||
delete [] outlineBitmap;
|
||||
delete [] copyBitmap;
|
||||
delete[] outlineBitmap;
|
||||
delete[] copyBitmap;
|
||||
ret = blendImage;
|
||||
}
|
||||
|
||||
|
@ -502,7 +528,7 @@ unsigned char* FontFreeType::getGlyphBitmap(uint64_t theChar, long &outWidth, lo
|
|||
}
|
||||
}
|
||||
|
||||
unsigned char * FontFreeType::getGlyphBitmapWithOutline(uint64_t theChar, FT_BBox &bbox)
|
||||
unsigned char* FontFreeType::getGlyphBitmapWithOutline(uint64_t theChar, FT_BBox& bbox)
|
||||
{
|
||||
unsigned char* ret = nullptr;
|
||||
if (FT_Load_Char(_fontRef, static_cast<FT_ULong>(theChar), FT_LOAD_NO_BITMAP) == 0)
|
||||
|
@ -515,10 +541,10 @@ unsigned char * FontFreeType::getGlyphBitmapWithOutline(uint64_t theChar, FT_BBo
|
|||
FT_Glyph_StrokeBorder(&glyph, _stroker, 0, 1);
|
||||
if (glyph->format == FT_GLYPH_FORMAT_OUTLINE)
|
||||
{
|
||||
FT_Outline *outline = &reinterpret_cast<FT_OutlineGlyph>(glyph)->outline;
|
||||
FT_Glyph_Get_CBox(glyph,FT_GLYPH_BBOX_GRIDFIT,&bbox);
|
||||
long width = (bbox.xMax - bbox.xMin)>>6;
|
||||
long rows = (bbox.yMax - bbox.yMin)>>6;
|
||||
FT_Outline* outline = &reinterpret_cast<FT_OutlineGlyph>(glyph)->outline;
|
||||
FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_GRIDFIT, &bbox);
|
||||
long width = (bbox.xMax - bbox.xMin) >> 6;
|
||||
long rows = (bbox.yMax - bbox.yMin) >> 6;
|
||||
|
||||
FT_Bitmap bmp;
|
||||
bmp.buffer = new (std::nothrow) unsigned char[width * rows];
|
||||
|
@ -530,11 +556,11 @@ unsigned char * FontFreeType::getGlyphBitmapWithOutline(uint64_t theChar, FT_BBo
|
|||
bmp.num_grays = 256;
|
||||
|
||||
FT_Raster_Params params;
|
||||
memset(¶ms, 0, sizeof (params));
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.source = outline;
|
||||
params.target = &bmp;
|
||||
params.flags = FT_RASTER_FLAG_AA;
|
||||
FT_Outline_Translate(outline,-bbox.xMin,-bbox.yMin);
|
||||
FT_Outline_Translate(outline, -bbox.xMin, -bbox.yMin);
|
||||
FT_Outline_Render(_FTlibrary, outline, ¶ms);
|
||||
|
||||
ret = bmp.buffer;
|
||||
|
@ -547,18 +573,18 @@ unsigned char * FontFreeType::getGlyphBitmapWithOutline(uint64_t theChar, FT_BBo
|
|||
return ret;
|
||||
}
|
||||
|
||||
unsigned char * makeDistanceMap( unsigned char *img, long width, long height)
|
||||
unsigned char* makeDistanceMap(unsigned char* img, long width, long height)
|
||||
{
|
||||
long pixelAmount = (width + 2 * FontFreeType::DistanceMapSpread) * (height + 2 * FontFreeType::DistanceMapSpread);
|
||||
|
||||
short * xdist = (short *) malloc( pixelAmount * sizeof(short) );
|
||||
short * ydist = (short *) malloc( pixelAmount * sizeof(short) );
|
||||
double * gx = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * gy = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * data = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * outside = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * inside = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
long i,j;
|
||||
short* xdist = (short*)malloc(pixelAmount * sizeof(short));
|
||||
short* ydist = (short*)malloc(pixelAmount * sizeof(short));
|
||||
double* gx = (double*)calloc(pixelAmount, sizeof(double));
|
||||
double* gy = (double*)calloc(pixelAmount, sizeof(double));
|
||||
double* data = (double*)calloc(pixelAmount, sizeof(double));
|
||||
double* outside = (double*)calloc(pixelAmount, sizeof(double));
|
||||
double* inside = (double*)calloc(pixelAmount, sizeof(double));
|
||||
long i, j;
|
||||
|
||||
// Convert img into double (data) rescale image levels between 0 and 1
|
||||
long outWidth = width + 2 * FontFreeType::DistanceMapSpread;
|
||||
|
@ -574,32 +600,34 @@ unsigned char * makeDistanceMap( unsigned char *img, long width, long height)
|
|||
height += 2 * FontFreeType::DistanceMapSpread;
|
||||
|
||||
// Transform background (outside contour, in areas of 0's)
|
||||
computegradient( data, (int)width, (int)height, gx, gy);
|
||||
computegradient(data, (int)width, (int)height, gx, gy);
|
||||
edtaa3(data, gx, gy, (int)width, (int)height, xdist, ydist, outside);
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
if( outside[i] < 0.0 )
|
||||
for (i = 0; i < pixelAmount; i++)
|
||||
if (outside[i] < 0.0)
|
||||
outside[i] = 0.0;
|
||||
|
||||
// Transform foreground (inside contour, in areas of 1's)
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
for (i = 0; i < pixelAmount; i++)
|
||||
data[i] = 1 - data[i];
|
||||
computegradient( data, (int)width, (int)height, gx, gy);
|
||||
computegradient(data, (int)width, (int)height, gx, gy);
|
||||
edtaa3(data, gx, gy, (int)width, (int)height, xdist, ydist, inside);
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
if( inside[i] < 0.0 )
|
||||
for (i = 0; i < pixelAmount; i++)
|
||||
if (inside[i] < 0.0)
|
||||
inside[i] = 0.0;
|
||||
|
||||
// The bipolar distance field is now outside-inside
|
||||
double dist;
|
||||
/* Single channel 8-bit output (bad precision and range, but simple) */
|
||||
unsigned char *out = (unsigned char *) malloc( pixelAmount * sizeof(unsigned char) );
|
||||
for( i=0; i < pixelAmount; i++)
|
||||
unsigned char* out = (unsigned char*)malloc(pixelAmount * sizeof(unsigned char));
|
||||
for (i = 0; i < pixelAmount; i++)
|
||||
{
|
||||
dist = outside[i] - inside[i];
|
||||
dist = 128.0 - dist*16;
|
||||
if( dist < 0 ) dist = 0;
|
||||
if( dist > 255 ) dist = 255;
|
||||
out[i] = (unsigned char) dist;
|
||||
dist = 128.0 - dist * 16;
|
||||
if (dist < 0)
|
||||
dist = 0;
|
||||
if (dist > 255)
|
||||
dist = 255;
|
||||
out[i] = (unsigned char)dist;
|
||||
}
|
||||
/* Dual channel 16-bit output (more complicated, but good precision and range) */
|
||||
/*unsigned char *out = (unsigned char *) malloc( pixelAmount * 3 * sizeof(unsigned char) );
|
||||
|
@ -617,25 +645,30 @@ unsigned char * makeDistanceMap( unsigned char *img, long width, long height)
|
|||
out[3*i + 2] = (unsigned char)dist;
|
||||
}*/
|
||||
|
||||
free( xdist );
|
||||
free( ydist );
|
||||
free( gx );
|
||||
free( gy );
|
||||
free( data );
|
||||
free( outside );
|
||||
free( inside );
|
||||
free(xdist);
|
||||
free(ydist);
|
||||
free(gx);
|
||||
free(gy);
|
||||
free(data);
|
||||
free(outside);
|
||||
free(inside);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void FontFreeType::renderCharAt(unsigned char *dest,int posX, int posY, unsigned char* bitmap,long bitmapWidth,long bitmapHeight)
|
||||
void FontFreeType::renderCharAt(unsigned char* dest,
|
||||
int posX,
|
||||
int posY,
|
||||
unsigned char* bitmap,
|
||||
long bitmapWidth,
|
||||
long bitmapHeight)
|
||||
{
|
||||
int iX = posX;
|
||||
int iY = posY;
|
||||
|
||||
if (_distanceFieldEnabled)
|
||||
{
|
||||
auto distanceMap = makeDistanceMap(bitmap,bitmapWidth,bitmapHeight);
|
||||
auto distanceMap = makeDistanceMap(bitmap, bitmapWidth, bitmapHeight);
|
||||
|
||||
bitmapWidth += 2 * DistanceMapSpread;
|
||||
bitmapHeight += 2 * DistanceMapSpread;
|
||||
|
@ -653,8 +686,8 @@ void FontFreeType::renderCharAt(unsigned char *dest,int posX, int posY, unsigned
|
|||
dest[index + 1] = out[index2 + 1];
|
||||
dest[index + 2] = out[index2 + 2];*/
|
||||
|
||||
//Single channel 8-bit output
|
||||
dest[iX + ( iY * FontAtlas::CacheTextureWidth )] = distanceMap[bitmap_y + x];
|
||||
// Single channel 8-bit output
|
||||
dest[iX + (iY * FontAtlas::CacheTextureWidth)] = distanceMap[bitmap_y + x];
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
@ -664,7 +697,7 @@ void FontFreeType::renderCharAt(unsigned char *dest,int posX, int posY, unsigned
|
|||
}
|
||||
free(distanceMap);
|
||||
}
|
||||
else if(_outlineSize > 0)
|
||||
else if (_outlineSize > 0)
|
||||
{
|
||||
unsigned char tempChar;
|
||||
for (long y = 0; y < bitmapHeight; ++y)
|
||||
|
@ -674,9 +707,9 @@ void FontFreeType::renderCharAt(unsigned char *dest,int posX, int posY, unsigned
|
|||
for (int x = 0; x < bitmapWidth; ++x)
|
||||
{
|
||||
tempChar = bitmap[(bitmap_y + x) * 2];
|
||||
dest[(iX + ( iY * FontAtlas::CacheTextureWidth ) ) * 2] = tempChar;
|
||||
dest[(iX + (iY * FontAtlas::CacheTextureWidth)) * 2] = tempChar;
|
||||
tempChar = bitmap[(bitmap_y + x) * 2 + 1];
|
||||
dest[(iX + ( iY * FontAtlas::CacheTextureWidth ) ) * 2 + 1] = tempChar;
|
||||
dest[(iX + (iY * FontAtlas::CacheTextureWidth)) * 2 + 1] = tempChar;
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
@ -684,7 +717,7 @@ void FontFreeType::renderCharAt(unsigned char *dest,int posX, int posY, unsigned
|
|||
iX = posX;
|
||||
iY += 1;
|
||||
}
|
||||
delete [] bitmap;
|
||||
delete[] bitmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -697,7 +730,7 @@ void FontFreeType::renderCharAt(unsigned char *dest,int posX, int posY, unsigned
|
|||
unsigned char cTemp = bitmap[bitmap_y + x];
|
||||
|
||||
// the final pixel
|
||||
dest[(iX + ( iY * FontAtlas::CacheTextureWidth ) )] = cTemp;
|
||||
dest[(iX + (iY * FontAtlas::CacheTextureWidth))] = cTemp;
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
@ -740,7 +773,7 @@ const char* FontFreeType::getGlyphCollection() const
|
|||
return glyphCollection;
|
||||
}
|
||||
|
||||
void FontFreeType::releaseFont(const std::string &fontName)
|
||||
void FontFreeType::releaseFont(const std::string& fontName)
|
||||
{
|
||||
auto item = s_cacheFontData.begin();
|
||||
while (s_cacheFontData.end() != item)
|
||||
|
|
|
@ -71,7 +71,7 @@ public:
|
|||
* dimensions. The application has to cater for this, especially if it
|
||||
* wants to rely on a TTF's vertical data (for example, to properly align
|
||||
* box characters vertically).
|
||||
* - since freetype-2.8.1 TureType acender,decender not sync to size_matrics
|
||||
* - Since freetype-2.8.1 TureType matrics isn't sync to size_matrics
|
||||
* - By default it's enabled for compatible with cocos2d-x-4.0 or older with freetype-2.5.5
|
||||
* - Please see freetype.h
|
||||
* */
|
||||
|
|
Loading…
Reference in New Issue