source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Clean-up of variable-width glyph support.
@ 2010-06-28 23:26 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-06-28 23:26 UTC (permalink / raw)
  To: source

Log Message:
-----------
Clean-up of variable-width glyph support.  Adds no new code; only
restructured to make a bit more readable.  Also removed an unused entry
in the PS engine structure.

Modified Files:
--------------
    mdocml:
        term.c
        term.h
        term_ps.c

Revision Data
-------------
Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.153
retrieving revision 1.154
diff -Lterm.c -Lterm.c -u -p -r1.153 -r1.154
--- term.c
+++ term.c
@@ -161,21 +161,17 @@ term_flushln(struct termp *p)
 	 */
 	vbl = p->flags & TERMP_NOLPAD ? 0 : p->offset;
 
-	/* 
-	 * FIXME: if bp is zero, we still output the first word before
-	 * breaking the line.
-	 */
-
 	vis = vend = i = 0;
-	while (i < (int)p->col) {
 
+	while (i < (int)p->col) {
 		/*
-		 * Handle literal tab characters.
+		 * Handle literal tab characters: collapse all
+		 * subsequent tabs into a single huge set of spaces.
 		 */
 		for (j = i; j < (int)p->col; j++) {
 			if ('\t' != p->buf[j])
 				break;
-			vend = (vis/p->tabwidth+1)*p->tabwidth;
+			vend = (vis / p->tabwidth + 1) * p->tabwidth;
 			vbl += vend - vis;
 			vis = vend;
 		}
@@ -191,15 +187,21 @@ term_flushln(struct termp *p)
 		for (jhy = 0; j < (int)p->col; j++) {
 			if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j])
 				break;
-			if (8 != p->buf[j]) {
-				if (vend > vis && vend < bp &&
-				    ASCII_HYPH == p->buf[j])
-					jhy = j;
-				vend += (*p->width)(p, p->buf[j]);
-			} else {
+
+			/* Back over the the last printed character. */
+			if (8 == p->buf[j]) {
 				assert(j);
 				vend -= (*p->width)(p, p->buf[j - 1]);
+				continue;
 			}
+
+			/* Regular word. */
+			/* Break at the hyphen point if we overrun. */
+			if (vend > vis && vend < bp && 
+					ASCII_HYPH == p->buf[j])
+				jhy = j;
+
+			vend += (*p->width)(p, p->buf[j]);
 		}
 
 		/*
@@ -308,7 +310,8 @@ term_flushln(struct termp *p)
 
 	/* Right-pad. */
 	if (maxvis > vis + /* LINTED */
-			((TERMP_TWOSPACE & p->flags) ? (*p->width)(p, ' ') : 0)) {
+			((TERMP_TWOSPACE & p->flags) ? 
+			 (*p->width)(p, ' ') : 0)) {
 		p->viscol += maxvis - vis;
 		(*p->advance)(p, maxvis - vis);
 		vis += (maxvis - vis);
Index: term.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.h,v
retrieving revision 1.66
retrieving revision 1.67
diff -Lterm.h -Lterm.h -u -p -r1.66 -r1.67
--- term.h
+++ term.h
@@ -49,7 +49,6 @@ struct	termp_ps {
 	char		 *psmarg;	/* margin buf */
 	size_t		  psmargsz;	/* margin buf size */
 	size_t		  psmargcur;	/* current pos in margin buf */
-	size_t	 	  pspage;	/* current page */
 	char		  last;		/* character buffer */
 	enum termfont	  lastf;	/* last set font */
 };
Index: term_ps.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ps.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.14 -r1.15
--- term_ps.c
+++ term_ps.c
@@ -31,14 +31,21 @@
 #include "main.h"
 #include "term.h"
 
+/* TODO: all this will go away with different paper sizes. */
+#define	PS_CHAR_HEIGHT	  12
+#define	PS_CHAR_TOPMARG	 (792 - 24)
+#define	PS_CHAR_TOP	 (PS_CHAR_TOPMARG - 36)
+#define	PS_CHAR_LEFT	  36
+#define	PS_CHAR_BOTMARG	  24
+#define	PS_CHAR_BOT	 (PS_CHAR_BOTMARG + 36)
+
 struct	glyph {
 	int		  wx; /* WX in AFM */
 };
 
-#define	MAXCHAR		  95
-
 struct	font {
 	const char	 *name; /* FontName in AFM */
+#define	MAXCHAR		  95 /* total characters we can handle */
 	struct glyph	  gly[MAXCHAR]; /* glyph metrics */
 };
 
@@ -342,13 +349,7 @@ static	const struct font fonts[3] = {
 	} },
 };
 
-#define	PS_CHAR_HEIGHT	  12
-#define	PS_CHAR_TOPMARG	 (792 - 24)
-#define	PS_CHAR_TOP	 (PS_CHAR_TOPMARG - 36)
-#define	PS_CHAR_LEFT	  36
-#define	PS_CHAR_BOTMARG	  24
-#define	PS_CHAR_BOT	 (PS_CHAR_BOTMARG + 36)
-
+/* These work the buffer used by the header and footer. */
 #define	PS_BUFSLOP	  128
 #define	PS_GROWBUF(p, sz) \
 	do if ((p)->engine.ps.psmargcur + (sz) > \
@@ -388,6 +389,7 @@ ps_alloc(void)
 		return(NULL);
 
 	p->defrmargin = 612 - (PS_CHAR_LEFT * 2);
+
 	p->type = TERMTYPE_PS;
 	p->letter = ps_letter;
 	p->begin = ps_begin;
--
 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:[~2010-06-28 23:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-28 23:26 mdocml: Clean-up of variable-width glyph support kristaps

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