home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / stex2-18.zip / SeeTeX / Fonts / build-fm.c next >
C/C++ Source or Header  |  1990-02-08  |  6KB  |  241 lines

  1. /*
  2.  * Copyright 1989 Dirk Grunwald
  3.  * 
  4.  * Permission to use, copy, modify, distribute, and sell this software
  5.  * and its documentation for any purpose is hereby granted without fee,
  6.  * provided that the above copyright notice appear in all copies and that
  7.  * both that copyright notice and this permission notice appear in
  8.  * supporting documentation, and that the name of Dirk Grunwald or M.I.T.
  9.  * not be used in advertising or publicity pertaining to distribution of
  10.  * the software without specific, written prior permission.  Dirk
  11.  * Grunwald and M.I.T. makes no representations about the suitability of
  12.  * this software for any purpose.  It is provided "as is" without express
  13.  * or implied warranty.
  14.  * 
  15.  * DIRK GRUNWALD AND M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL M.I.T.  BE LIABLE FOR ANY SPECIAL, INDIRECT
  18.  * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  19.  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  20.  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  21.  * OR PERFORMANCE OF THIS SOFTWARE.
  22.  * 
  23.  * Author:
  24.  *     Dr. Dirk Grunwald
  25.  *     Dept. of Computer Science
  26.  *     Campus Box 430
  27.  *     Univ. of Colorado, Boulder
  28.  *     Boulder, CO 80309
  29.  * 
  30.  *     grunwald@colorado.edu
  31.  *     
  32.  */ 
  33. #include <stdio.h>
  34. #include <string.h>
  35.  
  36. typedef struct FontStruct Font;
  37.  
  38. struct FontStruct {
  39.   char *name;
  40.   unsigned int scale;
  41.   unsigned int extension;
  42.   Font *next;
  43. };
  44.  
  45. unsigned int Dpi = 85;
  46. unsigned int AndMag = 1440;
  47. char *Mode = "sun";
  48.  
  49. int    DviBlackness = -1;
  50. int    DviMag = 1000;
  51. int    DviDsz = 1000;
  52. char    *ProgName;
  53. int    ShowSnf = 0;
  54. int    UserMag = 1000;
  55.  
  56. long Numerator = 25400000;
  57. long Denomonator = 473628272;
  58.  
  59. #define TWOTO16    0x10000
  60. #define TWOTO24 16777216
  61. #define PTPI 72.27
  62.  
  63. Font *FontList = 0;
  64.  
  65. static
  66. int suffix(scale, usermag)
  67. int scale;
  68. int usermag;
  69. {
  70.   double foo;
  71.   double dsuffix;
  72. #define    ROUND(f) ((int) ((f) < 0.0 ? (f) - 0.5 : (f) + 0.5))
  73.   int isuffix;
  74.  
  75. #if 0
  76.    fprintf(stdout,  "IN: mag = %d, scale = %d, Dpi = %d\n",
  77.         usermag, scale, Dpi);
  78. #endif
  79.  
  80.     foo = scale * usermag;
  81.     dsuffix = Dpi * ROUND(foo);
  82.   dsuffix /= 1000;
  83.   dsuffix /= 1000;
  84.  
  85.     isuffix = ROUND(dsuffix);
  86.  
  87. #if 0
  88.  
  89.     fprintf(stdout,  " foo = %f, OUT: dsuffix = %f, isuffix = %d\n",
  90.         foo, dsuffix,isuffix);
  91. #endif
  92.  
  93.     return(isuffix);
  94. }
  95.  
  96. void
  97. AddFont(name, scale, usermag)
  98. char *name;
  99. int scale;
  100. int usermag;
  101. {
  102.   if ( name ) {
  103.     Font *font = (Font *) malloc( sizeof(Font) );
  104.     int len = strlen(name)+1;
  105.  
  106.     font -> name = (char *) malloc( len+1 );
  107.     strncpy(font -> name, name, len);
  108.     font -> scale = scale;
  109.     font -> extension = suffix(scale, usermag);
  110.     font -> next = FontList;
  111.     FontList = font;
  112.   }
  113. }
  114.  
  115. int
  116. InFontList(name,scale,mag)
  117. char *name;
  118. int scale;
  119. int mag;
  120. {
  121.   Font *p = FontList;
  122.   int extension = suffix(scale,mag);
  123.   while ( p ) {
  124.     if ( p -> extension == extension && strcmp(p -> name, name) == 0 ) {
  125.       return(1);
  126.     }
  127.     p = p -> next;
  128.   }
  129.   return(0);
  130. }
  131.  
  132. main(argc, argv)
  133. int argc;
  134. char **argv;
  135. {
  136.   int arg;
  137.   for (arg = 1; arg < argc; arg++ ) {
  138.     if ( strcmp(argv[arg],"-dpi") == 0 ) {
  139.       arg++;
  140.       Dpi = atoi(argv[arg]);
  141.     }
  142.     else if (strcmp(argv[arg],"-andMag") == 0 ) {
  143.       arg++;
  144.       AndMag = atoi(argv[arg]);
  145.     }
  146.   }
  147.   
  148.   /* build the list of fonts */
  149.   
  150.   while (! feof(stdin) ) {
  151.     static char fontName[128];
  152.     static char trash[128];
  153.     int scale;
  154.     int number;
  155.  
  156.     bzero(fontName,128);
  157.     bzero(trash,128);
  158.     number = fscanf(stdin, " %s %s %d\n",
  159.             fontName, trash, &scale);
  160.  
  161.     if ( strcmp(trash,"scaled") != 0 ) {
  162.       fprintf(stderr,"Bogus line: got %s %s %d\n", fontName, trash, scale);
  163.     }
  164.  
  165.     if ( number == 3 ) {
  166.       if ( ! InFontList(fontName, scale, 1000) ) {
  167.     AddFont(fontName, scale, 1000);
  168.       }
  169.       if ( ! InFontList(fontName, scale, AndMag) ) {
  170.     AddFont(fontName, scale, AndMag);
  171.       }
  172.     }
  173.     else {
  174.       fprintf(stderr,"Wrong number(%d): got %s %s %d\n",
  175.           number, fontName, trash, scale);
  176.     }
  177.   }
  178.   
  179.   fprintf(stdout,".SUFFIXES: .snf .bdf .pk .gf .mf\n\n");
  180.   fprintf(stdout,"goals: snf-fonts\n\techo Done\n");
  181.   
  182.   /* generate the rules to build PK files in two different sizes */
  183.   {
  184.     Font *p = FontList;
  185.     while ( p ) {
  186.       char* name = p -> name;
  187.       int scale = p -> scale;
  188.       int extension = p -> extension;
  189.       
  190.       fprintf(stdout, "#\n# NAME=%s\n# SCALE = %d\n# EXTENSION = %d\n#\n",
  191.           name, scale, extension);
  192.       
  193.       /* MF -> PK */
  194.       
  195.       fprintf(stdout,"%s.%dpk:\n", name, extension, name);
  196.       fprintf(stdout,"    -mf '\\mode:=%s;mag=%d/1000;\input %s'\n",
  197.           Mode, scale, name);
  198.       fprintf(stdout,"    -gftopk %s.%dgf && rm -f %s.%dgf\n",
  199.           name, extension, name, extension);
  200.       
  201.       /* PK -> SNF */
  202.       
  203.       fprintf(stdout,"%s.%d.snf:    %s.%dpk\n",
  204.           name, extension, name, extension);
  205.       fprintf(stdout,"    -mftobdf -dpi %d %s.%dpk\n",
  206.           Dpi, name, extension);
  207.       fprintf(stdout,"    bdftosnf < %s.%d.bdf > %s.%d.snf\n",
  208.           name, extension, name, extension);
  209.       
  210.       p = p -> next;
  211.     }
  212.   }
  213.   /* generate the goal line for PK files */
  214.   {
  215.     Font *p = FontList;
  216.     fprintf(stdout,"pk-fonts:\\\n");
  217.     while ( p ) {
  218.       char* name = p -> name;
  219.       int extension = p -> extension;
  220.       
  221.       fprintf(stdout, "\t%s.%dpk\\\n", name, extension);
  222.       p = p -> next;
  223.     }
  224.     fprintf(stdout,"#    end of pk-fonts\n");    
  225.   }
  226.   
  227.   /* generate the goal line for SNF files */
  228.   {
  229.     Font *p = FontList;
  230.     fprintf(stdout,"snf-fonts:\\\n");
  231.     while ( p ) {
  232.       char* name = p -> name;
  233.       int extension = p -> extension;
  234.       
  235.       fprintf(stdout, "\t%s.%d.snf\\\n", name, extension);
  236.       p = p -> next;
  237.     }
  238.     fprintf(stdout,"#    end of snf-fonts\n");    
  239.   }
  240. }
  241.