comparison src/glyphs-msw.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 5fd7ba8b56e7
children 38db05db9cb5
comparison
equal deleted inserted replaced
607:9979b8030c99 608:4d7fdf497470
1361 } 1361 }
1362 1362
1363 /********************************************************************** 1363 /**********************************************************************
1364 * XBM * 1364 * XBM *
1365 **********************************************************************/ 1365 **********************************************************************/
1366 #ifndef HAVE_X_WINDOWS
1367 /* $XConsortium: RdBitF.c,v 1.10 94/04/17 20:16:13 kaleb Exp $ */
1368
1369 /*
1370
1371 Copyright (c) 1988 X Consortium
1372
1373 Permission is hereby granted, free of charge, to any person obtaining a copy
1374 of this software and associated documentation files (the "Software"), to deal
1375 in the Software without restriction, including without limitation the rights
1376 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1377 copies of the Software, and to permit persons to whom the Software is
1378 furnished to do so, subject to the following conditions:
1379
1380 The above copyright notice and this permission notice shall be included in
1381 all copies or substantial portions of the Software.
1382
1383 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1384 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1385 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1386 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1387 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1388 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1389
1390 Except as contained in this notice, the name of the X Consortium shall not be
1391 used in advertising or otherwise to promote the sale, use or other dealings
1392 in this Software without prior written authorization from the X Consortium.
1393
1394 */
1395
1396 /*
1397 * This file contains miscellaneous utility routines and is not part of the
1398 * Xlib standard.
1399 *
1400 * Public entry points:
1401 *
1402 * XmuReadBitmapData read data from FILE descriptor
1403 * XmuReadBitmapDataFromFile read X10 or X11 format bitmap files
1404 * and return data
1405 *
1406 * Note that this file and ../X/XRdBitF.c look very similar.... Keep them
1407 * that way (but don't use common source code so that people can have one
1408 * without the other).
1409 */
1410
1411
1412 /*
1413 * Based on an optimized version provided by Jim Becker, August 5, 1988.
1414 */
1415 #ifndef BitmapSuccess
1416 #define BitmapSuccess 0
1417 #define BitmapOpenFailed 1
1418 #define BitmapFileInvalid 2
1419 #define BitmapNoMemory 3
1420 #endif
1421 #define MAX_SIZE 255
1422
1423 /* shared data for the image read/parse logic */
1424 static short hexTable[256]; /* conversion value */
1425 static int initialized = FALSE; /* easier to fill in at run time */
1426
1427 /*
1428 * Table index for the hex values. Initialized once, first time.
1429 * Used for translation value or delimiter significance lookup.
1430 */
1431 static void
1432 initHexTable (void)
1433 {
1434 /*
1435 * We build the table at run time for several reasons:
1436 *
1437 * 1. portable to non-ASCII machines.
1438 * 2. still reentrant since we set the init flag after setting table.
1439 * 3. easier to extend.
1440 * 4. less prone to bugs.
1441 */
1442 hexTable['0'] = 0; hexTable['1'] = 1;
1443 hexTable['2'] = 2; hexTable['3'] = 3;
1444 hexTable['4'] = 4; hexTable['5'] = 5;
1445 hexTable['6'] = 6; hexTable['7'] = 7;
1446 hexTable['8'] = 8; hexTable['9'] = 9;
1447 hexTable['A'] = 10; hexTable['B'] = 11;
1448 hexTable['C'] = 12; hexTable['D'] = 13;
1449 hexTable['E'] = 14; hexTable['F'] = 15;
1450 hexTable['a'] = 10; hexTable['b'] = 11;
1451 hexTable['c'] = 12; hexTable['d'] = 13;
1452 hexTable['e'] = 14; hexTable['f'] = 15;
1453
1454 /* delimiters of significance are flagged w/ negative value */
1455 hexTable[' '] = -1; hexTable[','] = -1;
1456 hexTable['}'] = -1; hexTable['\n'] = -1;
1457 hexTable['\t'] = -1;
1458
1459 initialized = TRUE;
1460 }
1461
1462 /*
1463 * read next hex value in the input stream, return -1 if EOF
1464 */
1465 static int
1466 NextInt (FILE *fstream)
1467 {
1468 int ch;
1469 int value = 0;
1470 int gotone = 0;
1471 int done = 0;
1472
1473 /* loop, accumulate hex value until find delimiter */
1474 /* skip any initial delimiters found in read stream */
1475
1476 while (!done) {
1477 ch = getc(fstream);
1478 if (ch == EOF) {
1479 value = -1;
1480 done++;
1481 } else {
1482 /* trim high bits, check type and accumulate */
1483 ch &= 0xff;
1484 if (isascii(ch) && isxdigit(ch)) {
1485 value = (value << 4) + hexTable[ch];
1486 gotone++;
1487 } else if ((hexTable[ch]) < 0 && gotone)
1488 done++;
1489 }
1490 }
1491 return value;
1492 }
1493
1494
1495 /*
1496 * The data returned by the following routine is always in left-most byte
1497 * first and left-most bit first. If it doesn't return BitmapSuccess then
1498 * its arguments won't have been touched. This routine should look as much
1499 * like the Xlib routine XReadBitmapfile as possible.
1500 */
1501 int read_bitmap_data (FILE* fstream, unsigned int *width,
1502 unsigned int *height, UChar_Binary **datap,
1503 int *x_hot, int *y_hot)
1504 {
1505 UChar_Binary *data = NULL; /* working variable */
1506 char line[MAX_SIZE]; /* input line from file */
1507 int size; /* number of bytes of data */
1508 char name_and_type[MAX_SIZE]; /* an input line */
1509 char *type; /* for parsing */
1510 int value; /* from an input line */
1511 int version10p; /* boolean, old format */
1512 int padding; /* to handle alignment */
1513 int bytes_per_line; /* per scanline of data */
1514 unsigned int ww = 0; /* width */
1515 unsigned int hh = 0; /* height */
1516 int hx = -1; /* x hotspot */
1517 int hy = -1; /* y hotspot */
1518
1519 #define Xmalloc(size) malloc(size)
1520
1521 /* first time initialization */
1522 if (initialized == FALSE) initHexTable();
1523
1524 /* error cleanup and return macro */
1525 #define RETURN(code) { if (data) free (data); return code; }
1526
1527 while (fgets(line, MAX_SIZE, fstream)) {
1528 if (strlen(line) == MAX_SIZE-1) {
1529 RETURN (BitmapFileInvalid);
1530 }
1531 if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) {
1532 if (!(type = strrchr(name_and_type, '_')))
1533 type = name_and_type;
1534 else
1535 type++;
1536
1537 if (!strcmp("width", type))
1538 ww = (unsigned int) value;
1539 if (!strcmp("height", type))
1540 hh = (unsigned int) value;
1541 if (!strcmp("hot", type)) {
1542 if (type-- == name_and_type || type-- == name_and_type)
1543 continue;
1544 if (!strcmp("x_hot", type))
1545 hx = value;
1546 if (!strcmp("y_hot", type))
1547 hy = value;
1548 }
1549 continue;
1550 }
1551
1552 if (sscanf(line, "static short %s = {", name_and_type) == 1)
1553 version10p = 1;
1554 else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1)
1555 version10p = 0;
1556 else if (sscanf(line, "static char %s = {", name_and_type) == 1)
1557 version10p = 0;
1558 else
1559 continue;
1560
1561 if (!(type = strrchr(name_and_type, '_')))
1562 type = name_and_type;
1563 else
1564 type++;
1565
1566 if (strcmp("bits[]", type))
1567 continue;
1568
1569 if (!ww || !hh)
1570 RETURN (BitmapFileInvalid);
1571
1572 if ((ww % 16) && ((ww % 16) < 9) && version10p)
1573 padding = 1;
1574 else
1575 padding = 0;
1576
1577 bytes_per_line = (ww+7)/8 + padding;
1578
1579 size = bytes_per_line * hh;
1580 data = (UChar_Binary *) Xmalloc ((unsigned int) size);
1581 if (!data)
1582 RETURN (BitmapNoMemory);
1583
1584 if (version10p) {
1585 UChar_Binary *ptr;
1586 int bytes;
1587
1588 for (bytes=0, ptr=data; bytes<size; (bytes += 2)) {
1589 if ((value = NextInt(fstream)) < 0)
1590 RETURN (BitmapFileInvalid);
1591 *(ptr++) = value;
1592 if (!padding || ((bytes+2) % bytes_per_line))
1593 *(ptr++) = value >> 8;
1594 }
1595 } else {
1596 UChar_Binary *ptr;
1597 int bytes;
1598
1599 for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) {
1600 if ((value = NextInt(fstream)) < 0)
1601 RETURN (BitmapFileInvalid);
1602 *ptr=value;
1603 }
1604 }
1605 break;
1606 } /* end while */
1607
1608 if (data == NULL) {
1609 RETURN (BitmapFileInvalid);
1610 }
1611
1612 *datap = data;
1613 data = NULL;
1614 *width = ww;
1615 *height = hh;
1616 if (x_hot) *x_hot = hx;
1617 if (y_hot) *y_hot = hy;
1618
1619 RETURN (BitmapSuccess);
1620 }
1621
1622
1623 int read_bitmap_data_from_file (const char *filename, unsigned int *width,
1624 unsigned int *height, UChar_Binary **datap,
1625 int *x_hot, int *y_hot)
1626 {
1627 FILE *fstream;
1628 int status;
1629
1630 if ((fstream = fopen (filename, "r")) == NULL) {
1631 return BitmapOpenFailed;
1632 }
1633 status = read_bitmap_data (fstream, width, height, datap, x_hot, y_hot);
1634 fclose (fstream);
1635 return status;
1636 }
1637 #endif /* HAVE_X_WINDOWS */
1638
1639 /* this table flips four bits around. */ 1366 /* this table flips four bits around. */
1640 static int flip_table[] = 1367 static int flip_table[] =
1641 { 1368 {
1642 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 1369 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
1643 }; 1370 };