"Fossies" - the Fresh Open Source Software Archive

Member "ttf2pt1-3.4.4/app/TeX/cjk-latex-config" (9 Aug 2002, 8461 Bytes) of package /linux/misc/old/ttf2pt1-3.4.4.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl -w
    2 #
    3 # Copyright (c) 2002 SuSE Linux AG, Nuernberg, Germany.  All rights reserved.
    4 #
    5 # Author: Mike Fabian <mfabian@suse.de>, 2002
    6 #
    7 
    8 use English;
    9 use Getopt::Long;
   10 
   11 # check if we are started as root
   12 # only one of UID and USER must be set correctly
   13 
   14 if ($UID != 0 && $ENV{USER} !~ /root/) {
   15     print "You must be root to start $0\n";
   16     exit 1;
   17 }
   18 
   19 if (system ("rpm -q freetype-tools >/dev/null 2>&1") != 0) {
   20   print "freetype-tools package missing, exiting.\n";
   21   exit 1;
   22 }
   23 
   24 
   25 sub usage {
   26   print "Usage: cjk-latex-config [--verbose|v] [--force|f] [--type1|t]\n";
   27   exit 1;
   28 }
   29 
   30 # Process command line options
   31 my %opt;
   32 unless (GetOptions(\%opt,
   33            'verbose|v', \$OPT_VERBOSE,
   34            'force|f',   \$OPT_FORCE,
   35            'type1|t',   \$OPT_TYPE1,
   36           )) {
   37   &usage();
   38   exit 1;
   39 }
   40 
   41 # to make sure ttf2tfm finds the .sdf files:
   42 system("texhash");
   43 
   44 $tfm_created = 0;
   45 $type1_created = 0;
   46 
   47 system("mkdir -p /usr/share/texmf/fonts/truetype/");
   48 
   49 open (TTFONTS_MAP, "/etc/ttf2pk/ttfonts.map");
   50 
   51 while (<TTFONTS_MAP>) {
   52   
   53   chomp($ARG);
   54   
   55   if ($ARG =~ /\@[a-zA-Z0-9\/]+\@/) {
   56 
   57     if($OPT_VERBOSE) {
   58       print "----------------------------------------------------------------------\n";
   59       print "$ARG\n";
   60     }
   61     
   62     @fields = split(/\s+/, $ARG);
   63     
   64     $tt_dir = "/usr/X11R6/lib/X11/fonts/truetype/";
   65     $tt_basename = $fields[1];
   66     
   67     if ($fields[0] =~ /([^\s]+)\@[a-zA-Z0-9\/]+\@/) {
   68       $latex_font_name = $1;
   69     } else {
   70       print "can't find latex font name.\n";
   71       exit 1
   72     }
   73     
   74     if ($fields[0] =~ /\@([a-zA-Z0-9\/]+)\@/) {
   75       $sfd_name = $1;
   76       $sfd_name =~ /.*\/([a-zA-Z0-9]+)/;
   77       $sfd_basename = $1;
   78     } else {
   79       print "can't find sfd_name.\n";
   80       exit 1
   81     }
   82 
   83     if ($ARG =~ /Pid=([0-9]+)/) {
   84       $pid = "$1";
   85     } else {
   86       $pid = "3";
   87     }
   88 
   89     if ($ARG =~ /Eid=([0-9]+)/) {
   90       $eid = "$1";
   91     } else {
   92       $eid = "1";
   93     }
   94 
   95     if ($ARG =~ /Slant=([0-9.]+)/) {
   96       $slant = $1;
   97       $slant_opt = "-s $1";
   98     } else {
   99       $slant = 0;
  100       $slant_opt = "-s 0";
  101     }
  102 
  103     if ($ARG =~ /Rotate=(Yes)/) {
  104       $rotate = 1;
  105       $rotate_opt = "-x";
  106     } else {
  107       $rotate = 0;
  108       $rotate_opt = "";
  109     }
  110 
  111     if (-e "$tt_dir/$tt_basename") {
  112       symlink("$tt_dir/$tt_basename",
  113           "/usr/share/texmf/fonts/truetype/$tt_basename");
  114       $tfm_dir = "/usr/share/texmf/fonts/tfm/cjk-latex/";
  115       $type1_dir = "/usr/share/texmf/fonts/type1/cjk-latex/";
  116 
  117       if (0 != create_or_update_tfm ()) {
  118     print "creating .tfm failed.\n";
  119       }
  120       if ($OPT_TYPE1 && $slant == 0 && $rotate == 0) {
  121     if (0 != create_or_update_type1 ()) {
  122       print "creating type1 font failed.\n";
  123     }
  124       }
  125     }
  126   }
  127 }
  128 
  129 if ($type1_created) {
  130   $command = "cjk-latex-t1mapgen $type1_dir";
  131   if (0 != system ($command)) {
  132     print "$command failed.\n";
  133     exit 1;
  134   }
  135 }
  136 
  137 if ($tfm_created || $type1_created) {
  138   system("texhash");
  139 }
  140 
  141 
  142 exit 0;
  143 
  144 
  145 ######################################################################
  146 
  147 sub create_or_update_tfm {
  148   
  149   if ($OPT_FORCE ||
  150       mtime_differs_or_missing ("$tt_dir/$tt_basename",
  151                 "$tfm_dir/$sfd_basename/$latex_font_name/")) {
  152       
  153     if (0 != system ("mkdir -p $tfm_dir/$sfd_basename/$latex_font_name/")) {
  154       print "mkdir -p $tfm_dir/$sfd_basename/$latex_font_name/ failed.\n";
  155       exit 1;
  156     }
  157     if (! chdir ("$tfm_dir/$sfd_basename/$latex_font_name/")) {
  158       print "can't chdir to $tfm_dir/$sfd_basename/$latex_font_name/\n";
  159       exit 1;
  160     }
  161     
  162     $command = "ttf2tfm $tt_dir/$tt_basename ";
  163     unless ($OPT_VERBOSE) {
  164       $command .= " -q"; 
  165     }
  166     $command .= " -P $pid -E $eid $rotate_opt $slant_opt $latex_font_name\@$sfd_name\@";
  167     if ($OPT_VERBOSE) {
  168       print "$command\n";
  169     } else {
  170       $command .= " > /dev/null 2>&1";
  171       print "$latex_font_name\@$sfd_name\@: calling ttf2tfm ...\n";
  172     }
  173     if (0 != system($command)) {
  174       print "$command failed.\n";
  175       return 1;
  176     }
  177 
  178     # success, mark this by giving the created directory the same time stamp
  179     # as the TT-font:
  180     system("touch -r $tt_dir/$tt_basename $tfm_dir/$sfd_basename/$latex_font_name/");
  181     $tfm_created = 1;
  182     return 0; 
  183   }
  184   
  185 }
  186 
  187 ######################################################################
  188 
  189 sub create_or_update_type1 {
  190 
  191   if ($OPT_FORCE ||
  192       mtime_differs_or_missing ("$tt_dir/$tt_basename",
  193                 "$type1_dir/$sfd_basename/$latex_font_name/")) {
  194       
  195     if (0 != system ("mkdir -p $type1_dir/$sfd_basename/$latex_font_name/")) {
  196       print "mkdir -p $type1_dir/$sfd_basename/$latex_font_name/ failed.\n";
  197       exit 1;
  198     }
  199     if (! chdir ("$type1_dir/$sfd_basename/$latex_font_name/")) {
  200       print "can't chdir to $type1_dir/$sfd_basename/$latex_font_name/\n";
  201       exit 1;
  202     }
  203 
  204     if (grep(/$tt_basename/,("wadalab-gothic.ttf","watanabe-mincho.ttf"))) {
  205       print "$tt_basename does not work with ttf2pt1, skipping ...\n";
  206       return 0;
  207     }
  208     
  209     # disable smoothing of outlines for broken fonts
  210     # (for details see 'man ttf2pt1'):
  211     my $smoothing_opt = " ";
  212     if (grep(/$tt_basename/,("kochi-gothic.ttf"))) {
  213       print "$tt_basename broken, disabling smoothing of outlines.\n";
  214       $smoothing_opt = " -O s ";
  215     } 
  216     
  217     $sfd_file = "/usr/share/texmf/ttf2tfm/$sfd_basename.sfd";
  218     $map_file = `mktemp /tmp/cjk-latex-config-map.XXXXXX`;
  219     chomp $map_file;
  220     if ($map_file eq "") {
  221       print "mktemp /tmp/cjk-latex-config-map.XXXXXX failed.\n";
  222     }
  223     
  224     @planes = sfd2map($sfd_file,$map_file);
  225     if ($#planes == -1) {
  226       print "sfd2map($sfd_file,$map_file) failed.\n";
  227       return 1;
  228     }
  229     
  230     for my $plane (@planes) {
  231       if ($OPT_VERBOSE) {
  232     $command = "ttf2pt1 -W 99 ";
  233       } else {
  234     $command = "ttf2pt1 -W 0 ";
  235       }
  236       $command .= $smoothing_opt;
  237       $command .= " -p ft -b -G a -m h=5000 ";
  238       $command .= " -L $map_file+pid=$pid,eid=$eid,$plane ";
  239       $command .= " $tt_dir/$tt_basename $latex_font_name$plane";
  240       if ($OPT_VERBOSE) {
  241     print "$command\n";
  242       } else {
  243     $command .= " > /dev/null 2>&1";
  244     print "$latex_font_name\@$sfd_name\@, plane=$plane: calling ttf2pt1 ...\n";
  245       }
  246       if (0 != system($command)) {
  247     print "$command failed.\n";
  248     return 1;
  249       }      
  250     }
  251 
  252     unlink $map_file;
  253     
  254     # success, mark this by giving the created directory the same time stamp
  255     # as the TT-font:
  256     system("touch -r $tt_dir/$tt_basename $type1_dir/$sfd_basename/$latex_font_name/");
  257     $type1_created = 1;
  258     return 0;
  259   }
  260 }
  261 
  262 ######################################################################
  263 
  264 sub sfd2map {
  265   my($sfd_file,$map_file) = @_;
  266   if (! open (SFD, "<$sfd_file")) {
  267     print "cannot open $sfd_file\n";
  268     return ();
  269   }
  270   if (! open (MAP, ">$map_file")) {
  271     print "cannot open $map_file\n";
  272     close (SFD);
  273     return ();
  274   }
  275 
  276   my(@planes) = ();
  277 
  278   while (<SFD>) {
  279   
  280     if ( ! ($ARG =~ /^[[:space:]]*\#/)) {  # skip comment lines
  281 
  282       # handle plane numbers:
  283       if ( $ARG =~ /^([[:xdigit:]]{2})[[:space:]]*/ ) {
  284     $ARG =~ s/^([[:xdigit:]]{2})[[:space:]]*/   /;
  285     print MAP "plane $1\n";
  286     print MAP "at 0x00\n";
  287     $planes[$#planes + 1] = $1;
  288       }
  289     
  290       # remove continuation chars '\':
  291       $ARG =~ s/\\$//;
  292     
  293       $ARG =~ s/(0x[[:xdigit:]]{1,4})/$1,/g;
  294       # handle ranges like 0xF800_0xF8FF
  295       $ARG =~ s/(0x[[:xdigit:]]{1,4}),_/$1-/g;
  296     }
  297 
  298     print MAP $ARG;
  299 
  300   }
  301 
  302   close (MAP);
  303   close (SFD);
  304   return @planes;
  305 }
  306 
  307 
  308 # Returns true if the modification time of $f1 differs from
  309 # the modification time of $f2 
  310 sub mtime_differs {
  311   my($f1,$f2) = @_;
  312   if( -e $f1 && -e $f2) {
  313     local (@f1s) = stat ($f1);
  314     local (@f2s) = stat ($f2);
  315     return ($f1s[9] != $f2s[9]);
  316   } else {
  317     return 0;
  318   }
  319 }
  320 
  321 # Returns true if the modification time of $f1 differs from
  322 # the modification time of $f2 or if one of the files is missing
  323 sub mtime_differs_or_missing {
  324     my($f1,$f2) = @_;
  325     if (! -e $f1 || ! -e $f2 || mtime_differs($f1,$f2)) {
  326       return 1;
  327     } else {
  328       return 0;
  329     }
  330 }  
  331 
  332 # Returns true if $f1 is newer than $f2
  333 sub newer {
  334   my($f1,$f2) = @_;
  335   if( -e $f1 && -e $f2) {
  336     local (@f1s) = stat ($f1);
  337     local (@f2s) = stat ($f2);
  338     return ($f1s[9] > $f2s[9]);
  339   } else {
  340     return 0;
  341   }
  342 }
  343 
  344 # Returns true if $f1 is newer than $f2 or if one of the files is missing
  345 sub newer_or_missing {
  346     my($f1,$f2) = @_;
  347     if (! -e $f1 || ! -e $f2 || newer($f1,$f2)) {
  348       return 1;
  349     } else {
  350       return 0;
  351     }
  352 }