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::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(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; }
void nkDebug::Initialize() { g_shader_debugfont.loadProgram(); const u32 width = 64; const u32 height = 64; u8 font_buffer[height][width] = {0}; createFontAtlas(&font_buffer[0][0], width, height); nkTexture *texture = TEXTURE::LoadBuffer(&font_buffer[0][0], Luminance, width, height); g_font_tex_id = texture->m_id; }
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; }