101 lines
3.8 KiB
C++
101 lines
3.8 KiB
C++
|
|
/**
|
|||
|
|
* @file main.cpp
|
|||
|
|
* @brief MSDF 字体构建工具命令行入口
|
|||
|
|
*
|
|||
|
|
* 用法:
|
|||
|
|
* msdf_font_builder -i <input.ttf> -o <output.png> [options]
|
|||
|
|
*
|
|||
|
|
* 选项:
|
|||
|
|
* -i, --input <file> 输入 TTF 字体文件路径
|
|||
|
|
* -o, --output <file> 输出 PNG 图集路径
|
|||
|
|
* -c, --charset <string> 字符集字符串
|
|||
|
|
* -f, --charset-file <file> 字符集文件路径
|
|||
|
|
* -s, --size <pixels> 字体大小(默认 48)
|
|||
|
|
* -r, --range <pixels> 像素范围(默认 4.0)
|
|||
|
|
* -w, --width <pixels> 图集宽度(默认 2048)
|
|||
|
|
* -h, --height <pixels> 图集高度(默认 2048)
|
|||
|
|
* --help 显示帮助信息
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#include "msdf_font_builder.h"
|
|||
|
|
#include <iostream>
|
|||
|
|
#include <string>
|
|||
|
|
#include <cstdlib>
|
|||
|
|
|
|||
|
|
using namespace extra2d::tools;
|
|||
|
|
|
|||
|
|
void printUsage(const char* programName) {
|
|||
|
|
std::cout << "MSDF Font Builder - TTF 转 MSDF PNG 图集工具\n\n";
|
|||
|
|
std::cout << "用法:\n";
|
|||
|
|
std::cout << " " << programName << " -i <input.ttf> -o <output.png> [options]\n\n";
|
|||
|
|
std::cout << "选项:\n";
|
|||
|
|
std::cout << " -i, --input <file> 输入 TTF 字体文件路径\n";
|
|||
|
|
std::cout << " -o, --output <file> 输出 PNG 图集路径\n";
|
|||
|
|
std::cout << " -c, --charset <string> 字符集字符串\n";
|
|||
|
|
std::cout << " -f, --charset-file <file> 字符集文件路径\n";
|
|||
|
|
std::cout << " -s, --size <pixels> 字体大小(默认 48)\n";
|
|||
|
|
std::cout << " -r, --range <pixels> 像素范围(默认 4.0)\n";
|
|||
|
|
std::cout << " -w, --width <pixels> 图集宽度(默认 2048)\n";
|
|||
|
|
std::cout << " -h, --height <pixels> 图集高度(默认 2048)\n";
|
|||
|
|
std::cout << " --help 显示帮助信息\n\n";
|
|||
|
|
std::cout << "示例:\n";
|
|||
|
|
std::cout << " " << programName << " -i font.ttf -o font.msdf.png\n";
|
|||
|
|
std::cout << " " << programName << " -i font.ttf -o font.msdf.png -s 64 -c \"ABCabc123\"\n";
|
|||
|
|
std::cout << " " << programName << " -i font.ttf -o font.msdf.png -f charset.txt\n";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int main(int argc, char* argv[]) {
|
|||
|
|
MSDFFontBuilder builder;
|
|||
|
|
bool showHelp = false;
|
|||
|
|
int width = 2048;
|
|||
|
|
int height = 2048;
|
|||
|
|
|
|||
|
|
for (int i = 1; i < argc; ++i) {
|
|||
|
|
std::string arg = argv[i];
|
|||
|
|
|
|||
|
|
if (arg == "--help") {
|
|||
|
|
showHelp = true;
|
|||
|
|
} else if ((arg == "-i" || arg == "--input") && i + 1 < argc) {
|
|||
|
|
builder.setInputFont(argv[++i]);
|
|||
|
|
} else if ((arg == "-o" || arg == "--output") && i + 1 < argc) {
|
|||
|
|
builder.setOutputPath(argv[++i]);
|
|||
|
|
} else if ((arg == "-c" || arg == "--charset") && i + 1 < argc) {
|
|||
|
|
builder.setCharset(argv[++i]);
|
|||
|
|
} else if ((arg == "-f" || arg == "--charset-file") && i + 1 < argc) {
|
|||
|
|
builder.setCharsetFile(argv[++i]);
|
|||
|
|
} else if ((arg == "-s" || arg == "--size") && i + 1 < argc) {
|
|||
|
|
builder.setFontSize(std::atoi(argv[++i]));
|
|||
|
|
} else if ((arg == "-r" || arg == "--range") && i + 1 < argc) {
|
|||
|
|
builder.setPxRange(static_cast<float>(std::atof(argv[++i])));
|
|||
|
|
} else if ((arg == "-w" || arg == "--width") && i + 1 < argc) {
|
|||
|
|
width = std::atoi(argv[++i]);
|
|||
|
|
} else if ((arg == "-h" || arg == "--height") && i + 1 < argc) {
|
|||
|
|
height = std::atoi(argv[++i]);
|
|||
|
|
} else {
|
|||
|
|
std::cerr << "未知参数: " << arg << "\n";
|
|||
|
|
showHelp = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
builder.setAtlasSize(width, height);
|
|||
|
|
|
|||
|
|
if (showHelp) {
|
|||
|
|
printUsage(argv[0]);
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
std::cout << "MSDF Font Builder\n";
|
|||
|
|
std::cout << "==================\n\n";
|
|||
|
|
std::cout << "开始构建...\n\n";
|
|||
|
|
|
|||
|
|
if (!builder.build()) {
|
|||
|
|
std::cerr << "错误: " << builder.getError() << "\n";
|
|||
|
|
return 1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
std::cout << "成功生成 MSDF 字体图集!\n";
|
|||
|
|
std::cout << "字形数量: " << builder.getMetadata().glyphs.size() << "\n";
|
|||
|
|
|
|||
|
|
return 0;
|
|||
|
|
}
|