Skip to content

Commit 8bd4285

Browse files
committed
Merge pull request godotengine#106621 from bruvzg/hexbox_bl
Adjust hex code box baseline calculation.
2 parents bc50082 + 7fc4521 commit 8bd4285

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

modules/text_server_adv/text_server_adv.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4961,7 +4961,8 @@ bool TextServerAdvanced::_shaped_text_resize_object(const RID &p_shaped, const V
49614961
} else if (sd->preserve_invalid || (sd->preserve_control && is_control(gl.index))) {
49624962
// Glyph not found, replace with hex code box.
49634963
if (sd->orientation == ORIENTATION_HORIZONTAL) {
4964-
sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y);
4964+
sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.85);
4965+
sd->descent = MAX(sd->descent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.15);
49654966
} else {
49664967
sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5));
49674968
sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5));
@@ -5242,7 +5243,8 @@ bool TextServerAdvanced::_shape_substr(ShapedTextDataAdvanced *p_new_sd, const S
52425243
} else if (p_new_sd->preserve_invalid || (p_new_sd->preserve_control && is_control(gl.index))) {
52435244
// Glyph not found, replace with hex code box.
52445245
if (p_new_sd->orientation == ORIENTATION_HORIZONTAL) {
5245-
p_new_sd->ascent = MAX(p_new_sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y);
5246+
p_new_sd->ascent = MAX(p_new_sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.85);
5247+
p_new_sd->descent = MAX(p_new_sd->descent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.15);
52465248
} else {
52475249
p_new_sd->ascent = MAX(p_new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5));
52485250
p_new_sd->descent = MAX(p_new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5));
@@ -6593,7 +6595,8 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
65936595
gl.index = p_sd->text[i];
65946596
if (p_sd->orientation == ORIENTATION_HORIZONTAL) {
65956597
gl.advance = get_hex_code_box_size(fs, gl.index).x;
6596-
p_sd->ascent = MAX(p_sd->ascent, get_hex_code_box_size(fs, gl.index).y);
6598+
p_sd->ascent = MAX(p_sd->ascent, get_hex_code_box_size(fs, gl.index).y * 0.85);
6599+
p_sd->descent = MAX(p_sd->descent, get_hex_code_box_size(fs, gl.index).y * 0.15);
65976600
} else {
65986601
gl.advance = get_hex_code_box_size(fs, gl.index).y;
65996602
gl.y_off = get_hex_code_box_size(fs, gl.index).y;

modules/text_server_fb/text_server_fb.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,7 +3834,8 @@ bool TextServerFallback::_shaped_text_resize_object(const RID &p_shaped, const V
38343834
} else if (sd->preserve_invalid || (sd->preserve_control && is_control(gl.index))) {
38353835
// Glyph not found, replace with hex code box.
38363836
if (sd->orientation == ORIENTATION_HORIZONTAL) {
3837-
sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y);
3837+
sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.85);
3838+
sd->descent = MAX(sd->descent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.15);
38383839
} else {
38393840
sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5));
38403841
sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5));
@@ -4013,7 +4014,8 @@ RID TextServerFallback::_shaped_text_substr(const RID &p_shaped, int64_t p_start
40134014
} else if (new_sd->preserve_invalid || (new_sd->preserve_control && is_control(gl.index))) {
40144015
// Glyph not found, replace with hex code box.
40154016
if (new_sd->orientation == ORIENTATION_HORIZONTAL) {
4016-
new_sd->ascent = MAX(new_sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y);
4017+
new_sd->ascent = MAX(new_sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.85);
4018+
new_sd->descent = MAX(new_sd->descent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.15);
40174019
} else {
40184020
new_sd->ascent = MAX(new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5));
40194021
new_sd->descent = MAX(new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5));
@@ -4830,7 +4832,8 @@ bool TextServerFallback::_shaped_text_shape(const RID &p_shaped) {
48304832
// Glyph not found, replace with hex code box.
48314833
if (sd->orientation == ORIENTATION_HORIZONTAL) {
48324834
gl.advance = get_hex_code_box_size(gl.font_size, gl.index).x;
4833-
sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y);
4835+
sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.85);
4836+
sd->descent = MAX(sd->descent, get_hex_code_box_size(gl.font_size, gl.index).y * 0.15);
48344837
} else {
48354838
gl.advance = get_hex_code_box_size(gl.font_size, gl.index).y;
48364839
sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5));

scene/gui/rich_text_label.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V
17081708
} else if (!(glyphs[glyph_idx].flags & TextServer::GRAPHEME_IS_VIRTUAL)) {
17091709
// Hex code box.
17101710
Vector2 gl_size = TS->get_hex_code_box_size(glyphs[glyph_idx].font_size, glyphs[glyph_idx].index);
1711-
if (p_click.y >= baseline_y - gl_size.y * 0.9 && p_click.y <= baseline_y + gl_size.y * 0.2) {
1711+
if (p_click.y >= baseline_y - gl_size.y * 0.85 && p_click.y <= baseline_y + gl_size.y * 0.15) {
17121712
char_pos = glyphs[glyph_idx].start;
17131713
char_clicked = true;
17141714
}

0 commit comments

Comments
 (0)