add: more font
This commit is contained in:
@@ -7,6 +7,8 @@ using json = nlohmann::json;
|
||||
|
||||
void PrintGlyph(sf::Font const& font, sf::Glyph const& g, unsigned int size);
|
||||
|
||||
void ExportSize(json& out, uint32_t size, sf::Font& font);
|
||||
|
||||
int main()
|
||||
{
|
||||
sf::Font font;
|
||||
@@ -16,46 +18,39 @@ int main()
|
||||
|
||||
fmt::print("Loaded {}\n", ok);
|
||||
|
||||
std::vector<char> chars = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
|
||||
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
|
||||
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
|
||||
|
||||
fmt::print("{}\n", font.getInfo().family);
|
||||
fmt::print("Line Spacing: {}\n", font.getLineSpacing(14));
|
||||
|
||||
std::map<char, sf::Glyph> glyphs;
|
||||
|
||||
for(auto el : chars)
|
||||
{
|
||||
auto a = font.getGlyph(el, 14, false);
|
||||
|
||||
fmt::print("{}: w {} h {}\n",
|
||||
el,
|
||||
a.textureRect.width,
|
||||
a.textureRect.height);
|
||||
|
||||
fmt::print("- t: {} l: {} w: {} h: {}\n",
|
||||
a.bounds.top,
|
||||
a.bounds.left,
|
||||
a.bounds.width,
|
||||
a.bounds.height);
|
||||
|
||||
fmt::print("offset: {}\n\n", a.advance);
|
||||
|
||||
glyphs[el] = a;
|
||||
}
|
||||
|
||||
auto font_image = font.getTexture(14).copyToImage();
|
||||
auto size = font_image.getSize();
|
||||
|
||||
json export_font;
|
||||
export_font["name"] = font.getInfo().family;
|
||||
export_font["sizes"] = json::object();
|
||||
|
||||
auto& size_14 = export_font["sizes"]["14"];
|
||||
std::vector<uint32_t> sizes =
|
||||
{12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 100, 150, 200, 250, 300};
|
||||
|
||||
size_14["LineSpacing"] = font.getLineSpacing(14);
|
||||
auto& Glyphs = size_14["Glyphs"];
|
||||
for(auto& size : sizes)
|
||||
{
|
||||
fmt::print("Export: {}\n", size);
|
||||
ExportSize(export_font["sizes"][fmt::format("{}", size)], size, font);
|
||||
}
|
||||
|
||||
std::fstream out(fmt::format("{}.json", font.getInfo().family),
|
||||
std::ios::out);
|
||||
out << export_font.dump();
|
||||
}
|
||||
|
||||
void ExportSize(json& out, uint32_t size, sf::Font& font)
|
||||
{
|
||||
std::map<char, sf::Glyph> glyphs;
|
||||
|
||||
for(uint8_t c = 32; c <= 126; ++c)
|
||||
{
|
||||
glyphs[(char)c] = font.getGlyph(c, size, false);
|
||||
}
|
||||
auto font_image = font.getTexture(size).copyToImage();
|
||||
|
||||
out["LineSpacing"] = font.getLineSpacing(size);
|
||||
auto& Glyphs = out["Glyphs"];
|
||||
|
||||
for(auto&& [c, g] : glyphs)
|
||||
{
|
||||
@@ -82,13 +77,6 @@ int main()
|
||||
|
||||
current["data"] = data;
|
||||
}
|
||||
|
||||
std::fstream out(fmt::format("{}.json", font.getInfo().family),
|
||||
std::ios::out);
|
||||
out << export_font.dump();
|
||||
|
||||
fmt::print("Size x: {} y: {}\n", size.x, size.y);
|
||||
font_image.saveToFile("Test.png");
|
||||
}
|
||||
|
||||
void PrintGlyph(sf::Font const& font, sf::Glyph const& g, unsigned int size)
|
||||
|
||||
Reference in New Issue
Block a user