diff options
-rw-r--r-- | term.c | 35 | ||||
-rw-r--r-- | term.h | 2 | ||||
-rw-r--r-- | term_ascii.c | 63 | ||||
-rw-r--r-- | term_ps.c | 71 |
4 files changed, 124 insertions, 47 deletions
@@ -692,39 +692,6 @@ term_vspan(const struct termp *p, const struct roffsu *su) 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)); } - - @@ -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; diff --git a/term_ascii.c b/term_ascii.c index da85aae4..fa19eb1b 100644 --- a/term_ascii.c +++ b/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 len) 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); +} + @@ -359,13 +359,15 @@ static const struct font fonts[TERMFONT__MAX] = { } 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); +} + |