1 /* Interface definitions for display code.
2 
3 Copyright (C) 1985, 1993-1994, 1997-2021 Free Software Foundation, Inc.
4 
5 This file is part of GNU Emacs.
6 
7 GNU Emacs 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 (at
10 your option) any later version.
11 
12 GNU Emacs 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.
16 
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
19 
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.  */
21 
22 #ifndef DISPEXTERN_H_INCLUDED
23 #define DISPEXTERN_H_INCLUDED
24 
25 #include "character.h"
26 
27 #ifdef HAVE_X_WINDOWS
28 
29 #include <X11/Xlib.h>
30 #ifdef USE_X_TOOLKIT
31 #include <X11/Intrinsic.h>
32 #endif /* USE_X_TOOLKIT */
33 
34 #ifdef HAVE_XRENDER
35 # include <X11/extensions/Xrender.h>
36 #endif
37 
38 typedef XColor Emacs_Color;
39 typedef Cursor Emacs_Cursor;
40 #define No_Cursor (None)
41 #ifndef USE_CAIRO
42 typedef Pixmap Emacs_Pixmap;
43 #endif
44 typedef XRectangle Emacs_Rectangle;
45 typedef XGCValues Emacs_GC;
46 #else /* !HAVE_X_WINDOWS */
47 
48 /* XColor-like struct used by non-X code.  */
49 
50 typedef struct
51 {
52   unsigned long pixel;
53   unsigned short red, green, blue;
54 } Emacs_Color;
55 
56 /* Accommodate X's usage of None as a null resource ID.  */
57 #define No_Cursor (NULL)
58 
59 /* XRectangle-like struct used by non-X GUI code.  */
60 typedef struct
61 {
62   int x, y;
63   unsigned width, height;
64 } Emacs_Rectangle;
65 
66 /* XGCValues-like struct used by non-X GUI code.  */
67 typedef struct
68 {
69   unsigned long foreground;
70   unsigned long background;
71 } Emacs_GC;
72 
73 /* Mask values to select foreground/background.  */
74 /* FIXME: The GC handling in w32 really should be redesigned as to not
75    need these.  */
76 #define GCForeground 0x01
77 #define GCBackground 0x02
78 
79 #endif /* HAVE_X_WINDOWS */
80 
81 #ifdef MSDOS
82 #include "msdos.h"
83 #endif
84 
85 INLINE_HEADER_BEGIN
86 
87 #include <c-strcase.h>
88 INLINE int
xstrcasecmp(char const * a,char const * b)89 xstrcasecmp (char const *a, char const *b)
90 {
91   return c_strcasecmp (a, b);
92 }
93 
94 #ifdef HAVE_X_WINDOWS
95 #include <X11/Xresource.h> /* for XrmDatabase */
96 typedef struct x_display_info Display_Info;
97 #ifndef USE_CAIRO
98 typedef XImage *Emacs_Pix_Container;
99 typedef XImage *Emacs_Pix_Context;
100 #endif	/* !USE_CAIRO */
101 #define NativeRectangle XRectangle
102 #endif
103 
104 #ifdef USE_CAIRO
105 /* Minimal version of XImage.  */
106 typedef struct
107 {
108   int width, height;		/* size of image */
109   char *data;			/* pointer to image data */
110   int bytes_per_line;		/* accelarator to next line */
111   int bits_per_pixel;		/* bits per pixel (ZPixmap) */
112 } *Emacs_Pix_Container;
113 typedef Emacs_Pix_Container Emacs_Pixmap;
114 typedef Emacs_Pix_Container Emacs_Pix_Context;
115 #endif
116 
117 #ifdef HAVE_NTGUI
118 #include "w32gui.h"
119 typedef struct w32_display_info Display_Info;
120 typedef XImage *Emacs_Pix_Container;
121 typedef HDC Emacs_Pix_Context;
122 #endif
123 
124 #ifdef HAVE_NS
125 #include "nsgui.h"
126 /* Following typedef needed to accommodate the MSDOS port, believe it or not.  */
127 typedef struct ns_display_info Display_Info;
128 typedef Emacs_Pixmap Emacs_Pix_Container;
129 typedef Emacs_Pixmap Emacs_Pix_Context;
130 #endif
131 
132 #ifdef HAVE_PGTK
133 #include "pgtkgui.h"
134 /* Following typedef needed to accommodate the MSDOS port, believe it or not.  */
135 typedef struct pgtk_display_info Display_Info;
136 typedef Emacs_Pixmap XImagePtr;
137 typedef XImagePtr XImagePtr_or_DC;
138 #endif /* HAVE_PGTK */
139 
140 #ifdef HAVE_HAIKU
141 #include "haikugui.h"
142 typedef struct haiku_display_info Display_Info;
143 typedef Emacs_Pixmap Emacs_Pix_Container;
144 typedef Emacs_Pixmap Emacs_Pix_Context;
145 #endif
146 
147 #ifdef HAVE_WINDOW_SYSTEM
148 # include <time.h>
149 # include "fontset.h"
150 #endif
151 
152 #ifndef HAVE_WINDOW_SYSTEM
153 typedef void *Emacs_Cursor;
154 #endif
155 
156 #ifndef NativeRectangle
157 #define NativeRectangle int
158 #endif
159 
160 /* Text cursor types.  */
161 
162 enum text_cursor_kinds
163 {
164   DEFAULT_CURSOR = -2,
165   NO_CURSOR = -1,
166   FILLED_BOX_CURSOR,
167   HOLLOW_BOX_CURSOR,
168   BAR_CURSOR,
169   HBAR_CURSOR
170 };
171 
172 /* Values returned from coordinates_in_window.  */
173 
174 enum window_part
175 {
176   ON_NOTHING,
177   ON_TEXT,
178   ON_MODE_LINE,
179   ON_VERTICAL_BORDER,
180   ON_HEADER_LINE,
181   ON_TAB_LINE,
182   ON_LEFT_FRINGE,
183   ON_RIGHT_FRINGE,
184   ON_LEFT_MARGIN,
185   ON_RIGHT_MARGIN,
186   ON_VERTICAL_SCROLL_BAR,
187   ON_HORIZONTAL_SCROLL_BAR,
188   ON_RIGHT_DIVIDER,
189   ON_BOTTOM_DIVIDER
190 };
191 
192 /* Number of bits allocated to store fringe bitmap numbers.  */
193 #define FRINGE_ID_BITS  16
194 
195 /* Number of bits allocated to store fringe bitmap height.  */
196 #define FRINGE_HEIGHT_BITS 8
197 
198 
199 /***********************************************************************
200 			      Debugging
201  ***********************************************************************/
202 
203 /* If GLYPH_DEBUG is defined, additional checks are activated.  */
204 
205 /* Macros to include code only if GLYPH_DEBUG is defined.  */
206 
207 #ifdef GLYPH_DEBUG
208 #define IF_DEBUG(X)	((void) (X))
209 #else
210 #define IF_DEBUG(X)	((void) 0)
211 #endif
212 
213 /***********************************************************************
214 			    Text positions
215  ***********************************************************************/
216 
217 /* Starting with Emacs 20.3, characters from strings and buffers have
218    both a character and a byte position associated with them.  The
219    following structure holds such a pair of positions.  */
220 
221 struct text_pos
222 {
223   /* Character position.  */
224   ptrdiff_t charpos;
225 
226   /* Corresponding byte position.  */
227   ptrdiff_t bytepos;
228 };
229 
230 /* Access character and byte position of POS in a functional form.  */
231 
232 #define BYTEPOS(POS)	(POS).bytepos
233 #define CHARPOS(POS)	(POS).charpos
234 
235 /* Set character position of POS to CHARPOS, byte position to BYTEPOS.  */
236 
237 #define SET_TEXT_POS(POS, CHARPOS, BYTEPOS) \
238      ((POS).charpos = (CHARPOS), (POS).bytepos = BYTEPOS)
239 
240 /* Increment text position POS.  */
241 
242 #define INC_TEXT_POS(POS, MULTIBYTE_P)		\
243      do						\
244        {					\
245 	 ++(POS).charpos;			\
246          if (MULTIBYTE_P)			\
247 	   (POS).bytepos += next_char_len ((POS).bytepos); \
248 	 else					\
249 	   ++(POS).bytepos;			\
250        }					\
251      while (false)
252 
253 /* Decrement text position POS.  */
254 
255 #define DEC_TEXT_POS(POS, MULTIBYTE_P)		\
256      do						\
257        {					\
258 	 --(POS).charpos;			\
259          if (MULTIBYTE_P)			\
260 	   (POS).bytepos -= prev_char_len ((POS).bytepos); \
261 	 else					\
262 	   --(POS).bytepos;			\
263        }					\
264      while (false)
265 
266 /* Set text position POS from marker MARKER.  */
267 
268 #define SET_TEXT_POS_FROM_MARKER(POS, MARKER)		\
269   (CHARPOS (POS) = marker_position (MARKER),		\
270    BYTEPOS (POS) = marker_byte_position (MARKER))
271 
272 /* Like above, but clip POS within accessible range.  */
273 
274 #define CLIP_TEXT_POS_FROM_MARKER(POS, MARKER)		\
275   (CHARPOS (POS) = clip_to_bounds			\
276    (BEGV, marker_position (MARKER), ZV),		\
277    BYTEPOS (POS) = clip_to_bounds			\
278    (BEGV_BYTE, marker_byte_position (MARKER), ZV_BYTE))
279 
280 /* Set marker MARKER from text position POS.  */
281 
282 #define SET_MARKER_FROM_TEXT_POS(MARKER, POS) \
283      set_marker_both ((MARKER), Qnil, CHARPOS ((POS)), BYTEPOS ((POS)))
284 
285 /* Value is non-zero if character and byte positions of POS1 and POS2
286    are equal.  */
287 
288 #define TEXT_POS_EQUAL_P(POS1, POS2)		\
289      ((POS1).charpos == (POS2).charpos		\
290       && (POS1).bytepos == (POS2).bytepos)
291 
292 /* When rendering glyphs, redisplay scans string or buffer text,
293    overlay strings in that text, and does display table or control
294    character translations.  The following structure captures a
295    position taking all this into account.  */
296 
297 struct display_pos
298 {
299   /* Buffer or string position.  */
300   struct text_pos pos;
301 
302   /* If this is a position in an overlay string, overlay_string_index
303      is the index of that overlay string in the sequence of overlay
304      strings at `pos' in the order redisplay processes them.  A value
305      < 0 means that this is not a position in an overlay string.  */
306   ptrdiff_t overlay_string_index;
307 
308   /* If this is a position in an overlay string, string_pos is the
309      position within that string.  */
310   struct text_pos string_pos;
311 
312   /* If the character at the position above is a control character or
313      has a display table entry, dpvec_index is an index in the display
314      table or control character translation of that character.  A
315      value < 0 means this is not a position in such a translation.  */
316   int dpvec_index;
317 };
318 
319 
320 
321 /***********************************************************************
322 				Glyphs
323  ***********************************************************************/
324 
325 /* The glyph datatype, used to represent characters on the display.
326    It consists of a char code and a face id.  */
327 
328 typedef struct {
329   int ch;
330   int face_id;
331 } GLYPH;
332 
333 /* Return a glyph's character code.  */
GLYPH_CHAR(GLYPH glyph)334 INLINE int GLYPH_CHAR (GLYPH glyph) { return glyph.ch; }
335 
336 /* Return a glyph's face ID.  */
GLYPH_FACE(GLYPH glyph)337 INLINE int GLYPH_FACE (GLYPH glyph) { return glyph.face_id; }
338 
339 #define SET_GLYPH_CHAR(glyph, char) ((glyph).ch = (char))
340 #define SET_GLYPH_FACE(glyph, face) ((glyph).face_id = (face))
341 #define SET_GLYPH(glyph, char, face) \
342   ((glyph).ch = (char), (glyph).face_id = (face))
343 
344 /* The following are valid only if GLYPH_CODE_P (gc).  */
345 
346 INLINE int
GLYPH_CODE_CHAR(Lisp_Object gc)347 GLYPH_CODE_CHAR (Lisp_Object gc)
348 {
349   return (CONSP (gc)
350 	  ? XFIXNUM (XCAR (gc))
351 	  : XFIXNUM (gc) & MAX_CHAR);
352 }
353 
354 INLINE int
GLYPH_CODE_FACE(Lisp_Object gc)355 GLYPH_CODE_FACE (Lisp_Object gc)
356 {
357   return CONSP (gc) ? XFIXNUM (XCDR (gc)) : XFIXNUM (gc) >> CHARACTERBITS;
358 }
359 
360 #define SET_GLYPH_FROM_GLYPH_CODE(glyph, gc)				\
361   do									\
362     {									\
363       if (CONSP (gc))							\
364 	SET_GLYPH (glyph, XFIXNUM (XCAR (gc)), XFIXNUM (XCDR (gc)));		\
365       else								\
366 	SET_GLYPH (glyph, (XFIXNUM (gc) & ((1 << CHARACTERBITS)-1)),	\
367 		   (XFIXNUM (gc) >> CHARACTERBITS));			\
368     }									\
369   while (false)
370 
371 /* The ID of the mode line highlighting face.  */
372 enum { GLYPH_MODE_LINE_FACE = 1 };
373 
374 /* Enumeration of glyph types.  Glyph structures contain a type field
375    containing one of the enumerators defined here.  */
376 
377 enum glyph_type
378 {
379   /* Glyph describes a character.  */
380   CHAR_GLYPH,
381 
382   /* Glyph describes a static or automatic composition.  */
383   COMPOSITE_GLYPH,
384 
385   /* Glyph describes a glyphless character.  */
386   GLYPHLESS_GLYPH,
387 
388   /* Glyph describes an image.  */
389   IMAGE_GLYPH,
390 
391   /* Glyph is a space of fractional width and/or height.  */
392   STRETCH_GLYPH,
393 
394   /* Glyph is an external widget drawn by the GUI toolkit.  */
395   XWIDGET_GLYPH
396 };
397 
398 
399 /* Structure describing how to use partial glyphs (images slicing) */
400 
401 struct glyph_slice
402 {
403   unsigned x : 16;
404   unsigned y : 16;
405   unsigned width : 16;
406   unsigned height : 16;
407 };
408 
409 
410 /* Glyphs.
411 
412    Be extra careful when changing this structure!  Esp. make sure that
413    functions producing glyphs, like append_glyph, fill ALL of the
414    glyph structure, and that GLYPH_EQUAL_P compares all
415    display-relevant members of glyphs (not to imply that these are the
416    only things to check when you add a member).  */
417 
418 struct glyph
419 {
420   /* Position from which this glyph was drawn.  If `object' below is a
421      Lisp string, this is an index into that string.  If it is a
422      buffer, this is a position in that buffer.  In addition, some
423      special glyphs have special values for this:
424 
425       glyph standing for newline at end of line    0
426       empty space after the end of the line       -1
427       overlay arrow on a TTY                      -1
428       glyph displaying line number                -1
429       glyph at EOB that ends in a newline         -1
430       left truncation glyphs:                     -1
431       right truncation/continuation glyphs        next buffer position
432       glyph standing for newline of an empty line buffer position of newline
433       stretch glyph at left edge of R2L lines     buffer position of newline  */
434   ptrdiff_t charpos;
435 
436   /* Lisp object source of this glyph.  Currently either a buffer or a
437      string, if the glyph was produced from characters which came from
438      a buffer or a string; or nil if the glyph was inserted by
439      redisplay for its own purposes, such as padding, truncation, or
440      continuation glyphs, or the overlay-arrow glyphs on TTYs.  */
441   Lisp_Object object;
442 
443   /* Width in pixels.  */
444   short pixel_width;
445 
446   /* Ascent and descent in pixels.  */
447   short ascent, descent;
448 
449   /* Vertical offset.  If < 0, the glyph is displayed raised, if > 0
450      the glyph is displayed lowered.  */
451   short voffset;
452 
453   /* Which kind of glyph this is---character, image etc.  Value
454      should be an enumerator of type enum glyph_type.  */
455   unsigned type : 3;
456 
457   /* True means this glyph was produced from multibyte text.  False
458      means it was produced from unibyte text, i.e. charsets aren't
459      applicable, and encoding is not performed.  */
460   bool_bf multibyte_p : 1;
461 
462   /* True means draw a box line at the left or right side of this
463      glyph.  This is part of the implementation of the face attribute
464      `:box'.  */
465   bool_bf left_box_line_p : 1;
466   bool_bf right_box_line_p : 1;
467 
468   /* True means this glyph's physical ascent or descent is greater
469      than its logical ascent/descent, i.e. it may potentially overlap
470      glyphs above or below it.  */
471   bool_bf overlaps_vertically_p : 1;
472 
473   /* For terminal frames, true means glyph is a padding glyph.  Padding
474      glyphs are used for characters whose visual shape consists of
475      more than one glyph (e.g. Asian characters).  All but the first
476      glyph of such a glyph sequence have the padding_p flag set.  This
477      flag is used only to minimize code changes.  A better way would
478      probably be to use the width field of glyphs to express padding.
479 
480      For graphic frames, true means the pixel width of the glyph in a
481      font is 0, but 1-pixel is padded on displaying for correct cursor
482      displaying.  The member `pixel_width' above is set to 1.  */
483   bool_bf padding_p : 1;
484 
485   /* True means the actual glyph is not available, draw using `struct
486      glyphless' below instead.  This can happen when a font couldn't
487      be loaded, or a character doesn't have a glyph in a font.  */
488   bool_bf glyph_not_available_p : 1;
489 
490   /* True means don't display cursor here.  */
491   bool_bf avoid_cursor_p : 1;
492 
493   /* Resolved bidirectional level of this character [0..127].  */
494   unsigned resolved_level : 7;
495 
496   /* Resolved bidirectional type of this character, see enum
497      bidi_type_t below.  Note that according to UAX#9, only some
498      values (STRONG_L, STRONG_R, WEAK_AN, WEAK_EN, WEAK_BN, and
499      NEUTRAL_B) can appear in the resolved type, so we only reserve
500      space for those that can.  */
501   unsigned bidi_type : 3;
502 
503 #define FACE_ID_BITS	20
504 
505   /* Face of the glyph.  This is a realized face ID,
506      an index in the face cache of the frame.  */
507   unsigned face_id : FACE_ID_BITS;
508 
509   /* Type of font used to display the character glyph.  May be used to
510      determine which set of functions to use to obtain font metrics
511      for the glyph.  On W32, value should be an enumerator of the type
512      w32_char_font_type.  Otherwise it equals FONT_TYPE_UNKNOWN.  */
513   unsigned font_type : 3;
514 
515   /* A union of sub-structures for different glyph types.  */
516   union
517   {
518     /* Metrics of a partial glyph of an image (type == IMAGE_GLYPH).  */
519     struct glyph_slice img;
520     /* Start and end indices of glyphs of a grapheme cluster of a
521        composition (type == COMPOSITE_GLYPH).  */
522     struct { int from, to; } cmp;
523     /* Pixel offsets for upper and lower part of the acronym.  */
524     struct {
525       short upper_xoff, upper_yoff;
526       short lower_xoff, lower_yoff;
527     } glyphless;
528   } slice;
529 
530   /* A union of sub-structures for different glyph types.  */
531   union
532   {
533     /* Character code for character glyphs (type == CHAR_GLYPH).  */
534     unsigned ch;
535 
536     /* Sub-structures for type == COMPOSITE_GLYPH.  */
537     struct
538     {
539       /* Flag to tell if the composition is automatic or not.  */
540       bool_bf automatic : 1;
541       /* ID of the composition.  */
542       unsigned id    : 31;
543     } cmp;
544 
545     /* Image ID for image glyphs (type == IMAGE_GLYPH).  */
546     int img_id;
547 
548 #ifdef HAVE_XWIDGETS
549     /* Xwidget ID.  */
550     uint32_t xwidget;
551 #endif
552 
553     /* Sub-structure for type == STRETCH_GLYPH.  */
554     struct
555     {
556       /* The height of the glyph.  */
557       unsigned height  : 16;
558 
559       /* The ascent of the glyph.  */
560       unsigned ascent  : 16;
561     }
562     stretch;
563 
564     /* Sub-stretch for type == GLYPHLESS_GLYPH.  */
565     struct
566     {
567       /* Value is an enum of the type glyphless_display_method.  */
568       unsigned method : 2;
569       /* True iff this glyph is for a character of no font. */
570       bool_bf for_no_font : 1;
571       /* Length of acronym or hexadecimal code string (at most 8).  */
572       unsigned len : 4;
573       /* Character to display.  Actually we need only 22 bits.  */
574       unsigned ch : 25;
575     } glyphless;
576 
577     /* Used to compare all bit-fields above in one step.  */
578     unsigned val;
579   } u;
580 };
581 
582 
583 /* Default value of the glyph font_type field.  */
584 
585 #define FONT_TYPE_UNKNOWN	0
586 
587 /* Is GLYPH a space?  */
588 
589 #define CHAR_GLYPH_SPACE_P(GLYPH) \
590   ((GLYPH).u.ch == SPACEGLYPH && (GLYPH).face_id == DEFAULT_FACE_ID)
591 
592 /* Are glyph slices of glyphs *X and *Y equal?  It assumes that both
593    glyphs have the same type.
594 
595    Note: for composition glyphs, we don't have to compare slice.cmp.to
596    because they should be the same if and only if slice.cmp.from are
597    the same.  */
598 
599 #define GLYPH_SLICE_EQUAL_P(X, Y)				\
600   ((X)->type == IMAGE_GLYPH					\
601    ? ((X)->slice.img.x == (Y)->slice.img.x			\
602       && (X)->slice.img.y == (Y)->slice.img.y			\
603       && (X)->slice.img.width == (Y)->slice.img.width		\
604       && (X)->slice.img.height == (Y)->slice.img.height)	\
605    : ((X)->type != COMPOSITE_GLYPH				\
606       || (X)->slice.cmp.from == (Y)->slice.cmp.from))
607 
608 /* Are glyphs *X and *Y displayed equal?  */
609 
610 #define GLYPH_EQUAL_P(X, Y)					\
611      ((X)->type == (Y)->type					\
612       && (X)->u.val == (Y)->u.val				\
613       && GLYPH_SLICE_EQUAL_P (X, Y)				\
614       && (X)->face_id == (Y)->face_id				\
615       && (X)->padding_p == (Y)->padding_p			\
616       && (X)->left_box_line_p == (Y)->left_box_line_p		\
617       && (X)->right_box_line_p == (Y)->right_box_line_p		\
618       && (X)->voffset == (Y)->voffset				\
619       && (X)->pixel_width == (Y)->pixel_width)
620 
621 /* Are character codes, faces, padding_ps of glyphs *X and *Y equal?  */
622 
623 #define GLYPH_CHAR_AND_FACE_EQUAL_P(X, Y)	\
624   ((X)->u.ch == (Y)->u.ch			\
625    && (X)->face_id == (Y)->face_id		\
626    && (X)->padding_p == (Y)->padding_p)
627 
628 /* Fill a character glyph GLYPH.  CODE, FACE_ID, PADDING_P correspond
629    to the bits defined for the typedef `GLYPH' in lisp.h.  */
630 
631 #define SET_CHAR_GLYPH(GLYPH, CODE, FACE_ID, PADDING_P)	\
632      do							\
633        {						\
634          (GLYPH).u.ch = (CODE);				\
635          (GLYPH).face_id = (FACE_ID);			\
636          (GLYPH).padding_p = (PADDING_P);		\
637        }						\
638      while (false)
639 
640 /* Fill a character type glyph GLYPH from a glyph typedef FROM as
641    defined in lisp.h.  */
642 
643 #define SET_CHAR_GLYPH_FROM_GLYPH(GLYPH, FROM)			\
644      SET_CHAR_GLYPH ((GLYPH),					\
645 	 	     GLYPH_CHAR ((FROM)),			\
646 		     GLYPH_FACE ((FROM)),			\
647 		     false)
648 
649 /* Construct a glyph code from a character glyph GLYPH.  If the
650    character is multibyte, return -1 as we can't use glyph table for a
651    multibyte character.  */
652 
653 #define SET_GLYPH_FROM_CHAR_GLYPH(G, GLYPH)			\
654   do								\
655     {								\
656       if ((GLYPH).u.ch < 256)					\
657 	SET_GLYPH ((G), (GLYPH).u.ch, ((GLYPH).face_id));	\
658       else							\
659 	SET_GLYPH ((G), -1, 0);					\
660     }								\
661   while (false)
662 
663 #define GLYPH_INVALID_P(GLYPH) (GLYPH_CHAR (GLYPH) < 0)
664 
665 /* Is GLYPH a padding glyph?  */
666 
667 #define CHAR_GLYPH_PADDING_P(GLYPH) (GLYPH).padding_p
668 
669 
670 
671 
672 /***********************************************************************
673 			     Glyph Pools
674  ***********************************************************************/
675 
676 /* Glyph Pool.
677 
678    Glyph memory for frame-based redisplay is allocated from the heap
679    in one vector kept in a glyph pool structure which is stored with
680    the frame.  The size of the vector is made large enough to cover
681    all windows on the frame.
682 
683    Both frame and window glyph matrices reference memory from a glyph
684    pool in frame-based redisplay.
685 
686    In window-based redisplay, no glyphs pools exist; windows allocate
687    and free their glyph memory themselves.  */
688 
689 struct glyph_pool
690 {
691   /* Vector of glyphs allocated from the heap.  */
692   struct glyph *glyphs;
693 
694   /* Allocated size of `glyphs'.  */
695   ptrdiff_t nglyphs;
696 
697   /* Number of rows and columns in a matrix.  */
698   int nrows, ncolumns;
699 };
700 
701 
702 
703 /***********************************************************************
704 			     Glyph Matrix
705  ***********************************************************************/
706 
707 /* Glyph Matrix.
708 
709    Three kinds of glyph matrices exist:
710 
711    1. Frame glyph matrices.  These are used for terminal frames whose
712    redisplay needs a view of the whole screen due to limited terminal
713    capabilities.  Frame matrices are used only in the update phase
714    of redisplay.  They are built in update_frame and not used after
715    the update has been performed.
716 
717    2. Window glyph matrices on frames having frame glyph matrices.
718    Such matrices are sub-matrices of their corresponding frame matrix,
719    i.e., frame glyph matrices and window glyph matrices share the same
720    glyph memory, which is allocated in the form of a glyph_pool structure.
721    Glyph rows in such a window matrix are slices of frame matrix rows.
722 
723    3. Free-standing window glyph matrices managing their own glyph
724    storage.  This form is used in window-based redisplay which
725    includes variable width and height fonts etc.
726 
727    The size of a window's row vector depends on the height of fonts
728    defined on its frame.  It is chosen so that the vector is large
729    enough to describe all lines in a window when it is displayed in
730    the smallest possible character size.  When new fonts are loaded,
731    or window sizes change, the row vector is adjusted accordingly.  */
732 
733 struct glyph_matrix
734 {
735   /* The pool from which glyph memory is allocated, if any.  This is
736      null for frame matrices and for window matrices managing their
737      own storage.  */
738   struct glyph_pool *pool;
739 
740   /* Vector of glyph row structures.  The row at nrows - 1 is reserved
741      for the mode line.  */
742   struct glyph_row *rows;
743 
744   /* Number of elements allocated for the vector rows above.  */
745   ptrdiff_t rows_allocated;
746 
747   /* The number of rows used by the window if all lines were displayed
748      with the smallest possible character height.  */
749   int nrows;
750 
751   /* Origin within the frame matrix if this is a window matrix on a
752      frame having a frame matrix.  Both values are zero for
753      window-based redisplay.  */
754   int matrix_x, matrix_y;
755 
756   /* Width and height of the matrix in columns and rows.  */
757   int matrix_w, matrix_h;
758 
759   /* If this structure describes a window matrix of window W,
760      window_pixel_left is the value of W->pixel_left, window_pixel_top
761      the value of W->pixel_top, window_height and window_width are width
762      and height of W, as returned by window_box, and window_vscroll is
763      the value of W->vscroll at the time the matrix was last adjusted.
764      Only set for window-based redisplay.  */
765   int window_pixel_left, window_pixel_top;
766   int window_height, window_width;
767   int window_vscroll;
768 
769   /* Number of glyphs reserved for left and right marginal areas when
770      the matrix was last adjusted.  */
771   int left_margin_glyphs, right_margin_glyphs;
772 
773   /* Flag indicating that scrolling should not be tried in
774      update_window.  This flag is set by functions like try_window_id
775      which do their own scrolling.  */
776   bool_bf no_scrolling_p : 1;
777 
778   /* True means window displayed in this matrix has a tab line.  */
779   bool_bf tab_line_p : 1;
780 
781   /* True means window displayed in this matrix has a header
782      line.  */
783   bool_bf header_line_p : 1;
784 
785 #ifdef GLYPH_DEBUG
786   /* A string identifying the method used to display the matrix.  */
787   char method[512];
788 #endif
789 
790   /* The buffer this matrix displays.  Set in
791      mark_window_display_accurate_1.  */
792   struct buffer *buffer;
793 
794   /* Values of BEGV and ZV as of last redisplay.  Set in
795      mark_window_display_accurate_1.  */
796   ptrdiff_t begv, zv;
797 };
798 
799 
800 /* Check that glyph pointers stored in glyph rows of MATRIX are okay.
801    This aborts if any pointer is found twice.  */
802 
803 #ifdef GLYPH_DEBUG
804 void check_matrix_pointer_lossage (struct glyph_matrix *);
805 #define CHECK_MATRIX(MATRIX) check_matrix_pointer_lossage ((MATRIX))
806 #else
807 #define CHECK_MATRIX(MATRIX) ((void) 0)
808 #endif
809 
810 
811 
812 /***********************************************************************
813 			     Glyph Rows
814  ***********************************************************************/
815 
816 /* Area in window glyph matrix.  If values are added or removed,
817    the function mark_glyph_matrix in alloc.c may need to be changed.  */
818 
819 enum glyph_row_area
820 {
821   ANY_AREA = -1,
822   LEFT_MARGIN_AREA,
823   TEXT_AREA,
824   RIGHT_MARGIN_AREA,
825   LAST_AREA
826 };
827 
828 
829 /* Rows of glyphs in a windows or frame glyph matrix.
830 
831    Each row is partitioned into three areas.  The start and end of
832    each area is recorded in a pointer as shown below.
833 
834    +--------------------+-------------+---------------------+
835    |  left margin area  |  text area  |  right margin area  |
836    +--------------------+-------------+---------------------+
837    |                    |             |                     |
838    glyphs[LEFT_MARGIN_AREA]           glyphs[RIGHT_MARGIN_AREA]
839 			|                                   |
840 			glyphs[TEXT_AREA]                   |
841 			                      glyphs[LAST_AREA]
842 
843    Rows in frame matrices reference glyph memory allocated in a frame
844    glyph pool (see the description of struct glyph_pool).  Rows in
845    window matrices on frames having frame matrices reference slices of
846    the glyphs of corresponding rows in the frame matrix.
847 
848    Rows in window matrices on frames having no frame matrices point to
849    glyphs allocated from the heap via xmalloc;
850    glyphs[LEFT_MARGIN_AREA] is the start address of the allocated
851    glyph structure array.
852 
853    NOTE: layout of first four members of this structure is important,
854    see clear_glyph_row and copy_row_except_pointers to check why.  */
855 
856 struct glyph_row
857 {
858   /* Pointers to beginnings of areas.  The end of an area A is found at
859      A + 1 in the vector.  The last element of the vector is the end
860      of the whole row.
861 
862      Kludge alert: Even if used[TEXT_AREA] == 0, glyphs[TEXT_AREA][0]'s
863      position field is used.  It is -1 if this row does not correspond
864      to any text; it is some buffer position if the row corresponds to
865      an empty display line that displays a line end.  This is what old
866      redisplay used to do.  (Except in code for terminal frames, this
867      kludge is no longer used, I believe. --gerd).
868 
869      See also start, end, displays_text_p and ends_at_zv_p for cleaner
870      ways to do it.  The special meaning of positions 0 and -1 will be
871      removed some day, so don't use it in new code.  */
872   struct glyph *glyphs[1 + LAST_AREA];
873 
874   /* Number of glyphs actually filled in areas.  This could have size
875      LAST_AREA, but it's 1 + LAST_AREA to simplify offset calculations.  */
876   short used[1 + LAST_AREA];
877 
878   /* Hash code.  This hash code is available as soon as the row
879      is constructed, i.e. after a call to display_line.  */
880   unsigned hash;
881 
882   /* Window-relative x and y-position of the top-left corner of this
883      row.  If y < 0, this means that eabs (y) pixels of the row are
884      invisible because it is partially visible at the top of a window.
885      If x < 0, this means that eabs (x) pixels of the first glyph of
886      the text area of the row are invisible because the glyph is
887      partially visible.  */
888   int x, y;
889 
890   /* Width of the row in pixels without taking face extension at the
891      end of the row into account, and without counting truncation
892      and continuation glyphs at the end of a row on ttys.  */
893   int pixel_width;
894 
895   /* Logical ascent/height of this line.  The value of ascent is zero
896      and height is 1 on terminal frames.  */
897   int ascent, height;
898 
899   /* Physical ascent/height of this line.  If max_ascent > ascent,
900      this line overlaps the line above it on the display.  Otherwise,
901      if max_height > height, this line overlaps the line beneath it.  */
902   int phys_ascent, phys_height;
903 
904   /* Portion of row that is visible.  Partially visible rows may be
905      found at the top and bottom of a window.  This is 1 for tty
906      frames.  It may be < 0 in case of completely invisible rows.  */
907   int visible_height;
908 
909   /* Extra line spacing added after this row.  Do not consider this
910      in last row when checking if row is fully visible.  */
911   int extra_line_spacing;
912 
913   /* First position in this row.  This is the text position, including
914      overlay position information etc, where the display of this row
915      started, and can thus be less than the position of the first
916      glyph (e.g. due to invisible text or horizontal scrolling).
917      BIDI Note: In R2L rows, that have its reversed_p flag set, this
918      position is at or beyond the right edge of the row.  */
919   struct display_pos start;
920 
921   /* Text position at the end of this row.  This is the position after
922      the last glyph on this row.  It can be greater than the last
923      glyph position + 1, due to a newline that ends the line,
924      truncation, invisible text etc.  In an up-to-date display, this
925      should always be equal to the start position of the next row.
926      BIDI Note: In R2L rows, this position is at or beyond the left
927      edge of the row.  */
928   struct display_pos end;
929 
930   /* The smallest and the largest buffer positions that contributed to
931      glyphs in this row.  Note that due to bidi reordering, these are
932      in general different from the text positions stored in `start'
933      and `end' members above, and also different from the buffer
934      positions recorded in the glyphs displayed the leftmost and
935      rightmost on the screen.  */
936   struct text_pos minpos, maxpos;
937 
938   /* Non-zero means the overlay arrow bitmap is on this line.
939      -1 means use default overlay arrow bitmap, else
940      it specifies actual fringe bitmap number.  */
941   int overlay_arrow_bitmap;
942 
943   /* Left fringe bitmap number (enum fringe_bitmap_type).  */
944   unsigned left_user_fringe_bitmap : FRINGE_ID_BITS;
945 
946   /* Right fringe bitmap number (enum fringe_bitmap_type).  */
947   unsigned right_user_fringe_bitmap : FRINGE_ID_BITS;
948 
949   /* Left fringe bitmap number (enum fringe_bitmap_type).  */
950   unsigned left_fringe_bitmap : FRINGE_ID_BITS;
951 
952   /* Right fringe bitmap number (enum fringe_bitmap_type).  */
953   unsigned right_fringe_bitmap : FRINGE_ID_BITS;
954 
955   /* Face of the left fringe glyph.  */
956   unsigned left_user_fringe_face_id : FACE_ID_BITS;
957 
958   /* Face of the right fringe glyph.  */
959   unsigned right_user_fringe_face_id : FACE_ID_BITS;
960 
961   /* Face of the left fringe glyph.  */
962   unsigned left_fringe_face_id : FACE_ID_BITS;
963 
964   /* Face of the right fringe glyph.  */
965   unsigned right_fringe_face_id : FACE_ID_BITS;
966 
967   /* Vertical offset of the left fringe bitmap.  */
968   signed left_fringe_offset : FRINGE_HEIGHT_BITS;
969 
970   /* Vertical offset of the right fringe bitmap.  */
971   signed right_fringe_offset : FRINGE_HEIGHT_BITS;
972 
973   /* True means that at least one of the left and right fringe bitmaps is
974      periodic and thus depends on the y-position of the row.  */
975   bool_bf fringe_bitmap_periodic_p : 1;
976 
977   /* True means that we must draw the bitmaps of this row.  */
978   bool_bf redraw_fringe_bitmaps_p : 1;
979 
980   /* In a desired matrix, true means that this row must be updated.  In a
981      current matrix, false means that the row has been invalidated, i.e.
982      the row's contents do not agree with what is visible on the
983      screen.  */
984   bool_bf enabled_p : 1;
985 
986   /* True means row displays a text line that is truncated on the left or
987      right side.  */
988   bool_bf truncated_on_left_p : 1;
989   bool_bf truncated_on_right_p : 1;
990 
991   /* True means that this row displays a continued line, i.e. it has a
992      continuation mark at the right side.  */
993   bool_bf continued_p : 1;
994 
995   /* False means that this row does not contain any text, i.e., it is
996      a blank line at the window and buffer end.  */
997   bool_bf displays_text_p : 1;
998 
999   /* True means that this line ends at ZV.  */
1000   bool_bf ends_at_zv_p : 1;
1001 
1002   /* True means the face of the last glyph in the text area is drawn to
1003      the right end of the window.  This flag is used in
1004      update_text_area to optimize clearing to the end of the area.  */
1005   bool_bf fill_line_p : 1;
1006 
1007   /* True means display a bitmap on X frames indicating that this
1008      line contains no text and ends in ZV.  */
1009   bool_bf indicate_empty_line_p : 1;
1010 
1011   /* True means this row contains glyphs that overlap each other because
1012      of lbearing or rbearing.  */
1013   bool_bf contains_overlapping_glyphs_p : 1;
1014 
1015   /* True means this row is as wide as the window it is displayed in, including
1016      scroll bars, fringes, and internal borders.  This also
1017      implies that the row doesn't have marginal areas.  */
1018   bool_bf full_width_p : 1;
1019 
1020   /* True means row is a mode or header/tab-line.  */
1021   bool_bf mode_line_p : 1;
1022 
1023   /* True means row is a tab-line.  */
1024   bool_bf tab_line_p : 1;
1025 
1026   /* True in a current row means this row is overlapped by another row.  */
1027   bool_bf overlapped_p : 1;
1028 
1029   /* True means this line ends in the middle of a character consisting
1030      of more than one glyph.  Some glyphs have been put in this row,
1031      the rest are put in rows below this one.  */
1032   bool_bf ends_in_middle_of_char_p : 1;
1033 
1034   /* True means this line starts in the middle of a character consisting
1035      of more than one glyph.  Some glyphs have been put in the
1036      previous row, the rest are put in this row.  */
1037   bool_bf starts_in_middle_of_char_p : 1;
1038 
1039   /* True in a current row means this row overlaps others.  */
1040   bool_bf overlapping_p : 1;
1041 
1042   /* True means some glyphs in this row are displayed in mouse-face.  */
1043   bool_bf mouse_face_p : 1;
1044 
1045   /* True means this row was ended by a newline from a string.  */
1046   bool_bf ends_in_newline_from_string_p : 1;
1047 
1048   /* True means this row width is exactly the width of the window, and the
1049      final newline character is hidden in the right fringe.  */
1050   bool_bf exact_window_width_line_p : 1;
1051 
1052   /* True means this row currently shows the cursor in the right fringe.  */
1053   bool_bf cursor_in_fringe_p : 1;
1054 
1055   /* True means the last glyph in the row is part of an ellipsis.  */
1056   bool_bf ends_in_ellipsis_p : 1;
1057 
1058   /* True means display a bitmap on X frames indicating that this
1059      the first line of the buffer.  */
1060   bool_bf indicate_bob_p : 1;
1061 
1062   /* True means display a bitmap on X frames indicating that this
1063      the top line of the window, but not start of the buffer.  */
1064   bool_bf indicate_top_line_p : 1;
1065 
1066   /* True means display a bitmap on X frames indicating that this
1067      the last line of the buffer.  */
1068   bool_bf indicate_eob_p : 1;
1069 
1070   /* True means display a bitmap on X frames indicating that this
1071      the bottom line of the window, but not end of the buffer.  */
1072   bool_bf indicate_bottom_line_p : 1;
1073 
1074   /* True means the row was reversed to display text in a
1075      right-to-left paragraph.  */
1076   bool_bf reversed_p : 1;
1077 
1078   /* Continuation lines width at the start of the row.  */
1079   int continuation_lines_width;
1080 
1081 #ifdef HAVE_WINDOW_SYSTEM
1082   /* Non-NULL means the current clipping area.  This is temporarily
1083      set while exposing a region.  Coordinates are frame-relative.  */
1084   const Emacs_Rectangle *clip;
1085 #endif
1086 };
1087 
1088 
1089 /* Get a pointer to row number ROW in matrix MATRIX.  If GLYPH_DEBUG
1090    is defined, the function matrix_row checks that we don't try to
1091    access rows that are out of bounds.  */
1092 
1093 #ifdef GLYPH_DEBUG
1094 struct glyph_row *matrix_row (struct glyph_matrix *, int);
1095 #define MATRIX_ROW(MATRIX, ROW)   matrix_row ((MATRIX), (ROW))
1096 #else
1097 #define MATRIX_ROW(MATRIX, ROW)	  ((MATRIX)->rows + (ROW))
1098 #endif
1099 
1100 /* Return a pointer to the row reserved for the mode line in MATRIX.
1101    Row MATRIX->nrows - 1 is always reserved for the mode line.  */
1102 
1103 #define MATRIX_MODE_LINE_ROW(MATRIX) \
1104      ((MATRIX)->rows + (MATRIX)->nrows - 1)
1105 
1106 /* Return a pointer to the row reserved for the tab line in MATRIX.
1107    This is always the first row in MATRIX because that's the only
1108    way that works in frame-based redisplay.  */
1109 
1110 #define MATRIX_TAB_LINE_ROW(MATRIX) (MATRIX)->rows
1111 
1112 /* Return a pointer to the row reserved for the header line in MATRIX.
1113    This is always the second row in MATRIX because that's the only
1114    way that works in frame-based redisplay.  */
1115 
1116 #define MATRIX_HEADER_LINE_ROW(MATRIX) \
1117      ((MATRIX)->tab_line_p ? ((MATRIX)->rows + 1) : (MATRIX)->rows)
1118 
1119 /* Return a pointer to first row in MATRIX used for text display.  */
1120 
1121 #define MATRIX_FIRST_TEXT_ROW(MATRIX) \
1122   ((MATRIX)->rows->mode_line_p ?                                        \
1123    (((MATRIX)->rows + 1)->mode_line_p ?                                 \
1124     (MATRIX)->rows + 2 : (MATRIX)->rows + 1) : (MATRIX)->rows)
1125 
1126 /* Return a pointer to the first glyph in the text area of a row.
1127    MATRIX is the glyph matrix accessed, and ROW is the row index in
1128    MATRIX.  */
1129 
1130 #define MATRIX_ROW_GLYPH_START(MATRIX, ROW) \
1131      (MATRIX_ROW ((MATRIX), (ROW))->glyphs[TEXT_AREA])
1132 
1133 /* Return the number of used glyphs in the text area of a row.  */
1134 
1135 #define MATRIX_ROW_USED(MATRIX, ROW) \
1136      (MATRIX_ROW ((MATRIX), (ROW))->used[TEXT_AREA])
1137 
1138 /* Return the character/ byte position at which the display of ROW
1139    starts.  BIDI Note: this is the smallest character/byte position
1140    among characters in ROW, i.e. the first logical-order character
1141    displayed by ROW, which is not necessarily the smallest horizontal
1142    position.  */
1143 
1144 #define MATRIX_ROW_START_CHARPOS(ROW) ((ROW)->minpos.charpos)
1145 #define MATRIX_ROW_START_BYTEPOS(ROW) ((ROW)->minpos.bytepos)
1146 
1147 /* Return the character/ byte position at which ROW ends.  BIDI Note:
1148    this is the largest character/byte position among characters in
1149    ROW, i.e. the last logical-order character displayed by ROW, which
1150    is not necessarily the largest horizontal position.  */
1151 
1152 #define MATRIX_ROW_END_CHARPOS(ROW) ((ROW)->maxpos.charpos)
1153 #define MATRIX_ROW_END_BYTEPOS(ROW) ((ROW)->maxpos.bytepos)
1154 
1155 /* Return the vertical position of ROW in MATRIX.  */
1156 
1157 #define MATRIX_ROW_VPOS(ROW, MATRIX) ((ROW) - (MATRIX)->rows)
1158 
1159 /* Return the last glyph row + 1 in MATRIX on window W reserved for
1160    text.  If W has a mode line, the last row in the matrix is reserved
1161    for it.  */
1162 
1163 #define MATRIX_BOTTOM_TEXT_ROW(MATRIX, W)		\
1164      ((MATRIX)->rows					\
1165       + (MATRIX)->nrows					\
1166       - (window_wants_mode_line ((W)) ? 1 : 0))
1167 
1168 /* Non-zero if the face of the last glyph in ROW's text area has
1169    to be drawn to the end of the text area.  */
1170 
1171 #define MATRIX_ROW_EXTENDS_FACE_P(ROW) ((ROW)->fill_line_p)
1172 
1173 /* Set and query the enabled_p flag of glyph row ROW in MATRIX.  */
1174 
1175 #define SET_MATRIX_ROW_ENABLED_P(MATRIX, ROW, VALUE) \
1176      (MATRIX_ROW (MATRIX, ROW)->enabled_p = (VALUE))
1177 
1178 #define MATRIX_ROW_ENABLED_P(MATRIX, ROW) \
1179      (MATRIX_ROW (MATRIX, ROW)->enabled_p)
1180 
1181 /* Non-zero if ROW displays text.  Value is non-zero if the row is
1182    blank but displays a line end.  */
1183 
1184 #define MATRIX_ROW_DISPLAYS_TEXT_P(ROW) ((ROW)->displays_text_p)
1185 
1186 
1187 /* Helper macros */
1188 
1189 #define MR_PARTIALLY_VISIBLE(ROW)	\
1190   ((ROW)->height != (ROW)->visible_height)
1191 
1192 #define MR_PARTIALLY_VISIBLE_AT_TOP(W, ROW)  \
1193   ((ROW)->y < WINDOW_TAB_LINE_HEIGHT (W) + WINDOW_HEADER_LINE_HEIGHT (W))
1194 
1195 #define MR_PARTIALLY_VISIBLE_AT_BOTTOM(W, ROW)  \
1196   (((ROW)->y + (ROW)->height - (ROW)->extra_line_spacing) \
1197    > WINDOW_BOX_HEIGHT_NO_MODE_LINE ((W)))
1198 
1199 /* Non-zero if ROW is not completely visible in window W.  */
1200 
1201 #define MATRIX_ROW_PARTIALLY_VISIBLE_P(W, ROW)		\
1202   (MR_PARTIALLY_VISIBLE ((ROW))				\
1203    && (MR_PARTIALLY_VISIBLE_AT_TOP ((W), (ROW))		\
1204        || MR_PARTIALLY_VISIBLE_AT_BOTTOM ((W), (ROW))))
1205 
1206 
1207 
1208 /* Non-zero if ROW is partially visible at the top of window W.  */
1209 
1210 #define MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P(W, ROW)		\
1211   (MR_PARTIALLY_VISIBLE ((ROW))					\
1212    && MR_PARTIALLY_VISIBLE_AT_TOP ((W), (ROW)))
1213 
1214 /* Non-zero if ROW is partially visible at the bottom of window W.  */
1215 
1216 #define MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P(W, ROW)	\
1217   (MR_PARTIALLY_VISIBLE ((ROW))					\
1218    && MR_PARTIALLY_VISIBLE_AT_BOTTOM ((W), (ROW)))
1219 
1220 /* Return the bottom Y + 1 of ROW.   */
1221 
1222 #define MATRIX_ROW_BOTTOM_Y(ROW) ((ROW)->y + (ROW)->height)
1223 
1224 /* Is ROW the last visible one in the display described by the
1225    iterator structure pointed to by IT?.  */
1226 
1227 #define MATRIX_ROW_LAST_VISIBLE_P(ROW, IT) \
1228      (MATRIX_ROW_BOTTOM_Y ((ROW)) >= (IT)->last_visible_y)
1229 
1230 /* Non-zero if ROW displays a continuation line.  */
1231 
1232 #define MATRIX_ROW_CONTINUATION_LINE_P(ROW) \
1233      ((ROW)->continuation_lines_width > 0)
1234 
1235 /* Non-zero if ROW ends in the middle of a character.  This is the
1236    case for continued lines showing only part of a display table entry
1237    or a control char, or an overlay string.  */
1238 
1239 #define MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P(ROW)	\
1240      ((ROW)->end.dpvec_index > 0			\
1241       || (ROW)->end.overlay_string_index >= 0		\
1242       || (ROW)->ends_in_middle_of_char_p)
1243 
1244 /* Non-zero if ROW ends in the middle of an overlay string.  */
1245 
1246 #define MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P(ROW) \
1247      ((ROW)->end.overlay_string_index >= 0)
1248 
1249 /* Non-zero if ROW starts in the middle of a character.  See above.  */
1250 
1251 #define MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P(ROW)	\
1252      ((ROW)->start.dpvec_index > 0			\
1253       || (ROW)->starts_in_middle_of_char_p		\
1254       || ((ROW)->start.overlay_string_index >= 0	\
1255 	  && (ROW)->start.string_pos.charpos > 0))
1256 
1257 /* True means ROW overlaps its predecessor.  */
1258 
1259 #define MATRIX_ROW_OVERLAPS_PRED_P(ROW) \
1260      ((ROW)->phys_ascent > (ROW)->ascent)
1261 
1262 /* True means ROW overlaps its successor.  */
1263 
1264 #define MATRIX_ROW_OVERLAPS_SUCC_P(ROW)		\
1265       ((ROW)->phys_height - (ROW)->phys_ascent	\
1266        > (ROW)->height - (ROW)->ascent)
1267 
1268 /* A glyph for a space.  */
1269 
1270 extern struct glyph space_glyph;
1271 
1272 /* True means last display completed.  False means it was preempted.  */
1273 
1274 extern bool display_completed;
1275 
1276 /************************************************************************
1277 			  Glyph Strings
1278  ************************************************************************/
1279 
1280 /* Enumeration for overriding/changing the face to use for drawing
1281    glyphs in draw_glyphs.  */
1282 
1283 enum draw_glyphs_face
1284 {
1285   DRAW_NORMAL_TEXT,
1286   DRAW_INVERSE_VIDEO,
1287   DRAW_CURSOR,
1288   DRAW_MOUSE_FACE,
1289   DRAW_IMAGE_RAISED,
1290   DRAW_IMAGE_SUNKEN
1291 };
1292 
1293 #ifdef HAVE_WINDOW_SYSTEM
1294 
1295 /* A sequence of glyphs to be drawn in the same face.  */
1296 
1297 struct glyph_string
1298 {
1299   /* X-origin of the string.  */
1300   int x;
1301 
1302   /* Y-origin and y-position of the base line of this string.  */
1303   int y, ybase;
1304 
1305   /* The width of the string, not including a face extension.  */
1306   int width;
1307 
1308   /* The width of the string, including a face extension.  */
1309   int background_width;
1310 
1311   /* The height of this string.  This is the height of the line this
1312      string is drawn in, and can be different from the height of the
1313      font the string is drawn in.  */
1314   int height;
1315 
1316   /* Number of pixels this string overwrites in front of its x-origin.
1317      This number is zero if the string has an lbearing >= 0; it is
1318      -lbearing, if the string has an lbearing < 0.  */
1319   int left_overhang;
1320 
1321   /* Number of pixels this string overwrites past its right-most
1322      nominal x-position, i.e. x + width.  Zero if the string's
1323      rbearing is <= its nominal width, rbearing - width otherwise.  */
1324   int right_overhang;
1325 
1326   /* The frame on which the glyph string is drawn.  */
1327   struct frame *f;
1328 
1329   /* The window on which the glyph string is drawn.  */
1330   struct window *w;
1331 
1332   /* The glyph row for which this string was built.  It determines the
1333      y-origin and height of the string.  */
1334   struct glyph_row *row;
1335 
1336   /* The area within row.  */
1337   enum glyph_row_area area;
1338 
1339   /* Characters to be drawn, and number of characters.  Note that
1340      NCHARS can be zero if this is a composition glyph string, as
1341      evidenced by FIRST_GLYPH->type.  */
1342   unsigned *char2b;
1343   int nchars;
1344 
1345   /* A face-override for drawing cursors, mouse face and similar.  */
1346   enum draw_glyphs_face hl;
1347 
1348   /* Face in which this string is to be drawn.  */
1349   struct face *face;
1350 
1351   /* Font in which this string is to be drawn.  */
1352   struct font *font;
1353 
1354   /* Non-null means this string describes (part of) a static
1355      composition.  */
1356   struct composition *cmp;
1357 
1358   /* If not negative, this string describes a compos.  */
1359   ptrdiff_t cmp_id;
1360 
1361   /* Start and end glyph indices in a glyph-string.  */
1362   int cmp_from, cmp_to;
1363 
1364   /* True means this glyph strings face has to be drawn to the right end
1365      of the window's drawing area.  */
1366   bool_bf extends_to_end_of_line_p : 1;
1367 
1368   /* True means the background of this string has been drawn.  */
1369   bool_bf background_filled_p : 1;
1370 
1371   /* True means that the original font determined for drawing this glyph
1372      string could not be loaded.  The member `font' has been set to
1373      the frame's default font in this case.  */
1374   bool_bf font_not_found_p : 1;
1375 
1376   /* True means that the face in which this glyph string is drawn has a
1377      stipple pattern.  */
1378   bool_bf stippled_p : 1;
1379 
1380 #define OVERLAPS_PRED		(1 << 0)
1381 #define OVERLAPS_SUCC		(1 << 1)
1382 #define OVERLAPS_BOTH		(OVERLAPS_PRED | OVERLAPS_SUCC)
1383 #define OVERLAPS_ERASED_CURSOR 	(1 << 2)
1384   /* Non-zero means only the foreground of this glyph string must be
1385      drawn, and we should use the physical height of the line this
1386      glyph string appears in as clip rect.  If the value is
1387      OVERLAPS_ERASED_CURSOR, the clip rect is restricted to the rect
1388      of the erased cursor.  OVERLAPS_PRED and OVERLAPS_SUCC mean we
1389      draw overlaps with the preceding and the succeeding rows,
1390      respectively.  */
1391   unsigned for_overlaps : 3;
1392 
1393   /* True means that all glyphs in this glyph string has the flag
1394      padding_p set, and thus must be drawn one by one to have 1-pixel
1395      width even though the logical width in the font is zero.  */
1396   bool_bf padding_p : 1;
1397 
1398   /* The GC to use for drawing this glyph string.  */
1399 #if defined (HAVE_X_WINDOWS)
1400   GC gc;
1401 #endif
1402 #if defined (HAVE_NTGUI)
1403   Emacs_GC *gc;
1404   HDC hdc;
1405 #endif
1406 #if defined (HAVE_PGTK)
1407   Emacs_GC xgcv;
1408 #endif
1409 
1410   /* A pointer to the first glyph in the string.  This glyph
1411      corresponds to char2b[0].  Needed to draw rectangles if
1412      font_not_found_p is true.  */
1413   struct glyph *first_glyph;
1414 
1415   /* Image, if any.  */
1416   struct image *img;
1417 
1418   /* Xwidget.  */
1419   struct xwidget *xwidget;
1420 
1421   /* Slice */
1422   struct glyph_slice slice;
1423 
1424   /* Non-null means the horizontal clipping region starts from the
1425      left edge of *clip_head, and ends with the right edge of
1426      *clip_tail, not including their overhangs.  */
1427   struct glyph_string *clip_head, *clip_tail;
1428 
1429   /* The current clipping areas.  */
1430   NativeRectangle clip[2];
1431 
1432   /* Number of clipping areas. */
1433   int num_clips;
1434 
1435   int underline_position;
1436 
1437   int underline_thickness;
1438 
1439   struct glyph_string *next, *prev;
1440 };
1441 
1442 #endif /* HAVE_WINDOW_SYSTEM */
1443 
1444 
1445 /************************************************************************
1446 			  Display Dimensions
1447  ************************************************************************/
1448 
1449 /* Return the height of the mode line in glyph matrix MATRIX, or zero
1450    if not known.  This macro is called under circumstances where
1451    MATRIX might not have been allocated yet.  */
1452 
1453 #define MATRIX_MODE_LINE_HEIGHT(MATRIX)		\
1454      ((MATRIX) && (MATRIX)->rows		\
1455       ? MATRIX_MODE_LINE_ROW (MATRIX)->height	\
1456       : 0)
1457 
1458 /* Return the height of the header line in glyph matrix MATRIX, or zero
1459    if not known.  This macro is called under circumstances where
1460    MATRIX might not have been allocated yet.  */
1461 
1462 #define MATRIX_HEADER_LINE_HEIGHT(MATRIX)	\
1463      ((MATRIX) && (MATRIX)->rows		\
1464       ? MATRIX_HEADER_LINE_ROW (MATRIX)->height	\
1465       : 0)
1466 
1467 /* Return the height of the tab line in glyph matrix MATRIX, or zero
1468    if not known.  This macro is called under circumstances where
1469    MATRIX might not have been allocated yet.  */
1470 
1471 #define MATRIX_TAB_LINE_HEIGHT(MATRIX)	\
1472      ((MATRIX) && (MATRIX)->rows		\
1473       ? MATRIX_TAB_LINE_ROW (MATRIX)->height	\
1474       : 0)
1475 
1476 /* Return the desired face id for the mode line of a window, depending
1477    on whether the window is selected or not, or if the window is the
1478    scrolling window for the currently active minibuffer window.
1479 
1480    Due to the way display_mode_lines manipulates with the contents of
1481    selected_window, this macro needs three arguments: SELW which is
1482    compared against the current value of selected_window, MBW which is
1483    compared against minibuf_window (if SELW doesn't match), and SCRW
1484    which is compared against minibuf_selected_window (if MBW matches).  */
1485 
1486 #define CURRENT_MODE_LINE_ACTIVE_FACE_ID_3(SELW, MBW, SCRW)    	\
1487      ((!mode_line_in_non_selected_windows			\
1488        || (SELW) == XWINDOW (selected_window)			\
1489        || (minibuf_level > 0					\
1490            && !NILP (minibuf_selected_window)			\
1491            && (MBW) == XWINDOW (minibuf_window)			\
1492            && (SCRW) == XWINDOW (minibuf_selected_window)))	\
1493       ? MODE_LINE_ACTIVE_FACE_ID				\
1494       : MODE_LINE_INACTIVE_FACE_ID)
1495 
1496 
1497 /* Return the desired face id for the mode line of window W.  */
1498 
1499 #define CURRENT_MODE_LINE_ACTIVE_FACE_ID(W)		\
1500 	(CURRENT_MODE_LINE_ACTIVE_FACE_ID_3((W),        \
1501 					    XWINDOW (selected_window), \
1502 					    (W)))
1503 
1504 /* Return the current height of the mode line of window W.  If not known
1505    from W->mode_line_height, look at W's current glyph matrix, or return
1506    a default based on the height of the font of the face `mode-line'.  */
1507 
1508 #define CURRENT_MODE_LINE_HEIGHT(W)					\
1509   ((W)->mode_line_height >= 0						\
1510    ? (W)->mode_line_height						\
1511    : ((W)->mode_line_height						\
1512       = (MATRIX_MODE_LINE_HEIGHT ((W)->current_matrix)			\
1513 	 ? MATRIX_MODE_LINE_HEIGHT ((W)->current_matrix)		\
1514 	 : estimate_mode_line_height					\
1515 	 (XFRAME ((W)->frame), CURRENT_MODE_LINE_ACTIVE_FACE_ID (W)))))
1516 
1517 /* Return the current height of the header line of window W.  If not known
1518    from W->header_line_height, look at W's current glyph matrix, or return
1519    an estimation based on the height of the font of the face `header-line'.  */
1520 
1521 #define CURRENT_HEADER_LINE_HEIGHT(W)				\
1522   ((W)->header_line_height >= 0					\
1523    ? (W)->header_line_height					\
1524    : ((W)->header_line_height					\
1525       = (MATRIX_HEADER_LINE_HEIGHT ((W)->current_matrix)	\
1526 	 ? MATRIX_HEADER_LINE_HEIGHT ((W)->current_matrix)	\
1527 	 : estimate_mode_line_height				\
1528 	     (XFRAME ((W)->frame), HEADER_LINE_FACE_ID))))
1529 
1530 /* Return the current height of the tab line of window W.  If not known
1531    from W->tab_line_height, look at W's current glyph matrix, or return
1532    an estimation based on the height of the font of the face `tab-line'.  */
1533 
1534 #define CURRENT_TAB_LINE_HEIGHT(W)				\
1535   ((W)->tab_line_height >= 0					\
1536    ? (W)->tab_line_height					\
1537    : ((W)->tab_line_height					\
1538       = (MATRIX_TAB_LINE_HEIGHT ((W)->current_matrix)		\
1539 	 ? MATRIX_TAB_LINE_HEIGHT ((W)->current_matrix)		\
1540 	 : estimate_mode_line_height				\
1541 	     (XFRAME ((W)->frame), TAB_LINE_FACE_ID))))
1542 
1543 /* Return the height of the desired mode line of window W.  */
1544 
1545 #define DESIRED_MODE_LINE_HEIGHT(W) \
1546      MATRIX_MODE_LINE_HEIGHT ((W)->desired_matrix)
1547 
1548 /* Return the height of the desired header line of window W.  */
1549 
1550 #define DESIRED_HEADER_LINE_HEIGHT(W) \
1551      MATRIX_HEADER_LINE_HEIGHT ((W)->desired_matrix)
1552 
1553 /* Return the height of the desired tab line of window W.  */
1554 
1555 #define DESIRED_TAB_LINE_HEIGHT(W) \
1556      MATRIX_TAB_LINE_HEIGHT ((W)->desired_matrix)
1557 
1558 /* Return proper value to be used as baseline offset of font that has
1559    ASCENT and DESCENT to draw characters by the font at the vertical
1560    center of the line of frame F.
1561 
1562    Here, our task is to find the value of BOFF in the following figure;
1563 
1564 	-------------------------+-----------+-
1565 	 -+-+---------+-+        |           |
1566 	  | |         | |        |           |
1567 	  | |         | |        F_ASCENT    F_HEIGHT
1568 	  | |         | ASCENT   |           |
1569      HEIGHT |         | |        |           |
1570 	  | |         |-|-+------+-----------|------- baseline
1571 	  | |         | | BOFF   |           |
1572 	  | |---------|-+-+      |           |
1573 	  | |         | DESCENT  |           |
1574 	 -+-+---------+-+        F_DESCENT   |
1575 	-------------------------+-----------+-
1576 
1577 	-BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1578 	BOFF = DESCENT +  (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1579 	DESCENT = FONT->descent
1580 	HEIGHT = FONT_HEIGHT (FONT)
1581 	F_DESCENT = (FRAME_FONT (F)->descent
1582 		     - F->terminal->output_data.x->baseline_offset)
1583 	F_HEIGHT = FRAME_LINE_HEIGHT (F)
1584 */
1585 
1586 #define VCENTER_BASELINE_OFFSET(FONT, F)			\
1587   (FONT_DESCENT (FONT)						\
1588    + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT))		\
1589       + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2	\
1590    - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F)))
1591 
1592 /* A heuristic test for fonts that claim they need a preposterously
1593    large vertical space.  The heuristics is in the factor of 3.  We
1594    ignore the ascent and descent values reported by such fonts, and
1595    instead go by the values reported for individual glyphs.  */
1596 #define FONT_TOO_HIGH(ft)						\
1597   ((ft)->pixel_size > 0 && (ft)->ascent + (ft)->descent > 3*(ft)->pixel_size)
1598 
1599 
1600 /***********************************************************************
1601 				Faces
1602  ***********************************************************************/
1603 
1604 /* Indices of face attributes in Lisp face vectors.  Slot zero is the
1605    symbol `face'.  */
1606 
1607 enum lface_attribute_index
1608 {
1609   LFACE_FAMILY_INDEX = 1,
1610   LFACE_FOUNDRY_INDEX,
1611   LFACE_SWIDTH_INDEX,
1612   LFACE_HEIGHT_INDEX,
1613   LFACE_WEIGHT_INDEX,
1614   LFACE_SLANT_INDEX,
1615   LFACE_UNDERLINE_INDEX,
1616   LFACE_INVERSE_INDEX,
1617   LFACE_FOREGROUND_INDEX,
1618   LFACE_BACKGROUND_INDEX,
1619   LFACE_STIPPLE_INDEX,
1620   LFACE_OVERLINE_INDEX,
1621   LFACE_STRIKE_THROUGH_INDEX,
1622   LFACE_BOX_INDEX,
1623   LFACE_FONT_INDEX,
1624   LFACE_INHERIT_INDEX,
1625   LFACE_FONTSET_INDEX,
1626   LFACE_DISTANT_FOREGROUND_INDEX,
1627   LFACE_EXTEND_INDEX,
1628   LFACE_VECTOR_SIZE
1629 };
1630 
1631 
1632 /* Box types of faces.  */
1633 
1634 enum face_box_type
1635 {
1636   /* No box around text.  */
1637   FACE_NO_BOX,
1638 
1639   /* Simple box of specified width and color.  Default width is 1, and
1640      default color is the foreground color of the face.  */
1641   FACE_SIMPLE_BOX,
1642 
1643   /* Boxes with 3D shadows.  Color equals the background color of the
1644      face.  Width is specified.  */
1645   FACE_RAISED_BOX,
1646   FACE_SUNKEN_BOX
1647 };
1648 
1649 /* Underline type. */
1650 
1651 enum face_underline_type
1652 {
1653   FACE_NO_UNDERLINE = 0,
1654   FACE_UNDER_LINE,
1655   FACE_UNDER_WAVE
1656 };
1657 
1658 /* Structure describing a realized face.
1659 
1660    For each Lisp face, 0..N realized faces can exist for different
1661    frames and different charsets.  Realized faces are built from Lisp
1662    faces and text properties/overlays by merging faces and adding
1663    unspecified attributes from the `default' face.  */
1664 
1665 struct face
1666 {
1667   /* The Lisp face attributes this face realizes.  All attributes
1668      in this vector are non-nil.  */
1669   Lisp_Object lface[LFACE_VECTOR_SIZE];
1670 
1671   /* The id of this face.  The id equals the index of this face in the
1672      vector faces_by_id of its face cache.  */
1673   int id;
1674 
1675 #ifdef HAVE_WINDOW_SYSTEM
1676 
1677   /* If non-zero, this is a GC that we can use without modification for
1678      drawing the characters in this face.  */
1679 # ifdef HAVE_X_WINDOWS
1680   GC gc;
1681 # else
1682   Emacs_GC *gc;
1683 # endif
1684   /* Background stipple or bitmap used for this face.  This is
1685      an id as returned from load_pixmap.  */
1686   ptrdiff_t stipple;
1687 
1688 #endif /* not HAVE_WINDOW_SYSTEM */
1689 
1690   /* Pixel value of foreground color for X frames.  Color index
1691      for tty frames.  */
1692   unsigned long foreground;
1693 
1694   /* Pixel value or color index of background color.  */
1695   unsigned long background;
1696 
1697   /* Pixel value or color index of underline, overlined,
1698      strike-through, or box color.  */
1699   unsigned long underline_color;
1700   unsigned long overline_color;
1701   unsigned long strike_through_color;
1702   unsigned long box_color;
1703 
1704   struct font *font;
1705 
1706   /* Fontset ID if for this face's fontset.  Non-ASCII faces derived
1707      from the same ASCII face have the same fontset.  */
1708   int fontset;
1709 
1710   /* Non-zero means characters in this face have a box of that
1711      thickness around them. Vertical (left and right) and horizontal
1712      (top and bottom) borders size can be set separatedly using an
1713      associated list of two ints in the form
1714      (vertical_size . horizontal_size). In case one of the value is
1715      negative, its absolute value indicates the thickness, and the
1716      borders of box are drawn inside of the character glyphs' area
1717      potentially over the glyph itself but the glyph drawing size is
1718      not increase. If a (signed) int N is use instead of a list, it
1719      is the same as setting ( abs(N) . N ) values. */
1720   int box_vertical_line_width;
1721   int box_horizontal_line_width;
1722 
1723   /* Type of box drawn.  A value of FACE_NO_BOX means no box is drawn
1724      around text in this face.  A value of FACE_SIMPLE_BOX means a box
1725      of width box_line_width is drawn in color box_color.  A value of
1726      FACE_RAISED_BOX or FACE_SUNKEN_BOX means a 3D box is drawn with
1727      shadow colors derived from the background color of the face.  */
1728   ENUM_BF (face_box_type) box : 2;
1729 
1730   /* Style of underlining. */
1731   ENUM_BF (face_underline_type) underline : 2;
1732 
1733   /* If `box' above specifies a 3D type, true means use box_color for
1734      drawing shadows.  */
1735   bool_bf use_box_color_for_shadows_p : 1;
1736 
1737   /* Non-zero if text in this face should be underlined, overlined,
1738      strike-through or have a box drawn around it.  */
1739   bool_bf overline_p : 1;
1740   bool_bf strike_through_p : 1;
1741 
1742   /* True means that the colors specified for this face could not be
1743      loaded, and were replaced by default colors, so they shouldn't be
1744      freed.  */
1745   bool_bf foreground_defaulted_p : 1;
1746   bool_bf background_defaulted_p : 1;
1747 
1748   /* True means that either no color is specified for the corresponding
1749      attribute or that the specified color couldn't be loaded.
1750      Use the foreground color when drawing in that case. */
1751   bool_bf underline_defaulted_p : 1;
1752   bool_bf overline_color_defaulted_p : 1;
1753   bool_bf strike_through_color_defaulted_p : 1;
1754   bool_bf box_color_defaulted_p : 1;
1755 
1756   /* TTY appearances.  Colors are found in `lface' with empty color
1757      string meaning the default color of the TTY.  */
1758   bool_bf tty_bold_p : 1;
1759   bool_bf tty_italic_p : 1;
1760   bool_bf tty_underline_p : 1;
1761   bool_bf tty_reverse_p : 1;
1762   bool_bf tty_strike_through_p : 1;
1763 
1764   /* True means that colors of this face may not be freed because they
1765      have been copied bitwise from a base face (see
1766      realize_gui_face).  */
1767   bool_bf colors_copied_bitwise_p : 1;
1768 
1769   /* If non-zero, use overstrike (to simulate bold-face).  */
1770   bool_bf overstrike : 1;
1771 
1772 /* NOTE: this is not used yet, but eventually this impl should be done
1773          similarly to overstrike */
1774 #ifdef HAVE_NS
1775   /* If non-zero, use geometric rotation (to simulate italic).  */
1776   bool_bf synth_ital : 1;
1777 #endif
1778 
1779   /* The hash value of this face.  */
1780   uintptr_t hash;
1781 
1782   /* Next and previous face in hash collision list of face cache.  */
1783   struct face *next, *prev;
1784 
1785   /* If this face is an ASCII face, this points to this face itself.
1786      Otherwise, this points to an ASCII face that has the same
1787      attributes except the font.  */
1788   struct face *ascii_face;
1789 
1790 #if defined HAVE_XFT || defined HAVE_FREETYPE
1791 /* Extra member that a font-driver uses privately.  */
1792   void *extra;
1793 #endif
1794 };
1795 
1796 
1797 /* Color index indicating that face uses a terminal's default color.  */
1798 
1799 #define FACE_TTY_DEFAULT_COLOR ((unsigned long) -1)
1800 
1801 /* Color index indicating that face uses an unknown foreground color.  */
1802 
1803 #define FACE_TTY_DEFAULT_FG_COLOR ((unsigned long) -2)
1804 
1805 /* Color index indicating that face uses an unknown background color.  */
1806 
1807 #define FACE_TTY_DEFAULT_BG_COLOR ((unsigned long) -3)
1808 
1809 /* True if COLOR is a specified (i.e., nondefault) foreground or
1810    background color for a tty face.  */
1811 
1812 INLINE bool
face_tty_specified_color(unsigned long color)1813 face_tty_specified_color (unsigned long color)
1814 {
1815   return color < FACE_TTY_DEFAULT_BG_COLOR;
1816 }
1817 
1818 /* Non-zero if FACE was realized for unibyte use.  */
1819 
1820 #define FACE_UNIBYTE_P(FACE) ((FACE)->charset < 0)
1821 
1822 
1823 /* IDs of important faces known by the C face code.  These are the IDs
1824    of the faces for CHARSET_ASCII.  */
1825 
1826 enum face_id
1827 {
1828   DEFAULT_FACE_ID,
1829   MODE_LINE_ACTIVE_FACE_ID,
1830   MODE_LINE_INACTIVE_FACE_ID,
1831   TOOL_BAR_FACE_ID,
1832   FRINGE_FACE_ID,
1833   HEADER_LINE_FACE_ID,
1834   SCROLL_BAR_FACE_ID,
1835   BORDER_FACE_ID,
1836   CURSOR_FACE_ID,
1837   MOUSE_FACE_ID,
1838   MENU_FACE_ID,
1839   VERTICAL_BORDER_FACE_ID,
1840   WINDOW_DIVIDER_FACE_ID,
1841   WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID,
1842   WINDOW_DIVIDER_LAST_PIXEL_FACE_ID,
1843   INTERNAL_BORDER_FACE_ID,
1844   CHILD_FRAME_BORDER_FACE_ID,
1845   TAB_BAR_FACE_ID,
1846   TAB_LINE_FACE_ID,
1847   MODE_LINE_FACE_ID,
1848   BASIC_FACE_ID_SENTINEL
1849 };
1850 
1851 #define MAX_FACE_ID  ((1 << FACE_ID_BITS) - 1)
1852 
1853 /* A cache of realized faces.  Each frame has its own cache because
1854    Emacs allows different frame-local face definitions.  */
1855 
1856 struct face_cache
1857 {
1858   /* Hash table of cached realized faces.  */
1859   struct face **buckets;
1860 
1861   /* Back-pointer to the frame this cache belongs to.  */
1862   struct frame *f;
1863 
1864   /* A vector of faces so that faces can be referenced by an ID.  */
1865   struct face **faces_by_id;
1866 
1867   /* The allocated size, and number of used slots of faces_by_id.  */
1868   ptrdiff_t size;
1869   int used;
1870 
1871   /* Flag indicating that attributes of the `menu' face have been
1872      changed.  */
1873   bool_bf menu_face_changed_p : 1;
1874 };
1875 
1876 #define FACE_EXTENSIBLE_P(F)			\
1877   (!NILP (F->lface[LFACE_EXTEND_INDEX]))
1878 
1879 /* True if FACE is suitable for displaying ASCII characters.  */
1880 INLINE bool
FACE_SUITABLE_FOR_ASCII_CHAR_P(struct face * face)1881 FACE_SUITABLE_FOR_ASCII_CHAR_P (struct face *face)
1882 {
1883 #ifdef HAVE_WINDOW_SYSTEM
1884   return face == face->ascii_face;
1885 #else
1886   return true;
1887 #endif
1888 }
1889 
1890 /* Return the id of the realized face on frame F that is like the face
1891    FACE, but is suitable for displaying character CHARACTER at buffer or
1892    string position POS.  OBJECT is the string object, or nil for
1893    buffer.  This macro is only meaningful for multibyte character
1894    CHAR.  */
1895 INLINE int
FACE_FOR_CHAR(struct frame * f,struct face * face,int character,ptrdiff_t pos,Lisp_Object object)1896 FACE_FOR_CHAR (struct frame *f, struct face *face, int character,
1897 	       ptrdiff_t pos, Lisp_Object object)
1898 {
1899 #ifdef HAVE_WINDOW_SYSTEM
1900   return face_for_char (f, face, character, pos, object);
1901 #else
1902   return face->id;
1903 #endif
1904 }
1905 
1906 /* Return true if G contains a valid character code.  */
1907 INLINE bool
GLYPH_CHAR_VALID_P(GLYPH g)1908 GLYPH_CHAR_VALID_P (GLYPH g)
1909 {
1910   return CHAR_VALID_P (GLYPH_CHAR (g));
1911 }
1912 
1913 /* The glyph code from a display vector may either be an integer which
1914    encodes a char code in the lower CHARACTERBITS bits and a (very small)
1915    face-id in the upper bits, or it may be a cons (CHAR . FACE-ID).  */
1916 
1917 INLINE bool
GLYPH_CODE_P(Lisp_Object gc)1918 GLYPH_CODE_P (Lisp_Object gc)
1919 {
1920   return (CONSP (gc)
1921 	  ? (CHARACTERP (XCAR (gc))
1922 	     && RANGED_FIXNUMP (0, XCDR (gc), MAX_FACE_ID))
1923 	  : (RANGED_FIXNUMP
1924 	     (0, gc,
1925 	      (MAX_FACE_ID < TYPE_MAXIMUM (EMACS_INT) >> CHARACTERBITS
1926 	       ? ((EMACS_INT) MAX_FACE_ID << CHARACTERBITS) | MAX_CHAR
1927 	       : TYPE_MAXIMUM (EMACS_INT)))));
1928 }
1929 
1930 /* True means face attributes have been changed since the last
1931    redisplay.  Used in redisplay_internal.  */
1932 
1933 extern bool face_change;
1934 
1935 /* For reordering of bidirectional text.  */
1936 
1937 /* UAX#9's max_depth value.  */
1938 #define BIDI_MAXDEPTH 125
1939 
1940 /* Data type for describing the bidirectional character types.  The
1941    first 7 must be at the beginning, because they are the only values
1942    valid in the `bidi_type' member of `struct glyph'; we only reserve
1943    3 bits for it, so we cannot use there values larger than 7.
1944 
1945    The order of members must be in sync with the 8th element of the
1946    member of unidata-prop-alist (in admin/unidata/unidata-gen.el) for
1947    Unicode character property `bidi-class'.  */
1948 typedef enum {
1949   UNKNOWN_BT = 0,
1950   STRONG_L,	/* strong left-to-right */
1951   STRONG_R,	/* strong right-to-left */
1952   WEAK_EN,	/* european number */
1953   WEAK_AN,	/* arabic number */
1954   WEAK_BN,	/* boundary neutral */
1955   NEUTRAL_B,	/* paragraph separator */
1956   STRONG_AL,	/* arabic right-to-left letter */
1957   LRE,		/* left-to-right embedding */
1958   LRO,		/* left-to-right override */
1959   RLE,		/* right-to-left embedding */
1960   RLO,		/* right-to-left override */
1961   PDF,		/* pop directional format */
1962   LRI,		/* left-to-right isolate */
1963   RLI,		/* right-to-left isolate */
1964   FSI,		/* first strong isolate */
1965   PDI,		/* pop directional isolate */
1966   WEAK_ES,	/* european number separator */
1967   WEAK_ET,	/* european number terminator */
1968   WEAK_CS,	/* common separator */
1969   WEAK_NSM,	/* non-spacing mark */
1970   NEUTRAL_S,	/* segment separator */
1971   NEUTRAL_WS,	/* whitespace */
1972   NEUTRAL_ON	/* other neutrals */
1973 } bidi_type_t;
1974 
1975 /* Data type for describing the Bidi Paired Bracket Type of a character.
1976 
1977    The order of members must be in sync with the 8th element of the
1978    member of unidata-prop-alist (in admin/unidata/unidata-gen.el) for
1979    Unicode character property `bracket-type'.  */
1980 typedef enum {
1981   BIDI_BRACKET_NONE = 1,
1982   BIDI_BRACKET_OPEN,
1983   BIDI_BRACKET_CLOSE
1984 } bidi_bracket_type_t;
1985 
1986 /* The basic directionality data type.  */
1987 typedef enum { NEUTRAL_DIR = 0, L2R, R2L } bidi_dir_t;
1988 
1989 /* Data type for storing information about characters we need to
1990    remember.  */
1991 struct bidi_saved_info {
1992   ptrdiff_t charpos;		/* character's buffer position */
1993   bidi_type_t type;		/* character's resolved bidi type */
1994   bidi_type_t orig_type;	/* bidi type as we found it in the buffer */
1995 };
1996 
1997 /* Data type for keeping track of information about saved embedding
1998    levels, override status, isolate status, and isolating sequence
1999    runs.  This should be as tightly packed as possible, because there
2000    are 127 such entries in each iterator state, and so the size of
2001    cache is directly affected by the size of this struct.  */
2002 struct bidi_stack {
2003   ptrdiff_t next_for_neutral_pos;
2004   unsigned next_for_neutral_type : 3;
2005   unsigned last_strong_type : 3;
2006   unsigned prev_for_neutral_type : 3;
2007   unsigned char level;
2008   unsigned char flags;		/* sos, override, isolate_status */
2009 };
2010 
2011 /* Data type for storing information about a string being iterated on.  */
2012 struct bidi_string_data {
2013   Lisp_Object lstring;		/* Lisp string to reorder, or nil */
2014   const unsigned char *s;	/* string data, or NULL if reordering buffer */
2015   ptrdiff_t schars;		/* the number of characters in the string,
2016 				   excluding the terminating null */
2017   ptrdiff_t bufpos;		/* buffer position of lstring, or 0 if N/A */
2018   bool_bf from_disp_str : 1;	/* True means the string comes from a
2019 				   display property */
2020   bool_bf unibyte : 1;		/* True means the string is unibyte */
2021 };
2022 
2023 /* Data type for reordering bidirectional text.  */
2024 struct bidi_it {
2025   ptrdiff_t bytepos;		/* iterator's position in buffer/string */
2026   ptrdiff_t charpos;
2027   int ch;			/* character at that position, or u+FFFC
2028 				   ("object replacement character") for a run
2029 				   of characters covered by a display string */
2030   ptrdiff_t nchars;		/* its "length", usually 1; it's > 1 for a run
2031 				   of characters covered by a display string */
2032   ptrdiff_t ch_len;		/* its length in bytes */
2033   bidi_type_t type;		/* final bidi type of this character, after
2034 				   resolving weak and neutral types */
2035   bidi_type_t type_after_wn;	/* bidi type after overrides and Wn */
2036   bidi_type_t orig_type;	/* original bidi type, as found in the buffer */
2037   signed char resolved_level;	/* final resolved level of this character */
2038   signed char isolate_level;	/* count of isolate initiators unmatched by PDI */
2039   ptrdiff_t invalid_levels;	/* how many PDFs to ignore */
2040   ptrdiff_t invalid_isolates;	/* how many PDIs to ignore */
2041   struct bidi_saved_info prev;	/* info about previous character */
2042   struct bidi_saved_info last_strong; /* last-seen strong directional char */
2043   struct bidi_saved_info next_for_neutral; /* surrounding characters for... */
2044   struct bidi_saved_info prev_for_neutral; /* ...resolving neutrals */
2045   struct bidi_saved_info next_for_ws; /* character after sequence of ws */
2046   ptrdiff_t bracket_pairing_pos;	/* position of pairing bracket */
2047   bidi_type_t bracket_enclosed_type;	/* type for bracket resolution */
2048   ptrdiff_t next_en_pos;	/* pos. of next char for determining ET type */
2049   bidi_type_t next_en_type;	/* type of char at next_en_pos */
2050   bidi_dir_t sos;		/* direction of start-of-sequence in effect */
2051   int scan_dir;			/* direction of text scan, 1: forw, -1: back */
2052   ptrdiff_t disp_pos;		/* position of display string after ch */
2053   int disp_prop;		/* if non-zero, there really is a
2054 				   `display' property/string at disp_pos;
2055 				   if 2, the property is a `space' spec */
2056   int stack_idx;		/* index of current data on the stack */
2057   /* Note: Everything from here on is not copied/saved when the bidi
2058      iterator state is saved, pushed, or popped.  So only put here
2059      stuff that is not part of the bidi iterator's state!  */
2060   struct bidi_stack level_stack[BIDI_MAXDEPTH+2+1]; /* directional status stack */
2061   struct bidi_string_data string;	/* string to reorder */
2062   struct window *w;		/* the window being displayed */
2063   bidi_dir_t paragraph_dir;	/* current paragraph direction */
2064   ptrdiff_t separator_limit;	/* where paragraph separator should end */
2065   bool_bf first_elt : 1;	/* if true, examine current char first */
2066   bool_bf new_paragraph : 1;	/* if true, we expect a new paragraph */
2067   bool_bf frame_window_p : 1;	/* true if displaying on a GUI frame */
2068 };
2069 
2070 /* Value is non-zero when the bidi iterator is at base paragraph
2071    embedding level.  */
2072 #define BIDI_AT_BASE_LEVEL(BIDI_IT) \
2073   ((BIDI_IT).resolved_level == (BIDI_IT).level_stack[0].level)
2074 
2075 
2076 /***********************************************************************
2077 			       Fringes
2078  ***********************************************************************/
2079 
2080 /* Structure used to describe where and how to draw a fringe bitmap.
2081    WHICH is the fringe bitmap to draw.  WD and H is the (adjusted)
2082    width and height of the bitmap, DH is the height adjustment (if
2083    bitmap is periodic).  X and Y are frame coordinates of the area to
2084    display the bitmap, DY is relative offset of the bitmap into that
2085    area.  BX, NX, BY, NY specifies the area to clear if the bitmap
2086    does not fill the entire area.  FACE is the fringe face.  */
2087 
2088 struct draw_fringe_bitmap_params
2089 {
2090   int which;  /* enum fringe_bitmap_type */
2091   unsigned short *bits;
2092   int wd, h, dh;
2093   int x, y;
2094   int bx, nx, by, ny;
2095   bool_bf cursor_p : 1;
2096   bool_bf overlay_p : 1;
2097   struct face *face;
2098 };
2099 
2100 #define MAX_FRINGE_BITMAPS (1<<FRINGE_ID_BITS)
2101 
2102 
2103 /***********************************************************************
2104 			    Display Iterator
2105  ***********************************************************************/
2106 
2107 /* Iteration over things to display in current_buffer or in a string.
2108 
2109    The iterator handles:
2110 
2111    1. Overlay strings (after-string, before-string).
2112    2. Face properties.
2113    3. Invisible text properties.
2114    4. Selective display.
2115    5. Translation of characters via display tables.
2116    6. Translation of control characters to the forms `\003' or `^C'.
2117    7. `glyph' and `space-width' properties.
2118 
2119    Iterators are initialized by calling init_iterator or one of the
2120    equivalent functions below.  A call to get_next_display_element
2121    loads the iterator structure with information about what next to
2122    display.  A call to set_iterator_to_next increments the iterator's
2123    position.
2124 
2125    Characters from overlay strings, display table entries or control
2126    character translations are returned one at a time.  For example, if
2127    we have a text of `a\x01' where `a' has a display table definition
2128    of `cd' and the control character is displayed with a leading
2129    arrow, then the iterator will return:
2130 
2131    Call		Return  Source		Call next
2132    -----------------------------------------------------------------
2133    next		c	display table	move
2134    next		d	display table	move
2135    next		^	control char	move
2136    next		A	control char	move
2137 
2138    The same mechanism is also used to return characters for ellipses
2139    displayed at the end of invisible text.
2140 
2141    CAVEAT: Under some circumstances, move_.* functions can be called
2142    asynchronously, e.g. when computing a buffer position from an x and
2143    y pixel position.  This means that these functions and functions
2144    called from them SHOULD NOT USE xmalloc and alike.  See also the
2145    comment at the start of xdisp.c.  */
2146 
2147 /* Enumeration describing what kind of display element an iterator is
2148    loaded with after a call to get_next_display_element.  */
2149 
2150 enum display_element_type
2151 {
2152   /* A normal character.  */
2153   IT_CHARACTER,
2154 
2155   /* A composition (static and automatic).  */
2156   IT_COMPOSITION,
2157 
2158   /* A glyphless character (e.g. ZWNJ, LRE).  */
2159   IT_GLYPHLESS,
2160 
2161   /* An image.  */
2162   IT_IMAGE,
2163 
2164   /* A flexible width and height space.  */
2165   IT_STRETCH,
2166 
2167   /* End of buffer or string.  */
2168   IT_EOB,
2169 
2170   /* Truncation glyphs.  Never returned by get_next_display_element.
2171      Used to get display information about truncation glyphs via
2172      produce_glyphs.  */
2173   IT_TRUNCATION,
2174 
2175   /* Continuation glyphs.  See the comment for IT_TRUNCATION.  */
2176   IT_CONTINUATION,
2177 
2178   /* Xwidget.  */
2179   IT_XWIDGET
2180 };
2181 
2182 
2183 /* An enumerator for each text property that has a meaning for display
2184    purposes.  */
2185 
2186 enum prop_idx
2187 {
2188   FONTIFIED_PROP_IDX,
2189   FACE_PROP_IDX,
2190   INVISIBLE_PROP_IDX,
2191   DISPLAY_PROP_IDX,
2192   COMPOSITION_PROP_IDX,
2193 
2194   /* Not a property.  Used to indicate changes in overlays.  */
2195   OVERLAY_PROP_IDX,
2196 
2197   /* Sentinel.  */
2198   LAST_PROP_IDX
2199 };
2200 
2201 /* An enumerator for the method of wrapping long lines.  */
2202 
2203 enum line_wrap_method
2204 {
2205   TRUNCATE,
2206   WORD_WRAP,
2207   WINDOW_WRAP
2208 };
2209 
2210 /* An enumerator for the method of displaying glyphless characters.  */
2211 
2212 enum glyphless_display_method
2213   {
2214     /* Display a thin (1-pixel width) space.  On a TTY, display a
2215        1-character width space.  */
2216     GLYPHLESS_DISPLAY_THIN_SPACE,
2217     /* Display an empty box of proper width.  */
2218     GLYPHLESS_DISPLAY_EMPTY_BOX,
2219     /* Display an acronym string in a box.  */
2220     GLYPHLESS_DISPLAY_ACRONYM,
2221     /* Display the hexadecimal code of the character in a box.  */
2222     GLYPHLESS_DISPLAY_HEX_CODE
2223   };
2224 
2225 struct it_slice
2226 {
2227   Lisp_Object x;
2228   Lisp_Object y;
2229   Lisp_Object width;
2230   Lisp_Object height;
2231 };
2232 
2233 /* Input sources for fetching characters or data to display.
2234    The input source is found in the `method' field.  */
2235 
2236 enum it_method {
2237   GET_FROM_BUFFER = 0,
2238   GET_FROM_DISPLAY_VECTOR,
2239   GET_FROM_STRING,
2240   GET_FROM_C_STRING,
2241   GET_FROM_IMAGE,
2242   GET_FROM_STRETCH,
2243   GET_FROM_XWIDGET,
2244   NUM_IT_METHODS
2245 };
2246 
2247 /* FIXME: What is this?  Why 5?  */
2248 #define IT_STACK_SIZE 5
2249 
2250 /* Iterator for composition (both for static and automatic).  */
2251 struct composition_it
2252 {
2253   /* Next position at which to check the composition.  */
2254   ptrdiff_t stop_pos;
2255   /* ID number of the composition or glyph-string.  If negative, we
2256      are not iterating over a composition now.  */
2257   ptrdiff_t id;
2258   /* If non-negative, character that triggers the automatic
2259      composition at `stop_pos', and this is an automatic composition.
2260      If negative, this is a static composition.  This is set to -2
2261      temporarily if searching of composition reach a limit or a
2262      newline.  */
2263   int ch;
2264   /* If this is an automatic composition, index of a rule for making
2265      the automatic composition.  Provided that ELT is an element of
2266      Vcomposition_function_table for CH, (nth ELT RULE_IDX) is the
2267      rule for the composition.  */
2268   EMACS_INT rule_idx;
2269   /* If this is an automatic composition, how many characters to look
2270      back from the position where a character triggering the
2271      composition exists.  */
2272   ptrdiff_t lookback;
2273   /* If non-negative, number of glyphs of the glyph-string.  */
2274   int nglyphs;
2275   /* True iff the composition is created while buffer is scanned in
2276      reverse order, and thus the grapheme clusters must be rendered
2277      from the last to the first.  */
2278   bool reversed_p;
2279 
2280   /** The following members contain information about the current
2281       grapheme cluster.  */
2282   /* Position of the first character of the current grapheme cluster.  */
2283   ptrdiff_t charpos;
2284   /* Number of characters and bytes of the current grapheme cluster.  */
2285   int nchars, nbytes;
2286   /* Indices of the glyphs for the current grapheme cluster.  */
2287   int from, to;
2288   /* Width of the current grapheme cluster in units of columns it will
2289      occupy on display; see CHARACTER_WIDTH.  */
2290   int width;
2291 };
2292 
2293 struct it
2294 {
2295   /* The window in which we iterate over current_buffer (or a string).  */
2296   Lisp_Object window;
2297   struct window *w;
2298 
2299   /* The window's frame.  */
2300   struct frame *f;
2301 
2302   /* Method to use to load this structure with the next display element.  */
2303   enum it_method method;
2304 
2305   /* The next position at which to check for face changes, invisible
2306      text, overlay strings, end of text etc., which see.  */
2307   ptrdiff_t stop_charpos;
2308 
2309   /* Previous stop position, i.e. the last one before the current
2310      iterator position in `current'.  */
2311   ptrdiff_t prev_stop;
2312 
2313   /* Last stop position iterated across whose bidi embedding level is
2314      equal to the current paragraph's base embedding level.  */
2315   ptrdiff_t base_level_stop;
2316 
2317   /* Maximum string or buffer position + 1.  ZV when iterating over
2318      current_buffer.  When iterating over a string in display_string,
2319      this can be smaller or greater than the number of string
2320      characters, depending on the values of PRECISION and FIELD_WIDTH
2321      with which display_string was called.  */
2322   ptrdiff_t end_charpos;
2323 
2324   /* C string to iterate over.  Non-null means get characters from
2325      this string, otherwise characters are read from current_buffer
2326      or it->string.  */
2327   const unsigned char *s;
2328 
2329   /* Number of characters in the string (s, or it->string) we iterate
2330      over.  Used only in display_string and its subroutines; never
2331      used for overlay strings and strings from display properties.  */
2332   ptrdiff_t string_nchars;
2333 
2334   /* Position at which redisplay end trigger functions should be run.  */
2335   ptrdiff_t redisplay_end_trigger_charpos;
2336 
2337   /* True means multibyte characters are enabled.  */
2338   bool_bf multibyte_p : 1;
2339 
2340   /* True means window has a tab line at its top.  */
2341   bool_bf tab_line_p : 1;
2342 
2343   /* True means window has a mode line at its top.  */
2344   bool_bf header_line_p : 1;
2345 
2346   /* True means `string' is the value of a `display' property.
2347      Don't handle some `display' properties in these strings.  */
2348   bool_bf string_from_display_prop_p : 1;
2349 
2350   /* True means `string' comes from a `line-prefix' or `wrap-prefix'
2351      property.  */
2352   bool_bf string_from_prefix_prop_p : 1;
2353 
2354   /* True means we are iterating an object that came from a value of a
2355      `display' property.  */
2356   bool_bf from_disp_prop_p : 1;
2357 
2358   /* When METHOD == next_element_from_display_vector,
2359      this is true if we're doing an ellipsis.  Otherwise meaningless.  */
2360   bool_bf ellipsis_p : 1;
2361 
2362   /* True means cursor shouldn't be displayed here.  */
2363   bool_bf avoid_cursor_p : 1;
2364 
2365   /* Display table in effect or null for none.  */
2366   struct Lisp_Char_Table *dp;
2367 
2368   /* Current display table vector to return characters from and its
2369      end.  dpvec null means we are not returning characters from a
2370      display table entry; current.dpvec_index gives the current index
2371      into dpvec.  This same mechanism is also used to return
2372      characters from translated control characters, i.e. `\003' or
2373      `^C'.  */
2374   Lisp_Object *dpvec, *dpend;
2375 
2376   /* Length in bytes of the char that filled dpvec.  A value of zero
2377      means that no such character is involved.  A negative value means
2378      the rest of the line from the current iterator position onwards
2379      is hidden by selective display or ellipsis.  */
2380   int dpvec_char_len;
2381 
2382   /* Face id to use for all characters in display vector.  -1 if unused. */
2383   int dpvec_face_id;
2384 
2385   /* Face id of the iterator saved in case a glyph from dpvec contains
2386      a face.  The face is restored when all glyphs from dpvec have
2387      been delivered.  */
2388   int saved_face_id;
2389 
2390   /* Vector of glyphs for control character translation.  The pointer
2391      dpvec is set to ctl_chars when a control character is translated.
2392      This vector is also used for incomplete multibyte character
2393      translation (e.g \222\244).  Such a character is at most 4 bytes,
2394      thus we need at most 16 bytes here.  */
2395   Lisp_Object ctl_chars[16];
2396 
2397   /* Initial buffer or string position of the iterator, before skipping
2398      over display properties and invisible text.  */
2399   struct display_pos start;
2400 
2401   /* Current buffer or string position of the iterator, including
2402      position in overlay strings etc.  */
2403   struct display_pos current;
2404 
2405   /* Total number of overlay strings to process.  This can be >
2406      OVERLAY_STRING_CHUNK_SIZE.  Value is dependable only when
2407      current.overlay_string_index >= 0.  Use the latter to determine
2408      whether an overlay string is being iterated over, because
2409      n_overlay_strings can be positive even when we are not rendering
2410      an overlay string.  */
2411   ptrdiff_t n_overlay_strings;
2412 
2413   /* The charpos where n_overlay_strings was calculated.  This should
2414      be set at the same time as n_overlay_strings.  It is needed
2415      because we show before-strings at the start of invisible text;
2416      see handle_invisible_prop in xdisp.c.  */
2417   ptrdiff_t overlay_strings_charpos;
2418 
2419   /* Vector of overlays to process.  Overlay strings are processed
2420      OVERLAY_STRING_CHUNK_SIZE at a time.  */
2421 #define OVERLAY_STRING_CHUNK_SIZE 16
2422   Lisp_Object overlay_strings[OVERLAY_STRING_CHUNK_SIZE];
2423 
2424   /* For each overlay string, the overlay it came from.  */
2425   Lisp_Object string_overlays[OVERLAY_STRING_CHUNK_SIZE];
2426 
2427   /* If non-nil, a Lisp string being processed.  If
2428      current.overlay_string_index >= 0, this is an overlay string from
2429      pos.  Use STRINGP (it.string) to test whether we are rendering a
2430      string or something else; do NOT use BUFFERP (it.object).  */
2431   Lisp_Object string;
2432 
2433   /* If non-nil, we are processing a string that came
2434      from a `display' property given by an overlay.  */
2435   Lisp_Object from_overlay;
2436 
2437   /* Stack of saved values.  New entries are pushed when we begin to
2438      process an overlay string or a string from a `glyph' property.
2439      Entries are popped when we return to deliver display elements
2440      from what we previously had.  */
2441   struct iterator_stack_entry
2442   {
2443     Lisp_Object string;
2444     int string_nchars;
2445     ptrdiff_t end_charpos;
2446     ptrdiff_t stop_charpos;
2447     ptrdiff_t prev_stop;
2448     ptrdiff_t base_level_stop;
2449     struct composition_it cmp_it;
2450     int face_id;
2451 
2452     /* Save values specific to a given method.  */
2453     union {
2454       /* method == GET_FROM_IMAGE */
2455       struct {
2456 	Lisp_Object object;
2457 	struct it_slice slice;
2458 	ptrdiff_t image_id;
2459       } image;
2460       /* method == GET_FROM_STRETCH */
2461       struct {
2462 	Lisp_Object object;
2463       } stretch;
2464       /* method == GET_FROM_XWIDGET */
2465       struct {
2466 	Lisp_Object object;
2467       } xwidget;
2468     } u;
2469 
2470     /* Current text and display positions.  */
2471     struct text_pos position;
2472     struct display_pos current;
2473     Lisp_Object from_overlay;
2474     enum glyph_row_area area;
2475     enum it_method method;
2476     bidi_dir_t paragraph_embedding;
2477     bool_bf multibyte_p : 1;
2478     bool_bf string_from_display_prop_p : 1;
2479     bool_bf string_from_prefix_prop_p : 1;
2480     bool_bf display_ellipsis_p : 1;
2481     bool_bf avoid_cursor_p : 1;
2482     bool_bf bidi_p : 1;
2483     bool_bf from_disp_prop_p : 1;
2484     enum line_wrap_method line_wrap;
2485 
2486     /* Properties from display property that are reset by another display
2487        property.  */
2488     short voffset;
2489     Lisp_Object space_width;
2490     Lisp_Object font_height;
2491   }
2492   stack[IT_STACK_SIZE];
2493 
2494   /* Stack pointer.  */
2495   int sp;
2496 
2497   /* -1 means selective display hides everything between a \r and the
2498      next newline; > 0 means hide lines indented more than that value.  */
2499   ptrdiff_t selective;
2500 
2501   /* An enumeration describing what the next display element is
2502      after a call to get_next_display_element.  */
2503   enum display_element_type what;
2504 
2505   /* Face to use.  */
2506   int face_id;
2507 
2508   /* Setting of buffer-local variable selective-display-ellipses.  */
2509   bool_bf selective_display_ellipsis_p : 1;
2510 
2511   /* True means control characters are translated into the form `^C'
2512      where the `^' can be replaced by a display table entry.  */
2513   bool_bf ctl_arrow_p : 1;
2514 
2515   /* True means that the current face has a box.  */
2516   bool_bf face_box_p : 1;
2517 
2518   /* Non-null means that the current character is the first in a run
2519      of characters with box face.  */
2520   bool_bf start_of_box_run_p : 1;
2521 
2522   /* True means that the current character is the last in a run
2523      of characters with box face.  */
2524   bool_bf end_of_box_run_p : 1;
2525 
2526   /* True means overlay strings at end_charpos have been processed.  */
2527   bool_bf overlay_strings_at_end_processed_p : 1;
2528 
2529   /* True means to ignore overlay strings at current pos, as they have
2530      already been processed.  */
2531   bool_bf ignore_overlay_strings_at_pos_p : 1;
2532 
2533   /* True means the actual glyph is not available in the current
2534      system.  */
2535   bool_bf glyph_not_available_p : 1;
2536 
2537   /* True means the next line in display_line continues a character
2538      consisting of more than one glyph, and some glyphs of this
2539      character have been put on the previous line.  */
2540   bool_bf starts_in_middle_of_char_p : 1;
2541 
2542   /* If true, saved_face_id contains the id of the face in front of text
2543      skipped due to selective display.  */
2544   bool_bf face_before_selective_p : 1;
2545 
2546   /* If true, adjust current glyph so it does not increase current row
2547      descent/ascent (line-height property).  Reset after this glyph.  */
2548   bool_bf constrain_row_ascent_descent_p : 1;
2549 
2550   /* If true, glyphs for line number display were already produced for
2551      the current row.  */
2552   bool_bf line_number_produced_p : 1;
2553 
2554   enum line_wrap_method line_wrap;
2555 
2556   /* The ID of the default face to use.  One of DEFAULT_FACE_ID,
2557      MODE_LINE_ACTIVE_FACE_ID, etc, depending on what we are
2558      displaying.  */
2559   int base_face_id;
2560 
2561   /* If `what' == IT_CHARACTER, the character and the length in bytes
2562      of its multibyte sequence.  The character comes from a buffer or
2563      a string.  It may be different from the character displayed in
2564      case that unibyte_display_via_language_environment is set.
2565 
2566      If `what' == IT_COMPOSITION, the first component of a composition
2567      and length in bytes of the composition.
2568 
2569      If `what' is anything else, these two are undefined (will
2570      probably hold values for the last IT_CHARACTER or IT_COMPOSITION
2571      traversed by the iterator).
2572 
2573      The values are updated by get_next_display_element, so they are
2574      out of sync with the value returned by IT_CHARPOS between the
2575      time set_iterator_to_next advances the position and the time
2576      get_next_display_element loads the new values into c and len.  */
2577   int c, len;
2578 
2579   /* If what == IT_COMPOSITION, iterator substructure for the
2580      composition.  */
2581   struct composition_it cmp_it;
2582 
2583   /* The character to display, possibly translated to multibyte if
2584      multibyte_p is zero or unibyte_display_via_language_environment
2585      is set.  This is set after get_next_display_element has been
2586      called.  If we are setting it->C directly before calling
2587      PRODUCE_GLYPHS, this should be set beforehand too.  */
2588   int char_to_display;
2589 
2590   /* If what == IT_GLYPHLESS, the method to display such a
2591      character.  */
2592   enum glyphless_display_method glyphless_method;
2593 
2594   /* If what == IT_IMAGE, the id of the image to display.  */
2595   ptrdiff_t image_id;
2596 
2597   /* If what == IT_XWIDGET.  */
2598   struct xwidget *xwidget;
2599 
2600   /* Values from `slice' property.  */
2601   struct it_slice slice;
2602 
2603   /* Value of the `space-width' property, if any; nil if none.  */
2604   Lisp_Object space_width;
2605 
2606   /* Computed from the value of the `raise' property.  */
2607   short voffset;
2608 
2609   /* Number of columns per \t.  */
2610   short tab_width;
2611 
2612   /* Value of the `height' property, if any; nil if none.  */
2613   Lisp_Object font_height;
2614 
2615   /* Object and position where the current display element came from.
2616      Object is normally the buffer which is being rendered, but it can
2617      also be a Lisp string in case the current display element comes
2618      from an overlay string or from a display string (before- or
2619      after-string).  It may also be a zero-valued Lisp integer when a
2620      C string is being rendered, e.g., during mode-line or header-line
2621      update.  It can also be a cons cell of the form `(space ...)',
2622      when we produce a stretch glyph from a `display' specification.
2623      Finally, it can be nil, but only temporarily, when we are
2624      producing special glyphs for display purposes, like truncation
2625      and continuation glyphs, or blanks that extend each line to the
2626      edge of the window on a TTY.
2627 
2628      Do NOT use !BUFFERP (it.object) as a test whether we are
2629      iterating over a string; use STRINGP (it.string) instead.
2630 
2631      Position is the current iterator position in object.
2632 
2633      The 'position's CHARPOS is copied to glyph->charpos of the glyph
2634      produced by PRODUCE_GLYPHS, so any artificial value documented
2635      under 'struct glyph's 'charpos' member can also be found in the
2636      'position' member here.  */
2637   Lisp_Object object;
2638   struct text_pos position;
2639 
2640   /* Width in pixels of truncation and continuation glyphs.  */
2641   short truncation_pixel_width, continuation_pixel_width;
2642 
2643   /* First and last visible x-position in the display area.  If window
2644      is hscrolled by n columns, first_visible_x == n * FRAME_COLUMN_WIDTH
2645      (f), and last_visible_x == pixel width of W + first_visible_x.
2646      When truncation or continuation glyphs are produced due to lack of
2647      fringes, last_visible_x excludes the space required for these glyphs.  */
2648   int first_visible_x, last_visible_x;
2649 
2650   /* Last visible y-position + 1 in the display area without a mode
2651      line, if the window has one.  */
2652   int last_visible_y;
2653 
2654   /* Default amount of additional space in pixels between lines (for
2655      window systems only.)  */
2656   int extra_line_spacing;
2657 
2658   /* Max extra line spacing added in this row.  */
2659   int max_extra_line_spacing;
2660 
2661   /* Override font height information for this glyph.
2662      Used if override_ascent >= 0.  Cleared after this glyph.  */
2663   int override_ascent, override_descent, override_boff;
2664 
2665   /* If non-null, glyphs are produced in glyph_row with each call to
2666      produce_glyphs.  */
2667   struct glyph_row *glyph_row;
2668 
2669   /* The area of glyph_row to which glyphs are added.  */
2670   enum glyph_row_area area;
2671 
2672   /* Number of glyphs needed for the last character requested via
2673      produce_glyphs.  This is 1 except for tabs.  */
2674   int nglyphs;
2675 
2676   /* Width of the display element in pixels.  Result of
2677      produce_glyphs.  */
2678   int pixel_width;
2679 
2680   /* Current, maximum logical, and maximum physical line height
2681      information.  Result of produce_glyphs.  */
2682   int ascent, descent, max_ascent, max_descent;
2683   int phys_ascent, phys_descent, max_phys_ascent, max_phys_descent;
2684 
2685   /* Current x pixel position within the display line.  This value
2686      does not include the width of continuation lines in front of the
2687      line.  The value of current_x is automatically incremented by
2688      pixel_width with each call to produce_glyphs.  */
2689   int current_x;
2690 
2691   /* Accumulated width of continuation lines.  If > 0, this means we
2692      are currently in a continuation line.  This is initially zero and
2693      incremented/reset by display_line, move_it_to etc.  */
2694   int continuation_lines_width;
2695 
2696   /* Buffer position that ends the buffer text line being iterated.
2697      This is normally the position after the newline at EOL.  If this
2698      is the last line of the buffer and it doesn't have a newline,
2699      value is ZV/ZV_BYTE.  Set and used only if IT->bidi_p, for
2700      setting the end position of glyph rows produced for continuation
2701      lines, see display_line.  */
2702   struct text_pos eol_pos;
2703 
2704   /* Current y-position.  Automatically incremented by the height of
2705      glyph_row in move_it_to and display_line.  */
2706   int current_y;
2707 
2708   /* Vertical matrix position of first text line in window.  */
2709   int first_vpos;
2710 
2711   /* Current vertical matrix position, or line number.  Automatically
2712      incremented by move_it_to and display_line.  */
2713   int vpos;
2714 
2715   /* Horizontal matrix position reached in move_it_in_display_line.
2716      Only set there, not in display_line, and only when the X
2717      coordinate is past first_visible_x.  */
2718   int hpos;
2719 
2720   /* Current line number, zero-based.  */
2721   ptrdiff_t lnum;
2722 
2723   /* The byte position corresponding to lnum.  */
2724   ptrdiff_t lnum_bytepos;
2725 
2726   /* The width, in columns and in pixels, needed for display of the
2727      line numbers, or zero if not computed.  */
2728   int lnum_width;
2729   int lnum_pixel_width;
2730 
2731   /* The line number of point's line, or zero if not computed yet.  */
2732   ptrdiff_t pt_lnum;
2733 
2734   /* Number of pixels to offset tab stops due to width fixup of the
2735      first glyph that crosses first_visible_x.  This is only needed on
2736      GUI frames, only when display-line-numbers is in effect, and only
2737      in hscrolled windows.  */
2738   int tab_offset;
2739 
2740   /* Left fringe bitmap number (enum fringe_bitmap_type).  */
2741   unsigned left_user_fringe_bitmap : FRINGE_ID_BITS;
2742 
2743   /* Right fringe bitmap number (enum fringe_bitmap_type).  */
2744   unsigned right_user_fringe_bitmap : FRINGE_ID_BITS;
2745 
2746   /* Face of the left fringe glyph.  */
2747   unsigned left_user_fringe_face_id : FACE_ID_BITS;
2748 
2749   /* Face of the right fringe glyph.  */
2750   unsigned right_user_fringe_face_id : FACE_ID_BITS;
2751 
2752   /* True means we need to reorder bidirectional text for display
2753      in the visual order.  */
2754   bool_bf bidi_p : 1;
2755 
2756   /* For iterating over bidirectional text.  */
2757   struct bidi_it bidi_it;
2758   bidi_dir_t paragraph_embedding;
2759 
2760   /* For handling the :min-width property.  The object is the text
2761      property we're testing the `eq' of (nil if none), and the integer
2762      is the x position of the start of the run of glyphs. */
2763   Lisp_Object min_width_property;
2764   int min_width_start;
2765 };
2766 
2767 
2768 /* Access to positions of iterator IT.  */
2769 
2770 #define IT_CHARPOS(IT)		CHARPOS ((IT).current.pos)
2771 #define IT_BYTEPOS(IT)		BYTEPOS ((IT).current.pos)
2772 #define IT_STRING_CHARPOS(IT)	CHARPOS ((IT).current.string_pos)
2773 #define IT_STRING_BYTEPOS(IT)	BYTEPOS ((IT).current.string_pos)
2774 
2775 /* Test if IT has reached the end of its buffer or string.  This will
2776    only work after get_next_display_element has been called.  */
2777 
2778 #define ITERATOR_AT_END_P(IT) ((IT)->what == IT_EOB)
2779 
2780 /* True means IT is at the end of a line.  This is the case if it
2781    is either on a newline or on a carriage return and selective
2782    display hides the rest of the line.  */
2783 
2784 #define ITERATOR_AT_END_OF_LINE_P(IT)			\
2785      ((IT)->what == IT_CHARACTER			\
2786       && ((IT)->c == '\n'				\
2787 	  || ((IT)->c == '\r' && (IT)->selective)))
2788 
2789 /* Call produce_glyphs or FRAME_RIF->produce_glyphs, if set.  Shortcut
2790    to avoid the function call overhead.  */
2791 
2792 #define PRODUCE_GLYPHS(IT)                              \
2793   do {                                                  \
2794     if ((IT)->glyph_row != NULL && (IT)->bidi_p)	\
2795       (IT)->glyph_row->reversed_p = (IT)->bidi_it.paragraph_dir == R2L; \
2796     if (FRAME_RIF ((IT)->f) != NULL)                    \
2797       FRAME_RIF ((IT)->f)->produce_glyphs ((IT));       \
2798     else                                                \
2799       produce_glyphs ((IT));                            \
2800     if ((IT)->glyph_row != NULL)                        \
2801       inhibit_free_realized_faces =true;		\
2802     reset_box_start_end_flags ((IT));			\
2803   } while (false)
2804 
2805 /* Bit-flags indicating what operation move_it_to should perform.  */
2806 
2807 enum move_operation_enum
2808 {
2809   /* Stop if specified x-position is reached.  */
2810   MOVE_TO_X = 0x01,
2811 
2812   /* Stop if specified y-position is reached.  */
2813   MOVE_TO_Y = 0x02,
2814 
2815   /* Stop if specified vpos is reached.  */
2816   MOVE_TO_VPOS = 0x04,
2817 
2818   /* Stop if specified buffer or string position is reached.  */
2819   MOVE_TO_POS = 0x08
2820 };
2821 
2822 /***********************************************************************
2823 			    Mouse Highlight
2824  ***********************************************************************/
2825 
2826 /* Structure to hold mouse highlight data.  */
2827 
2828 typedef struct {
2829   /* These variables describe the range of text currently shown in its
2830      mouse-face, together with the window they apply to.  As long as
2831      the mouse stays within this range, we need not redraw anything on
2832      its account.  Rows and columns are glyph matrix positions in
2833      MOUSE_FACE_WINDOW.  */
2834   int mouse_face_beg_row, mouse_face_beg_col, mouse_face_beg_x;
2835   int mouse_face_end_row, mouse_face_end_col, mouse_face_end_x;
2836   Lisp_Object mouse_face_window;
2837   int mouse_face_face_id;
2838   Lisp_Object mouse_face_overlay;
2839 
2840   /* FRAME and X, Y position of mouse when last checked for
2841      highlighting.  X and Y can be negative or out of range for the frame.  */
2842   struct frame *mouse_face_mouse_frame;
2843   int mouse_face_mouse_x, mouse_face_mouse_y;
2844 
2845   /* Nonzero if part of the text currently shown in
2846      its mouse-face is beyond the window end.  */
2847   bool_bf mouse_face_past_end : 1;
2848 
2849   /* True means defer mouse-motion highlighting.  */
2850   bool_bf mouse_face_defer : 1;
2851 
2852   /* True means that the mouse highlight should not be shown.  */
2853   bool_bf mouse_face_hidden : 1;
2854 } Mouse_HLInfo;
2855 
2856 INLINE void
reset_mouse_highlight(Mouse_HLInfo * hlinfo)2857 reset_mouse_highlight (Mouse_HLInfo *hlinfo)
2858 {
2859 
2860     hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
2861     hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
2862     hlinfo->mouse_face_mouse_x = hlinfo->mouse_face_mouse_y = 0;
2863     hlinfo->mouse_face_beg_x = hlinfo->mouse_face_end_x = 0;
2864     hlinfo->mouse_face_face_id = DEFAULT_FACE_ID;
2865     hlinfo->mouse_face_mouse_frame = NULL;
2866     hlinfo->mouse_face_window = Qnil;
2867     hlinfo->mouse_face_overlay = Qnil;
2868     hlinfo->mouse_face_past_end = false;
2869     hlinfo->mouse_face_hidden = false;
2870     hlinfo->mouse_face_defer = false;
2871 }
2872 
2873 /***********************************************************************
2874 		   Window-based redisplay interface
2875  ***********************************************************************/
2876 
2877 /* Structure used to describe runs of lines that must be scrolled.  */
2878 
2879 struct run
2880 {
2881   /* Source and destination y pixel position.  */
2882   int desired_y, current_y;
2883 
2884   /* Source and destination vpos in matrix.  */
2885   int desired_vpos, current_vpos;
2886 
2887   /* Height in pixels, number of glyph rows.  */
2888   int height, nrows;
2889 };
2890 
2891 
2892 /* Handlers for setting frame parameters.  */
2893 
2894 typedef void (*frame_parm_handler) (struct frame *, Lisp_Object, Lisp_Object);
2895 
2896 
2897 /* Structure holding system-dependent interface functions needed
2898    for window-based redisplay.  */
2899 
2900 struct redisplay_interface
2901 {
2902   /* Handlers for setting frame parameters.  */
2903   frame_parm_handler *frame_parm_handlers;
2904 
2905   /* Produce glyphs/get display metrics for the display element IT is
2906      loaded with.  */
2907   void (*produce_glyphs) (struct it *it);
2908 
2909   /* Write or insert LEN glyphs from STRING at the nominal output
2910      position.  */
2911   void (*write_glyphs) (struct window *w, struct glyph_row *row,
2912 			struct glyph *string, enum glyph_row_area area,
2913 			int len);
2914   void (*insert_glyphs) (struct window *w, struct glyph_row *row,
2915 			 struct glyph *start, enum glyph_row_area area,
2916 			 int len);
2917 
2918   /* Clear from nominal output position to X.  X < 0 means clear
2919      to right end of display.  */
2920   void (*clear_end_of_line) (struct window *w, struct glyph_row *row,
2921 			     enum glyph_row_area area, int x);
2922 
2923   /* Function to call to scroll the display as described by RUN on
2924      window W.  */
2925   void (*scroll_run_hook) (struct window *w, struct run *run);
2926 
2927   /* Function to call after a line in a display has been completely
2928      updated.  Used to draw truncation marks and alike.  DESIRED_ROW
2929      is the desired row which has been updated.  */
2930   void (*after_update_window_line_hook) (struct window *w,
2931 					 struct glyph_row *desired_row);
2932 
2933   /* Function to call before beginning to update window W in
2934      window-based redisplay.  */
2935   void (*update_window_begin_hook) (struct window *w);
2936 
2937   /* Function to call after window W has been updated in window-based
2938      redisplay.  CURSOR_ON_P true means switch cursor on.
2939      MOUSE_FACE_OVERWRITTEN_P true means that some lines in W
2940      that contained glyphs in mouse-face were overwritten, so we
2941      have to update the mouse highlight.  */
2942   void (*update_window_end_hook) (struct window *w, bool cursor_on_p,
2943                                   bool mouse_face_overwritten_p);
2944 
2945   /* Flush the display of frame F.  For X, this is XFlush.  */
2946   void (*flush_display) (struct frame *f);
2947 
2948   /* Clear the mouse highlight in window W, if there is any.  */
2949   void (*clear_window_mouse_face) (struct window *w);
2950 
2951   /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2952      frame F.  */
2953   void (*get_glyph_overhangs) (struct glyph *glyph, struct frame *f,
2954                                int *left, int *right);
2955 
2956   /* Fix the display of AREA of ROW in window W for overlapping rows.
2957      This function is called from redraw_overlapping_rows after
2958      desired rows have been made current.  */
2959   void (*fix_overlapping_area) (struct window *w, struct glyph_row *row,
2960                                 enum glyph_row_area area, int);
2961 
2962 #ifdef HAVE_WINDOW_SYSTEM
2963 
2964   /* Draw a fringe bitmap in window W of row ROW using parameters P.  */
2965   void (*draw_fringe_bitmap) (struct window *w, struct glyph_row *row,
2966                               struct draw_fringe_bitmap_params *p);
2967 
2968   /* Define and destroy fringe bitmap no. WHICH.  */
2969   void (*define_fringe_bitmap) (int which, unsigned short *bits,
2970                                 int h, int wd);
2971   void (*destroy_fringe_bitmap) (int which);
2972 
2973   /* Compute left and right overhang of glyph string S.
2974      A NULL pointer if platform does not support this. */
2975   void (*compute_glyph_string_overhangs) (struct glyph_string *s);
2976 
2977   /* Draw a glyph string S.  */
2978   void (*draw_glyph_string) (struct glyph_string *s);
2979 
2980   /* Define cursor CURSOR on frame F.  */
2981   void (*define_frame_cursor) (struct frame *f, Emacs_Cursor cursor);
2982 
2983   /* Clear the area at (X,Y,WIDTH,HEIGHT) of frame F.  */
2984   void (*clear_frame_area) (struct frame *f, int x, int y,
2985                             int width, int height);
2986 
2987  /* Clear area of frame F's internal border.  If the internal border
2988     face of F has been specified (is not null), fill the area with
2989     that face.  */
2990   void (*clear_under_internal_border) (struct frame *f);
2991 
2992   /* Draw specified cursor CURSOR_TYPE of width CURSOR_WIDTH
2993      at row GLYPH_ROW on window W if ON_P is true.  If ON_P is
2994      false, don't draw cursor.  If ACTIVE_P is true, system caret
2995      should track this cursor (when applicable).  */
2996   void (*draw_window_cursor) (struct window *w,
2997 			      struct glyph_row *glyph_row,
2998 			      int x, int y,
2999 			      enum text_cursor_kinds cursor_type,
3000 			      int cursor_width, bool on_p, bool active_p);
3001 
3002   /* Draw vertical border for window W from (X,Y_0) to (X,Y_1).  */
3003   void (*draw_vertical_window_border) (struct window *w,
3004                                        int x, int y_0, int y_1);
3005 
3006   /* Draw window divider for window W from (X_0, Y_0) to (X_1, ,Y_1).  */
3007   void (*draw_window_divider) (struct window *w,
3008 			       int x_0, int x_1, int y_0, int y_1);
3009 
3010   /* Shift display of frame F to make room for inserted glyphs.
3011      The area at pixel (X,Y) of width WIDTH and height HEIGHT is
3012      shifted right by SHIFT_BY pixels.  */
3013   void (*shift_glyphs_for_insert) (struct frame *f,
3014                                    int x, int y, int width,
3015                                    int height, int shift_by);
3016 
3017   /* Start display hourglass cursor on frame F.  */
3018   void (*show_hourglass) (struct frame *f);
3019 
3020   /* Cancel hourglass cursor on frame F.  */
3021   void (*hide_hourglass) (struct frame *f);
3022 
3023   /* Called to (re)calculate the default face when changing the font
3024      backend.  */
3025   void (*default_font_parameter) (struct frame *f, Lisp_Object parms);
3026 #endif /* HAVE_WINDOW_SYSTEM */
3027 };
3028 
3029 
3030 /***********************************************************************
3031 				Images
3032  ***********************************************************************/
3033 
3034 #ifdef HAVE_WINDOW_SYSTEM
3035 
3036 # if (defined USE_CAIRO || defined HAVE_XRENDER \
3037       || defined HAVE_NS || defined HAVE_NTGUI || defined HAVE_HAIKU)
3038 #  define HAVE_NATIVE_TRANSFORMS
3039 # endif
3040 
3041 /* Structure describing an image.  Specific image formats like XBM are
3042    converted into this form, so that display only has to deal with
3043    this type of image.  */
3044 
3045 struct image
3046 {
3047   /* The time in seconds at which the image was last displayed.  Set
3048      in prepare_image_for_display.  */
3049   struct timespec timestamp;
3050 
3051   /* Pixmaps of the image.  */
3052   Emacs_Pixmap pixmap, mask;
3053 
3054 #ifdef USE_CAIRO
3055   void *cr_data;
3056 #endif
3057 #ifdef HAVE_X_WINDOWS
3058   /* X images of the image, corresponding to the above Pixmaps.
3059      Non-NULL means it and its Pixmap counterpart may be out of sync
3060      and the latter is outdated.  NULL means the X image has been
3061      synchronized to Pixmap.  */
3062   XImage *ximg, *mask_img;
3063 
3064 # if !defined USE_CAIRO && defined HAVE_XRENDER
3065   /* Picture versions of pixmap and mask for compositing.  */
3066   Picture picture, mask_picture;
3067 
3068   /* We need to store the original image dimensions in case we have to
3069      call XGetImage.  */
3070   int original_width, original_height;
3071 # endif
3072 #endif	/* HAVE_X_WINDOWS */
3073 #ifdef HAVE_NTGUI
3074   XFORM xform;
3075 #endif
3076 #ifdef HAVE_HAIKU
3077   /* Non-zero if the image has not yet been transformed for display.  */
3078   int have_be_transforms_p;
3079 
3080   double be_rotate;
3081   double be_scale_x;
3082   double be_scale_y;
3083 #endif
3084 
3085   /* Colors allocated for this image, if any.  Allocated via xmalloc.  */
3086   unsigned long *colors;
3087   int ncolors;
3088 
3089   /* A single `background color' for this image, for the use of anyone that
3090      cares about such a thing.  Only valid if the `background_valid' field
3091      is true.  This should generally be accessed by calling the accessor
3092      macro `IMAGE_BACKGROUND', which will heuristically calculate a value
3093      if necessary.  */
3094   unsigned long background;
3095 
3096   /* Foreground and background colors of the face on which the image
3097      is created.  */
3098   unsigned long face_foreground, face_background;
3099 
3100   /* Details of the font, only really relevant for types like SVG that
3101      allow us to draw text. */
3102   int face_font_size;
3103   char *face_font_family;
3104 
3105   /* True if this image has a `transparent' background -- that is, is
3106      uses an image mask.  The accessor macro for this is
3107      `IMAGE_BACKGROUND_TRANSPARENT'.  */
3108   bool_bf background_transparent : 1;
3109 
3110   /* True if the `background' and `background_transparent' fields are
3111      valid, respectively. */
3112   bool_bf background_valid : 1, background_transparent_valid : 1;
3113 
3114   /* Width and height of the image.  */
3115   int width, height;
3116 
3117   /* These values are used for the rectangles displayed for images
3118      that can't be loaded.  */
3119 #define DEFAULT_IMAGE_WIDTH 30
3120 #define DEFAULT_IMAGE_HEIGHT 30
3121 
3122   /* Top/left and bottom/right corner pixel of actual image data.
3123      Used by four_corners_best to consider the real image data,
3124      rather than looking at the optional image margin.  */
3125   int corners[4];
3126 #define TOP_CORNER 0
3127 #define LEFT_CORNER 1
3128 #define BOT_CORNER 2
3129 #define RIGHT_CORNER 3
3130 
3131   /* Percent of image height used as ascent.  A value of
3132      CENTERED_IMAGE_ASCENT means draw the image centered on the
3133      line.  */
3134   int ascent;
3135 #define DEFAULT_IMAGE_ASCENT 50
3136 #define CENTERED_IMAGE_ASCENT -1
3137 
3138   /* Lisp specification of this image.  */
3139   Lisp_Object spec;
3140 
3141   /* List of "references" followed to build the image.
3142      Typically will just contain the name of the image file.
3143      Used to allow fine-grained cache flushing.  */
3144   Lisp_Object dependencies;
3145 
3146   /* Relief to draw around the image.  */
3147   int relief;
3148 
3149   /* Optional margins around the image.  This includes the relief.  */
3150   int hmargin, vmargin;
3151 
3152   /* Reference to the type of the image.  */
3153   struct image_type const *type;
3154 
3155   /* True means that loading the image failed.  Don't try again.  */
3156   bool load_failed_p;
3157 
3158   /* A place for image types to store additional data.  It is marked
3159      during GC.  */
3160   Lisp_Object lisp_data;
3161 
3162   /* Hash value of image specification to speed up comparisons.  */
3163   EMACS_UINT hash;
3164 
3165   /* Image id of this image.  */
3166   ptrdiff_t id;
3167 
3168   /* Hash collision chain.  */
3169   struct image *next, *prev;
3170 };
3171 
3172 
3173 /* Cache of images.  Each frame has a cache.  X frames with the same
3174    x_display_info share their caches.  */
3175 
3176 struct image_cache
3177 {
3178   /* Hash table of images.  */
3179   struct image **buckets;
3180 
3181   /* Vector mapping image ids to images.  */
3182   struct image **images;
3183 
3184   /* Allocated size of `images'.  */
3185   ptrdiff_t size;
3186 
3187   /* Number of images in the cache.  */
3188   ptrdiff_t used;
3189 
3190   /* Reference count (number of frames sharing this cache).  */
3191   ptrdiff_t refcount;
3192 };
3193 
3194 /* Size of bucket vector of image caches.  Should be prime.  */
3195 
3196 #define IMAGE_CACHE_BUCKETS_SIZE 1009
3197 
3198 #endif /* HAVE_WINDOW_SYSTEM */
3199 
3200 
3201 
3202 /***********************************************************************
3203 			       Tab-bars
3204  ***********************************************************************/
3205 
3206 /* Enumeration defining where to find tab-bar item information in
3207    tab-bar items vectors stored with frames.  Each tab-bar item
3208    occupies TAB_BAR_ITEM_NSLOTS elements in such a vector.  */
3209 
3210 enum tab_bar_item_idx
3211 {
3212   /* The key of the tab-bar item.  Used to remove items when a binding
3213      for `undefined' is found.  */
3214   TAB_BAR_ITEM_KEY,
3215 
3216   /* Non-nil if item is enabled.  */
3217   TAB_BAR_ITEM_ENABLED_P,
3218 
3219   /* Non-nil if item is selected (pressed).  */
3220   TAB_BAR_ITEM_SELECTED_P,
3221 
3222   /* Caption.  */
3223   TAB_BAR_ITEM_CAPTION,
3224 
3225   /* The binding.  */
3226   TAB_BAR_ITEM_BINDING,
3227 
3228   /* Help string.  */
3229   TAB_BAR_ITEM_HELP,
3230 
3231   /* Sentinel = number of slots in tab_bar_items occupied by one
3232      tab-bar item.  */
3233   TAB_BAR_ITEM_NSLOTS
3234 };
3235 
3236 /* Default values of the above variables.  */
3237 
3238 #define DEFAULT_TAB_BAR_BUTTON_MARGIN 1
3239 #define DEFAULT_TAB_BAR_BUTTON_RELIEF 1
3240 
3241 /* The height in pixels of the default tab-bar images.  */
3242 
3243 #define DEFAULT_TAB_BAR_IMAGE_HEIGHT 18
3244 
3245 
3246 /***********************************************************************
3247 			       Tool-bars
3248  ***********************************************************************/
3249 
3250 /* Enumeration defining where to find tool-bar item information in
3251    tool-bar items vectors stored with frames.  Each tool-bar item
3252    occupies TOOL_BAR_ITEM_NSLOTS elements in such a vector.  */
3253 
3254 enum tool_bar_item_idx
3255 {
3256   /* The key of the tool-bar item.  Used to remove items when a binding
3257      for `undefined' is found.  */
3258   TOOL_BAR_ITEM_KEY,
3259 
3260   /* Non-nil if item is enabled.  */
3261   TOOL_BAR_ITEM_ENABLED_P,
3262 
3263   /* Non-nil if item is selected (pressed).  */
3264   TOOL_BAR_ITEM_SELECTED_P,
3265 
3266   /* Caption.  */
3267   TOOL_BAR_ITEM_CAPTION,
3268 
3269   /* Image(s) to display.  This is either a single image specification
3270      or a vector of specifications.  */
3271   TOOL_BAR_ITEM_IMAGES,
3272 
3273   /* The binding.  */
3274   TOOL_BAR_ITEM_BINDING,
3275 
3276   /* Button type.  One of nil (default button), t (a separator),
3277      `:radio', or `:toggle'.  The latter two currently do nothing.  */
3278   TOOL_BAR_ITEM_TYPE,
3279 
3280   /* Help string.  */
3281   TOOL_BAR_ITEM_HELP,
3282 
3283   /* Icon file name of right to left image when an RTL locale is used.  */
3284   TOOL_BAR_ITEM_RTL_IMAGE,
3285 
3286   /* Label to show when text labels are enabled.  */
3287   TOOL_BAR_ITEM_LABEL,
3288 
3289   /* If we shall show the label only below the icon and not beside it.  */
3290   TOOL_BAR_ITEM_VERT_ONLY,
3291 
3292   /* Sentinel = number of slots in tool_bar_items occupied by one
3293      tool-bar item.  */
3294   TOOL_BAR_ITEM_NSLOTS
3295 };
3296 
3297 
3298 /* An enumeration for the different images that can be specified
3299    for a tool-bar item.  */
3300 
3301 enum tool_bar_item_image
3302 {
3303   TOOL_BAR_IMAGE_ENABLED_SELECTED,
3304   TOOL_BAR_IMAGE_ENABLED_DESELECTED,
3305   TOOL_BAR_IMAGE_DISABLED_SELECTED,
3306   TOOL_BAR_IMAGE_DISABLED_DESELECTED
3307 };
3308 
3309 #define DEFAULT_TOOL_BAR_LABEL_SIZE 14
3310 
3311 /* Default values of the above variables.  */
3312 
3313 #define DEFAULT_TOOL_BAR_BUTTON_MARGIN 4
3314 #define DEFAULT_TOOL_BAR_BUTTON_RELIEF 1
3315 
3316 /* The height in pixels of the default tool-bar images.  */
3317 
3318 #define DEFAULT_TOOL_BAR_IMAGE_HEIGHT 24
3319 
3320 
3321 /***********************************************************************
3322 			 Terminal Capabilities
3323  ***********************************************************************/
3324 
3325 /* Each of these is a bit representing a terminal `capability' (bold,
3326    inverse, etc).  They are or'd together to specify the set of
3327    capabilities being queried for when calling `tty_capable_p' (which
3328    returns true if the terminal supports all of them).  */
3329 
3330 #define TTY_CAP_INVERSE		0x01
3331 #define TTY_CAP_UNDERLINE	0x02
3332 #define TTY_CAP_BOLD		0x04
3333 #define TTY_CAP_DIM		0x08
3334 #define TTY_CAP_ITALIC  	0x10
3335 #define TTY_CAP_STRIKE_THROUGH	0x20
3336 
3337 
3338 /***********************************************************************
3339 			  Function Prototypes
3340  ***********************************************************************/
3341 
3342 /* Defined in bidi.c */
3343 
3344 extern void bidi_init_it (ptrdiff_t, ptrdiff_t, bool, struct bidi_it *);
3345 extern void bidi_move_to_visually_next (struct bidi_it *);
3346 extern void bidi_paragraph_init (bidi_dir_t, struct bidi_it *, bool);
3347 extern int  bidi_mirror_char (int);
3348 extern void bidi_push_it (struct bidi_it *);
3349 extern void bidi_pop_it (struct bidi_it *);
3350 extern void *bidi_shelve_cache (void);
3351 extern void bidi_unshelve_cache (void *, bool);
3352 extern ptrdiff_t bidi_find_first_overridden (struct bidi_it *);
3353 
3354 /* Defined in xdisp.c */
3355 
3356 struct glyph_row *row_containing_pos (struct window *, ptrdiff_t,
3357                                       struct glyph_row *,
3358                                       struct glyph_row *, int);
3359 int line_bottom_y (struct it *);
3360 int default_line_pixel_height (struct window *);
3361 bool display_prop_intangible_p (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
3362 void resize_echo_area_exactly (void);
3363 bool resize_mini_window (struct window *, bool);
3364 void set_vertical_scroll_bar (struct window *);
3365 void set_horizontal_scroll_bar (struct window *);
3366 int try_window (Lisp_Object, struct text_pos, int);
3367 void window_box (struct window *, enum glyph_row_area,
3368 		 int *, int *, int *, int *);
3369 int window_box_height (struct window *);
3370 int window_text_bottom_y (struct window *);
3371 int window_box_width (struct window *, enum glyph_row_area);
3372 int window_box_left (struct window *, enum glyph_row_area);
3373 int window_box_left_offset (struct window *, enum glyph_row_area);
3374 int window_box_right (struct window *, enum glyph_row_area);
3375 int estimate_mode_line_height (struct frame *, enum face_id);
3376 int move_it_to (struct it *, ptrdiff_t, int, int, int, int);
3377 void pixel_to_glyph_coords (struct frame *, int, int, int *, int *,
3378                             NativeRectangle *, bool);
3379 void remember_mouse_glyph (struct frame *, int, int, NativeRectangle *);
3380 
3381 void mark_window_display_accurate (Lisp_Object, bool);
3382 void redisplay_preserve_echo_area (int);
3383 void init_iterator (struct it *, struct window *, ptrdiff_t,
3384                     ptrdiff_t, struct glyph_row *, enum face_id);
3385 void init_iterator_to_row_start (struct it *, struct window *,
3386                                  struct glyph_row *);
3387 void start_display (struct it *, struct window *, struct text_pos);
3388 void move_it_vertically (struct it *, int);
3389 void move_it_vertically_backward (struct it *, int);
3390 void move_it_by_lines (struct it *, ptrdiff_t);
3391 void move_it_past_eol (struct it *);
3392 void move_it_in_display_line (struct it *it,
3393 			      ptrdiff_t to_charpos, int to_x,
3394 			      enum move_operation_enum op);
3395 int partial_line_height (struct it *it_origin);
3396 bool in_display_vector_p (struct it *);
3397 int frame_mode_line_height (struct frame *);
3398 extern bool redisplaying_p;
3399 extern bool help_echo_showing_p;
3400 extern Lisp_Object help_echo_string, help_echo_window;
3401 extern Lisp_Object help_echo_object, previous_help_echo_string;
3402 extern ptrdiff_t help_echo_pos;
3403 extern int last_tab_bar_item;
3404 extern int last_tool_bar_item;
3405 extern void reseat_at_previous_visible_line_start (struct it *);
3406 extern Lisp_Object lookup_glyphless_char_display (int, struct it *);
3407 extern ptrdiff_t compute_display_string_pos (struct text_pos *,
3408 					     struct bidi_string_data *,
3409 					     struct window *, bool, int *);
3410 extern ptrdiff_t compute_display_string_end (ptrdiff_t,
3411 					     struct bidi_string_data *);
3412 extern void produce_stretch_glyph (struct it *);
3413 extern int merge_glyphless_glyph_face (struct it *);
3414 extern void forget_escape_and_glyphless_faces (void);
3415 
3416 extern void get_font_ascent_descent (struct font *, int *, int *);
3417 
3418 #ifdef HAVE_WINDOW_SYSTEM
3419 
3420 extern void gui_get_glyph_overhangs (struct glyph *, struct frame *,
3421                                      int *, int *);
3422 extern struct font *font_for_underline_metrics (struct glyph_string *);
3423 extern void gui_produce_glyphs (struct it *);
3424 
3425 extern void gui_write_glyphs (struct window *, struct glyph_row *,
3426                               struct glyph *, enum glyph_row_area, int);
3427 extern void gui_insert_glyphs (struct window *, struct glyph_row *,
3428                                struct glyph *, enum glyph_row_area, int);
3429 extern void gui_clear_end_of_line (struct window *, struct glyph_row *,
3430                                    enum glyph_row_area, int);
3431 extern void gui_fix_overlapping_area (struct window *, struct glyph_row *,
3432                                       enum glyph_row_area, int);
3433 extern void draw_phys_cursor_glyph (struct window *,
3434                                     struct glyph_row *,
3435                                     enum draw_glyphs_face);
3436 extern void get_phys_cursor_geometry (struct window *, struct glyph_row *,
3437                                       struct glyph *, int *, int *, int *);
3438 extern void erase_phys_cursor (struct window *);
3439 extern void display_and_set_cursor (struct window *, bool, int, int, int, int);
3440 extern void gui_update_cursor (struct frame *, bool);
3441 extern void gui_clear_cursor (struct window *);
3442 extern void gui_draw_vertical_border (struct window *w);
3443 extern void gui_draw_right_divider (struct window *w);
3444 
3445 extern int get_glyph_string_clip_rects (struct glyph_string *,
3446                                         NativeRectangle *, int);
3447 extern void get_glyph_string_clip_rect (struct glyph_string *,
3448                                         NativeRectangle *nr);
3449 extern Lisp_Object find_hot_spot (Lisp_Object, int, int);
3450 
3451 extern Lisp_Object handle_tab_bar_click (struct frame *,
3452 					 int, int, bool, int);
3453 extern void handle_tool_bar_click (struct frame *,
3454                                    int, int, bool, int);
3455 
3456 extern void expose_frame (struct frame *, int, int, int, int);
3457 extern bool gui_intersect_rectangles (const Emacs_Rectangle *,
3458                                       const Emacs_Rectangle *,
3459                                       Emacs_Rectangle *);
3460 #endif	/* HAVE_WINDOW_SYSTEM */
3461 
3462 extern void note_mouse_highlight (struct frame *, int, int);
3463 extern void gui_clear_window_mouse_face (struct window *);
3464 extern void cancel_mouse_face (struct frame *);
3465 extern bool clear_mouse_face (Mouse_HLInfo *);
3466 extern bool cursor_in_mouse_face_p (struct window *w);
3467 extern void tty_draw_row_with_mouse_face (struct window *, struct glyph_row *,
3468 					  int, int, enum draw_glyphs_face);
3469 extern void display_tty_menu_item (const char *, int, int, int, int, bool);
3470 
3471 /* Flags passed to try_window.  */
3472 #define TRY_WINDOW_CHECK_MARGINS	(1 << 0)
3473 #define TRY_WINDOW_IGNORE_FONTS_CHANGE	(1 << 1)
3474 
3475 int lookup_fringe_bitmap (Lisp_Object);
3476 void draw_fringe_bitmap (struct window *, struct glyph_row *, int);
3477 void draw_row_fringe_bitmaps (struct window *, struct glyph_row *);
3478 bool draw_window_fringes (struct window *, bool);
3479 bool update_window_fringes (struct window *, bool);
3480 
3481 void gui_init_fringe (struct redisplay_interface *);
3482 
3483 #ifdef HAVE_NTGUI
3484 void w32_reset_fringes (void);
3485 #endif
3486 
3487 extern unsigned row_hash (struct glyph_row *);
3488 
3489 extern bool buffer_flipping_blocked_p (void);
3490 
3491 /* Defined in image.c */
3492 
3493 #ifdef HAVE_WINDOW_SYSTEM
3494 
3495 extern ptrdiff_t image_bitmap_pixmap (struct frame *, ptrdiff_t);
3496 extern void image_reference_bitmap (struct frame *, ptrdiff_t);
3497 extern ptrdiff_t image_create_bitmap_from_data (struct frame *, char *,
3498                                                 unsigned int, unsigned int);
3499 extern ptrdiff_t image_create_bitmap_from_file (struct frame *, Lisp_Object);
3500 #if defined HAVE_XPM && defined HAVE_X_WINDOWS && !defined USE_GTK
3501 extern ptrdiff_t x_create_bitmap_from_xpm_data (struct frame *, const char **);
3502 #endif
3503 #ifndef image_destroy_bitmap
3504 extern void image_destroy_bitmap (struct frame *, ptrdiff_t);
3505 #endif
3506 extern void image_destroy_all_bitmaps (Display_Info *);
3507 #ifdef HAVE_X_WINDOWS
3508 extern void x_create_bitmap_mask (struct frame *, ptrdiff_t);
3509 #ifndef USE_CAIRO
3510 extern void x_kill_gs_process (Pixmap, struct frame *);
3511 #endif	/* !USE_CAIRO */
3512 #endif
3513 extern Lisp_Object image_find_image_file (Lisp_Object);
3514 
3515 struct image_cache *make_image_cache (void);
3516 void free_image_cache (struct frame *);
3517 void clear_image_caches (Lisp_Object);
3518 void mark_image_cache (struct image_cache *);
3519 bool valid_image_p (Lisp_Object);
3520 void prepare_image_for_display (struct frame *, struct image *);
3521 ptrdiff_t lookup_image (struct frame *, Lisp_Object, int);
3522 
3523 #if defined HAVE_X_WINDOWS || defined USE_CAIRO || defined HAVE_NS \
3524   || defined HAVE_HAIKU
3525 #define RGB_PIXEL_COLOR unsigned long
3526 #endif
3527 
3528 #ifdef HAVE_NTGUI
3529 #define RGB_PIXEL_COLOR COLORREF
3530 #endif
3531 
3532 RGB_PIXEL_COLOR image_background (struct image *, struct frame *,
3533                                   Emacs_Pix_Context img);
3534 int image_background_transparent (struct image *, struct frame *,
3535                                   Emacs_Pix_Context mask);
3536 
3537 int image_ascent (struct image *, struct face *, struct glyph_slice *);
3538 
3539 #endif
3540 
3541 /* Defined in sysdep.c */
3542 
3543 void get_tty_size (int, int *, int *);
3544 void request_sigio (void);
3545 void unrequest_sigio (void);
3546 bool tabs_safe_p (int);
3547 void init_baud_rate (int);
3548 void init_sigio (int);
3549 
3550 /* Defined in xfaces.c.  */
3551 
3552 #ifdef HAVE_X_WINDOWS
3553 void unload_color (struct frame *, unsigned long);
3554 void x_free_colors (struct frame *, unsigned long *, int);
3555 #endif
3556 
3557 void update_face_from_frame_parameter (struct frame *, Lisp_Object,
3558                                        Lisp_Object);
3559 extern bool tty_defined_color (struct frame *, const char *, Emacs_Color *,
3560                                bool, bool);
3561 bool parse_color_spec (const char *,
3562                        unsigned short *, unsigned short *, unsigned short *);
3563 
3564 Lisp_Object tty_color_name (struct frame *, int);
3565 void clear_face_cache (bool);
3566 unsigned long load_color (struct frame *, struct face *, Lisp_Object,
3567                           enum lface_attribute_index);
3568 char *choose_face_font (struct frame *, Lisp_Object *, Lisp_Object,
3569                         int *);
3570 #ifdef HAVE_WINDOW_SYSTEM
3571 void prepare_face_for_display (struct frame *, struct face *);
3572 #endif
3573 int lookup_named_face (struct window *, struct frame *, Lisp_Object, bool);
3574 int lookup_basic_face (struct window *, struct frame *, int);
3575 int smaller_face (struct frame *, int, int);
3576 int face_with_height (struct frame *, int, int);
3577 int lookup_derived_face (struct window *, struct frame *,
3578                          Lisp_Object, int, bool);
3579 void init_frame_faces (struct frame *);
3580 void free_frame_faces (struct frame *);
3581 void recompute_basic_faces (struct frame *);
3582 int face_at_buffer_position (struct window *, ptrdiff_t, ptrdiff_t *,
3583                              ptrdiff_t, bool, int, enum lface_attribute_index);
3584 int face_for_overlay_string (struct window *, ptrdiff_t, ptrdiff_t *, ptrdiff_t,
3585                              bool, Lisp_Object, enum lface_attribute_index);
3586 int face_at_string_position (struct window *, Lisp_Object, ptrdiff_t, ptrdiff_t,
3587                              ptrdiff_t *, enum face_id, bool,
3588                              enum lface_attribute_index);
3589 int merge_faces (struct window *, Lisp_Object, int, int);
3590 int compute_char_face (struct frame *, int, Lisp_Object);
3591 void free_all_realized_faces (Lisp_Object);
3592 extern char unspecified_fg[], unspecified_bg[];
3593 
3594 /* Defined in xfns.c.  */
3595 
3596 #ifdef HAVE_X_WINDOWS
3597 void gamma_correct (struct frame *, XColor *);
3598 #endif
3599 #ifdef HAVE_NTGUI
3600 void gamma_correct (struct frame *, COLORREF *);
3601 #endif
3602 
3603 #ifdef HAVE_WINDOW_SYSTEM
3604 
3605 extern void start_hourglass (void);
3606 extern void cancel_hourglass (void);
3607 
3608 /* Returns the background color of IMG, calculating one heuristically if
3609    necessary.  If non-zero, XIMG is an existing XImage object to use for
3610    the heuristic.  */
3611 
3612 #define IMAGE_BACKGROUND(img, f, ximg)					      \
3613    ((img)->background_valid						      \
3614     ? (img)->background							      \
3615     : image_background (img, f, ximg))
3616 
3617 /* Returns true if IMG has a `transparent' background, using heuristics
3618    to decide if necessary.  If non-zero, MASK is an existing XImage
3619    object to use for the heuristic.  */
3620 
3621 #define IMAGE_BACKGROUND_TRANSPARENT(img, f, mask)			      \
3622    ((img)->background_transparent_valid					      \
3623     ? (img)->background_transparent					      \
3624     : image_background_transparent (img, f, mask))
3625 
3626 #endif /* HAVE_WINDOW_SYSTEM */
3627 
3628 
3629 /* Defined in xmenu.c.  */
3630 
3631 int popup_activated (void);
3632 
3633 /* Defined in dispnew.c.  */
3634 
3635 extern Lisp_Object buffer_posn_from_coords (struct window *,
3636                                             int *, int *,
3637                                             struct display_pos *,
3638                                             Lisp_Object *,
3639                                             int *, int *, int *, int *);
3640 extern Lisp_Object mode_line_string (struct window *, enum window_part,
3641                                      int *, int *, ptrdiff_t *,
3642                                      Lisp_Object *,
3643                                      int *, int *, int *, int *);
3644 extern Lisp_Object marginal_area_string (struct window *, enum window_part,
3645                                          int *, int *, ptrdiff_t *,
3646                                          Lisp_Object *,
3647                                          int *, int *, int *, int *);
3648 extern void redraw_frame (struct frame *);
3649 extern bool update_frame (struct frame *, bool, bool);
3650 extern void update_frame_with_menu (struct frame *, int, int);
3651 extern int update_mouse_position (struct frame *, int, int);
3652 extern void bitch_at_user (void);
3653 extern void adjust_frame_glyphs (struct frame *);
3654 void free_glyphs (struct frame *);
3655 void free_window_matrices (struct window *);
3656 void check_glyph_memory (void);
3657 void mirrored_line_dance (struct glyph_matrix *, int, int, int *, char *);
3658 void clear_glyph_matrix (struct glyph_matrix *);
3659 void clear_current_matrices (struct frame *f);
3660 void clear_desired_matrices (struct frame *);
3661 void shift_glyph_matrix (struct window *, struct glyph_matrix *,
3662                          int, int, int);
3663 void rotate_matrix (struct glyph_matrix *, int, int, int);
3664 void increment_matrix_positions (struct glyph_matrix *,
3665                                  int, int, ptrdiff_t, ptrdiff_t);
3666 void blank_row (struct window *, struct glyph_row *, int);
3667 void clear_glyph_matrix_rows (struct glyph_matrix *, int, int);
3668 void clear_glyph_row (struct glyph_row *);
3669 void prepare_desired_row (struct window *, struct glyph_row *, bool);
3670 void update_single_window (struct window *);
3671 #ifdef HAVE_WINDOW_SYSTEM
3672 extern void gui_update_window_begin (struct window *);
3673 extern void gui_update_window_end (struct window *, bool, bool);
3674 #endif
3675 void do_pending_window_change (bool);
3676 void change_frame_size (struct frame *, int, int, bool, bool, bool);
3677 void init_display (void);
3678 void syms_of_display (void);
3679 extern void spec_glyph_lookup_face (struct window *, GLYPH *);
3680 extern void fill_up_frame_row_with_spaces (struct glyph_row *, int);
3681 
3682 /* Defined in terminal.c.  */
3683 
3684 extern void ring_bell (struct frame *);
3685 extern void update_begin (struct frame *);
3686 extern void update_end (struct frame *);
3687 extern void set_terminal_window (struct frame *, int);
3688 extern void cursor_to (struct frame *, int, int);
3689 extern void raw_cursor_to (struct frame *, int, int);
3690 extern void clear_to_end (struct frame *);
3691 extern void clear_frame (struct frame *);
3692 extern void clear_end_of_line (struct frame *, int);
3693 extern void write_glyphs (struct frame *, struct glyph *, int);
3694 extern void insert_glyphs (struct frame *, struct glyph *, int);
3695 extern void delete_glyphs (struct frame *, int);
3696 extern void ins_del_lines (struct frame *, int, int);
3697 
3698 extern struct terminal *init_initial_terminal (void);
3699 
3700 
3701 /* Defined in term.c */
3702 
3703 extern void tty_turn_off_insert (struct tty_display_info *);
3704 extern int string_cost (const char *);
3705 extern int per_line_cost (const char *);
3706 extern void calculate_costs (struct frame *);
3707 extern void produce_glyphs (struct it *);
3708 extern bool tty_capable_p (struct tty_display_info *, unsigned);
3709 extern void set_tty_color_mode (struct tty_display_info *, struct frame *);
3710 extern void create_tty_output (struct frame *);
3711 extern struct terminal *init_tty (const char *, const char *, bool);
3712 extern void tty_append_glyph (struct it *);
3713 
3714 /* All scrolling costs measured in characters.
3715    So no cost can exceed the area of a frame, measured in characters.
3716    Let's hope this is never more than 1000000 characters.  */
3717 enum { SCROLL_INFINITY = 1000000 };
3718 
3719 /* Defined in scroll.c */
3720 
3721 extern int scrolling_max_lines_saved (int, int, unsigned *, unsigned *, int *);
3722 extern void do_line_insertion_deletion_costs (struct frame *, const char *,
3723                                               const char *, const char *,
3724 					      const char *, const char *,
3725 					      const char *, int);
3726 void scrolling_1 (struct frame *, int, int, int, int *, int *, unsigned *,
3727                   unsigned *, int);
3728 
3729 /* Defined in frame.c */
3730 
3731 #ifdef HAVE_WINDOW_SYSTEM
3732 
3733 /* Types we might convert a resource string into.  */
3734 enum resource_types
3735 {
3736   RES_TYPE_NUMBER,
3737   RES_TYPE_FLOAT,
3738   RES_TYPE_BOOLEAN,
3739   RES_TYPE_STRING,
3740   RES_TYPE_SYMBOL,
3741   RES_TYPE_BOOLEAN_NUMBER
3742 };
3743 
3744 extern Display_Info *check_x_display_info (Lisp_Object);
3745 extern Lisp_Object gui_display_get_arg (Display_Info *, Lisp_Object,
3746                                         Lisp_Object, const char *, const char *,
3747                                         enum resource_types);
3748 extern Lisp_Object gui_frame_get_and_record_arg (struct frame *, Lisp_Object,
3749                                                  Lisp_Object,
3750                                                  const char *, const char *,
3751                                                  enum resource_types);
3752 extern Lisp_Object gui_default_parameter (struct frame *, Lisp_Object,
3753                                           Lisp_Object, Lisp_Object,
3754                                           const char *, const char *,
3755                                           enum resource_types);
3756 
3757 extern bool gui_mouse_grabbed (Display_Info *);
3758 extern void gui_redo_mouse_highlight (Display_Info *);
3759 
3760 #endif /* HAVE_WINDOW_SYSTEM */
3761 
3762 INLINE_HEADER_END
3763 
3764 #endif /* not DISPEXTERN_H_INCLUDED */
3765