File: t1embed

package info (click to toggle)
type1inst 0.6-1
  • links: PTS
  • area: main
  • in suites: hamm, potato, slink
  • size: 128 kB
  • ctags: 18
  • sloc: perl: 961; makefile: 36; sh: 6
file content (73 lines) | stat: -rwxr-xr-x 1,706 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl
#
# t1embed: Embed Type 1 font in a PostScript file that calls for 
# non-standard fonts but does not supply them.
#
# IMPORTANT NOTE: This script relies on the use of special comments which 
# are only embedded by type1inst.  This is NOT a general font embedding
# script!
#

@standard_fonts = ("Times-Roman", "Helvetica");

# Start of script proper

$numargs = @ARGV;

if ($numargs < 1) {
    die("Usage : $0 PSfile1 [PSfile2 PSfile3 ....]\n");
}

foreach $filename (@ARGV) {
    print "file : $filename\n";
    open(IN, $filename) || die("Can't open \"$filename\"\n");
    @toembed = ();
    while (<IN>) {
	if (/^%\s+t1embed\s+:\s+(\S+)\s+(\S+)\s*$/) {
	    @suppliedfonts = (@suppliedfonts, "/$2");
	    @toembed = (@toembed, $1);
	}
    }
    close(IN);
    
    $numtoembed = @toembed;
    
    if ($numtoembed == 0) {
	print "No fonts to embed\n";
	next;
    }
    
    foreach $i (@toembed) {
	print "Embed $i\n";
    }
    
    open(OUT, ">foo") || die("Can't open temporary file \"foo\"\n");
    open(IN, $filename) || die("Can't open $filename\n");
    while (<IN>) {
	if (/%%EndComments/) {
	    print OUT "%%DocumentSuppliedResources font @suppliedfonts\n";
	    print OUT;
	    foreach $fname (@toembed) {
		print "$fname\n";
		$fontname = shift(@suppliedfonts);
		print OUT "%%BeginResource: font $fontname\n";
		if ($fname =~ /\.pfb$/) {
		    open(F, "pfbtops $fname |") || die("Can't run pfbtops on $fname\n");
		} else {
		    open(F, $fname) || die("Can't open $fname\n");
		}
		while (<F>) {
		    print OUT;
		}
		close(F);
		print OUT "%%EndResource\n";
	    }
	} else {
	    print OUT;
	}
    }
    close(IN);
    close(OUT);
    
    system("mv foo $filename");
}