summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-04 22:21:04 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-08-04 22:21:04 +0000
commit9552816ddad6b1d9f261e4e899c4813205a034f2 (patch)
tree313f55bf6eec8081ac07f417f0da088a01e3f21e
parentbdfdadfa517e931138e42055472068b48f54ad14 (diff)
parentd53e5123b6fa797495af4f0cb5ceb69074278d8f (diff)
downloadpango-9552816ddad6b1d9f261e4e899c4813205a034f2.tar.gz
Merge branch 'fix-split-cursors-at-end' into 'main'
Add an old testcase See merge request GNOME/pango!386
-rw-r--r--pango/pango-layout.c8
-rw-r--r--tests/test-bidi.c2
-rw-r--r--tests/testmisc.c66
3 files changed, 68 insertions, 8 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 8303be2c..520782c5 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -2466,14 +2466,6 @@ pango_layout_get_cursor_pos (PangoLayout *layout,
else
x1_trailing = line_rect.width;
}
- else if (index >= layout_line->start_index + layout_line->length)
- {
- dir1 = layout_line->resolved_dir;
- if (layout_line->resolved_dir == PANGO_DIRECTION_LTR)
- x1_trailing = line_rect.width;
- else
- x1_trailing = 0;
- }
else
{
gint prev_index = g_utf8_prev_char (layout->text + index) - layout->text;
diff --git a/tests/test-bidi.c b/tests/test-bidi.c
index 48d2a81f..fbdcc8cb 100644
--- a/tests/test-bidi.c
+++ b/tests/test-bidi.c
@@ -125,6 +125,8 @@ test_bidi_embedding_levels (void)
{ "The title is مفتاح معايير الويب⁧!⁩ in Arabic.", PANGO_DIRECTION_LTR, "\0\0\0\0\0\0\0\0\0\0\0\0\0\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\1\0\0\0\0\0\0\0\0\0\0\0", PANGO_DIRECTION_LTR }, // FIXME
{ "one two ثلاثة 1234 خمسة", PANGO_DIRECTION_LTR, "\0\0\0\0\0\0\0\0\1\1\1\1\1\1\2\2\2\2\1\1\1\1\1", PANGO_DIRECTION_LTR },
{ "one two ثلاثة ١٢٣٤ خمسة", PANGO_DIRECTION_LTR, "\0\0\0\0\0\0\0\0\1\1\1\1\1\1\2\2\2\2\1\1\1\1\1", PANGO_DIRECTION_LTR },
+ { "abאב12cd", PANGO_DIRECTION_LTR, "\0\0\1\1\2\2\0\0" },
+ { "abאב‪xy‬cd", PANGO_DIRECTION_LTR, "\0\0\1\1\1\2\2\2\0\0" },
};
diff --git a/tests/testmisc.c b/tests/testmisc.c
index fe2e9075..54566f78 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -301,6 +301,70 @@ test_fallback_shape (void)
g_object_unref (context);
}
+/* https://bugzilla.gnome.org/show_bug.cgi?id=547303 */
+static void
+test_get_cursor_crash (void)
+{
+ PangoContext *context;
+ PangoLayout *layout;
+ int i;
+
+ char *string = "foo\n\rbar\r\nbaz\n\nqux\n\n..";
+
+ context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
+
+ layout = pango_layout_new (context);
+
+ pango_layout_set_text (layout, string, -1);
+
+ for (i = 0; string[i]; i++)
+ {
+ PangoRectangle rectA, rectB;
+
+ pango_layout_get_cursor_pos (layout, i, &rectA, &rectB);
+ g_assert_cmpint (rectA.x, ==, rectB.x);
+ }
+
+ g_object_unref (layout);
+ g_object_unref (context);
+}
+
+/* Test that get_cursor returns split cursors in the
+ * expected situations. In particular, this was broken
+ * at the end of the string here.
+ */
+static void
+test_get_cursor (void)
+{
+ const char *text = "abאב";
+ PangoContext *context;
+ PangoLayout *layout;
+ PangoRectangle strong, weak;
+
+ context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
+
+ layout = pango_layout_new (context);
+ pango_layout_set_text (layout, text, -1);
+
+ pango_layout_get_cursor_pos (layout, 0, &strong, &weak);
+ g_assert_cmpint (strong.x, ==, weak.x);
+
+ pango_layout_get_cursor_pos (layout, 1, &strong, &weak);
+ g_assert_cmpint (strong.x, ==, weak.x);
+
+ pango_layout_get_cursor_pos (layout, 2, &strong, &weak);
+ g_assert_cmpint (strong.x, !=, weak.x);
+
+ pango_layout_get_cursor_pos (layout, 4, &strong, &weak);
+ g_assert_cmpint (strong.x, ==, weak.x);
+
+ pango_layout_get_cursor_pos (layout, 6, &strong, &weak);
+ g_assert_cmpint (strong.x, !=, weak.x);
+
+ g_object_unref (layout);
+ g_object_unref (context);
+}
+
int
main (int argc, char *argv[])
{
@@ -320,6 +384,8 @@ main (int argc, char *argv[])
g_test_add_func ("/gravity/for-script", test_gravity_for_script);
g_test_add_func ("/layout/fallback-shape", test_fallback_shape);
g_test_add_func ("/language/to-tag", test_language_to_tag);
+ g_test_add_func ("/bidi/get-cursor-crash", test_get_cursor_crash);
+ g_test_add_func ("/bidi/get-cursor", test_get_cursor);
return g_test_run ();
}