From 41d7a274853bac40b6bb07c495ac977fb9b28076 Mon Sep 17 00:00:00 2001 From: "sheldon.teerlink" Date: Tue, 19 Jan 2016 11:43:35 -0700 Subject: [PATCH 1/2] Implement getFontFamily(). --- cocos/2d/CCFontFreeType.cpp | 8 ++++++++ cocos/2d/CCFontFreeType.h | 1 + 2 files changed, 9 insertions(+) diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index e8e0bb2daa..72762b744d 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -274,6 +274,14 @@ int FontFreeType::getFontAscender() const return (static_cast(_fontRef->size->metrics.ascender >> 6)); } +const char* FontFreeType::getFontFamily() const +{ + if (!_fontRef) + return nullptr; + + return _fontRef->family_name; +} + unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWidth, long &outHeight, Rect &outRect,int &xAdvance) { bool invalidChar = true; diff --git a/cocos/2d/CCFontFreeType.h b/cocos/2d/CCFontFreeType.h index 51600e1b30..b3406181c8 100644 --- a/cocos/2d/CCFontFreeType.h +++ b/cocos/2d/CCFontFreeType.h @@ -71,6 +71,7 @@ public: unsigned char* getGlyphBitmap(unsigned short theChar, long &outWidth, long &outHeight, Rect &outRect,int &xAdvance); int getFontAscender() const; + const char* getFontFamily() const; virtual FontAtlas* createFontAtlas() override; virtual int getFontMaxHeight() const override { return _lineHeight; } From 535dfdac270ad61b53f4105df0fdde8de691b584 Mon Sep 17 00:00:00 2001 From: "sheldon.teerlink" Date: Tue, 19 Jan 2016 11:47:18 -0700 Subject: [PATCH 2/2] Fix warning. --- cocos/2d/CCFontFreeType.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 72762b744d..3cb1363fe4 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -647,7 +647,7 @@ void FontFreeType::releaseFont(const std::string &fontName) auto item = s_cacheFontData.begin(); while (s_cacheFontData.end() != item) { - if (item->first.find(fontName) >= 0) + if (item->first.find(fontName) != std::string::npos) item = s_cacheFontData.erase(item); else item++;