root/src/dispextern.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. xstrcasecmp
  2. GLYPH_CHAR
  3. GLYPH_FACE
  4. GLYPH_CODE_CHAR
  5. GLYPH_CODE_FACE
  6. face_tty_specified_color
  7. FACE_SUITABLE_FOR_ASCII_CHAR_P
  8. FACE_FOR_CHAR
  9. GLYPH_CHAR_VALID_P
  10. GLYPH_CODE_P
  11. reset_mouse_highlight

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

/* [<][>][^][v][top][bottom][index][help] */