/
make-metrics.pl
executable file
·69 lines (54 loc) · 1.86 KB
/
make-metrics.pl
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
use v6;
#
# This program creates metrics modules for some fonts and place them
# under the "Metrics" directory.
#
# Author: Gisle Aas
# Perl 5 -> 6 Port: David Warring
BEGIN %*ENV<METRICS> //= 'etc/Core14_AFMs';
use lib 'lib';
use Font::AFM;
class Build {
method !build-metrics {
BEGIN our @CoreFonts = <
Courier Courier-Bold Courier-Oblique Courier-BoldOblique
Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique
Times-Roman Times-Bold Times-Italic Times-BoldItalic
Symbol ZapfDingbats
>;
for @CoreFonts -> $name {
my Str $class-name = Font::AFM.class-name( $name );
my Str @parts = $class-name.split('::');
my Str $mod-name = @parts.pop;
my $lib-dir = $*SPEC.catdir('lib', @parts);
mkdir( $lib-dir, 0o755)
unless $lib-dir.IO ~~ :e;
my $afm = Font::AFM.new: :$name;
say "Building $name => $class-name";
{
my $gen-path = $*SPEC.catfile($lib-dir, "$mod-name.pm");
my $*OUT = open( $gen-path, :w);
print q:s:c:to"--CODE-GEN--";
use v6;
# Font metrics for $name
#
# DO NOT EDIT!!!
#
# This file was auto-generated by {$*SPEC.abs2rel($?FILE)} based on the AFM file for the font.
#
# {$afm.Notice}
--CODE-GEN--
print $afm.perl-gen: :name($class-name);
}
}
}
method build($where) {
self!build-metrics();
}
}
# Build.pm can also be run standalone
sub MAIN(:$indir = '.', :$metrics-path?, :$glyphs-path ) {
%*ENV<METRICS> = $metrics-path
if $metrics-path.defined;
Build.new.build($indir);
}