summaryrefslogtreecommitdiff
path: root/scene/resources/text_line.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/text_line.cpp')
-rw-r--r--scene/resources/text_line.cpp49
1 files changed, 43 insertions, 6 deletions
diff --git a/scene/resources/text_line.cpp b/scene/resources/text_line.cpp
index 823d742d72..afab44834d 100644
--- a/scene/resources/text_line.cpp
+++ b/scene/resources/text_line.cpp
@@ -218,7 +218,48 @@ Array TextLine::get_objects() const {
}
Rect2 TextLine::get_object_rect(Variant p_key) const {
- return TS->shaped_text_get_object_rect(rid, p_key);
+ Vector2 ofs;
+
+ float length = TS->shaped_text_get_width(rid);
+ if (width > 0) {
+ switch (alignment) {
+ case HORIZONTAL_ALIGNMENT_FILL:
+ case HORIZONTAL_ALIGNMENT_LEFT:
+ break;
+ case HORIZONTAL_ALIGNMENT_CENTER: {
+ if (length <= width) {
+ if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
+ ofs.x += Math::floor((width - length) / 2.0);
+ } else {
+ ofs.y += Math::floor((width - length) / 2.0);
+ }
+ } else if (TS->shaped_text_get_inferred_direction(rid) == TextServer::DIRECTION_RTL) {
+ if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
+ ofs.x += width - length;
+ } else {
+ ofs.y += width - length;
+ }
+ }
+ } break;
+ case HORIZONTAL_ALIGNMENT_RIGHT: {
+ if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
+ ofs.x += width - length;
+ } else {
+ ofs.y += width - length;
+ }
+ } break;
+ }
+ }
+ if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
+ ofs.y += TS->shaped_text_get_ascent(rid);
+ } else {
+ ofs.x += TS->shaped_text_get_ascent(rid);
+ }
+
+ Rect2 rect = TS->shaped_text_get_object_rect(rid, p_key);
+ rect.position += ofs;
+
+ return rect;
}
void TextLine::set_horizontal_alignment(HorizontalAlignment p_alignment) {
@@ -276,11 +317,7 @@ float TextLine::get_width() const {
Size2 TextLine::get_size() const {
const_cast<TextLine *>(this)->_shape();
- if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) {
- return Size2(TS->shaped_text_get_size(rid).x, TS->shaped_text_get_size(rid).y);
- } else {
- return Size2(TS->shaped_text_get_size(rid).x, TS->shaped_text_get_size(rid).y);
- }
+ return TS->shaped_text_get_size(rid);
}
float TextLine::get_line_ascent() const {