source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: fix column width calculation for text block cells
@ 2017-06-12 20:14 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-06-12 20:14 UTC (permalink / raw)
  To: source

Log Message:
-----------
fix column width calculation for text block cells

Modified Files:
--------------
    mdocml:
        out.c
        out.h
        tbl_html.c
        tbl_term.c

Revision Data
-------------
Index: out.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/out.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -Lout.h -Lout.h -u -p -r1.29 -r1.30
--- out.h
+++ out.h
@@ -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);
Index: tbl_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/tbl_term.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -Ltbl_term.c -Ltbl_term.c -u -p -r1.47 -r1.48
--- tbl_term.c
+++ tbl_term.c
@@ -87,7 +87,7 @@ term_tbl(struct termp *tp, const struct 
 		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. */
 
Index: out.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/out.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -Lout.c -Lout.c -u -p -r1.65 -r1.66
--- out.c
+++ out.c
@@ -105,7 +105,7 @@ a2roffsu(const char *src, struct roffsu 
  */
 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 struc
 				    (*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 struc
 				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 struc
 	 * 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, str
 	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, str
 			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);
Index: tbl_html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/tbl_html.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -Ltbl_html.c -Ltbl_html.c -u -p -r1.21 -r1.22
--- tbl_html.c
+++ tbl_html.c
@@ -83,7 +83,7 @@ html_tblopen(struct html *h, const struc
 		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);
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-06-12 20:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-12 20:14 mdocml: fix column width calculation for text block cells schwarze

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).