Fix line trim/ellipsis when line do not have space or newline at the end.

This commit is contained in:
bruvzg 2022-09-16 19:46:11 +03:00
parent 99e06740cf
commit 19443a7fef
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
2 changed files with 53 additions and 39 deletions

View File

@ -3070,8 +3070,10 @@ int64_t TextServerAdvanced::font_get_glyph_index(const RID &p_font_rid, int64_t
bool TextServerAdvanced::font_has_char(const RID &p_font_rid, int64_t p_char) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
ERR_FAIL_COND_V(!fd, false);
ERR_FAIL_COND_V_MSG((p_char >= 0xd800 && p_char <= 0xdfff) || (p_char > 0x10ffff), false, "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_char, 16) + ".");
if (!fd) {
return false;
}
MutexLock lock(fd->mutex);
if (fd->cache.is_empty()) {
@ -4500,6 +4502,10 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(const RID &p_shaped_l
int glyphs_to = (is_rtl) ? sd_size - 1 : -1;
int glyphs_delta = (is_rtl) ? +1 : -1;
if (enforce_ellipsis && (width + ellipsis_width <= p_width)) {
trim_pos = -1;
ellipsis_pos = (is_rtl) ? 0 : sd_size;
} else {
for (int i = glyphs_from; i != glyphs_to; i += glyphs_delta) {
if (!is_rtl) {
width -= sd_glyphs[i].advance * sd_glyphs[i].repeat;
@ -4531,6 +4537,7 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(const RID &p_shaped_l
width -= sd_glyphs[i].advance * sd_glyphs[i].repeat;
}
}
}
sd->overrun_trim_data.trim_pos = trim_pos;
sd->overrun_trim_data.ellipsis_pos = ellipsis_pos;

View File

@ -2127,8 +2127,10 @@ int64_t TextServerFallback::font_get_glyph_index(const RID &p_font_rid, int64_t
bool TextServerFallback::font_has_char(const RID &p_font_rid, int64_t p_char) const {
FontFallback *fd = font_owner.get_or_null(p_font_rid);
ERR_FAIL_COND_V(!fd, false);
ERR_FAIL_COND_V_MSG((p_char >= 0xd800 && p_char <= 0xdfff) || (p_char > 0x10ffff), false, "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_char, 16) + ".");
if (!fd) {
return false;
}
MutexLock lock(fd->mutex);
if (fd->cache.is_empty()) {
@ -3453,6 +3455,10 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(const RID &p_shaped_l
int last_valid_cut = 0;
bool found = false;
if (enforce_ellipsis && (width + ellipsis_width <= p_width)) {
trim_pos = -1;
ellipsis_pos = sd_size;
} else {
for (int i = sd_size - 1; i != -1; i--) {
width -= sd_glyphs[i].advance * sd_glyphs[i].repeat;
@ -3480,6 +3486,7 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(const RID &p_shaped_l
}
}
}
}
sd->overrun_trim_data.trim_pos = trim_pos;
sd->overrun_trim_data.ellipsis_pos = ellipsis_pos;