summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-07-07 00:00:06 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-07-07 00:00:06 +0000
commitcfbf6dc53a61e1665b69149bcc1e003760a49499 (patch)
tree067201c87bd78ebd837fb9c1558a0a81b741f2a3
parentf9364a0e6e08140111dc8310eb753c456993c200 (diff)
parent0280fd31b01010b76c85ce7ac0bbff1d9c152933 (diff)
downloadpango-cfbf6dc53a61e1665b69149bcc1e003760a49499.tar.gz
Merge branch 'more-test-coverage2' into 'master'
utils: Remove leftover code See merge request GNOME/pango!360
-rw-r--r--pango/pango-layout.c27
-rw-r--r--tests/layouts/valid-1.expected8
-rw-r--r--tests/layouts/valid-10.expected37
-rw-r--r--tests/layouts/valid-10.markup2
-rw-r--r--tests/layouts/valid-11.expected53
-rw-r--r--tests/layouts/valid-11.markup2
-rw-r--r--tests/layouts/valid-12.expected35
-rw-r--r--tests/layouts/valid-12.markup2
-rw-r--r--tests/layouts/valid-13.expected35
-rw-r--r--tests/layouts/valid-13.markup2
-rw-r--r--tests/layouts/valid-14.expected39
-rw-r--r--tests/layouts/valid-14.markup2
-rw-r--r--tests/layouts/valid-15.expected36
-rw-r--r--tests/layouts/valid-15.markup2
-rw-r--r--tests/layouts/valid-16.expected37
-rw-r--r--tests/layouts/valid-16.markup2
-rw-r--r--tests/layouts/valid-2.expected8
-rw-r--r--tests/layouts/valid-3.expected8
-rw-r--r--tests/layouts/valid-4.expected8
-rw-r--r--tests/layouts/valid-5.expected8
-rw-r--r--tests/layouts/valid-6.expected8
-rw-r--r--tests/layouts/valid-7.expected43
-rw-r--r--tests/layouts/valid-7.markup2
-rw-r--r--tests/layouts/valid-8.expected34
-rw-r--r--tests/layouts/valid-8.markup2
-rw-r--r--tests/layouts/valid-9.expected49
-rw-r--r--tests/layouts/valid-9.markup2
-rw-r--r--tests/meson.build3
-rw-r--r--tests/test-bidi.c166
-rw-r--r--tests/test-break.c33
-rw-r--r--tests/test-layout.c424
-rw-r--r--tests/testmisc.c100
-rw-r--r--tests/testscript.c10
-rw-r--r--utils/pango-segmentation.c11
34 files changed, 1129 insertions, 111 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index a59e0ac0..0227f819 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -201,6 +201,7 @@ pango_layout_init (PangoLayout *layout)
layout->alignment = PANGO_ALIGN_LEFT;
layout->justify = FALSE;
layout->auto_dir = TRUE;
+ layout->single_paragraph = FALSE;
layout->log_attrs = NULL;
layout->lines = NULL;
@@ -390,7 +391,7 @@ pango_layout_get_width (PangoLayout *layout)
* If @height is negative, it will be the (negative of) maximum number of lines
* per paragraph. That is, the total number of lines shown may well be more than
* this value if the layout contains multiple paragraphs of text.
- * The default value of -1 means that first line of each paragraph is ellipsized.
+ * The default value of -1 means that the first line of each paragraph is ellipsized.
* This behavior may be changed in the future to act per layout instead of per
* paragraph. File a bug against pango at
* [https://gitlab.gnome.org/gnome/pango](https://gitlab.gnome.org/gnome/pango)
@@ -565,7 +566,7 @@ pango_layout_get_indent (PangoLayout *layout)
* @layout: a `PangoLayout`
* @spacing: the amount of spacing
*
- * Sets the amount of spacing in Pango unit between
+ * Sets the amount of spacing in Pango units between
* the lines of the layout.
*
* When placing lines with spacing, Pango arranges things so that
@@ -778,6 +779,8 @@ pango_layout_get_font_description (PangoLayout *layout)
*
* Note that this setting is not implemented and so is ignored in
* Pango older than 1.18.
+ *
+ * The default value is %FALSE.
*/
void
pango_layout_set_justify (PangoLayout *layout,
@@ -867,7 +870,7 @@ pango_layout_set_auto_dir (PangoLayout *layout,
gboolean
pango_layout_get_auto_dir (PangoLayout *layout)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT (layout), FALSE);
+ g_return_val_if_fail (PANGO_IS_LAYOUT (layout), TRUE);
return layout->auto_dir;
}
@@ -879,6 +882,8 @@ pango_layout_get_auto_dir (PangoLayout *layout)
*
* Sets the alignment for the layout: how partial lines are
* positioned within the horizontal space available.
+ *
+ * The default alignment is %PANGO_ALIGN_LEFT.
*/
void
pango_layout_set_alignment (PangoLayout *layout,
@@ -950,7 +955,7 @@ pango_layout_set_tabs (PangoLayout *layout,
*
* The return value should be freed with [method@Pango.TabArray.free].
*
- * Return value: (nullable): a copy of the tabs for this layout
+ * Return value: (transfer full) (nullable): a copy of the tabs for this layout
*/
PangoTabArray*
pango_layout_get_tabs (PangoLayout *layout)
@@ -974,6 +979,8 @@ pango_layout_get_tabs (PangoLayout *layout)
* as paragraph separators; instead, keep all text in a single paragraph,
* and display a glyph for paragraph separator characters. Used when
* you want to allow editing of newlines on a single text line.
+ *
+ * The default value is %FALSE.
*/
void
pango_layout_set_single_paragraph_mode (PangoLayout *layout,
@@ -1026,6 +1033,8 @@ pango_layout_get_single_paragraph_mode (PangoLayout *layout)
* each paragraph is ellipsized separately or the entire layout
* is ellipsized as a whole depends on the set height of the layout.
*
+ * The default value is %PANGO_ELLIPSIZE_NONE.
+ *
* See [method@Pango.Layout.set_height] for details.
*
* Since: 1.6
@@ -1895,9 +1904,9 @@ pango_layout_index_to_line_x (PangoLayout *layout,
* of a run.
*
* Motion here is in cursor positions, not in characters, so a single
- * call to [method@Pango.Layout.move_cursor_visually] may move the cursor over
- * multiple characters when multiple characters combine to form a single
- * grapheme.
+ * call to [method@Pango.Layout.move_cursor_visually] may move the cursor
+ * over multiple characters when multiple characters combine to form a
+ * single grapheme.
*/
void
pango_layout_move_cursor_visually (PangoLayout *layout,
@@ -2378,8 +2387,6 @@ pango_layout_line_get_char_direction (PangoLayoutLine *layout_line,
run_list = run_list->next;
}
- g_assert_not_reached ();
-
return PANGO_DIRECTION_LTR;
}
@@ -4302,7 +4309,7 @@ pango_layout_check_lines (PangoLayout *layout)
itemize_attrs = NULL;
}
- layout->log_attrs = g_new (PangoLogAttr, layout->n_chars + 1);
+ layout->log_attrs = g_new0 (PangoLogAttr, layout->n_chars + 1);
start_offset = 0;
start = layout->text;
diff --git a/tests/layouts/valid-1.expected b/tests/layouts/valid-1.expected
index 292d6f43..411c7560 100644
--- a/tests/layouts/valid-1.expected
+++ b/tests/layouts/valid-1.expected
@@ -15,6 +15,14 @@ range 22 41
[22,41]underline=1
range 41 2147483647
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 25(0) 26(0) 27(0) 28(0) 29(0) 30(0) 31(0) 32(0) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 44(0) 45(0) 46(0) 47(0) 47(1) 49(0)
+
--- lines
i=1, index=0, paragraph-start=1, dir=ltr 'This is a test of the automatic emergency brake!
diff --git a/tests/layouts/valid-10.expected b/tests/layouts/valid-10.expected
new file mode 100644
index 00000000..137024b7
--- /dev/null
+++ b/tests/layouts/valid-10.expected
@@ -0,0 +1,37 @@
+Hello שלום Γειά σας
+
+--- parameters
+
+wrapped: 0
+ellipsized: 1
+lines: 2
+width: 102400
+
+--- attributes
+
+range 0 2147483647
+
+--- directions
+
+0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 12(0) 10(0) 8(0) 14(0) 15(0) 17(0) 19(0) 21(0) 23(0) 24(0) 26(0) 28(0) 28(1) 31(0)
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr 'Hello שלום Γειά σας
+'
+i=2, index=31, paragraph-start=1, dir=ltr ''
+
+--- runs
+
+i=1, index=0, chars=6, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'Hello '
+i=2, index=12, chars=4, level=1, gravity=south, flags=0, font=OMITTED, script=hebrew, language=he, 'שלום'
+i=3, index=14, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=hebrew, language=he, ' '
+i=4, index=15, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=greek, language=el, 'Γ'
+i=5, index=17, chars=7, level=0, gravity=south, flags=2, font=OMITTED, script=common, language=en-us, 'ειά σας'
+[0,2147483647]fallback=0
+i=6, index=30, no run, line end
+i=7, index=31, no run, line end
diff --git a/tests/layouts/valid-10.markup b/tests/layouts/valid-10.markup
new file mode 100644
index 00000000..15bf693d
--- /dev/null
+++ b/tests/layouts/valid-10.markup
@@ -0,0 +1,2 @@
+width=100,justify=true,ellipsize=end
+Hello שלום Γειά σας
diff --git a/tests/layouts/valid-11.expected b/tests/layouts/valid-11.expected
new file mode 100644
index 00000000..a1fafc31
--- /dev/null
+++ b/tests/layouts/valid-11.expected
@@ -0,0 +1,53 @@
+double low error
+
+--- parameters
+
+wrapped: 0
+ellipsized: 0
+lines: 2
+width: 225280
+
+--- attributes
+
+range 0 6
+[0,6]underline=2
+[0,6]overline=1
+range 6 7
+range 7 10
+[7,10]underline=3
+[7,10]strikethrough=1
+range 10 11
+range 11 16
+[11,16]underline=4
+[11,16]rise=1024
+range 16 2147483647
+
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 15(1) 17(0)
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr 'double low error
+'
+i=2, index=17, paragraph-start=1, dir=ltr ''
+
+--- runs
+
+i=1, index=0, chars=6, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'double'
+[0,6]underline=2
+[0,6]overline=1
+i=2, index=6, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, ' '
+i=3, index=7, chars=3, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'low'
+[7,10]underline=3
+[7,10]strikethrough=1
+i=4, index=10, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, ' '
+i=5, index=11, chars=5, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'error'
+[11,16]rise=1024
+[11,16]underline=4
+i=6, index=16, no run, line end
+i=7, index=17, no run, line end
diff --git a/tests/layouts/valid-11.markup b/tests/layouts/valid-11.markup
new file mode 100644
index 00000000..fbf1abd2
--- /dev/null
+++ b/tests/layouts/valid-11.markup
@@ -0,0 +1,2 @@
+width=220,wrap=char
+<span underline='double' overline='single'>double</span> <span underline='low' strikethrough='true'>low</span> <span underline='error' rise='1024'>error</span>
diff --git a/tests/layouts/valid-12.expected b/tests/layouts/valid-12.expected
new file mode 100644
index 00000000..d66ae134
--- /dev/null
+++ b/tests/layouts/valid-12.expected
@@ -0,0 +1,35 @@
+a b c d
e f g h
+
+--- parameters
+
+wrapped: 1
+ellipsized: 0
+lines: 3
+
+--- attributes
+
+range 0 2147483647
+
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 25(0) 25(1) 29(0) 30(0) 31(0) 32(0) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 44(0) 45(0) 46(0) 47(0) 48(0) 49(0) 50(0) 50(1) 52(0)
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr 'a b c d
'
+i=2, index=28, paragraph-start=0, dir=ltr 'e f g h
+'
+i=3, index=52, paragraph-start=1, dir=ltr ''
+
+--- runs
+
+i=1, index=0, chars=25, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'a b c d'
+i=2, index=25, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, '
'
+i=3, index=28, no run, line end
+i=4, index=28, chars=23, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'e f g h'
+i=5, index=51, no run, line end
+i=6, index=52, no run, line end
diff --git a/tests/layouts/valid-12.markup b/tests/layouts/valid-12.markup
new file mode 100644
index 00000000..b7306cc6
--- /dev/null
+++ b/tests/layouts/valid-12.markup
@@ -0,0 +1,2 @@
+wrap=word,tabs=0 50 100 150 200
+a b c d
e f g h
diff --git a/tests/layouts/valid-13.expected b/tests/layouts/valid-13.expected
new file mode 100644
index 00000000..3064610d
--- /dev/null
+++ b/tests/layouts/valid-13.expected
@@ -0,0 +1,35 @@
+a b c d
e f g h
+
+--- parameters
+
+wrapped: 0
+ellipsized: 0
+lines: 1
+
+--- attributes
+
+range 0 2147483647
+
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 25(0) 28(0) 29(0) 30(0) 31(0) 32(0) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 44(0) 45(0) 46(0) 47(0) 48(0) 49(0) 50(0) 51(0) 51(1)
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr 'a b c d
e f g h
+'
+
+--- runs
+
+i=1, index=0, chars=25, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'a b c d'
+[0,-1]show=2
+i=2, index=25, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, '
'
+[0,-1]show=2
+i=3, index=28, chars=24, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'e f g h
+'
+[0,-1]show=2
+i=4, index=52, no run, line end
diff --git a/tests/layouts/valid-13.markup b/tests/layouts/valid-13.markup
new file mode 100644
index 00000000..be2345d1
--- /dev/null
+++ b/tests/layouts/valid-13.markup
@@ -0,0 +1,2 @@
+wrap=word,tabs=0 50 100 150 200,single_paragraph=true
+a b c d
e f g h
diff --git a/tests/layouts/valid-14.expected b/tests/layouts/valid-14.expected
new file mode 100644
index 00000000..9c4d5111
--- /dev/null
+++ b/tests/layouts/valid-14.expected
@@ -0,0 +1,39 @@
+你好 Hello שלום Γειά σας
+
+--- parameters
+
+wrapped: 0
+ellipsized: 1
+lines: 2
+width: 166912
+
+--- attributes
+
+range 0 2147483647
+
+--- directions
+
+0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 3(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 19(0) 17(0) 15(0) 21(0) 22(0) 24(0) 26(0) 28(0) 30(0) 31(0) 33(0) 35(0) 35(1) 38(0)
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr '你好 Hello שלום Γειά σας
+'
+i=2, index=38, paragraph-start=1, dir=ltr ''
+
+--- runs
+
+i=1, index=0, chars=1, level=0, gravity=south, flags=2, font=OMITTED, script=common, language=en-us, '你'
+[0,2147483647]fallback=1
+i=2, index=3, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=han, language=xx, '好'
+i=3, index=6, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=han, language=xx, ' '
+i=4, index=7, chars=6, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'Hello '
+i=5, index=19, chars=4, level=1, gravity=south, flags=0, font=OMITTED, script=hebrew, language=he, 'שלום'
+i=6, index=21, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=hebrew, language=he, ' '
+i=7, index=22, chars=8, level=0, gravity=south, flags=0, font=OMITTED, script=greek, language=el, 'Γειά σας'
+i=8, index=37, no run, line end
+i=9, index=38, no run, line end
diff --git a/tests/layouts/valid-14.markup b/tests/layouts/valid-14.markup
new file mode 100644
index 00000000..48412c04
--- /dev/null
+++ b/tests/layouts/valid-14.markup
@@ -0,0 +1,2 @@
+line_spacing=1.5,width=163,ellipsize=start
+你好 Hello שלום Γειά σας
diff --git a/tests/layouts/valid-15.expected b/tests/layouts/valid-15.expected
new file mode 100644
index 00000000..2711dfd8
--- /dev/null
+++ b/tests/layouts/valid-15.expected
@@ -0,0 +1,36 @@
+Lets see if this text is long enough to wrap due to height limitations. It might, or it might not.
+
+--- parameters
+
+wrapped: 1
+ellipsized: 1
+lines: 2
+width: 153600
+height: 40960
+
+--- attributes
+
+range 0 2147483647
+
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 24(1) 26(0) 27(0) 28(0) 29(0) 30(0) 31(0) 32(0) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 44(0) 45(0) 46(0) 47(0) 48(0) 49(0) 50(0) 51(0) 52(0) 53(0) 54(0) 55(0) 56(0) 57(0) 58(0) 59(0) 60(0) 61(0) 62(0) 63(0) 64(0) 65(0) 66(0) 67(0) 68(0) 69(0) 70(0) 71(0) 72(0) 73(0) 74(0) 75(0) 76(0) 77(0) 78(0) 79(0) 80(0) 81(0) 82(0) 83(0) 84(0) 85(0) 86(0) 87(0) 88(0) 89(0) 90(0) 91(0) 92(0) 93(0) 94(0) 95(0) 96(0) 97(0) 97(1)
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr 'Lets see if this text is '
+i=2, index=25, paragraph-start=0, dir=ltr 'long enough to wrap due to height limitations. It might, or it might not.
+'
+
+--- runs
+
+i=1, index=0, chars=25, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'Lets see if this text is '
+i=2, index=25, no run, line end
+i=3, index=25, chars=20, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'long enough to wrap '
+i=4, index=45, chars=53, level=0, gravity=south, flags=2, font=OMITTED, script=common, language=en-us, 'due to height limitations. It might, or it might not.'
+[0,2147483647]fallback=0
+i=5, index=98, no run, line end
diff --git a/tests/layouts/valid-15.markup b/tests/layouts/valid-15.markup
new file mode 100644
index 00000000..e3081c81
--- /dev/null
+++ b/tests/layouts/valid-15.markup
@@ -0,0 +1,2 @@
+ellipsize=end,height=40,width=150
+Lets see if this text is long enough to wrap due to height limitations. It might, or it might not.
diff --git a/tests/layouts/valid-16.expected b/tests/layouts/valid-16.expected
new file mode 100644
index 00000000..7ae3ae62
--- /dev/null
+++ b/tests/layouts/valid-16.expected
@@ -0,0 +1,37 @@
+Lets see if this text is long enough to wrap due to height limitations. It might, or it might not.
+
+--- parameters
+
+wrapped: 1
+ellipsized: 1
+lines: 3
+width: 153600
+
+--- attributes
+
+range 0 2147483647
+
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 24(1) 26(0) 27(0) 28(0) 29(0) 30(0) 31(0) 32(0) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 44(0) 45(0) 46(0) 47(0) 48(0) 49(0) 50(0) 51(0) 52(0) 53(0) 54(0) 55(0) 56(0) 57(0) 58(0) 59(0) 60(0) 61(0) 62(0) 63(0) 64(0) 65(0) 66(0) 67(0) 68(0) 69(0) 70(0) 71(0) 72(0) 73(0) 74(0) 75(0) 76(0) 77(0) 78(0) 79(0) 80(0) 81(0) 82(0) 83(0) 84(0) 85(0) 86(0) 87(0) 88(0) 89(0) 90(0) 91(0) 92(0) 93(0) 94(0) 95(0) 96(0) 97(0) 97(1) 99(0)
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr 'Lets see if this text is '
+i=2, index=25, paragraph-start=0, dir=ltr 'long enough to wrap due to height limitations. It might, or it might not.
+'
+i=3, index=99, paragraph-start=1, dir=ltr ''
+
+--- runs
+
+i=1, index=0, chars=25, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'Lets see if this text is '
+i=2, index=25, no run, line end
+i=3, index=25, chars=20, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'long enough to wrap '
+i=4, index=45, chars=53, level=0, gravity=south, flags=2, font=OMITTED, script=common, language=en-us, 'due to height limitations. It might, or it might not.'
+[0,2147483647]fallback=0
+i=5, index=98, no run, line end
+i=6, index=99, no run, line end
diff --git a/tests/layouts/valid-16.markup b/tests/layouts/valid-16.markup
new file mode 100644
index 00000000..91a8ae37
--- /dev/null
+++ b/tests/layouts/valid-16.markup
@@ -0,0 +1,2 @@
+wrap=word-char,ellipsize=end,width=150,height=-2
+Lets see if this text is long enough to wrap due to height limitations. It might, or it might not.
diff --git a/tests/layouts/valid-2.expected b/tests/layouts/valid-2.expected
index 2efc56fe..b71f5da3 100644
--- a/tests/layouts/valid-2.expected
+++ b/tests/layouts/valid-2.expected
@@ -16,6 +16,14 @@ range 20 25
[20,25]underline=1
range 25 2147483647
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 25(0) 26(0) 27(0) 28(0) 29(0) 30(0) 31(0) 31(1) 33(0)
+
--- lines
i=1, index=0, paragraph-start=1, dir=ltr 'test the blue drink after dinner
diff --git a/tests/layouts/valid-3.expected b/tests/layouts/valid-3.expected
index 247c61bf..d090bac0 100644
--- a/tests/layouts/valid-3.expected
+++ b/tests/layouts/valid-3.expected
@@ -10,6 +10,14 @@ lines: 2
range 0 2147483647
+--- directions
+
+0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 10(0) 10(1) 12(0)
+
--- lines
i=1, index=0, paragraph-start=1, dir=ltr 'ABC😀️D
diff --git a/tests/layouts/valid-4.expected b/tests/layouts/valid-4.expected
index 66796cb5..49688492 100644
--- a/tests/layouts/valid-4.expected
+++ b/tests/layouts/valid-4.expected
@@ -11,6 +11,14 @@ width: 192512
range 0 2147483647
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 26(0) 27(0) 28(0) 29(0) 30(0) 30(1) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 44(0) 45(0) 46(0) 47(0) 48(0) 49(0) 50(0) 51(0) 52(0) 53(0) 54(0) 55(0) 56(0) 57(0) 58(0) 59(0) 60(0) 61(0) 62(0) 62(1) 64(0) 65(0) 66(0) 67(0) 68(0) 69(0) 70(0) 71(0) 72(0) 73(0) 74(0) 75(0) 76(0) 77(0) 78(0) 79(0) 80(0) 81(0) 82(0) 83(0) 84(0) 85(0) 87(0) 89(0) 91(0) 92(0) 93(0) 94(0) 94(1) 97(0) 98(0) 100(0) 101(0) 102(0) 103(0) 104(0) 105(0) 106(0) 107(0) 108(0) 109(0) 110(0) 111(0) 112(0) 113(0) 114(0) 115(0) 116(0) 117(0) 118(0) 119(0) 120(0) 121(0) 122(0) 123(0) 123(1) 125(0) 126(0) 127(0) 128(0) 129(0) 130(0) 131(0) 132(0) 133(0) 134(0) 135(0) 136(0) 137(0) 138(0) 139(0) 140(0) 141(0) 142(0) 143(0) 144(0) 145(0) 146(0) 147(0) 148(0) 149(0) 150(0) 150(1) 152(0)
+
--- lines
i=1, index=0, paragraph-start=1, dir=ltr 'This paragraph should ac­tual­'
diff --git a/tests/layouts/valid-5.expected b/tests/layouts/valid-5.expected
index 5c6fa749..ce4ff215 100644
--- a/tests/layouts/valid-5.expected
+++ b/tests/layouts/valid-5.expected
@@ -15,6 +15,14 @@ range 21 31
[21,31]font-features=tnum=1
range 31 2147483647
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 20(1) 22(0) 23(0) 24(0) 25(0) 26(0) 27(0) 28(0) 29(0) 30(0) 31(0) 32(0) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 43(1) 45(0) 46(0) 47(0) 48(0) 49(0) 50(0) 51(0) 52(0) 53(0) 54(0) 55(0) 56(0) 57(0) 58(0) 59(0) 60(0) 61(0) 62(0) 63(0) 64(0) 65(0) 66(0) 67(0) 67(1) 69(0) 70(0) 71(0) 72(0) 73(0) 74(0) 75(0) 76(0) 77(0) 78(0) 79(0) 80(0) 81(0) 82(0) 83(0) 84(0) 85(0) 86(0) 87(0) 88(0) 89(0) 89(1) 91(0) 92(0) 93(0) 94(0) 95(0) 96(0) 97(0) 98(0) 99(0) 100(0) 101(0) 102(0) 103(0) 104(0) 105(0) 106(0) 107(0) 108(0) 109(0) 110(0) 111(0) 112(0) 113(0) 114(0) 115(0) 116(0) 116(1) 118(0) 119(0) 120(0) 121(0) 122(0) 123(0) 123(1) 125(0)
+
--- lines
i=1, index=0, paragraph-start=1, dir=ltr 'A test with multiple '
diff --git a/tests/layouts/valid-6.expected b/tests/layouts/valid-6.expected
index b8f90c34..040e0fa4 100644
--- a/tests/layouts/valid-6.expected
+++ b/tests/layouts/valid-6.expected
@@ -10,6 +10,14 @@ lines: 2
range 0 2147483647
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 25(0) 25(1) 27(0)
+
--- lines
i=1, index=0, paragraph-start=1, dir=ltr ' 0️⃣ Keycap Digit Zero
diff --git a/tests/layouts/valid-7.expected b/tests/layouts/valid-7.expected
new file mode 100644
index 00000000..7560a9cc
--- /dev/null
+++ b/tests/layouts/valid-7.expected
@@ -0,0 +1,43 @@
+This is a test of the automatic emergency brake!
+
+--- parameters
+
+wrapped: 0
+ellipsized: 1
+lines: 2
+width: 204800
+indent: 51200
+
+--- attributes
+
+range 0 22
+range 22 41
+[22,41]foreground=#00000000ffff
+[22,41]underline=1
+range 41 2147483647
+
+--- directions
+
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 25(0) 26(0) 27(0) 28(0) 29(0) 30(0) 31(0) 32(0) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 44(0) 45(0) 46(0) 47(0) 47(1) 49(0)
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr 'This is a test of the automatic emergency brake!
+'
+i=2, index=49, paragraph-start=1, dir=ltr ''
+
+--- runs
+
+i=1, index=0, chars=12, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'This is a te'
+i=2, index=12, chars=26, level=0, gravity=south, flags=2, font=OMITTED, script=common, language=en-us, 'st of the automatic emerge'
+[0,2147483647]fallback=0
+i=3, index=38, chars=3, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'ncy'
+[22,41]foreground=#00000000ffff
+[22,41]underline=1
+i=4, index=41, chars=7, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, ' brake!'
+i=5, index=48, no run, line end
+i=6, index=49, no run, line end
diff --git a/tests/layouts/valid-7.markup b/tests/layouts/valid-7.markup
new file mode 100644
index 00000000..d5f9821e
--- /dev/null
+++ b/tests/layouts/valid-7.markup
@@ -0,0 +1,2 @@
+width=200,indent=50,ellipsize=middle
+This is a test of the <span foreground="#0000ff" underline="single">automatic emergency</span> brake!
diff --git a/tests/layouts/valid-8.expected b/tests/layouts/valid-8.expected
new file mode 100644
index 00000000..185ba373
--- /dev/null
+++ b/tests/layouts/valid-8.expected
@@ -0,0 +1,34 @@
+Hello שלום Γειά σας
+
+--- parameters
+
+wrapped: 0
+ellipsized: 0
+lines: 2
+
+--- attributes
+
+range 0 2147483647
+
+--- directions
+
+0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 12(0) 10(0) 8(0) 14(0) 15(0) 17(0) 19(0) 21(0) 23(0) 24(0) 26(0) 28(0) 28(1) 31(0)
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr 'Hello שלום Γειά σας
+'
+i=2, index=31, paragraph-start=1, dir=ltr ''
+
+--- runs
+
+i=1, index=0, chars=6, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'Hello '
+i=2, index=12, chars=4, level=1, gravity=south, flags=0, font=OMITTED, script=hebrew, language=he, 'שלום'
+i=3, index=14, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=hebrew, language=he, ' '
+i=4, index=15, chars=8, level=0, gravity=south, flags=0, font=OMITTED, script=greek, language=el, 'Γειά σας'
+i=5, index=30, no run, line end
+i=6, index=31, no run, line end
diff --git a/tests/layouts/valid-8.markup b/tests/layouts/valid-8.markup
new file mode 100644
index 00000000..3272ea2b
--- /dev/null
+++ b/tests/layouts/valid-8.markup
@@ -0,0 +1,2 @@
+spacing=50,auto_dir=false,alignment=center
+Hello שלום Γειά σας
diff --git a/tests/layouts/valid-9.expected b/tests/layouts/valid-9.expected
new file mode 100644
index 00000000..d1388f62
--- /dev/null
+++ b/tests/layouts/valid-9.expected
@@ -0,0 +1,49 @@
+Hello שלום Γειά σας
+
+--- parameters
+
+wrapped: 1
+ellipsized: 0
+lines: 5
+width: 102400
+
+--- attributes
+
+range 0 30
+[0,30]letter-spacing=8888
+range 30 2147483647
+
+--- directions
+
+0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0
+
+--- cursor positions
+
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 5(1) 12(0) 10(0) 8(0) 14(0) 14(1) 17(0) 19(0) 21(0) 23(0) 23(1) 26(0) 28(0) 28(1) 31(0)
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr 'Hello שלו'
+i=2, index=12, paragraph-start=0, dir=ltr 'ם '
+i=3, index=15, paragraph-start=0, dir=ltr 'Γειά '
+i=4, index=24, paragraph-start=0, dir=ltr 'σας
+'
+i=5, index=31, paragraph-start=1, dir=ltr ''
+
+--- runs
+
+i=1, index=0, chars=6, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'Hello '
+[0,30]letter-spacing=8888
+i=2, index=6, no run, line end
+i=3, index=12, chars=4, level=1, gravity=south, flags=0, font=OMITTED, script=hebrew, language=he, 'שלום'
+[0,30]letter-spacing=8888
+i=4, index=14, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=hebrew, language=he, ' '
+[0,30]letter-spacing=8888
+i=5, index=15, no run, line end
+i=6, index=15, chars=5, level=0, gravity=south, flags=0, font=OMITTED, script=greek, language=el, 'Γειά '
+[0,30]letter-spacing=8888
+i=7, index=24, no run, line end
+i=8, index=24, chars=3, level=0, gravity=south, flags=0, font=OMITTED, script=greek, language=el, 'σας'
+[0,30]letter-spacing=8888
+i=9, index=30, no run, line end
+i=10, index=31, no run, line end
diff --git a/tests/layouts/valid-9.markup b/tests/layouts/valid-9.markup
new file mode 100644
index 00000000..ced8f8e5
--- /dev/null
+++ b/tests/layouts/valid-9.markup
@@ -0,0 +1,2 @@
+width=100
+<span letter_spacing="8888">Hello שלום Γειά σας</span>
diff --git a/tests/meson.build b/tests/meson.build
index 3e9d8075..baf5ad6b 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -18,6 +18,7 @@ test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
tests = [
+ [ 'test-bidi' ],
[ 'test-coverage' ],
[ 'testboundaries' ],
[ 'testboundaries_ucd' ],
@@ -47,7 +48,7 @@ if cairo_dep.found()
[ 'test-shape', [ 'test-shape.c', 'test-common.c' ], [ libpangocairo_dep ] ],
[ 'test-font', [ 'test-font.c' ], [ libpangocairo_dep ] ],
[ 'testattributes', [ 'testattributes.c', 'test-common.c' ], [ libpangocairo_dep ] ],
- [ 'testmisc', [ 'testmisc.c' ], [ libpangocairo_dep, glib_dep, harfbuzz_dep ] ],
+ [ 'testmisc', [ 'testmisc.c' ], [ libpangocairo_dep, libpangoft2_dep, glib_dep, harfbuzz_dep ] ],
[ 'cxx-test', [ 'cxx-test.cpp' ], [ libpangocairo_dep, gobject_dep, harfbuzz_dep ] ],
[ 'test-harfbuzz', [ 'test-harfbuzz.c' ], [ libpangocairo_dep, gobject_dep, harfbuzz_dep ] ],
[ 'test-break', [ 'test-break.c', 'test-common.c' ], [libpangocairo_dep, glib_dep, harfbuzz_dep ] ]
diff --git a/tests/test-bidi.c b/tests/test-bidi.c
new file mode 100644
index 00000000..48d2a81f
--- /dev/null
+++ b/tests/test-bidi.c
@@ -0,0 +1,166 @@
+/* Pango
+ * test-bidi.c: Test bidi apis
+ *
+ * Copyright (C) 2021 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <pango/pango.h>
+
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
+static void
+test_mirror_char (void)
+{
+ /* just some samples */
+ struct {
+ gunichar a;
+ gunichar b;
+ } tests[] = {
+ { '(', ')' },
+ { '<', '>' },
+ { '[', ']' },
+ { '{', '}' },
+ { 0x00ab, 0x00bb },
+ { 0x2045, 0x2046 },
+ { 0x226e, 0x226f },
+ };
+
+ for (int i = 0; i < G_N_ELEMENTS (tests); i++)
+ {
+ gboolean ret;
+ gunichar ch;
+
+ ret = pango_get_mirror_char (tests[i].a, &ch);
+ g_assert_true (ret);
+ g_assert_true (ch == tests[i].b);
+ ret = pango_get_mirror_char (tests[i].b, &ch);
+ g_assert_true (ret);
+ g_assert_true (ch == tests[i].a);
+ }
+}
+
+static void
+test_bidi_type_for_unichar (void)
+{
+ /* one representative from each class we support */
+ g_assert_true (pango_bidi_type_for_unichar ('a') == PANGO_BIDI_TYPE_L);
+ g_assert_true (pango_bidi_type_for_unichar (0x202a) == PANGO_BIDI_TYPE_LRE);
+ g_assert_true (pango_bidi_type_for_unichar (0x202d) == PANGO_BIDI_TYPE_LRO);
+ g_assert_true (pango_bidi_type_for_unichar (0x05d0) == PANGO_BIDI_TYPE_R);
+ g_assert_true (pango_bidi_type_for_unichar (0x0627) == PANGO_BIDI_TYPE_AL);
+ g_assert_true (pango_bidi_type_for_unichar (0x202b) == PANGO_BIDI_TYPE_RLE);
+ g_assert_true (pango_bidi_type_for_unichar (0x202e) == PANGO_BIDI_TYPE_RLO);
+ g_assert_true (pango_bidi_type_for_unichar (0x202c) == PANGO_BIDI_TYPE_PDF);
+ g_assert_true (pango_bidi_type_for_unichar ('0') == PANGO_BIDI_TYPE_EN);
+ g_assert_true (pango_bidi_type_for_unichar ('+') == PANGO_BIDI_TYPE_ES);
+ g_assert_true (pango_bidi_type_for_unichar ('#') == PANGO_BIDI_TYPE_ET);
+ g_assert_true (pango_bidi_type_for_unichar (0x601) == PANGO_BIDI_TYPE_AN);
+ g_assert_true (pango_bidi_type_for_unichar (',') == PANGO_BIDI_TYPE_CS);
+ g_assert_true (pango_bidi_type_for_unichar (0x0301) == PANGO_BIDI_TYPE_NSM);
+ g_assert_true (pango_bidi_type_for_unichar (0x200d) == PANGO_BIDI_TYPE_BN);
+ g_assert_true (pango_bidi_type_for_unichar (0x2029) == PANGO_BIDI_TYPE_B);
+ g_assert_true (pango_bidi_type_for_unichar (0x000b) == PANGO_BIDI_TYPE_S);
+ g_assert_true (pango_bidi_type_for_unichar (' ') == PANGO_BIDI_TYPE_WS);
+ g_assert_true (pango_bidi_type_for_unichar ('!') == PANGO_BIDI_TYPE_ON);
+ /* these are new */
+ g_assert_true (pango_bidi_type_for_unichar (0x2066) == PANGO_BIDI_TYPE_LRI);
+ g_assert_true (pango_bidi_type_for_unichar (0x2067) == PANGO_BIDI_TYPE_RLI);
+ g_assert_true (pango_bidi_type_for_unichar (0x2068) == PANGO_BIDI_TYPE_FSI);
+ g_assert_true (pango_bidi_type_for_unichar (0x2069) == PANGO_BIDI_TYPE_PDI);
+}
+
+static void
+test_unichar_direction (void)
+{
+ struct {
+ gunichar ch;
+ PangoDirection dir;
+ } tests[] = {
+ { 'a', PANGO_DIRECTION_LTR },
+ { '0', PANGO_DIRECTION_NEUTRAL },
+ { '.', PANGO_DIRECTION_NEUTRAL },
+ { '(', PANGO_DIRECTION_NEUTRAL },
+ { 0x05d0, PANGO_DIRECTION_RTL },
+ };
+
+ for (int i = 0; i < G_N_ELEMENTS (tests); i++)
+ {
+ g_assert_true (pango_unichar_direction (tests[i].ch) == tests[i].dir);
+ }
+}
+
+G_GNUC_END_IGNORE_DEPRECATIONS
+
+static void
+test_bidi_embedding_levels (void)
+{
+ /* Examples taken from https://www.w3.org/International/articles/inline-bidi-markup/uba-basics */
+ struct {
+ const char *text;
+ PangoDirection dir;
+ const char *levels;
+ PangoDirection out_dir;
+ } tests[] = {
+ { "bahrain مصر kuwait", PANGO_DIRECTION_LTR, "\0\0\0\0\0\0\0\0\1\1\1\0\0\0\0\0\0\0", PANGO_DIRECTION_LTR },
+ { "bahrain مصر kuwait", PANGO_DIRECTION_WEAK_LTR, "\0\0\0\0\0\0\0\0\1\1\1\0\0\0\0\0\0\0", PANGO_DIRECTION_LTR },
+ { "bahrain مصر kuwait", PANGO_DIRECTION_RTL, "\2\2\2\2\2\2\2\1\1\1\1\1\2\2\2\2\2\2", PANGO_DIRECTION_RTL },
+ { "bahrain مصر kuwait", PANGO_DIRECTION_WEAK_RTL, "\0\0\0\0\0\0\0\0\1\1\1\0\0\0\0\0\0\0", PANGO_DIRECTION_LTR },
+ { "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\0\0\0\0\0\0\0\0\0\0", PANGO_DIRECTION_LTR },
+ { "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\0\0\0\0\0\0\0\0\0\0\0", PANGO_DIRECTION_LTR },
+ { "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 },
+
+ };
+
+ for (int i = 0; i < G_N_ELEMENTS (tests); i++)
+ {
+ const char *text = tests[i].text;
+ PangoDirection dir = tests[i].dir;
+ guint8 *levels;
+ gsize len;
+
+ levels = pango_log2vis_get_embedding_levels (text, -1, &dir);
+
+ len = g_utf8_strlen (text, -1);
+
+ if (memcmp (levels, tests[i].levels, sizeof (guint8) * len) != 0)
+ {
+ for (int j = 0; j < len; j++)
+ g_print ("\\%d", levels[j]);
+ g_print ("\n");
+ }
+ g_assert_true (memcmp (levels, tests[i].levels, sizeof (guint8) * len) == 0);
+ g_assert_true (dir == tests[i].out_dir);
+
+ g_free (levels);
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/bidi/mirror-char", test_mirror_char);
+ g_test_add_func ("/bidi/type-for-unichar", test_bidi_type_for_unichar);
+ g_test_add_func ("/bidi/unichar-direction", test_unichar_direction);
+ g_test_add_func ("/bidi/embedding-levels", test_bidi_embedding_levels);
+
+ return g_test_run ();
+}
diff --git a/tests/test-break.c b/tests/test-break.c
index 51074d80..b06fb4c0 100644
--- a/tests/test-break.c
+++ b/tests/test-break.c
@@ -41,7 +41,9 @@ test_file (const gchar *filename, GString *string)
gsize length;
GError *error = NULL;
PangoLogAttr *attrs;
+ const PangoLogAttr *attrs2;
int len;
+ int len2;
char *p;
int i;
GString *s1, *s2, *s3, *s4;
@@ -50,6 +52,7 @@ test_file (const gchar *filename, GString *string)
char *text;
PangoAttrList *attributes;
PangoLayout *layout;
+ PangoLayout *layout2;
g_file_get_contents (filename, &contents, &length, &error);
g_assert_no_error (error);
@@ -73,7 +76,10 @@ test_file (const gchar *filename, GString *string)
if (pango_layout_get_unknown_glyphs_count (layout) > 0)
{
char *msg = g_strdup_printf ("Missing glyphs - skipping %s. Maybe fonts are missing?", filename);
- g_test_skip (msg);
+ if (g_test_initialized())
+ g_test_skip (msg);
+ else
+ g_warning ("%s", msg);
g_free (msg);
g_free (contents);
g_object_unref (layout);
@@ -83,6 +89,18 @@ test_file (const gchar *filename, GString *string)
}
pango_layout_get_log_attrs (layout, &attrs, &len);
+ attrs2 = pango_layout_get_log_attrs_readonly (layout, &len2);
+
+ g_assert_cmpint (len, ==, len2);
+ g_assert_true (memcmp (attrs, attrs2, sizeof (PangoLogAttr) * len) == 0);
+
+ layout2 = pango_layout_copy (layout);
+ attrs2 = pango_layout_get_log_attrs_readonly (layout2, &len2);
+
+ g_assert_cmpint (len, ==, len2);
+ g_assert_true (memcmp (attrs, attrs2, sizeof (PangoLogAttr) * len) == 0);
+
+ g_object_unref (layout2);
s1 = g_string_new ("Breaks: ");
s2 = g_string_new ("Whitespace: ");
@@ -313,8 +331,6 @@ main (int argc, char *argv[])
const gchar *name;
gchar *path;
- g_test_init (&argc, &argv, NULL);
-
setlocale (LC_ALL, "");
context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
@@ -334,19 +350,24 @@ main (int argc, char *argv[])
" x - expandable space b - sentence boundary\n"
" w - whitespace s - sentence start\n"
" e - sentence end\n");
+ return 0;
}
- else
+ else if (argv[1][0] != '-')
{
GString *string;
string = g_string_sized_new (0);
test_file (argv[1], string);
g_print ("%s", string->str);
- }
- return 0;
+ g_string_free (string, TRUE);
+
+ return 0;
+ }
}
+ g_test_init (&argc, &argv, NULL);
+
path = g_test_build_filename (G_TEST_DIST, "breaks", NULL);
dir = g_dir_open (path, 0, &error);
g_free (path);
diff --git a/tests/test-layout.c b/tests/test-layout.c
index 9c5d13a0..0d71ab54 100644
--- a/tests/test-layout.c
+++ b/tests/test-layout.c
@@ -178,26 +178,100 @@ dump_runs (PangoLayout *layout, GString *string)
}
static void
-parse_params (const gchar *str,
- gint *width,
- gint *ellipsize_at,
- PangoEllipsizeMode *ellipsize,
- PangoWrapMode *wrap)
+dump_directions (PangoLayout *layout, GString *string)
{
- gchar **strings;
- gchar **str2;
- gint i;
+ const char *text, *p;
+
+ text = pango_layout_get_text (layout);
+ for (p = text; *p; p = g_utf8_next_char (p))
+ {
+ g_string_append_printf (string, "%d ", pango_layout_get_direction (layout, p - text));
+ }
+ g_string_append (string, "\n");
+}
+
+static void
+dump_cursor_positions (PangoLayout *layout, GString *string)
+{
+ int index, trailing;
+
+ index = 0;
+ trailing = 0;
+
+ while (index < G_MAXINT)
+ {
+ g_string_append_printf (string, "%d(%d) ", index, trailing);
+ pango_layout_move_cursor_visually (layout, TRUE, index, trailing, 1, &index, &trailing);
+ }
+
+ g_string_append (string, "\n");
+}
+
+typedef struct {
+ int width;
+ int height;
+ int indent;
+ int spacing;
+ float line_spacing;
+ PangoEllipsizeMode ellipsize;
+ PangoWrapMode wrap;
+ PangoAlignment alignment;
+ gboolean justify;
+ gboolean auto_dir;
+ gboolean single_paragraph;
+ PangoTabArray *tabs;
+} LayoutParams;
+
+static void
+init_params (LayoutParams *params)
+{
+ params->width = -1;
+ params->height = -1;
+ params->indent = 0;
+ params->spacing = 0;
+ params->line_spacing = 0.0;
+ params->ellipsize = PANGO_ELLIPSIZE_NONE;
+ params->wrap = PANGO_WRAP_WORD;
+ params->alignment = PANGO_ALIGN_LEFT;
+ params->justify = FALSE;
+ params->auto_dir = TRUE;
+ params->single_paragraph = FALSE;
+ params->tabs = NULL;
+}
+
+static void
+parse_params (const char *str,
+ LayoutParams *params)
+{
+ char **strings;
+ int i;
GEnumClass *eclass;
GEnumValue *ev;
strings = g_strsplit (str, ",", -1);
for (i = 0; strings[i]; i++)
{
- str2 = g_strsplit (strings[i], "=", -1);
+ char **str2 = g_strsplit (strings[i], "=", -1);
if (strcmp (str2[0], "width") == 0)
- *width = (gint) g_ascii_strtoll (str2[1], NULL, 10);
- else if (strcmp (str2[0], "ellipsize-at") == 0)
- *ellipsize_at = (gint) g_ascii_strtoll (str2[1], NULL, 10);
+ {
+ params->width = (int) g_ascii_strtoll (str2[1], NULL, 10);
+ }
+ else if (strcmp (str2[0], "height") == 0)
+ {
+ params->height = (int) g_ascii_strtoll (str2[1], NULL, 10);
+ }
+ else if (strcmp (str2[0], "indent") == 0)
+ {
+ params->indent = (int) g_ascii_strtoll (str2[1], NULL, 10);
+ }
+ else if (strcmp (str2[0], "spacing") == 0)
+ {
+ params->spacing = (int) g_ascii_strtoll (str2[1], NULL, 10);
+ }
+ else if (strcmp (str2[0], "line_spacing") == 0)
+ {
+ params->line_spacing = (float) g_ascii_strtod (str2[1], NULL);
+ }
else if (strcmp (str2[0], "ellipsize") == 0)
{
eclass = g_type_class_ref (PANGO_TYPE_ELLIPSIZE_MODE);
@@ -205,7 +279,7 @@ parse_params (const gchar *str,
if (!ev)
ev = g_enum_get_value_by_nick (eclass, str2[1]);
if (ev)
- *ellipsize = ev->value;
+ params->ellipsize = ev->value;
g_type_class_unref (eclass);
}
else if (strcmp (str2[0], "wrap") == 0)
@@ -215,28 +289,89 @@ parse_params (const gchar *str,
if (!ev)
ev = g_enum_get_value_by_nick (eclass, str2[1]);
if (ev)
- *wrap = ev->value;
+ params->wrap = ev->value;
g_type_class_unref (eclass);
}
+ else if (strcmp (str2[0], "alignment") == 0)
+ {
+ eclass = g_type_class_ref (PANGO_TYPE_ALIGNMENT);
+ ev = g_enum_get_value_by_name (eclass, str2[1]);
+ if (!ev)
+ ev = g_enum_get_value_by_nick (eclass, str2[1]);
+ if (ev)
+ params->alignment = ev->value;
+ g_type_class_unref (eclass);
+ }
+ else if (strcmp (str2[0], "justify") == 0)
+ {
+ params->justify = g_str_equal (str2[1], "true");
+ }
+ else if (strcmp (str2[0], "auto_dir") == 0)
+ {
+ params->auto_dir = g_str_equal (str2[1], "true");
+ }
+ else if (strcmp (str2[0], "single_paragraph") == 0)
+ {
+ params->single_paragraph = g_str_equal (str2[1], "true");
+ }
+ else if (strcmp (str2[0], "tabs") == 0)
+ {
+ char **str3 = g_strsplit (strings[i], " ", -1);
+ params->tabs = pango_tab_array_new (g_strv_length (str3), TRUE);
+ for (int j = 0; str3[j]; j++)
+ {
+ int tab = (int) g_ascii_strtoll (str3[j], NULL, 10);
+ pango_tab_array_set_tab (params->tabs, j, PANGO_TAB_LEFT, tab);
+ }
+ g_strfreev (str3);
+ }
+
g_strfreev (str2);
}
g_strfreev (strings);
}
+#define assert_layout_changed(layout) \
+ g_assert_cmpuint (pango_layout_get_serial (layout), !=, serial); \
+ serial = pango_layout_get_serial (layout);
+
+#define assert_rectangle_equal(r1, r2) \
+ g_assert_true((r1)->x == (r2)->x && \
+ (r1)->y == (r2)->y && \
+ (r1)->width == (r2)->width && \
+ (r1)->height == (r2)->height)
+
+#define assert_rectangle_contained(r1, r2) \
+ g_assert_true ((r1)->x >= (r2)->x && \
+ (r1)->y >= (r2)->y && \
+ (r1)->x + (r1)->width <= (r2)->x + (r2)->width && \
+ (r1)->y + (r1)->height <= (r2)->y + (r2)->height)
+
+#define assert_rectangle_size_contained(r1, r2) \
+ g_assert_true ((r1)->width <= (r2)->width && \
+ (r1)->height <= (r2)->height)
+
static void
-test_file (const gchar *filename, GString *string)
+test_file (const char *filename, GString *string)
{
- gchar *contents;
- gchar *markup;
+ char *contents;
+ char *markup;
gsize length;
GError *error = NULL;
PangoLayout *layout;
- gchar *p;
- gint width = 0;
- gint ellipsize_at = 0;
- PangoEllipsizeMode ellipsize = PANGO_ELLIPSIZE_NONE;
- PangoWrapMode wrap = PANGO_WRAP_WORD;
+ char *p;
+ LayoutParams params;
PangoFontDescription *desc;
+ PangoFontDescription *desc2;
+ guint serial;
+ PangoRectangle ink_rect, logical_rect;
+ PangoRectangle ink_rect1, logical_rect1;
+ int width, height;
+ int width1, height1;
+ PangoTabArray *tabs;
+ GSList *lines, *l;
+ PangoLayoutIter *iter;
+ PangoLayoutIter *iter2;
if (context == NULL)
context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
@@ -250,36 +385,266 @@ test_file (const gchar *filename, GString *string)
*p = '\0';
length = strlen (markup);
- parse_params (contents, &width, &ellipsize_at, &ellipsize, &wrap);
+ init_params (&params);
layout = pango_layout_new (context);
+
+ serial = pango_layout_get_serial (layout);
+ g_assert_cmpuint (serial, !=, 0);
+
+ /* Check initial values */
+ g_assert_cmpint (pango_layout_get_width (layout), ==, params.width);
+ g_assert_cmpint (pango_layout_get_height (layout), ==, params.height);
+ g_assert_cmpint (pango_layout_get_indent (layout), ==, params.indent);
+ g_assert_cmpint (pango_layout_get_spacing (layout), ==, params.spacing);
+ g_assert_cmpfloat (pango_layout_get_line_spacing (layout), ==, params.line_spacing);
+ g_assert_cmpint (pango_layout_get_ellipsize (layout), ==, params.ellipsize);
+ g_assert_cmpint (pango_layout_get_wrap (layout), ==, params.wrap);
+ g_assert_cmpint (pango_layout_get_alignment (layout), ==, params.alignment);
+ g_assert_cmpint (pango_layout_get_justify (layout), ==, params.justify);
+ g_assert_cmpint (pango_layout_get_auto_dir (layout), ==, params.auto_dir);
+ g_assert_cmpint (pango_layout_get_single_paragraph_mode (layout), ==, params.single_paragraph);
+
+ g_assert_cmpstr (pango_layout_get_text (layout), ==, "");
+ g_assert_null (pango_layout_get_attributes (layout));
+ g_assert_null (pango_layout_get_tabs (layout));
+ g_assert_null (pango_layout_get_font_description (layout));
+ g_assert_cmpint (pango_layout_is_ellipsized (layout), ==, FALSE);
+ g_assert_cmpint (pango_layout_is_wrapped (layout), ==, FALSE);
+
desc = pango_font_description_from_string ("Cantarell 11");
pango_layout_set_font_description (layout, desc);
+ desc2 = pango_layout_get_font_description (layout);
+ g_assert_true (pango_font_description_equal (desc, desc2));
pango_font_description_free (desc);
+ assert_layout_changed (layout);
pango_layout_set_markup (layout, markup, length);
- g_free (contents);
+ assert_layout_changed (layout);
+
+ parse_params (contents, &params);
+
+ pango_layout_set_width (layout, params.width > 0 ? params.width * PANGO_SCALE : -1);
+ pango_layout_set_height (layout, params.height > 0 ? params.height * PANGO_SCALE : params.height);
+ pango_layout_set_indent (layout, params.indent * PANGO_SCALE);
+ pango_layout_set_spacing (layout, params.spacing * PANGO_SCALE);
+ pango_layout_set_line_spacing (layout, params.line_spacing);
+ pango_layout_set_ellipsize (layout, params.ellipsize);
+ pango_layout_set_wrap (layout, params.wrap);
+ pango_layout_set_alignment (layout, params.alignment);
+ pango_layout_set_justify (layout, params.justify);
+ pango_layout_set_auto_dir (layout, params.auto_dir);
+ pango_layout_set_single_paragraph_mode (layout, params.single_paragraph);
+ pango_layout_set_tabs (layout, params.tabs);
+
+ /* Check the values we set */
+ g_assert_cmpint (pango_layout_get_width (layout), ==, params.width > 0 ? params.width * PANGO_SCALE : -1);
+ g_assert_cmpint (pango_layout_get_height (layout), ==, params.height > 0 ? params.height * PANGO_SCALE : params.height);
+ g_assert_cmpint (pango_layout_get_indent (layout), ==, params.indent * PANGO_SCALE);
+ g_assert_cmpint (pango_layout_get_spacing (layout), ==, params.spacing * PANGO_SCALE);
+ g_assert_cmpfloat (pango_layout_get_line_spacing (layout), ==, params.line_spacing);
+ g_assert_cmpint (pango_layout_get_ellipsize (layout), ==, params.ellipsize);
+ g_assert_cmpint (pango_layout_get_wrap (layout), ==, params.wrap);
+ g_assert_cmpint (pango_layout_get_alignment (layout), ==, params.alignment);
+ g_assert_cmpint (pango_layout_get_justify (layout), ==, params.justify);
+ g_assert_cmpint (pango_layout_get_auto_dir (layout), ==, params.auto_dir);
+ g_assert_cmpint (pango_layout_get_single_paragraph_mode (layout), ==, params.single_paragraph);
+
+ tabs = pango_layout_get_tabs (layout);
+ g_assert_true ((tabs == NULL) == (params.tabs == NULL));
+ if (tabs)
+ pango_tab_array_free (tabs);
+
+ g_assert_cmpint (pango_layout_get_character_count (layout), ==, g_utf8_strlen (pango_layout_get_text (layout), -1));
+
+ /* Some checks on extents - we have to be careful here, since we
+ * don't want to depend on font metrics.
+ */
+ pango_layout_get_extents (layout, &ink_rect, &logical_rect);
+ pango_extents_to_pixels (&ink_rect, NULL);
+ pango_extents_to_pixels (&logical_rect, NULL);
+ pango_layout_get_pixel_extents (layout, &ink_rect1, &logical_rect1);
+ pango_layout_get_size (layout, &width, &height);
+ pango_layout_get_pixel_size (layout, &width1, &height1);
+
+ assert_rectangle_equal (&ink_rect, &ink_rect1);
+ assert_rectangle_equal (&logical_rect, &logical_rect1);
+ g_assert_cmpint (PANGO_PIXELS (width), ==, logical_rect.width);
+ g_assert_cmpint (PANGO_PIXELS (height), ==, logical_rect.height);
+ g_assert_cmpint (width1, ==, logical_rect1.width);
+ g_assert_cmpint (height1, ==, logical_rect1.height);
+
+ lines = pango_layout_get_lines (layout);
+ for (l = lines; l; l = l->next)
+ {
+ PangoLayoutLine *line = l->data;
+ int line_height, line_width;
+ int line_x;
+ PangoRectangle line_ink, line_logical;
+ PangoRectangle line_ink1, line_logical1;
+ gboolean done;
+
+ pango_layout_line_get_height (line, &line_height);
+ g_assert_cmpint (line_height, <=, height);
+
+ pango_layout_line_get_extents (line, &line_ink, &line_logical);
+ line_x = line_logical.x;
+ line_width = line_logical.width;
+ pango_extents_to_pixels (&line_ink, NULL);
+ pango_extents_to_pixels (&line_logical, NULL);
+ pango_layout_line_get_pixel_extents (line, &line_ink1, &line_logical1);
+
+ /* Not in layout coordinates, so just compare sizes */
+ assert_rectangle_size_contained (&line_ink, &ink_rect);
+ assert_rectangle_size_contained (&line_logical, &logical_rect);
+ assert_rectangle_size_contained (&line_ink1, &ink_rect1);
+ assert_rectangle_size_contained (&line_logical1, &logical_rect1);
+
+ if (pango_layout_is_ellipsized (layout))
+ continue;
+
+ /* FIXME: should have a way to position iters */
+ iter = pango_layout_get_iter (layout);
+ while (pango_layout_iter_get_line_readonly (iter) != line)
+ pango_layout_iter_next_line (iter);
+
+ done = FALSE;
+ while (!done && pango_layout_iter_get_line_readonly (iter) == line)
+ {
+ int prev_index, index, next_index;
+ int x, index2, trailing;
+ int *ranges;
+ int n_ranges;
+ gboolean found_range;
+ PangoLayoutRun *run;
+
+ index = pango_layout_iter_get_index (iter);
+ run = pango_layout_iter_get_run_readonly (iter);
+
+ if (!pango_layout_iter_next_cluster (iter))
+ done = TRUE;
+
+ pango_layout_line_index_to_x (line, index, 0, &x);
+ pango_layout_line_x_to_index (line, x, &index2, &trailing);
+
+#if 0
+ /* FIXME: why doesn't this hold true? */
+ g_assert_cmpint (index2, ==, index);
+ g_assert_cmpint (trailing, ==, 0);
+#endif
+
+ g_assert_cmpint (0, <=, x);
+ g_assert_cmpint (x, <=, line_width);
- if (width != 0)
- pango_layout_set_width (layout, width * PANGO_SCALE);
- pango_layout_set_ellipsize (layout, ellipsize);
- pango_layout_set_wrap (layout, wrap);
+ g_assert_cmpint (line->start_index, <=, index2);
+ g_assert_cmpint (index2, <=, line->start_index + line->length);
+
+ if (!run)
+ break;
+
+ prev_index = run->item->offset;
+ next_index = run->item->offset + run->item->length;
+
+ pango_layout_line_get_x_ranges (line, prev_index, next_index, &ranges, &n_ranges);
+
+ /* The index is within the run, so the x should be in one of the ranges */
+ if (n_ranges > 0)
+ {
+ found_range = FALSE;
+ for (int k = 0; k < n_ranges; k++)
+ {
+ if (x + line_x >= ranges[2*k] && x + line_x <= ranges[2*k + 1])
+ {
+ found_range = TRUE;
+ break;
+ }
+ }
+ }
+
+ g_assert_true (found_range);
+ g_free (ranges);
+ }
+
+ pango_layout_iter_free (iter);
+ }
+
+ iter = pango_layout_get_iter (layout);
+ g_assert_true (pango_layout_iter_get_layout (iter) == layout);
+ g_assert_cmpint (pango_layout_iter_get_index (iter), ==, 0);
+ pango_layout_iter_get_layout_extents (iter, &ink_rect, &logical_rect);
+
+ iter2 = pango_layout_iter_copy (iter);
+
+ do
+ {
+ PangoRectangle line_ink, line_logical;
+ int baseline;
+ PangoLayoutLine *line;
+ line = pango_layout_iter_get_line (iter);
+
+ pango_layout_iter_get_line_extents (iter, &line_ink, &line_logical);
+ baseline = pango_layout_iter_get_baseline (iter);
+
+ assert_rectangle_contained (&line_ink, &ink_rect);
+ assert_rectangle_contained (&line_logical, &logical_rect);
+
+ g_assert_cmpint (line_logical.y, <=, baseline);
+ g_assert_cmpint (baseline, <=, line_logical.y + line_logical.height);
+
+ if (pango_layout_iter_get_index (iter) == pango_layout_iter_get_index (iter2))
+ {
+ g_assert_cmpint (baseline, ==, pango_layout_get_baseline (layout));
+ g_assert_true (line->is_paragraph_start);
+ }
+
+ if (pango_layout_iter_at_last_line (iter))
+ {
+ g_assert_cmpint (line->start_index + line->length, <=, strlen (pango_layout_get_text (layout)));
+ }
+ }
+ while (pango_layout_iter_next_line (iter));
+
+ pango_layout_iter_free (iter);
+ pango_layout_iter_free (iter2);
+
+ /* generate the dumps */
g_string_append (string, pango_layout_get_text (layout));
+
g_string_append (string, "\n--- parameters\n\n");
+
g_string_append_printf (string, "wrapped: %d\n", pango_layout_is_wrapped (layout));
g_string_append_printf (string, "ellipsized: %d\n", pango_layout_is_ellipsized (layout));
g_string_append_printf (string, "lines: %d\n", pango_layout_get_line_count (layout));
- if (width != 0)
+ if (params.width > 0)
g_string_append_printf (string, "width: %d\n", pango_layout_get_width (layout));
+
+ if (params.height > 0)
+ g_string_append_printf (string, "height: %d\n", pango_layout_get_height (layout));
+
+ if (params.indent != 0)
+ g_string_append_printf (string, "indent: %d\n", pango_layout_get_indent (layout));
+
g_string_append (string, "\n--- attributes\n\n");
print_attr_list (pango_layout_get_attributes (layout), string);
+
+ g_string_append (string, "\n--- directions\n\n");
+ dump_directions (layout, string);
+
+ g_string_append (string, "\n--- cursor positions\n\n");
+ dump_cursor_positions (layout, string);
+
g_string_append (string, "\n--- lines\n\n");
dump_lines (layout, string);
+
g_string_append (string, "\n--- runs\n\n");
dump_runs (layout, string);
g_object_unref (layout);
+ g_free (contents);
+
+ if (params.tabs)
+ pango_tab_array_free (params.tabs);
}
static gchar *
@@ -369,6 +734,7 @@ main (int argc, char *argv[])
string = g_string_sized_new (0);
test_file (argv[1], string);
g_print ("%s", string->str);
+ g_string_free (string, TRUE);
return 0;
}
diff --git a/tests/testmisc.c b/tests/testmisc.c
index a095cbf1..c0f8c426 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -22,6 +22,7 @@
#include "config.h"
#include <glib.h>
#include <pango/pangocairo.h>
+#include <pango/pango-ot.h>
/* test that we don't crash in shape_tab when the layout
* is such that we don't have effective attributes
@@ -236,67 +237,58 @@ test_gravity_for_script (void)
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static void
-test_bidi_type_for_unichar (void)
+test_language_to_tag (void)
{
- /* one representative from each class we support */
- g_assert_true (pango_bidi_type_for_unichar ('a') == PANGO_BIDI_TYPE_L);
- g_assert_true (pango_bidi_type_for_unichar (0x202a) == PANGO_BIDI_TYPE_LRE);
- g_assert_true (pango_bidi_type_for_unichar (0x202d) == PANGO_BIDI_TYPE_LRO);
- g_assert_true (pango_bidi_type_for_unichar (0x05d0) == PANGO_BIDI_TYPE_R);
- g_assert_true (pango_bidi_type_for_unichar (0x0627) == PANGO_BIDI_TYPE_AL);
- g_assert_true (pango_bidi_type_for_unichar (0x202b) == PANGO_BIDI_TYPE_RLE);
- g_assert_true (pango_bidi_type_for_unichar (0x202e) == PANGO_BIDI_TYPE_RLO);
- g_assert_true (pango_bidi_type_for_unichar (0x202c) == PANGO_BIDI_TYPE_PDF);
- g_assert_true (pango_bidi_type_for_unichar ('0') == PANGO_BIDI_TYPE_EN);
- g_assert_true (pango_bidi_type_for_unichar ('+') == PANGO_BIDI_TYPE_ES);
- g_assert_true (pango_bidi_type_for_unichar ('#') == PANGO_BIDI_TYPE_ET);
- g_assert_true (pango_bidi_type_for_unichar (0x601) == PANGO_BIDI_TYPE_AN);
- g_assert_true (pango_bidi_type_for_unichar (',') == PANGO_BIDI_TYPE_CS);
- g_assert_true (pango_bidi_type_for_unichar (0x0301) == PANGO_BIDI_TYPE_NSM);
- g_assert_true (pango_bidi_type_for_unichar (0x200d) == PANGO_BIDI_TYPE_BN);
- g_assert_true (pango_bidi_type_for_unichar (0x2029) == PANGO_BIDI_TYPE_B);
- g_assert_true (pango_bidi_type_for_unichar (0x000b) == PANGO_BIDI_TYPE_S);
- g_assert_true (pango_bidi_type_for_unichar (' ') == PANGO_BIDI_TYPE_WS);
- g_assert_true (pango_bidi_type_for_unichar ('!') == PANGO_BIDI_TYPE_ON);
- /* these are new */
- g_assert_true (pango_bidi_type_for_unichar (0x2066) == PANGO_BIDI_TYPE_LRI);
- g_assert_true (pango_bidi_type_for_unichar (0x2067) == PANGO_BIDI_TYPE_RLI);
- g_assert_true (pango_bidi_type_for_unichar (0x2068) == PANGO_BIDI_TYPE_FSI);
- g_assert_true (pango_bidi_type_for_unichar (0x2069) == PANGO_BIDI_TYPE_PDI);
+ PangoLanguage *lang;
+ PangoOTTag tag;
+ PangoLanguage *lang2;
+
+ lang = pango_language_from_string ("de");
+
+ tag = pango_ot_tag_from_language (lang);
+
+ lang2 = pango_ot_tag_to_language (tag);
+
+ g_assert_true (lang2 == lang);
}
+G_GNUC_END_IGNORE_DEPRECATIONS
+
static void
-test_bidi_mirror_char (void)
+test_fallback_shape (void)
{
- /* just some samples */
- struct {
- gunichar a;
- gunichar b;
- } tests[] = {
- { '(', ')' },
- { '<', '>' },
- { '[', ']' },
- { '{', '}' },
- { 0x00ab, 0x00bb },
- { 0x2045, 0x2046 },
- { 0x226e, 0x226f },
- };
+ PangoContext *context;
+ const char *text;
+ GList *items, *l;
- for (int i = 0; i < G_N_ELEMENTS (tests); i++)
+ context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
+
+ text = "Some text to sha​pe ﺄﻧﺍ ﻕﺍﺩﺭ ﻊﻟﻯ ﺄﻜﻟ ﺎﻟﺰﺟﺎﺟ ﻭ ﻩﺫﺍ ﻻ ﻱﺆﻠﻤﻨﻳ";
+ items = pango_itemize (context, text, 0, strlen (text), NULL, NULL);
+ for (l = items; l; l = l->next)
{
- gboolean ret;
- gunichar ch;
-
- ret = pango_get_mirror_char (tests[i].a, &ch);
- g_assert_true (ret);
- g_assert_true (ch == tests[i].b);
- ret = pango_get_mirror_char (tests[i].b, &ch);
- g_assert_true (ret);
- g_assert_true (ch == tests[i].a);
+ PangoItem *item = l->data;
+ PangoGlyphString *glyphs;
+
+ /* We want to test fallback shaping, which happens when we don't have a font */
+ g_clear_object (&item->analysis.font);
+
+ glyphs = pango_glyph_string_new ();
+ pango_shape_full (text + item->offset, item->length, NULL, 0, &item->analysis, glyphs);
+
+ for (int i = 0; i < glyphs->num_glyphs; i++)
+ {
+ PangoGlyph glyph = glyphs->glyphs[i].glyph;
+ g_assert_true (glyph == PANGO_GLYPH_EMPTY || (glyph & PANGO_GLYPH_UNKNOWN_FLAG));
+ }
+
+ pango_glyph_string_free (glyphs);
}
-}
-G_GNUC_END_IGNORE_DEPRECATIONS
+ g_list_free_full (items, (GDestroyNotify)pango_item_free);
+
+ g_object_unref (context);
+}
int
main (int argc, char *argv[])
@@ -315,8 +307,8 @@ main (int argc, char *argv[])
g_test_add_func ("/gravity/to-rotation", test_gravity_to_rotation);
g_test_add_func ("/gravity/from-matrix", test_gravity_from_matrix);
g_test_add_func ("/gravity/for-script", test_gravity_for_script);
- g_test_add_func ("/bidi/type-for-unichar", test_bidi_type_for_unichar);
- g_test_add_func ("/bidi/mirror-char", test_bidi_mirror_char);
+ g_test_add_func ("/layout/fallback-shape", test_fallback_shape);
+ g_test_add_func ("/language/to-tag", test_language_to_tag);
return g_test_run ();
}
diff --git a/tests/testscript.c b/tests/testscript.c
index 33e8ad2e..7260dbbe 100644
--- a/tests/testscript.c
+++ b/tests/testscript.c
@@ -143,6 +143,7 @@ test_script_iter (void)
};
PangoScriptIter *iter;
+ PangoScriptIter *iter2;
GString *all = g_string_new (FALSE);
char *pos;
const char *start;
@@ -158,6 +159,8 @@ test_script_iter (void)
iter = pango_script_iter_new (all->str, -1);
+ iter2 = g_boxed_copy (pango_script_iter_get_type (), iter);
+
g_test_message ("Total length: %" G_GSIZE_FORMAT "\n", all->len);
pos = all->str;
@@ -183,6 +186,13 @@ test_script_iter (void)
pos = next_pos;
}
+ /* Check that copying the iter worked */
+ pango_script_iter_get_range (iter2, &start, &end, &script);
+ g_assert_true (start == all->str);
+ g_assert_true (end == all->str + strlen (test_data[0].run_text));
+ g_assert_true (script == test_data[0].run_code);
+ pango_script_iter_free (iter2);
+
pango_script_iter_free (iter);
/*
diff --git a/utils/pango-segmentation.c b/utils/pango-segmentation.c
index 6931d180..0d5b5a49 100644
--- a/utils/pango-segmentation.c
+++ b/utils/pango-segmentation.c
@@ -83,17 +83,6 @@ show_segmentation (const char *input,
pango_layout_set_text (layout, text, length);
pango_layout_set_attributes (layout, attributes);
- if (pango_layout_get_unknown_glyphs_count (layout) > 0)
- {
- char *msg = g_strdup_printf ("Missing glyphs - skipping. Maybe fonts are missing?");
- g_test_skip (msg);
- g_free (msg);
- g_object_unref (layout);
- pango_attr_list_unref (attributes);
- g_free (text);
- return FALSE;
- }
-
pango_layout_get_log_attrs (layout, &attrs, &len);
for (i = 0, p = text; i < len; i++, p = g_utf8_next_char (p))