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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 亲戚天天来吃饭怎么办 cad找不到图了怎么办 新建没有工作表怎么办 Html打开是乱码怎么办 xp只读取消不了怎么办 手机地图信号弱怎么办 苹果定位不准确怎么办 苹果导航卡死怎么办 没有上传的发票怎么办 发票显示未上传怎么办 发票未上传怎么办 影响 公务员国考补录不合格的怎么办 车辆转入退档怎么办 校园网总是断网怎么办 校园网经常断网怎么办 身份证号姓名电话号码泄露怎么办 中国邮政银行短信通知怎么办 中通递送不到怎么办 智齿碎了一半怎么办 驾照扣50分怎么办 办不了租赁合同怎么办 收到佰仟律师函怎么办 佰仟律师打电话怎么办 右转车道右方路禁行怎么办 收费站没带现金怎么办 过收费站没有现金怎么办 高速收费站没有现金怎么办 过收费站没现金怎么办 查社保忘记密码怎么办 医保密码忘记了怎么办 买房房东不过户怎么办 转户口金牛区怎么办 高中办休学手续怎么办 电动车灯壳发黄怎么办 买二手车上当了怎么办 成都社保卡遗失怎么办 成都个人怎么办健康证 成都健康证怎么办周末 扶贫办 2020年后怎么办 学历认证通不过怎么办 中考落榜后该怎么办