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 / tfm / tfm_kern.c < prev    next >
C/C++ Source or Header  |  1992-06-13  |  2KB  |  76 lines

  1. /* tfm_kern.c: deal with TFM kern lists.
  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 "list.h"
  22. #include "tfm.h"
  23.  
  24.  
  25. /* The character RIGHT may or may not be in the list of kerns already.  */
  26.  
  27. void
  28. tfm_set_kern (list_type *kern_table, charcode_type right, real k)
  29. {
  30.   unsigned this_right;
  31.   tfm_kern_type *new_kern;
  32.   
  33.   assert (kern_table != NULL);
  34.   
  35.   for (this_right = 0; this_right < LIST_SIZE (*kern_table); this_right++)
  36.     {
  37.       tfm_kern_type *kern = LIST_ELT (*kern_table, this_right);
  38.  
  39.       if (kern->character == right)
  40.     { /* Already there, just replace the value.  */
  41.       kern->kern = k;
  42.       return;
  43.     }
  44.     }
  45.  
  46.   /* RIGHT wasn't in the existing list.  Add it to the end.  */
  47.   new_kern = LIST_TAPPEND (kern_table, tfm_kern_type);
  48.   new_kern->character = right;
  49.   new_kern->kern = k;
  50. }
  51.  
  52. /* Find the kern between the characters LEFT and RIGHT.  (Return zero if
  53.    none such.)  */ 
  54.  
  55. real
  56. tfm_get_kern (tfm_char_type left, charcode_type right)
  57. {
  58.   list_type kern_table;
  59.   unsigned r;
  60.   
  61.   if (!TFM_CHAR_EXISTS (left))
  62.     return 0.0;
  63.   
  64.   kern_table = left.kern;
  65.  
  66.   for (r = 0; r < LIST_SIZE (kern_table); r++)
  67.     {
  68.       tfm_kern_type *kern = LIST_ELT (kern_table, r);
  69.  
  70.       if (kern->character == right)
  71.     return kern->kern;
  72.     }
  73.  
  74.   return 0.0;
  75. }
  76.