Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct.
| 12926 | |
| 12927 | // Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct. |
| 12928 | void ImGui::DebugTextEncoding(const char* str) |
| 12929 | { |
| 12930 | Text("Text: \"%s\"", str); |
| 12931 | if (!BeginTable("list", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) |
| 12932 | return; |
| 12933 | TableSetupColumn("Offset"); |
| 12934 | TableSetupColumn("UTF-8"); |
| 12935 | TableSetupColumn("Glyph"); |
| 12936 | TableSetupColumn("Codepoint"); |
| 12937 | TableHeadersRow(); |
| 12938 | for (const char* p = str; *p != 0; ) |
| 12939 | { |
| 12940 | unsigned int c; |
| 12941 | const int c_utf8_len = ImTextCharFromUtf8(&c, p, NULL); |
| 12942 | TableNextColumn(); |
| 12943 | Text("%d", (int)(p - str)); |
| 12944 | TableNextColumn(); |
| 12945 | for (int byte_index = 0; byte_index < c_utf8_len; byte_index++) |
| 12946 | { |
| 12947 | if (byte_index > 0) |
| 12948 | SameLine(); |
| 12949 | Text("0x%02X", (int)(unsigned char)p[byte_index]); |
| 12950 | } |
| 12951 | TableNextColumn(); |
| 12952 | if (GetFont()->FindGlyphNoFallback((ImWchar)c)) |
| 12953 | TextUnformatted(p, p + c_utf8_len); |
| 12954 | else |
| 12955 | TextUnformatted((c == IM_UNICODE_CODEPOINT_INVALID) ? "[invalid]" : "[missing]"); |
| 12956 | TableNextColumn(); |
| 12957 | Text("U+%04X", (int)c); |
| 12958 | p += c_utf8_len; |
| 12959 | } |
| 12960 | EndTable(); |
| 12961 | } |
| 12962 | |
| 12963 | // Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds. |
| 12964 | static void MetricsHelpMarker(const char* desc) |
nothing calls this directly
no test coverage detected