1 /* Face data structures.
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
3 Copyright (C) 1995 Ben Wing
5 This file is part of SXEmacs
7 SXEmacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 SXEmacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* Synched up with: Not in FSF. */
23 #ifndef INCLUDED_faces_h_
24 #define INCLUDED_faces_h_
26 #include "buffer.h" /* for NUM_LEADING_BYTES */
28 /* a Lisp_Face is the C object corresponding to a face. There is one
29 of these per face. It basically contains all of the specifiers for
30 the built-in face properties, plus the plist of user-specified
34 struct lcrecord_header header;
37 Lisp_Object doc_string;
38 unsigned int dirty:1; /* Set whenever a face property is changed on
41 Lisp_Object foreground;
42 Lisp_Object background;
45 Lisp_Object display_table;
46 Lisp_Object background_pixmap;
48 Lisp_Object underline;
49 Lisp_Object strikethru;
50 Lisp_Object highlight;
57 Lisp_Object charsets_warned_about;
62 A face cache element caches the results of instantiating the
63 properties of a face in a particular window. (Instantiation can
64 take a long time so this is very important.) Each window contains
65 an array of face cache elements (called the "face cache"), one for
66 each face that has been seen in the window so far.
68 Some tricky stuff is done to make sure the face cache does not
71 1) Switching buffers in a window clears the face cache for that
72 window, because this can change the way any property is
73 instantiated in the window.
74 2) Setting a face property causes that face to be marked as
75 dirty. This causes various stuff to happen to make sure
76 the appropriate face cache elements are invalidated.
77 (#### Actually this doesn't work quite right, and errs
78 too much on the side of invalidating unnecessary stuff.)
80 There are also face cache elements for "merged faces", which are the
81 result of merging all the faces that overlap a particular buffer
82 position. The merging is always done in the context of a particular
83 domain (specifically, a window), and the face cache element is
84 specific to a particular window. (Face cache elements are contained
85 in an array that is attached to each struct_window.) The reason that
86 the merging takes place in the context of a particular window has
87 to do with the way the merging works:
89 1) All extents overlying the buffer position are sorted by descending
91 2) The property of a particular merged face comes from the highest-
92 priority face that specifies a value for that particular property.
93 3) The way to determine whether a face specifies a value for a
94 particular property is to instantiate that face's property in
95 the window in question with the no-fallback option set, to
96 see if we got anything.
98 For Mule, things get a bit trickier because there can be multiple
99 fonts per face/window combination -- the charset is an argument
100 to specifier-instance.
102 We have two possible data structure representations:
104 1) Keep the original "one font per face cache element" representation
105 and use a different face cache element for each charset.
106 2) Allow multiple fonts to be in a single face cache element.
108 I've chosen to use (2) -- the data structure gets more complicated
109 but the algorithms for maintaining face cache elements end up
113 #define NUM_STATIC_CACHEL_FACES 4
115 typedef struct face_cachel face_cachel;
117 /* There are two kinds of cachels; those created from a single face
118 and those created by merging more than one face. In the former
119 case, the FACE element specifies the face used. In the latter
120 case, the MERGED_FACES_STATIC and MERGED_FACES elements specify
121 the faces used for merging by giving the indices of the
122 corresponding single-face cachels.
124 Formerly we didn't bother to keep track of the faces used for
125 merging. We do now because we need to do so because there is no
126 other way to properly handle multiple charsets for Mule in the
127 presence of display tables short of always computing the values
128 for all charsets, which is very expensive. Instead, we use a
129 lazy scheme where we only compute the font for a particular charset
130 when it is needed. (The exception is the font for the ASCII charset.
131 We always compute it, just like the other attributes, because
132 many places in the C code refer to the font of the ASCII charset
133 and expect it to always be there.)
135 We store the first four faces in a static array, and use a
136 Dynarr for the rest. This has the advantage that the space used
137 is small but the Dynarr will almost never be created, so we
138 won't spend much time in malloc()/free().
140 The order of the faces here is decreasing extent priority. */
142 int merged_faces_static[NUM_STATIC_CACHEL_FACES];
143 int_dynarr *merged_faces;
146 /* The values stored here are computed by calling specifier_instance()
147 on the appropriate specifiers. This means that we will have either
148 a value computed from the face itself or a value computed from the
149 default face. We need to distinguish the two so that merging works
150 properly -- a value that comes from the default face is treated
151 as "unspecified" during merging and is overridden by lower-priority
152 faces. This is what the _specified flags below are for. */
154 Lisp_Object foreground;
155 Lisp_Object background;
156 /* There are currently 128 possible charsets under Mule. For the
157 moment we just take the easy way out and allocate space for each
158 of them. This avoids messing with Dynarrs.
160 #### We should look into this and probably clean it up
161 to use Dynarrs. This may be a big space hog as is. */
162 Lisp_Object font[NUM_LEADING_BYTES];
164 Lisp_Object display_table;
165 Lisp_Object background_pixmap;
167 unsigned int underline:1;
168 unsigned int strikethru:1;
169 unsigned int highlight:1;
171 unsigned int blinking:1;
172 unsigned int reverse:1;
174 /* Used when merging to tell if the above field represents an actual
175 value of this face or a fallback value. */
176 /* #### Of course we should use a bit array or something. */
177 unsigned char font_specified[NUM_LEADING_BYTES];
178 unsigned int foreground_specified:1;
179 unsigned int background_specified:1;
180 unsigned int display_table_specified:1;
181 unsigned int background_pixmap_specified:1;
183 unsigned int strikethru_specified:1;
184 unsigned int underline_specified:1;
185 unsigned int highlight_specified:1;
186 unsigned int dim_specified:1;
187 unsigned int blinking_specified:1;
188 unsigned int reverse_specified:1;
190 /* The updated flag is set after we calculate the values for the
191 face cachel and cleared whenever a face changes, to indicate
192 that the values stored here might be wrong. The next time
193 we go to access the values, we recompute them; if any values
194 change, we set the DIRTY flag, which tells the output routines
195 that a face value has in fact changed and the sections of text
196 using this face need to be redrawn.
198 It is trickier with fonts because we don't automatically
199 recompute the fonts but do it only when it is necessary.
200 (The ASCII font is an exception, of course; see above).
202 In the case of fonts, we maintain a separate updated flag
203 for each font. Whenever we need to access the font for
204 a particular charset, we recalculate it if either its
205 value is Qunbound (meaning it's never been computed at all)
206 or the updated flag is not set. We set the dirty flag if
207 the value is not the same as before and the previous value
210 #### Note that we don't yet deal with the case of the new
211 value being Qunbound, as could happen if no fonts of the
212 right sort are available on the system. In this case, the
213 whole program will just crash. For the moment, this is
214 OK (for debugging purposes) but we should fix this by
215 storing a "blank font" if the instantiation fails. */
216 unsigned int dirty:1;
217 unsigned int updated:1;
218 /* #### Of course we should use a bit array or something. */
219 unsigned char font_updated[NUM_LEADING_BYTES];
222 DECLARE_LRECORD(face, Lisp_Face);
223 #define XFACE(x) XRECORD (x, face, Lisp_Face)
224 #define XSETFACE(x, p) XSETRECORD (x, p, face)
225 #define FACEP(x) RECORDP (x, face)
226 #define CHECK_FACE(x) CHECK_RECORD (x, face)
228 Lisp_Object ensure_face_cachel_contains_charset(struct face_cachel *cachel,
230 Lisp_Object charset);
231 void ensure_face_cachel_complete(struct face_cachel *cachel,
232 Lisp_Object domain, unsigned char *charsets);
233 void update_face_cachel_data(struct face_cachel *cachel,
234 Lisp_Object domain, Lisp_Object face);
235 void face_cachel_charset_font_metric_info(struct face_cachel *cachel,
236 unsigned char *charsets,
237 struct font_metric_info *fm);
238 void mark_face_cachels(face_cachel_dynarr * elements);
239 void mark_face_cachels_as_clean(struct window *w);
240 void mark_face_cachels_as_not_updated(struct window *w);
241 void reset_face_cachel(struct face_cachel *inst);
242 void reset_face_cachels(struct window *w);
243 face_index get_builtin_face_cache_index(struct window *w, Lisp_Object face);
244 #ifdef MEMORY_USAGE_STATS
245 int compute_face_cachel_usage(face_cachel_dynarr * face_cachels,
246 struct overhead_stats *ovstats);
247 #endif /* MEMORY_USAGE_STATS */
249 EXFUN(Fface_name, 1);
250 EXFUN(Ffind_face, 1);
253 extern Lisp_Object Qstrikethru, Vbuilt_in_face_specifiers, Vdefault_face;
254 extern Lisp_Object Vleft_margin_face, Vpointer_face, Vright_margin_face;
255 extern Lisp_Object Vtext_cursor_face, Vvertical_divider_face;
256 extern Lisp_Object Vtoolbar_face, Vgui_element_face, Vwidget_face;
258 void mark_all_faces_as_clean(void);
259 void init_frame_faces(struct frame *f);
260 void init_device_faces(struct device *d);
261 void init_global_faces(struct device *d);
262 face_index get_extent_fragment_face_cache_index(struct window *w,
263 struct extent_fragment *ef);
264 void update_frame_face_values(struct frame *f);
265 void face_property_was_changed(Lisp_Object face, Lisp_Object property,
267 void default_face_font_info(Lisp_Object domain, int *ascent,
268 int *descent, int *height, int *width,
269 int *proportional_p);
270 void default_face_height_and_width(Lisp_Object domain, int *height, int *width);
271 void default_face_height_and_width_1(Lisp_Object domain,
272 int *height, int *width);
274 #define FACE_CACHEL_FONT(cachel, charset) \
275 (cachel->font[XCHARSET_LEADING_BYTE (charset) - 128])
277 #define WINDOW_FACE_CACHEL(window, index) \
278 Dynarr_atp ((window)->face_cachels, index)
280 #define FACE_CACHEL_FINDEX_UNSAFE(cachel, offset) \
281 ((offset) < NUM_STATIC_CACHEL_FACES \
282 ? (cachel)->merged_faces_static[offset] \
283 : Dynarr_at ((cachel)->merged_faces, (offset) - NUM_STATIC_CACHEL_FACES))
285 #define WINDOW_FACE_CACHEL_FACE(window, index) \
286 (WINDOW_FACE_CACHEL (window, index)->face)
287 #define WINDOW_FACE_CACHEL_FOREGROUND(window, index) \
288 (WINDOW_FACE_CACHEL (window, index)->foreground)
289 #define WINDOW_FACE_CACHEL_BACKGROUND(window, index) \
290 (WINDOW_FACE_CACHEL (window, index)->background)
291 /* #### This can be referenced by various functions,
292 but face_cachels isn't initialized for the stream device.
293 Since it doesn't need the value we just return nil here to avoid
294 blowing up in multiple places. */
295 #define WINDOW_FACE_CACHEL_FONT(window, index, charset) \
296 ((window)->face_cachels \
297 ? FACE_CACHEL_FONT (WINDOW_FACE_CACHEL (window, index), charset) \
299 #define WINDOW_FACE_CACHEL_DISPLAY_TABLE(window, index) \
300 (WINDOW_FACE_CACHEL (window, index)->display_table)
301 #define WINDOW_FACE_CACHEL_BACKGROUND_PIXMAP(window, index) \
302 (WINDOW_FACE_CACHEL (window, index)->background_pixmap)
303 #define WINDOW_FACE_CACHEL_DIRTY(window, index) \
304 (WINDOW_FACE_CACHEL (window, index)->dirty)
305 #define WINDOW_FACE_CACHEL_UNDERLINE_P(window, index) \
306 (WINDOW_FACE_CACHEL (window, index)->underline)
307 #define WINDOW_FACE_CACHEL_HIGHLIGHT_P(window, index) \
308 (WINDOW_FACE_CACHEL (window, index)->highlight)
309 #define WINDOW_FACE_CACHEL_DIM_P(window, index) \
310 (WINDOW_FACE_CACHEL (window, index)->dim)
311 #define WINDOW_FACE_CACHEL_BLINKING_P(window, index) \
312 (WINDOW_FACE_CACHEL (window, index)->blinking)
313 #define WINDOW_FACE_CACHEL_REVERSE_P(window, index) \
314 (WINDOW_FACE_CACHEL (window, index)->reverse)
316 #define FACE_PROPERTY_SPECIFIER(face, property) Fget (face, property, Qnil)
318 #define FACE_PROPERTY_INSTANCE_1(face, property, domain, errb, no_fallback, depth) \
319 specifier_instance (FACE_PROPERTY_SPECIFIER (face, property), Qunbound, \
320 domain, errb, 1, no_fallback, depth)
322 #define FACE_PROPERTY_INSTANCE(face, property, domain, no_fallback, depth) \
323 FACE_PROPERTY_INSTANCE_1 (face, property, domain, ERROR_ME_NOT, \
326 Lisp_Object face_property_matching_instance(Lisp_Object face,
327 Lisp_Object property,
331 int no_fallback, Lisp_Object depth);
333 #define FACE_PROPERTY_SPEC_LIST(face, property, locale) \
334 Fspecifier_spec_list (FACE_PROPERTY_SPECIFIER (face, property), \
336 #define SET_FACE_PROPERTY(face, property, value, locale, tag, how_to_add) \
337 Fadd_spec_to_specifier (FACE_PROPERTY_SPECIFIER (face, property), \
338 value, locale, tag, how_to_add)
340 #define FACE_FOREGROUND(face, domain) \
341 FACE_PROPERTY_INSTANCE (face, Qforeground, domain, 0, Qzero)
342 #define FACE_BACKGROUND(face, domain) \
343 FACE_PROPERTY_INSTANCE (face, Qbackground, domain, 0, Qzero)
344 #define FACE_FONT(face, domain, charset) \
345 face_property_matching_instance (face, Qfont, charset, domain, \
346 ERROR_ME_NOT, 0, Qzero)
347 #define FACE_DISPLAY_TABLE(face, domain) \
348 FACE_PROPERTY_INSTANCE (face, Qdisplay_table, domain, 0, Qzero)
349 #define FACE_BACKGROUND_PIXMAP(face, domain) \
350 FACE_PROPERTY_INSTANCE (face, Qbackground_pixmap, domain, 0, Qzero)
351 #define FACE_UNDERLINE_P(face, domain) \
352 (!NILP (FACE_PROPERTY_INSTANCE (face, Qunderline, domain, 0, Qzero)))
353 #define FACE_STRIKETHRU_P(face, domain) \
354 (!NILP (FACE_PROPERTY_INSTANCE (face, Qstrikethru, domain, 0, Qzero)))
355 #define FACE_HIGHLIGHT_P(face, domain) \
356 (!NILP (FACE_PROPERTY_INSTANCE (face, Qhighlight, domain, 0, Qzero)))
357 #define FACE_DIM_P(face, domain) \
358 (!NILP (FACE_PROPERTY_INSTANCE (face, Qdim, domain, 0, Qzero)))
359 #define FACE_BLINKING_P(face, domain) \
360 (!NILP (FACE_PROPERTY_INSTANCE (face, Qblinking, domain, 0, Qzero)))
361 #define FACE_REVERSE_P(face, domain) \
362 (!NILP (FACE_PROPERTY_INSTANCE (face, Qreverse, domain, 0, Qzero)))
364 #endif /* INCLUDED_faces_h_ */