home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / useful / dist / text / tex / pastex / macros / latex / nfss2 / psmetrics / vpltovpl.c < prev    next >
C/C++ Source or Header  |  1993-07-29  |  29KB  |  1,042 lines

  1. #define VERSION "10 (July 1993)"
  2.  
  3. /*
  4. vpltovpl.c. version 1. december 1990
  5.             version 2. january 1992
  6.             version 3. may 1992
  7.             version 4. dec 1992
  8.         version 5. dec 28 1992
  9.         version 6. may 20 1993. removed progress indicators. 
  10.                         put back with -DDEBUG
  11.         version 7. may 25 1993. cleaned up and re-used generation of 
  12.                         extra file for dotlessj only (activated by -DSPECIAL)
  13.         version 8. july 12 1993. redo some of virtual font code;
  14.                        and generate the dotlessj missing char with vpl
  15.                rather than using a tiny PS font
  16.         version 9. july 14 1993. add in code to check if we are an
  17.                     artificial small caps font, and do things right for
  18.             that
  19.         version 10. july 1993. corrected aogonek
  20.  
  21. by Sebastian Rahtz
  22.  
  23. spqr@minster.york.ac.uk
  24.  
  25. (thanks also to Alexander Samarin for suggestions;
  26. and Michael Doob and Craig Platt for ideas on how to do dotlessj)
  27.  
  28. Take an existing .vpl file, create extra characters for new composite
  29. characters for extended TeX layout, and add them to the end of the
  30. file
  31.  
  32. [
  33. where necessary write a tiny new font metric file for extra characters;
  34. abandoned in version 8
  35. ]
  36.  
  37. Parameters: 1) name of vpl file (which is going to be overwritten)
  38.             2) name of original AFM file
  39.  
  40.  
  41. a quite dreadfully written C program converted from an Icon program:
  42. --------------------------------------------------------
  43. # vplovx.icn version 1
  44. #
  45. # Sebastian Rahtz October 1990
  46. #
  47. --------------------------------------------------------
  48.  
  49. bits pinched from other people. notably the `findchar' and `newchar'
  50. functions, with associated material, taken from afm2tfm almost verbatim
  51.  
  52. */
  53. #include "vpltovpl.h"
  54.  
  55.  
  56. char vplname[LINELENGTH], afmname[LINELENGTH];
  57. char command[LINELENGTH], plname[LINELENGTH];
  58. char basefont[100];
  59. float uppergap,lowergap = -1.0 ;
  60. FILE *vplfile, *afmfile, *plfile;
  61. char entry[MAXENTRY];
  62. int SCFont = 0;
  63. float fontat=.8;
  64.  
  65. struct character {
  66.     struct character *next;
  67.     char *name;
  68.     float width,height,depth,charic;
  69.     } *chars,*vchars[MAXCHARS] ;
  70.     
  71. /*---------------------------*/
  72. struct character * findchar(p)
  73. char *p ;
  74. {
  75.    register struct character *ai ;
  76.  
  77.    for (ai=chars; ai; ai = ai->next)
  78. {
  79.       if (strcmp(p, ai->name)==0)
  80.          return(ai) ;
  81. }
  82.    return(NULL) ;
  83. }
  84.  
  85. /*--------------------------*/
  86. float width(key)
  87. char *key;
  88. {
  89.  register struct character *ai;
  90.  ai = findchar(key);
  91.  if (ai == NULL)
  92. {
  93. #ifdef DEBUG
  94.     fprintf(stderr,"No width for %s\n",key);
  95. #endif
  96.     return (0);
  97. }
  98.  else
  99.     return (ai->width);
  100. }
  101.  
  102. /*--------------------------*/
  103. float height(key) 
  104. char *key;
  105. {
  106.  register struct character *ai;
  107.  ai = findchar(key);
  108.  if (ai == NULL)
  109. {
  110. #ifdef DEBUG
  111.     fprintf(stderr,"No height for %s\n",key);
  112. #endif
  113.     return (0);
  114. }
  115.  else
  116.     return (ai->height);
  117. }
  118.  
  119.  
  120. /*--------------------------*/
  121. float depth(key) 
  122. char *key;
  123. {
  124.  register struct character *ai;
  125.  ai = findchar(key);
  126.  if (ai == NULL)
  127. {
  128. #ifdef DEBUG
  129.     fprintf(stderr,"No depth for %s\n",key);
  130. #endif
  131.     return (0);
  132. }
  133.  else
  134.     return (ai->depth);
  135. }
  136.  
  137. /*--------------------------*/
  138. float charic(key) 
  139. char *key;
  140. {
  141.  register struct character *ai;
  142.  ai = findchar(key);
  143.  if (ai == NULL)
  144. {
  145. #ifdef DEBUG
  146.     fprintf(stderr,"No charic for %s\n",key);
  147. #endif
  148.     return (0);
  149. }
  150.  else
  151.     return (ai->charic);
  152. }
  153.  
  154. /*--------------------------*/
  155. void error(s)
  156. register char *s ;
  157. {
  158.    extern void exit() ;
  159.  
  160.    (void)fprintf(stderr, "%s\n", s) ;
  161.    if (*s == '!')
  162.       exit(1) ;
  163. }
  164. /*--------------------------*/
  165. char * mymalloc(len)
  166. unsigned long len ;
  167. {   
  168.    register char *p ;
  169.    int i ;
  170. #ifdef SMALLMALLOC
  171.    if (len > 65500L)
  172.       error("! can't allocate more than 64K!") ;
  173. #endif
  174.    p = malloc((unsigned)len) ;
  175.    if (p==NULL)
  176.       error("! out of memory") ;
  177.    for (i=0; i<len; i++)
  178.       p[i] = 0 ;
  179.    return(p) ;
  180. }
  181.  
  182. /*--------------------------*/
  183. char * namespace() {
  184.    register char *q;
  185.    q = mymalloc(6) ;
  186.    return(q) ;
  187. }
  188.  
  189. /*--------------------------*/
  190. struct character * anewchar() {
  191.    register struct character *ai ;
  192.    ai = (struct character *)mymalloc((unsigned long)sizeof(struct character)) ;
  193.    ai->width = 0 ;
  194.    ai->name = NULL ;
  195.    ai->height = 0 ;
  196.    ai->depth = 0 ;
  197.    ai->charic = 0 ;
  198.    ai->next = chars ;
  199.    chars = ai ;
  200.    return(ai) ;
  201. }
  202.  
  203. /*--------------------------*/
  204. int count(line)
  205. char *line;
  206. {
  207. /* count the parentheses in a line, add +1 for a '(', -1 for a ')' */
  208.   char *p;
  209.   int cnt = 0;
  210.  
  211.   for (p=line; *p; p++) {
  212.     if (*p=='(')
  213.       cnt += 1;
  214.     if (*p==')')
  215.       cnt -= 1;
  216.   }
  217.   return(cnt);
  218. }
  219.  
  220. #ifndef MSDOS
  221. /*--------------------------*/
  222.  
  223. float max(float a, float b)
  224. {
  225. if (a > b )
  226.     return (a) ;
  227. else 
  228.     return (b) ;
  229. #endif
  230. /*--------------------------*/
  231. void vchar(charnum,charname,charwd,charht,chardp,
  232.            charic,oldchar,accent,moveright,moveup,WhichFont)
  233. int charnum; /*  number of new character*/
  234. char *charname; /* name of new character*/
  235. float   charwd; /*   width of character*/
  236. float   charht; /*   height of character*/
  237. float   chardp; /*   depth of character*/
  238. float   charic; /*   italic correction of character*/
  239. char    *oldchar; /*  number of old character*/
  240. char    *accent; /*   string of accent number*/
  241. float   moveright; /* (can be negative)*/
  242. float   moveup; /*    (can be negative)*/
  243. int WhichFont ; /* for small caps. 0 or 1 */
  244. {
  245. #ifdef DEBUG
  246. fprintf(stderr,"generate character %s from %s and %s: %f %f\n",
  247. charname,oldchar,accent,moveup,moveright);
  248. #endif
  249. fprintf(vplfile,"(CHARACTER O %d (comment %s: %.2f %.2f)\n",charnum,charname,moveright,moveup);
  250.  
  251. if (charwd  != 0 )
  252.      fprintf(vplfile,"   (CHARWD R %.2f)\n",charwd);
  253. if (charht  != 0 )
  254.      fprintf(vplfile,"   (CHARHT R %.2f)\n",charht);
  255. if (chardp  != 0 )
  256.      fprintf(vplfile,"   (CHARDP R %.2f)\n",chardp);
  257. if (charic  != 0 )
  258.      fprintf(vplfile,"   (CHARIC R %.2f)\n",charic);
  259. /* WhichFont will be 0 normally, but 1 if we are a small caps font */
  260. fprintf(vplfile,"   (MAP (SELECTFONT D %d)\n",WhichFont);
  261. fprintf(vplfile,"      (SETCHAR %s)\n",oldchar);
  262. if (moveright  != 0.0)
  263.      fprintf(vplfile,"      (MOVERIGHT R %.2f)\n",-moveright);
  264. if (moveup  != 0.0  )
  265.      fprintf(vplfile,"      (MOVEUP R %.2f)\n",moveup);
  266. fprintf(vplfile,"      (SETCHAR %s)\n",accent);
  267. fprintf(vplfile,"      )\n");
  268. fprintf(vplfile,"   )\n");
  269. }
  270.  
  271. /*----------------------*/
  272. void upperacc(number,c,accent,name)
  273. int number;
  274. char *c,*accent,*name;
  275. {
  276. float xdepth,xheight,xmoveup;
  277. #ifdef DEBUG
  278. fprintf(vplfile,"(COMMENT UPPERACC with  %d: %s, %s, %s )\n",number,c,accent,name);
  279. #endif
  280. xdepth=depth(accent);
  281. if (xdepth > 0.0) 
  282. /*
  283. # its an underneath accent
  284. # no need to move up
  285. */
  286.  { 
  287.    xheight=height(c);
  288.    xmoveup=0.0;
  289.  }
  290. else
  291.  {
  292.    xdepth=depth(c);
  293.    xheight=height(accent);
  294.    xmoveup=uppergap;
  295.   }
  296. vchar(number,
  297.     name,
  298.     width(c),
  299.     xheight+xmoveup,
  300.     xdepth,
  301.     charic(c),
  302.     c,
  303.     accent,
  304.     (float) ( ( width(c) / 2.0  )   + (  width(accent) / 2.0 ) ),
  305.     xmoveup,0);
  306. }
  307. /*--------------------------*/
  308. void loweracc(number,c,accent,name,movedown)
  309. int number;
  310. float movedown;
  311. char *c,*accent,*name;
  312. {
  313. float moveup,adepth,xheight,xdepth,xmoveup;
  314. float CDepth,CHeight,CWidth,ADepth,AHeight,AWidth,CIc;
  315. char CharName[5];
  316. char LastChar;
  317. strcpy(CharName,c);
  318. /* if we are in small caps, uppercase the character name */
  319. if (SCFont == 1 )
  320.   {
  321.   LastChar=CharName[strlen(CharName)-1]; 
  322.   CharName[strlen(CharName)-1]=toupper(LastChar);
  323.   /* 
  324.   for a small caps font, we need to reduce the dimensions to the size
  325.   of the small caps font; we have derived this from the vpl file earlier
  326.   as `fontat'
  327.   */
  328.   ADepth=depth(accent) * fontat;
  329.   AWidth=width(accent) * fontat  ;
  330.   AHeight=height(accent) * fontat + SC_ACCENT_RAISE ;
  331.   CWidth=width(CharName) * fontat  ;
  332.   CHeight=height(CharName) * fontat  ;
  333.   CDepth=depth(CharName) * fontat  ;
  334.   CIc=charic(CharName) * fontat  ;
  335. }
  336. else
  337.   {
  338.   ADepth=depth(accent);
  339.   AWidth=width(accent) ;
  340.   AHeight=height(accent) ;
  341.   CWidth=width(CharName) ;
  342.   CHeight=height(CharName) ;
  343.   CDepth=depth(CharName) ;
  344.   CIc=charic(CharName) ;
  345. }
  346. #ifdef DEBUG
  347. fprintf(vplfile,"(COMMENT LOWERACC with  %d: %s, %s, %s %f)\n",number,CharName,accent,name,movedown);
  348. #endif
  349. xdepth=ADepth;
  350. if (xdepth > 0.0 )
  351.  { 
  352.    xheight=CHeight;
  353.    xmoveup=0.0;
  354.  }
  355. else
  356.  {
  357.    xdepth=CDepth;
  358.    xheight=AHeight;
  359.    xmov