颜色解析

This commit is contained in:
2025-04-08 01:17:51 +08:00
parent d596ae4c09
commit 84330d5069
2 changed files with 260 additions and 147 deletions

View File

@@ -20,6 +20,34 @@ int main(int argc, char* argv[]) {
auto description = mirage_style::get().description();
auto license = mirage_style::get().license();
const char* test_cases[] = {
"#FFF", // hex rgb
"#ff0000", // hex RRGGBB
"#00ff0080", // hex RRGGBBAA
"#1234", // hex RGBA
"rgb(255,0,0)", // rgb int
"rgba(0,255,0,128)",// rgba int
"rgba(0, 0, 255, 255)", // rgba int with spaces
"rgb(1.0, 0.0, 0.0)", // rgb float
"rgba(0.0, 1.0, 0.0, 0.5)",// rgba float
" rgb(0.0, 0.0, 1.0) ", // rgb float with spaces
"rgba(1, 0.5, 0, 1.0)", // rgba mixed - should parse as float
"invalid",
"#12345",
"rgb(300,0,0)",
"rgba(1.1, 0, 0, 1)",
"rgba(100,100,100)" // missing alpha
};
for (const char* test_str : test_cases) {
std::optional<linear_color> color = linear_color::from_string(test_str);
std::cout << "Parsing '" << test_str << "': ";
if (color) {
std::cout << "Success -> r:" << color->r << " g:" << color->g << " b:" << color->b << " a:" << color->a << std::endl;
} else {
std::cout << "Failed" << std::endl;
}
}
auto& manager = font_manager::instance();
manager.add_font(L"C:/Users/46944/AppData/Local/Microsoft/Windows/Fonts/MapleMono-NF-CN-Regular.ttf");
@@ -36,10 +64,8 @@ int main(int argc, char* argv[]) {
ss << "license: " << license << "\n";
// text_block->set_text(U"Hello, World! 你好,世界!\n换行测试1111测试测试测试测试,测试测试😀🐵🙏 😃🐵🙏");
const auto& utf32 = utf8::utf8to32(ss.str());
// const char*转换为std::u32string
text_block->set_text(utf32);
text_block->set_text(utf8::utf8to32(ss.str()));
const auto& text_block2 = std::make_shared<mtext_block>();
text_block2->set_text(U"Hello, World!");