some more refactoring and improvements
This commit is contained in:
@@ -34,10 +34,23 @@ namespace OpenVulkano::Scene
|
||||
m_atlasData = std::make_shared<AtlasData>();
|
||||
const auto& [lib, face] = FontAtlasGeneratorBase::InitFreetype(source);
|
||||
|
||||
// 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(face.get(), 0, cellSize.y - cellSize.y / 3);
|
||||
Math::Vector2ui cellSize;
|
||||
if (m_pixelSizeConfig.isPixelSize)
|
||||
{
|
||||
cellSize = { m_pixelSizeConfig.size, m_pixelSizeConfig.size };
|
||||
// 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(face.get(), 0, cellSize.y - cellSize.y / 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
const float pixelSize = (m_pixelSizeConfig.size * m_pixelSizeConfig.dpi) / 72.0f;
|
||||
//int fontHeight = round((face->bbox.yMax - face->bbox.yMin) * pixelSize / face->units_per_EM);
|
||||
//int fontWidth = round((face->bbox.xMax - face->bbox.xMin) * pixelSize / face->units_per_EM);
|
||||
cellSize = { pixelSize, pixelSize };
|
||||
FT_Set_Char_Size(face.get(), 0, static_cast<FT_F26Dot6>(m_pixelSizeConfig.size) * 64,
|
||||
static_cast<FT_UInt>(m_pixelSizeConfig.dpi), static_cast<FT_UInt>(m_pixelSizeConfig.dpi));
|
||||
}
|
||||
|
||||
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 rows = (chset.size() / glyphsPerRow) + (chset.size() % glyphsPerRow != 0);
|
||||
@@ -68,6 +81,8 @@ namespace OpenVulkano::Scene
|
||||
if (slot->bitmap.width > cellSize.x || slot->bitmap.rows > cellSize.y)
|
||||
{
|
||||
Logger::APP->warn("Glyph size exceeds grid cell size: {}x{} exceeds {}x{}", slot->bitmap.width, slot->bitmap.rows, cellSize.x, cellSize.y);
|
||||
// skip such glyph for now to avoid crash
|
||||
continue;
|
||||
}
|
||||
|
||||
const size_t firstGlyphByte = (gridPos.y * cellSize.x + gridPos.x * atlasResolution.x * cellSize.y);
|
||||
|
||||
Reference in New Issue
Block a user