source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Push paper calculation out of getsubopt() loop.
@ 2010-06-30 11:45 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-06-30 11:45 UTC (permalink / raw)
  To: source

Log Message:
-----------
Push paper calculation out of getsubopt() loop.  Make all points be AFM
glyph units to make positioning more precise.

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

Revision Data
-------------
Index: term.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.h,v
retrieving revision 1.68
retrieving revision 1.69
diff -Lterm.h -Lterm.h -u -p -r1.68 -r1.69
--- term.h
+++ term.h
@@ -45,22 +45,22 @@ struct	termp_ps {
 	int		  psstate;	/* state of ps output */
 #define	PS_INLINE	 (1 << 0)	/* we're in a word */
 #define	PS_MARGINS	 (1 << 1)	/* we're in the margins */
-	size_t		  pscol;	/* visible column (points) */
-	size_t		  psrow;	/* visible row (points) */
+	size_t		  pscol;	/* visible column (AFM units) */
+	size_t		  psrow;	/* visible row (AFM units) */
 	char		 *psmarg;	/* margin buf */
 	size_t		  psmargsz;	/* margin buf size */
 	size_t		  psmargcur;	/* cur index in margin buf */
 	char		  last;		/* character buffer */
 	enum termfont	  lastf;	/* last set font */
 	size_t		  pages;	/* number of pages shown */
-	size_t		  lineheight;	/* each line's height (points) */
-	size_t		  top;		/* body top (points) */
-	size_t		  bottom;	/* body bottom (points) */
-	size_t		  height;	/* total height (points) */
-	size_t		  width;	/* total width (points) */
-	size_t		  left;		/* body left (points) */
-	size_t		  header;	/* header position (points) */
-	size_t		  footer;	/* footer position (points) */
+	size_t		  lineheight;	/* line height (AFM units) */
+	size_t		  top;		/* body top (AFM units) */
+	size_t		  bottom;	/* body bottom (AFM units) */
+	size_t		  height;	/* page height (AFM units */
+	size_t		  width;	/* page width (AFM units) */
+	size_t		  left;		/* body left (AFM units) */
+	size_t		  header;	/* header pos (AFM units) */
+	size_t		  footer;	/* footer pos (AFM units) */
 };
 
 struct	termp {
Index: term_ps.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ps.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.17 -r1.18
--- term_ps.c
+++ term_ps.c
@@ -377,18 +377,14 @@ void *
 ps_alloc(char *outopts)
 {
 	struct termp	*p;
-	size_t		 pagex, pagey, margin;
+	size_t		 pagex, pagey, margin, lineheight;
 	const char	*toks[2];
+	const char	*paper;
 	char		*v;
 
 	if (NULL == (p = term_alloc(TERMENC_ASCII)))
 		return(NULL);
 
-	/* Default is USA letter. */
-	pagex = 612;
-	pagey = 792;
-	margin = 72;
-
 	p->type = TERMTYPE_PS;
 	p->letter = ps_letter;
 	p->begin = ps_begin;
@@ -403,18 +399,23 @@ ps_alloc(char *outopts)
 	while (outopts && *outopts)
 		switch (getsubopt(&outopts, UNCONST(toks), &v)) {
 		case (0):
-			if (0 == strcasecmp(v, "a4")) {
-				pagex = 595;
-				pagey = 842;
-			} else if (0 == strcasecmp(v, "letter")) {
-				pagex = 612;
-				pagey = 792;
-			}
+			paper = v;
 			break;
 		default:
 			break;
 		}
 
+	if (0 == strcasecmp(paper, "a4")) {
+		pagex = 595 * 100;
+		pagey = 842 * 100;
+	} else {
+		pagex = 612 * 100;
+		pagey = 792 * 100;
+	}
+
+	margin = 72 * 100;
+	lineheight = 12 * 100;
+
 	assert(margin * 2 < pagex);
 	assert(margin * 2 < pagey);
 
@@ -425,7 +426,7 @@ ps_alloc(char *outopts)
 	p->engine.ps.footer = (margin / 2);
 	p->engine.ps.bottom = margin;
 	p->engine.ps.left = margin;
-	p->engine.ps.lineheight = 12;
+	p->engine.ps.lineheight = lineheight;
 
 	p->defrmargin = pagex - (margin * 2);
 	return(p);
@@ -609,8 +610,8 @@ ps_pletter(struct termp *p, int c)
 
 	if ( ! (PS_INLINE & p->engine.ps.psstate)) {
 		ps_printf(p, "%zu %zu moveto\n(", 
-				p->engine.ps.pscol, 
-				p->engine.ps.psrow);
+				(size_t)(p->engine.ps.pscol / 100), 
+				(size_t)(p->engine.ps.psrow / 100));
 		p->engine.ps.psstate |= PS_INLINE;
 	}
 
@@ -639,13 +640,13 @@ ps_pletter(struct termp *p, int c)
 
 	if (c <= 32 || (c - 32 > MAXCHAR)) {
 		ps_putchar(p, ' ');
-		p->engine.ps.pscol += (fonts[f].gly[0].wx / 100);
+		p->engine.ps.pscol += fonts[f].gly[0].wx;
 		return;
 	} 
 
 	ps_putchar(p, c);
 	c -= 32;
-	p->engine.ps.pscol += (fonts[f].gly[c].wx / 100);
+	p->engine.ps.pscol += fonts[f].gly[c].wx;
 }
 
 
@@ -815,8 +816,8 @@ ps_width(const struct termp *p, char c)
 {
 
 	if (c <= 32 || c - 32 >= MAXCHAR)
-		return(fonts[(int)TERMFONT_NONE].gly[0].wx / 100);
+		return(fonts[(int)TERMFONT_NONE].gly[0].wx);
 
 	c -= 32;
-	return(fonts[(int)TERMFONT_NONE].gly[(int)c].wx / 100);
+	return(fonts[(int)TERMFONT_NONE].gly[(int)c].wx);
 }
--
 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-30 11:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-30 11:45 mdocml: Push paper calculation out of getsubopt() loop 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).