mirror of https://github.com/axmolengine/axmol.git
Changes the type of FontFreeType::_ttfData from `unsigned char*` to `Data`, makes codes more elegant.
This commit is contained in:
parent
366c4ca9fb
commit
11423b5851
|
@ -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()
|
||||
|
|
|
@ -25,11 +25,12 @@
|
|||
#ifndef _FontFreetype_h_
|
||||
#define _FontFreetype_h_
|
||||
|
||||
#include "CCFont.h"
|
||||
#include "CCData.h"
|
||||
|
||||
#include <string>
|
||||
#include <ft2build.h>
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue