Skip to content

Commit 51a02b3

Browse files
committed
Added IM_UNICODE_CODEPOINT_MAX. Changed specs of ImFontAtlas::AddCustomRectRegular() (breaking change).
1 parent ca63349 commit 51a02b3

File tree

6 files changed

+37
-27
lines changed

6 files changed

+37
-27
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Breaking Changes:
5252
If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you.
5353
- Misc: Renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS. (#1038)
5454
- Misc: Renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS.
55+
- Fonts: ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of 0x10000) to
56+
conform with supporting Unicode planes 1-16 in a future update. ID below 0x110000 will now assert.
5557
- Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function.
5658
The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate]
5759

imgui.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ CODE
353353
When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
354354
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
355355
356+
- 2019/11/21 (1.74) - ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of 0x10000) to conform with supporting Unicode planes 1-16 in a future update. ID below 0x110000 will now assert.
356357
- 2019/11/19 (1.74) - renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS for consistency.
357358
- 2019/11/19 (1.74) - renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS for consistency.
358359
- 2019/10/22 (1.74) - removed redirecting functions/enums that were marked obsolete in 1.52 (October 2017): Begin() (5 arguments signature), IsRootWindowOrAnyChildHovered(), AlignFirstTextHeightToWidgets(), SetNextWindowPosCenter(), ImFont::Glyph. See docs/Changelog.txt or grep this log for details and new names, or see how they were implemented until 1.73.
@@ -1061,7 +1062,7 @@ ImGuiIO::ImGuiIO()
10611062
// - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
10621063
void ImGuiIO::AddInputCharacter(unsigned int c)
10631064
{
1064-
if (c > 0 && c < 0x10000)
1065+
if (c > 0 && c <= IM_UNICODE_CODEPOINT_MAX)
10651066
InputQueueCharacters.push_back((ImWchar)c);
10661067
}
10671068

@@ -1071,7 +1072,7 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
10711072
{
10721073
unsigned int c = 0;
10731074
utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL);
1074-
if (c > 0 && c < 0x10000)
1075+
if (c > 0 && c <= IM_UNICODE_CODEPOINT_MAX)
10751076
InputQueueCharacters.push_back((ImWchar)c);
10761077
}
10771078
}
@@ -1463,7 +1464,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char*
14631464
}
14641465
if ((*str & 0xe0) == 0xc0)
14651466
{
1466-
*out_char = 0xFFFD; // will be invalid but not end of string
1467+
*out_char = IM_UNICODE_CODEPOINT_INVALID; // will be invalid but not end of string
14671468
if (in_text_end && in_text_end - (const char*)str < 2) return 1;
14681469
if (*str < 0xc2) return 2;
14691470
c = (unsigned int)((*str++ & 0x1f) << 6);
@@ -1474,7 +1475,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char*
14741475
}
14751476
if ((*str & 0xf0) == 0xe0)
14761477
{
1477-
*out_char = 0xFFFD; // will be invalid but not end of string
1478+
*out_char = IM_UNICODE_CODEPOINT_INVALID; // will be invalid but not end of string
14781479
if (in_text_end && in_text_end - (const char*)str < 3) return 1;
14791480
if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return 3;
14801481
if (*str == 0xed && str[1] > 0x9f) return 3; // str[1] < 0x80 is checked below
@@ -1488,7 +1489,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char*
14881489
}
14891490
if ((*str & 0xf8) == 0xf0)
14901491
{
1491-
*out_char = 0xFFFD; // will be invalid but not end of string
1492+
*out_char = IM_UNICODE_CODEPOINT_INVALID; // will be invalid but not end of string
14921493
if (in_text_end && in_text_end - (const char*)str < 4) return 1;
14931494
if (*str > 0xf4) return 4;
14941495
if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return 4;
@@ -1519,7 +1520,7 @@ int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const cha
15191520
in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
15201521
if (c == 0)
15211522
break;
1522-
if (c < 0x10000) // FIXME: Losing characters that don't fit in 2 bytes
1523+
if (c <= IM_UNICODE_CODEPOINT_MAX) // FIXME: Losing characters that don't fit in 2 bytes
15231524
*buf_out++ = (ImWchar)c;
15241525
}
15251526
*buf_out = 0;
@@ -1537,7 +1538,7 @@ int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end)
15371538
in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
15381539
if (c == 0)
15391540
break;
1540-
if (c < 0x10000)
1541+
if (c <= IM_UNICODE_CODEPOINT_MAX)
15411542
char_count++;
15421543
}
15431544
return char_count;

imgui.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ Index of this file:
8080
#else
8181
#define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Old style macro.
8282
#endif
83+
#define IM_UNICODE_CODEPOINT_MAX 0xFFFF // Last Unicode code point supported by this build.
84+
#define IM_UNICODE_CODEPOINT_INVALID 0xFFFD // Standard invalid Unicode code point.
8385

8486
// Warnings
8587
#if defined(__clang__)
@@ -2045,7 +2047,7 @@ struct ImFontGlyphRangesBuilder
20452047
ImVector<ImU32> UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used)
20462048

20472049
ImFontGlyphRangesBuilder() { Clear(); }
2048-
inline void Clear() { int size_in_bytes = 0x10000 / 8; UsedChars.resize(size_in_bytes / (int)sizeof(ImU32)); memset(UsedChars.Data, 0, (size_t)size_in_bytes); }
2050+
inline void Clear() { int size_in_bytes = (IM_UNICODE_CODEPOINT_MAX+1) / 8; UsedChars.resize(size_in_bytes / (int)sizeof(ImU32)); memset(UsedChars.Data, 0, (size_t)size_in_bytes); }
20492051
inline bool GetBit(int n) const { int off = (n >> 5); ImU32 mask = 1u << (n & 31); return (UsedChars[off] & mask) != 0; } // Get bit n in the array
20502052
inline void SetBit(int n) { int off = (n >> 5); ImU32 mask = 1u << (n & 31); UsedChars[off] |= mask; } // Set bit n in the array
20512053
inline void AddChar(ImWchar c) { SetBit(c); } // Add character
@@ -2057,12 +2059,12 @@ struct ImFontGlyphRangesBuilder
20572059
// See ImFontAtlas::AddCustomRectXXX functions.
20582060
struct ImFontAtlasCustomRect
20592061
{
2060-
unsigned int ID; // Input // User ID. Use <0x10000 to map into a font glyph, >=0x10000 for other/internal/custom texture data.
2062+
unsigned int ID; // Input // User ID. Use < 0x110000 to map into a font glyph, >= 0x110000 for other/internal/custom texture data.
20612063
unsigned short Width, Height; // Input // Desired rectangle dimension
20622064
unsigned short X, Y; // Output // Packed position in Atlas
2063-
float GlyphAdvanceX; // Input // For custom font glyphs only (ID<0x10000): glyph xadvance
2064-
ImVec2 GlyphOffset; // Input // For custom font glyphs only (ID<0x10000): glyph display offset
2065-
ImFont* Font; // Input // For custom font glyphs only (ID<0x10000): target font
2065+
float GlyphAdvanceX; // Input // For custom font glyphs only (ID < 0x110000): glyph xadvance
2066+
ImVec2 GlyphOffset; // Input // For custom font glyphs only (ID < 0x110000): glyph display offset
2067+
ImFont* Font; // Input // For custom font glyphs only (ID < 0x110000): target font
20662068
ImFontAtlasCustomRect() { ID = 0xFFFFFFFF; Width = Height = 0; X = Y = 0xFFFF; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0,0); Font = NULL; }
20672069
bool IsPacked() const { return X != 0xFFFF; }
20682070
};
@@ -2142,8 +2144,8 @@ struct ImFontAtlas
21422144
// You can also request your rectangles to be mapped as font glyph (given a font + Unicode point),
21432145
// so you can render e.g. custom colorful icons and use them as regular glyphs.
21442146
// Read misc/fonts/README.txt for more details about using colorful icons.
2145-
IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList
2146-
IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x10000 to register a rectangle to map into a specific font.
2147+
IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x110000. Id >= 0x80000000 are reserved for ImGui and ImDrawList
2148+
IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x110000 to register a rectangle to map into a specific font.
21472149
const ImFontAtlasCustomRect*GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; }
21482150

21492151
// [Internal]

imgui_demo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3416,18 +3416,18 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
34163416
if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size))
34173417
{
34183418
// Display all glyphs of the fonts in separate pages of 256 characters
3419-
for (int base = 0; base < 0x10000; base += 256)
3419+
for (unsigned int base = 0; base <= IM_UNICODE_CODEPOINT_MAX; base += 256)
34203420
{
34213421
int count = 0;
3422-
for (int n = 0; n < 256; n++)
3422+
for (unsigned int n = 0; n < 256; n++)
34233423
count += font->FindGlyphNoFallback((ImWchar)(base + n)) ? 1 : 0;
34243424
if (count > 0 && ImGui::TreeNode((void*)(intptr_t)base, "U+%04X..U+%04X (%d %s)", base, base + 255, count, count > 1 ? "glyphs" : "glyph"))
34253425
{
34263426
float cell_size = font->FontSize * 1;
34273427
float cell_spacing = style.ItemSpacing.y;
34283428
ImVec2 base_pos = ImGui::GetCursorScreenPos();
34293429
ImDrawList* draw_list = ImGui::GetWindowDrawList();
3430-
for (int n = 0; n < 256; n++)
3430+
for (unsigned int n = 0; n < 256; n++)
34313431
{
34323432
ImVec2 cell_p1(base_pos.x + (n % 16) * (cell_size + cell_spacing), base_pos.y + (n / 16) * (cell_size + cell_spacing));
34333433
ImVec2 cell_p2(cell_p1.x + cell_size, cell_p1.y + cell_size);

imgui_draw.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,8 @@ ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed
17251725

17261726
int ImFontAtlas::AddCustomRectRegular(unsigned int id, int width, int height)
17271727
{
1728-
IM_ASSERT(id >= 0x10000);
1728+
// Breaking change on 2019/11/21 (1.74): ImFontAtlas::AddCustomRectRegular() now requires an ID >= 0x110000 (instead of >= 0x10000)
1729+
IM_ASSERT(id >= 0x110000);
17291730
IM_ASSERT(width > 0 && width <= 0xFFFF);
17301731
IM_ASSERT(height > 0 && height <= 0xFFFF);
17311732
ImFontAtlasCustomRect r;
@@ -1905,7 +1906,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
19051906
dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1);
19061907

19071908
for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
1908-
for (int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++)
1909+
for (unsigned int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++)
19091910
{
19101911
if (dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option for MergeMode (e.g. MergeOverwrite==true)
19111912
continue;
@@ -2189,7 +2190,7 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
21892190
for (int i = 0; i < atlas->CustomRects.Size; i++)
21902191
{
21912192
const ImFontAtlasCustomRect& r = atlas->CustomRects[i];
2192-
if (r.Font == NULL || r.ID > 0x10000)
2193+
if (r.Font == NULL || r.ID >= 0x110000)
21932194
continue;
21942195

21952196
IM_ASSERT(r.Font->ContainerAtlas == atlas);
@@ -2453,7 +2454,7 @@ void ImFontGlyphRangesBuilder::AddText(const char* text, const char* text_end)
24532454
text += c_len;
24542455
if (c_len == 0)
24552456
break;
2456-
if (c < 0x10000)
2457+
if (c <= IM_UNICODE_CODEPOINT_MAX)
24572458
AddChar((ImWchar)c);
24582459
}
24592460
}
@@ -2467,12 +2468,12 @@ void ImFontGlyphRangesBuilder::AddRanges(const ImWchar* ranges)
24672468

24682469
void ImFontGlyphRangesBuilder::BuildRanges(ImVector<ImWchar>* out_ranges)
24692470
{
2470-
int max_codepoint = 0x10000;
2471-
for (int n = 0; n < max_codepoint; n++)
2471+
const int max_codepoint = IM_UNICODE_CODEPOINT_MAX;
2472+
for (int n = 0; n <= max_codepoint; n++)
24722473
if (GetBit(n))
24732474
{
24742475
out_ranges->push_back((ImWchar)n);
2475-
while (n < max_codepoint - 1 && GetBit(n + 1))
2476+
while (n < max_codepoint && GetBit(n + 1))
24762477
n++;
24772478
out_ranges->push_back((ImWchar)n);
24782479
}
@@ -2601,7 +2602,7 @@ void ImFont::AddGlyph(ImWchar codepoint, float x0, float y0, float x1, float y1,
26012602
void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst)
26022603
{
26032604
IM_ASSERT(IndexLookup.Size > 0); // Currently this can only be called AFTER the font has been built, aka after calling ImFontAtlas::GetTexDataAs*() function.
2604-
int index_size = IndexLookup.Size;
2605+
unsigned int index_size = (unsigned int)IndexLookup.Size;
26052606

26062607
if (dst < index_size && IndexLookup.Data[dst] == (ImWchar)-1 && !overwrite_dst) // 'dst' already exists
26072608
return;

imgui_widgets.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,7 +3157,7 @@ namespace ImStb
31573157
static int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return obj->CurLenW; }
31583158
static ImWchar STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return obj->TextW[idx]; }
31593159
static float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { ImWchar c = obj->TextW[line_start_idx + char_idx]; if (c == '\n') return STB_TEXTEDIT_GETWIDTH_NEWLINE; ImGuiContext& g = *GImGui; return g.Font->GetCharAdvance(c) * (g.FontSize / g.Font->FontSize); }
3160-
static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : key; }
3160+
static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x200000 ? 0 : key; }
31613161
static ImWchar STB_TEXTEDIT_NEWLINE = '\n';
31623162
static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
31633163
{
@@ -3340,6 +3340,10 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
33403340
if (c >= 0xE000 && c <= 0xF8FF)
33413341
return false;
33423342

3343+
// Filter Unicode ranges we are not handling in this build.
3344+
if (c > IM_UNICODE_CODEPOINT_MAX)
3345+
return false;
3346+
33433347
// Generic named filters
33443348
if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific))
33453349
{
@@ -3763,7 +3767,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
37633767
s += ImTextCharFromUtf8(&c, s, NULL);
37643768
if (c == 0)
37653769
break;
3766-
if (c >= 0x10000 || !InputTextFilterCharacter(&c, flags, callback, callback_user_data))
3770+
if (!InputTextFilterCharacter(&c, flags, callback, callback_user_data))
37673771
continue;
37683772
clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
37693773
}

0 commit comments

Comments
 (0)