summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-11-11 03:59:30 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-11-11 03:59:30 +0000
commit907b6e21fcb846995cc5b03d2cb1b68fbbc2a2b5 (patch)
tree3a68163dde9e6008456756fd489185d02e7142f4
parentffdc738e9057b9202dc889dd87829dcd90f4d87a (diff)
parent9a275af8c4cc950a8c277005c99b2282fdf00f79 (diff)
downloadpango-907b6e21fcb846995cc5b03d2cb1b68fbbc2a2b5.tar.gz
Merge branch 'fix-hyphen-width' into 'main'
layout: Fix a poblem with hyphen width See merge request GNOME/pango!500
-rw-r--r--pango/pango-layout.c13
-rw-r--r--tests/layouts/valid-4.expected14
-rw-r--r--tests/layouts/valid-4.markup2
-rw-r--r--tests/testmisc.c26
4 files changed, 39 insertions, 16 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 9e8ce248..1a460d4c 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3792,7 +3792,8 @@ find_break_extra_width (PangoLayout *layout,
#if 0
# define DEBUG debug
-void
+static int pango_layout_line_get_width (PangoLayoutLine *line);
+static void
debug (const char *where, PangoLayoutLine *line, ParaBreakState *state)
{
int line_width = pango_layout_line_get_width (line);
@@ -3919,10 +3920,10 @@ process_item (PangoLayout *layout,
extra_width = 0;
for (num_chars = 0; num_chars < item->num_chars; num_chars++)
{
+ extra_width = find_break_extra_width (layout, state, num_chars);
+
if (width + extra_width > state->remaining_width && break_num_chars < item->num_chars)
- {
- break;
- }
+ break;
/* If there are no previous runs we have to take care to grab at least one char. */
if (can_break_at (layout, state->start_offset + num_chars, retrying_with_char_breaks) &&
@@ -3931,11 +3932,7 @@ process_item (PangoLayout *layout,
break_num_chars = num_chars;
break_width = width;
break_extra_width = extra_width;
-
- extra_width = find_break_extra_width (layout, state, num_chars);
}
- else
- extra_width = 0;
width += state->log_widths[state->log_widths_offset + num_chars];
}
diff --git a/tests/layouts/valid-4.expected b/tests/layouts/valid-4.expected
index f1c6934b..4e69d61d 100644
--- a/tests/layouts/valid-4.expected
+++ b/tests/layouts/valid-4.expected
@@ -5,7 +5,7 @@ This paragraph should ac­tual­ly have multiple lines, unlike all the other wan
wrapped: 1
ellipsized: 0
lines: 6
-width: 192512
+width: 198656
--- attributes
@@ -17,15 +17,15 @@ range 0 2147483647
--- 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) 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) 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)
+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) 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) 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) 124(0) 125(0) 126(0) 127(0) 128(0) 128(1) 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­'
i=2, index=32, paragraph-start=0, dir=ltr 'ly have multiple lines, unlike '
i=3, index=63, paragraph-start=0, dir=ltr 'all the other wannabe äöü pa­'
-i=4, index=96, paragraph-start=0, dir=ltr 'ra­graph tests in this ugh '
-i=5, index=124, paragraph-start=0, dir=ltr 'test-case. Grow some lines!
+i=4, index=96, paragraph-start=0, dir=ltr 'ra­graph tests in this ugh test-'
+i=5, index=129, paragraph-start=0, dir=ltr 'case. Grow some lines!
'
i=6, index=152, paragraph-start=1, dir=ltr ''
@@ -37,8 +37,8 @@ i=3, index=32, chars=31, level=0, gravity=south, flags=0, font=OMITTED, script=l
i=4, index=63, no run, line end
i=5, index=63, chars=29, level=0, gravity=south, flags=4, font=OMITTED, script=latin, language=en-us, 'all the other wannabe äöü pa­'
i=6, index=96, no run, line end
-i=7, index=96, chars=27, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'ra­graph tests in this ugh '
-i=8, index=124, no run, line end
-i=9, index=124, chars=27, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'test-case. Grow some lines!'
+i=7, index=96, chars=32, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'ra­graph tests in this ugh test-'
+i=8, index=129, no run, line end
+i=9, index=129, chars=22, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'case. Grow some lines!'
i=10, index=151, no run, line end
i=11, index=152, no run, line end
diff --git a/tests/layouts/valid-4.markup b/tests/layouts/valid-4.markup
index 0b2bb51a..d8890baf 100644
--- a/tests/layouts/valid-4.markup
+++ b/tests/layouts/valid-4.markup
@@ -1,2 +1,2 @@
-width=188
+width=194
This paragraph should ac­tual­ly have multiple lines, unlike all the other wannabe äöü pa­ra­graph tests in this ugh test-case. Grow some lines!
diff --git a/tests/testmisc.c b/tests/testmisc.c
index 355e8ed0..a91dcbb3 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -754,6 +754,31 @@ test_transform_rectangle (void)
g_assert_cmpint (rect2.height, ==, rect.width);
}
+static void
+test_wrap_char (void)
+{
+ PangoContext *context;
+ PangoLayout *layout;
+ int w, h, w0, h0;
+
+ context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
+ layout = pango_layout_new (context);
+ pango_layout_set_text (layout, "Rows can have suffix widgets", -1);
+ pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
+
+ pango_layout_set_width (layout, 0);
+ pango_layout_get_size (layout, &w0, &h0);
+
+ pango_layout_set_width (layout, w0);
+ pango_layout_get_size (layout, &w, &h);
+
+ g_assert_cmpint (w0, ==, w);
+ g_assert_cmpint (h0, >=, h);
+
+ g_object_unref (layout);
+ g_object_unref (context);
+}
+
int
main (int argc, char *argv[])
{
@@ -786,6 +811,7 @@ main (int argc, char *argv[])
g_test_add_func ("/layout/extents", test_extents);
g_test_add_func ("/layout/empty-line-height", test_empty_line_height);
g_test_add_func ("/layout/gravity-metrics", test_gravity_metrics);
+ g_test_add_func ("/layout/wrap-char", test_wrap_char);
g_test_add_func ("/matrix/transform-rectangle", test_transform_rectangle);
return g_test_run ();