discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: discuss@mdocml.bsd.lv
Subject: Re: tbl issues with 1.11.1
Date: Sat, 14 May 2011 06:12:28 +0200	[thread overview]
Message-ID: <20110514041228.GA30797@iris.usta.de> (raw)
In-Reply-To: <4DCD9CA4.2060708@bsd.lv>

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

  reply	other threads:[~2011-05-14  4:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-14  1:45 Yuri Pankov
2011-04-16 21:34 ` Ingo Schwarze
2011-04-26 20:10   ` Joerg Sonnenberger
2011-05-12 22:02     ` Joerg Sonnenberger
2011-05-13 21:03       ` Kristaps Dzonsons
2011-05-14  4:12         ` Ingo Schwarze [this message]
2011-09-12 20:11           ` Yuri Pankov
2011-09-18 17:25             ` Yuri Pankov
2011-04-17  0:12 ` Joerg Sonnenberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110514041228.GA30797@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=discuss@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).