[Top][All Lists]

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

[PATCH] [troff]: Make unbreakable spaces have a minimum length.

From: Alejandro Colomar
Subject: [PATCH] [troff]: Make unbreakable spaces have a minimum length.
Date: Tue, 7 Mar 2023 13:55:56 +0100

Previously, there was a bug by which a very long unbreakable element was
right after an unbreakable adjustable space, the space would be adjusted
to a negative value, so that the line is not broken and it would "seem
right" to troff(1).  Of course, a negative space would have the unwanted
effect of hiding previous text, which wouldn't seem so right to a

Now, we don't adjust space negatively, so \~ has now a minimum length of
a single space.

Closes: <>
Closes: <>
Reported-by: Bjarni Ingi Gislason <>
Reported-by: Alejandro Colomar <>
Cc: "G. Branden Robinson" <>
Signed-off-by: Alejandro Colomar <>

Hi Branden,

I tested my reproducer and Bjarni's (2017) reproducer before and after
this patch, and both are fixed by this patch.  Existing tests are not
affected (I can't reproduce the failure I had yesterday, which was about
fonts, IIRC).

I would add a regression test, but don't really know how to do it, so
I'll let you (or Bjarni) do it.



 src/roff/troff/env.cpp | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 9f00284c6..f15225af7 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -2081,11 +2081,8 @@ static node *node_list_reverse(node *n)
 static void distribute_space(node *n, int nspaces, hunits desired_space,
                             bool force_reverse_node_list = false)
-  if (desired_space.is_zero() || nspaces == 0)
+  if (desired_space.to_units() <= 0 || nspaces == 0)
-  // Positive desired space is the typical case.  Negative desired space
-  // is possible if we have overrun an unbreakable line.  But we should
-  // not get here if there are no adjustable space nodes to adjust.
   assert(nspaces > 0);
   // Space cannot always be distributed evenly among all of the space
   // nodes in the node list: there are limits to device resolution.  We
@@ -2098,8 +2095,7 @@ static void distribute_space(node *n, int nspaces, hunits 
   static bool do_reverse_node_list = false;
   if (force_reverse_node_list || do_reverse_node_list)
     n = node_list_reverse(n);
-  if (!force_reverse_node_list && spread_limit >= 0
-      && desired_space.to_units() > 0) {
+  if (!force_reverse_node_list && spread_limit >= 0) {
     hunits em = curenv->get_size();
     double Ems = (double)desired_space.to_units() / nspaces
                 / (em.is_zero() ? hresolution : em.to_units());

reply via email to

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