More font rendering cleanup
This commit is contained in:
@@ -17,12 +17,6 @@ namespace OpenVulkano::Scene
|
||||
SdfFontAtlasGeneratorConfig SdfFontAtlasGeneratorConfig::sdfDefaultConfig = { 42, 1.0, 5 };
|
||||
SdfFontAtlasGeneratorConfig SdfFontAtlasGeneratorConfig::msdfDefaultConfig = { 32, 1.0, 3 };
|
||||
|
||||
template<int Channels>
|
||||
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& inCs)
|
||||
{
|
||||
GenerateAtlas(Utils::ReadFile(fontFile), inCs);
|
||||
}
|
||||
|
||||
template<int Channels> SdfFontAtlasGeneratorGeneric<Channels>::SdfFontAtlasGeneratorGeneric() : FontAtlasGeneratorBase(Channels)
|
||||
{
|
||||
if constexpr (Channels == 1) m_config = SdfFontAtlasGeneratorConfig::sdfDefaultConfig;
|
||||
@@ -39,7 +33,7 @@ namespace OpenVulkano::Scene
|
||||
std::set<uint32_t> fallback;
|
||||
if (inCs.empty())
|
||||
{
|
||||
FontAtlasGeneratorBase::LoadAllGlyphs(fallback, fontData.AsBytes());
|
||||
LoadAllGlyphs(fallback, fontData.AsBytes());
|
||||
}
|
||||
const auto& charset = inCs.empty() ? fallback : inCs;
|
||||
std::for_each(charset.begin(), charset.end(), [&](uint32_t unicode) { s.add(unicode); });
|
||||
@@ -47,43 +41,21 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
|
||||
template<int Channels>
|
||||
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const std::string& fontFile, const msdf_atlas::Charset& charset)
|
||||
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const std::filesystem::path& fontFile, const msdf_atlas::Charset& charset)
|
||||
{
|
||||
// TODO: dynamic atlas and add only those symbols which are not present yet in current atlas
|
||||
msdfgen::FreetypeHandle* ft;
|
||||
msdfgen::FontHandle* font;
|
||||
InitFreetypeFromFile(ft, font, fontFile);
|
||||
Generate(ft, font, charset);
|
||||
auto data = Utils::ReadFile(fontFile);
|
||||
GenerateAtlas(reinterpret_cast<const uint8_t*>(data.Data()), data.Size(), charset);
|
||||
}
|
||||
|
||||
template<int Channels>
|
||||
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const msdfgen::byte* fontData, int length, const msdf_atlas::Charset& charset)
|
||||
{
|
||||
{ // TODO: dynamic atlas and add only those symbols which are not present yet in current atlas
|
||||
msdfgen::FreetypeHandle* ft;
|
||||
msdfgen::FontHandle* font;
|
||||
InitFreetypeFromBuffer(ft, font, fontData, length);
|
||||
Generate(ft, font, charset);
|
||||
}
|
||||
|
||||
template<int Channels>
|
||||
void SdfFontAtlasGeneratorGeneric<Channels>::InitFreetypeFromFile(msdfgen::FreetypeHandle*& ft,
|
||||
msdfgen::FontHandle*& font,
|
||||
const std::string& fontFile)
|
||||
{
|
||||
ft = msdfgen::initializeFreetype();
|
||||
if (!ft)
|
||||
{
|
||||
throw std::runtime_error("Failed to initialize freetype");
|
||||
}
|
||||
font = loadFont(ft, fontFile.data());
|
||||
if (!font)
|
||||
{
|
||||
deinitializeFreetype(ft);
|
||||
ft = nullptr;
|
||||
throw std::runtime_error(fmt::format("Failed to load font from file {0}", fontFile.data()));
|
||||
}
|
||||
}
|
||||
|
||||
template<int Channels>
|
||||
void SdfFontAtlasGeneratorGeneric<Channels>::InitFreetypeFromBuffer(msdfgen::FreetypeHandle*& ft,
|
||||
msdfgen::FontHandle*& font,
|
||||
@@ -113,7 +85,7 @@ namespace OpenVulkano::Scene
|
||||
|
||||
if constexpr (Channels == 3)
|
||||
{
|
||||
const double maxCornerAngle = 3.0;
|
||||
constexpr double maxCornerAngle = 3.0;
|
||||
for (msdf_atlas::GlyphGeometry& glyph : glyphsGeometry)
|
||||
{
|
||||
glyph.edgeColoring(&msdfgen::edgeColoringByDistance, maxCornerAngle, 0);
|
||||
@@ -162,7 +134,7 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
else
|
||||
{
|
||||
const msdfgen::BitmapConstRef<msdfgen::byte, 1>& storage = generator.atlasStorage();
|
||||
const msdfgen::BitmapConstRef<msdfgen::byte>& storage = generator.atlasStorage();
|
||||
memcpy(m_atlasData->GetTexture()->textureBuffer, storage.pixels, width * height);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user