Refactor FontAtlas class

This commit is contained in:
Georg Hagen
2025-01-11 01:25:52 +01:00
parent 6a3c31346f
commit 9cb3d4de85
14 changed files with 246 additions and 247 deletions

View File

@@ -6,6 +6,7 @@
#include "BitmapFontAtlasGenerator.hpp"
#include "Base/Logger.hpp"
#include "Text/FontAtlas.hpp"
namespace OpenVulkano::Scene
{
@@ -31,7 +32,6 @@ namespace OpenVulkano::Scene
return;
}
m_atlasData = std::make_shared<AtlasData>();
const auto& [lib, face] = FontAtlasGeneratorBase::InitFreetype(source);
FT_Set_Pixel_Sizes(face.get(), 0, m_pixelSizeConfig.CalculatePixelSize());
@@ -47,12 +47,9 @@ namespace OpenVulkano::Scene
// but since some algorithms have already been implemented for EM_NORMALIZED mode, currently there is no support for default font metrics (ints)
// The coordinates will be normalized to the em size, i.e. 1 = 1 em
const double scaleFactor = (1. / face->units_per_EM);
SetupAtlasData(atlasResolution, face->height * scaleFactor, FontAtlasType::BITMAP);
m_atlasData = std::make_shared<FontAtlas>(atlasResolution, face->height * scaleFactor, FontAtlasType::BITMAP);
FillGlyphsInfo(allGlyphs, face, scaleFactor);
if (pngOutput)
{
SavePng(*pngOutput);
}
if (pngOutput) m_atlasData->Save(*pngOutput);
}
std::pair<std::vector<GlyphForPacking>, double>
@@ -94,14 +91,15 @@ namespace OpenVulkano::Scene
}
FT_GlyphSlot slot = face->glyph;
char* baseAddress = static_cast<char*>(m_atlasData->GetTexture()->textureBuffer) + glyph.firstGlyphByteInAtlas;
for (int row = 0; row < slot->bitmap.rows; row++)
{
std::memcpy(&m_atlasData->img->data[glyph.firstGlyphByteInAtlas + row * m_atlasData->img->resolution.x],
std::memcpy(baseAddress + row * m_atlasData->GetTexture()->resolution.x,
&slot->bitmap.buffer[(slot->bitmap.rows - 1 - row) * slot->bitmap.pitch],
slot->bitmap.width);
}
GlyphInfo& glyphInfo = m_atlasData->glyphs[glyph.code];
GlyphInfo& glyphInfo = m_atlasData->GetGlyphs()[glyph.code];
const Math::Vector2d glyphMetrics = { slot->metrics.width * scaleFactor,
slot->metrics.height * scaleFactor };
const Math::Vector2d glyphBearing = { slot->metrics.horiBearingX * scaleFactor,