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 / xbfe / char.c < prev    next >
C/C++ Source or Header  |  1992-06-21  |  5KB  |  168 lines

  1. /* char.c: manipulate a TFM and bitmap character simultaneously.
  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 "xt-common.h"
  22. #include <X11/Xaw/Form.h>
  23.  
  24. #include "Bitmap.h"
  25. #include "font.h"
  26. #include "Item.h"
  27. #include "tfm.h"
  28.  
  29. #include "char.h"
  30. #include "kern.h"
  31. #include "main.h"
  32.  
  33.  
  34. static char_type *font_read_char (string, charcode_type);
  35. static void show_bitmap (Widget top, font_type *f, bitmap_type *b);
  36.  
  37.  
  38.  
  39. /* Read the TFM and bitmap character CODE from the font FONT_NAME, and
  40.    return a pointer to a filled-in character structure.  If the
  41.    character doesn't exist in either the TFM or bitmap file, return
  42.    NULL.  If we've already read the character don't read it again.  */
  43.  
  44. char_type *
  45. read_char (font_type f, charcode_type code)
  46. {
  47.   return FONT_CHAR (f, code)
  48.     ? 
  49.     : font_read_char (FONT_NAME (f), code);
  50. }  
  51.  
  52.  
  53. /* Return a pointer to the character CODE from the font named FONT.  If
  54.    the character doesn't exist in either the TFM or the bitmap file,
  55.    return NULL.  */
  56.  
  57. static char_type *
  58. font_read_char (string font, charcode_type code)
  59. {
  60.   char_type *font_char;
  61.   char_info_type *bitmap_info = get_char (font, code);
  62.   tfm_char_type *tfm_info = tfm_get_char (code);
  63.  
  64.   if (bitmap_info == NULL || tfm_info == NULL)
  65.     return NULL;
  66.  
  67.   /* OK, we'll have a character to return.  Fill in the `char_type'
  68.      structure.  */
  69.   font_char = XTALLOC1 (char_type);
  70.   
  71.   CHAR_BITMAP_INFO (*font_char) = *bitmap_info;
  72.   CHAR_TFM_INFO (*font_char) = *tfm_info;
  73.  
  74.   /* Copy the bitmap into fresh storage, so the original, which the
  75.      library routines store, isn't corrupted.  */
  76.   BCHAR_BITMAP (*font_char) = copy_bitmap (BCHAR_BITMAP (*font_char));
  77.   
  78.   return font_char;
  79. }
  80.  
  81.  
  82.  
  83. /* Make C the current character in the font F, and update the display. 
  84.    The widget TOP is the Form that manages all the other widgets.  */
  85.  
  86. void
  87. show_char (Widget top, font_type *f, char_type *c)
  88. {
  89.   Widget box_widget, item_widget, lsb_widget, rsb_widget;
  90.   WidgetList old_kerns;
  91.   Cardinal old_kern_count;
  92.   unsigned k;
  93.   list_type kern_list;
  94.   char value[MAX_INT_LENGTH];
  95.   char_info_type bitmap_info = CHAR_BITMAP_INFO (*c);
  96.   charcode_type code = CHARCODE (CHAR_BITMAP_INFO (*c));
  97.  
  98.   /* We assign to this below.  */
  99.   Arg item_args[] = { { XtNvalue, (XtArgVal) NULL } };
  100.  
  101.   /* Change the string displayed in the current character widget.  */
  102.   item_widget = XFIND_WIDGET (top, "current character item");
  103.   sprintf (value, "%u", code);
  104.   XTASSIGN_ARG (item_args[0], value);
  105.   XtSetValues (item_widget, XTARG (item_args));
  106.   
  107.   lsb_widget = XFIND_WIDGET (top, "lsb item");
  108.   sprintf (value, "%d", CHAR_LSB (bitmap_info));
  109.   XTASSIGN_ARG (item_args[0], value);
  110.   XtSetValues (lsb_widget, XTARG (item_args));
  111.   
  112.   rsb_widget = XFIND_WIDGET (top, "rsb item");
  113.   sprintf (value, "%d", CHAR_RSB (bitmap_info));
  114.   XTASSIGN_ARG (item_args[0], value);
  115.   XtSetValues (rsb_widget, XTARG (item_args));
  116.  
  117.   /* Show the bitmap on the display.  */
  118.   show_bitmap (top, f, &BCHAR_BITMAP (*c));
  119.  
  120.   box_widget = XtNameToWidget (top, "kern box");
  121.  
  122.   /* Destroy the old kern items.  */
  123.   XtVaGetValues (box_widget, XtNchildren, &old_kerns,
  124.                  XtNnumChildren, &old_kern_count, NULL, NULL);
  125.  
  126.   /* Unmanage the children explicitly, so that the Box can get rid of
  127.      the old ones before making the new ones.  (XtDestroyWidget doesn't
  128.      actually destroy anything until after all procedures---that's
  129.      us---have finished.)  */
  130.   XtUnmanageChildren (old_kerns, old_kern_count);
  131.   for (k = 0; k < old_kern_count; k++)
  132.     XtDestroyWidget (old_kerns[k]);
  133.   
  134.   /* Add one Item widget for each of the kerns.  */
  135.   kern_list = CHAR_TFM_INFO (*c).kern;
  136.   for (k = 0; k < LIST_SIZE (kern_list); k++)
  137.     {
  138.       tfm_kern_type *kern = LIST_ELT (kern_list, k);
  139.       add_kern_widget (box_widget, f, kern->character, kern->kern);
  140.     }
  141.     
  142.   FONT_CURRENT_CHARCODE (*f) = code;
  143.   FONT_CURRENT_CHAR (*f) = c;
  144. }
  145.  
  146.  
  147. /* Display the bitmap B in the font F in both the editing and viewing
  148.    windows.  The widget TOP is the Form that manages all the other
  149.    widgets.  */
  150.  
  151. static void
  152. show_bitmap (Widget top, font_type *f, bitmap_type *b)
  153. {
  154.   Arg bitmap_args[] = { { XtNbits, (XtArgVal) b } };
  155.  
  156.   Widget bw = XFIND_WIDGET (top, "*bitmap");
  157.   Widget true_bw = XFIND_WIDGET (top, "true bitmap");
  158.  
  159.   /* Update the font structure.  */
  160.   if (BitmapModified (bw))
  161.     FONT_MODIFIED (*f) = true;
  162.     
  163.   /* We do want to reconfigure the form after changing `true_bw'---it
  164.      might shrink, thus allowing more space for the big bitmap.  */
  165.   XtSetValues (true_bw, XTARG (bitmap_args));
  166.   XtSetValues (bw, XTARG (bitmap_args));
  167. }
  168.