gbranden pushed a commit to branch master
in repository groff.
commit 82192662ba84d7a2d13bb52fc4acb23162cc9bfa
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Apr 8 18:15:48 2025 -0500
[troff]: Refactor break/adjustment warnings.
* src/roff/troff/env.cpp (environment::choose_breakpoint): Stop throwing
break warnings here...
(distribute_space): ...and here...
(environment::possibly_break_line): ...instead doing so here.
---
ChangeLog | 9 +++++++++
src/roff/troff/env.cpp | 45 +++++++++++++++++++--------------------------
2 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fbe296a9a..22bf08fc3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-04-08 G. Branden Robinson <[email protected]>
+
+ [troff]: Refactor break/adjustment warning production.
+
+ * src/roff/troff/env.cpp (environment::choose_breakpoint): Stop
+ throwing break warnings here...
+ (distribute_space): ...and here...
+ (environment::possibly_break_line): ...instead doing so here.
+
2025-04-08 G. Branden Robinson <[email protected]>
[groff]: Test for presence of over-/underset line diagnostics
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index a00058bcb..8340b0ade 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -2099,14 +2099,8 @@ breakpoint *environment::choose_breakpoint()
}
nd = nd->next;
}
- if (best_bp) {
- if (!best_bp_fits)
- // TODO: If we implement shrinkable/squeezable adjustable spaces,
- // this warning could become spurious in cases where we can
- // achieve the desired adjustment.
- output_warning(WARN_BREAK, "cannot break line");
+ if (best_bp)
return best_bp;
- }
return 0 /* nullptr */;
}
@@ -2193,19 +2187,8 @@ static bool distribute_space(node *nd, int nspaces,
hunits desired_space,
bool force_reverse_node_list = false)
{
- if (desired_space.is_zero() || nspaces == 0)
- return false;
- if (desired_space < H0) {
- // TODO: Implement shrinkable/squeezable space adjustments here.
- if (nspaces == 0)
- output_warning(WARN_BREAK, "cannot adjust line lacking adjustable"
- " spaces; overset by %1 units",
- abs(desired_space.to_units()));
- else
- output_warning(WARN_BREAK, "cannot adjust line; overset by %1"
- " units", abs(desired_space.to_units()));
+ if (desired_space.is_zero() || (nspaces == 0) || (desired_space < H0))
return false;
- }
// 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.
@@ -2260,21 +2243,31 @@ void environment::possibly_break_line(bool
must_break_here,
ndp = &(*ndp)->next;
bp->nd->split(bp->index, &pre, &post);
*ndp = post;
- // The space deficit tells us how much the line is overset (or, if
- // negative, underset) relative to the configured line length.
+ // The space deficit tells us how much the line is overset if
+ // negative, or underset if positive, relative to the configured
+ // line length.
hunits space_deficit = target_text_length - bp->width;
+ // An overset line always gets a warning.
+ if (space_deficit < H0)
+ output_warning(WARN_BREAK, "cannot %1 line; overset by %2 units",
+ (ADJUST_BOTH == adjust_mode) ? "adjust" : "break",
+ abs(space_deficit.to_units()));
+ // An underset line warns only if it requires adjustment but no
+ // adjustable spaces exist on the line.
+ else if ((ADJUST_BOTH == adjust_mode)
+ && (space_deficit > H0)
+ && (0 == bp->nspaces))
+ output_warning(WARN_BREAK, "cannot adjust line; underset by %1"
+ " units", space_deficit.to_units());
// The extra space is the amount of space to distribute among the
// adjustable space nodes in an output line; this process occurs
- // only if adjustment is enabled.
+ // only if adjustment is enabled. We may however want to synthesize
+ // an extra indentation from it if centering or right-aligning.
hunits extra_space = H0;
switch (adjust_mode) {
case ADJUST_BOTH:
if (bp->nspaces != 0)
extra_space = space_deficit;
- else if (bp->width > 0 && target_text_length > 0
- && target_text_length > bp->width)
- output_warning(WARN_BREAK, "cannot adjust line; underset by %1"
- " units", space_deficit.to_units());
break;
case ADJUST_CENTER:
saved_indent += space_deficit / 2;
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit