comparison src/glyphs-gtk.c @ 608:4d7fdf497470

[xemacs-hg @ 2001-06-04 16:59:51 by wmperry] 2001-06-04 William M. Perry <wmperry@gnu.org> * gpmevent.c (KG_CTRL): Just define these unconditionally. The linux headers are so lame that they do not expose these to userland programs and you cannot gracefully include the kernel headers. 2001-06-03 William M. Perry <wmperry@gnu.org> * scrollbar-gtk.c (gtk_create_scrollbar_instance): Make calling of gtk_size_request unconditional. 2001-06-02 William M. Perry <wmperry@gnu.org> * emacs-marshals.c: Regenerated. 2001-06-01 William M. Perry <wmperry@gnu.org> * glyphs-shared.c (read_bitmap_data): Common definition of read_bitmap_data_from_file added. This does not attempt to use the Xmu based code at all - lets us be consistent across platforms. * glyphs-gtk.c: Removed definition of read_bitmap_data_from_file - this is now in glyphs-shared.c * glyphs-msw.c: Ditto. * glyphs-x.c: Ditto. 2001-06-03 William M. Perry <wmperry@gnu.org> * dialog-gtk.el (popup-builtin-open-dialog): Yikes - don't forget to return the filename! * font.el (font-window-system-mappings): Add gtk entry - just an alias to the X code) 2001-06-02 William M. Perry <wmperry@gnu.org> * gtk-marshal.el: Fix for removing of the string_hash utility functions in hash.c
author wmperry
date Mon, 04 Jun 2001 17:00:02 +0000
parents fec27b06b4e5
children 1df69dc58840
comparison
equal deleted inserted replaced
607:9979b8030c99 608:4d7fdf497470
2726 BUILD_GLYPH_INST (Vhscroll_glyph, hscroll); 2726 BUILD_GLYPH_INST (Vhscroll_glyph, hscroll);
2727 2727
2728 #undef BUILD_GLYPH_INST 2728 #undef BUILD_GLYPH_INST
2729 } 2729 }
2730 2730
2731
2732 /* Ripped off from glyphs-msw.c */
2733 /*
2734 * The data returned by the following routine is always in left-most byte
2735 * first and left-most bit first. If it doesn't return BitmapSuccess then
2736 * its arguments won't have been touched. This routine should look as much
2737 * like the Xlib routine XReadBitmapfile as possible.
2738 */
2739 #define MAX_SIZE 1024
2740
2741 /* shared data for the image read/parse logic */
2742 static short hexTable[256]; /* conversion value */
2743 static int initialized = FALSE; /* easier to fill in at run time */
2744
2745 /*
2746 * Table index for the hex values. Initialized once, first time.
2747 * Used for translation value or delimiter significance lookup.
2748 */
2749 static void initHexTable()
2750 {
2751 /*
2752 * We build the table at run time for several reasons:
2753 *
2754 * 1. portable to non-ASCII machines.
2755 * 2. still reentrant since we set the init flag after setting table.
2756 * 3. easier to extend.
2757 * 4. less prone to bugs.
2758 */
2759 hexTable['0'] = 0; hexTable['1'] = 1;
2760 hexTable['2'] = 2; hexTable['3'] = 3;
2761 hexTable['4'] = 4; hexTable['5'] = 5;
2762 hexTable['6'] = 6; hexTable['7'] = 7;
2763 hexTable['8'] = 8; hexTable['9'] = 9;
2764 hexTable['A'] = 10; hexTable['B'] = 11;
2765 hexTable['C'] = 12; hexTable['D'] = 13;
2766 hexTable['E'] = 14; hexTable['F'] = 15;
2767 hexTable['a'] = 10; hexTable['b'] = 11;
2768 hexTable['c'] = 12; hexTable['d'] = 13;
2769 hexTable['e'] = 14; hexTable['f'] = 15;
2770
2771 /* delimiters of significance are flagged w/ negative value */
2772 hexTable[' '] = -1; hexTable[','] = -1;
2773 hexTable['}'] = -1; hexTable['\n'] = -1;
2774 hexTable['\t'] = -1;
2775
2776 initialized = TRUE;
2777 }
2778
2779 /*
2780 * read next hex value in the input stream, return -1 if EOF
2781 */
2782 static int NextInt ( FILE *fstream )
2783 {
2784 int ch;
2785 int value = 0;
2786 int gotone = 0;
2787 int done = 0;
2788
2789 /* loop, accumulate hex value until find delimiter */
2790 /* skip any initial delimiters found in read stream */
2791
2792 while (!done) {
2793 ch = getc(fstream);
2794 if (ch == EOF) {
2795 value = -1;
2796 done++;
2797 } else {
2798 /* trim high bits, check type and accumulate */
2799 ch &= 0xff;
2800 if (isascii(ch) && isxdigit(ch)) {
2801 value = (value << 4) + hexTable[ch];
2802 gotone++;
2803 } else if ((hexTable[ch]) < 0 && gotone)
2804 done++;
2805 }
2806 }
2807 return value;
2808 }
2809
2810 int read_bitmap_data (fstream, width, height, datap, x_hot, y_hot)
2811 FILE *fstream; /* handle on file */
2812 unsigned int *width, *height; /* RETURNED */
2813 unsigned char **datap; /* RETURNED */
2814 int *x_hot, *y_hot; /* RETURNED */
2815 {
2816 unsigned char *data = NULL; /* working variable */
2817 char line[MAX_SIZE]; /* input line from file */
2818 int size; /* number of bytes of data */
2819 char name_and_type[MAX_SIZE]; /* an input line */
2820 char *type; /* for parsing */
2821 int value; /* from an input line */
2822 int version10p; /* boolean, old format */
2823 int padding; /* to handle alignment */
2824 int bytes_per_line; /* per scanline of data */
2825 unsigned int ww = 0; /* width */
2826 unsigned int hh = 0; /* height */
2827 int hx = -1; /* x hotspot */
2828 int hy = -1; /* y hotspot */
2829
2830 #define Xmalloc(size) malloc(size)
2831
2832 /* first time initialization */
2833 if (initialized == FALSE) initHexTable();
2834
2835 /* error cleanup and return macro */
2836 #define RETURN(code) { if (data) free (data); return code; }
2837
2838 while (fgets(line, MAX_SIZE, fstream)) {
2839 if (strlen(line) == MAX_SIZE-1) {
2840 RETURN (BitmapFileInvalid);
2841 }
2842 if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) {
2843 if (!(type = strrchr(name_and_type, '_')))
2844 type = name_and_type;
2845 else
2846 type++;
2847
2848 if (!strcmp("width", type))
2849 ww = (unsigned int) value;
2850 if (!strcmp("height", type))
2851 hh = (unsigned int) value;
2852 if (!strcmp("hot", type)) {
2853 if (type-- == name_and_type || type-- == name_and_type)
2854 continue;
2855 if (!strcmp("x_hot", type))
2856 hx = value;
2857 if (!strcmp("y_hot", type))
2858 hy = value;
2859 }
2860 continue;
2861 }
2862
2863 if (sscanf(line, "static short %s = {", name_and_type) == 1)
2864 version10p = 1;
2865 else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1)
2866 version10p = 0;
2867 else if (sscanf(line, "static char %s = {", name_and_type) == 1)
2868 version10p = 0;
2869 else
2870 continue;
2871
2872 if (!(type = strrchr(name_and_type, '_')))
2873 type = name_and_type;
2874 else
2875 type++;
2876
2877 if (strcmp("bits[]", type))
2878 continue;
2879
2880 if (!ww || !hh)
2881 RETURN (BitmapFileInvalid);
2882
2883 if ((ww % 16) && ((ww % 16) < 9) && version10p)
2884 padding = 1;
2885 else
2886 padding = 0;
2887
2888 bytes_per_line = (ww+7)/8 + padding;
2889
2890 size = bytes_per_line * hh;
2891 data = (unsigned char *) Xmalloc ((unsigned int) size);
2892 if (!data)
2893 RETURN (BitmapNoMemory);
2894
2895 if (version10p) {
2896 unsigned char *ptr;
2897 int bytes;
2898
2899 for (bytes=0, ptr=data; bytes<size; (bytes += 2)) {
2900 if ((value = NextInt(fstream)) < 0)
2901 RETURN (BitmapFileInvalid);
2902 *(ptr++) = value;
2903 if (!padding || ((bytes+2) % bytes_per_line))
2904 *(ptr++) = value >> 8;
2905 }
2906 } else {
2907 unsigned char *ptr;
2908 int bytes;
2909
2910 for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) {
2911 if ((value = NextInt(fstream)) < 0)
2912 RETURN (BitmapFileInvalid);
2913 *ptr=value;
2914 }
2915 }
2916 break;
2917 } /* end while */
2918
2919 if (data == NULL) {
2920 RETURN (BitmapFileInvalid);
2921 }
2922
2923 *datap = data;
2924 data = NULL;
2925 *width = ww;
2926 *height = hh;
2927 if (x_hot) *x_hot = hx;
2928 if (y_hot) *y_hot = hy;
2929
2930 RETURN (BitmapSuccess);
2931 }
2932
2933
2934 int read_bitmap_data_from_file (CONST char *filename, unsigned int *width,
2935 unsigned int *height, unsigned char **datap,
2936 int *x_hot, int *y_hot)
2937 {
2938 FILE *fstream;
2939 int rval;
2940
2941 if ((fstream = fopen (filename, "r")) == NULL) {
2942 return BitmapOpenFailed;
2943 }
2944 rval = read_bitmap_data (fstream, width, height, datap, x_hot, y_hot);
2945 fclose (fstream);
2946 return rval;
2947 }
2948
2949 /* X specific crap */ 2731 /* X specific crap */
2950 #include <gdk/gdkx.h> 2732 #include <gdk/gdkx.h>
2951 /* #### Should remove all this X specific stuff when GTK/GDK matures a 2733 /* #### Should remove all this X specific stuff when GTK/GDK matures a
2952 bit more and provides an abstraction for it. */ 2734 bit more and provides an abstraction for it. */
2953 static int 2735 static int