|
@@ -1701,7 +1701,7 @@ int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end)
|
|
|
}
|
|
|
|
|
|
// Based on stb_to_utf8() from github.com/nothings/stb/
|
|
|
-static inline int ImTextCharToUtf8(char* buf, int buf_size, unsigned int c)
|
|
|
+static inline int ImTextCharToUtf8_inline(char* buf, int buf_size, unsigned int c)
|
|
|
{
|
|
|
if (c < 0x80)
|
|
|
{
|
|
@@ -1736,6 +1736,13 @@ static inline int ImTextCharToUtf8(char* buf, int buf_size, unsigned int c)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+const char* ImTextCharToUtf8(char out_buf[5], unsigned int c)
|
|
|
+{
|
|
|
+ int count = ImTextCharToUtf8_inline(out_buf, 5, c);
|
|
|
+ out_buf[count] = 0;
|
|
|
+ return out_buf;
|
|
|
+}
|
|
|
+
|
|
|
// Not optimal but we very rarely use this function.
|
|
|
int ImTextCountUtf8BytesFromChar(const char* in_text, const char* in_text_end)
|
|
|
{
|
|
@@ -1752,20 +1759,20 @@ static inline int ImTextCountUtf8BytesFromChar(unsigned int c)
|
|
|
return 3;
|
|
|
}
|
|
|
|
|
|
-int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end)
|
|
|
+int ImTextStrToUtf8(char* out_buf, int out_buf_size, const ImWchar* in_text, const ImWchar* in_text_end)
|
|
|
{
|
|
|
- char* buf_out = buf;
|
|
|
- const char* buf_end = buf + buf_size;
|
|
|
- while (buf_out < buf_end - 1 && (!in_text_end || in_text < in_text_end) && *in_text)
|
|
|
+ char* buf_p = out_buf;
|
|
|
+ const char* buf_end = out_buf + out_buf_size;
|
|
|
+ while (buf_p < buf_end - 1 && (!in_text_end || in_text < in_text_end) && *in_text)
|
|
|
{
|
|
|
unsigned int c = (unsigned int)(*in_text++);
|
|
|
if (c < 0x80)
|
|
|
- *buf_out++ = (char)c;
|
|
|
+ *buf_p++ = (char)c;
|
|
|
else
|
|
|
- buf_out += ImTextCharToUtf8(buf_out, (int)(buf_end - buf_out - 1), c);
|
|
|
+ buf_p += ImTextCharToUtf8_inline(buf_p, (int)(buf_end - buf_p - 1), c);
|
|
|
}
|
|
|
- *buf_out = 0;
|
|
|
- return (int)(buf_out - buf);
|
|
|
+ *buf_p = 0;
|
|
|
+ return (int)(buf_p - out_buf);
|
|
|
}
|
|
|
|
|
|
int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end)
|
|
@@ -11459,8 +11466,9 @@ void ImGui::DebugNodeFont(ImFont* font)
|
|
|
"You can also render at multiple sizes and select which one to use at runtime.\n\n"
|
|
|
"(Glimmer of hope: the atlas system will be rewritten in the future to make scaling more flexible.)");
|
|
|
Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent);
|
|
|
- Text("Fallback character: '%c' (U+%04X)", font->FallbackChar, font->FallbackChar);
|
|
|
- Text("Ellipsis character: '%c' (U+%04X)", font->EllipsisChar, font->EllipsisChar);
|
|
|
+ char c_str[5];
|
|
|
+ Text("Fallback character: '%s' (U+%04X)", ImTextCharToUtf8(c_str, font->FallbackChar), font->FallbackChar);
|
|
|
+ Text("Ellipsis character: '%s' (U+%04X)", ImTextCharToUtf8(c_str, font->EllipsisChar), font->EllipsisChar);
|
|
|
const int surface_sqrt = (int)ImSqrt((float)font->MetricsTotalSurface);
|
|
|
Text("Texture Area: about %d px ~%dx%d px", font->MetricsTotalSurface, surface_sqrt, surface_sqrt);
|
|
|
for (int config_i = 0; config_i < font->ConfigDataCount; config_i++)
|