summaryrefslogtreecommitdiffstatshomepage
path: root/term_ps.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-06-30 13:00:00 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-06-30 13:00:00 +0000
commita5999c0c13a2a8d3cc4f5efc4f8f977a0cc8d326 (patch)
tree9237e180442546e47a6443d2dc1db333e7ca82f1 /term_ps.c
parentdfaa88b92e98290528c2dec012e0186375a89b4a (diff)
downloadmandoc-a5999c0c13a2a8d3cc4f5efc4f8f977a0cc8d326.tar.gz
mandoc-a5999c0c13a2a8d3cc4f5efc4f8f977a0cc8d326.tar.zst
mandoc-a5999c0c13a2a8d3cc4f5efc4f8f977a0cc8d326.zip
PostScript can now handle scaled glyph sizes (see "scale" in struct
termp_ps) to arbitrarily scale font. Tested with 10 (default), 12, 14.
Diffstat (limited to 'term_ps.c')
-rw-r--r--term_ps.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/term_ps.c b/term_ps.c
index da5355ee..5c8c41bb 100644
--- a/term_ps.c
+++ b/term_ps.c
@@ -1,4 +1,4 @@
-/* $Id: term_ps.c,v 1.20 2010/06/30 12:30:36 kristaps Exp $ */
+/* $Id: term_ps.c,v 1.21 2010/06/30 13:00:00 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -32,6 +32,14 @@
#include "main.h"
#include "term.h"
+/* Convert PostScript point "x" to an AFM unit. */
+#define PNT2AFM(p, x) \
+ (size_t)((double)(x) * (1000.0 / (double)(p)->engine.ps.scale))
+
+/* Convert an AFM unit "x" to a PostScript points */
+#define AFM2PNT(p, x) \
+ (size_t)((double)(x) / (1000.0 / (double)(p)->engine.ps.scale))
+
struct glyph {
int wx; /* WX in AFM */
};
@@ -395,6 +403,8 @@ ps_alloc(char *outopts)
p->letter = ps_letter;
p->type = TERMTYPE_PS;
p->width = ps_width;
+
+ p->engine.ps.scale = 10;
toks[0] = "paper";
toks[1] = NULL;
@@ -410,17 +420,17 @@ ps_alloc(char *outopts)
break;
}
+ margin = PNT2AFM(p, 72);
+ lineheight = PNT2AFM(p, 12);
+
if (0 == strcasecmp(paper, "a4")) {
- pagex = 595 * 100;
- pagey = 842 * 100;
+ pagex = PNT2AFM(p, 595);
+ pagey = PNT2AFM(p, 842);
} else {
- pagex = 612 * 100;
- pagey = 792 * 100;
+ pagex = PNT2AFM(p, 612);
+ pagey = PNT2AFM(p, 792);
}
- margin = 72 * 100;
- lineheight = 12 * 100;
-
assert(margin * 2 < pagex);
assert(margin * 2 < pagey);
@@ -615,8 +625,8 @@ ps_pletter(struct termp *p, int c)
if ( ! (PS_INLINE & p->engine.ps.psstate)) {
ps_printf(p, "%zu %zu moveto\n(",
- (size_t)(p->engine.ps.pscol / 100),
- (size_t)(p->engine.ps.psrow / 100));
+ AFM2PNT(p, p->engine.ps.pscol),
+ AFM2PNT(p, p->engine.ps.psrow));
p->engine.ps.psstate |= PS_INLINE;
}
@@ -810,7 +820,8 @@ ps_setfont(struct termp *p, enum termfont f)
{
assert(f < TERMFONT__MAX);
- ps_printf(p, "/%s 10 selectfont\n", fonts[(int)f].name);
+ ps_printf(p, "/%s %zu selectfont\n",
+ fonts[(int)f].name, p->engine.ps.scale);
p->engine.ps.lastf = f;
}
@@ -835,29 +846,28 @@ ps_hspan(const struct termp *p, const struct roffsu *su)
/*
* All of these measurements are derived by converting from the
- * native measurement to AFM units, which are (scalesize/1000).
- * Since scalesize is 10 for us, we can just skip to (x/100).
+ * native measurement to AFM units.
*/
switch (su->unit) {
case (SCALE_CM):
- r = su->scale * 28.34 * 100;
+ r = PNT2AFM(p, su->scale * 28.34);
break;
case (SCALE_IN):
- r = su->scale * 72 * 100;
+ r = PNT2AFM(p, su->scale * 72);
break;
case (SCALE_PC):
- r = su->scale * 12 * 100;
+ r = PNT2AFM(p, su->scale * 12);
break;
case (SCALE_PT):
- r = su->scale * 100;
+ r = PNT2AFM(p, su->scale * 100);
break;
case (SCALE_EM):
r = su->scale *
fonts[(int)TERMFONT_NONE].gly[109 - 32].wx;
break;
case (SCALE_MM):
- r = su->scale * 2.834 * 100;
+ r = PNT2AFM(p, su->scale * 2.834);
break;
case (SCALE_EN):
r = su->scale *