From: schwarze Date: Tue, 23 Dec 2014 06:16:21 +0000 (+0000) Subject: Fix vertical scaling. Obviously, nobody ever had a serious look at this. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=82de3b2c616f7eb5dd93bf423bcd6b7080b6001e;p=openbsd Fix vertical scaling. Obviously, nobody ever had a serious look at this. Basic units, centimeters, points, ens, ems, and the rounding algorithm were all wrong, only inches, pica, and the default vertical span worked. --- diff --git a/regress/usr.bin/mandoc/roff/sp/Makefile b/regress/usr.bin/mandoc/roff/sp/Makefile index 62e2b34001b..9e853e0da69 100644 --- a/regress/usr.bin/mandoc/roff/sp/Makefile +++ b/regress/usr.bin/mandoc/roff/sp/Makefile @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile,v 1.3 2012/07/13 14:15:50 schwarze Exp $ +# $OpenBSD: Makefile,v 1.4 2014/12/23 06:16:21 schwarze Exp $ -REGRESS_TARGETS = badargs-mdoc badargs-man negative +REGRESS_TARGETS = badargs-man badargs-mdoc negative scaling-man scaling-mdoc .include diff --git a/regress/usr.bin/mandoc/roff/sp/scaling-man.in b/regress/usr.bin/mandoc/roff/sp/scaling-man.in new file mode 100644 index 00000000000..69318ecafeb --- /dev/null +++ b/regress/usr.bin/mandoc/roff/sp/scaling-man.in @@ -0,0 +1,27 @@ +.TH SP-SCALING-MAN 1 "December 23, 2014" OpenBSD +.SH NAME +sp-scaling-man \- scaled arguments to .sp requests in man(7) +.SH DESCRIPTION +20 basic units: +.sp 20u +21 basic units: +.sp 21u +one centimeter: +.sp 1c +quarter of an inch: +.sp 0.25i +half a pica: +.sp 0.5P +one pica: +.sp 1P +6 points: +.sp 6p +7 points: +.sp 7p +one en: +.sp 1n +three en: +.sp 3n +two em: +.sp 2m +end of test document diff --git a/regress/usr.bin/mandoc/roff/sp/scaling-man.out_ascii b/regress/usr.bin/mandoc/roff/sp/scaling-man.out_ascii new file mode 100644 index 00000000000..72a0b53bcbd --- /dev/null +++ b/regress/usr.bin/mandoc/roff/sp/scaling-man.out_ascii @@ -0,0 +1,34 @@ +SP-SCALING-MAN(1) General Commands Manual SP-SCALING-MAN(1) + + + +NNAAMMEE + sp-scaling-man - scaled arguments to .sp requests in man(7) + +DDEESSCCRRIIPPTTIIOONN + 20 basic units: + 21 basic units: + + one centimeter: + + + quarter of an inch: + + half a pica: + one pica: + + 6 points: + 7 points: + + one en: + + three en: + + + two em: + + end of test document + + + +OpenBSD December 23, 2014 SP-SCALING-MAN(1) diff --git a/regress/usr.bin/mandoc/roff/sp/scaling-mdoc.in b/regress/usr.bin/mandoc/roff/sp/scaling-mdoc.in new file mode 100644 index 00000000000..ff4d45c76c8 --- /dev/null +++ b/regress/usr.bin/mandoc/roff/sp/scaling-mdoc.in @@ -0,0 +1,30 @@ +.Dd December 23, 2014 +.Dt SP-SCALING-MDOC 1 +.Os OpenBSD +.Sh NAME +.Nm sp-scaling-mdoc +.Nd scaled arguments to .sp requests in mdoc(7) +.Sh DESCRIPTION +20 basic units: +.sp 20u +21 basic units: +.sp 21u +one centimeter: +.sp 1c +quarter of an inch: +.sp 0.25i +half a pica: +.sp 0.5P +one pica: +.sp 1P +6 points: +.sp 6p +7 points: +.sp 7p +one en: +.sp 1n +three en: +.sp 3n +two em: +.sp 2m +end of test document diff --git a/regress/usr.bin/mandoc/roff/sp/scaling-mdoc.out_ascii b/regress/usr.bin/mandoc/roff/sp/scaling-mdoc.out_ascii new file mode 100644 index 00000000000..625ba7c4b1c --- /dev/null +++ b/regress/usr.bin/mandoc/roff/sp/scaling-mdoc.out_ascii @@ -0,0 +1,30 @@ +SP-SCALING-MDOC(1) General Commands Manual SP-SCALING-MDOC(1) + +NNAAMMEE + sspp--ssccaalliinngg--mmddoocc - scaled arguments to .sp requests in mdoc(7) + +DDEESSCCRRIIPPTTIIOONN + 20 basic units: + 21 basic units: + + one centimeter: + + + quarter of an inch: + + half a pica: + one pica: + + 6 points: + 7 points: + + one en: + + three en: + + + two em: + + end of test document + +OpenBSD December 23, 2014 OpenBSD diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index 79f02395ba1..1c69ca2417d 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.98 2014/12/19 17:10:42 schwarze Exp $ */ +/* $OpenBSD: term.c,v 1.99 2014/12/23 06:16:21 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -774,32 +774,43 @@ term_vspan(const struct termp *p, const struct roffsu *su) double r; switch (su->unit) { + case SCALE_BU: + r = su->scale / 40.0; + break; case SCALE_CM: - r = su->scale * 2.0; + r = su->scale * 6.0 / 2.54; + break; + case SCALE_FS: + r = su->scale * 65536.0 / 40.0; break; case SCALE_IN: r = su->scale * 6.0; break; + case SCALE_MM: + r = su->scale * 0.006; + break; case SCALE_PC: r = su->scale; break; case SCALE_PT: - r = su->scale / 8.0; + r = su->scale / 12.0; break; - case SCALE_MM: - r = su->scale / 1000.0; + case SCALE_EN: + /* FALLTHROUGH */ + case SCALE_EM: + r = su->scale * 0.6; break; case SCALE_VS: r = su->scale; break; default: - r = su->scale - 1.0; - break; + abort(); + /* NOTREACHED */ } if (r < 0.0) r = 0.0; - return((size_t)(r + 0.0005)); + return((size_t)(r + 0.4995)); } size_t