Commit Diff


commit - 5af8dd63eb193290c1f9c316012eb14d538569f1
commit + eaec1e5a39b6de1ed7c4c0e57b46c9e2de230ce3
blob - /dev/null
blob + 80fbccb96fd57c7210754d60010d75bd2d66bfc4 (mode 644)
--- /dev/null
+++ dist/troff/README
@@ -0,0 +1,4 @@
+This directory contains tools used to import fonts for use in troff.
+
+afm2troff.c - simple AFM file reader, generates desc for troff/font/devutf.
+tfont - simple TTF or SFD converter
blob - /dev/null
blob + da185230fba69a5f087abcd25efe7f63d289d01e (mode 644)
--- /dev/null
+++ dist/troff/afm2troff.c
@@ -0,0 +1,93 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+
+int didname;
+int didfontname;
+int offset;
+void run(char*, int);
+Biobuf bout;
+
+void
+usage(void)
+{
+	fprint(2, "usage: afm2troff [-h] [-o offset] [file...]\n");
+	exits("usage");
+}
+
+void
+main(int argc, char **argv)
+{
+	int i, fd;
+	
+	ARGBEGIN{
+	case 'h':
+		didname = 1;
+		didfontname = 1;
+		break;
+	case 'o':
+		offset = atoi(EARGF(usage()));
+		break;
+	default:
+		usage();
+	}ARGEND
+	
+	Binit(&bout, 1, OWRITE);
+	if(argc == 0)
+		run("<stdin>", 0);
+	else{
+		for(i=0; i<argc; i++){
+			if((fd = open(argv[i], OREAD)) < 0)
+				sysfatal("open %s: %r", argv[i]);
+			run(argv[i], fd);
+		}
+	}
+	Bflush(&bout);
+}
+
+void
+run(char *name, int fd)
+{
+	char *p, *q, *f[100];
+	int nf, code, wid, ad;
+	Biobuf b;
+	
+	Binit(&b, fd, OREAD);
+	while((p = Brdline(&b, '\n')) != nil){
+		p[Blinelen(&b)-1] = 0;
+		q = strchr(p, ' ');
+		if(q == nil)
+			continue;
+		*q++ = 0;
+		while(*q == ' ' || *q == '\t')
+			q++;
+		if(*q == 0)
+			continue;
+		if(strcmp(p, "FontName") == 0 && didname++ == 0)
+			 Bprint(&bout, "name %s\n", q);
+		if(strcmp(p, "FullName") == 0 && didfontname++ == 0)
+			 Bprint(&bout, "fontname %s\n", q);
+		if(strcmp(p, "C") == 0){
+			nf = getfields(q, f, nelem(f), 1, "\t\r\n\v ");
+			if(nf < 5 || strcmp(f[1], ";") != 0 || strcmp(f[2], "WX") != 0)
+				continue;
+			code = strtol(f[0], 0, 10);
+			wid = strtol(f[3], 0, 10);
+			wid = (wid+5)/10;
+			if(code == 0)
+				continue;
+			code += offset;
+			ad = 0;
+			if(nf < 6 || strcmp(f[nf-6], "B") != 0)
+				continue;
+			if(atoi(f[nf-4]) < -50)
+				ad |= 1;
+			if(atoi(f[nf-2]) > 600)
+				ad |= 2;
+			if(code == ' ')
+				Bprint(&bout, "spacewidth %d\ncharset\n", wid);
+			else
+				Bprint(&bout, "%C\t%d\t%d\t%d %04x\n", code, wid, ad, code, code);
+		}
+	}
+}
blob - /dev/null
blob + 4d4239715c83ade8425491dc15b69f811e9f0c0b (mode 644)
--- /dev/null
+++ dist/troff/devutf.sam
@@ -0,0 +1,67 @@
+,s/^`.*\n//
+,s/^'.*\n//
+,s/^‘.*/&\n` "/
+,s/^’.*/&\n' "/
+,s/^".*/&\ndq	"/
+,s/^".*/&\ndq "/
+,s/^'.*/&\n’ "/
+,s/^\\.*/&\nbs "/
+,s/^`.*/&\n‘ "/
+,s/^\\`.*/&\nga "/
+,s/^­.*/&\nhy "/
+,s/^®.*/&\nrg "/
+,s/^±.*/&\n+- "/
+,s/^´.*/&\naa "/
+,s/^×.*/&\nmu "/
+,s/^÷.*/&\n-: "/
+,s/^-:.*/&\ndi "/
+,s/^–.*/&\nen "/
+,s/^en.*/&\n\\- "/
+,s/^—.*/&\nem "/
+,s/^em.*/&\n-- "/
+,s/^™.*/&\ntm "/
+,s/^←.*/&\n<- "/
+,s/^↑.*/&\nua "/
+,s/^→.*/&\n-> "/
+,s/^↓.*/&\nda "/
+,s/^↔.*/&\nab "/
+,s/^∀.*/&\nfa "/
+,s/^∂.*/&\npd "/
+,s/^∃.*/&\nte "/
+,s/^∅.*/&\nes "/
+,s/^∇.*/&\ngr "/
+,s/^∉.*/&\n!m "/
+,s/^∍.*/&\nst "/
+,s/^∗.*/&\n** "/
+,s/^∙.*/&\nbu "/
+,s/^√.*/&\nsr "/
+,s/^∝.*/&\npt "/
+,s/^∞.*/&\nif "/
+,s/^∠.*/&\nan "/
+,s/^∧.*/&\nl& "/
+,s/^∨.*/&\nl| "/
+,s/^∩.*/&\nca "/
+,s/^∪.*/&\ncu "/
+,s/^∫.*/&\nis "/
+,s/^∴.*/&\ntf "/
+,s/^≃.*/&\n~= "/
+,s/^≅.*/&\ncg "/
+,s/^≈.*/&\n~~ "/
+,s/^≠.*/&\n!= "/
+,s/^≡.*/&\n== "/
+,s/^≦.*/&\n<= "/
+,s/^≧.*/&\n>= "/
+,s/^⊂.*/&\nsb "/
+,s/^⊃.*/&\nsp "/
+,s/^⊄.*/&\n!b "/
+,s/^⊆.*/&\nib "/
+,s/^⊇.*/&\nip "/
+,s/^⊕.*/&\nO+ "/
+,s/^⊖.*/&\nO- "/
+,s/^⊗.*/&\nOx "/
+,s/^⊢.*/&\ntu "/
+,s/^⊨.*/&\nTu "/
+,s/^⋄.*/&\nlz "/
+,s/^⋯.*/&\nel "/
+w
+q
blob - /dev/null
blob + 48bd9362c51c6425576ac7133f452d2516fa2010 (mode 644)
--- /dev/null
+++ dist/troff/mono.sam
@@ -0,0 +1,4 @@
+,s/^hy "\n//g
+,s/^-.*/&\nhy "/
+w
+q
blob - /dev/null
blob + ea99641cc0532d0672b7be6e74284bb308ff0682 (mode 755)
--- /dev/null
+++ dist/troff/tfont
@@ -0,0 +1,43 @@
+#!/usr/local/plan9/bin/rc
+
+rm *.tpost *.troff *.pfb *.pfa *.afm map.sfd
+
+hex1=(0 1 2 3 4 5 6 7 8 9 A B C D E F)
+hex=()
+for(i in $hex1) for(j in $hex1) hex=($hex $i$j)
+{
+	for(h in $hex)
+		echo $h 0x$h^00_0x$h^FF
+} >map.sfd
+for(font){
+	f0=$font
+	if(~ $font *.ttf)
+		font=`{9 basename $font .ttf}
+	if not if(~ $font *.sfd)
+		font=`{9 basename $font .sfd}
+	fontforge -c 'Open($1); Generate($2, "", -1, 72, "map.sfd")' \
+		$f0 $font^%s.pfb map.sfd
+	{
+		echo name $font
+		echo fontname $font
+	} >$font.troff
+	>$font.tpost
+	for(h in $hex){
+		if(test -f $font$h.pfb){
+			pfb2pfa $font$h.pfb $font$h.pfa
+			mv $font$h.pfa /usr/local/plan9/postscript/font/dejavu/$font$h
+			afm2troff -h -o 0x$h^00 $font$h.afm >>$font.troff
+			echo 0x$h^00 0x$h^FF $font$h >>$font.tpost
+		}
+	}
+	{
+		echo '0x0027 0x0027 0x19 '$font'20  # map apostrophe to right quote'
+		echo '0x0060 0x0060 0x18 '$font'20  # map grave to left quote'
+	} >>$font.tpost
+
+	sam -d $font.troff <$PLAN9/dist/troff/devutf.sam
+	if(~ $font *Mono*)
+		sam -d $font.troff <$PLAN9/dist/troff/mono.sam
+	cp $font.troff /usr/local/plan9/troff/font/devutf/$font
+	cp $font.tpost /usr/local/plan9/postscript/troff/$font
+}