From d13ed93fc1ec3e3e308d0dddae0e6c5e7a0bc590 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Wed, 21 May 2014 14:08:30 +0800 Subject: [PATCH] issue #5277:Label:It could be possible that for using outline and invoking 'Director::setContentScaleFactor' cause label show nothing. --- cocos/2d/CCFontFreeType.cpp | 11 ++++++----- cocos/2d/CCFontFreeType.h | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 53607fc127..48ce2d8bba 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -102,9 +102,10 @@ FontFreeType::FontFreeType(bool distanceFieldEnabled /* = false */,int outline / { if (_outlineSize > 0) { + _outlineSize *= CC_CONTENT_SCALE_FACTOR(); FT_Stroker_New(FontFreeType::getFTLibrary(), &_stroker); FT_Stroker_Set(_stroker, - (int)(_outlineSize * 64 * CC_CONTENT_SCALE_FACTOR()), + (int)(_outlineSize * 64), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); @@ -305,8 +306,8 @@ unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWid auto blendImage = new unsigned char[blendWidth * blendHeight * 2]; memset(blendImage, 0, blendWidth * blendHeight * 2); - int px = blendWidth == outlineWidth ? 0 : _outlineSize; - int py = blendHeight == outlineHeight ? 0 : _outlineSize; + int px = (blendWidth - outlineWidth) / 2; + int py = (blendHeight - outlineHeight) / 2; for (int x = 0; x < outlineWidth; ++x) { for (int y = 0; y < outlineHeight; ++y) @@ -317,8 +318,8 @@ unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWid } } - px = blendWidth == outWidth ? 0 : _outlineSize; - py = blendHeight == outHeight ? 0 : _outlineSize; + px = (blendWidth - outWidth) / 2; + py = (blendHeight - outHeight) / 2; for (int x = 0; x < outWidth; ++x) { for (int y = 0; y < outHeight; ++y) diff --git a/cocos/2d/CCFontFreeType.h b/cocos/2d/CCFontFreeType.h index 9c38e979b8..681f009a3b 100644 --- a/cocos/2d/CCFontFreeType.h +++ b/cocos/2d/CCFontFreeType.h @@ -58,7 +58,7 @@ public: static void shutdownFreeType(); bool isDistanceFieldEnabled() const { return _distanceFieldEnabled;} - int getOutlineSize() const { return _outlineSize; } + float getOutlineSize() const { return _outlineSize; } void renderCharAt(unsigned char *dest,int posX, int posY, unsigned char* bitmap,long bitmapWidth,long bitmapHeight); virtual FontAtlas * createFontAtlas() override; @@ -89,7 +89,7 @@ private: FT_Stroker _stroker; std::string _fontName; bool _distanceFieldEnabled; - int _outlineSize; + float _outlineSize; }; NS_CC_END