diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-06-24 08:40:00 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-06-24 08:52:02 -0400 |
commit | 7fa2dc0c69a1b1499913be65a20619e35b149ec5 (patch) | |
tree | b117cbf72fd4b1fb2b7e5c9aa021e5d918b541f5 | |
parent | ab12425de4668f02f7390b987f94374fa5f6f871 (diff) | |
download | pango-7fa2dc0c69a1b1499913be65a20619e35b149ec5.tar.gz |
Fix handling of ligature carets in some casesfix-lig-carets-sinhala
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
-rw-r--r-- | pango/glyphstring.c | 2 | ||||
-rw-r--r-- | tests/test-bidi.c | 39 |
2 files changed, 40 insertions, 1 deletions
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 (); } |