summaryrefslogtreecommitdiffstats
path: root/out.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-06-12 20:14:18 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-06-12 20:14:18 +0000
commitfd8254b702c0e458aaf5fe609520c3b90f8d02e8 (patch)
tree782f3bc2f36c8d59129d7d985a2882d0a54ecb1c /out.c
parent9d72453df4dc511deb6dc6371e56a40f8fe3c0a8 (diff)
downloadmandoc-fd8254b702c0e458aaf5fe609520c3b90f8d02e8.tar.gz
fix column width calculation for text block cells
Diffstat (limited to 'out.c')
-rw-r--r--out.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/out.c b/out.c
index 6e517373..5da58c6a 100644
--- a/out.c
+++ b/out.c
@@ -105,7 +105,7 @@ a2roffsu(const char *src, struct roffsu *dst, enum roffscale def)
*/
void
tblcalc(struct rofftbl *tbl, const struct tbl_span *sp,
- size_t totalwidth)
+ size_t offset, size_t rmargin)
{
struct roffsu su;
const struct tbl_opts *opts;
@@ -156,8 +156,9 @@ tblcalc(struct rofftbl *tbl, const struct tbl_span *sp,
(*tbl->sulen)(&su, tbl->arg);
if (col->width < dp->layout->width)
col->width = dp->layout->width;
- tblcalc_data(tbl, col, opts, dp, dp->block ?
- totalwidth / (sp->opts->cols + 1) : 0);
+ tblcalc_data(tbl, col, opts, dp,
+ rmargin && dp->block ?
+ rmargin / (sp->opts->cols + 1) : 0);
}
}
@@ -194,7 +195,7 @@ tblcalc(struct rofftbl *tbl, const struct tbl_span *sp,
continue;
if (col->width == ewidth)
continue;
- if (nxcol && totalwidth)
+ if (nxcol && rmargin)
xwidth += ewidth - col->width;
col->width = ewidth;
}
@@ -206,13 +207,13 @@ tblcalc(struct rofftbl *tbl, const struct tbl_span *sp,
* Distribute the available width evenly.
*/
- if (nxcol && totalwidth) {
+ if (nxcol && rmargin) {
xwidth += 3*maxcol +
(opts->opts & (TBL_OPT_BOX | TBL_OPT_DBOX) ?
2 : !!opts->lvert + !!opts->rvert);
- if (xwidth >= totalwidth)
+ if (rmargin <= offset + xwidth)
return;
- xwidth = totalwidth - xwidth;
+ xwidth = rmargin - offset - xwidth;
/*
* Emulate a bug in GNU tbl width calculation that
@@ -281,11 +282,13 @@ tblcalc_literal(struct rofftbl *tbl, struct roffcol *col,
const char *str; /* Beginning of the first line. */
const char *beg; /* Beginning of the current line. */
char *end; /* End of the current line. */
- size_t sz; /* Length of the current line. */
+ size_t lsz; /* Length of the current line. */
+ size_t wsz; /* Length of the current word. */
if (dp->string == NULL || *dp->string == '\0')
return;
str = mw ? mandoc_strdup(dp->string) : dp->string;
+ lsz = 0;
for (beg = str; beg != NULL && *beg != '\0'; beg = end) {
end = mw ? strchr(beg, ' ') : NULL;
if (end != NULL) {
@@ -293,9 +296,13 @@ tblcalc_literal(struct rofftbl *tbl, struct roffcol *col,
while (*end == ' ')
end++;
}
- sz = (*tbl->slen)(beg, tbl->arg);
- if (col->width < sz)
- col->width = sz;
+ wsz = (*tbl->slen)(beg, tbl->arg);
+ if (mw && lsz && lsz + 1 + wsz <= mw)
+ lsz += 1 + wsz;
+ else
+ lsz = wsz;
+ if (col->width < lsz)
+ col->width = lsz;
}
if (mw)
free((void *)str);