diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-01-13 10:20:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-13 10:20:02 +0100 |
commit | a987ebfde2810fb5092437b0ffd1ee3c2f54e7c9 (patch) | |
tree | 2a5898b52e4d97b647d5da9b99537bfdb9a2a83d /servers | |
parent | 8fce6166cbc635b069c09b782ea67c495348abcb (diff) | |
parent | baec983d8ab1877768eab3cd122566f05b4bce26 (diff) |
Merge pull request #56714 from bruvzg/fix_alignment_break_overrun
Diffstat (limited to 'servers')
-rw-r--r-- | servers/text/text_server_extension.cpp | 9 | ||||
-rw-r--r-- | servers/text/text_server_extension.h | 2 | ||||
-rw-r--r-- | servers/text_server.cpp | 47 | ||||
-rw-r--r-- | servers/text_server.h | 1 |
4 files changed, 36 insertions, 23 deletions
diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp index a51b62e730..a2195d1ddf 100644 --- a/servers/text/text_server_extension.cpp +++ b/servers/text/text_server_extension.cpp @@ -194,6 +194,7 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(_shaped_text_set_direction, "shaped", "direction"); GDVIRTUAL_BIND(_shaped_text_get_direction, "shaped"); + GDVIRTUAL_BIND(_shaped_text_get_inferred_direction, "shaped"); GDVIRTUAL_BIND(_shaped_text_set_bidi_override, "shaped", "override"); @@ -954,6 +955,14 @@ TextServer::Direction TextServerExtension::shaped_text_get_direction(RID p_shape return TextServer::Direction::DIRECTION_AUTO; } +TextServer::Direction TextServerExtension::shaped_text_get_inferred_direction(RID p_shaped) const { + int ret; + if (GDVIRTUAL_CALL(_shaped_text_get_inferred_direction, p_shaped, ret)) { + return (TextServer::Direction)ret; + } + return TextServer::Direction::DIRECTION_LTR; +} + void TextServerExtension::shaped_text_set_orientation(RID p_shaped, TextServer::Orientation p_orientation) { GDVIRTUAL_CALL(_shaped_text_set_orientation, p_shaped, p_orientation); } diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h index 9b456c2dd7..77f2ced951 100644 --- a/servers/text/text_server_extension.h +++ b/servers/text/text_server_extension.h @@ -315,8 +315,10 @@ public: virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) override; virtual Direction shaped_text_get_direction(RID p_shaped) const override; + virtual Direction shaped_text_get_inferred_direction(RID p_shaped) const override; GDVIRTUAL2(_shaped_text_set_direction, RID, Direction); GDVIRTUAL1RC(/*Direction*/ int, _shaped_text_get_direction, RID); + GDVIRTUAL1RC(/*Direction*/ int, _shaped_text_get_inferred_direction, RID); virtual void shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) override; GDVIRTUAL2(_shaped_text_set_bidi_override, RID, const Array &); diff --git a/servers/text_server.cpp b/servers/text_server.cpp index 143cda985d..0cc4358785 100644 --- a/servers/text_server.cpp +++ b/servers/text_server.cpp @@ -347,6 +347,7 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("shaped_text_set_direction", "shaped", "direction"), &TextServer::shaped_text_set_direction, DEFVAL(DIRECTION_AUTO)); ClassDB::bind_method(D_METHOD("shaped_text_get_direction", "shaped"), &TextServer::shaped_text_get_direction); + ClassDB::bind_method(D_METHOD("shaped_text_get_inferred_direction", "shaped"), &TextServer::shaped_text_get_inferred_direction); ClassDB::bind_method(D_METHOD("shaped_text_set_bidi_override", "shaped", "override"), &TextServer::shaped_text_set_bidi_override); @@ -1224,6 +1225,17 @@ void TextServer::shaped_text_draw(RID p_shaped, RID p_canvas, const Vector2 &p_p } // Draw at the baseline. for (int i = 0; i < v_size; i++) { + if (trim_pos >= 0) { + if (rtl) { + if (i < trim_pos) { + continue; + } + } else { + if (i >= trim_pos) { + break; + } + } + } for (int j = 0; j < glyphs[i].repeat; j++) { if (p_clip_r > 0) { // Clip right / bottom. @@ -1251,17 +1263,6 @@ void TextServer::shaped_text_draw(RID p_shaped, RID p_canvas, const Vector2 &p_p } } } - if (trim_pos >= 0) { - if (rtl) { - if (i < trim_pos && (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { - continue; - } - } else { - if (i >= trim_pos && (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { - break; - } - } - } if (glyphs[i].font_rid != RID()) { font_draw_glyph(glyphs[i].font_rid, p_canvas, glyphs[i].font_size, ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, p_color); @@ -1293,7 +1294,7 @@ void TextServer::shaped_text_draw(RID p_shaped, RID p_canvas, const Vector2 &p_p void TextServer::shaped_text_draw_outline(RID p_shaped, RID p_canvas, const Vector2 &p_pos, float p_clip_l, float p_clip_r, int p_outline_size, const Color &p_color) const { TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped); - bool rtl = (shaped_text_get_direction(p_shaped) == DIRECTION_RTL); + bool rtl = (shaped_text_get_inferred_direction(p_shaped) == DIRECTION_RTL); int ellipsis_pos = shaped_text_get_ellipsis_pos(p_shaped); int trim_pos = shaped_text_get_trim_pos(p_shaped); @@ -1319,6 +1320,17 @@ void TextServer::shaped_text_draw_outline(RID p_shaped, RID p_canvas, const Vect } // Draw at the baseline. for (int i = 0; i < v_size; i++) { + if (trim_pos >= 0) { + if (rtl) { + if (i < trim_pos) { + continue; + } + } else { + if (i >= trim_pos) { + break; + } + } + } for (int j = 0; j < glyphs[i].repeat; j++) { if (p_clip_r > 0) { // Clip right / bottom. @@ -1346,17 +1358,6 @@ void TextServer::shaped_text_draw_outline(RID p_shaped, RID p_canvas, const Vect } } } - if (trim_pos >= 0) { - if (rtl) { - if (i < trim_pos) { - continue; - } - } else { - if (i >= trim_pos && (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { - break; - } - } - } if (glyphs[i].font_rid != RID()) { font_draw_glyph_outline(glyphs[i].font_rid, p_canvas, glyphs[i].font_size, p_outline_size, ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, p_color); } diff --git a/servers/text_server.h b/servers/text_server.h index d5dccc0edb..07f0ae5045 100644 --- a/servers/text_server.h +++ b/servers/text_server.h @@ -370,6 +370,7 @@ public: virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) = 0; virtual Direction shaped_text_get_direction(RID p_shaped) const = 0; + virtual Direction shaped_text_get_inferred_direction(RID p_shaped) const = 0; virtual void shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) = 0; |