Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct.
| 13422 | |
| 13423 | // Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct. |
| 13424 | void ImGui::DebugTextEncoding(const char* str) |
| 13425 | { |
| 13426 | Text("Text: \"%s\"", str); |
| 13427 | if (!BeginTable("##DebugTextEncoding", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable)) |
| 13428 | return; |
| 13429 | TableSetupColumn("Offset"); |
| 13430 | TableSetupColumn("UTF-8"); |
| 13431 | TableSetupColumn("Glyph"); |
| 13432 | TableSetupColumn("Codepoint"); |
| 13433 | TableHeadersRow(); |
| 13434 | for (const char* p = str; *p != 0; ) |
| 13435 | { |
| 13436 | unsigned int c; |
| 13437 | const int c_utf8_len = ImTextCharFromUtf8(&c, p, NULL); |
| 13438 | TableNextColumn(); |
| 13439 | Text("%d", (int)(p - str)); |
| 13440 | TableNextColumn(); |
| 13441 | for (int byte_index = 0; byte_index < c_utf8_len; byte_index++) |
| 13442 | { |
| 13443 | if (byte_index > 0) |
| 13444 | SameLine(); |
| 13445 | Text("0x%02X", (int)(unsigned char)p[byte_index]); |
| 13446 | } |
| 13447 | TableNextColumn(); |
| 13448 | if (GetFont()->FindGlyphNoFallback((ImWchar)c)) |
| 13449 | TextUnformatted(p, p + c_utf8_len); |
| 13450 | else |
| 13451 | TextUnformatted((c == IM_UNICODE_CODEPOINT_INVALID) ? "[invalid]" : "[missing]"); |
| 13452 | TableNextColumn(); |
| 13453 | Text("U+%04X", (int)c); |
| 13454 | p += c_utf8_len; |
| 13455 | } |
| 13456 | EndTable(); |
| 13457 | } |
| 13458 | |
| 13459 | // Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds. |
| 13460 | static void MetricsHelpMarker(const char* desc) |
nothing calls this directly
no test coverage detected