-
Notifications
You must be signed in to change notification settings - Fork 7
/
fix-fontbbox.pl
executable file
·55 lines (42 loc) · 1.41 KB
/
fix-fontbbox.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
#!/usr/bin/perl
# Written by Dr. Ken Lunde ([email protected])
# Senior Computer Scientist 2, Adobe Inc.
# Version 2019-03-27
#
# This script takes a CIDFont resource as its only argument, and
# outputs to STDOUT a CIDFont resource with a corrected /FontBBox
# array. The original and corrected /FontBBox array values are output
# to STDERR.
#
# Tool Dependencies: tx (AFDKO)
$file = $ARGV[0];
# Set initial coordinates to the center of [0,-120,1000,880]
$llx = $urx = 500;
$lly = $ury = 380;
# Create and open AFM file
open(AFM,"tx -afm $file |") or die "Cannot open $file input file!\n";
while(defined($line = <AFM>)) {
chomp $line;
if ($line =~ /FontBBox/) {
($bbox1) = $line =~ /FontBBox\s+(.+)/;
} elsif ($line =~ /^C\s+.+;\s+N\s+.+\s+;\s+B\s+(.+)\s+;/) {
($a,$b,$c,$d) = split(/\s+/,$1);
if ($a < $llx) { $llx = $a; }
if ($b < $lly) { $lly = $b; }
if ($c > $urx) { $urx = $c; }
if ($d > $ury) { $ury = $d; }
}
}
close(AFM);
print STDERR "Original FontBBox: $bbox1\n";
print STDERR "Correct FontBBox: $llx $lly $urx $ury\n";
# Open CIDFont resource to change the /FontBBox array in its header
open(FILE,"<$file") or die "Cannot open $file input file!\n";
while(defined($line = <FILE>)) {
if ($line =~ /\/FontBBox/) {
$line = "/FontBBox {$llx $lly $urx $ury} def\n";
print STDERR "Corrected FontBBox\n";
}
print STDOUT $line;
}
close(FILE);