From d2e22edf089ef0d635671732487d7d4918d30186 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 7 Apr 2013 12:57:32 -0700 Subject: [PATCH] ascii: Omit whitespace at the end of a line. Long string variables tend not to be completely filled with data, which means that they end in a lot of spaces. The ASCII output driver didn't handle these well. Instead, it put a blank line in the cell for each trailing space. This fixes the problem and adds a test. Reported by Ronald Crichton. Bug #38672. --- src/output/ascii.c | 33 ++++++++++++++------------- tests/output/render.at | 51 ++++++++++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/src/output/ascii.c b/src/output/ascii.c index 00806b4e64..78626cf13f 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -858,6 +858,7 @@ ascii_layout_cell (struct ascii_driver *a, const struct table_cell *cell, size_t last_break_ofs = 0; int last_break_width = 0; int width = 0; + size_t graph_ofs; size_t ofs; for (ofs = 0; ofs < n; ) @@ -893,25 +894,27 @@ ascii_layout_cell (struct ascii_driver *a, const struct table_cell *cell, } ofs += mblen; } - if (b[ofs] != UC_BREAK_MANDATORY) - { - while (ofs > 0 && isspace (line[ofs - 1])) - { - ofs--; - width--; - } - } - if (width > *widthp) - *widthp = width; + + /* Trim any trailing spaces off the end of the text to be drawn. */ + for (graph_ofs = ofs; graph_ofs > 0; graph_ofs--) + if (!isspace (line[graph_ofs - 1])) + break; + width -= ofs - graph_ofs; /* Draw text. */ - text_draw (a, cell->options, bb, clip, y, line, ofs, width); + text_draw (a, cell->options, bb, clip, y, line, graph_ofs, width); - /* Next line. */ - pos += ofs; - if (ofs < n && isspace (line[ofs])) - pos++; + /* If a new-line ended the line, just skip the new-line. Otherwise, skip + past any spaces past the end of the line (but not past a new-line). */ + if (b[ofs] == UC_BREAK_MANDATORY) + ofs++; + else + while (ofs < n && isspace (line[ofs]) && b[ofs] != UC_BREAK_MANDATORY) + ofs++; + if (width > *widthp) + *widthp = width; + pos += ofs; } *heightp = y - bb[V][0]; diff --git a/tests/output/render.at b/tests/output/render.at index 9821348adb..230299223f 100644 --- a/tests/output/render.at +++ b/tests/output/render.at @@ -1725,12 +1725,11 @@ AT_CHECK([render-test --width=15 --length=15 input], [0], [dnl +-+--+--+---+ |h| The | | su -| | determ -+-+ han -|i|missing va -| | If IN -| | s -+-+ user ++-+ determ +|i| han +| |missing va +| |If INCLUDE ++-+ then user |j| va | | include | | calculati @@ -1739,14 +1738,14 @@ AT_CHECK([render-test --width=15 --length=15 input], [0], [dnl +-+ NOINCLUDE |k| whic | | -+-+ user -|l| va -| | e +| | user ++-+ va +|l| e +| | | | +-+ |m| | | -| | +-+---------- +--+--+--+ @@ -1757,8 +1756,7 @@ ubcommand| mines the| ndling of| ariables.| -NCLUDE is| -set, then| +E is set,| r‑missing| alues are| ed in the| @@ -1804,3 +1802,32 @@ x y z 7 8 9 ]) AT_CLEANUP + +# Long string variables tend to end in lots of spaces. The ASCII +# driver didn't handle this very well: it would essentially produce +# one blank line in a cell for each trailing space. This test +# checks for regression. See bug #38672. +AT_SETUP([ASCII driver renders end of line spaces reasonably]) +AT_KEYWORDS([render rendering]) +AT_DATA([input], [dnl +3 3 +@a +@b +@xyzzy @&t@ +@d +@e +@f +@g +@h +@i +]) +AT_CHECK([render-test --width=15 --length=15 input], [0], [dnl ++-+-+-----+ +|a|b|xyzzy| ++-+-+-----+ +|d|e| f| ++-+-+-----+ +|g|h| i| ++-+-+-----+ +]) +AT_CLEANUP -- 2.30.2