source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Begin cleaning up scaling units.
Date: Wed, 13 Aug 2014 16:34:29 -0400 (EDT)	[thread overview]
Message-ID: <201408132034.s7DKYTAT030019@krisdoz.my.domain> (raw)

Log Message:
-----------
Begin cleaning up scaling units.
Start with the horizontal terminal specifiers, making sure that they match
up with troff.
Then move on to PS, PDF, and HTML, noting that we stick to the terminal 
default width for "u".
Lastly, fix some completely-wrong documentation and note that we diverge
from troff w/r/t "u".

Modified Files:
--------------
    mdocml:
        html.c
        roff.7
        term_ascii.c
        term_ps.c

Revision Data
-------------
Index: roff.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.7,v
retrieving revision 1.55
retrieving revision 1.56
diff -Lroff.7 -Lroff.7 -u -p -r1.55 -r1.56
--- roff.7
+++ roff.7
@@ -239,8 +239,9 @@ pica (~1/6 inch)
 .It p
 point (~1/72 inch)
 .It f
-synonym for
+scale
 .Sq u
+by 65536
 .It v
 default vertical span
 .It m
@@ -254,7 +255,7 @@ width of rendered
 .Pq en
 character
 .It u
-default horizontal span
+default horizontal span for the terminal
 .It M
 mini-em (~1/100 em)
 .El
@@ -262,7 +263,6 @@ mini-em (~1/100 em)
 Using anything other than
 .Sq m ,
 .Sq n ,
-.Sq u ,
 or
 .Sq v
 is necessarily non-portable across output media.
@@ -1347,6 +1347,12 @@ The term
 refers to groff version 1.15.
 .Pp
 .Bl -dash -compact
+.It
+The
+.Sq u
+scaling unit is the default terminal unit.
+In traditional troff systems, this unit would change depending on the
+output media.
 .It
 In mandoc, the
 .Sx \&EQ ,
Index: term_ascii.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ascii.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -Lterm_ascii.c -Lterm_ascii.c -u -p -r1.28 -r1.29
--- term_ascii.c
+++ term_ascii.c
@@ -230,31 +230,41 @@ ascii_hspan(const struct termp *p, const
 	double		 r;
 
 	/*
-	 * Approximate based on character width.  These are generated
-	 * entirely by eyeballing the screen, but appear to be correct.
+	 * 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;
+		break;
 	case SCALE_CM:
-		r = su->scale * 4.0;
+		r = su->scale * 10.0 / 2.54;
+		break;
+	case SCALE_FS:
+		r = su->scale * 2730.666;
 		break;
 	case SCALE_IN:
 		r = su->scale * 10.0;
 		break;
+	case SCALE_MM:
+		r = su->scale / 100.0;
+		break;
 	case SCALE_PC:
-		r = (su->scale * 10.0) / 6.0;
+		r = su->scale * 10.0 / 6.0;
 		break;
 	case SCALE_PT:
-		r = (su->scale * 10.0) / 72.0;
-		break;
-	case SCALE_MM:
-		r = su->scale / 1000.0;
+		r = su->scale * 10.0 / 72.0;
 		break;
 	case SCALE_VS:
 		r = su->scale * 2.0 - 1.0;
 		break;
-	default:
+	case SCALE_EN:
+	case SCALE_EM:
 		r = su->scale;
+		break;
+	case SCALE_MAX:
+		abort();
 		break;
 	}
 
Index: html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/html.c,v
retrieving revision 1.161
retrieving revision 1.162
diff -Lhtml.c -Lhtml.c -u -p -r1.161 -r1.162
--- html.c
+++ html.c
@@ -760,6 +760,8 @@ bufcat_su(struct html *h, const char *p,
 	v = su->scale;
 	if (SCALE_MM == su->unit && 0.0 == (v /= 100.0))
 		v = 1.0;
+	else if (SCALE_BU == su->unit)
+		v /= 24.0;
 
 	bufcat_fmt(h, "%s: %.2f%s;", p, v, roffscales[su->unit]);
 }
Index: term_ps.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ps.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.63 -r1.64
--- term_ps.c
+++ term_ps.c
@@ -1115,30 +1115,40 @@ ps_hspan(const struct termp *p, const st
 	 * All of these measurements are derived by converting from the
 	 * native measurement to AFM units.
 	 */
-
 	switch (su->unit) {
-	case SCALE_CM:
-		r = PNT2AFM(p, su->scale * 28.34);
-		break;
-	case SCALE_IN:
-		r = PNT2AFM(p, su->scale * 72.0);
+	case SCALE_BU:
+		/*
+		 * Traditionally, the default unit is fixed to the
+		 * output media.  So this would refer to the point.  In
+		 * mandoc(1), however, we stick to the default terminal
+		 * scaling unit so that output is the same regardless
+		 * the media.
+		 */
+		r = PNT2AFM(p, su->scale * 72.0 / 240.0);
 		break;
-	case SCALE_PC:
-		r = PNT2AFM(p, su->scale * 12.0);
-		break;
-	case SCALE_PT:
-		r = PNT2AFM(p, su->scale * 100.0);
+	case SCALE_CM:
+		r = PNT2AFM(p, su->scale * 72.0 / 2.54);
 		break;
 	case SCALE_EM:
 		r = su->scale *
 		    fonts[(int)TERMFONT_NONE].gly[109 - 32].wx;
 		break;
-	case SCALE_MM:
-		r = PNT2AFM(p, su->scale * 2.834);
-		break;
 	case SCALE_EN:
 		r = su->scale *
 		    fonts[(int)TERMFONT_NONE].gly[110 - 32].wx;
+		break;
+	case SCALE_IN:
+		r = PNT2AFM(p, su->scale * 72.0);
+		break;
+	case SCALE_MM:
+		r = su->scale *
+		    fonts[(int)TERMFONT_NONE].gly[109 - 32].wx / 100.0;
+		break;
+	case SCALE_PC:
+		r = PNT2AFM(p, su->scale * 12.0);
+		break;
+	case SCALE_PT:
+		r = PNT2AFM(p, su->scale * 1.0);
 		break;
 	case SCALE_VS:
 		r = su->scale * p->ps->lineheight;
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-08-13 20:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=201408132034.s7DKYTAT030019@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).