From 11423b5851b0933d89c6cacd27d5f8068550031b Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 11:53:39 +0800 Subject: [PATCH] Changes the type of FontFreeType::_ttfData from `unsigned char*` to `Data`, makes codes more elegant. --- cocos/2d/CCFontFreeType.cpp | 19 +++---------------- cocos/2d/CCFontFreeType.h | 7 ++++--- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 8c2e6ddeb7..77a64bcfd9 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -90,7 +90,6 @@ FT_Library FontFreeType::getFTLibrary() FontFreeType::FontFreeType(bool dynamicGlyphCollection) : _fontRef(nullptr), _letterPadding(5), -_ttfData(nullptr), _dynamicGlyphCollection(dynamicGlyphCollection) { if(_distanceFieldEnabled) @@ -101,20 +100,13 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize) { FT_Face face; - ssize_t len = 0; - Data data = FileUtils::getInstance()->getDataFromFile(fontName); - _ttfData = data.getBytes(); - len = data.getSize(); + _ttfData = FileUtils::getInstance()->getDataFromFile(fontName); - // The data needs to be saved in this class, - // to prevent the buffer is freed in the destructor of Data, we should reset the buffer pointer by Data::fastSet. - data.fastSet(nullptr, 0); - - if (!_ttfData) + if (_ttfData.isNull()) return false; // create the face from the data - if (FT_New_Memory_Face(getFTLibrary(), _ttfData, len, 0, &face )) + if (FT_New_Memory_Face(getFTLibrary(), _ttfData.getBytes(), _ttfData.getSize(), 0, &face )) return false; //we want to use unicode @@ -143,11 +135,6 @@ FontFreeType::~FontFreeType() { FT_Done_Face(_fontRef); } - if (_ttfData) - { - free(_ttfData); - _ttfData = nullptr; - } } FontAtlas * FontFreeType::createFontAtlas() diff --git a/cocos/2d/CCFontFreeType.h b/cocos/2d/CCFontFreeType.h index 948ce9a601..7ff7596c20 100644 --- a/cocos/2d/CCFontFreeType.h +++ b/cocos/2d/CCFontFreeType.h @@ -25,11 +25,12 @@ #ifndef _FontFreetype_h_ #define _FontFreetype_h_ +#include "CCFont.h" +#include "CCData.h" + #include #include -#include "CCFont.h" - #include FT_FREETYPE_H NS_CC_BEGIN @@ -73,7 +74,7 @@ private: FT_Face _fontRef; int _letterPadding; std::string _fontName; - unsigned char* _ttfData; + Data _ttfData; bool _dynamicGlyphCollection; };