1
0
mirror of synced 2024-11-12 02:00:52 +01:00

impr: Properly center icon fonts

This commit is contained in:
WerWolv 2023-11-28 14:21:48 +01:00
parent df7cc1fefd
commit 56064df8d5

View File

@ -234,11 +234,8 @@ namespace hex::plugin::builtin {
} }
} }
// Build default font to get its metrics
fonts->Build(); fonts->Build();
// Merge all fonts into one big font atlas
cfg.MergeMode = true;
cfg.FontDataOwnedByAtlas = false; cfg.FontDataOwnedByAtlas = false;
// Add all other fonts to the atlas // Add all other fonts to the atlas
@ -260,9 +257,15 @@ namespace hex::plugin::builtin {
cfg.FontBuilderFlags = startFlags | font.flags; cfg.FontBuilderFlags = startFlags | font.flags;
cfg.MergeMode = false;
ImFontAtlas atlas;
auto queryFont = atlas.AddFontFromMemoryTTF(font.fontData.data(), int(font.fontData.size()), 0, &cfg, ranges.back().Data);
atlas.Build();
cfg.MergeMode = true;
std::memset(cfg.Name, 0x00, sizeof(cfg.Name)); std::memset(cfg.Name, 0x00, sizeof(cfg.Name));
std::strncpy(cfg.Name, font.name.c_str(), sizeof(cfg.Name) - 1); std::strncpy(cfg.Name, font.name.c_str(), sizeof(cfg.Name) - 1);
cfg.GlyphOffset = { font.offset.x, font.offset.y - defaultFont->Descent }; cfg.GlyphOffset = { font.offset.x, font.offset.y - defaultFont->Descent + queryFont->Descent };
fonts->AddFontFromMemoryTTF(font.fontData.data(), int(font.fontData.size()), 0, &cfg, ranges.back().Data); fonts->AddFontFromMemoryTTF(font.fontData.data(), int(font.fontData.size()), 0, &cfg, ranges.back().Data);
} }