gbranden pushed a commit to branch master
in repository groff.
commit a55808efb8bb21f8afe8bfa463669f9543678fa4
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Oct 4 05:42:12 2025 -0500
[troff]: Trivially refactor for clarity.
* src/roff/troff/node.h (enum hyphenation_type): Rename symbols.
`HYPHENATE_MIDDLE` -> `HYPHENATION_PERMITTED`
`HYPHENATE_BOUNDARY` -> `HYPHENATION_UNNECESSARY`
`HYPHENATE_INHIBIT` -> `HYPHENATION_INHIBITED`
* src/roff/troff/env.cpp (environment::possibly_hyphenate_line):
* src/roff/troff/node.cpp (glyph_node::get_hyphenation_type)
(hyphen_inhibitor_node::get_hyphenation_type)
(break_char_node::get_hyphen_list)
(node::get_hyphenation_type)
(dbreak_node::get_hyphenation_type)
(kern_pair_node::get_hyphenation_type)
(dummy_node::get_hyphenation_type)
(transparent_dummy_node::get_hyphenation_type)
(hmotion_node::get_hyphenation_type)
(space_char_hmotion_node::get_hyphenation_type)
(space_node::get_hyphenation_type)
(unbreakable_space_node::get_hyphenation_type)
(composite_node::get_hyphenation_type)
(left_italic_corrected_node::get_hyphenation_type): Update.
Also annotate what `environment::possibly_hyphenate_line()` does.
---
ChangeLog | 24 ++++++++++++++++++++++++
src/roff/troff/env.cpp | 17 ++++++++++++-----
src/roff/troff/node.cpp | 35 +++++++++++++++++------------------
src/roff/troff/node.h | 6 +++---
4 files changed, 56 insertions(+), 26 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f3907880e..c1ab36180 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2025-10-04 G. Branden Robinson <[email protected]>
+
+ [troff]: Trivially refactor for clarity.
+
+ * src/roff/troff/node.h (enum hyphenation_type): Rename symbols.
+ `HYPHENATE_MIDDLE` -> `HYPHENATION_PERMITTED`
+ `HYPHENATE_BOUNDARY` -> `HYPHENATION_UNNECESSARY`
+ `HYPHENATE_INHIBIT` -> `HYPHENATION_INHIBITED`
+ * src/roff/troff/env.cpp (environment::possibly_hyphenate_line):
+ * src/roff/troff/node.cpp (glyph_node::get_hyphenation_type)
+ (hyphen_inhibitor_node::get_hyphenation_type)
+ (break_char_node::get_hyphen_list)
+ (node::get_hyphenation_type)
+ (dbreak_node::get_hyphenation_type)
+ (kern_pair_node::get_hyphenation_type)
+ (dummy_node::get_hyphenation_type)
+ (transparent_dummy_node::get_hyphenation_type)
+ (hmotion_node::get_hyphenation_type)
+ (space_char_hmotion_node::get_hyphenation_type)
+ (space_node::get_hyphenation_type)
+ (unbreakable_space_node::get_hyphenation_type)
+ (composite_node::get_hyphenation_type)
+ (left_italic_corrected_node::get_hyphenation_type): Update.
+
2025-10-04 G. Branden Robinson <[email protected]>
[troff]: Regression-test Savannah #67577.
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 4571f09c1..43fe62bb6 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -2140,6 +2140,12 @@ breakpoint *environment::choose_breakpoint()
return 0 /* nullptr */;
}
+// Iterate over the nodes of the output line, looking for break points.
+// The node list is in reverse order, so the first node we see is the
+// last (or rightmost) on the line. Whether a break requires
+// hyphenation depends on the properties of the node and the context;
+// if we're at a word boundary, we can break without a hyphen regardless
+// of the node's own hyphenation properties.
void environment::possibly_hyphenate_line(bool must_break_here)
{
assert(line != 0 /* nullptr */);
@@ -2151,8 +2157,8 @@ void environment::possibly_hyphenate_line(bool
must_break_here)
for (startp = &line->next; *startp != 0 /* nullptr */;
startp = &(*startp)->next) {
hyphenation_type this_type = (*startp)->get_hyphenation_type();
- if (prev_type == HYPHENATE_BOUNDARY
- && this_type == HYPHENATE_MIDDLE)
+ if (prev_type == HYPHENATION_UNNECESSARY
+ && this_type == HYPHENATION_PERMITTED)
break;
prev_type = this_type;
}
@@ -2163,10 +2169,11 @@ void environment::possibly_hyphenate_line(bool
must_break_here)
do {
tem = tem->next;
} while (tem != 0 /* nullptr */
- && tem->get_hyphenation_type() == HYPHENATE_MIDDLE);
+ && tem->get_hyphenation_type() == HYPHENATION_PERMITTED);
// This is for characters like hyphen and em dash.
- bool inhibit = (tem != 0 /* nullptr */
- && tem->get_hyphenation_type() == HYPHENATE_INHIBIT);
+ bool inhibit = ((tem != 0 /* nullptr */)
+ && (tem->get_hyphenation_type()
+ == HYPHENATION_INHIBITED));
node *end = tem;
hyphen_list *sl = 0 /* nullptr */;
tem = *startp;
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 1294677f9..f8982e2ac 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -2293,7 +2293,7 @@ hunits glyph_node::left_italic_correction()
hyphenation_type glyph_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
void glyph_node::ascii_print(ascii_output_file *ascii)
@@ -2633,7 +2633,7 @@ const char *hyphen_inhibitor_node::type()
hyphenation_type hyphen_inhibitor_node::get_hyphenation_type()
{
- return HYPHENATE_INHIBIT;
+ return HYPHENATION_INHIBITED;
}
/* add_discretionary_hyphen methods */
@@ -3162,7 +3162,7 @@ hyphen_list *break_char_node::get_hyphen_list(hyphen_list
*tail, int *)
hyphenation_type break_char_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
void break_char_node::ascii_print(ascii_output_file *ascii)
@@ -4239,55 +4239,54 @@ void dbreak_node::split(int where, node **prep, node
**postp)
hyphenation_type node::get_hyphenation_type()
{
- return HYPHENATE_BOUNDARY;
+ return HYPHENATION_UNNECESSARY;
}
hyphenation_type dbreak_node::get_hyphenation_type()
{
- return HYPHENATE_INHIBIT;
+ return HYPHENATION_INHIBITED;
}
hyphenation_type kern_pair_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
hyphenation_type dummy_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
hyphenation_type transparent_dummy_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
hyphenation_type hmotion_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
hyphenation_type space_char_hmotion_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
hyphenation_type overstrike_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
hyphenation_type space_node::get_hyphenation_type()
{
- // XXX: This conditional seems to have no practical consequence. --GBR
if (was_escape_colon)
- return HYPHENATE_MIDDLE;
- return HYPHENATE_BOUNDARY;
+ return HYPHENATION_PERMITTED;
+ return HYPHENATION_UNNECESSARY;
}
hyphenation_type unbreakable_space_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
bool node::interpret(macro *)
@@ -4362,7 +4361,7 @@ bool device_extension_node::causes_tprint()
hyphenation_type device_extension_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
bool device_extension_node::is_tag()
@@ -4818,7 +4817,7 @@ units composite_node::size()
hyphenation_type composite_node::get_hyphenation_type()
{
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
void composite_node::asciify(macro *m)
@@ -6172,7 +6171,7 @@ hyphenation_type
left_italic_corrected_node::get_hyphenation_type()
if (nodes != 0 /* nullptr */)
return nodes->get_hyphenation_type();
else
- return HYPHENATE_MIDDLE;
+ return HYPHENATION_PERMITTED;
}
hyphen_list *left_italic_corrected_node::get_hyphen_list(
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index 6530ee766..342338789 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -26,9 +26,9 @@ struct hyphen_list {
};
enum hyphenation_type {
- HYPHENATE_MIDDLE,
- HYPHENATE_BOUNDARY,
- HYPHENATE_INHIBIT
+ HYPHENATION_PERMITTED,
+ HYPHENATION_UNNECESSARY,
+ HYPHENATION_INHIBITED
};
class ascii_output_file;
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit