Skip to content

Commit 5bfe5cf

Browse files
committed
dep/imgui: Remap non-breaking space to space
MacOS likes to use them for formatting.
1 parent 351f67a commit 5bfe5cf

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

dep/imgui/src/imgui_draw.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,11 +4408,21 @@ static void ImFontBaked_BuildGrowIndex(ImFontBaked* baked, int new_size)
44084408
baked->IndexLookup.resize(new_size, IM_FONTGLYPH_INDEX_UNUSED);
44094409
}
44104410

4411-
static void ImFontAtlas_FontHookRemapCodepoint(ImFontAtlas* atlas, ImFont* font, ImWchar* c)
4411+
static ImWchar ImFontAtlas_FontHookRemapCodepoint(ImFontAtlas* atlas, ImFont* font, ImWchar c)
44124412
{
44134413
IM_UNUSED(atlas);
44144414
if (font->RemapPairs.Data.Size != 0)
4415-
*c = (ImWchar)font->RemapPairs.GetInt((ImGuiID)*c, (int)*c);
4415+
{
4416+
const ImWchar remap_c = (ImWchar)font->RemapPairs.GetInt((ImGuiID)c, 0);
4417+
if (remap_c != 0)
4418+
return remap_c;
4419+
}
4420+
4421+
// Handle non-breaking spaces. The non-breaking space isn't handled by ImCharIsBlankW(),
4422+
// so word wrapping should behave correctly if we remap it to a regular space here.
4423+
// MacOS likes to use NNBSP in formatting, so need to handle that here. Strictly speaking,
4424+
// it should be narrower, but it doesn't exist in our fonts so shrug.
4425+
return (c == 0x00A0 || c == 0x202F) ? ImWchar(' ') : c; // NBSP/NNBSP
44164426
}
44174427

44184428
static ImFontGlyph* ImFontBaked_BuildLoadGlyph(ImFontBaked* baked, ImWchar codepoint)
@@ -4429,7 +4439,7 @@ static ImFontGlyph* ImFontBaked_BuildLoadGlyph(ImFontBaked* baked, ImWchar codep
44294439

44304440
// User remapping hooks
44314441
ImWchar src_codepoint = codepoint;
4432-
ImFontAtlas_FontHookRemapCodepoint(atlas, font, &codepoint);
4442+
codepoint = ImFontAtlas_FontHookRemapCodepoint(atlas, font, codepoint);
44334443

44344444
//char utf8_buf[5];
44354445
//IMGUI_DEBUG_LOG("[font] BuildLoadGlyph U+%04X (%s)\n", (unsigned int)codepoint, ImTextCharToUtf8(utf8_buf, (unsigned int)codepoint));
@@ -5195,7 +5205,7 @@ bool ImFontBaked::IsGlyphLoaded(ImWchar c)
51955205
bool ImFont::IsGlyphInFont(ImWchar c)
51965206
{
51975207
ImFontAtlas* atlas = ContainerAtlas;
5198-
ImFontAtlas_FontHookRemapCodepoint(atlas, this, &c);
5208+
c = ImFontAtlas_FontHookRemapCodepoint(atlas, this, c);
51995209
for (ImFontConfig* src : Sources)
52005210
{
52015211
const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader;

0 commit comments

Comments
 (0)