Merge pull request #110317 from bruvzg/ts_zero_w

[TextServer] Do not add extra spacing to zero-width glyphs.
This commit is contained in:
Thaddeus Crews
2025-10-01 13:12:38 -05:00
2 changed files with 36 additions and 5 deletions

View File

@ -6816,6 +6816,22 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
unsigned int last_cluster_index = 0;
bool last_cluster_valid = true;
unsigned int last_non_zero_w = glyph_count - 1;
if (last_run) {
for (unsigned int i = glyph_count - 1; i > 0; i--) {
last_non_zero_w = i;
if (p_sd->orientation == ORIENTATION_HORIZONTAL) {
if (glyph_pos[i].x_advance != 0) {
break;
}
} else {
if (glyph_pos[i].y_advance != 0) {
break;
}
}
}
}
double adv_rem = 0.0;
for (unsigned int i = 0; i < glyph_count; i++) {
if ((i > 0) && (last_cluster_id != glyph_info[i].cluster)) {
@ -6907,8 +6923,8 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
gl.x_off += _font_get_baseline_offset(gl.font_rid) * (double)(_font_get_ascent(gl.font_rid, gl.font_size) + _font_get_descent(gl.font_rid, gl.font_size));
}
}
if (!last_run || i < glyph_count - 1) {
// Do not add extra spacing to the last glyph of the string.
if ((!last_run || i < last_non_zero_w) && !Math::is_zero_approx(gl.advance)) {
// Do not add extra spacing to the last glyph of the string and zero width glyphs.
if (sp_sp && is_whitespace(p_sd->text[glyph_info[i].cluster])) {
gl.advance += sp_sp;
} else {