@@ -4810,6 +4810,17 @@ bool TextServerFallback::_shaped_text_shape(const RID &p_shaped) {
48104810 sd->glyphs .push_back (gl);
48114811 } else {
48124812 // Text span.
4813+ int last_non_zero_w = sd->end - 1 ;
4814+ if (i == sd->spans .size () - 1 ) {
4815+ for (int j = span.end - 1 ; j > span.start ; j--) {
4816+ last_non_zero_w = j;
4817+ uint32_t idx = (int32_t )sd->text [j - sd->start ];
4818+ if (!is_control (idx) && !(idx >= 0x200B && idx <= 0x200D )) {
4819+ break ;
4820+ }
4821+ }
4822+ }
4823+
48134824 RID prev_font;
48144825 for (int j = span.start ; j < span.end ; j++) {
48154826 Glyph gl;
@@ -4819,7 +4830,8 @@ bool TextServerFallback::_shaped_text_shape(const RID &p_shaped) {
48194830 gl.count = 1 ;
48204831 gl.font_size = span.font_size ;
48214832 gl.index = (int32_t )sd->text [j - sd->start ]; // Use codepoint.
4822- if (gl.index == 0x0009 || gl.index == 0x000b ) {
4833+ bool zw = (gl.index >= 0x200b && gl.index <= 0x200d );
4834+ if (gl.index == 0x0009 || gl.index == 0x000b || zw) {
48234835 gl.index = 0x0020 ;
48244836 }
48254837 if (!sd->preserve_control && is_control (gl.index )) {
@@ -4865,8 +4877,11 @@ bool TextServerFallback::_shaped_text_shape(const RID &p_shaped) {
48654877 sd->descent = MAX (sd->descent , Math::round (_font_get_glyph_advance (gl.font_rid , gl.font_size , gl.index ).x * 0.5 ));
48664878 }
48674879 }
4868- if (j < sd->end - 1 ) {
4869- // Do not add extra spacing to the last glyph of the string.
4880+ if (zw) {
4881+ gl.advance = 0.0 ;
4882+ }
4883+ if ((j < last_non_zero_w) && !Math::is_zero_approx (gl.advance )) {
4884+ // Do not add extra spacing to the last glyph of the string and zero width glyphs.
48704885 if (is_whitespace (sd->text [j - sd->start ])) {
48714886 gl.advance += sd->extra_spacing [SPACING_SPACE] + _font_get_spacing (gl.font_rid , SPACING_SPACE);
48724887 } else {
0 commit comments