diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2010-06-30 11:45:21 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2010-06-30 11:45:21 +0000 |
commit | dcf50a690b6571696456b49bcbccad413234f421 (patch) | |
tree | b7828637f233273bd0493f248eb0d230c9dc30e0 | |
parent | 25b3bcbde4cab98bd4a3175d20053187201d2dce (diff) | |
download | mandoc-dcf50a690b6571696456b49bcbccad413234f421.tar.gz |
Push paper calculation out of getsubopt() loop. Make all points be AFM
glyph units to make positioning more precise.
-rw-r--r-- | term.h | 20 | ||||
-rw-r--r-- | term_ps.c | 41 |
2 files changed, 31 insertions, 30 deletions
@@ -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 { @@ -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); } |