source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: PostScript can now handle scaled glyph sizes (see "scale" in
@ 2010-06-30 13:00 kristaps
  2010-06-30 13:11 ` Kristaps Dzonsons
  0 siblings, 1 reply; 2+ messages in thread
From: kristaps @ 2010-06-30 13:00 UTC (permalink / raw)
  To: source

Log Message:
-----------
PostScript can now handle scaled glyph sizes (see "scale" in struct
termp_ps) to arbitrarily scale font.  Tested with 10 (default), 12, 14.

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.71
retrieving revision 1.72
diff -Lterm.h -Lterm.h -u -p -r1.71 -r1.72
--- term.h
+++ term.h
@@ -52,6 +52,7 @@ struct	termp_ps {
 	size_t		  psmargcur;	/* cur index in margin buf */
 	char		  last;		/* character buffer */
 	enum termfont	  lastf;	/* last set font */
+	size_t		  scale;	/* font scaling factor */
 	size_t		  pages;	/* number of pages shown */
 	size_t		  lineheight;	/* line height (AFM units) */
 	size_t		  top;		/* body top (AFM units) */
Index: term_ps.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ps.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.20 -r1.21
--- term_ps.c
+++ term_ps.c
@@ -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 termfon
 {
 
 	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 st
 	
 	/*
 	 * 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 * 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: mdocml: PostScript can now handle scaled glyph sizes (see "scale" in
  2010-06-30 13:00 mdocml: PostScript can now handle scaled glyph sizes (see "scale" in kristaps
@ 2010-06-30 13:11 ` Kristaps Dzonsons
  0 siblings, 0 replies; 2+ messages in thread
From: Kristaps Dzonsons @ 2010-06-30 13:11 UTC (permalink / raw)
  To: source

> Log Message:
> -----------
> PostScript can now handle scaled glyph sizes (see "scale" in struct
> termp_ps) to arbitrarily scale font.  Tested with 10 (default), 12, 14.

...and down to 8 and 6.  Little tiny manuals!  Hilarious.
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-06-30 13:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-30 13:00 mdocml: PostScript can now handle scaled glyph sizes (see "scale" in kristaps
2010-06-30 13:11 ` Kristaps Dzonsons

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