groff-commit
[Top][All Lists]
Advanced

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

[groff] 01/02: Fix some problems related to hyphenation.


From: Werner LEMBERG
Subject: [groff] 01/02: Fix some problems related to hyphenation.
Date: Thu, 1 Mar 2018 14:29:01 -0500 (EST)

wl pushed a commit to branch master
in repository groff.

commit b5aaab51158255411fd196b43f70f45dda511a42
Author: Werner Lemberg <address@hidden>
Date:   Thu Mar 1 20:17:21 2018 +0100

    Fix some problems related to hyphenation.
---
 ChangeLog              | 23 +++++++++++++++++++++++
 NEWS                   |  9 +++++++++
 doc/groff.texi         | 32 ++++++++++++++++++++++++++++----
 man/groff_diff.7.man   |  6 ++++++
 src/roff/troff/env.cpp | 40 +++++++++++++++++++++++++++++++---------
 5 files changed, 97 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1506e57..9ce1d1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2018-03-01  Werner LEMBERG  <address@hidden>
+
+       Fix some problems related to hyphenation.
+
+       Introduce values 16 (allow hyphenation before last character) and 32
+       (allow hyphenation before first character) to the `hy' request
+       (#48904).
+
+       Really fix problem reported in issue #48904.
+
+       Fix #53243, which is a regression introduced in 2016-09-09.
+
+       * src/roff/troff/env.cpp (HYPHEN_LAST_CHAR, HYPHEN_FIRST_CHAR): New
+       enumeration values.
+       (hyphenate_request): Check for contradicting values.
+       (environment::hyphenate_line): Fix minimum word length considered
+       for hyphenation.
+       (environment::print_env): Updated.
+       (hyphenate): Fix and extend logic.  The original patch to handle
+       #48904 was bad.
+
+       * doc/groff.texi, man/groff_diff.7.man, NEWS: Updated.
+
 2018-03-01  Deri James  <address@hidden>
 
        Add page transitions to pdfs created with gropdf.
diff --git a/NEWS b/NEWS
index e738e2c..10c6550 100644
--- a/NEWS
+++ b/NEWS
@@ -7,9 +7,18 @@
 This file describes recent user-visible changes in groff.  Bug fixes are not
 described.  There are more details in the man and info pages.
 
+
 VERSION 1.22.3
 ==============
 
+Troff
+-----
+
+o The `hy' request has been extended.  Value 16 enables hyphenation before
+  the last character, and value 32 enables hyphenation after the first
+  character.
+
+
 Gxditview
 ---------
 
diff --git a/doc/groff.texi b/doc/groff.texi
index 87c5167..fc3abd0 100644
--- a/doc/groff.texi
+++ b/doc/groff.texi
@@ -7015,8 +7015,9 @@ Enable hyphenation.  The request has an optional numeric 
argument,
 
 @table @code
 @item 1
-The default argument if @var{mode} is omitted.  Hyphenate without
-restrictions.  This is also the start-up value of @code{gtroff}.
+The default argument if @var{mode} is omitted: Hyphenation is enabled,
+and the first and the last character of a word is not hyphenated.  This
+is also the start-up value of @code{gtroff}.
 
 @item 2
 Do not hyphenate the last word on a page or column.
@@ -7026,11 +7027,30 @@ Do not hyphenate the last two characters of a word.
 
 @item 8
 Do not hyphenate the first two characters of a word.
+
address@hidden 16
+Allow hyphenation before the last character of a word.
+
address@hidden 32
+Allow hyphenation after the first character of a word.
 @end table
 
-Values in the previous table are additive.  For example, the
+The values in the previous table are additive.  For example,
 address@hidden causes @code{gtroff} to neither hyphenate the last two nor
-the first two characters of a word.
+the first two characters of a word.  Note that address@hidden would do
+exactly the same; in other words, address@hidden need not be added if the
+value is larger address@hidden
+
+Using values 4 address@hidden can't be used together since they contradict
+each other; the same holds for values 8 address@hidden
+
+For historical reasons the default value of the @code{hy} request
+doesn't fit the American English hyphenation patterns that are used by
+groff as the default.  These patterns expect that neither the first
+character nor the last two characters are to be hyphenated; this
+corresponds to address@hidden  Consequently, @code{hy}'s default
address@hidden or even setting values 16 address@hidden might lead to
+(additional) incorrect hyphenation points.
 
 @cindex hyphenation restrictions register (@code{.hy})
 The current hyphenation restrictions can be found in the read-only
@@ -7085,6 +7105,10 @@ is zero can be used to separate the arguments of 
@code{hw} (see the
 documentation for the @code{hcode} request below for more information).
 In addition, this request can be used more than once.
 
address@hidden @code{hw} request, and @code{hy} restrictions
+Hyphenation points specified with @code{hw} are not subject to the
+restrictions given by the @code{hy} request.
+
 Hyphenation exceptions specified with the @code{hw} request are
 associated with the current hyphenation language; it causes an error if
 there is no current hyphenation language.
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index 7414e42..458e26a 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -2595,6 +2595,12 @@ There is no limit on the number of named environments; 
they are
 created the first time that they are referenced.
 .
 .TP
+.BI .hy\  n
+New additive values 32 and\~64 are available; the former enables
+hyphenation before the last character, the latter enables hyphenation
+after the first character.
+.
+.TP
 .BI .ss\  m\ n
 When two arguments are given to the
 .B ss
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 518af2e..e22d235 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -41,7 +41,9 @@ enum { ADJUST_LEFT = 0, ADJUST_BOTH = 1, ADJUST_CENTER = 3, 
ADJUST_RIGHT = 5 };
 enum {
   HYPHEN_NOT_LAST_LINE = 2,
   HYPHEN_NOT_LAST_CHARS = 4,
-  HYPHEN_NOT_FIRST_CHARS = 8
+  HYPHEN_NOT_FIRST_CHARS = 8,
+  HYPHEN_LAST_CHAR = 16,
+  HYPHEN_FIRST_CHAR = 32
 };
 
 struct env_list {
@@ -1655,8 +1657,13 @@ void no_hyphenate()
 void hyphenate_request()
 {
   int n;
-  if (has_arg() && get_integer(&n))
-    curenv->hyphenation_flags = n;
+  if (has_arg() && get_integer(&n)) {
+    if (((n & HYPHEN_FIRST_CHAR) && (n & HYPHEN_NOT_FIRST_CHARS))
+       || ((n & HYPHEN_LAST_CHAR) && (n & HYPHEN_NOT_LAST_CHARS)))
+      warning(WARN_SYNTAX, "contradicting hyphenation flags, ignored");
+    else
+      curenv->hyphenation_flags = n;
+  }
   else
     curenv->hyphenation_flags = 1;
   skip_line();
@@ -1694,8 +1701,8 @@ void environment::newline()
       prev_fontno = fontno;
       fontno = pre_underline_fontno;
       if (underline_spaces) {
-        underline_spaces = 0;
-        add_node(do_underline_special(0));
+       underline_spaces = 0;
+       add_node(do_underline_special(0));
       }
     }
   }
@@ -2027,7 +2034,9 @@ void environment::hyphenate_line(int start_here)
       && !((hyphenation_flags & HYPHEN_NOT_LAST_LINE)
           && (curdiv->distance_to_next_trap()
               <= vertical_spacing + total_post_vertical_spacing()))
-      && i >= (2
+      && i >= (4
+              - (hyphenation_flags & HYPHEN_FIRST_CHAR ? 1 : 0)
+              - (hyphenation_flags & HYPHEN_LAST_CHAR ? 1 : 0)
               + (hyphenation_flags & HYPHEN_NOT_FIRST_CHARS ? 1 : 0)
               + (hyphenation_flags & HYPHEN_NOT_LAST_CHARS ? 1 : 0)))
     hyphenate(sl, hyphenation_flags);
@@ -3310,8 +3319,12 @@ void environment::print_env()
   string hf = hyphenation_flags ? "on" : "off";
   if (hyphenation_flags & HYPHEN_NOT_LAST_LINE)
     hf += ", not last line";
+  if (hyphenation_flags & HYPHEN_LAST_CHAR)
+    hf += ", last char";
   if (hyphenation_flags & HYPHEN_NOT_LAST_CHARS)
     hf += ", not last two chars";
+  if (hyphenation_flags & HYPHEN_FIRST_CHAR)
+    hf += ", first char";
   if (hyphenation_flags & HYPHEN_NOT_FIRST_CHARS)
     hf += ", not first two chars";
   hf += '\0';
@@ -3953,7 +3966,7 @@ void hyphenate(hyphen_list *h, unsigned flags)
        break;
     }
     hyphen_list *nexth = tem;
-    if (len > 2) {
+    if (len >= 2) {
       buf[len] = 0;
       unsigned char *pos
        = (unsigned char *)current_language->exceptions.lookup(buf);
@@ -3970,11 +3983,20 @@ void hyphenate(hyphen_list *h, unsigned flags)
        hbuf[0] = hbuf[len + 1] = '.';
        int num[WORD_MAX + 3];
        current_language->patterns.hyphenate(hbuf, len + 2, num);
-       int i;
-       if (flags & HYPHEN_NOT_FIRST_CHARS)
+       // The position of a hyphenation point gets marked with an odd
+       // number.  Example:
+       //
+       //   hbuf:  . h e l p f u l .
+       //   num:  0 0 0 0 0 1 0 0 0 0
+       if (!(flags & HYPHEN_FIRST_CHAR))
          num[2] = 0;
+       if (flags & HYPHEN_NOT_FIRST_CHARS)
+         num[3] = 0;
+       if (flags & HYPHEN_LAST_CHAR)
+         ++len;
        if (flags & HYPHEN_NOT_LAST_CHARS)
          --len;
+       int i;
        for (i = 2, tem = h; i < len && tem; tem = tem->next, i++)
          if (num[i] & 1)
            tem->hyphen = 1;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]