CCFontAtlasCache,CCFontCharMap,CCFontFNT,CCFontFreeType解析
来源:互联网 发布:夜神模拟器for mac 编辑:程序博客网 时间:2024/06/05 12:50
CCFontAtlasCache:
代码:
class FontAtlas;// 字体图集缓存class CC_DLL FontAtlasCache{ public:// 得到字体图集 static FontAtlas * getFontAtlasTTF(const TTFConfig & config); static FontAtlas * getFontAtlasFNT(const std::string& fontFileName, const Vec2& imageOffset = Vec2::ZERO); static FontAtlas * getFontAtlasCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap); static FontAtlas * getFontAtlasCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap); static FontAtlas * getFontAtlasCharMap(const std::string& plistFile); static bool releaseFontAtlas(FontAtlas *atlas); /** Removes cached data. It will purge the textures atlas and if multiple texture exist in one FontAtlas. */ // 清除缓存数据 static void purgeCachedData(); private: // 生成字体名字 static std::string generateFontName(const std::string& fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField); static std::unordered_map<std::string, FontAtlas *> _atlasMap;};NS_CC_END
CCFontCharMap:
代码:
NS_CC_BEGIN// 字体字符图class FontCharMap : public Font{ public:// 创建一个字体字符图 static FontCharMap * create(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap); static FontCharMap * create(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap); static FontCharMap * create(const std::string& plistFile); // 得到水平字间距 virtual int* getHorizontalKerningForTextUTF16(const std::u16string& text, int &outNumLetters) const override; // 创建一个字体图集virtual FontAtlas *createFontAtlas() override; protected: // 构造函数 FontCharMap(Texture2D* texture,int itemWidth, int itemHeight, int startCharMap) :_texture(texture) ,_mapStartChar(startCharMap) ,_itemWidth(itemWidth) ,_itemHeight(itemHeight) {} /** * @js NA * @lua NA */ virtual ~FontCharMap(); private: Texture2D* _texture; int _mapStartChar; int _itemWidth; int _itemHeight;};
CCFontFNT:
代码:
// FNT字体class CC_DLL FontFNT : public Font{ public: // 创建一个FNT字体 static FontFNT * create(const std::string& fntFilePath, const Vec2& imageOffset = Vec2::ZERO); /** Purges the cached data. Removes from memory the cached configurations and the atlas name dictionary. */// 清除缓存的数据 static void purgeCachedData();// 得到水平字间距 virtual int* getHorizontalKerningForTextUTF16(const std::u16string& text, int &outNumLetters) const override;// 创建字体图集 virtual FontAtlas *createFontAtlas() override; protected: // 构造函数 FontFNT(BMFontConfiguration *theContfig, const Vec2& imageOffset = Vec2::ZERO); /** * @js NA * @lua NA */ virtual ~FontFNT(); private: // 得到水平字间距 int getHorizontalKerningForChars(unsigned short firstChar, unsigned short secondChar) const; BMFontConfiguration * _configuration; Vec2 _imageOffset; };
CCFontFreeType:
代码:
// 自由字体类型class CC_DLL FontFreeType : public Font{public: static const int DistanceMapSpread;// 创建一个自由字体类型 static FontFreeType * create(const std::string &fontName, int fontSize, GlyphCollection glyphs, const char *customGlyphs,bool distanceFieldEnabled = false,int outline = 0);// 关闭自由字体类型 static void shutdownFreeType(); bool isDistanceFieldEnabled() const { return _distanceFieldEnabled;}// 得到描边的尺寸 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;// 得到UTF-16水平的字间距 virtual int * getHorizontalKerningForTextUTF16(const std::u16string& text, int &outNumLetters) const override; // 得到标志符的位图资源 unsigned char * getGlyphBitmap(unsigned short theChar, long &outWidth, long &outHeight, Rect &outRect,int &xAdvance); // 得到字体的最大高度 virtual int getFontMaxHeight() const override; // 得到小写字母超出部分 virtual int getFontAscender() const;protected: // 构造函数 FontFreeType(bool distanceFieldEnabled = false,int outline = 0); virtual ~FontFreeType();// 创建一个字体对象 bool createFontObject(const std::string &fontName, int fontSize); private:// 初始化自由类型 bool initFreeType();// 得到FreeFont库 FT_Library getFTLibrary(); // 得到水平字间距 int getHorizontalKerningForChars(unsigned short firstChar, unsigned short secondChar) const;// 得到描边尺寸 unsigned char * getGlyphBitmapWithOutline(unsigned short theChar, FT_BBox &bbox); static FT_Library _FTlibrary; static bool _FTInitialized; FT_Face _fontRef; FT_Stroker _stroker; std::string _fontName; bool _distanceFieldEnabled; float _outlineSize;};
0 0
- CCFontAtlasCache,CCFontCharMap,CCFontFNT,CCFontFreeType解析
- 解析
- 解析
- 解析
- 解析
- 解析
- 解析
- 解析
- 解析
- 解析
- 解析[ ]
- 解析
- ffmpeg解析-----解析文件格式
- Xen解析 netfilter解析
- JSON解析,XML解析
- 硬解析 软解析
- 解析xml dom 解析
- JSON解析、XML解析
- [Leetcode 263] Ugly Number
- Winform:关于滚动条美化
- hdu 3524 Perfect Squares 快速幂+ 除法取余
- Xhprof----facebook开源的,轻量级的PHP性能分析工具
- c/c++使用gsoap发布和调用webservice
- CCFontAtlasCache,CCFontCharMap,CCFontFNT,CCFontFreeType解析
- [Leetcode 264] Ugly Number II
- Sublime Text 3 常用插件以及安装方法
- 二叉树的基本操作-递归实现
- 基于spring框架的BS构架web应用程序的一些学习心得
- Asp.mvc ~ 使用AngularJs构建SPA
- TFT显示汉字
- c/c++使用gsoap调用wcf发布的webservice
- HDOJ 题目3397 Sequence operation(线段树区间覆盖异或合并)