From c81e63a8ff99ceeee1e97fa790b363742ca96ac8 Mon Sep 17 00:00:00 2001 From: ohyzha Date: Tue, 21 Jan 2025 16:24:33 +0200 Subject: [PATCH] fix wrong charset being used for atlas generation and use namespaces explicitly because of broken intellisense --- .../Scene/SdfFontAtlasGenerator.cpp | 80 ++++++++++--------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/openVulkanoCpp/Scene/SdfFontAtlasGenerator.cpp b/openVulkanoCpp/Scene/SdfFontAtlasGenerator.cpp index cd1c049..6d11046 100644 --- a/openVulkanoCpp/Scene/SdfFontAtlasGenerator.cpp +++ b/openVulkanoCpp/Scene/SdfFontAtlasGenerator.cpp @@ -14,9 +14,6 @@ namespace OpenVulkano::Scene { - using namespace msdfgen; - using namespace msdf_atlas; - SdfFontAtlasGeneratorConfig SdfFontAtlasGeneratorConfig::sdfDefaultConfig = { 42, 1.0, 5 }; SdfFontAtlasGeneratorConfig SdfFontAtlasGeneratorConfig::msdfDefaultConfig = { 32, 1.0, 3 }; @@ -24,11 +21,11 @@ namespace OpenVulkano::Scene void SdfFontAtlasGeneratorGeneric::GenerateAtlas(const std::string& fontFile, const std::set& charset, const std::optional& pngOutput) { - FreetypeHandle* ft; - FontHandle* font; + msdfgen::FreetypeHandle* ft; + msdfgen::FontHandle* font; InitFreetypeFromFile(ft, font, fontFile); - Charset s; - std::for_each(s.begin(), s.end(), [&](uint32_t unicode) { s.add(unicode); }); + msdf_atlas::Charset s; + std::for_each(charset.begin(), charset.end(), [&](uint32_t unicode) { s.add(unicode); }); Generate(ft, font, s, pngOutput); } @@ -42,42 +39,47 @@ namespace OpenVulkano::Scene void SdfFontAtlasGeneratorGeneric::GenerateAtlas(const Array& fontData, const std::set& charset, const std::optional& pngOutput) { - FreetypeHandle* ft; - FontHandle* font; + msdfgen::FreetypeHandle* ft; + msdfgen::FontHandle* font; InitFreetypeFromBuffer(ft, font, (const msdfgen::byte*)(fontData.Data()), fontData.Size()); - Charset s; - std::for_each(s.begin(), s.end(), [&](uint32_t unicode) { s.add(unicode); }); + msdf_atlas::Charset s; + std::for_each(charset.begin(), charset.end(), [&](uint32_t unicode) { s.add(unicode); }); Generate(ft, font, s, pngOutput); } template - void SdfFontAtlasGeneratorGeneric::GenerateAtlas(const std::string& fontFile, const Charset& charset, - const std::optional& pngOutput) + void SdfFontAtlasGeneratorGeneric::GenerateAtlas(const std::string& fontFile, + const msdf_atlas::Charset& charset, + const std::optional& pngOutput) { // TODO: dynamic atlas and add only those symbols which are not present yet in current atlas - FreetypeHandle* ft; - FontHandle* font; + msdfgen::FreetypeHandle* ft; + msdfgen::FontHandle* font; InitFreetypeFromFile(ft, font, fontFile); Generate(ft, font, charset, pngOutput); } template void SdfFontAtlasGeneratorGeneric::GenerateAtlas(const msdfgen::byte* fontData, int length, - const Charset& charset, - const std::optional& pngOutput) + const msdf_atlas::Charset& charset, + const std::optional& pngOutput) { - FreetypeHandle* ft; - FontHandle* font; + msdfgen::FreetypeHandle* ft; + msdfgen::FontHandle* font; InitFreetypeFromBuffer(ft, font, fontData, length); Generate(ft, font, charset, pngOutput); } template - void SdfFontAtlasGeneratorGeneric::InitFreetypeFromFile(FreetypeHandle*& ft, FontHandle*& font, - const std::string& fontFile) + void SdfFontAtlasGeneratorGeneric::InitFreetypeFromFile(msdfgen::FreetypeHandle*& ft, + msdfgen::FontHandle*& font, + const std::string& fontFile) { - ft = initializeFreetype(); - if (!ft) { throw std::runtime_error("Failed to initialize freetype"); } + ft = msdfgen::initializeFreetype(); + if (!ft) + { + throw std::runtime_error("Failed to initialize freetype"); + } font = loadFont(ft, fontFile.data()); if (!font) { @@ -88,11 +90,15 @@ namespace OpenVulkano::Scene } template - void SdfFontAtlasGeneratorGeneric::InitFreetypeFromBuffer(FreetypeHandle*& ft, FontHandle*& font, - const msdfgen::byte* fontData, int length) + void SdfFontAtlasGeneratorGeneric::InitFreetypeFromBuffer(msdfgen::FreetypeHandle*& ft, + msdfgen::FontHandle*& font, + const msdfgen::byte* fontData, int length) { - ft = initializeFreetype(); - if (!ft) { throw std::runtime_error("Failed to initialize freetype"); } + ft = msdfgen::initializeFreetype(); + if (!ft) + { + throw std::runtime_error("Failed to initialize freetype"); + } font = loadFontData(ft, fontData, length); if (!font) { @@ -103,24 +109,24 @@ namespace OpenVulkano::Scene } template - void SdfFontAtlasGeneratorGeneric::Generate(FreetypeHandle* ft, FontHandle* font, const Charset& chset, + void SdfFontAtlasGeneratorGeneric::Generate(msdfgen::FreetypeHandle* ft, msdfgen::FontHandle* font, + const msdf_atlas::Charset& chset, const std::optional& pngOutput) { - - std::vector glyphsGeometry; + std::vector glyphsGeometry; // FontGeometry is a helper class that loads a set of glyphs from a single font. - FontGeometry fontGeometry(&glyphsGeometry); + msdf_atlas::FontGeometry fontGeometry(&glyphsGeometry); fontGeometry.loadCharset(font, 1, chset); if constexpr (Channels == 3) { const double maxCornerAngle = 3.0; - for (GlyphGeometry& glyph: glyphsGeometry) + for (msdf_atlas::GlyphGeometry& glyph : glyphsGeometry) glyph.edgeColoring(&msdfgen::edgeColoringByDistance, maxCornerAngle, 0); } - TightAtlasPacker packer; - packer.setDimensionsConstraint(DimensionsConstraint::SQUARE); + msdf_atlas::TightAtlasPacker packer; + packer.setDimensionsConstraint(msdf_atlas::DimensionsConstraint::SQUARE); int width, height; const int glyphsPerRow = std::sqrt(glyphsGeometry.size()); const int glyphSize = m_config.glyphSize; @@ -135,7 +141,7 @@ namespace OpenVulkano::Scene Generator generator; generator.resize(width, height); - GeneratorAttributes attributes; + msdf_atlas::GeneratorAttributes attributes; generator.setAttributes(attributes); generator.setThreadCount(4); generator.generate(glyphsGeometry.data(), glyphsGeometry.size()); @@ -147,7 +153,7 @@ namespace OpenVulkano::Scene if constexpr (Channels == 3) { // store RGB as RGBA - const BitmapConstRef storage = generator.atlasStorage(); + const msdfgen::BitmapConstRef storage = generator.atlasStorage(); msdfgen::byte* data = static_cast(m_atlasData->GetTexture()->textureBuffer); for (size_t srcPos = 0, dstPos = 0; srcPos < width * height * 3; srcPos += 3, dstPos += 4) { @@ -171,7 +177,7 @@ namespace OpenVulkano::Scene for (const auto& glyph: glyphsGeometry) { GlyphInfo& info = m_atlasData->GetGlyphs()[glyph.getCodepoint()]; - const GlyphBox& glyphBox = generator.getLayout()[idx++]; + const msdf_atlas::GlyphBox& glyphBox = generator.getLayout()[idx++]; Bbox glyphBaselineBbox, glyphAtlasBbox; glyph.getQuadPlaneBounds(glyphBaselineBbox.l, glyphBaselineBbox.b, glyphBaselineBbox.r,