cntstems.pl
1002 Bytes
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
#!/usr/bin/perl
#
# Copyright (c) 2000 by Sergey Babkin
# (see COPYRIGHT for full copyright notice)
#
# script to calculate the total number of stems used by the
# glyphs in case if stems are always pushed to the stack and
# never popped (as X11 does)
$insubrs = 0;
$inchars = 0;
while(<>)
{
if(/\/Subrs/) {
$insubrs = 1;
} elsif(/\/CharStrings/) {
$insubrs = 0;
$inchars = 1;
}
if($insubrs && /^dup (\d+)/) {
$cursubr = $1;
$substems[$cursubr] = 0;
} elsif (/^dup (\d+) \/(\S+) put/) {
$codeof{$2} = $1;
}
if($inchars) {
if(/^\/(\S+)\s+\{/) {
$curchar = $1;
$charstems = 0;
} elsif( /endchar/ ) {
printf("%d:%s\t%d\n", $codeof{$curchar}, $curchar, $charstems);
} elsif( /(\d+)\s+4\s+callsubr/) {
$charstems += $substems[$1+0];
}
}
if(/[hv]stem3/) {
if($insubrs) {
$substems[$cursubr] += 3;
} elsif($inchars) {
$charstems += 3;
}
} elsif( /[hv]stem/ ) {
if($insubrs) {
$substems[$cursubr]++;
} elsif($inchars) {
$charstems++;
}
}
}