Forráskód Böngészése

Merge pull request #102854 from bruvzg/brk_trim3

[TextServer] Fix space trimming on line break.
Thaddeus Crews 5 hónapja
szülő
commit
030cc9945e
2 módosított fájl, 15 hozzáadás és 2 törlés
  1. 2 2
      servers/text_server.cpp
  2. 13 0
      tests/servers/test_text_server.h

+ 2 - 2
servers/text_server.cpp

@@ -847,7 +847,7 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped
 					if (last_end <= l_gl[start_pos].start) {
 						lines.push_back(l_gl[start_pos].start);
 						lines.push_back(l_gl[end_pos].end);
-						cur_safe_brk = end_pos;
+						cur_safe_brk = last_safe_break;
 						last_end = l_gl[end_pos].end;
 					}
 					trim_next = true;
@@ -1021,7 +1021,7 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, do
 						if (p_width > indent) {
 							l_width = p_width - indent;
 						}
-						cur_safe_brk = end_pos;
+						cur_safe_brk = last_safe_break;
 						last_end = l_gl[end_pos].end;
 					}
 					trim_next = true;

+ 13 - 0
tests/servers/test_text_server.h

@@ -596,6 +596,19 @@ TEST_SUITE("[TextServer]") {
 					CHECK_FALSE_MESSAGE(brks[5] != 14, "Invalid line break position.");
 				}
 
+				brks = ts->shaped_text_get_line_breaks(ctx, 35.0, 0, TextServer::BREAK_WORD_BOUND | TextServer::BREAK_MANDATORY | TextServer::BREAK_TRIM_EDGE_SPACES);
+				CHECK_FALSE_MESSAGE(brks.size() != 6, "Invalid line breaks number.");
+				if (brks.size() == 6) {
+					CHECK_FALSE_MESSAGE(brks[0] != 0, "Invalid line break position.");
+					CHECK_FALSE_MESSAGE(brks[1] != 4, "Invalid line break position.");
+
+					CHECK_FALSE_MESSAGE(brks[2] != 5, "Invalid line break position.");
+					CHECK_FALSE_MESSAGE(brks[3] != 9, "Invalid line break position.");
+
+					CHECK_FALSE_MESSAGE(brks[4] != 10, "Invalid line break position.");
+					CHECK_FALSE_MESSAGE(brks[5] != 14, "Invalid line break position.");
+				}
+
 				ts->free_rid(ctx);
 
 				for (int j = 0; j < font.size(); j++) {