Skip to content

Commit 6c34f48

Browse files
committed
Fix font fallback for lines with only non-visual/control characters.
1 parent 967e2d4 commit 6c34f48

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

modules/text_server_adv/text_server_adv.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4998,6 +4998,7 @@ bool TextServerAdvanced::_shaped_text_resize_object(const RID &p_shaped, const V
49984998

49994999
int sd_size = sd->glyphs.size();
50005000
int span_size = spans.size();
5001+
const char32_t *ch = sd->text.ptr();
50015002

50025003
for (int i = 0; i < sd_size; i++) {
50035004
Glyph gl = sd->glyphs[i];
@@ -5026,7 +5027,7 @@ bool TextServerAdvanced::_shaped_text_resize_object(const RID &p_shaped, const V
50265027
}
50275028
sd->upos = MAX(sd->upos, _font_get_underline_position(gl.font_rid, gl.font_size));
50285029
sd->uthk = MAX(sd->uthk, _font_get_underline_thickness(gl.font_rid, gl.font_size));
5029-
} else if (sd->preserve_invalid || (sd->preserve_control && is_control(gl.index))) {
5030+
} else if (sd->preserve_invalid || (sd->preserve_control && is_control(ch[gl.start - sd->start]))) {
50305031
// Glyph not found, replace with hex code box.
50315032
if (sd->orientation == ORIENTATION_HORIZONTAL) {
50325033
sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.85);
@@ -5200,6 +5201,7 @@ bool TextServerAdvanced::_shape_substr(ShapedTextDataAdvanced *p_new_sd, const S
52005201

52015202
int sd_size = p_sd->glyphs.size();
52025203
const Glyph *sd_glyphs = p_sd->glyphs.ptr();
5204+
const char32_t *ch = p_sd->text.ptr();
52035205
for (int ov = 0; ov < bidi_ranges.size(); ov++) {
52045206
UErrorCode err = U_ZERO_ERROR;
52055207

@@ -5330,7 +5332,7 @@ bool TextServerAdvanced::_shape_substr(ShapedTextDataAdvanced *p_new_sd, const S
53305332
p_new_sd->ascent = MAX(p_new_sd->ascent, Math::round(_font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5));
53315333
p_new_sd->descent = MAX(p_new_sd->descent, Math::round(_font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5));
53325334
}
5333-
} else if (p_new_sd->preserve_invalid || (p_new_sd->preserve_control && is_control(gl.index))) {
5335+
} else if (p_new_sd->preserve_invalid || (p_new_sd->preserve_control && is_control(ch[gl.start - p_sd->start]))) {
53345336
// Glyph not found, replace with hex code box.
53355337
if (p_new_sd->orientation == ORIENTATION_HORIZONTAL) {
53365338
p_new_sd->ascent = MAX(p_new_sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.85);
@@ -6936,6 +6938,24 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
69366938
p_sd->descent = MAX(p_sd->descent, _font_get_descent(f, fs) + _font_get_spacing(f, SPACING_BOTTOM));
69376939
p_sd->upos = MAX(p_sd->upos, _font_get_underline_position(f, fs));
69386940
p_sd->uthk = MAX(p_sd->uthk, _font_get_underline_thickness(f, fs));
6941+
} else if (p_start != p_end) {
6942+
if (p_fb_index >= p_fonts.size()) {
6943+
Glyph gl;
6944+
gl.start = p_start;
6945+
gl.end = p_end;
6946+
gl.span_index = p_span;
6947+
gl.font_rid = f;
6948+
gl.font_size = fs;
6949+
gl.flags = GRAPHEME_IS_VALID;
6950+
p_sd->glyphs.push_back(gl);
6951+
6952+
p_sd->ascent = MAX(p_sd->ascent, _font_get_ascent(f, fs) + _font_get_spacing(f, SPACING_TOP));
6953+
p_sd->descent = MAX(p_sd->descent, _font_get_descent(f, fs) + _font_get_spacing(f, SPACING_BOTTOM));
6954+
p_sd->upos = MAX(p_sd->upos, _font_get_underline_position(f, fs));
6955+
p_sd->uthk = MAX(p_sd->uthk, _font_get_underline_thickness(f, fs));
6956+
} else {
6957+
_shape_run(p_sd, p_start, p_end, p_script, p_direction, p_fonts, p_span, p_fb_index + 1, p_start, p_end, f);
6958+
}
69396959
}
69406960
}
69416961

scene/gui/label.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void Label::_shape() const {
159159
for (const String &str : para_text) {
160160
Paragraph para;
161161
para.text_rid = TS->create_shaped_text();
162-
para.text = str;
162+
para.text = str + String::chr(0x200B);
163163
para.start = start;
164164
start += str.length() + ps.length();
165165
paragraphs.push_back(para);

0 commit comments

Comments
 (0)