From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout.scc.kit.edu (scc-mailout.scc.kit.edu [129.13.185.202]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p4E4CUsF032625 for ; Sat, 14 May 2011 00:12:33 -0400 (EDT) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by scc-mailout-02.scc.kit.edu with esmtp (Exim 4.72 #1) id 1QL6DM-0005j5-Vr; Sat, 14 May 2011 06:12:29 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1QL6DN-0003i9-29 for discuss@mdocml.bsd.lv; Sat, 14 May 2011 06:12:29 +0200 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.69) (envelope-from ) id 1QL6DN-00083j-1N for discuss@mdocml.bsd.lv; Sat, 14 May 2011 06:12:29 +0200 Received: from schwarze by usta.de with local (Exim 4.72) (envelope-from ) id 1QL6DM-0003Ua-WE for discuss@mdocml.bsd.lv; Sat, 14 May 2011 06:12:29 +0200 Date: Sat, 14 May 2011 06:12:28 +0200 From: Ingo Schwarze To: discuss@mdocml.bsd.lv Subject: Re: tbl issues with 1.11.1 Message-ID: <20110514041228.GA30797@iris.usta.de> References: <20110414014526.GB1280@darklight.org.ru> <20110416213413.GI13629@iris.usta.de> <20110426201050.GA5448@britannica.bec.de> <20110512220226.GA23153@britannica.bec.de> <4DCD9CA4.2060708@bsd.lv> X-Mailinglist: mdocml-discuss Reply-To: discuss@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4DCD9CA4.2060708@bsd.lv> User-Agent: Mutt/1.5.21 (2010-09-15) Hi Kristaps and Joerg, >>> Ingo, that's your change from January. Care to check the attached patch? >> Anyone? > Ingo? I remember you checking these in... care to take another look? Er, jaja, i was a bit swamped... Unfortunately, Joergs patch is not right, i breaks the horizontal spacing in tables without vertical rulers almost completely, see for example captoinfo(1) and compare the groff and mandoc output. Getting this right in both cases - with and without vertical rulers - requires rather large changes. The logic, as far as i understand it so far, goes like this: - box produces "|" - no spacing at this point - first cell, width is max(lengths) - one space - vertical ruler, if none, another space - another space, unless there was a double ruler (!!) - second cell - and so on. That is vastly different from what we have now, both regarding the width calculations - which apparently must not include padding - and regarding the output itself. The work-in-progress patch below comes closer. However, it still has at least two deficiencies, so it is not ready for commit: - There still is a bogus space after double rulers, see (!!). - The handling of explicit spacing options got sweeped away by the reorg i was forced to do. Probably, i need to put it back in at the right places. It was in the calc routine but probably belongs in the output routines themselves. Just sending this such that you finally get some feedback. In case we need more discussion, we should probably move to tech@. Yours, Ingo P.S. The patch is large, but at least it shortens the code. :) Index: out.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/out.c,v retrieving revision 1.13 diff -u -p -r1.13 out.c --- out.c 21 Apr 2011 22:59:54 -0000 1.13 +++ out.c 14 May 2011 03:55:52 -0000 @@ -506,39 +506,12 @@ static void tblcalc_literal(struct rofftbl *tbl, struct roffcol *col, const struct tbl_dat *dp) { - size_t sz, bufsz, spsz; + size_t sz; const char *str; - /* - * Calculate our width and use the spacing, with a minimum - * spacing dictated by position (centre, e.g,. gets a space on - * either side, while right/left get a single adjacent space). - */ - - bufsz = spsz = 0; str = dp->string ? dp->string : ""; sz = (*tbl->slen)(str, tbl->arg); - /* FIXME: TBL_DATA_HORIZ et al.? */ - - assert(dp->layout); - switch (dp->layout->pos) { - case (TBL_CELL_LONG): - /* FALLTHROUGH */ - case (TBL_CELL_CENTRE): - bufsz = (*tbl->len)(1, tbl->arg); - break; - default: - bufsz = (*tbl->len)(1, tbl->arg); - break; - } - - if (dp->layout->spacing) { - spsz = (*tbl->len)(dp->layout->spacing, tbl->arg); - bufsz = bufsz > spsz ? bufsz : spsz; - } - - sz += bufsz; if (col->width < sz) col->width = sz; } @@ -555,7 +528,7 @@ tblcalc_number(struct rofftbl *tbl, stru /* * First calculate number width and decimal place (last + 1 for - * no-decimal numbers). If the stored decimal is subsequent + * non-decimal numbers). If the stored decimal is subsequent to * ours, make our size longer by that difference * (right-"shifting"); similarly, if ours is subsequent the * stored, then extend the stored size by the difference. @@ -582,11 +555,6 @@ tblcalc_number(struct rofftbl *tbl, stru } else d = sz + psz; - /* Padding. */ - - sz += (*tbl->len)(2, tbl->arg); - d += (*tbl->len)(1, tbl->arg); - /* Adjust the settings for this column. */ if (col->decimal > d) { @@ -599,11 +567,4 @@ tblcalc_number(struct rofftbl *tbl, stru col->width = sz; if (d > col->decimal) col->decimal = d; - - /* Adjust for stipulated width. */ - - if (col->width < dp->layout->spacing) - col->width = dp->layout->spacing; } - - Index: tbl_term.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/tbl_term.c,v retrieving revision 1.8 diff -u -p -r1.8 tbl_term.c --- tbl_term.c 25 Jan 2011 12:07:26 -0000 1.8 +++ tbl_term.c 14 May 2011 03:55:52 -0000 @@ -37,7 +37,6 @@ static void tbl_number(struct termp *, c const struct tbl_dat *, const struct roffcol *); static void tbl_hrule(struct termp *, const struct tbl_span *); -static void tbl_vframe(struct termp *, const struct tbl *); static void tbl_vrule(struct termp *, const struct tbl_head *); @@ -96,7 +95,9 @@ term_tbl(struct termp *tp, const struct /* Vertical frame at the start of each row. */ - tbl_vframe(tp, sp->tbl); + if (TBL_OPT_BOX & sp->tbl->opts || TBL_OPT_DBOX & sp->tbl->opts) + term_word(tp, TBL_SPAN_HORIZ == sp->pos || + TBL_SPAN_DHORIZ == sp->pos ? "+" : "|"); /* * Now print the actual data itself depending on the span type. @@ -134,9 +135,28 @@ term_tbl(struct termp *tp, const struct if (--spans >= 0) continue; + /* All cells but the first get a leading blank. */ + + if (hp != sp->head) + tbl_char(tp, ASCII_NBRSP, 1); + col = &tp->tbl.cols[hp->ident]; tbl_data(tp, sp->tbl, dp, col); + /* No trailing blanks. */ + + if (NULL == hp->next) + break; + + /* + * Add another blank between cells, + * or two when there is no vertical ruler. + */ + + tbl_char(tp, ASCII_NBRSP, + TBL_HEAD_VERT == hp->next->pos || + TBL_HEAD_DVERT == hp->next->pos ? 1 : 2); + /* * Go to the next data cell and assign the * number of subsequent spans, if applicable. @@ -150,7 +170,9 @@ term_tbl(struct termp *tp, const struct break; } - tbl_vframe(tp, sp->tbl); + if (TBL_OPT_BOX & sp->tbl->opts || TBL_OPT_DBOX & sp->tbl->opts) + term_word(tp, TBL_SPAN_HORIZ == sp->pos || + TBL_SPAN_DHORIZ == sp->pos ? "+" : " |"); term_flushln(tp); /* @@ -176,7 +198,7 @@ tbl_hrule(struct termp *tp, const struct { const struct tbl_head *hp; char c; - size_t width; + size_t width, spc; /* * An hrule extends across the entire table and is demarked by a @@ -190,16 +212,14 @@ tbl_hrule(struct termp *tp, const struct /* FIXME: don't use `+' between data and a spanner! */ + spc = 1; for (hp = sp->head; hp; hp = hp->next) { width = tp->tbl.cols[hp->ident].width; switch (hp->pos) { case (TBL_HEAD_DATA): - if (hp->next) - width += 2; - tbl_char(tp, c, width); + tbl_char(tp, c, width + spc); break; case (TBL_HEAD_DVERT): - tbl_char(tp, '+', width); /* FALLTHROUGH */ case (TBL_HEAD_VERT): tbl_char(tp, '+', width); @@ -208,6 +228,7 @@ tbl_hrule(struct termp *tp, const struct abort(); /* NOTREACHED */ } + spc = 2; } } @@ -215,7 +236,7 @@ static void tbl_hframe(struct termp *tp, const struct tbl_span *sp) { const struct tbl_head *hp; - size_t width; + size_t width, spc; if ( ! (TBL_OPT_BOX & sp->tbl->opts || TBL_OPT_DBOX & sp->tbl->opts)) @@ -231,25 +252,29 @@ tbl_hframe(struct termp *tp, const struc if (TBL_OPT_DBOX & sp->tbl->opts) { term_word(tp, "+"); + spc = 1; for (hp = sp->head; hp; hp = hp->next) { - width = tp->tbl.cols[hp->ident].width; + width = tp->tbl.cols[hp->ident].width + spc; tbl_char(tp, '-', width); + spc = 2; } term_word(tp, "+"); term_flushln(tp); } term_word(tp, "+"); + spc = 1; for (hp = sp->head; hp; hp = hp->next) { width = tp->tbl.cols[hp->ident].width; switch (hp->pos) { case (TBL_HEAD_DATA): - tbl_char(tp, '-', width); + tbl_char(tp, '-', width + spc); break; default: tbl_char(tp, '+', width); break; } + spc = 2; } term_word(tp, "+"); term_flushln(tp); @@ -330,14 +355,6 @@ tbl_vrule(struct termp *tp, const struct } static void -tbl_vframe(struct termp *tp, const struct tbl *tbl) -{ - - if (TBL_OPT_BOX & tbl->opts || TBL_OPT_DBOX & tbl->opts) - term_word(tp, "|"); -} - -static void tbl_char(struct termp *tp, char c, size_t len) { size_t i, sz; @@ -356,37 +373,34 @@ static void tbl_literal(struct termp *tp, const struct tbl_dat *dp, const struct roffcol *col) { - size_t padl, padr, ssz; - - padl = padr = 0; + size_t padl, padr; assert(dp->string); - - ssz = term_len(tp, 1); + padr = col->width - term_strlen(tp, dp->string); + padl = 0; switch (dp->layout->pos) { case (TBL_CELL_LONG): - padl = ssz; - padr = col->width - term_strlen(tp, dp->string) - ssz; + padl = term_len(tp, 1); + padr -= padl; break; case (TBL_CELL_CENTRE): - padr = col->width - term_strlen(tp, dp->string); - if (3 > padr) + if (2 > padr) break; - padl = (padr - 1) / 2; + padl = padr / 2; padr -= padl; break; case (TBL_CELL_RIGHT): - padl = col->width - term_strlen(tp, dp->string); + padl = padr; + padr = 0; break; default: - padr = col->width - term_strlen(tp, dp->string); break; } tbl_char(tp, ASCII_NBRSP, padl); term_word(tp, dp->string); - tbl_char(tp, ASCII_NBRSP, padr + 2); + tbl_char(tp, ASCII_NBRSP, padr); } static void @@ -422,9 +436,6 @@ tbl_number(struct termp *tp, const struc d = ssz + psz; } else d = sz + psz; - - sz += term_len(tp, 2); - d += term_len(tp, 1); padl = col->decimal - d; -- To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv