Mercurial > hg > xemacs-beta
comparison src/glyphs-shared.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 | 183866b06e0b |
children | 38db05db9cb5 |
comparison
equal
deleted
inserted
replaced
607:9979b8030c99 | 608:4d7fdf497470 |
---|---|
1 /* mswindows-specific glyph objects. | 1 /* Routines shared between window-system backends for glyph objects. |
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc. | 2 Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
3 Copyright (C) 1995 Board of Trustees, University of Illinois. | 3 Copyright (C) 1995 Board of Trustees, University of Illinois. |
4 Copyright (C) 1995 Tinker Systems | 4 Copyright (C) 1995 Tinker Systems |
5 Copyright (C) 1995, 1996 Ben Wing | 5 Copyright (C) 1995, 1996 Ben Wing |
6 Copyright (C) 1995 Sun Microsystems | 6 Copyright (C) 1995 Sun Microsystems |
93 free_alist (alist); | 93 free_alist (alist); |
94 RETURN_UNGCPRO (result); | 94 RETURN_UNGCPRO (result); |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 /* Originally from xmu.c, but is now shared across X11, GTK, and MSW. */ | |
99 /* | |
100 * Based on an optimized version provided by Jim Becker, August 5, 1988. | |
101 */ | |
102 | |
103 | |
104 #ifndef BitmapSuccess | |
105 #define BitmapSuccess 0 | |
106 #define BitmapOpenFailed 1 | |
107 #define BitmapFileInvalid 2 | |
108 #define BitmapNoMemory 3 | |
109 #endif | |
110 | |
111 #define MAX_SIZE 255 | |
112 | |
113 /* shared data for the image read/parse logic */ | |
114 static short hexTable[256]; /* conversion value */ | |
115 static int hex_initialized; /* easier to fill in at run time */ | |
116 | |
117 | |
118 /* | |
119 * Table index for the hex values. Initialized once, first time. | |
120 * Used for translation value or delimiter significance lookup. | |
121 */ | |
122 static void initHexTable (void) | |
123 { | |
124 /* | |
125 * We build the table at run time for several reasons: | |
126 * | |
127 * 1. portable to non-ASCII machines. | |
128 * 2. still reentrant since we set the init flag after setting table. | |
129 * 3. easier to extend. | |
130 * 4. less prone to bugs. | |
131 */ | |
132 hexTable['0'] = 0; hexTable['1'] = 1; | |
133 hexTable['2'] = 2; hexTable['3'] = 3; | |
134 hexTable['4'] = 4; hexTable['5'] = 5; | |
135 hexTable['6'] = 6; hexTable['7'] = 7; | |
136 hexTable['8'] = 8; hexTable['9'] = 9; | |
137 hexTable['A'] = 10; hexTable['B'] = 11; | |
138 hexTable['C'] = 12; hexTable['D'] = 13; | |
139 hexTable['E'] = 14; hexTable['F'] = 15; | |
140 hexTable['a'] = 10; hexTable['b'] = 11; | |
141 hexTable['c'] = 12; hexTable['d'] = 13; | |
142 hexTable['e'] = 14; hexTable['f'] = 15; | |
143 | |
144 /* delimiters of significance are flagged w/ negative value */ | |
145 hexTable[' '] = -1; hexTable[','] = -1; | |
146 hexTable['}'] = -1; hexTable['\n'] = -1; | |
147 hexTable['\t'] = -1; | |
148 | |
149 hex_initialized = 1; | |
150 } | |
151 | |
152 /* | |
153 * read next hex value in the input stream, return -1 if EOF | |
154 */ | |
155 static int NextInt (FILE *fstream) | |
156 { | |
157 int ch; | |
158 int value = 0; | |
159 int gotone = 0; | |
160 int done = 0; | |
161 | |
162 /* loop, accumulate hex value until find delimiter */ | |
163 /* skip any initial delimiters found in read stream */ | |
164 | |
165 while (!done) { | |
166 ch = getc(fstream); | |
167 if (ch == EOF) { | |
168 value = -1; | |
169 done++; | |
170 } else { | |
171 /* trim high bits, check type and accumulate */ | |
172 ch &= 0xff; | |
173 if (isascii(ch) && isxdigit(ch)) { | |
174 value = (value << 4) + hexTable[ch]; | |
175 gotone++; | |
176 } else if ((hexTable[ch]) < 0 && gotone) | |
177 done++; | |
178 } | |
179 } | |
180 return value; | |
181 } | |
182 | |
183 | |
184 /* | |
185 * The data returned by the following routine is always in left-most byte | |
186 * first and left-most bit first. If it doesn't return BitmapSuccess then | |
187 * its arguments won't have been touched. This routine should look as much | |
188 * like the Xlib routine XReadBitmapfile as possible. | |
189 */ | |
190 int read_bitmap_data (FILE* fstream, unsigned int *width, | |
191 unsigned int *height, UChar_Binary **datap, | |
192 int *x_hot, int *y_hot) | |
193 { | |
194 UChar_Binary *data = NULL; /* working variable */ | |
195 char line[MAX_SIZE]; /* input line from file */ | |
196 int size; /* number of bytes of data */ | |
197 char name_and_type[MAX_SIZE]; /* an input line */ | |
198 char *type; /* for parsing */ | |
199 int value; /* from an input line */ | |
200 int version10p; /* boolean, old format */ | |
201 int padding; /* to handle alignment */ | |
202 int bytes_per_line; /* per scanline of data */ | |
203 unsigned int ww = 0; /* width */ | |
204 unsigned int hh = 0; /* height */ | |
205 int hx = -1; /* x hotspot */ | |
206 int hy = -1; /* y hotspot */ | |
207 | |
208 #ifndef Xmalloc | |
209 #define Xmalloc(size) malloc(size) | |
210 #endif | |
211 | |
212 /* first time initialization */ | |
213 if (!hex_initialized) initHexTable(); | |
214 | |
215 /* error cleanup and return macro */ | |
216 #define RETURN(code) { if (data) free (data); return code; } | |
217 | |
218 while (fgets(line, MAX_SIZE, fstream)) { | |
219 if (strlen(line) == MAX_SIZE-1) { | |
220 RETURN (BitmapFileInvalid); | |
221 } | |
222 if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) { | |
223 if (!(type = strrchr(name_and_type, '_'))) | |
224 type = name_and_type; | |
225 else | |
226 type++; | |
227 | |
228 if (!strcmp("width", type)) | |
229 ww = (unsigned int) value; | |
230 if (!strcmp("height", type)) | |
231 hh = (unsigned int) value; | |
232 if (!strcmp("hot", type)) { | |
233 if (type-- == name_and_type || type-- == name_and_type) | |
234 continue; | |
235 if (!strcmp("x_hot", type)) | |
236 hx = value; | |
237 if (!strcmp("y_hot", type)) | |
238 hy = value; | |
239 } | |
240 continue; | |
241 } | |
242 | |
243 if (sscanf(line, "static short %s = {", name_and_type) == 1) | |
244 version10p = 1; | |
245 else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1) | |
246 version10p = 0; | |
247 else if (sscanf(line, "static char %s = {", name_and_type) == 1) | |
248 version10p = 0; | |
249 else | |
250 continue; | |
251 | |
252 if (!(type = strrchr(name_and_type, '_'))) | |
253 type = name_and_type; | |
254 else | |
255 type++; | |
256 | |
257 if (strcmp("bits[]", type)) | |
258 continue; | |
259 | |
260 if (!ww || !hh) | |
261 RETURN (BitmapFileInvalid); | |
262 | |
263 if ((ww % 16) && ((ww % 16) < 9) && version10p) | |
264 padding = 1; | |
265 else | |
266 padding = 0; | |
267 | |
268 bytes_per_line = (ww+7)/8 + padding; | |
269 | |
270 size = bytes_per_line * hh; | |
271 data = (UChar_Binary *) Xmalloc ((unsigned int) size); | |
272 if (!data) | |
273 RETURN (BitmapNoMemory); | |
274 | |
275 if (version10p) { | |
276 UChar_Binary *ptr; | |
277 int bytes; | |
278 | |
279 for (bytes=0, ptr=data; bytes<size; (bytes += 2)) { | |
280 if ((value = NextInt(fstream)) < 0) | |
281 RETURN (BitmapFileInvalid); | |
282 *(ptr++) = value; | |
283 if (!padding || ((bytes+2) % bytes_per_line)) | |
284 *(ptr++) = value >> 8; | |
285 } | |
286 } else { | |
287 UChar_Binary *ptr; | |
288 int bytes; | |
289 | |
290 for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) { | |
291 if ((value = NextInt(fstream)) < 0) | |
292 RETURN (BitmapFileInvalid); | |
293 *ptr=value; | |
294 } | |
295 } | |
296 break; | |
297 } /* end while */ | |
298 | |
299 if (data == NULL) { | |
300 RETURN (BitmapFileInvalid); | |
301 } | |
302 | |
303 *datap = data; | |
304 data = NULL; | |
305 *width = ww; | |
306 *height = hh; | |
307 if (x_hot) *x_hot = hx; | |
308 if (y_hot) *y_hot = hy; | |
309 | |
310 RETURN (BitmapSuccess); | |
311 } | |
312 | |
313 | |
314 int read_bitmap_data_from_file (const char *filename, | |
315 /* Remaining args are RETURNED */ | |
316 unsigned int *width, | |
317 unsigned int *height, | |
318 UChar_Binary **datap, | |
319 int *x_hot, int *y_hot) | |
320 { | |
321 FILE *fstream; | |
322 int status; | |
323 | |
324 if ((fstream = fopen (filename, "r")) == NULL) { | |
325 return BitmapOpenFailed; | |
326 } | |
327 status = read_bitmap_data (fstream, width, height, datap, x_hot, y_hot); | |
328 fclose (fstream); | |
329 return status; | |
330 } | |
331 | |
98 void | 332 void |
99 syms_of_glyphs_shared (void) | 333 syms_of_glyphs_shared (void) |
100 { | 334 { |
101 DEFKEYWORD (Q_resource_id); | 335 DEFKEYWORD (Q_resource_id); |
102 DEFKEYWORD (Q_resource_type); | 336 DEFKEYWORD (Q_resource_type); |