3 # BuildFoundries : Given a Foundry file generate groff and download files
4 # Deri James : Monday 07 Feb 2011
6 # Copyright (C) 2011-2018 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/>.
26 (my $progname = $0) =~s @.*/@@;
28 my $devps=shift||'../devps';
29 chdir $where if $where ne '';
30 my (%foundry,%flg,@downloadpreamble,%download);
31 my $GSpath=FindGSpath();
34 my $foundry=''; # the default foundry
36 LoadDownload("download");
37 LoadFoundry("Foundry");
38 WriteDownload("download");
50 open(F,"<$fn") or Die("No $fn file found");
56 s/\r$//; # in case edited in windows
58 s/\s*#.*?$//; # remove comments
71 if (lc($r[0]) eq 'foundry')
73 Warn("\nThe path(s) used for searching:\n$foundrypath\n") if $notFoundFont;
75 $foundrypath=$r[2].' : '.$devps;
76 $foundrypath=~s/\(gs\)/$GSpath /;
82 # 1=IsBase Y/N (one of PDFs 14 base fonts)
89 if (!defined($r[6]) or $r[6] eq '')
91 # if no afm file, have a guess!
92 $r[6]=substr($r[5],0,-3)."afm";
95 my $gfont=($foundry eq '')?$r[0]:"$foundry-$r[0]";
99 # Don't run afmtodit, just copy the grops font file
102 my $gropsfnt=LocateFile($devps,$r[0],0);
104 if ($gropsfnt ne '' and -r "$gropsfnt")
106 my $psfont=UseGropsVersion($gropsfnt);
107 if (!PutDownload($psfont,LocatePF($foundrypath,$r[5]),uc($r[1])))
109 if (uc($r[1]) ne 'Y')
112 my $fns=join(',',split('!',$r[5]));
113 Warn("Unable to locate font(s) $fns");
115 unlink $gfont; # Unable to find the postscript file for the font just created by afmtodit
118 Notice("Copied grops font $gfont...") if $gotf;
123 Warn("Can't read grops font '$r[0]' for Foundry '$foundry'");
128 # We need to run afmtodit to create this groff font
129 my $psfont=RunAfmtodit($gfont,LocateAF($foundrypath,$r[6]),$r[2],$r[3],$r[4]);
133 if (!PutDownload($psfont,LocatePF($foundrypath,$r[5]),uc($r[1])))
135 unlink $gfont; # Unable to find the postscript file for the font just created by afmtodit
139 Notice("Generated $gfont...");
144 Warn("Failed to create groff font '$gfont' by running afmtodit");
152 Warn("\nThe path(s) used for searching:\n$foundrypath\n") if $notFoundFont;
164 $enc="-e 'enc/$enc'" if $enc;
165 $map="'map/$map'" if $map;
167 my $cmd='afmtodit -c -dDESC';
169 foreach my $f (split('',$flags))
171 if (!exists($flg{$f}))
173 Warn("Can't use undefined flag '$f' in calling afmtodit for groff font '$gfont'");
180 system("$cmd $enc '$afmfile' $map $gfont 2>/dev/null");
188 if (open(GF,"<$gfont"))
191 my @ps=grep(/^internalname /,@gf);
192 if ($#ps == 0) # Just 1 match
194 (undef,$psfont)=split(' ',$ps[0],2);
199 Warn("Unexpected format for grops font '$gfont' for Foundry '$foundry' - ignoring");
213 return(LocateFile($path,$file,1));
221 return(LocateFile($path,$file,0));
229 return(substr($files,1)) if substr($files,0,1) eq '*';
231 foreach my $file (split('!',$files))
235 # path given with file name so no need to search the paths
242 if ($tryafm and $file=~s'type1/'afm/'i)
253 if ($path eq '(tex)')
255 my $res=`kpsewhich $file`;
261 my (@paths)=split(/ (:|;)/,$path);
263 foreach my $p (@paths)
265 next if !defined($p) or $p eq ';' or $p eq ':';
269 next if $p=~m/^\%rom\%/; # exclude %rom% paths (from (gs))
276 if ($tryafm and $p=~s'type1/'afm/'i)
291 my (@res)=`@GROFF_GHOSTSCRIPT_INTERPRETERS@ -h 2>/dev/null`;
300 if ($stg==1 and $l=~m/^Search path:/)
306 if (substr($l,0,1) ne ' ')
325 my (@gfa)=split('/',$gfont);
326 my $gfontbase=pop(@gfa);
328 if (open(GF,"<$gfont"))
331 my @ps=grep(/^internalname /,@gf);
332 if ($#ps == 0) # Just 1 match
334 (undef,$psfont)=split(' ',$ps[0],2);
339 Warn("Unexpected format for grops font '$gfont' for Foundry '$foundry' - ignoring");
346 if (open(GF,">$gfontbase"))
355 Warn("Failed to create new font '$gfont' for Foundry '$foundry'");
360 Warn("Failed to locate postscript internalname in grops font '$gfont' for Foundry '$foundry'");
367 Warn("Failed to open grops font '$gfont' for Foundry '$foundry'");
378 my $key="$foundry $psfont";
380 delete($download{$key}), return 0 if ($pffile eq '');
382 $pffile='*'.$pffile if $IsBase14 eq 'Y'; # This signals to gropdf to only edmbed if -e given
383 $download{$key}=$pffile;
393 return if !open(F,"<$fn");
398 s/\r$//; # in case edited in windows
400 if ($top and substr($_,0,1) eq '#' or $_ eq '')
402 # Preserve comments at top of download file
404 push(@downloadpreamble,$_);
409 s/\s*#.*?$//; # remove comments
413 my (@r)=split(/\t+/);
416 $download{$key}=$r[2];
427 open(F,">$fn") or Die("Can't Create new file '$fn'");
429 print F join("\n",@downloadpreamble),"\n";
431 foreach my $k (sort keys %download)
433 my ($f,$ps)=split(/ /,$k);
434 print F "$f\t$ps\t$download{$k}\n";
447 Msg("warning: line $lct: $msg");
453 Msg("error: line $lct: $msg");
459 print STDERR "$progname: $msg\n";