Browse Source

Fix center aligned text clipping.

bruvzg 3 năm trước cách đây
mục cha
commit
28520002cf
2 tập tin đã thay đổi với 48 bổ sung16 xóa
  1. 24 8
      scene/resources/text_line.cpp
  2. 24 8
      scene/resources/text_paragraph.cpp

+ 24 - 8
scene/resources/text_line.cpp

@@ -327,10 +327,18 @@ void TextLine::draw(RID p_canvas, const Vector2 &p_pos, const Color &p_color) co
 			case HORIZONTAL_ALIGNMENT_LEFT:
 				break;
 			case HORIZONTAL_ALIGNMENT_CENTER: {
-				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);
+				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: {
@@ -366,10 +374,18 @@ void TextLine::draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outline_si
 			case HORIZONTAL_ALIGNMENT_LEFT:
 				break;
 			case HORIZONTAL_ALIGNMENT_CENTER: {
-				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);
+				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: {

+ 24 - 8
scene/resources/text_paragraph.cpp

@@ -609,10 +609,18 @@ void TextParagraph::draw(RID p_canvas, const Vector2 &p_pos, const Color &p_colo
 				case HORIZONTAL_ALIGNMENT_LEFT:
 					break;
 				case HORIZONTAL_ALIGNMENT_CENTER: {
-					if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) {
-						ofs.x += Math::floor((l_width - line_width) / 2.0);
-					} else {
-						ofs.y += Math::floor((l_width - line_width) / 2.0);
+					if (line_width <= l_width) {
+						if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) {
+							ofs.x += Math::floor((l_width - line_width) / 2.0);
+						} else {
+							ofs.y += Math::floor((l_width - line_width) / 2.0);
+						}
+					} else if (TS->shaped_text_get_inferred_direction(lines_rid[i]) == TextServer::DIRECTION_RTL) {
+						if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) {
+							ofs.x += l_width - line_width;
+						} else {
+							ofs.y += l_width - line_width;
+						}
 					}
 				} break;
 				case HORIZONTAL_ALIGNMENT_RIGHT: {
@@ -701,10 +709,18 @@ void TextParagraph::draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outli
 				case HORIZONTAL_ALIGNMENT_LEFT:
 					break;
 				case HORIZONTAL_ALIGNMENT_CENTER: {
-					if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) {
-						ofs.x += Math::floor((l_width - length) / 2.0);
-					} else {
-						ofs.y += Math::floor((l_width - length) / 2.0);
+					if (length <= l_width) {
+						if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) {
+							ofs.x += Math::floor((l_width - length) / 2.0);
+						} else {
+							ofs.y += Math::floor((l_width - length) / 2.0);
+						}
+					} else if (TS->shaped_text_get_inferred_direction(lines_rid[i]) == TextServer::DIRECTION_RTL) {
+						if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) {
+							ofs.x += l_width - length;
+						} else {
+							ofs.y += l_width - length;
+						}
 					}
 				} break;
 				case HORIZONTAL_ALIGNMENT_RIGHT: {