-
Notifications
You must be signed in to change notification settings - Fork 7
/
fdarray-check.pl
executable file
·102 lines (95 loc) · 3.29 KB
/
fdarray-check.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl
# Written by Dr. Ken Lunde ([email protected])
# Senior Computer Scientist 2, Adobe Inc.
# Version 2019-03-27
#
# This tool takes a CID-keyed font, which can be a CIDFont resource
# (instantiated as a file), CFF resource/table (instantiated as a
# file), or an OpenType/CFF font, as its only argument, and reports
# to STDOUT the name of each FDArray element, along with its index in
# parentheses, the CIDs that are assigned to it, and the total number
# of CIDs in parentheses. The CIDs are prefixed with a slash to
# explicitly indicate CIDs, as opposed to GIDs, which is useful when
# using the "-g" or "-gx" command-line options for many AFDKO tools,
# especially when GIDs do not equal CIDs in a particular font. The
# slash prefix can be suppressed by specifying the "-g" command-line
# option, and the values are still CIDs, not GIDs. The ROS (/Registry,
# /Ordering, and /Supplement) of the CID-keyed font is also reported
# to STDOUT. This tool also reports, via STDERR, whether GIDs do not
# equal CIDs in the specified font, and starting from which GID/CID.
#
# Tool Dependencies: tx (AFDKO)
$pre = "/";
$gidNEcid = 0;
while ($ARGV[0]) {
if ($ARGV[0] =~ /^-[huHU]/) {
print STDERR "Usage: fdarray-check.pl [-g] <CID-keyed font>\n";
exit;
} elsif ($ARGV[0] =~ /^-[gG]/) {
$pre = "";
shift;
} else {
$file = "\"$ARGV[0]\"";
shift;
}
}
open(FILE,"tx -1 $file |") or die "Cannot open $file input file!\n";
while(defined($line = <FILE>)) {
chomp $line;
if ($line =~ /^cid\.Registry\s+\"(.+)\"/) {
$r = $1;
} elsif ($line =~ /^cid\.Ordering\s+\"(.+)\"/) {
$o = $1;
} elsif ($line =~ /^cid\.Supplement\s+(\d+)/) {
$s = $1;
} elsif ($line =~ /^## FontDict\[(\d+)\]/) {
$index = $1;
} elsif ($line =~ /^FontName\s+\"(.+)\"/) {
$fdarray->{$index}{NAME} = $1;
} elsif ($line =~ /^glyph\[(\d+)\]\s+{(\d+),(\d+)(?:,[01])?}/) {
$gid = $1;
$cid = $2;
$index = $3;
if (not exists $fdarray->{$index}{CIDs}) {
$fdarray->{$index}{CIDs} = $cid;
} else {
$fdarray->{$index}{CIDs} .= "," . $cid;
}
if (not $gidNEcid and $gid != $cid) {
$gidNEcid = 1;
print STDERR "NOTE: GIDs do not equal CIDs starting from GID+$gid/CID+$cid!\n";
}
} elsif ($line =~ /^glyph\[\d+\]\s+{[^0-9].*,/) {
die "ERROR: name-keyed font! Quitting...\n";
}
}
print STDOUT "Detected ROS: $r-$o-$s\n";
foreach $element (sort {$a <=> $b} keys %{ $fdarray }) {
printf STDOUT "%s ($element): ",$fdarray->{$element}{NAME};
@cids = split(/,/,$fdarray->{$element}{CIDs});
$count = scalar @cids;
$second = 0;
foreach $cid (@cids) {
if (not $second) {
$orig = $previous = $cid;
$second = 1;
next;
}
if ($cid != $previous + 1) {
if ($orig == $previous) {
print STDOUT "$pre$orig,";
} else {
print STDOUT "$pre$orig-$pre$previous,";
}
$orig = $previous = $cid;
} else {
$previous = $cid;
}
}
if ($orig == $previous) {
print STDOUT "$pre$orig";
} else {
print STDOUT "$pre$orig-$pre$previous";
}
print STDOUT " ($count)\n";
}