comparison src/glyphs-x.c @ 219:262b8bb4a523 r20-4b8

Import from CVS: tag r20-4b8
author cvs
date Mon, 13 Aug 2007 10:09:35 +0200
parents d44af0c54775
children 6c0ae1f9357f
comparison
equal deleted inserted replaced
218:c9f226976f56 219:262b8bb4a523
144 if (!p->data) 144 if (!p->data)
145 return; 145 return;
146 146
147 if (DEVICE_LIVE_P (XDEVICE (p->device))) 147 if (DEVICE_LIVE_P (XDEVICE (p->device)))
148 { 148 {
149 Screen *scr = LISP_DEVICE_TO_X_SCREEN (IMAGE_INSTANCE_DEVICE (p)); 149 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (p->device));
150 150
151 if (IMAGE_INSTANCE_X_PIXMAP (p)) 151 if (IMAGE_INSTANCE_X_PIXMAP (p))
152 XFreePixmap (DisplayOfScreen (scr), IMAGE_INSTANCE_X_PIXMAP (p)); 152 XFreePixmap (dpy, IMAGE_INSTANCE_X_PIXMAP (p));
153 if (IMAGE_INSTANCE_X_MASK (p) && 153 if (IMAGE_INSTANCE_X_MASK (p) &&
154 IMAGE_INSTANCE_X_MASK (p) != IMAGE_INSTANCE_X_PIXMAP (p)) 154 IMAGE_INSTANCE_X_MASK (p) != IMAGE_INSTANCE_X_PIXMAP (p))
155 XFreePixmap (DisplayOfScreen (scr), IMAGE_INSTANCE_X_MASK (p)); 155 XFreePixmap (dpy, IMAGE_INSTANCE_X_MASK (p));
156 IMAGE_INSTANCE_X_PIXMAP (p) = 0; 156 IMAGE_INSTANCE_X_PIXMAP (p) = 0;
157 IMAGE_INSTANCE_X_MASK (p) = 0; 157 IMAGE_INSTANCE_X_MASK (p) = 0;
158 158
159 if (IMAGE_INSTANCE_X_CURSOR (p)) 159 if (IMAGE_INSTANCE_X_CURSOR (p))
160 { 160 {
161 XFreeCursor (DisplayOfScreen (scr), IMAGE_INSTANCE_X_CURSOR (p)); 161 XFreeCursor (dpy, IMAGE_INSTANCE_X_CURSOR (p));
162 IMAGE_INSTANCE_X_CURSOR (p) = 0; 162 IMAGE_INSTANCE_X_CURSOR (p) = 0;
163 } 163 }
164 164
165 if (IMAGE_INSTANCE_X_NPIXELS (p) != 0) 165 if (IMAGE_INSTANCE_X_NPIXELS (p) != 0)
166 { 166 {
167 XFreeColors (DisplayOfScreen (scr), 167 XFreeColors (dpy,
168 DefaultColormapOfScreen (scr), 168 DEVICE_X_COLORMAP (XDEVICE(p->device)),
169 IMAGE_INSTANCE_X_PIXELS (p), 169 IMAGE_INSTANCE_X_PIXELS (p),
170 IMAGE_INSTANCE_X_NPIXELS (p), 0); 170 IMAGE_INSTANCE_X_NPIXELS (p), 0);
171 IMAGE_INSTANCE_X_NPIXELS (p) = 0; 171 IMAGE_INSTANCE_X_NPIXELS (p) = 0;
172 } 172 }
173 } 173 }
565 int npixels, 565 int npixels,
566 Lisp_Object instantiator) 566 Lisp_Object instantiator)
567 { 567 {
568 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 568 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
569 Display *dpy; 569 Display *dpy;
570 Screen *xs;
571 GC gc; 570 GC gc;
572 Drawable d; 571 Drawable d;
573 Pixmap pixmap; 572 Pixmap pixmap;
574 573
575 if (!DEVICE_X_P (XDEVICE (device))) 574 if (!DEVICE_X_P (XDEVICE (device)))
576 signal_simple_error ("Not an X device", device); 575 signal_simple_error ("Not an X device", device);
577 576
578 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); 577 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
579 xs = DefaultScreenOfDisplay (dpy); 578 d = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (device)));
580 d = RootWindowOfScreen (xs);
581 579
582 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK)) 580 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK))
583 incompatible_image_types (instantiator, dest_mask, 581 incompatible_image_types (instantiator, dest_mask,
584 IMAGE_COLOR_PIXMAP_MASK); 582 IMAGE_COLOR_PIXMAP_MASK);
585 583
829 static Pixmap 827 static Pixmap
830 pixmap_from_xbm_inline (Lisp_Object device, int width, int height, 828 pixmap_from_xbm_inline (Lisp_Object device, int width, int height,
831 /* Note that data is in ext-format! */ 829 /* Note that data is in ext-format! */
832 CONST Extbyte *bits) 830 CONST Extbyte *bits)
833 { 831 {
834 Screen *screen = LISP_DEVICE_TO_X_SCREEN (device); 832 return XCreatePixmapFromBitmapData (DEVICE_X_DISPLAY (XDEVICE(device)),
835 return XCreatePixmapFromBitmapData (DisplayOfScreen (screen), 833 XtWindow (DEVICE_XT_APP_SHELL (XDEVICE (device))),
836 RootWindowOfScreen (screen),
837 (char *) bits, width, height, 834 (char *) bits, width, height,
838 1, 0, 1); 835 1, 0, 1);
839 } 836 }
840 837
841 /* Given inline data for a mono pixmap, initialize the given 838 /* Given inline data for a mono pixmap, initialize the given
856 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 853 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
857 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground); 854 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
858 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background); 855 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
859 Display *dpy; 856 Display *dpy;
860 Screen *scr; 857 Screen *scr;
858 Drawable draw;
861 enum image_instance_type type; 859 enum image_instance_type type;
862 860
863 if (!DEVICE_X_P (XDEVICE (device))) 861 if (!DEVICE_X_P (XDEVICE (device)))
864 signal_simple_error ("Not an X device", device); 862 signal_simple_error ("Not an X device", device);
865 863
866 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); 864 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
865 draw = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (device)));
867 scr = DefaultScreenOfDisplay (dpy); 866 scr = DefaultScreenOfDisplay (dpy);
868 867
869 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) && 868 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
870 (dest_mask & IMAGE_COLOR_PIXMAP_MASK)) 869 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
871 { 870 {
900 } 899 }
901 break; 900 break;
902 901
903 case IMAGE_COLOR_PIXMAP: 902 case IMAGE_COLOR_PIXMAP:
904 { 903 {
905 Dimension d = DefaultDepthOfScreen (scr); 904 Dimension d = DEVICE_X_DEPTH (XDEVICE(device));
906 unsigned long fg = BlackPixelOfScreen (scr); 905 unsigned long fg = BlackPixelOfScreen (scr);
907 unsigned long bg = WhitePixelOfScreen (scr); 906 unsigned long bg = WhitePixelOfScreen (scr);
908 907
909 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground)) 908 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
910 foreground = 909 foreground =
927 color instances here and GC-protect them, so this doesn't 926 color instances here and GC-protect them, so this doesn't
928 happen. */ 927 happen. */
929 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground; 928 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
930 IMAGE_INSTANCE_PIXMAP_BG (ii) = background; 929 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
931 IMAGE_INSTANCE_X_PIXMAP (ii) = 930 IMAGE_INSTANCE_X_PIXMAP (ii) =
932 XCreatePixmapFromBitmapData (DisplayOfScreen (scr), 931 XCreatePixmapFromBitmapData (dpy, draw,
933 RootWindowOfScreen (scr),
934 (char *) bits, width, height, 932 (char *) bits, width, height,
935 fg, bg, d); 933 fg, bg, d);
936 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d; 934 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d;
937 } 935 }
938 break; 936 break;
943 Pixmap source; 941 Pixmap source;
944 942
945 check_pointer_sizes (scr, width, height, instantiator); 943 check_pointer_sizes (scr, width, height, instantiator);
946 944
947 source = 945 source =
948 XCreatePixmapFromBitmapData (DisplayOfScreen (scr), 946 XCreatePixmapFromBitmapData (dpy, draw,
949 RootWindowOfScreen (scr),
950 (char *) bits, width, height, 947 (char *) bits, width, height,
951 1, 0, 1); 948 1, 0, 1);
952 949
953 if (NILP (foreground)) 950 if (NILP (foreground))
954 foreground = pointer_fg; 951 foreground = pointer_fg;
1262 extract_xpm_color_names (XpmAttributes *xpmattrs, Lisp_Object device, 1259 extract_xpm_color_names (XpmAttributes *xpmattrs, Lisp_Object device,
1263 Lisp_Object domain, 1260 Lisp_Object domain,
1264 Lisp_Object color_symbol_alist) 1261 Lisp_Object color_symbol_alist)
1265 { 1262 {
1266 /* This function can GC */ 1263 /* This function can GC */
1267 Screen *xs = LISP_DEVICE_TO_X_SCREEN (device); 1264 Display *dpy = DEVICE_X_DISPLAY (XDEVICE(device));
1268 Display *dpy = DisplayOfScreen (xs); 1265 Colormap cmap = DEVICE_X_COLORMAP (XDEVICE(device));
1269 Colormap cmap = DefaultColormapOfScreen (xs);
1270 XColor color; 1266 XColor color;
1271 Lisp_Object rest; 1267 Lisp_Object rest;
1272 Lisp_Object results = Qnil; 1268 Lisp_Object results = Qnil;
1273 int i; 1269 int i;
1274 XpmColorSymbol *symbols; 1270 XpmColorSymbol *symbols;
1349 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 1345 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1350 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); 1346 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1351 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 1347 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1352 Display *dpy; 1348 Display *dpy;
1353 Screen *xs; 1349 Screen *xs;
1350 Colormap cmap;
1351 int depth;
1354 Pixmap pixmap; 1352 Pixmap pixmap;
1355 Pixmap mask = 0; 1353 Pixmap mask = 0;
1356 XpmAttributes xpmattrs; 1354 XpmAttributes xpmattrs;
1357 int result; 1355 int result;
1358 XpmColorSymbol *color_symbols; 1356 XpmColorSymbol *color_symbols;
1364 1362
1365 if (!DEVICE_X_P (XDEVICE (device))) 1363 if (!DEVICE_X_P (XDEVICE (device)))
1366 signal_simple_error ("Not an X device", device); 1364 signal_simple_error ("Not an X device", device);
1367 1365
1368 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); 1366 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
1367 cmap = DEVICE_X_COLORMAP (XDEVICE(device));
1368 depth = DEVICE_X_DEPTH (XDEVICE(device));
1369 xs = DefaultScreenOfDisplay (dpy); 1369 xs = DefaultScreenOfDisplay (dpy);
1370 1370
1371 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK) 1371 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
1372 type = IMAGE_COLOR_PIXMAP; 1372 type = IMAGE_COLOR_PIXMAP;
1373 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK) 1373 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
1400 } 1400 }
1401 else 1401 else
1402 { 1402 {
1403 xpmattrs.closeness = 65535; 1403 xpmattrs.closeness = 65535;
1404 xpmattrs.valuemask |= XpmCloseness; 1404 xpmattrs.valuemask |= XpmCloseness;
1405 xpmattrs.depth = depth;
1406 xpmattrs.valuemask |= XpmDepth;
1407 xpmattrs.visual = DEVICE_X_VISUAL (XDEVICE(device));
1408 xpmattrs.valuemask |= XpmVisual;
1409 xpmattrs.colormap = cmap;
1410 xpmattrs.valuemask |= XpmColormap;
1405 } 1411 }
1406 1412
1407 color_symbols = extract_xpm_color_names (&xpmattrs, device, domain, 1413 color_symbols = extract_xpm_color_names (&xpmattrs, device, domain,
1408 color_symbol_alist); 1414 color_symbol_alist);
1409 1415
1410 result = XpmCreatePixmapFromBuffer (dpy, 1416 result = XpmCreatePixmapFromBuffer (dpy,
1411 RootWindowOfScreen (xs), 1417 XtWindow(DEVICE_XT_APP_SHELL (XDEVICE(device))),
1412 (char *) XSTRING_DATA (data), 1418 (char *) XSTRING_DATA (data),
1413 &pixmap, &mask, &xpmattrs); 1419 &pixmap, &mask, &xpmattrs);
1414 1420
1415 if (color_symbols) 1421 if (color_symbols)
1416 { 1422 {
1498 case IMAGE_MONO_PIXMAP: 1504 case IMAGE_MONO_PIXMAP:
1499 break; 1505 break;
1500 1506
1501 case IMAGE_COLOR_PIXMAP: 1507 case IMAGE_COLOR_PIXMAP:
1502 { 1508 {
1503 /* XpmReadFileToPixmap() doesn't return the depth (bogus!) so 1509 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth;
1504 we need to get it ourself. (No, xpmattrs.depth is not it;
1505 that's an input slot, not output.) We could just assume
1506 that it has the same depth as the root window, but some
1507 devices allow more than one depth, so that isn't
1508 necessarily correct (I guess?) */
1509 Window root;
1510 int x, y;
1511 unsigned int w2, h2, bw;
1512
1513 unsigned int d;
1514
1515 if (!XGetGeometry (dpy, pixmap, &root, &x, &y, &w2, &h2, &bw, &d))
1516 abort ();
1517 if (w != w2 || h != h2)
1518 abort ();
1519
1520 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d;
1521 } 1510 }
1522 break; 1511 break;
1523 1512
1524 case IMAGE_POINTER: 1513 case IMAGE_POINTER:
1525 { 1514 {
1604 1593
1605 /* If (fg.pixel == bg.pixel) then probably something has 1594 /* If (fg.pixel == bg.pixel) then probably something has
1606 gone wrong, but I don't think signalling an error would 1595 gone wrong, but I don't think signalling an error would
1607 be appropriate. */ 1596 be appropriate. */
1608 1597
1609 XQueryColor (dpy, DefaultColormapOfScreen (xs), &fg); 1598 XQueryColor (dpy, cmap, &fg);
1610 XQueryColor (dpy, DefaultColormapOfScreen (xs), &bg); 1599 XQueryColor (dpy, cmap, &bg);
1611 1600
1612 /* If the foreground is lighter than the background, swap them. 1601 /* If the foreground is lighter than the background, swap them.
1613 (This occurs semi-randomly, depending on the ordering of the 1602 (This occurs semi-randomly, depending on the ordering of the
1614 color list in the XPM file.) 1603 color list in the XPM file.)
1615 */ 1604 */
1738 { 1727 {
1739 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 1728 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1740 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 1729 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1741 Display *dpy; 1730 Display *dpy;
1742 Screen *scr; 1731 Screen *scr;
1732 Visual *visual;
1743 Dimension depth; 1733 Dimension depth;
1744 struct imagick_unwind_data unwind; 1734 struct imagick_unwind_data unwind;
1745 int speccount = specpdl_depth (); 1735 int speccount = specpdl_depth ();
1746 ImageInfo image_info; 1736 ImageInfo image_info;
1747 1737
1751 if (!DEVICE_X_P (XDEVICE (device))) 1741 if (!DEVICE_X_P (XDEVICE (device)))
1752 signal_simple_error ("Not an X device", device); 1742 signal_simple_error ("Not an X device", device);
1753 1743
1754 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); 1744 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
1755 scr = DefaultScreenOfDisplay (dpy); 1745 scr = DefaultScreenOfDisplay (dpy);
1756 depth = DefaultDepthOfScreen (scr); 1746 depth = DEVICE_X_DEPTH (XDEVICE (device));
1747 visual = DEVICE_X_VISUAL (XDEVICE (device));
1748
1757 /* Set up the unwind */ 1749 /* Set up the unwind */
1758 memset (&unwind, 0, sizeof (unwind)); 1750 memset (&unwind, 0, sizeof (unwind));
1759 unwind.dpy = dpy; 1751 unwind.dpy = dpy;
1760 record_unwind_protect(imagick_instantiate_unwind,make_opaque_ptr(&unwind)); 1752 record_unwind_protect(imagick_instantiate_unwind,make_opaque_ptr(&unwind));
1761 1753
1785 1777
1786 #if 1 1778 #if 1
1787 DescribeImage(unwind.image,stderr,1); 1779 DescribeImage(unwind.image,stderr,1);
1788 #endif 1780 #endif
1789 1781
1790 unwind.ximage = XCreateImage(dpy, DefaultVisualOfScreen (scr), 1782 unwind.ximage = XCreateImage(dpy, visual, depth,
1791 depth, 1783 (depth == 1) ? XYPixmap : ZPixmap,
1792 (depth == 1) ? XYPixmap : ZPixmap, 1784 0, 0,
1793 0, 0, 1785 unwind.image->columns,
1794 unwind.image->columns, 1786 unwind.image->rows,
1795 unwind.image->rows, 1787 XBitmapPad(dpy), 0);
1796 XBitmapPad(dpy), 0);
1797 1788
1798 if (!unwind.ximage) { 1789 if (!unwind.ximage) {
1799 signal_simple_error("Unable to allocate XImage structure", 1790 signal_simple_error("Unable to allocate XImage structure",
1800 instantiator); 1791 instantiator);
1801 } 1792 }
1841 { 1832 {
1842 color.red = p->red; 1833 color.red = p->red;
1843 color.green = p->green; 1834 color.green = p->green;
1844 color.blue = p->blue; 1835 color.blue = p->blue;
1845 color.flags = DoRed | DoGreen | DoBlue; 1836 color.flags = DoRed | DoGreen | DoBlue;
1846 allocate_nearest_color (dpy, DefaultColormapOfScreen (scr), &color); 1837 allocate_nearest_color (dpy, DefaultColormapOfScreen (scr), visual, &color);
1847 unwind.pixels[i] = color.pixel; 1838 unwind.pixels[i] = color.pixel;
1848 1839
1849 for (j=0; j <= ((int) p->length); j++) 1840 for (j=0; j <= ((int) p->length); j++)
1850 { 1841 {
1851 *q++=(unsigned char) color.pixel; 1842 *q++=(unsigned char) color.pixel;
2411 return 0; 2402 return 0;
2412 } 2403 }
2413 2404
2414 { 2405 {
2415 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (IMAGE_INSTANCE_DEVICE (p))); 2406 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
2416 Screen *scr = DefaultScreenOfDisplay (dpy); 2407 Drawable draw = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (IMAGE_INSTANCE_DEVICE (p))));
2417 Dimension d = DefaultDepthOfScreen (scr); 2408 Dimension d = DEVICE_X_DEPTH (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
2418 Pixmap new = XCreatePixmap (dpy, RootWindowOfScreen (scr), 2409 Pixmap new = XCreatePixmap (dpy, draw,
2419 IMAGE_INSTANCE_PIXMAP_WIDTH (p), 2410 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
2420 IMAGE_INSTANCE_PIXMAP_HEIGHT (p), d); 2411 IMAGE_INSTANCE_PIXMAP_HEIGHT (p), d);
2421 XColor color; 2412 XColor color;
2422 XGCValues gcv; 2413 XGCValues gcv;
2423 GC gc; 2414 GC gc;