summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-07-01 14:23:45 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-07-01 14:23:45 +0000
commit24c6fa8ac2ce2f4beae4ada2ac4848432f34b668 (patch)
treeacaf74cb21e4ce890b9557ca6be1b8d0f1dfa9f4
parentcd0478c4c1c8072f32c673df44009c70e8a2c3a3 (diff)
downloadmandoc-24c6fa8ac2ce2f4beae4ada2ac4848432f34b668.tar.gz
First, I'm defaulting to 11-point font, which renders much nicer (the
"Internet" vaguely suggests using 11- or 9-Point for serifed fonts). This verified on GNU/Linux, Mac OSX, Windows, and OpenBSD. Noted in mandoc.1. Then added a3, a4, a5, letter, legal, and custom page dimensions. These seem to be the main players. Noted in mandoc.1. Lintified the casting.
-rw-r--r--mandoc.113
-rw-r--r--term_ps.c54
2 files changed, 51 insertions, 16 deletions
diff --git a/mandoc.1 b/mandoc.1
index 37cd3efd..f0737685 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -303,7 +303,7 @@ PostScript
Level-2 pages may be generated by
.Fl T Ns Cm ps .
Output pages default to letter sized and are rendered in the Times font
-family.
+family, 11-point.
.Pp
Special characters are rendered as in
.Sx ASCII Output .
@@ -316,9 +316,18 @@ arguments are accepted:
The paper size
.Ar name
may be one of
-.Ar a4
+.Ar a3 ,
+.Ar a4 ,
+.Ar a5 ,
+.Ar legal ,
or
.Ar letter .
+You may also manually specify dimensions as
+.Ar NNxNN ,
+width by height in millimetres.
+If an unknown value is encountered,
+.Ar letter
+is used.
.El
.Ss XHTML Output
Output produced by
diff --git a/term_ps.c b/term_ps.c
index 717be239..1852c3d7 100644
--- a/term_ps.c
+++ b/term_ps.c
@@ -33,15 +33,15 @@
#include "term.h"
/* Convert PostScript point "x" to an AFM unit. */
-#define PNT2AFM(p, x) \
+#define PNT2AFM(p, x) /* LINTED */ \
(size_t)((double)(x) * (1000.0 / (double)(p)->engine.ps.scale))
/* Convert an AFM unit "x" to a PostScript points */
-#define AFM2PNT(p, x) \
+#define AFM2PNT(p, x) /* LINTED */ \
(size_t)((double)(x) / (1000.0 / (double)(p)->engine.ps.scale))
struct glyph {
- int wx; /* WX in AFM */
+ size_t wx; /* WX in AFM */
};
struct font {
@@ -389,7 +389,7 @@ ps_alloc(char *outopts)
struct termp *p;
size_t pagex, pagey, margin, lineheight;
const char *toks[2];
- const char *paper;
+ const char *pp;
char *v;
if (NULL == (p = term_alloc(TERMENC_ASCII)))
@@ -404,17 +404,17 @@ ps_alloc(char *outopts)
p->type = TERMTYPE_PS;
p->width = ps_width;
- p->engine.ps.scale = 10;
+ p->engine.ps.scale = 11;
toks[0] = "paper";
toks[1] = NULL;
- paper = "letter";
+ pp = NULL;
while (outopts && *outopts)
switch (getsubopt(&outopts, UNCONST(toks), &v)) {
case (0):
- paper = v;
+ pp = v;
break;
default:
break;
@@ -423,14 +423,40 @@ ps_alloc(char *outopts)
margin = PNT2AFM(p, 72);
lineheight = PNT2AFM(p, 12);
- if (0 == strcasecmp(paper, "a4")) {
- pagex = PNT2AFM(p, 595);
- pagey = PNT2AFM(p, 842);
- } else {
- pagex = PNT2AFM(p, 612);
- pagey = PNT2AFM(p, 792);
+ /* Default to US letter (millimetres). */
+
+ pagex = 216;
+ pagey = 279;
+
+ /*
+ * The ISO-269 paper sizes can be calculated automatically, but
+ * it would require bringing in -lm for pow() and I'd rather not
+ * do that. So just do it the easy way for now. Since this
+ * only happens once, I'm not terribly concerned.
+ */
+
+ if (pp && strcasecmp(pp, "letter")) {
+ if (0 == strcasecmp(pp, "a3")) {
+ pagex = 297;
+ pagey = 420;
+ } else if (0 == strcasecmp(pp, "a4")) {
+ pagex = 210;
+ pagey = 297;
+ } else if (0 == strcasecmp(pp, "a5")) {
+ pagex = 148;
+ pagey = 210;
+ } else if (0 == strcasecmp(pp, "legal")) {
+ pagex = 216;
+ pagey = 356;
+ } else if (2 != sscanf(pp, "%zux%zu", &pagex, &pagey))
+ fprintf(stderr, "%s: Unknown paper\n", pp);
}
+ /* Remember millimetres -> AFM units. */
+
+ pagex = PNT2AFM(p, ((double)pagex * 2.834));
+ pagey = PNT2AFM(p, ((double)pagey * 2.834));
+
assert(margin * 2 < pagex);
assert(margin * 2 < pagey);
@@ -658,7 +684,7 @@ ps_pletter(struct termp *p, int c)
return;
}
- ps_putchar(p, c);
+ ps_putchar(p, (char)c);
c -= 32;
p->engine.ps.pscol += fonts[f].gly[c].wx;
}