3 # BuildFoundries : Given a Foundry file generate groff and download files
4 # Deri James : Monday 07 Feb 2011
6 # Copyright (C) 2011 Free Software Foundation, Inc.
7 # Written by Deri James <deri@chuzzlewit.demon.co.uk>
9 # This file is part of groff.
11 # groff is free software; you can redistribute it and/or modify it under
12 # the terms of the GNU General Public License as published by the Free
13 # Software Foundation, either version 3 of the License, or
14 # (at your option) any later version.
16 # groff is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 my $devps=shift||'../devps';
28 chdir $where if $where ne '';
29 my (%foundry,%flg,@downloadpreamble,%download);
30 my $GSpath=FindGSpath();
33 my $foundry=''; # the default foundry
35 LoadDownload("download");
36 LoadFoundry("Foundry");
37 WriteDownload("download");
48 open(F,"<$fn") or die "No $fn file found";
54 s/\r$//; # in case edited in windows
56 s/\s*#.*?$//; # remove comments
69 if (lc($r[0]) eq 'foundry')
72 $foundrypath=$r[2].' : '.$devps;
73 $foundrypath=~s/\(gs\)/$GSpath /;
78 # 1=IsBase Y/N (one of PDFs 14 base fonts)
85 if (!defined($r[6]) or $r[6] eq '')
87 # if no afm file, have a guess!
88 $r[6]=substr($r[5],0,-3)."afm";
91 my $gfont=($foundry eq '')?$r[0]:"$foundry-$r[0]";
95 # Don't run afmtodit, just copy the grops font file
98 my $gropsfnt=LocateFile($devps,$r[0],0);
100 if ($gropsfnt ne '' and -r "$gropsfnt")
102 my $psfont=UseGropsVersion($gropsfnt);
103 if (!PutDownload($psfont,LocatePF($foundrypath,$r[5]),uc($r[1])))
105 if (uc($r[1]) ne 'Y')
108 my $fns=join(',',split('!',$r[5]));
109 Msg(0,"Unable to locate font(s) $fns on the given path(s)");
110 unlink $gfont; # Unable to find the postscript file for the font just created by afmtodit
113 print STDERR "Copied grops font $gfont...\n" if $gotf;
118 Msg(0,"Can't read grops font '$r[0]' for Foundry '$foundry'");
123 # We need to run afmtodit to create this groff font
124 my $psfont=RunAfmtodit($gfont,LocateAF($foundrypath,$r[6]),$r[2],$r[3],$r[4]);
128 if (!PutDownload($psfont,LocatePF($foundrypath,$r[5]),uc($r[1])))
130 unlink $gfont; # Unable to find the postscript file for the font just created by afmtodit
134 print STDERR "Generated $gfont...\n";
139 Msg(0,"Failed to create groff font '$gfont' by running afmtodit");
157 $enc="-e 'enc/$enc'" if $enc;
158 $map="'map/$map'" if $map;
160 my $cmd='afmtodit -c -dDESC';
162 foreach my $f (split('',$flags))
164 if (!exists($flg{$f}))
166 Msg(0,"Can't use undefined flag '$f' in calling afmtodit for groff font '$gfont'");
173 system("$cmd $enc '$afmfile' $map $gfont 2>/dev/null");
181 if (open(GF,"<$gfont"))
184 my @ps=grep(/^internalname /,@gf);
185 if ($#ps == 0) # Just 1 match
187 (undef,$psfont)=split(' ',$ps[0],2);
192 Msg(0,"Unexpected format for grops font '$gfont' for Foundry '$foundry' - ignoring");
206 return(LocateFile($path,$file,1));
214 return(LocateFile($path,$file,0));
222 return(substr($files,1)) if substr($files,0,1) eq '*';
224 foreach my $file (split('!',$files))
228 # path given with file name so no need to search the paths
235 if ($tryafm and $file=~s'type1/'afm/'i)
246 if ($path eq '(tex)')
248 my $res=`kpsewhich $file`;
254 my (@paths)=split(/ (:|;)/,$path);
256 foreach my $p (@paths)
258 next if !defined($p) or $p eq ';' or $p eq ':';
262 next if $p=~m/^\%rom\%/; # exclude %rom% paths (from (gs))
269 if ($tryafm and $p=~s'type1/'afm/'i)
284 my (@res)=`@GROFF_GHOSTSCRIPT_INTERPRETERS@ -h 2>/dev/null`;
293 if ($stg==1 and $l=~m/^Search path:/)
299 if (substr($l,0,1) ne ' ')
318 my (@gfa)=split('/',$gfont);
319 my $gfontbase=pop(@gfa);
321 if (open(GF,"<$gfont"))
324 my @ps=grep(/^internalname /,@gf);
325 if ($#ps == 0) # Just 1 match
327 (undef,$psfont)=split(' ',$ps[0],2);
332 Msg(0,"Unexpected format for grops font '$gfont' for Foundry '$foundry' - ignoring");
339 if (open(GF,">$gfontbase"))
348 Msg(0,"Failed to create new font '$gfont' for Foundry '$foundry'");
353 Msg(0,"Failed to locate postscript internalname in grops font '$gfont' for Foundry '$foundry'");
360 Msg(0,"Failed to open grops font '$gfont' for Foundry '$foundry'");
371 my $key="$foundry $psfont";
373 delete($download{$key}), return 0 if ($pffile eq '');
375 $pffile='*'.$pffile if $IsBase14 eq 'Y'; # This signals to gropdf to only edmbed if -e given
376 $download{$key}=$pffile;
386 return if !open(F,"<$fn");
391 s/\r$//; # in case edited in windows
393 if ($top and substr($_,0,1) eq '#' or $_ eq '')
395 # Preserve comments at top of download file
397 push(@downloadpreamble,$_);
402 s/\s*#.*?$//; # remove comments
406 my (@r)=split(/\t+/);
409 $download{$key}=$r[2];
420 open(F,">$fn") or die "Can't Create new file '$fn'";
422 print F join("\n",@downloadpreamble),"\n";
424 foreach my $k (sort keys %download)
426 my ($f,$ps)=split(/ /,$k);
427 print F "$f\t$ps\t$download{$k}\n";
440 print STDERR "Error: line $lct: $msg\n";
445 print STDERR "Warning: line $lct: $msg\n";