home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / web2c / lib / MakeTeXPK.pl < prev    next >
Perl Script  |  1996-09-28  |  6KB  |  178 lines

  1. #! /usr/local/bin/perl
  2. #
  3. # From: Martin Ward <Martin.Ward@durham.ac.uk>
  4. # Date: Fri, 28 Jan 94 15:40:14 GMT
  5. # Here's my MakeTeXPK. Currently it puts all the .pk files in 
  6. # $prefix/texmf/fonts/pk/dpiNNN/name.pk  and the .tfm files in
  7. # $prefix/texmf/fonts/tfm
  8. # With the automatic generation of pk's and tfm's (and a 40 MIP sparcstation 2
  9. # to run metafont on!) I can get by quite happily with a minimal set of fonts.
  10. #   This script file makes a new TeX PK font, because one wasn't
  11. #   found.  Parameters are:
  12. #
  13. #   name dpi bdpi magnification [mode]
  14. #
  15. #   `name' is the name of the font, such as `cmr10'.  `dpi' is
  16. #   the resolution the font is needed at.  `bdpi' is the base
  17. #   resolution, useful for figuring out the mode to make the font
  18. #   in.  `magnification' is a string to pass to MF as the
  19. #   magnification.  `mode', if supplied, is the mode to use.
  20. #
  21. #   Note that this file must execute Metafont, and then gftopk,
  22. #   and place the result in the correct location for the PostScript
  23. #   driver to find it subsequently.  If this doesn't work, it will
  24. #   be evident because MF will be invoked over and over again.
  25. #
  26. #   Modified to generate dc fonts automatically. To generate dcXXXnn:
  27. #   (1) Create dcXXXnn.mf in current dir, containing the lines:
  28. #         if unknown dxbase: input dxbase fi;
  29. #         gensize:=nnn;
  30. #         generate dcXXX
  31. #   (2) Use dxbase base file
  32.  
  33. print STDERR "MakeTeXPK @ARGV\n";
  34.  
  35. # Old defaults:
  36. #$base = "/home/ws-csm3/user15/gnu/lib/tex/fonts";
  37. #$pkbase = "/home/ws-csm3/user15/gnu/lib/tex/fonts/pk.RicohA";  # Default pk dir#$stdmode = "RicohA";                   # Default mode_def (write-white):
  38. #$pkdefault = "/home/ws-csm3/user15/gnu/lib/tex/fonts/RicohA";
  39.  
  40. # Default paths:
  41. $prefix = "/local/home/user15/gnu/lib";
  42. $base = "$prefix/texmf/fonts";
  43. $pkbase = "$prefix/texmf/fonts/pk";     # Default pk dir
  44. $stdmode = "CanonCX";                   # Default mode_def (write-black):
  45. $pkdefault = "$prefix/texmf/fonts/canon300";
  46. $TEMPDIR = "/tmp";
  47. $name = $ARGV[0];
  48. $dpi = $ARGV[1];
  49. $bdpi = $ARGV[2];
  50. $mag = $ARGV[3];
  51. $mode = $ARGV[4];
  52.  
  53. $FINALname = "$pkbase/dpi$dpi/$name.pk";
  54. # cd to TEMPDIR if current dir is not writable:
  55. chdir($TEMPDIR) if (! -w ".");
  56. if (-f "$pkdefault/dpi$dpi/$name.pk") { # check if file exists
  57.   die "dpi$dpi/$name.pk already exists in $pkdefault\n";
  58. }
  59. if (-f "$pkbase/dpi$dpi/$name.pk") {    # check if file exists
  60.   die "dpi$dpi/$name.pk already exists in $pkbase\n";
  61. }
  62. if (-f $FINALname) {
  63.   die "$FINALname already exists!\n";
  64. }
  65. if (! -w $pkbase) {
  66.   mkdir($pkbase, 755);
  67.   chmod 0755, $pkbase;
  68.   if (! -w $pkbase) {
  69.     die "Can't write to $pkbase\n";
  70.   }
  71. }
  72. if ($mode eq "") {
  73.   if ($bdpi = 300) {
  74.     $mode = $stdmode;
  75.   } elsif ($bdpi = 118) {
  76.     $mode = "sun";
  77.   } else {
  78.   die "I don't know the mode for $bdpi\n";
  79.   }
  80. }
  81.  
  82. &grokformat;
  83.  
  84. # redirect stdout to stderr
  85. open(SAVEOUT, ">&STDOUT");
  86. open(STDOUT, ">&STDERR");
  87. print "Running Metafont...\n";
  88. # the split gives an array which prevents perl from using the shell:
  89. $line = "virmf $fmt \\mode:=$mode; \\mag:=$mag; input $name";
  90. print "$line\n";
  91. system split(/\s/, $line);
  92. if (!-f "$name.${dpi}gf") {
  93.   $dpi++;
  94.   if (!-f "$name.${dpi}gf") { 
  95.     $dpi--; $dpi--;
  96.     if (!-f "$name.${dpi}gf") { 
  97.       die "Metafont failed to create $name.${dpi}gf\n";
  98.     }
  99.   }
  100. }
  101. system "gftopk ./$name.${dpi}gf";
  102. die "gftopk failed on $name.${dpi}gf\n" unless (-f "$name.${dpi}pk");
  103. if (! -d "$pkbase/dpi$dpi") {   # make the directory:
  104.   mkdir("$pkbase/dpi$dpi",755);
  105.   chmod 0755, "$pkbase/dpi$dpi";
  106. }
  107. system "mv $name.${dpi}pk $pkbase/dpi$dpi/$name.pk";
  108. chmod 0644, "$pkbase/dpi$dpi/$name.pk";
  109. if (! $mfpic) {
  110.   system "mv $name.tfm $base/tfm";
  111.   chmod 0644, "$base/tfm/$name.tfm";
  112. }
  113. unlink "$name.${dpi}gf";
  114. unlink "$name.mf" if ($name =~ /^dc/);
  115.  
  116. # tell dvipsk where the pk file is:
  117. print SAVEOUT "$pkbase/dpi$dpi/$name.pk\n";
  118.  
  119.  
  120. exit(0);
  121.  
  122.  
  123. sub grokformat {
  124.   # See what fmt (if any) to use:
  125.   if ($plain) {         # -plain option
  126.     $fmt = '&plain';
  127.   } elsif ($name =~ /^cm/) {    # computer modern
  128.     $fmt = '&cmbase';
  129.   } elsif ($name =~ /^dc/) {    # DC fonts
  130.     $fmt = '&dxbase';
  131.     # Create the .mf file in current directory:
  132.     $name =~ m/^([a-zA-Z]+)(\d+)$/ || die "Error in dc font name: $name\n";
  133.     $basename = $1;
  134.     $designsize = $2;
  135.     open(MFFILE, ">$name.mf");
  136.     print MFFILE <<END;
  137. if unknown dxbase: input dxbase fi;
  138. gensize:=$designsize;
  139. generate $basename
  140. END
  141.     close (MFFILE);
  142.   } elsif (($name =~ /circle/)  || # latex circle fonts
  143.            ($name =~ /^line/)   || # latex line fonts
  144.            ($name =~ /^chess/)  || # chess font
  145.            ($name =~ /^knot/)   || # Celtic knotwork fonts
  146.            ($name =~ /^bbold/)  || # blackboard bold font
  147.            ($name =~ /^pn/)     || # Pandora fonts
  148.            ($name =~ /^uic/)    || # modified Pandora fonts
  149.            ($name =~ /^blackletter/) || # blackletter
  150.            ($name =~ /^manfnt/) || # TeX and METAFONT manuals special font
  151.            ($name =~ /^ark/)    || # hands and pencils
  152.            ($name =~ /^dingbat/)|| # nice borders
  153.            ($name =~ /^font29/)  || # large headings font
  154.            ($name =~ /^beam/)   || # music font
  155.            ($name =~ /^music/)  || # music font
  156.            ($name =~ /^slur/))   { # music font
  157.     $fmt = '&plain';
  158.   } elsif ($name =~ /^logo/) {  # logo font
  159.     $fmt = '&logo';
  160.   } elsif ($name =~ /^eu/) {    # Euler fonts
  161.     $fmt = '&plain';
  162.   } else {                      # some other font - use cmbase
  163.     $fmt = '&cmbase';
  164.   }
  165.   # mfpic hack! If the mf file is in current dir, and contains
  166.   # the string "graphbase" then its an mfpic file, so use plain base:
  167.   if (-r "$name.mf") {
  168.     system "egrep -s 'graphbase' $name.mf";
  169.     if ($? == 0) {
  170.       $mfpic = 1;
  171.       $fmt = '&plain';
  172.       $pkbase = ".";
  173.     }
  174.   }
  175. }
  176.