1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
#!/usr/bin/perl
=pod
=head1 NAME
showglyphs - create a F<pdf> file that shows all glyphs in a font
=head1 SYNOPSIS
showglyphs I<fontfile>
=head1 DESCRIPTION
This program creates a F<pdf> file that shows all glyphs in a given font.
=head1 FILES
=over 4
=item I<font>
This can be any Type 1 or TrueType font; OpenType fonts are not (yet?)
supported.
=back
=head1 RESTRICTIONS
=over 4
=item B<->
B<showglyphs> only works on Unix/Linux systems.
=item B<->
B<showglyphs> needs a working, TDS-compliant Tex installation
=back
=head1 SEE ALSO
F<afm2afm>, F<autoinst>, F<cmap2enc>, F<pfm2kpx>, F<enc2etx>,
F<etx2enc>, F<ot2kpx>.
=head1 AUTHOR
Marc Penninga <marc@penninga.info>
=head1 HISTORY
=over 12
=item I<2005-04-28>
First version
=item I<2005-04-29>
A few bugfixes; B<showglyphs> now works with glyphnames containing underscores
=item I<2005-05-24>
Another bugfix
=item I<2005-07-29>
A few updates to the documentation
=back
=cut
use integer;
use warnings; no warnings qw(uninitialized);
$0 =~ s!.*/!!g;
die "Usage: $0 fontfile\n" if @ARGV != 1;
system "mkdir -p ./showglyphs/";
system "cp $ARGV[0] ./showglyphs/";
chdir "./showglyphs";
system "font2afm $ARGV[0]";
$ARGV[0] =~ /([\w-]+)\./ and $fontname = $1;
open AFM, "<${fontname}.afm" or
die "Error: can't open `${fontname}.afm' - $!\n";
{
local $/;
$_ = <AFM>;
}
(/StartCharMetrics (\d+)/m and $num_glyphs = $1) or $num_glyphs = 255;
@vec = (".notdef") x (($num_glyphs / 256 + 1) * 256);
for (/(WX.*?$)/gm) {/N\s+([\w.]+)/ and $vec[$i++] = $1}
system "cp `locate pdftex.map` .";
open TEX, ">tmp.tex" or die "Error: can't create `tmp.tex' - $!\n";
print TEX <<EOF;
\\documentclass[a4paper]{article}
\\setlength\\parindent{0pt}
\\setlength\\parskip{0pt}
\\raggedbottom\\frenchspacing
\\newlength\\tempdima
\\makeatletter
\\setlength\\textheight{\\paperheight}
\\addtolength\\textheight{-2in}
\\setlength\\textwidth{\\paperwidth}
\\addtolength\\textwidth{-2in}
\\setlength\\oddsidemargin{0pt}
\\setlength\\evensidemargin{0pt}
\\setlength\\topmargin{0pt}
\\addtolength\\topmargin{-\\headheight}
\\addtolength\\topmargin{-\\headsep}
\\makeatother
\\newcommand*{\\printglyph}[2]{%
\\frame{%
\\settodepth{\\tempdima}{#1}%
\\makebox[2em][l]{%
\\rule[-18pt]{0pt}{48pt}%
\\makebox[0pt][l]{%
\\raisebox{-14pt}{\\makebox[2em][c]{\\tiny#2}}}%
\\raisebox{-\\tempdima}{%
\\makebox[2em][c]{\\linethickness{0pt}\\frame{#1}}}}}}
\\begin{document}
EOF
for ($i = 0; $i < $num_glyphs / 256 + 1; $i++) {
$filename = sprintf "%s%03d", $fontname, $i + 1;
open ENC, ">$filename.enc" or
die "Error: can't create `$filename.enc' - $!\n";
print ENC "%\n% Created ", scalar localtime,
" by $0 from `${fontname}.afm'\n";
print ENC "%\n/", $filename, " [\n";
for ($j = 0; $j < 256; $j += 16) {
printf ENC "%% 0x%04x\n", $j;
for ($k = 0; $k < 16; $k += 4) {
print ENC "\t";
for ($l = 0; $l < 4; $l++) {
print ENC "/$vec[$i * 256 + $j + $k + $l] ";
}
print ENC "\n";
}
}
print ENC "] def\n";
close ENC;
system "afm2afm -e '${filename}.enc' -o '${filename}.afm' " .
"'${fontname}.afm' >>./pdftex.map";
system "afm2tfm '${fontname}.afm' -T '${filename}.enc' '${filename}.tfm'"
. ">/dev/null";
for (@vec[256 * $i..256*($i+1)]) {s/(?<!\\)_/\\_/g}
print TEX "\\font\\test=${filename} at 24pt\\test\n";
for $j (0 .. 31) {
for $k (0 .. 7) {
print TEX "\\printglyph{\\char", 8 * $j + $k,
"}{$vec[$i * 256 + 8 * $j + $k]} ";
}
print TEX "\\par\n";
last if 256 * $i + 8 * ($j + 1) >= $num_glyphs;
}
}
print TEX "\n\\end{document}\n";
close TEX;
system "pdflatex tmp >/dev/null";
chdir "../";
system "mv showglyphs/tmp.pdf './${fontname}.pdf'";
system "/bin/rm -r ./showglyphs/";
__END__
|