From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: PostScript can now handle scaled glyph sizes (see "scale" in
Date: Wed, 30 Jun 2010 09:00:00 -0400 (EDT) [thread overview]
Message-ID: <201006301300.o5UD00IM001140@krisdoz.my.domain> (raw)
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
next reply other threads:[~2010-06-30 13:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-30 13:00 kristaps [this message]
2010-06-30 13:11 ` Kristaps Dzonsons
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201006301300.o5UD00IM001140@krisdoz.my.domain \
--to=kristaps@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).