diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2017-06-27 18:25:02 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2017-06-27 18:25:02 +0000 |
commit | 4810b815f8d91b4ce1c346e211abc6f5abbad778 (patch) | |
tree | a85a3bc0b26547badb2fcc130ca8bbf76afb6d25 /tbl_term.c | |
parent | e9817d1eee252f2a60704c140932abd01803441b (diff) | |
download | mandoc-4810b815f8d91b4ce1c346e211abc6f5abbad778.tar.gz |
Implement spacing of columns as defined in the table layout;
this is for example used by lftp(1)
and, ironically, misused by our very own tbl(7) manual...
Diffstat (limited to 'tbl_term.c')
-rw-r--r-- | tbl_term.c | 47 |
1 files changed, 27 insertions, 20 deletions
@@ -101,7 +101,7 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) for (ic = 0; ic < sp->opts->cols; ic++) { coloff += tp->tbl.cols[ic].width; term_tab_iset(coloff); - coloff += 3; + coloff += tp->tbl.cols[ic].spacing; } /* Center the table as a whole. */ @@ -110,9 +110,11 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) if (sp->opts->opts & TBL_OPT_CENTRE) { tsz = sp->opts->opts & (TBL_OPT_BOX | TBL_OPT_DBOX) ? 2 : !!sp->opts->lvert + !!sp->opts->rvert; - for (ic = 0; ic < sp->opts->cols; ic++) - tsz += tp->tbl.cols[ic].width + 3; - tsz -= 3; + for (ic = 0; ic + 1 < sp->opts->cols; ic++) + tsz += tp->tbl.cols[ic].width + + tp->tbl.cols[ic].spacing; + if (sp->opts->cols) + tsz += tp->tbl.cols[sp->opts->cols - 1].width; if (offset + tsz > tp->tcol->rmargin) tsz -= 1; tp->tcol->offset = offset + tp->tcol->rmargin > tsz ? @@ -159,9 +161,8 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) } coloff += tp->tbl.cols[ic].width; tp->tcol->rmargin = coloff; - coloff++; if (ic + 1 < sp->opts->cols) - coloff += 2; + coloff += tp->tbl.cols[ic].spacing; if (spans) { spans--; continue; @@ -175,7 +176,7 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) /* Set up a column for a right vertical frame. */ tp->tcol++; - tp->tcol->offset = coloff; + tp->tcol->offset = coloff + 1; tp->tcol->rmargin = tp->maxrmargin; /* Spans may have reduced the number of columns. */ @@ -327,13 +328,13 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) tp->tcol + 1 == tp->tcols + tp->lasttcol)) continue; - if (tp->tcol->rmargin > tp->viscol) { + if (tp->viscol < tp->tcol->rmargin) { (*tp->advance)(tp, tp->tcol->rmargin - tp->viscol); tp->viscol = tp->tcol->rmargin; } - - if (tp->tcol->rmargin + 1 > tp->viscol) { + while (tp->viscol < tp->tcol->rmargin + + tp->tbl.cols[ic].spacing / 2) { (*tp->letter)(tp, fc); tp->viscol++; } @@ -353,10 +354,11 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) break; } } - - (*tp->letter)(tp, - fc == ' ' ? '|' : vert ? '+' : fc); - tp->viscol++; + if (tp->tbl.cols[ic].spacing) { + (*tp->letter)(tp, fc == ' ' ? '|' : + vert ? '+' : fc); + tp->viscol++; + } if (fc != ' ') { if (cp != NULL && @@ -368,7 +370,8 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) else fc = ' '; } - if (vert > 1 || fc != ' ') { + if (tp->tbl.cols[ic].spacing > 2 && + (vert > 1 || fc != ' ')) { (*tp->letter)(tp, fc == ' ' ? '|' : vert > 1 ? '+' : fc); tp->viscol++; @@ -448,6 +451,7 @@ static void tbl_hrule(struct termp *tp, const struct tbl_span *sp, int kind) { const struct tbl_cell *cp, *cpn, *cpp; + const struct roffcol *col; int vert; char line, cross; @@ -464,7 +468,8 @@ tbl_hrule(struct termp *tp, const struct tbl_span *sp, int kind) if (cpn == cp) cpn = NULL; for (;;) { - tbl_char(tp, line, tp->tbl.cols[cp->col].width + 1); + col = tp->tbl.cols + cp->col; + tbl_char(tp, line, col->width + col->spacing / 2); vert = cp->vert; if ((cp = cp->next) == NULL) break; @@ -480,10 +485,12 @@ tbl_hrule(struct termp *tp, const struct tbl_span *sp, int kind) } if (sp->opts->opts & TBL_OPT_ALLBOX && !vert) vert = 1; - if (vert) - tbl_char(tp, cross, vert); - if (vert < 2) - tbl_char(tp, line, 2 - vert); + if (col->spacing) + tbl_char(tp, vert ? cross : line, 1); + if (col->spacing > 2) + tbl_char(tp, vert > 1 ? cross : line, 1); + if (col->spacing > 4) + tbl_char(tp, line, (col->spacing - 3) / 2); } if (kind) { term_word(tp, "+"); |