FontAtlas * FontAtlasCache::getFontAtlasCharMap(const std::string& plistFile) { std::string atlasName = generateFontName(plistFile, 0, GlyphCollection::CUSTOM,false); FontAtlas *tempAtlas = _atlasMap[atlasName]; if ( !tempAtlas ) { Font *font = FontCharMap::create(plistFile); if(font) { tempAtlas = font->createFontAtlas(); if (tempAtlas) _atlasMap[atlasName] = tempAtlas; } else { return nullptr; } } else { tempAtlas->retain(); } return tempAtlas; }
FontAtlas * FontAtlasCache::getFontAtlasTTF(const std::string& fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField) { std::string atlasName = generateFontName(fontFileName, size, glyphs, useDistanceField); FontAtlas *tempAtlas = _atlasMap[atlasName]; if ( !tempAtlas ) { FontFreeType *font = FontFreeType::create(fontFileName, size, glyphs, customGlyphs); if (font) { font->setDistanceFieldEnabled(useDistanceField); tempAtlas = font->createFontAtlas(); if (tempAtlas) _atlasMap[atlasName] = tempAtlas; } else { return nullptr; } } else { tempAtlas->retain(); } return tempAtlas; }
FontAtlas * FontAtlasCache::getFontAtlasCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap) { char tmp[30]; sprintf(tmp,"name:%u_%d_%d_%d",texture->getName(),itemWidth,itemHeight,startCharMap); std::string atlasName = generateFontName(tmp, 0, GlyphCollection::CUSTOM,false); FontAtlas *tempAtlas = _atlasMap[atlasName]; if ( !tempAtlas ) { Font *font = FontCharMap::create(texture,itemWidth,itemHeight,startCharMap); if(font) { tempAtlas = font->createFontAtlas(); if (tempAtlas) _atlasMap[atlasName] = tempAtlas; } else { return nullptr; } } else { tempAtlas->retain(); } return tempAtlas; }
FontAtlas * FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName, const Vector2& imageOffset /* = Vector2::ZERO */) { std::string atlasName = generateFontName(fontFileName, 0, GlyphCollection::CUSTOM,false); auto it = _atlasMap.find(atlasName); if ( it == _atlasMap.end() ) { auto font = FontFNT::create(fontFileName,imageOffset); if(font) { auto tempAtlas = font->createFontAtlas(); if (tempAtlas) { _atlasMap[atlasName] = tempAtlas; return _atlasMap[atlasName]; } } } else { _atlasMap[atlasName]->retain(); return _atlasMap[atlasName]; } return nullptr; }
FontAtlas * FontAtlasCache::getFontAtlasCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap) { std::string atlasName = generateFontName(charMapFile, 0, GlyphCollection::CUSTOM,false); auto it = _atlasMap.find(atlasName); if ( it == _atlasMap.end() ) { auto font = FontCharMap::create(charMapFile,itemWidth,itemHeight,startCharMap); if(font) { auto tempAtlas = font->createFontAtlas(); if (tempAtlas) { _atlasMap[atlasName] = tempAtlas; return _atlasMap[atlasName]; } } } else { _atlasMap[atlasName]->retain(); return _atlasMap[atlasName]; } return nullptr; }
FontAtlas * FontAtlasCache::getFontAtlasCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap) { char tmp[30]; sprintf(tmp,"name:%u_%d_%d_%d",texture->getName(),itemWidth,itemHeight,startCharMap); std::string atlasName = generateFontName(tmp, 0, GlyphCollection::CUSTOM,false); auto it = _atlasMap.find(atlasName); if ( it == _atlasMap.end() ) { auto font = FontCharMap::create(texture,itemWidth,itemHeight,startCharMap); if(font) { auto tempAtlas = font->createFontAtlas(); if (tempAtlas) { _atlasMap[atlasName] = tempAtlas; return _atlasMap[atlasName]; } } } else { _atlasMap[atlasName]->retain(); return _atlasMap[atlasName]; } return nullptr; }
FontAtlas * FontAtlasCache::getFontAtlasTTF(const TTFConfig & config) { bool useDistanceField = config.distanceFieldEnabled; if(config.outlineSize > 0) { useDistanceField = false; } int fontSize = config.fontSize; auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR(); if (useDistanceField) { fontSize = Label::DistanceFieldFontSize / contentScaleFactor; } auto atlasName = generateFontName(config.fontFilePath, fontSize, GlyphCollection::DYNAMIC, useDistanceField); atlasName.append("_outline_"); std::stringstream ss; ss << config.outlineSize; atlasName.append(ss.str()); auto it = _atlasMap.find(atlasName); if ( it == _atlasMap.end() ) { auto font = FontFreeType::create(config.fontFilePath, fontSize, config.glyphs, config.customGlyphs, useDistanceField, config.outlineSize); if (font) { auto tempAtlas = font->createFontAtlas(); if (tempAtlas) { _atlasMap[atlasName] = tempAtlas; return _atlasMap[atlasName]; } } } else { _atlasMap[atlasName]->retain(); return _atlasMap[atlasName]; } return nullptr; }