Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text rendering character advancing adds visual space for Unicode VARIATION_SELECTOR-16 codepoint #7471

Open
ConnorBP opened this issue Apr 4, 2024 · 2 comments

Comments

@ConnorBP
Copy link

ConnorBP commented Apr 4, 2024

Version/Branch of Dear ImGui:

Version 1.90.5 WIP Docking branch

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx11.cpp

Compiler, OS:

Windows 10 22H2

Full config/build information:

Dear ImGui 1.90.5 WIP (19044)
--------------------------------

sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1937
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------

io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
io.ConfigFlags: 0x00000001
 NavEnableKeyboard
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------

io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 1024,1024
io.DisplaySize: 1920.00,1080.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------

style.WindowPadding: 16.00,16.00
style.WindowBorderSize: 2.00
style.FramePadding: 8.00,6.00
style.FrameRounding: 3.00
style.FrameBorderSize: 2.00
style.ItemSpacing: 8.00,8.00
style.ItemInnerSpacing: 4.00,4.00

Details:

My Issue/Question:

When rendering certain unicode characters (emojis primarily) on Text, or buttons, or tabs, the text rendering code advances an additional space when the character includes the variation selector 16 codepoint at the end of the emoji.

here is an example of a mouse emoji which uses this codepoint as well as one which does not:
https://unicode.scarfboy.com/?s=%F0%9F%96%B2%EF%B8%8F%F0%9F%96%B1

issue happens inside of imgui_draw.cpp in the function void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip) const

I am investigating where to put a fix right now, if I find it I will submit a PR. If someone else already knows where to skip past this character however I would most appreciate the info :)

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce your issue
ImGui::Begin("Example Bug");
if(ImGui::BeginTabBar("#tabBar1", ImGuiTabBarFlags_FittingPolicyResizeDown | ImGuiTabBarFlags_NoCloseWithMiddleMouseButton || ImGuiTabBarFlags_NoTabListScrollingButtons)) {
    if(ImGui::BeginTabItem((const char*)u8"🖱InputConfig")) {
    
    }
    if(ImGui::BeginTabItem((const char*)u8"🖲️InputConfigBroken")) {
    
    }
    ImGui::EndTabBar();
}
ImGui::End();

UPDATE:
Some of the spacing issues were related to visual studio saving with BOM (byte order mark) enabled by default. Here is how to fix it for anyone who stumbles upon this: https://stackoverflow.com/questions/5406172/utf-8-without-bom

@ocornut ocornut changed the title BUG: Text rendering character advancing adds visual space for Unicode VARIATION_SELECTOR-16 codepoint Text rendering character advancing adds visual space for Unicode VARIATION_SELECTOR-16 codepoint Apr 4, 2024
@GamingMinds-DanielC
Copy link
Contributor

I am investigating where to put a fix right now, if I find it I will submit a PR. If someone else already knows where to skip past this character however I would most appreciate the info :)

The best way I can think of would be to adjust ImFontGlyph::AdvanceX for the glyphs in question when loading a font, plus the corresponding entries of ImFont::IndexAdvanceX.

@ConnorBP
Copy link
Author

I am investigating where to put a fix right now, if I find it I will submit a PR. If someone else already knows where to skip past this character however I would most appreciate the info :)

The best way I can think of would be to adjust ImFontGlyph::AdvanceX for the glyphs in question when loading a font, plus the corresponding entries of ImFont::IndexAdvanceX.

Ahh interesting. I like this, will give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants