summaryrefslogtreecommitdiff
path: root/fonts/utilities/corelfonts/corelfonts
blob: 48d3e47456bb555a7636b8dc7763a1e951a6c9da (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/perl -w
#################################################################
# corelfonts                                                    #
# Tony McClelland   11-Feb-2003                                 #
# Copy  the  PostScript  Type1  fonts from the Corel Ventura 5  #
# CD into  the local TeXMF tree and install these fonts for use #
# with TeX and LaTeX. These fonts are from Bitstream.           #
#################################################################

use strict;
use Cwd 'chdir', 'cwd';
use File::Copy;

#################################################################
# Global variables                                              #
#################################################################
my $texmfdir;       # Path to local TeXMF directory
my $coreldir;       # Where the Corel fonts are
my $scriptdir;      # Where this script and support files are
my $afmdir;         # Where subdirectories for .afm files are
my $tfmdir;         # Where subdirectories for .tfm files are
my $vfdir;          # Where subdirectories for .vf files are
my $pfbdir;         # Where subdirectories for .pfb files are
my $latexdir;       # Where the .sty and .fd files go
my $latexbindir;	# Path to the latex/pltotf/vptovf binaries

#################################################################
# init_paths                                                    #
# Set up various paths for the TeXMF tree etc                   #
#################################################################
sub init_paths {
    print "Enter the path for the local TeXMF tree [/usr/local/share/texmf]: ";
    my $response = <STDIN>;
    chomp $response;
    if ($response eq "") {
        $texmfdir = "/usr/local/share/texmf";
    }
    else {
        $texmfdir = $response;
    }

    print "Enter the path for the Corel fonts [/cdrom/Fonts/Type1]: ";
    $response = <STDIN>;
    chomp $response;
    if ($response eq "") {
        $coreldir = "/cdrom/Fonts/Type1";
    }
    else {
        $coreldir = $response;
    }

    print "Enter the full path of the latex executables [/usr/local/bin/]: ";
    $response = <STDIN>;
    chomp $response;
    if ($response eq "") {
        $latexbindir = "/usr/local/bin";
    }
    else {
        $latexbindir = $response;
    }

    $scriptdir = cwd();
    $afmdir = "$texmfdir/fonts/afm/bitstrea";
    $tfmdir = "$texmfdir/fonts/tfm/bitstrea";
    $vfdir = "$texmfdir/fonts/vf/bitstrea";
    $pfbdir = "$texmfdir/fonts/type1/bitstrea";
    $latexdir = "$texmfdir/tex/latex/bitstrea";
    
    # Create the directories if necessary
    mkdir $afmdir unless -e $afmdir ;
    mkdir $tfmdir unless -e $tfmdir;
    mkdir $vfdir  unless -e $vfdir;
    mkdir $pfbdir  unless -e $pfbdir;
    mkdir $latexdir unless -e $latexdir;
}


#################################################################
# Copy fonts from the CD, renaming according to the fontname    #
# scheme. The fonts are arranged on the CD in subdirectories    #
# under $coreldir named by the first letter of the font name.   #
#################################################################
sub copy_fonts {
    # Start off with fonts beginning with 'A'
    my $oldsubdir = "A";
    chdir("$coreldir/$oldsubdir");

    # Prepare a map file for dvips
    open(MAPFILE, ">$texmfdir/dvips/config/bitstrea.map")
    	or die "Unable to open the map file: $!";

    # Use the font name information in fontnames.dat (taken from
    # the file bitstrea.map in the fontinst info on CTAN) to copy
    # the afm and pfb files and build the dvips map file.
    open(FONTNAMES, "$scriptdir/fontnames.dat")
	    or die "Unable to open the fontnames.dat file: $!";

    while (<FONTNAMES>) {
	    chomp;
	    my ($fontname, $prefix, $kbname, $shortname, $shape) = split;
	    my $subdir = substr($fontname, 0, 1);
	
        # Only change directory when the first letter changes
	    if ($subdir ne $oldsubdir) {
		    $oldsubdir = $subdir;
		    chdir("$coreldir/$subdir");
	    }

	    # Set up the name of the AFM and PFB files used by Corel
	    my $fontfile = "${prefix}A___";
	    my $afmfile = "$fontfile.afm";
	    my $pfbfile = "$fontfile.pfb";

	    # Not all the files in the bitstrea.map are on the CD.
	    # Only set up texmf directories for those that are.		
	    if (-e $afmfile) {
		    # Create subdirectories in the texmf tree
		    mkdir "$afmdir/$shortname" unless -e "$afmdir/$shortname";
		    mkdir "$tfmdir/$shortname" unless -e "$tfmdir/$shortname";
		    mkdir "$vfdir/$shortname" unless -e "$vfdir/$shortname";
		    mkdir "$pfbdir/$shortname" unless -e "$pfbdir/$shortname";
		
		    # Copy the font using the fontname scheme
		    copy($afmfile, "$afmdir/$shortname/$kbname.afm");
		    copy($pfbfile, "$pfbdir/$shortname/$kbname.pfb");
		
		    # Put an entry for this font in the map file
		    my $reencode = $kbname;
		    $reencode =~ s/8a/8r/;
		    print MAPFILE "$reencode $fontname \"TeXBase1Encoding ReEncodeFont\" <8r.enc <$kbname.pfb\n";

            # If this font is not already italic or oblique, add a fake
            # slanted variant to the map file
            unless (($fontname =~ /[Oo]blique/) || ($fontname =~ /[Ii]talic/)) {
                $reencode =~ s/8r/o8r/;
                print MAPFILE "$reencode $fontname \".167 SlantFont TeXBase1Encoding ReEncodeFont\" <8r.enc <$kbname.pfb\n";
            }
	    }
    }

    close(FONTNAMES);
    close(MAPFILE);
}


#################################################################
# install_fonts                                                 #
# Install font families by running fontinst on the afm files    #
#################################################################
sub install_fonts {
    my %families;       # font families and rm, sf or tt shapes
    my %famcodes;       # 3 letter codes for font families
    my %btnames;        # Bitstream names for font families

    # Get a list of all the subdirectories containing *.afm files
    # organised by font name, for fontinst to work on
    open(FONTNAMES, "$scriptdir/fontnames.dat")
        or die "Unable to open the file fontnames.dat: $!";

    while (<FONTNAMES>) {
        chomp;
	    my ($fontname, $prefix, $kbname, $shortname, $shape) = split;
        if (-e "$afmdir/$shortname") {
            $families{$shortname} = $shape;	
            $famcodes{$shortname} = substr($kbname, 0, 3);
            $fontname =~ s/BT.*//;      # strip off everything after BT
            $btnames{$shortname} = $fontname;
        }
    }

    close(FONTNAMES);
    
    # Run fontinst in each subdirectory
    foreach my $font (sort keys %families) {
	    chdir "$afmdir/$font";

	    # Create a tex file to allow latex to be run on fontinst with
	    # this family of fonts as the \latinfamily
	    copy("$scriptdir/fontinst.sty", "$afmdir/$font/fontinst.sty");
	    open(FONTINST, ">$afmdir/$font/corelfont.tex")
		    or die "Cannot open the LaTeX file: $!";
	    print FONTINST <<EOF;
\\input fontinst.sty
\\latinfamily{$famcodes{$font}}{} \\bye
EOF
	    system("$latexbindir/latex corelfont.tex");
	
	    # Now create .tfm and .vf files from the fontinst output
	    while (my $vpl = glob("*.vpl")) {
		    system("$latexbindir/vptovf $vpl");
	    }
	    while (my $pl = glob("*.pl")) {
		    system("$latexbindir/pltotf $pl");
	    }
	
	    # Move the .tfm, .vf and .fd files to their destinations
	    while (my $tfm = glob("*.tfm")) {
		    rename($tfm, "$tfmdir/$font/$tfm");
	    }
	    while (my $vf = glob("*.vf")) {
		    rename($vf, "$vfdir/$font/$vf");
	    }
	    while (my $fd = glob("*.fd")) {
		    rename($fd, "$latexdir/$fd");
	    }
	
	    # Clean up the files created by fontinst
	    unlink <*.vpl>;
	    unlink <*.pl>;
	    unlink <*.mtx>;
	    unlink <*.tex>;
	    unlink <*.sty>;
	
	    # Create a LaTeX style file for this font
	    open(LATEXFILE, ">$latexdir/$font.sty");
	    print LATEXFILE "% LaTeX package file for using the Bitstream font $btnames{$font}\n";
	    print LATEXFILE "\\ProvidesPackage{$font}[2003/02/11 Bitstream font $btnames{$font}]\n";
	    print LATEXFILE "\\renewcommand{\\$families{$font}default}{$famcodes{$font}}\n";
	    close(LATEXFILE);
	
	    chdir $afmdir;
    }
}


#################################################################
# Main program                                                  #
#################################################################
init_paths();
copy_fonts();
install_fonts();

print "Done.\n";