2 Copyright (C) 1993, 1994 Free Software Foundation.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This is derived from work by Lucid (some parts very loosely so). */
22 #include <sys/types.h>
37 #include "dispextern.h"
39 #include "blockinput.h"
41 #include "intervals.h"
44 /* Compensate for bug in Xos.h on some systems, on which it requires
45 time.h. On some such systems, Xos.h tries to redefine struct
46 timeval and struct timezone if USG is #defined while it is
48 #ifdef XOS_NEEDS_TIME_H
61 #endif /* HAVE_X_WINDOWS */
63 /* An explanation of the face data structures. */
65 /* ========================= Face Data Structures =========================
67 Let FACE-NAME be a symbol naming a face.
69 Let FACE-VECTOR be (assq FACE-NAME (frame-face-alist FRAME))
70 FACE-VECTOR is either nil, or a vector of the form
71 [face NAME ID FONT FOREGROUND BACKGROUND BACKGROUND-PIXMAP UNDERLINE-P]
73 face is the symbol `face',
74 NAME is the symbol with which this vector is associated (a backpointer),
75 ID is the face ID, an integer used internally by the C code to identify
77 FONT, FOREGROUND, and BACKGROUND are strings naming the fonts and colors
79 BACKGROUND-PIXMAP is the name of an x bitmap filename, which we don't
81 UNDERLINE-P is non-nil if the face should be underlined.
82 If any of these elements are nil, that parameter is considered
83 unspecified; parameters from faces specified by lower-priority
84 overlays or text properties, or the parameters of the frame itself,
85 can show through. (lisp/faces.el maintains these lists.)
87 (assq FACE-NAME global-face-data) returns a vector describing the
88 global parameters for that face.
90 Let PARAM-FACE be FRAME->output_data.x->param_faces[Faref (FACE-VECTOR, 2)].
91 PARAM_FACE is a struct face whose members are the Xlib analogues of
92 the parameters in FACE-VECTOR. If an element of FACE-VECTOR is
93 nil, then the corresponding member of PARAM_FACE is FACE_DEFAULT.
94 These faces are called "parameter faces", because they're the ones
95 lisp manipulates to control what gets displayed. Elements 0 and 1
96 of FRAME->output_data.x->param_faces are special - they describe the
97 default and mode line faces. None of the faces in param_faces have
98 GC's. (See src/dispextern.h for the definition of struct face.
99 lisp/faces.el maintains the isomorphism between face_alist and
102 The functions compute_char_face and compute_glyph_face find and
103 combine the parameter faces associated with overlays and text
104 properties. The resulting faces are called "computed faces"; none
105 of their members are FACE_DEFAULT; they are completely specified.
106 They then call intern_compute_face to search
107 FRAME->output_data.x->computed_faces for a matching face, add one if
108 none is found, and return the index into
109 FRAME->output_data.x->computed_faces. FRAME's glyph matrices use these
110 indices to record the faces of the matrix characters, and the X
111 display hooks consult compute_faces to decide how to display these
112 characters. Elements 0 and 1 of computed_faces always describe the
113 default and mode-line faces.
115 Each computed face belongs to a particular frame.
117 Computed faces have graphics contexts some of the time.
118 intern_face builds a GC for a specified computed face
119 if it doesn't have one already.
120 clear_face_cache clears out the GCs of all computed faces.
121 This is done from time to time so that we don't hold on to
122 lots of GCs that are no longer needed.
124 If a computed face has 0 as its font,
125 it is unused, and can be reused by new_computed_face.
129 Symbols naming faces must have associations on all frames; for any
130 FRAME, for all FACE-NAME, if (assq FACE-NAME (frame-face-alist
131 FRAME)) is non-nil, it must be non-nil for all frames.
133 Analogously, indices into param_faces must be valid on all frames;
134 if param_faces[i] is a non-zero face pointer on one frame, then it
135 must be filled in on all frames. Code assumes that face ID's can
136 be used on any frame.
140 Why do we keep param_faces and computed_faces separate?
141 computed_faces contains an element for every combination of facial
142 parameters we have ever displayed. indices into param_faces have
143 to be valid on all frames. If they were the same array, then that
144 array would grow very large on all frames, because any facial
145 combination displayed on any frame would need to be a valid entry
148 /* Definitions and declarations. */
150 /* The number of face-id's in use (same for all frames). */
151 static int next_face_id
;
153 /* The number of the face to use to indicate the region. */
154 static int region_face
;
156 /* This is what appears in a slot in a face to signify that the face
157 does not specify that display aspect. */
158 #define FACE_DEFAULT (~0)
160 Lisp_Object Qface
, Qmouse_face
;
161 Lisp_Object Qpixmap_spec_p
;
163 int face_name_id_number ( /* FRAME_PTR, Lisp_Object name */ );
165 struct face
*intern_face ( /* FRAME_PTR, struct face * */ );
166 static int new_computed_face ( /* FRAME_PTR, struct face * */ );
167 static int intern_computed_face ( /* FRAME_PTR, struct face * */ );
168 static void ensure_face_ready ( /* FRAME_PTR, int id */ );
169 void recompute_basic_faces ( /* FRAME_PTR f */ );
171 /* Allocating, copying, and comparing struct faces. */
173 /* Allocate a new face */
177 struct face
*result
= (struct face
*) xmalloc (sizeof (struct face
));
178 bzero (result
, sizeof (struct face
));
179 result
->font
= (XFontStruct
*) FACE_DEFAULT
;
180 result
->foreground
= FACE_DEFAULT
;
181 result
->background
= FACE_DEFAULT
;
182 result
->stipple
= FACE_DEFAULT
;
186 /* Make a new face that's a copy of an existing one. */
191 struct face
*result
= allocate_face ();
193 result
->font
= face
->font
;
194 result
->foreground
= face
->foreground
;
195 result
->background
= face
->background
;
196 result
->stipple
= face
->stipple
;
197 result
->underline
= face
->underline
;
198 result
->pixmap_h
= face
->pixmap_h
;
199 result
->pixmap_w
= face
->pixmap_w
;
205 face_eql (face1
, face2
)
206 struct face
*face1
, *face2
;
208 return ( face1
->font
== face2
->font
209 && face1
->foreground
== face2
->foreground
210 && face1
->background
== face2
->background
211 && face1
->stipple
== face2
->stipple
212 && face1
->underline
== face2
->underline
);
215 /* Managing graphics contexts of faces. */
217 #ifdef HAVE_X_WINDOWS
218 /* Given a computed face, construct its graphics context if necessary. */
221 intern_face (f
, face
)
234 if (face
->foreground
!= FACE_DEFAULT
)
235 xgcv
.foreground
= face
->foreground
;
237 xgcv
.foreground
= f
->output_data
.x
->foreground_pixel
;
239 if (face
->background
!= FACE_DEFAULT
)
240 xgcv
.background
= face
->background
;
242 xgcv
.background
= f
->output_data
.x
->background_pixel
;
244 if (face
->font
&& face
->font
!= (XFontStruct
*) FACE_DEFAULT
)
245 xgcv
.font
= face
->font
->fid
;
247 xgcv
.font
= f
->output_data
.x
->font
->fid
;
249 xgcv
.graphics_exposures
= 0;
251 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
252 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
254 xgcv
.fill_style
= FillStippled
;
255 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
256 mask
|= GCFillStyle
| GCStipple
;
259 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
269 /* Clear out all graphics contexts for all computed faces
270 except for the default and mode line faces.
271 This should be done from time to time just to avoid
272 keeping too many graphics contexts that are no longer needed. */
277 Lisp_Object tail
, frame
;
280 FOR_EACH_FRAME (tail
, frame
)
282 FRAME_PTR f
= XFRAME (frame
);
286 Display
*dpy
= FRAME_X_DISPLAY (f
);
288 for (i
= 2; i
< FRAME_N_COMPUTED_FACES (f
); i
++)
290 struct face
*face
= FRAME_COMPUTED_FACES (f
) [i
];
292 XFreeGC (dpy
, face
->gc
);
301 /* Allocating, freeing, and duplicating fonts, colors, and pixmaps.
303 These functions operate on param faces only.
304 Computed faces get their fonts, colors and pixmaps
305 by merging param faces. */
315 return (XFontStruct
*) FACE_DEFAULT
;
317 CHECK_STRING (name
, 0);
319 font
= XLoadQueryFont (FRAME_X_DISPLAY (f
), (char *) XSTRING (name
)->data
);
323 Fsignal (Qerror
, Fcons (build_string ("undefined font"),
324 Fcons (name
, Qnil
)));
329 unload_font (f
, font
)
333 int len
= FRAME_N_COMPUTED_FACES (f
);
336 if (!font
|| font
== ((XFontStruct
*) FACE_DEFAULT
))
340 /* Invalidate any computed faces which use this font,
341 and free their GC's if they have any. */
342 for (i
= 2; i
< len
; i
++)
344 struct face
*face
= FRAME_COMPUTED_FACES (f
)[i
];
345 if (face
->font
== font
)
347 Display
*dpy
= FRAME_X_DISPLAY (f
);
349 XFreeGC (dpy
, face
->gc
);
351 /* This marks the computed face as available to reuse. */
356 XFreeFont (FRAME_X_DISPLAY (f
), font
);
371 CHECK_STRING (name
, 0);
372 /* if the colormap is full, defined_color will return a best match
373 to the values in an an existing cell. */
374 result
= defined_color(f
, (char *) XSTRING (name
)->data
, &color
, 1);
376 Fsignal (Qerror
, Fcons (build_string ("undefined color"),
377 Fcons (name
, Qnil
)));
378 return (unsigned long) color
.pixel
;
382 unload_color (f
, pixel
)
387 Display
*dpy
= FRAME_X_DISPLAY (f
);
388 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
390 if (pixel
== FACE_DEFAULT
391 || pixel
== BLACK_PIX_DEFAULT (f
)
392 || pixel
== WHITE_PIX_DEFAULT (f
))
394 cmap
= DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy
));
396 /* If display has an immutable color map, freeing colors is not
397 necessary and some servers don't allow it. So don't do it. */
398 if (! (class == StaticColor
|| class == StaticGray
|| class == TrueColor
))
400 int len
= FRAME_N_COMPUTED_FACES (f
);
404 /* Invalidate any computed faces which use this color,
405 and free their GC's if they have any. */
406 for (i
= 2; i
< len
; i
++)
408 struct face
*face
= FRAME_COMPUTED_FACES (f
)[i
];
409 if (face
->foreground
== pixel
410 || face
->background
== pixel
)
412 Display
*dpy
= FRAME_X_DISPLAY (f
);
414 XFreeGC (dpy
, face
->gc
);
416 /* This marks the computed face as available to reuse. */
421 XFreeColors (dpy
, cmap
, &pixel
, 1, (unsigned long)0);
426 DEFUN ("pixmap-spec-p", Fpixmap_spec_p
, Spixmap_spec_p
, 1, 1, 0,
427 "Return t if ARG is a valid pixmap specification.")
431 Lisp_Object height
, width
;
433 return ((STRINGP (arg
)
435 && CONSP (XCONS (arg
)->cdr
)
436 && CONSP (XCONS (XCONS (arg
)->cdr
)->cdr
)
437 && NILP (XCONS (XCONS (XCONS (arg
)->cdr
)->cdr
)->cdr
)
438 && (width
= XCONS (arg
)->car
, INTEGERP (width
))
439 && (height
= XCONS (XCONS (arg
)->cdr
)->car
, INTEGERP (height
))
440 && STRINGP (XCONS (XCONS (XCONS (arg
)->cdr
)->cdr
)->car
)
443 /* The string must have enough bits for width * height. */
444 && ((XSTRING (XCONS (XCONS (XCONS (arg
)->cdr
)->cdr
)->car
)->size
445 * (BITS_PER_INT
/ sizeof (int)))
446 >= XFASTINT (width
) * XFASTINT (height
))))
450 /* Load a bitmap according to NAME (which is either a file name
451 or a pixmap spec). Return the bitmap_id (see xfns.c)
452 or get an error if NAME is invalid.
454 Store the bitmap width in *W_PTR and height in *H_PTR. */
457 load_pixmap (f
, name
, w_ptr
, h_ptr
)
460 unsigned int *w_ptr
, *h_ptr
;
468 tem
= Fpixmap_spec_p (name
);
470 wrong_type_argument (Qpixmap_spec_p
, name
);
476 /* Decode a bitmap spec into a bitmap. */
481 w
= XINT (Fcar (name
));
482 h
= XINT (Fcar (Fcdr (name
)));
483 bits
= Fcar (Fcdr (Fcdr (name
)));
485 bitmap_id
= x_create_bitmap_from_data (f
, XSTRING (bits
)->data
,
490 /* It must be a string -- a file name. */
491 bitmap_id
= x_create_bitmap_from_file (f
, name
);
496 Fsignal (Qerror
, Fcons (build_string ("invalid or undefined bitmap"),
497 Fcons (name
, Qnil
)));
499 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
500 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
505 #else /* !HAVE_X_WINDOWS */
507 /* Stubs for MSDOS when not under X. */
510 intern_face (f
, face
)
534 CHECK_STRING (name
, 0);
535 result
= call1 (Qmsdos_color_translate
, name
);
536 if (INTEGERP (result
))
537 return XINT (result
);
539 Fsignal (Qerror
, Fcons (build_string ("undefined color"),
540 Fcons (name
, Qnil
)));
543 #endif /* !HAVE_X_WINDOWS */
546 /* Managing parameter face arrays for frames. */
552 ensure_face_ready (f
, 0);
553 ensure_face_ready (f
, 1);
555 FRAME_N_COMPUTED_FACES (f
) = 0;
556 FRAME_SIZE_COMPUTED_FACES (f
) = 0;
558 new_computed_face (f
, FRAME_PARAM_FACES (f
)[0]);
559 new_computed_face (f
, FRAME_PARAM_FACES (f
)[1]);
560 recompute_basic_faces (f
);
563 /* Find another X frame. */
565 Lisp_Object tail
, frame
, result
;
568 FOR_EACH_FRAME (tail
, frame
)
569 if (FRAME_X_P (XFRAME (frame
))
570 && XFRAME (frame
) != f
)
576 /* If we didn't find any X frames other than f, then we don't need
577 any faces other than 0 and 1, so we're okay. Otherwise, make
578 sure that all faces valid on the selected frame are also valid
579 on this new frame. */
583 int n_faces
= FRAME_N_PARAM_FACES (XFRAME (result
));
584 struct face
**faces
= FRAME_PARAM_FACES (XFRAME (result
));
586 for (i
= 2; i
< n_faces
; i
++)
588 ensure_face_ready (f
, i
);
591 #endif /* MULTI_FRAME */
595 /* Called from Fdelete_frame. */
601 Display
*dpy
= FRAME_X_DISPLAY (f
);
606 for (i
= 0; i
< FRAME_N_PARAM_FACES (f
); i
++)
608 struct face
*face
= FRAME_PARAM_FACES (f
) [i
];
611 unload_font (f
, face
->font
);
612 unload_color (f
, face
->foreground
);
613 unload_color (f
, face
->background
);
614 x_destroy_bitmap (f
, face
->stipple
);
618 xfree (FRAME_PARAM_FACES (f
));
619 FRAME_PARAM_FACES (f
) = 0;
620 FRAME_N_PARAM_FACES (f
) = 0;
622 /* All faces in FRAME_COMPUTED_FACES use resources copied from
623 FRAME_PARAM_FACES; we can free them without fuss.
624 But we do free the GCs and the face objects themselves. */
625 for (i
= 0; i
< FRAME_N_COMPUTED_FACES (f
); i
++)
627 struct face
*face
= FRAME_COMPUTED_FACES (f
) [i
];
631 XFreeGC (dpy
, face
->gc
);
635 xfree (FRAME_COMPUTED_FACES (f
));
636 FRAME_COMPUTED_FACES (f
) = 0;
637 FRAME_N_COMPUTED_FACES (f
) = 0;
642 /* Interning faces in a frame's face array. */
645 new_computed_face (f
, new_face
)
647 struct face
*new_face
;
649 int len
= FRAME_N_COMPUTED_FACES (f
);
652 /* Search for an unused computed face in the middle of the table. */
653 for (i
= 0; i
< len
; i
++)
655 struct face
*face
= FRAME_COMPUTED_FACES (f
)[i
];
658 FRAME_COMPUTED_FACES (f
)[i
] = copy_face (new_face
);
663 if (i
>= FRAME_SIZE_COMPUTED_FACES (f
))
665 int new_size
= i
+ 32;
667 FRAME_COMPUTED_FACES (f
)
668 = (struct face
**) (FRAME_SIZE_COMPUTED_FACES (f
) == 0
669 ? xmalloc (new_size
* sizeof (struct face
*))
670 : xrealloc (FRAME_COMPUTED_FACES (f
),
671 new_size
* sizeof (struct face
*)));
672 FRAME_SIZE_COMPUTED_FACES (f
) = new_size
;
675 i
= FRAME_N_COMPUTED_FACES (f
)++;
676 FRAME_COMPUTED_FACES (f
)[i
] = copy_face (new_face
);
681 /* Find a match for NEW_FACE in a FRAME's computed face array, and add
682 it if we don't find one. */
684 intern_computed_face (f
, new_face
)
686 struct face
*new_face
;
688 int len
= FRAME_N_COMPUTED_FACES (f
);
691 /* Search for a computed face already on F equivalent to FACE. */
692 for (i
= 0; i
< len
; i
++)
694 if (! FRAME_COMPUTED_FACES (f
)[i
])
696 if (face_eql (new_face
, FRAME_COMPUTED_FACES (f
)[i
]))
700 /* We didn't find one; add a new one. */
701 return new_computed_face (f
, new_face
);
704 /* Make parameter face id ID valid on frame F. */
707 ensure_face_ready (f
, id
)
711 if (FRAME_N_PARAM_FACES (f
) <= id
)
715 if (!FRAME_N_PARAM_FACES (f
))
716 FRAME_PARAM_FACES (f
)
717 = (struct face
**) xmalloc (sizeof (struct face
*) * n
);
719 FRAME_PARAM_FACES (f
)
720 = (struct face
**) xrealloc (FRAME_PARAM_FACES (f
),
721 sizeof (struct face
*) * n
);
723 bzero (FRAME_PARAM_FACES (f
) + FRAME_N_PARAM_FACES (f
),
724 (n
- FRAME_N_PARAM_FACES (f
)) * sizeof (struct face
*));
725 FRAME_N_PARAM_FACES (f
) = n
;
728 if (FRAME_PARAM_FACES (f
) [id
] == 0)
729 FRAME_PARAM_FACES (f
) [id
] = allocate_face ();
732 #ifdef HAVE_X_WINDOWS
733 /* Return non-zero if FONT1 and FONT2 have the same width.
734 We do not check the height, because we can now deal with
736 We assume that they're both character-cell fonts. */
739 same_size_fonts (font1
, font2
)
740 XFontStruct
*font1
, *font2
;
742 XCharStruct
*bounds1
= &font1
->min_bounds
;
743 XCharStruct
*bounds2
= &font2
->min_bounds
;
745 return (bounds1
->width
== bounds2
->width
);
748 /* Update the line_height of frame F according to the biggest font in
749 any face. Return nonzero if if line_height changes. */
752 frame_update_line_height (f
)
756 int biggest
= FONT_HEIGHT (f
->output_data
.x
->font
);
758 for (i
= 0; i
< f
->output_data
.x
->n_param_faces
; i
++)
759 if (f
->output_data
.x
->param_faces
[i
] != 0
760 && f
->output_data
.x
->param_faces
[i
]->font
!= (XFontStruct
*) FACE_DEFAULT
)
762 int height
= FONT_HEIGHT (f
->output_data
.x
->param_faces
[i
]->font
);
763 if (height
> biggest
)
767 if (biggest
== f
->output_data
.x
->line_height
)
770 f
->output_data
.x
->line_height
= biggest
;
773 #endif /* not HAVE_X_WINDOWS */
775 /* Modify face TO by copying from FROM all properties which have
776 nondefault settings. */
779 merge_faces (from
, to
)
780 struct face
*from
, *to
;
782 /* Only merge the font if it's the same width as the base font.
783 Otherwise ignore it, since we can't handle it properly. */
784 if (from
->font
!= (XFontStruct
*) FACE_DEFAULT
785 && same_size_fonts (from
->font
, to
->font
))
786 to
->font
= from
->font
;
787 if (from
->foreground
!= FACE_DEFAULT
)
788 to
->foreground
= from
->foreground
;
789 if (from
->background
!= FACE_DEFAULT
)
790 to
->background
= from
->background
;
791 if (from
->stipple
!= FACE_DEFAULT
)
793 to
->stipple
= from
->stipple
;
794 to
->pixmap_h
= from
->pixmap_h
;
795 to
->pixmap_w
= from
->pixmap_w
;
798 to
->underline
= from
->underline
;
801 /* Set up the basic set of facial parameters, based on the frame's
802 data; all faces are deltas applied to this. */
805 compute_base_face (f
, face
)
810 face
->foreground
= FRAME_FOREGROUND_PIXEL (f
);
811 face
->background
= FRAME_BACKGROUND_PIXEL (f
);
812 face
->font
= FRAME_FONT (f
);
817 /* Return the face ID to use to display a special glyph which selects
818 FACE_CODE as the face ID, assuming that ordinarily the face would
819 be CURRENT_FACE. F is the frame. */
822 compute_glyph_face (f
, face_code
, current_face
)
824 int face_code
, current_face
;
828 face
= *FRAME_COMPUTED_FACES (f
)[current_face
];
830 if (face_code
>= 0 && face_code
< FRAME_N_PARAM_FACES (f
)
831 && FRAME_PARAM_FACES (f
) [face_code
] != 0)
832 merge_faces (FRAME_PARAM_FACES (f
) [face_code
], &face
);
834 return intern_computed_face (f
, &face
);
837 /* Return the face ID to use to display a special glyph which selects
838 FACE_CODE as the face ID, assuming that ordinarily the face would
839 be CURRENT_FACE. F is the frame. */
842 compute_glyph_face_1 (f
, face_name
, current_face
)
844 Lisp_Object face_name
;
849 face
= *FRAME_COMPUTED_FACES (f
)[current_face
];
851 if (!NILP (face_name
))
853 int facecode
= face_name_id_number (f
, face_name
);
854 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
855 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
856 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
859 return intern_computed_face (f
, &face
);
862 /* Return the face ID associated with a buffer position POS.
863 Store into *ENDPTR the position at which a different face is needed.
864 This does not take account of glyphs that specify their own face codes.
865 F is the frame in use for display, and W is a window displaying
868 REGION_BEG, REGION_END delimit the region, so it can be highlighted.
870 LIMIT is a position not to scan beyond. That is to limit
871 the time this function can take.
873 If MOUSE is nonzero, use the character's mouse-face, not its face. */
876 compute_char_face (f
, w
, pos
, region_beg
, region_end
, endptr
, limit
, mouse
)
880 int region_beg
, region_end
;
886 Lisp_Object prop
, position
;
889 Lisp_Object
*overlay_vec
;
892 Lisp_Object propname
;
894 /* W must display the current buffer. We could write this function
895 to use the frame and buffer of W, but right now it doesn't. */
896 if (XBUFFER (w
->buffer
) != current_buffer
)
899 XSETFRAME (frame
, f
);
902 if (pos
< region_beg
&& region_beg
< endpos
)
905 XSETFASTINT (position
, pos
);
908 propname
= Qmouse_face
;
912 prop
= Fget_text_property (position
, propname
, w
->buffer
);
915 Lisp_Object limit1
, end
;
917 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
918 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
927 /* First try with room for 40 overlays. */
929 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
931 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
932 &next_overlay
, (int *) 0);
934 /* If there are more than 40,
935 make enough space for all, and try again. */
939 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
940 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
941 &next_overlay
, (int *) 0);
944 if (next_overlay
< endpos
)
945 endpos
= next_overlay
;
950 /* Optimize the default case. */
951 if (noverlays
== 0 && NILP (prop
)
952 && !(pos
>= region_beg
&& pos
< region_end
))
955 compute_base_face (f
, &face
);
959 /* We have a list of faces, merge them in reverse order */
964 length
= Fsafe_length (prop
);
965 len
= XFASTINT (length
);
967 /* Put them into an array */
968 faces
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
969 for (j
= 0; j
< len
; j
++)
971 faces
[j
] = Fcar (prop
);
974 /* So that we can merge them in the reverse order */
975 for (j
= len
- 1; j
>= 0; j
--)
977 facecode
= face_name_id_number (f
, faces
[j
]);
978 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
979 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
980 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
983 else if (!NILP (prop
))
985 facecode
= face_name_id_number (f
, prop
);
986 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
987 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
988 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
991 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
993 /* Now merge the overlay data in that order. */
994 for (i
= 0; i
< noverlays
; i
++)
996 prop
= Foverlay_get (overlay_vec
[i
], propname
);
999 /* We have a list of faces, merge them in reverse order */
1004 length
= Fsafe_length (prop
);
1005 len
= XFASTINT (length
);
1007 /* Put them into an array */
1008 faces
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
1009 for (j
= 0; j
< len
; j
++)
1011 faces
[j
] = Fcar (prop
);
1014 /* So that we can merge them in the reverse order */
1015 for (j
= len
- 1; j
>= 0; j
--)
1017 facecode
= face_name_id_number (f
, faces
[j
]);
1018 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
1019 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
1020 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
1023 else if (!NILP (prop
))
1028 facecode
= face_name_id_number (f
, prop
);
1029 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
1030 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
1031 merge_faces (FRAME_PARAM_FACES (f
)[facecode
], &face
);
1033 oend
= OVERLAY_END (overlay_vec
[i
]);
1034 oendpos
= OVERLAY_POSITION (oend
);
1035 if (oendpos
< endpos
)
1040 if (pos
>= region_beg
&& pos
< region_end
)
1042 if (region_end
< endpos
)
1043 endpos
= region_end
;
1044 if (region_face
>= 0 && region_face
< next_face_id
)
1045 merge_faces (FRAME_PARAM_FACES (f
)[region_face
], &face
);
1050 return intern_computed_face (f
, &face
);
1053 /* Recompute the GC's for the default and modeline faces.
1054 We call this after changing frame parameters on which those GC's
1058 recompute_basic_faces (f
)
1061 /* If the frame's faces haven't been initialized yet, don't worry about
1063 if (FRAME_N_PARAM_FACES (f
) < 2)
1068 if (FRAME_DEFAULT_FACE (f
)->gc
)
1069 XFreeGC (FRAME_X_DISPLAY (f
), FRAME_DEFAULT_FACE (f
)->gc
);
1070 if (FRAME_MODE_LINE_FACE (f
)->gc
)
1071 XFreeGC (FRAME_X_DISPLAY (f
), FRAME_MODE_LINE_FACE (f
)->gc
);
1073 compute_base_face (f
, FRAME_DEFAULT_FACE (f
));
1074 compute_base_face (f
, FRAME_MODE_LINE_FACE (f
));
1076 merge_faces (FRAME_DEFAULT_PARAM_FACE (f
), FRAME_DEFAULT_FACE (f
));
1077 merge_faces (FRAME_MODE_LINE_PARAM_FACE (f
), FRAME_MODE_LINE_FACE (f
));
1079 intern_face (f
, FRAME_DEFAULT_FACE (f
));
1080 intern_face (f
, FRAME_MODE_LINE_FACE (f
));
1087 /* Lisp interface. */
1089 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
, 1, 1, 0,
1094 CHECK_FRAME (frame
, 0);
1095 return XFRAME (frame
)->face_alist
;
1098 DEFUN ("set-frame-face-alist", Fset_frame_face_alist
, Sset_frame_face_alist
,
1101 Lisp_Object frame
, value
;
1103 CHECK_FRAME (frame
, 0);
1104 XFRAME (frame
)->face_alist
= value
;
1109 DEFUN ("make-face-internal", Fmake_face_internal
, Smake_face_internal
, 1, 1, 0,
1110 "Create face number FACE-ID on all frames.")
1112 Lisp_Object face_id
;
1114 Lisp_Object rest
, frame
;
1115 int id
= XINT (face_id
);
1117 CHECK_NUMBER (face_id
, 0);
1118 if (id
< 0 || id
>= next_face_id
)
1119 error ("Face id out of range");
1121 FOR_EACH_FRAME (rest
, frame
)
1123 if (FRAME_X_P (XFRAME (frame
)))
1124 ensure_face_ready (XFRAME (frame
), id
);
1130 DEFUN ("set-face-attribute-internal", Fset_face_attribute_internal
,
1131 Sset_face_attribute_internal
, 4, 4, 0, "")
1132 (face_id
, attr_name
, attr_value
, frame
)
1133 Lisp_Object face_id
, attr_name
, attr_value
, frame
;
1141 CHECK_FRAME (frame
, 0);
1142 CHECK_NUMBER (face_id
, 0);
1143 CHECK_SYMBOL (attr_name
, 0);
1146 id
= XINT (face_id
);
1147 if (id
< 0 || id
>= next_face_id
)
1148 error ("Face id out of range");
1150 if (! FRAME_X_P (f
))
1153 ensure_face_ready (f
, id
);
1154 face
= FRAME_PARAM_FACES (f
) [XFASTINT (face_id
)];
1156 if (EQ (attr_name
, intern ("font")))
1158 #if defined (MSDOS) && !defined (HAVE_X_WINDOWS)
1159 /* The one and only font. Must *not* be zero (which
1160 is taken to mean an unused face nowadays). */
1161 face
->font
= (XFontStruct
*)1 ;
1163 XFontStruct
*font
= load_font (f
, attr_value
);
1164 if (face
->font
!= f
->output_data
.x
->font
)
1165 unload_font (f
, face
->font
);
1167 if (frame_update_line_height (f
))
1168 x_set_window_size (f
, 0, f
->width
, f
->height
);
1169 /* Must clear cache, since it might contain the font
1170 we just got rid of. */
1174 else if (EQ (attr_name
, intern ("foreground")))
1176 unsigned long new_color
= load_color (f
, attr_value
);
1177 unload_color (f
, face
->foreground
);
1178 face
->foreground
= new_color
;
1181 else if (EQ (attr_name
, intern ("background")))
1183 unsigned long new_color
= load_color (f
, attr_value
);
1184 unload_color (f
, face
->background
);
1185 #if defined (MSDOS) && !defined (HAVE_X_WINDOWS)
1186 new_color
&= ~8; /* Bright would give blinking characters. */
1188 face
->background
= new_color
;
1191 else if (EQ (attr_name
, intern ("background-pixmap")))
1194 unsigned long new_pixmap
= load_pixmap (f
, attr_value
, &w
, &h
);
1195 x_destroy_bitmap (f
, face
->stipple
);
1196 face
->stipple
= new_pixmap
;
1201 else if (EQ (attr_name
, intern ("underline")))
1203 int new = !NILP (attr_value
);
1204 face
->underline
= new;
1207 error ("unknown face attribute");
1209 if (id
== 0 || id
== 1)
1210 recompute_basic_faces (f
);
1212 /* We must redraw the frame whenever any face font or color changes,
1213 because it's possible that a merged (display) face
1214 contains the font or color we just replaced.
1215 And we must inhibit any Expose events until the redraw is done,
1216 since they would try to use the invalid display faces. */
1218 SET_FRAME_GARBAGED (f
);
1223 DEFUN ("internal-next-face-id", Finternal_next_face_id
, Sinternal_next_face_id
,
1227 return make_number (next_face_id
++);
1230 /* Return the face id for name NAME on frame FRAME.
1231 (It should be the same for all frames,
1232 but it's as easy to use the "right" frame to look it up
1233 as to use any other one.) */
1236 face_name_id_number (f
, name
)
1242 tem
= Fcdr (assq_no_quit (name
, f
->face_alist
));
1245 CHECK_VECTOR (tem
, 0);
1246 tem
= XVECTOR (tem
)->contents
[2];
1247 CHECK_NUMBER (tem
, 0);
1251 /* Emacs initialization. */
1256 Qface
= intern ("face");
1258 Qmouse_face
= intern ("mouse-face");
1259 staticpro (&Qmouse_face
);
1260 Qpixmap_spec_p
= intern ("pixmap-spec-p");
1261 staticpro (&Qpixmap_spec_p
);
1263 DEFVAR_INT ("region-face", ®ion_face
,
1264 "Face number to use to highlight the region\n\
1265 The region is highlighted with this face\n\
1266 when Transient Mark mode is enabled and the mark is active.");
1268 #ifdef HAVE_X_WINDOWS
1269 defsubr (&Spixmap_spec_p
);
1271 defsubr (&Sframe_face_alist
);
1272 defsubr (&Sset_frame_face_alist
);
1273 defsubr (&Smake_face_internal
);
1274 defsubr (&Sset_face_attribute_internal
);
1275 defsubr (&Sinternal_next_face_id
);
1278 #endif /* HAVE_FACES */