[pango/fix-lig-carets-sinhala] Fix handling of ligature carets in some cases
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/fix-lig-carets-sinhala] Fix handling of ligature carets in some cases
- Date: Fri, 24 Jun 2022 12:52:11 +0000 (UTC)
commit 7fa2dc0c69a1b1499913be65a20619e35b149ec5
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jun 24 08:40:00 2022 -0400
Fix handling of ligature carets in some cases
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 ea9a63981..e52d41d4f 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 ba578ba8d..70e96543f 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 ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]