From cfcec5cccade634936ce7272fd97b01508cdd61e Mon Sep 17 00:00:00 2001 From: barthy-koeln Date: Thu, 21 May 2026 10:56:54 +0200 Subject: [PATCH] fix(text_server_fb): zero-width space detection and rendering --- modules/text_server_fb/text_server_fb.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index 447fc62783..bcd838c3c6 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -4937,7 +4937,8 @@ bool TextServerFallback::_shaped_text_shape(const RID &p_shaped) { for (int j = span.end - 1; j >= span.start; j--) { last_non_zero_w = j; uint32_t idx = (int32_t)sd->text[j - sd->start]; - if (!is_control(idx) && !(idx >= 0x200B && idx <= 0x200D)) { + bool zero_w_idx = (sd->preserve_control) ? (idx == 0x200B || idx == 0xFEFF) : ((idx >= 0x200B && idx <= 0x200D) || idx == 0x2060 || idx == 0xFEFF); + if (!is_control(idx) && !zero_w_idx) { break; } } @@ -4952,7 +4953,7 @@ bool TextServerFallback::_shaped_text_shape(const RID &p_shaped) { gl.count = 1; gl.font_size = span.font_size; gl.index = (int32_t)sd->text[j - sd->start]; // Use codepoint. - bool zw = (gl.index >= 0x200b && gl.index <= 0x200d); + bool zw = (sd->preserve_control) ? (gl.index == 0x200B || gl.index == 0xFEFF) : ((gl.index >= 0x200B && gl.index <= 0x200D) || gl.index == 0x2060 || gl.index == 0xFEFF); if (gl.index == 0x0009 || gl.index == 0x000b || zw) { gl.index = 0x0020; } @@ -5039,6 +5040,10 @@ bool TextServerFallback::_shaped_text_shape(const RID &p_shaped) { sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5)); } } + if (zw) { + gl.index = 0; + gl.advance = 0.0; + } sd->width += gl.advance; sd->glyphs.push_back(gl); }