aboutsummaryrefslogtreecommitdiffstatshomepage
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
commitb9afab5e3f173e16ac169b27fa39efd01ea9afe7 (patch)
treef9f8499bf43fd06517a1fa6d47a76d0896583355
parente0177b9bff2cd6141e183411fe5a31f6ba8fe1a9 (diff)
downloadmandoc-b9afab5e3f173e16ac169b27fa39efd01ea9afe7.tar.gz
mandoc-b9afab5e3f173e16ac169b27fa39efd01ea9afe7.tar.zst
mandoc-b9afab5e3f173e16ac169b27fa39efd01ea9afe7.zip
fix column width calculation for text block cells
-rw-r--r--out.c31
-rw-r--r--out.h4
-rw-r--r--tbl_html.c4
-rw-r--r--tbl_term.c4
4 files changed, 25 insertions, 18 deletions
diff --git a/out.c b/out.c
index 73769d2b..9fa50098 100644
--- a/out.c
+++ b/out.c
@@ -1,4 +1,4 @@
-/* $Id: out.c,v 1.65 2017/06/08 18:11:22 schwarze Exp $ */
+/* $Id: out.c,v 1.66 2017/06/12 20:14:18 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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);
diff --git a/out.h b/out.h
index ac617b32..94040035 100644
--- a/out.h
+++ b/out.h
@@ -1,4 +1,4 @@
-/* $Id: out.h,v 1.29 2017/06/08 18:11:22 schwarze Exp $ */
+/* $Id: out.h,v 1.30 2017/06/12 20:14:18 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -68,4 +68,4 @@ struct tbl_span;
const char *a2roffsu(const char *, struct roffsu *, enum roffscale);
void tblcalc(struct rofftbl *tbl,
- const struct tbl_span *, size_t);
+ const struct tbl_span *, size_t, size_t);
diff --git a/tbl_html.c b/tbl_html.c
index 5db39af5..06fae5eb 100644
--- a/tbl_html.c
+++ b/tbl_html.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_html.c,v 1.21 2017/06/08 18:11:22 schwarze Exp $ */
+/* $Id: tbl_html.c,v 1.22 2017/06/12 20:14:18 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -83,7 +83,7 @@ html_tblopen(struct html *h, const struct tbl_span *sp)
h->tbl.len = html_tbl_len;
h->tbl.slen = html_tbl_strlen;
h->tbl.sulen = html_tbl_sulen;
- tblcalc(&h->tbl, sp, 0);
+ tblcalc(&h->tbl, sp, 0, 0);
}
assert(NULL == h->tblt);
diff --git a/tbl_term.c b/tbl_term.c
index 36fa2b70..5af39df3 100644
--- a/tbl_term.c
+++ b/tbl_term.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_term.c,v 1.47 2017/06/12 19:05:47 schwarze Exp $ */
+/* $Id: tbl_term.c,v 1.48 2017/06/12 20:14:18 schwarze Exp $ */
/*
* Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011,2012,2014,2015,2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -87,7 +87,7 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
tp->tbl.sulen = term_tbl_sulen;
tp->tbl.arg = tp;
- tblcalc(&tp->tbl, sp, tp->tcol->rmargin - tp->tcol->offset);
+ tblcalc(&tp->tbl, sp, tp->tcol->offset, tp->tcol->rmargin);
/* Center the table as a whole. */