From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id o5UCRuIS016504 for ; Wed, 30 Jun 2010 08:27:56 -0400 (EDT) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.3/8.14.3/Submit) id o5UCRt8T000445; Wed, 30 Jun 2010 08:27:55 -0400 (EDT) Date: Wed, 30 Jun 2010 08:27:55 -0400 (EDT) Message-Id: <201006301227.o5UCRt8T000445@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Move term_hspan() calculation into the output devices, where it X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Move term_hspan() calculation into the output devices, where it belongs. Modified Files: -------------- mdocml: term.c term.h term_ascii.c term_ps.c Revision Data ------------- Index: term.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v retrieving revision 1.154 retrieving revision 1.155 diff -Lterm.c -Lterm.c -u -p -r1.154 -r1.155 --- term.c +++ term.c @@ -692,39 +692,6 @@ term_vspan(const struct termp *p, const size_t term_hspan(const struct termp *p, const struct roffsu *su) { - double r; - /* XXX: CM, IN, and PT are approximations. */ - - switch (su->unit) { - case (SCALE_CM): - r = 4 * su->scale; - break; - case (SCALE_IN): - /* XXX: this is an approximation. */ - r = 10 * su->scale; - break; - case (SCALE_PC): - r = (10 * su->scale) / 6; - break; - case (SCALE_PT): - r = (10 * su->scale) / 72; - break; - case (SCALE_MM): - r = su->scale / 1000; /* FIXME: double-check. */ - break; - case (SCALE_VS): - r = su->scale * 2 - 1; /* FIXME: double-check. */ - break; - default: - r = su->scale; - break; - } - - if (r < 0.0) - r = 0.0; - return((size_t)/* LINTED */ - r); + return((*p->hspan)(p, su)); } - - Index: term.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.h,v retrieving revision 1.69 retrieving revision 1.70 diff -Lterm.h -Lterm.h -u -p -r1.69 -r1.70 --- term.h +++ term.h @@ -103,6 +103,8 @@ struct termp { void (*endline)(struct termp *); void (*advance)(struct termp *, size_t); size_t (*width)(const struct termp *, char); + size_t (*hspan)(const struct termp *, + const struct roffsu *); const void *argf; /* arg for headf/footf */ union { struct termp_ps ps; Index: term_ascii.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ascii.c,v retrieving revision 1.6 retrieving revision 1.7 diff -Lterm_ascii.c -Lterm_ascii.c -u -p -r1.6 -r1.7 --- term_ascii.c +++ term_ascii.c @@ -30,12 +30,14 @@ #include "term.h" #include "main.h" -static void ascii_endline(struct termp *); -static void ascii_letter(struct termp *, char); -static void ascii_begin(struct termp *); +static size_t ascii_hspan(const struct termp *, + const struct roffsu *); +static size_t ascii_width(const struct termp *, char); static void ascii_advance(struct termp *, size_t); +static void ascii_begin(struct termp *); static void ascii_end(struct termp *); -static size_t ascii_width(const struct termp *, char); +static void ascii_endline(struct termp *); +static void ascii_letter(struct termp *, char); void * @@ -51,12 +53,13 @@ ascii_alloc(char *outopts) p->tabwidth = 5; p->defrmargin = 78; - p->type = TERMTYPE_CHAR; - p->letter = ascii_letter; + p->advance = ascii_advance; p->begin = ascii_begin; p->end = ascii_end; p->endline = ascii_endline; - p->advance = ascii_advance; + p->hspan = ascii_hspan; + p->letter = ascii_letter; + p->type = TERMTYPE_CHAR; p->width = ascii_width; toks[0] = "width"; @@ -140,3 +143,49 @@ ascii_advance(struct termp *p, size_t le for (i = 0; i < len; i++) putchar(' '); } + + +/* ARGSUSED */ +static size_t +ascii_hspan(const struct termp *p, const struct roffsu *su) +{ + double r; + + /* + * Approximate based on character width. These are generated + * entirely by eyeballing the screen, but appear to be correct. + */ + + switch (su->unit) { + case (SCALE_CM): + r = 4 * su->scale; + break; + case (SCALE_IN): + r = 10 * su->scale; + break; + case (SCALE_PC): + r = (10 * su->scale) / 6; + break; + case (SCALE_PT): + r = (10 * su->scale) / 72; + break; + case (SCALE_MM): + r = su->scale / 1000; + break; + case (SCALE_VS): + r = su->scale * 2 - 1; + break; + default: + r = su->scale; + break; + } + + /* Explicitly disallow negative values. */ + + if (r < 0.0) + r = 0.0; + + return((size_t)/* LINTED */ + r); +} + Index: term_ps.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ps.c,v retrieving revision 1.18 retrieving revision 1.19 diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.18 -r1.19 --- term_ps.c +++ term_ps.c @@ -359,13 +359,15 @@ static const struct font fonts[TERMFONT_ } while (/* CONSTCOND */ 0) -static void ps_letter(struct termp *, char); +static size_t ps_hspan(const struct termp *, + const struct roffsu *); +static size_t ps_width(const struct termp *, char); +static void ps_advance(struct termp *, size_t); static void ps_begin(struct termp *); static void ps_end(struct termp *); -static void ps_advance(struct termp *, size_t); static void ps_endline(struct termp *); static void ps_fclose(struct termp *); -static size_t ps_width(const struct termp *, char); +static void ps_letter(struct termp *, char); static void ps_pclose(struct termp *); static void ps_pletter(struct termp *, int); static void ps_printf(struct termp *, const char *, ...); @@ -385,17 +387,20 @@ ps_alloc(char *outopts) if (NULL == (p = term_alloc(TERMENC_ASCII))) return(NULL); - p->type = TERMTYPE_PS; - p->letter = ps_letter; + p->advance = ps_advance; p->begin = ps_begin; p->end = ps_end; - p->advance = ps_advance; p->endline = ps_endline; + p->hspan = ps_hspan; + p->letter = ps_letter; + p->type = TERMTYPE_PS; p->width = ps_width; toks[0] = "paper"; toks[1] = NULL; + paper = "letter"; + while (outopts && *outopts) switch (getsubopt(&outopts, UNCONST(toks), &v)) { case (0): @@ -821,3 +826,57 @@ ps_width(const struct termp *p, char c) c -= 32; return(fonts[(int)TERMFONT_NONE].gly[(int)c].wx); } + + +static size_t +ps_hspan(const struct termp *p, const struct roffsu *su) +{ + double r; + + /* + * 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). + */ + + switch (su->unit) { + case (SCALE_CM): + r = su->scale * 28.34 * 100; + break; + case (SCALE_IN): + r = su->scale * 72 * 100; + break; + case (SCALE_PC): + r = su->scale * 12 * 100; + break; + case (SCALE_PT): + r = 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; + break; + case (SCALE_EN): + r = su->scale * + fonts[(int)TERMFONT_NONE].gly[110 - 32].wx; + break; + case (SCALE_VS): + r = su->scale * p->engine.ps.lineheight; + break; + default: + r = su->scale; + break; + } + + /* Explicitly disallow negative values. */ + + if (r < 0.0) + r = 0.0; + + return((size_t)/* LINTED */ + r); +} + -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv