code refactoring

This commit is contained in:
ohyzha
2024-12-30 12:05:46 +02:00
parent 503e31947f
commit e8289c643b
10 changed files with 111 additions and 110 deletions

View File

@@ -31,17 +31,15 @@ namespace OpenVulkano::Scene
return;
}
m_atlasData.reset(new AtlasData);
const std::string sourceName = (std::holds_alternative<std::string>(source) ? std::get<0>(source) : "Binary array");
m_atlasData = std::make_shared<AtlasData>();
const auto& [lib, face] = FontAtlasGeneratorBase::InitFreetype(source);
FT_FaceRec* pFace = face.get();
// TODO: add flexibility to set your own size
const Math::Vector2ui cellSize = { 24, 24 };
// set pixel width/height lower than glyph size above, otherwise some glyphs will be cropped or some overlapping will be present
FT_Set_Pixel_Sizes(pFace, 0, cellSize.y - cellSize.y / 3);
FT_Set_Pixel_Sizes(face.get(), 0, cellSize.y - cellSize.y / 3);
const double sq = std::sqrt(chset.size());
const size_t glyphsPerRow = static_cast<size_t>(sq) + (sq - static_cast<size_t>(sq) != 0);
const size_t glyphsPerRow = (static_cast<size_t>(sq)) + (sq - static_cast<size_t>(sq) != 0);
const size_t rows = (chset.size() / glyphsPerRow) + (chset.size() % glyphsPerRow != 0);
const Math::Vector2ui atlasResolution = { glyphsPerRow * cellSize.x, rows * cellSize.y };
@@ -49,8 +47,8 @@ namespace OpenVulkano::Scene
// TODO: probably also support keeping coordinates as the integer values native to the font file
// 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. / pFace->units_per_EM);
SetupAtlasData(atlasResolution, pFace->height * scaleFactor, FontAtlasType::BITMAP);
const double scaleFactor = (1. / face->units_per_EM);
SetupAtlasData(atlasResolution, face->height * scaleFactor, FontAtlasType::BITMAP);
size_t loadedGlyphs = 0;
FT_Error error = 0;
@@ -59,10 +57,10 @@ namespace OpenVulkano::Scene
Math::Vector2ui gridPos = { 0, 0 };
for (uint32_t codepoint : chset)
{
error = FT_Load_Char(pFace, codepoint, FT_LOAD_RENDER);
error = FT_Load_Char(face.get(), codepoint, FT_LOAD_RENDER);
if (error)
{
Logger::APP->error("FT_Load_Char for codepoint {} failed while reading from source {}", codepoint, sourceName);
Logger::APP->error("FT_Load_Char for codepoint {} has failed. {}", codepoint, GetFreetypeErrorDescription(error));
continue;
}