diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/man_term.c | 12 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_term.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/term.c | 12 | ||||
-rw-r--r-- | usr.bin/mandoc/term.h | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/term_ascii.c | 44 | ||||
-rw-r--r-- | usr.bin/mandoc/term_ps.c | 16 |
6 files changed, 44 insertions, 50 deletions
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index 1314cd519a5..d59762f34a7 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_term.c,v 1.127 2015/04/04 11:43:53 schwarze Exp $ */ +/* $OpenBSD: man_term.c,v 1.128 2015/04/04 17:46:58 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -425,7 +425,7 @@ pre_in(DECL_ARGS) if ( ! a2roffsu(++cp, &su, SCALE_EN)) return(0); - v = term_hspan(p, &su); + v = (term_hspan(p, &su) + 11) / 24; if (less < 0) p->offset -= p->offset > v ? v : p->offset; @@ -510,7 +510,7 @@ pre_HP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && a2roffsu(nn->string, &su, SCALE_EN)) { - len = term_hspan(p, &su); + len = term_hspan(p, &su) / 24; if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -595,7 +595,7 @@ pre_IP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && (nn = nn->next) != NULL && a2roffsu(nn->string, &su, SCALE_EN)) { - len = term_hspan(p, &su); + len = term_hspan(p, &su) / 24; if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -677,7 +677,7 @@ pre_TP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && nn->string != NULL && ! (MAN_LINE & nn->flags) && a2roffsu(nn->string, &su, SCALE_EN)) { - len = term_hspan(p, &su); + len = term_hspan(p, &su) / 24; if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -866,7 +866,7 @@ pre_RS(DECL_ARGS) n = n->parent->head; n->aux = SHRT_MAX + 1; if (n->child != NULL && a2roffsu(n->child->string, &su, SCALE_EN)) - n->aux = term_hspan(p, &su); + n->aux = term_hspan(p, &su) / 24; if (n->aux < 0 && (size_t)(-n->aux) > mt->offset) n->aux = -mt->offset; else if (n->aux > SHRT_MAX) diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index a55fd47a1ce..901a3c1a961 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_term.c,v 1.215 2015/04/02 23:47:43 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.216 2015/04/04 17:46:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -531,7 +531,7 @@ a2width(const struct termp *p, const char *v) SCALE_HS_INIT(&su, term_strlen(p, v)); su.scale /= term_strlen(p, "0"); } - return(term_hspan(p, &su)); + return(term_hspan(p, &su) / 24); } /* diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index dce82c28501..9e6ee91a392 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.106 2015/04/02 23:47:43 schwarze Exp $ */ +/* $OpenBSD: term.c,v 1.107 2015/04/04 17:46:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -617,8 +617,7 @@ void term_setwidth(struct termp *p, const char *wstr) { struct roffsu su; - size_t width; - int iop; + int iop, width; iop = 0; width = 0; @@ -829,11 +828,12 @@ term_vspan(const struct termp *p, const struct roffsu *su) return(ri < 66 ? ri : 1); } +/* + * Convert a scaling width to basic units, rounding down. + */ int term_hspan(const struct termp *p, const struct roffsu *su) { - double v; - v = (*p->hspan)(p, su); - return(v > 0.0 ? v + 0.0005 : v - 0.0005); + return((*p->hspan)(p, su)); } diff --git a/usr.bin/mandoc/term.h b/usr.bin/mandoc/term.h index ea080580a22..9a677c7b37a 100644 --- a/usr.bin/mandoc/term.h +++ b/usr.bin/mandoc/term.h @@ -1,4 +1,4 @@ -/* $OpenBSD: term.h,v 1.56 2015/04/02 23:47:43 schwarze Exp $ */ +/* $OpenBSD: term.h,v 1.57 2015/04/04 17:46:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -95,9 +95,9 @@ struct termp { void (*end)(struct termp *); void (*endline)(struct termp *); void (*advance)(struct termp *, size_t); - void (*setwidth)(struct termp *, int, size_t); + void (*setwidth)(struct termp *, int, int); size_t (*width)(const struct termp *, int); - double (*hspan)(const struct termp *, + int (*hspan)(const struct termp *, const struct roffsu *); const void *argf; /* arg for headf/footf */ struct termp_ps *ps; diff --git a/usr.bin/mandoc/term_ascii.c b/usr.bin/mandoc/term_ascii.c index 31f2f4e6d05..144c335fc81 100644 --- a/usr.bin/mandoc/term_ascii.c +++ b/usr.bin/mandoc/term_ascii.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term_ascii.c,v 1.31 2015/03/27 21:17:16 schwarze Exp $ */ +/* $OpenBSD: term_ascii.c,v 1.32 2015/04/04 17:46:58 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -34,7 +34,7 @@ static struct termp *ascii_init(enum termenc, const struct mchars *, const struct manoutput *); -static double ascii_hspan(const struct termp *, +static int ascii_hspan(const struct termp *, const struct roffsu *); static size_t ascii_width(const struct termp *, int); static void ascii_advance(struct termp *, size_t); @@ -42,7 +42,7 @@ static void ascii_begin(struct termp *); static void ascii_end(struct termp *); static void ascii_endline(struct termp *); static void ascii_letter(struct termp *, int); -static void ascii_setwidth(struct termp *, int, size_t); +static void ascii_setwidth(struct termp *, int, int); static void locale_advance(struct termp *, size_t); static void locale_endline(struct termp *); @@ -127,15 +127,16 @@ locale_alloc(const struct mchars *mchars, const struct manoutput *outopts) } static void -ascii_setwidth(struct termp *p, int iop, size_t width) +ascii_setwidth(struct termp *p, int iop, int width) { + width /= 24; p->rmargin = p->defrmargin; if (iop > 0) p->defrmargin += width; else if (iop == 0) - p->defrmargin = width ? width : p->lastrmargin; - else if (p->defrmargin > width) + p->defrmargin = width ? (size_t)width : p->lastrmargin; + else if (p->defrmargin > (size_t)width) p->defrmargin -= width; else p->defrmargin = 0; @@ -208,52 +209,45 @@ ascii_advance(struct termp *p, size_t len) putchar(' '); } -static double +static int ascii_hspan(const struct termp *p, const struct roffsu *su) { double r; - /* - * Approximate based on character width. - * None of these will be actually correct given that an inch on - * the screen depends on character size, terminal, etc., etc. - */ switch (su->unit) { case SCALE_BU: - r = su->scale * 10.0 / 240.0; + r = su->scale; break; case SCALE_CM: - r = su->scale * 10.0 / 2.54; + r = su->scale * 240.0 / 2.54; break; case SCALE_FS: - r = su->scale * 2730.666; + r = su->scale * 65536.0; break; case SCALE_IN: - r = su->scale * 10.0; + r = su->scale * 240.0; break; case SCALE_MM: - r = su->scale / 100.0; + r = su->scale * 0.24; break; + case SCALE_VS: + /* FALLTHROUGH */ case SCALE_PC: - r = su->scale * 10.0 / 6.0; + r = su->scale * 40.0; break; case SCALE_PT: - r = su->scale * 10.0 / 72.0; - break; - case SCALE_VS: - r = su->scale * 2.0 - 1.0; + r = su->scale * 10.0 / 3.0; break; case SCALE_EN: /* FALLTHROUGH */ case SCALE_EM: - r = su->scale; + r = su->scale * 24.0; break; default: abort(); /* NOTREACHED */ } - - return(r); + return(r > 0.0 ? r + 0.01 : r - 0.01); } const char * diff --git a/usr.bin/mandoc/term_ps.c b/usr.bin/mandoc/term_ps.c index 95d76f8f1a9..d40133171b5 100644 --- a/usr.bin/mandoc/term_ps.c +++ b/usr.bin/mandoc/term_ps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term_ps.c,v 1.38 2015/03/27 21:17:16 schwarze Exp $ */ +/* $OpenBSD: term_ps.c,v 1.39 2015/04/04 17:46:58 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -85,7 +85,7 @@ struct termp_ps { size_t pdfobjsz; /* size of pdfobjs */ }; -static double ps_hspan(const struct termp *, +static int ps_hspan(const struct termp *, const struct roffsu *); static size_t ps_width(const struct termp *, int); static void ps_advance(struct termp *, size_t); @@ -101,7 +101,7 @@ static void ps_pletter(struct termp *, int); static void ps_printf(struct termp *, const char *, ...); static void ps_putchar(struct termp *, char); static void ps_setfont(struct termp *, enum termfont); -static void ps_setwidth(struct termp *, int, size_t); +static void ps_setwidth(struct termp *, int, int); static struct termp *pspdf_alloc(const struct mchars *, const struct manoutput *); static void pdf_obj(struct termp *, size_t); @@ -615,7 +615,7 @@ pspdf_alloc(const struct mchars *mchars, const struct manoutput *outopts) } static void -ps_setwidth(struct termp *p, int iop, size_t width) +ps_setwidth(struct termp *p, int iop, int width) { size_t lastwidth; @@ -623,8 +623,8 @@ ps_setwidth(struct termp *p, int iop, size_t width) if (iop > 0) p->ps->width += width; else if (iop == 0) - p->ps->width = width ? width : p->ps->lastwidth; - else if (p->ps->width > width) + p->ps->width = width ? (size_t)width : p->ps->lastwidth; + else if (p->ps->width > (size_t)width) p->ps->width -= width; else p->ps->width = 0; @@ -1268,7 +1268,7 @@ ps_width(const struct termp *p, int c) return((size_t)fonts[(int)TERMFONT_NONE].gly[c].wx); } -static double +static int ps_hspan(const struct termp *p, const struct roffsu *su) { double r; @@ -1320,7 +1320,7 @@ ps_hspan(const struct termp *p, const struct roffsu *su) break; } - return(r); + return(r * 24.0); } static void |