[pango/matthiasc/for-main: 2/2] Fix a case of unintended hyphenation




commit f854a1681ccccc2dc843a85ba5cef7dae9e5d8b2
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Nov 21 11:02:07 2021 -0500

    Fix a case of unintended hyphenation
    
    When we take a complete item because there are
    no breakpoints, we were inserting a hyphen at
    the end even though there may not be a breakpoint
    there, and ending up with a hyphen in the middle
    of an (overlong) line: Brat-wurst.
    
    Test included.
    
    This but was discovered with the help of
    http://gitlab.gnome.org/matthiasc/layout-editor

 pango/pango-layout.c             |  3 ++-
 tests/layouts/bratwurst.expected | 32 ++++++++++++++++++++++++++++++++
 tests/layouts/bratwurst.layout   | 21 +++++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 050138df..3cdb677a 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -4107,7 +4107,8 @@ retry_break:
 
       if (break_num_chars == item->num_chars)
         {
-          if (break_needs_hyphen (layout, state, break_num_chars))
+          if (can_break_at (layout, state->start_offset + break_num_chars, wrap) &&
+              break_needs_hyphen (layout, state, break_num_chars))
             item->analysis.flags |= PANGO_ANALYSIS_FLAG_NEED_HYPHEN;
 
           insert_run (line, state, item, NULL, TRUE);
diff --git a/tests/layouts/bratwurst.expected b/tests/layouts/bratwurst.expected
new file mode 100644
index 00000000..f81dbaeb
--- /dev/null
+++ b/tests/layouts/bratwurst.expected
@@ -0,0 +1,32 @@
+Bratwurst
+--- parameters
+
+wrapped: 0
+ellipsized: 0
+lines: 1
+width: 102400
+
+--- attributes
+
+range 0 4
+range 4 2147483647
+4 4294967295 style italic
+range 2147483647 2147483647
+
+--- directions
+
+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) 8(1) 
+
+--- lines
+
+i=1, index=0, paragraph-start=1, dir=ltr 'Bratwurst'
+
+--- runs
+
+i=1, index=0, chars=4, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'Brat'
+i=2, index=4, chars=5, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'wurst'
+i=3, index=9, no run, line end
diff --git a/tests/layouts/bratwurst.layout b/tests/layouts/bratwurst.layout
new file mode 100644
index 00000000..65104276
--- /dev/null
+++ b/tests/layouts/bratwurst.layout
@@ -0,0 +1,21 @@
+{
+  "text" : "Bratwurst",
+  "attributes" : [
+    {
+      "start" : 4,
+      "type" : "style",
+      "value" : "italic"
+    }
+  ],
+  "font" : "Sans Bold 32",
+  "tabs" : {
+    "positions-in-pixels" : true,
+    "positions" : [
+      0,
+      50,
+      100
+    ]
+  },
+  "width" : 102400,
+  "line-spacing" : 1.2999999523162842
+}
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]