home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / fontutils-0.6-base.tgz / fontutils-0.6-base.tar / fsf / fontutils / bzrto / input-ccc.c < prev    next >
C/C++ Source or Header  |  1992-10-11  |  5KB  |  173 lines

  1. /* input-ccc.c: control the CCC parsing by Bison.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include "encoding.h"
  22.  
  23. #include "char.h"
  24. #include "main.h"
  25.  
  26. #include "input-ccc.h"
  27.  
  28.  
  29. /* The main input file and its name.  */
  30. FILE *ccc_file;
  31. string ccc_filename;
  32.  
  33. /* The information we've collected about the characters.  */
  34. bzr_char_type **chars;
  35.  
  36. /* The information for resolving various CCC units of measure.  */
  37. ccc_fontinfo_type ccc_fontinfo;
  38.  
  39. /* Set as we parse.  */
  40. ccc_type *ccc_chars[MAX_CHARCODE + 1];
  41.  
  42. /* Go through all of CHARS, setting the various components in the return
  43.    struct.  Some defaults are taken from TFM_INFO (if it's non-null),
  44.    and the global `encoding_info'.  */
  45.  
  46. static ccc_fontinfo_type
  47. get_ccc_fontinfo (real design_size, bzr_char_type *chars[],
  48.                   tfm_global_info_type *tfm_info)
  49. {
  50.   ccc_fontinfo_type ccc_info; /* What we'll return.  */
  51.   unsigned this_char;
  52.   int font_height;
  53.   boolean cap_height_found = false;
  54.   boolean xheight_found = false;
  55.  
  56.   /* The designsize is always present.  */
  57.   ccc_info.design_size = design_size;
  58.   
  59.   /* If the `quad' parameter is not present in TFM_INFO to define the
  60.      font's em space, use the design size.  */
  61.   ccc_info.em
  62.     = tfm_info
  63.       ? TFM_SAFE_FONTDIMEN (*tfm_info, TFM_QUAD_PARAMETER, design_size)
  64.       : design_size;
  65.  
  66.   /* If the `xheight' parameter is present in TFM_INFO, use it.  */
  67.   if (tfm_info && TFM_XHEIGHT_PARAMETER <= TFM_FONTDIMEN_COUNT (*tfm_info))
  68.     {
  69.       ccc_info.xheight = TFM_FONTDIMEN (*tfm_info, TFM_XHEIGHT_PARAMETER);
  70.       xheight_found = true;
  71.     }
  72.  
  73.   /* For the cap_height and font depth (and maybe for the xheight) we
  74.      must go through all the characters, so initialize.  */
  75.   ccc_info.cap_height = ccc_info.font_depth = font_height = INT_MIN;
  76.  
  77.   for (this_char = 0; this_char < MAX_CHARCODE; this_char++)
  78.     {
  79.       if (chars[this_char])
  80.         {
  81.           bzr_char_type c = *chars[this_char];
  82.           int char_height = CHAR_HEIGHT (c);
  83.           int char_depth = CHAR_DEPTH (c);
  84.           string char_name = ENCODING_CHAR_NAME (encoding_info, this_char);
  85.  
  86.           if (char_height > font_height) 
  87.             font_height = char_height;
  88.  
  89.           if (char_depth > ccc_info.font_depth) 
  90.             ccc_info.font_depth = char_depth;
  91.  
  92.           /* If it's a letter from which we can find the font's
  93.              cap_height, use it.  Don't use `F' et al. because they
  94.              might have serifs that go above the height of the stem.  */
  95.           if (!cap_height_found && char_name[1] == 0
  96.               && (*char_name == 'B'
  97.                   || *char_name == 'D'
  98.                   || *char_name == 'H'
  99.                   || *char_name == 'P'
  100.                   || *char_name == 'R'
  101.                   || *char_name == 'X'))
  102.             {
  103.               ccc_info.cap_height = char_height;
  104.               cap_height_found = true;
  105.             }
  106.  
  107.           /* If we haven't found the x-height yet, and `this_char' is a
  108.              letter from which we can determined it, use it.  */
  109.           if (!xheight_found && char_name[1] == 0
  110.               && (*char_name == 'u'
  111.                   || *char_name == 'v'
  112.                   || *char_name == 'w'
  113.                   || *char_name == 'x'
  114.                   || *char_name == 'y'
  115.                   || *char_name == 'z'))
  116.             {
  117.               ccc_info.xheight = char_height;
  118.               xheight_found = true;
  119.             }
  120.         }
  121.     }
  122.   
  123.   /* Having gone through all the characters, if we haven't been able to
  124.      determine the cap height, use the maximum font height.  */
  125.   if (!cap_height_found)
  126.     ccc_info.cap_height = font_height;
  127.   
  128.   /* Similarly for the x-height.  */
  129.   if (!xheight_found)
  130.     ccc_info.xheight = .6 * font_height;
  131.  
  132.   return ccc_info;
  133. }
  134.  
  135. /* If the CCC file `IN_FILENAME' (extended with `.ccc' if necessary)
  136.    exists, read it, updating CHARS_ARG.  Default information for some
  137.    CCC dimensions comes from TFM_INFO.
  138.    
  139.    If `IN_FILENAME' isn't readable, complain unless WARNING_P is false.  */
  140.  
  141. ccc_type **
  142. parse_ccc_file (string in_filename, bzr_char_type *chars_arg[],
  143.         tfm_global_info_type *tfm_info, real design_size,
  144.                 boolean warning_p)
  145. {
  146.   string ccc_name = extend_filename (in_filename, "ccc");
  147.  
  148.   ccc_file = fopen (ccc_name, "r");
  149.  
  150.   if (ccc_file == NULL)
  151.     {
  152.       if (warning_p)
  153.         perror (ccc_name);
  154.     }
  155.   else
  156.     {
  157.       extern int yyparse ();
  158.       
  159.       /* We have to use these globals, since we can't alter `yyparse's
  160.          signature.  */
  161.       ccc_fontinfo = get_ccc_fontinfo (design_size, chars_arg, tfm_info);
  162.       ccc_filename = ccc_name;
  163.       chars = chars_arg;
  164.       
  165.       /* Parse the CCC source file.  */
  166.       yyparse ();
  167.  
  168.       xfclose (ccc_file, ccc_name);
  169.     }
  170.  
  171.   return ccc_chars;
  172. }
  173.