comparison src/glyphs.c @ 288:e11d67e05968 r21-0b42

Import from CVS: tag r21-0b42
author cvs
date Mon, 13 Aug 2007 10:35:54 +0200
parents 558f606b08ae
children c9fe270a4101
comparison
equal deleted inserted replaced
287:13a0bd77a29d 288:e11d67e05968
53 Lisp_Object Qpointer_image_instance_p; 53 Lisp_Object Qpointer_image_instance_p;
54 Lisp_Object Qsubwindow_image_instance_p; 54 Lisp_Object Qsubwindow_image_instance_p;
55 Lisp_Object Qconst_glyph_variable; 55 Lisp_Object Qconst_glyph_variable;
56 Lisp_Object Qmono_pixmap, Qcolor_pixmap, Qsubwindow; 56 Lisp_Object Qmono_pixmap, Qcolor_pixmap, Qsubwindow;
57 Lisp_Object Q_file, Q_data, Q_face; 57 Lisp_Object Q_file, Q_data, Q_face;
58 Lisp_Object Qicon;
59 Lisp_Object Qformatted_string; 58 Lisp_Object Qformatted_string;
60 59
61 Lisp_Object Vcurrent_display_table; 60 Lisp_Object Vcurrent_display_table;
62 Lisp_Object Vtruncation_glyph, Vcontinuation_glyph, Voctal_escape_glyph; 61 Lisp_Object Vtruncation_glyph, Vcontinuation_glyph, Voctal_escape_glyph;
63 Lisp_Object Vcontrol_arrow_glyph, Vinvisible_text_glyph, Vhscroll_glyph; 62 Lisp_Object Vcontrol_arrow_glyph, Vinvisible_text_glyph, Vhscroll_glyph;
70 DEFINE_IMAGE_INSTANTIATOR_FORMAT (nothing); 69 DEFINE_IMAGE_INSTANTIATOR_FORMAT (nothing);
71 DEFINE_IMAGE_INSTANTIATOR_FORMAT (inherit); 70 DEFINE_IMAGE_INSTANTIATOR_FORMAT (inherit);
72 DEFINE_IMAGE_INSTANTIATOR_FORMAT (string); 71 DEFINE_IMAGE_INSTANTIATOR_FORMAT (string);
73 DEFINE_IMAGE_INSTANTIATOR_FORMAT (formatted_string); 72 DEFINE_IMAGE_INSTANTIATOR_FORMAT (formatted_string);
74 73
75 Lisp_Object x_locate_pixmap_file (Lisp_Object name); 74 #ifdef HAVE_WINDOW_SYSTEM
76 Lisp_Object mswindows_locate_pixmap_file (Lisp_Object name); 75 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xbm);
76 Lisp_Object Qxbm;
77
78 Lisp_Object Q_mask_file, Q_mask_data, Q_hotspot_x, Q_hotspot_y;
79 Lisp_Object Q_foreground, Q_background;
80 #ifndef BitmapSuccess
81 #define BitmapSuccess 0
82 #define BitmapOpenFailed 1
83 #define BitmapFileInvalid 2
84 #define BitmapNoMemory 3
85 #endif
86 #endif
77 87
78 #ifdef HAVE_XPM 88 #ifdef HAVE_XPM
79 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xpm); 89 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xpm);
80 Lisp_Object Qxpm; 90 Lisp_Object Qxpm;
81 Lisp_Object Q_color_symbols; 91 Lisp_Object Q_color_symbols;
1531 RETURN_UNGCPRO (result); 1541 RETURN_UNGCPRO (result);
1532 } 1542 }
1533 } 1543 }
1534 1544
1535 1545
1546 #ifdef HAVE_WINDOW_SYSTEM
1547 /**********************************************************************
1548 * XBM *
1549 **********************************************************************/
1550
1551 /* Check if DATA represents a valid inline XBM spec (i.e. a list
1552 of (width height bits), with checking done on the dimensions).
1553 If not, signal an error. */
1554
1555 static void
1556 check_valid_xbm_inline (Lisp_Object data)
1557 {
1558 Lisp_Object width, height, bits;
1559
1560 if (!CONSP (data) ||
1561 !CONSP (XCDR (data)) ||
1562 !CONSP (XCDR (XCDR (data))) ||
1563 !NILP (XCDR (XCDR (XCDR (data)))))
1564 signal_simple_error ("Must be list of 3 elements", data);
1565
1566 width = XCAR (data);
1567 height = XCAR (XCDR (data));
1568 bits = XCAR (XCDR (XCDR (data)));
1569
1570 CHECK_STRING (bits);
1571
1572 if (!NATNUMP (width))
1573 signal_simple_error ("Width must be a natural number", width);
1574
1575 if (!NATNUMP (height))
1576 signal_simple_error ("Height must be a natural number", height);
1577
1578 if (((XINT (width) * XINT (height)) / 8) > XSTRING_CHAR_LENGTH (bits))
1579 signal_simple_error ("data is too short for width and height",
1580 vector3 (width, height, bits));
1581 }
1582
1583 /* Validate method for XBM's. */
1584
1585 static void
1586 xbm_validate (Lisp_Object instantiator)
1587 {
1588 file_or_data_must_be_present (instantiator);
1589 }
1590
1591 /* Given a filename that is supposed to contain XBM data, return
1592 the inline representation of it as (width height bits). Return
1593 the hotspot through XHOT and YHOT, if those pointers are not 0.
1594 If there is no hotspot, XHOT and YHOT will contain -1.
1595
1596 If the function fails:
1597
1598 -- if OK_IF_DATA_INVALID is set and the data was invalid,
1599 return Qt.
1600 -- maybe return an error, or return Qnil.
1601 */
1602
1603
1604 Lisp_Object
1605 bitmap_to_lisp_data (Lisp_Object name, int *xhot, int *yhot,
1606 int ok_if_data_invalid)
1607 {
1608 unsigned int w, h;
1609 Extbyte *data;
1610 int result;
1611 CONST char *filename_ext;
1612
1613 GET_C_STRING_FILENAME_DATA_ALLOCA (name, filename_ext);
1614 result = read_bitmap_data_from_file (filename_ext, &w, &h,
1615 &data, xhot, yhot);
1616
1617 if (result == BitmapSuccess)
1618 {
1619 Lisp_Object retval;
1620 int len = (w + 7) / 8 * h;
1621
1622 retval = list3 (make_int (w), make_int (h),
1623 make_ext_string (data, len, FORMAT_BINARY));
1624 XFree ((char *) data);
1625 return retval;
1626 }
1627
1628 switch (result)
1629 {
1630 case BitmapOpenFailed:
1631 {
1632 /* should never happen */
1633 signal_double_file_error ("Opening bitmap file",
1634 "no such file or directory",
1635 name);
1636 }
1637 case BitmapFileInvalid:
1638 {
1639 if (ok_if_data_invalid)
1640 return Qt;
1641 signal_double_file_error ("Reading bitmap file",
1642 "invalid data in file",
1643 name);
1644 }
1645 case BitmapNoMemory:
1646 {
1647 signal_double_file_error ("Reading bitmap file",
1648 "out of memory",
1649 name);
1650 }
1651 default:
1652 {
1653 signal_double_file_error_2 ("Reading bitmap file",
1654 "unknown error code",
1655 make_int (result), name);
1656 }
1657 }
1658
1659 return Qnil; /* not reached */
1660 }
1661
1662 Lisp_Object
1663 xbm_mask_file_munging (Lisp_Object alist, Lisp_Object file,
1664 Lisp_Object mask_file, Lisp_Object console_type)
1665 {
1666 /* This is unclean but it's fairly standard -- a number of the
1667 bitmaps in /usr/include/X11/bitmaps use it -- so we support
1668 it. */
1669 if (NILP (mask_file)
1670 /* don't override explicitly specified mask data. */
1671 && NILP (assq_no_quit (Q_mask_data, alist))
1672 && !NILP (file))
1673 {
1674 mask_file = MAYBE_LISP_CONTYPE_METH
1675 (decode_console_type(console_type, ERROR_ME),
1676 locate_pixmap_file, (concat2 (file, build_string ("Mask"))));
1677 if (NILP (mask_file))
1678 mask_file = MAYBE_LISP_CONTYPE_METH
1679 (decode_console_type(console_type, ERROR_ME),
1680 locate_pixmap_file, (concat2 (file, build_string ("msk"))));
1681 }
1682
1683 if (!NILP (mask_file))
1684 {
1685 Lisp_Object mask_data =
1686 bitmap_to_lisp_data (mask_file, 0, 0, 0);
1687 alist = remassq_no_quit (Q_mask_file, alist);
1688 /* there can't be a :mask-data at this point. */
1689 alist = Fcons (Fcons (Q_mask_file, mask_file),
1690 Fcons (Fcons (Q_mask_data, mask_data), alist));
1691 }
1692
1693 return alist;
1694 }
1695
1696 /* Normalize method for XBM's. */
1697
1698 static Lisp_Object
1699 xbm_normalize (Lisp_Object inst, Lisp_Object console_type)
1700 {
1701 Lisp_Object file = Qnil, mask_file = Qnil;
1702 struct gcpro gcpro1, gcpro2, gcpro3;
1703 Lisp_Object alist = Qnil;
1704
1705 GCPRO3 (file, mask_file, alist);
1706
1707 /* Now, convert any file data into inline data for both the regular
1708 data and the mask data. At the end of this, `data' will contain
1709 the inline data (if any) or Qnil, and `file' will contain
1710 the name this data was derived from (if known) or Qnil.
1711 Likewise for `mask_file' and `mask_data'.
1712
1713 Note that if we cannot generate any regular inline data, we
1714 skip out. */
1715
1716 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
1717 console_type);
1718 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file,
1719 Q_mask_data, console_type);
1720
1721 if (CONSP (file)) /* failure locating filename */
1722 signal_double_file_error ("Opening bitmap file",
1723 "no such file or directory",
1724 Fcar (file));
1725
1726 if (NILP (file) && NILP (mask_file)) /* no conversion necessary */
1727 RETURN_UNGCPRO (inst);
1728
1729 alist = tagged_vector_to_alist (inst);
1730
1731 if (!NILP (file))
1732 {
1733 int xhot, yhot;
1734 Lisp_Object data = bitmap_to_lisp_data (file, &xhot, &yhot, 0);
1735 alist = remassq_no_quit (Q_file, alist);
1736 /* there can't be a :data at this point. */
1737 alist = Fcons (Fcons (Q_file, file),
1738 Fcons (Fcons (Q_data, data), alist));
1739
1740 if (xhot != -1 && NILP (assq_no_quit (Q_hotspot_x, alist)))
1741 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
1742 alist);
1743 if (yhot != -1 && NILP (assq_no_quit (Q_hotspot_y, alist)))
1744 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
1745 alist);
1746 }
1747
1748 alist = xbm_mask_file_munging (alist, file, mask_file, console_type);
1749
1750 {
1751 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
1752 free_alist (alist);
1753 RETURN_UNGCPRO (result);
1754 }
1755 }
1756
1757
1758 static int
1759 xbm_possible_dest_types (void)
1760 {
1761 return
1762 IMAGE_MONO_PIXMAP_MASK |
1763 IMAGE_COLOR_PIXMAP_MASK |
1764 IMAGE_POINTER_MASK;
1765 }
1766
1767 static void
1768 xbm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1769 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1770 int dest_mask, Lisp_Object domain)
1771 {
1772 Lisp_Object device= IMAGE_INSTANCE_DEVICE (XIMAGE_INSTANCE (image_instance));
1773
1774 MAYBE_DEVMETH (XDEVICE (device),
1775 xbm_instantiate,
1776 (image_instance, instantiator, pointer_fg,
1777 pointer_bg, dest_mask, domain));
1778 }
1779
1780 #endif
1781
1782
1536 #ifdef HAVE_XPM 1783 #ifdef HAVE_XPM
1537 1784
1538 /********************************************************************** 1785 /**********************************************************************
1539 * XPM * 1786 * XPM *
1540 **********************************************************************/ 1787 **********************************************************************/
2998 defkeyword (&Q_face, ":face"); 3245 defkeyword (&Q_face, ":face");
2999 3246
3000 #ifdef HAVE_XPM 3247 #ifdef HAVE_XPM
3001 defkeyword (&Q_color_symbols, ":color-symbols"); 3248 defkeyword (&Q_color_symbols, ":color-symbols");
3002 #endif 3249 #endif
3003 3250 #ifdef HAVE_WINDOW_SYSTEM
3251 defkeyword (&Q_mask_file, ":mask-file");
3252 defkeyword (&Q_mask_data, ":mask-data");
3253 defkeyword (&Q_hotspot_x, ":hotspot-x");
3254 defkeyword (&Q_hotspot_y, ":hotspot-y");
3255 defkeyword (&Q_foreground, ":foreground");
3256 defkeyword (&Q_background, ":background");
3257 #endif
3004 /* image specifiers */ 3258 /* image specifiers */
3005 3259
3006 DEFSUBR (Fimage_specifier_p); 3260 DEFSUBR (Fimage_specifier_p);
3007 /* Qimage in general.c */ 3261 /* Qimage in general.c */
3008 3262
3065 DEFSUBR (Fglyph_descent); 3319 DEFSUBR (Fglyph_descent);
3066 DEFSUBR (Fglyph_height); 3320 DEFSUBR (Fglyph_height);
3067 3321
3068 /* Qbuffer defined in general.c. */ 3322 /* Qbuffer defined in general.c. */
3069 /* Qpointer defined above */ 3323 /* Qpointer defined above */
3070 defsymbol (&Qicon, "icon");
3071 3324
3072 /* Errors */ 3325 /* Errors */
3073 deferror (&Qimage_conversion_error, 3326 deferror (&Qimage_conversion_error,
3074 "image-conversion-error", 3327 "image-conversion-error",
3075 "image-conversion error", Qio_error); 3328 "image-conversion error", Qio_error);
3129 IIFORMAT_HAS_METHOD (formatted_string, validate); 3382 IIFORMAT_HAS_METHOD (formatted_string, validate);
3130 IIFORMAT_HAS_METHOD (formatted_string, possible_dest_types); 3383 IIFORMAT_HAS_METHOD (formatted_string, possible_dest_types);
3131 IIFORMAT_HAS_METHOD (formatted_string, instantiate); 3384 IIFORMAT_HAS_METHOD (formatted_string, instantiate);
3132 3385
3133 IIFORMAT_VALID_KEYWORD (formatted_string, Q_data, check_valid_string); 3386 IIFORMAT_VALID_KEYWORD (formatted_string, Q_data, check_valid_string);
3387
3388 #ifdef HAVE_WINDOW_SYSTEM
3389 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xbm, "xbm");
3390
3391 IIFORMAT_HAS_METHOD (xbm, validate);
3392 IIFORMAT_HAS_METHOD (xbm, normalize);
3393 IIFORMAT_HAS_METHOD (xbm, possible_dest_types);
3394 IIFORMAT_HAS_METHOD (xbm, instantiate);
3395
3396 IIFORMAT_VALID_KEYWORD (xbm, Q_data, check_valid_xbm_inline);
3397 IIFORMAT_VALID_KEYWORD (xbm, Q_file, check_valid_string);
3398 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_data, check_valid_xbm_inline);
3399 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_file, check_valid_string);
3400 IIFORMAT_VALID_KEYWORD (xbm, Q_hotspot_x, check_valid_int);
3401 IIFORMAT_VALID_KEYWORD (xbm, Q_hotspot_y, check_valid_int);
3402 IIFORMAT_VALID_KEYWORD (xbm, Q_foreground, check_valid_string);
3403 IIFORMAT_VALID_KEYWORD (xbm, Q_background, check_valid_string);
3404 #endif /* HAVE_WINDOW_SYSTEM */
3134 3405
3135 #ifdef HAVE_XPM 3406 #ifdef HAVE_XPM
3136 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xpm, "xpm"); 3407 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xpm, "xpm");
3137 3408
3138 IIFORMAT_HAS_METHOD (xpm, validate); 3409 IIFORMAT_HAS_METHOD (xpm, validate);