Mercurial > hg > xemacs-beta
comparison src/glyphs.c @ 280:7df0dd720c89 r21-0b38
Import from CVS: tag r21-0b38
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:32:22 +0200 |
parents | 90d73dddcdc4 |
children | 558f606b08ae |
comparison
equal
deleted
inserted
replaced
279:c20b2fb5bb0a | 280:7df0dd720c89 |
---|---|
77 | 77 |
78 #ifdef HAVE_XPM | 78 #ifdef HAVE_XPM |
79 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xpm); | 79 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xpm); |
80 Lisp_Object Qxpm; | 80 Lisp_Object Qxpm; |
81 Lisp_Object Q_color_symbols; | 81 Lisp_Object Q_color_symbols; |
82 void x_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, | |
83 Lisp_Object pointer_fg, Lisp_Object pointer_bg, | |
84 int dest_mask, Lisp_Object domain); | |
85 void mswindows_xpm_instantiate (Lisp_Object image_instance, | |
86 Lisp_Object instantiator, | |
87 Lisp_Object pointer_fg, Lisp_Object pointer_bg, | |
88 int dest_mask, Lisp_Object domain); | |
89 Lisp_Object x_xpm_normalize (Lisp_Object inst, Lisp_Object console_type); | |
90 Lisp_Object mswindows_xpm_normalize (Lisp_Object inst, | |
91 Lisp_Object console_type); | |
92 #endif | 82 #endif |
93 | 83 |
94 typedef struct image_instantiator_format_entry image_instantiator_format_entry; | 84 typedef struct image_instantiator_format_entry image_instantiator_format_entry; |
95 struct image_instantiator_format_entry | 85 struct image_instantiator_format_entry |
96 { | 86 { |
1547 | 1537 |
1548 /********************************************************************** | 1538 /********************************************************************** |
1549 * XPM * | 1539 * XPM * |
1550 **********************************************************************/ | 1540 **********************************************************************/ |
1551 | 1541 |
1542 Lisp_Object | |
1543 pixmap_to_lisp_data (Lisp_Object name, int ok_if_data_invalid) | |
1544 { | |
1545 char **data; | |
1546 int result; | |
1547 | |
1548 result = XpmReadFileToData ((char *) XSTRING_DATA (name), &data); | |
1549 | |
1550 if (result == XpmSuccess) | |
1551 { | |
1552 Lisp_Object retval = Qnil; | |
1553 struct buffer *old_buffer = current_buffer; | |
1554 Lisp_Object temp_buffer = | |
1555 Fget_buffer_create (build_string (" *pixmap conversion*")); | |
1556 int elt; | |
1557 int height, width, ncolors; | |
1558 struct gcpro gcpro1, gcpro2, gcpro3; | |
1559 int speccount = specpdl_depth (); | |
1560 | |
1561 GCPRO3 (name, retval, temp_buffer); | |
1562 | |
1563 specbind (Qinhibit_quit, Qt); | |
1564 set_buffer_internal (XBUFFER (temp_buffer)); | |
1565 Ferase_buffer (Qnil); | |
1566 | |
1567 buffer_insert_c_string (current_buffer, "/* XPM */\r"); | |
1568 buffer_insert_c_string (current_buffer, "static char *pixmap[] = {\r"); | |
1569 | |
1570 sscanf (data[0], "%d %d %d", &height, &width, &ncolors); | |
1571 for (elt = 0; elt <= width + ncolors; elt++) | |
1572 { | |
1573 buffer_insert_c_string (current_buffer, "\""); | |
1574 buffer_insert_c_string (current_buffer, data[elt]); | |
1575 | |
1576 if (elt < width + ncolors) | |
1577 buffer_insert_c_string (current_buffer, "\",\r"); | |
1578 else | |
1579 buffer_insert_c_string (current_buffer, "\"};\r"); | |
1580 } | |
1581 | |
1582 retval = Fbuffer_substring (Qnil, Qnil, Qnil); | |
1583 XpmFree (data); | |
1584 | |
1585 set_buffer_internal (old_buffer); | |
1586 unbind_to (speccount, Qnil); | |
1587 | |
1588 RETURN_UNGCPRO (retval); | |
1589 } | |
1590 | |
1591 switch (result) | |
1592 { | |
1593 case XpmFileInvalid: | |
1594 { | |
1595 if (ok_if_data_invalid) | |
1596 return Qt; | |
1597 signal_image_error ("invalid XPM data in file", name); | |
1598 } | |
1599 case XpmNoMemory: | |
1600 { | |
1601 signal_double_file_error ("Reading pixmap file", | |
1602 "out of memory", name); | |
1603 } | |
1604 case XpmOpenFailed: | |
1605 { | |
1606 /* should never happen? */ | |
1607 signal_double_file_error ("Opening pixmap file", | |
1608 "no such file or directory", name); | |
1609 } | |
1610 default: | |
1611 { | |
1612 signal_double_file_error_2 ("Parsing pixmap file", | |
1613 "unknown error code", | |
1614 make_int (result), name); | |
1615 break; | |
1616 } | |
1617 } | |
1618 | |
1619 return Qnil; /* not reached */ | |
1620 } | |
1621 | |
1552 static void | 1622 static void |
1553 check_valid_xpm_color_symbols (Lisp_Object data) | 1623 check_valid_xpm_color_symbols (Lisp_Object data) |
1554 { | 1624 { |
1555 Lisp_Object rest; | 1625 Lisp_Object rest; |
1556 | 1626 |
1606 } | 1676 } |
1607 | 1677 |
1608 static Lisp_Object | 1678 static Lisp_Object |
1609 xpm_normalize (Lisp_Object inst, Lisp_Object console_type) | 1679 xpm_normalize (Lisp_Object inst, Lisp_Object console_type) |
1610 { | 1680 { |
1611 #ifdef HAVE_X_WINDOWS | 1681 Lisp_Object file = Qnil; |
1612 if (CONSOLE_TYPESYM_X_P (console_type)) | 1682 Lisp_Object color_symbols; |
1613 return x_xpm_normalize (inst, console_type); | 1683 struct gcpro gcpro1, gcpro2; |
1614 else | 1684 Lisp_Object alist = Qnil; |
1615 #endif | 1685 |
1616 #ifdef HAVE_MS_WINDOWS | 1686 GCPRO2 (file, alist); |
1617 if (CONSOLE_TYPESYM_MSWINDOWS_P (console_type)) | 1687 |
1618 return mswindows_xpm_normalize (inst, console_type); | 1688 /* Now, convert any file data into inline data. At the end of this, |
1619 else | 1689 `data' will contain the inline data (if any) or Qnil, and |
1620 #endif | 1690 `file' will contain the name this data was derived from (if |
1621 signal_image_error ("Can't display XPM images on this console", | 1691 known) or Qnil. |
1622 console_type); | 1692 |
1693 Note that if we cannot generate any regular inline data, we | |
1694 skip out. */ | |
1695 | |
1696 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data, | |
1697 console_type); | |
1698 | |
1699 if (CONSP (file)) /* failure locating filename */ | |
1700 signal_double_file_error ("Opening pixmap file", | |
1701 "no such file or directory", | |
1702 Fcar (file)); | |
1703 | |
1704 color_symbols = find_keyword_in_vector_or_given (inst, Q_color_symbols, | |
1705 Qunbound); | |
1706 | |
1707 if (NILP (file) && !UNBOUNDP (color_symbols)) | |
1708 /* no conversion necessary */ | |
1709 RETURN_UNGCPRO (inst); | |
1710 | |
1711 alist = tagged_vector_to_alist (inst); | |
1712 | |
1713 if (!NILP (file)) | |
1714 { | |
1715 Lisp_Object data = pixmap_to_lisp_data (file, 0); | |
1716 alist = remassq_no_quit (Q_file, alist); | |
1717 /* there can't be a :data at this point. */ | |
1718 alist = Fcons (Fcons (Q_file, file), | |
1719 Fcons (Fcons (Q_data, data), alist)); | |
1720 } | |
1721 | |
1722 if (UNBOUNDP (color_symbols)) | |
1723 { | |
1724 color_symbols = evaluate_xpm_color_symbols (); | |
1725 alist = Fcons (Fcons (Q_color_symbols, color_symbols), | |
1726 alist); | |
1727 } | |
1728 | |
1729 { | |
1730 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist); | |
1731 free_alist (alist); | |
1732 RETURN_UNGCPRO (result); | |
1733 } | |
1623 } | 1734 } |
1624 | 1735 |
1625 static int | 1736 static int |
1626 xpm_possible_dest_types (void) | 1737 xpm_possible_dest_types (void) |
1627 { | 1738 { |
1635 xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, | 1746 xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, |
1636 Lisp_Object pointer_fg, Lisp_Object pointer_bg, | 1747 Lisp_Object pointer_fg, Lisp_Object pointer_bg, |
1637 int dest_mask, Lisp_Object domain) | 1748 int dest_mask, Lisp_Object domain) |
1638 { | 1749 { |
1639 Lisp_Object device= IMAGE_INSTANCE_DEVICE (XIMAGE_INSTANCE (image_instance)); | 1750 Lisp_Object device= IMAGE_INSTANCE_DEVICE (XIMAGE_INSTANCE (image_instance)); |
1640 #ifdef HAVE_X_WINDOWS | 1751 |
1641 if (DEVICE_X_P (XDEVICE (device))) | 1752 MAYBE_DEVMETH (XDEVICE (device), |
1642 { | 1753 xpm_instantiate, |
1643 x_xpm_instantiate (image_instance, instantiator, | 1754 (image_instance, instantiator, pointer_fg, |
1644 pointer_fg, pointer_bg, | 1755 pointer_bg, dest_mask, domain)); |
1645 dest_mask, domain); | |
1646 return; | |
1647 } | |
1648 else | |
1649 #endif | |
1650 #ifdef HAVE_MS_WINDOWS | |
1651 if (DEVICE_MSWINDOWS_P (XDEVICE (device))) | |
1652 { | |
1653 mswindows_xpm_instantiate (image_instance, instantiator, | |
1654 pointer_fg, pointer_bg, | |
1655 dest_mask, domain); | |
1656 return; | |
1657 } | |
1658 else | |
1659 #endif | |
1660 signal_image_error ("Can't display XPM images on this device", device); | |
1661 } | 1756 } |
1662 | 1757 |
1663 #endif /* HAVE_XPM */ | 1758 #endif /* HAVE_XPM */ |
1664 | 1759 |
1665 | 1760 |