-
Notifications
You must be signed in to change notification settings - Fork 7
/
mkvmtx.pl
executable file
·81 lines (66 loc) · 2.12 KB
/
mkvmtx.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
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl
# Written by Dr. Ken Lunde ([email protected])
# Senior Computer Scientist 2, Adobe Inc.
# Version 2019-03-27
#
# This tool takes a CIDFont resource as its only command-line argument,
# along with a list of CIDs or CID ranges that correspond to full-width
# glyphs that rest on the Western baseline, such as Latin, Greek,
# Cyrillic, currency symbols, and other characters, as STDIN, and
# generates a 'vmtx' table override that can be included in a "features"
# file. The glyphs are mechanically centered along the Y-axis by using
# the top and bottom of the em-box as reference points, along with the
# top and bottom of their bounding boxes.
#
# Tool Dependencies: tx (AFDKO)
$file = $ARGV[0];
open(AFM,"tx -afm $file |") or die "Cannot open $file input file!\n";
$count = 0;
print STDERR "Loading CIDs ...";
while ($line = <STDIN>) {
chomp $line;
$count++;
$line =~ s/^\s*(.*)\s*$/$1/;
$line =~ s/\s+/ /;
if ($line =~ /-/) {
($cidstart,$cidend) = split /-/, $line;
} else {
$cidstart = $line;
$cidend = $cidstart;
}
foreach $cid ($cidstart .. $cidend) {
$cidrange{$cid} = 1;
}
}
print STDERR "Done\n";
# Adjust the values of the variables $ybottomlimit and $ytoplimit to
# correspond to the bottom and top of the em-box.
$ybottomlimit = -120;
$ytoplimit = 880;
$ycenter = ($ybottomlimit + $ytoplimit) / 2;
# Generate the 'vmtx' table override by mechanically-centering the
# specified CIDs along the Y-axis according to the em-box and glyph
# bounding boxes.
print STDOUT "table vmtx {\n";
while ($line = <AFM>) {
if ($line =~ /^C.*/) {
chomp $line;
($cid,$ymin,$ymax) = (split(/ /,$line))[7,11,13];
if (exists $cidrange{$cid}) {
$halfy = ($ymax - $ymin) / 2;
$yminnew = $ycenter - $halfy;
$pushy = round($yminnew - $ymin);
$pushy =~ s/^\+(\d+)/$1/;
printf STDOUT " VertOriginY \\$cid %s;\n",$ytoplimit - $pushy if $pushy !~ /^-?[0-4]$/;
}
}
}
print STDOUT "} vmtx;\n";
sub round {
my ($arg) = @_;
if ($arg =~ /\.[0-4]\d*/) {
$arg =~ s/\.[0-4]\d*$//;
} elsif ($arg =~ /\.[5-9]\d*/) {
$arg =~ s/(\d+)\.[5-9]\d*$/$1 + 1/e;
} return $arg;
}