From 7fa2dc0c69a1b1499913be65a20619e35b149ec5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 24 Jun 2022 08:40:00 -0400 Subject: Fix handling of ligature carets in some cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With a text of "ර් ", we were accidentally producing a cursor position outside of the [start_xpos, end_xpos] range, which clearly makes no sense. Test included. Fixes: #684 --- pango/glyphstring.c | 2 +- tests/test-bidi.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/pango/glyphstring.c b/pango/glyphstring.c index ea9a6398..e52d41d4 100644 --- a/pango/glyphstring.c +++ b/pango/glyphstring.c @@ -548,7 +548,7 @@ pango_glyph_string_index_to_x_full (PangoGlyphString *glyphs, } if (trailing) - cluster_offset += 1; + cluster_offset = MIN (cluster_offset + 1, cluster_chars); if (G_UNLIKELY (!cluster_chars)) /* pedantic */ { diff --git a/tests/test-bidi.c b/tests/test-bidi.c index ba578ba8..70e96543 100644 --- a/tests/test-bidi.c +++ b/tests/test-bidi.c @@ -453,6 +453,44 @@ test_move_cursor_para (void) g_object_unref (layout); } +static void +test_sinhala_cursor (void) +{ + const char *text = "ර් á "; + PangoLayout *layout; + const char *p; + const PangoLogAttr *attrs; + int n, i; + + layout = pango_layout_new (context); + + pango_layout_set_text (layout, text, -1); + + if (pango_layout_get_unknown_glyphs_count (layout) > 0) + { + g_object_unref (layout); + g_test_skip ("missing Sinhala fonts"); + return; + } + + attrs = pango_layout_get_log_attrs_readonly (layout, &n); + + for (i = 0, p = text; *p; i++, p = g_utf8_next_char (p)) + { + int index = p - text; + PangoRectangle strong, weak; + + if (!attrs[i].is_cursor_position) + continue; + + g_assert_true (pango_layout_get_direction (layout, index) == PANGO_DIRECTION_LTR); + + pango_layout_get_cursor_pos (layout, index, &strong, &weak); + g_assert_true (strong.x == weak.x); + g_assert_true (strong.width == weak.width); + } +} + int main (int argc, char *argv[]) { @@ -471,6 +509,7 @@ main (int argc, char *argv[]) g_test_add_func ("/bidi/embedding-levels", test_bidi_embedding_levels); g_test_add_func ("/bidi/move-cursor-line", test_move_cursor_line); g_test_add_func ("/bidi/move-cursor-para", test_move_cursor_para); + g_test_add_func ("/bidi/sinhala-cursor", test_sinhala_cursor); return g_test_run (); } -- cgit v1.2.1