🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #87840

Re: getting RGB values from the X server for ps-print.el

#87840
From: Kevin Rodgers
Date: Fri, 26 Aug 1994 20:13
166 lines
6484 bytes
I wrote:
>I am working with Jim Thompson <thompson@wg2.waii.com>, the author of
>ps-print.el, to add support for printing buffers that have text in
>varying foreground and background colors.  Since PostScript and X both
>use the RGB color model, it should be simple to generate PostScript that
>uses the foreground and background colors from overlay and text property
>faces; unfortunately, there's no way to get the RGB values for a color
>name in Emacs Lisp currently.
>
>The simplest scheme I've come up with is to modify the predicate
>`x-color-defined-p' to return the RGB values (as a vector) instead of
>the symbol `t' to indicate success.  Here's a patch to illustrate:

[ChangeLog entry and patch deleted]

`x-color-defined-p' calls `defined_color', which calls `XParseColor' (to
translate the color name to an RGB value) and then `XAllocColor', which
returns a cell from the colormap most closely approximating the
requested RGB values.  Because the PostScript printing device may have
different color resolution abilities than the X display device, it would
be preferable if the "true" RGB values were returned from the color name
database, rather than the "actual" (approximate) values from the
colormap.

Here's a patch, based on the previous one, that adds an optional
argument to `x-color-defined-p' to allow the programmer to request the
true RGB value for a color name.  The original behavior is preserved
by default.

>WARNING: I've never written a line of X code in my life, I'm not
>familiar with garbage collection issues in Emacs C, and the following
>patch is completely untested -- I haven't even tried to compile it.

This is still true.

Fri Aug 26 1994 17:29:59  Kevin Rodgers <kevinr@ihs.com>

	* xfns.c (defined_color): Add a third argument ALLOC, which is a
	flag that controls whether a colormap cell is allocated.
	(x_decode_color): Pass 1 as the new ALLOC arg to defined_color.
	(Fx_color_defined_p): Accept an optional argument NO-ALLOC, and
	pass its inverted value as the new ALLOC arg to defined_color.

===================================================================
RCS file: RCS/xfns.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -c -r1.2 -r1.3
*** 1.2	1994/08/26 16:35:06
--- 1.3	1994/08/26 17:29:59
***************
*** 616,627 ****
  		   : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
  }
  
! /* Decide if color named COLOR is valid for the display
!    associated with the selected frame. */
  int
! defined_color (color, color_def)
       char *color;
       Color *color_def;
  {
    register int foo;
    Colormap screen_colormap;
--- 616,629 ----
  		   : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
  }
  
! /* Decide if color named COLOR is valid for the display associated with
!    the selected frame; if so, return the rgb values in COLOR_DEF.
!    If ALLOC is false, don't try to allocate a colormap cell. */
  int
! defined_color (color, color_def, alloc)
       char *color;
       Color *color_def;
+      int alloc;
  {
    register int foo;
    Colormap screen_colormap;
***************
*** 631,641 ****
    screen_colormap
      = DefaultColormap (x_current_display, XDefaultScreen (x_current_display));
  
!   foo = XParseColor (x_current_display, screen_colormap,
!        	      color, color_def)
!     && XAllocColor (x_current_display, screen_colormap, color_def);
  #else
!   foo = XParseColor (color, color_def) && XGetHardwareColor (color_def);
  #endif /* not HAVE_X11 */
    UNBLOCK_INPUT;
  
--- 633,643 ----
    screen_colormap
      = DefaultColormap (x_current_display, XDefaultScreen (x_current_display));
  
!   foo = XParseColor (x_current_display, screen_colormap, color, color_def)
!     && (! alloc || XAllocColor (x_current_display, screen_colormap, color_def));
  #else
!   foo = XParseColor (color, color_def)
!     && (! alloc || XGetHardwareColor (color_def));
  #endif /* not HAVE_X11 */
    UNBLOCK_INPUT;
  
***************
*** 672,678 ****
      return def;
  #endif
  
!   if (defined_color (XSTRING (arg)->data, &cdef))
      return cdef.pixel;
    else
      Fsignal (Qundefined_color, Fcons (arg, Qnil));
--- 674,680 ----
      return def;
  #endif
  
!   if (defined_color (XSTRING (arg)->data, &cdef, 1))
      return cdef.pixel;
    else
      Fsignal (Qundefined_color, Fcons (arg, Qnil));
***************
*** 2870,2886 ****
  }
  
  
! DEFUN ("x-color-defined-p", Fx_color_defined_p, Sx_color_defined_p, 1, 1, 0,
!   "Return a vector of RGB values if the X display supports the color named COLOR.")
!   (color)
!      Lisp_Object color;
  {
    Color foo;
    
    check_x ();
    CHECK_STRING (color, 0);
  
!   if (defined_color (XSTRING (color)->data, &foo))
      {
        Lisp_Object rgb[3];
  
--- 2872,2891 ----
  }
  
  
! DEFUN ("x-color-defined-p", Fx_color_defined_p, Sx_color_defined_p, 1, 2, 0,
!   "Return a vector of rgb values if the X display supports the color named COLOR.\n\
! Optional second arg NO-ALLOC means don't allocate a colormap cell: if\n\
! non-nil, the rgb values are returned from the color name database,\n\
! instead of the actual values from the colormap.")
!   (color, no_alloc)
!      Lisp_Object color, no_alloc;
  {
    Color foo;
    
    check_x ();
    CHECK_STRING (color, 0);
  
!   if (defined_color (XSTRING (color)->data, &foo, NILP(no_alloc)))
      {
        Lisp_Object rgb[3];

-- 
Kevin Rodgers <kevinr@ihs.com>		Project Engineer
Information Handling Services		Electronic Systems Development
15 Inverness Way East, M/S A203		
Englewood CO 80112 USA			(303) 397-2807[voice]/-2620[fax]
Technical Details
Message-ID: <9408262006.AA18643@airedale.ihsyp>
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!uunet!cs.utexas.edu!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!airedale.ai.mit.EDU!kevinr
References: <9408261935.AA18615@airedale.ihsyp>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,9b8ea3307cd86d87
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1994-08-26 21:27:47 PST
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!uunet!cs.utexas.edu!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!airedale.ai.mit.EDU!kevinr
From: kevinr@airedale.ai.mit.EDU (Kevin Rodgers)
Newsgroups: gnu.emacs.bug
Subject: Re: getting RGB values from the X server for ps-print.el
Date: 26 Aug 1994 16:13:11 -0400
Organization: GNUs Not Usenet
Lines: 166
Sender: daemon@cis.ohio-state.edu
Approved: bug-gnu-emacs@prep.ai.mit.edu
Distribution: gnu
Message-ID: <9408262006.AA18643@airedale.ihsyp>
References: <9408261935.AA18615@airedale.ihsyp>
Reply-To: Kevin Rodgers <kevinr@ihs.com>