/* Implementation of GUI terminal on the Mac OS. Copyright (C) 2000 Free Software Foundation, Inc. This file is part of GNU Emacs. GNU Emacs is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Contributed by Andrew Choi (akochoi@users.sourceforge.net). */ #include /* On 4.3 these lose if they come after xterm.h. */ /* Putting these at the beginning seems to be standard for other .c files. */ #include #include #include "lisp.h" #include "blockinput.h" /* Need syssignal.h for various externs and definitions that may be required by some configurations for calls to signal later in this source file. */ #include "syssignal.h" /* This may include sys/types.h, and that somehow loses if this is not done before the other system files. */ #include "macterm.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined (__MRC__) || defined (CODEWARRIOR_VERSION_6) #include #endif #if __profile__ #include #endif #include #include "systty.h" #include "systime.h" #ifndef INCLUDED_FCNTL #include #endif #include #include #include #include #include "charset.h" #include "ccl.h" #include "frame.h" #include "dispextern.h" #include "fontset.h" #include "termhooks.h" #include "termopts.h" #include "termchar.h" #include "gnu.h" #include "disptab.h" #include "buffer.h" #include "window.h" #include "keyboard.h" #include "intervals.h" #include "process.h" #include "atimer.h" #include "coding.h" #ifdef HAVE_UNISTD_H #include #endif #ifndef USE_X_TOOLKIT #define x_any_window_to_frame x_window_to_frame #define x_top_window_to_frame x_window_to_frame #endif #ifndef min #define min(a,b) ((a) < (b) ? (a) : (b)) #endif #ifndef max #define max(a,b) ((a) > (b) ? (a) : (b)) #endif #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER)) /* Bitmaps for truncated lines. */ enum bitmap_type { NO_BITMAP, LEFT_TRUNCATION_BITMAP, RIGHT_TRUNCATION_BITMAP, OVERLAY_ARROW_BITMAP, CONTINUED_LINE_BITMAP, CONTINUATION_LINE_BITMAP, ZV_LINE_BITMAP }; /* Bitmap drawn to indicate lines not displaying text if `indicate-empty-lines' is non-nil. */ #define zv_width 8 #define zv_height 8 static unsigned char zv_bits[] = { 0x00, 0x00, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00}; /* An arrow like this: `<-'. */ #define left_width 8 #define left_height 8 static unsigned char left_bits[] = { 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18}; /* Right truncation arrow bitmap `->'. */ #define right_width 8 #define right_height 8 static unsigned char right_bits[] = { 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18}; /* Marker for continued lines. */ #define continued_width 8 #define continued_height 8 static unsigned char continued_bits[] = { 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e}; /* Marker for continuation lines. */ #define continuation_width 8 #define continuation_height 8 static unsigned char continuation_bits[] = { 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c}; /* Overlay arrow bitmap. */ #if 0 /* A bomb. */ #define ov_width 8 #define ov_height 8 static unsigned char ov_bits[] = { 0x0c, 0x10, 0x3c, 0x7e, 0x5e, 0x5e, 0x46, 0x3c}; #else /* A triangular arrow. */ #define ov_width 8 #define ov_height 8 static unsigned char ov_bits[] = { 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0}; #endif extern Lisp_Object Qhelp_echo; /* Non-zero means Emacs uses toolkit scroll bars. */ int x_toolkit_scroll_bars_p; /* If a string, XTread_socket generates an event to display that string. (The display is done in read_char.) */ static Lisp_Object help_echo; static Lisp_Object help_echo_window; static Lisp_Object help_echo_object; static int help_echo_pos; /* Temporary variable for XTread_socket. */ static Lisp_Object previous_help_echo; /* Non-zero means that a HELP_EVENT has been generated since Emacs start. */ static int any_help_event_p; /* Non-zero means draw block and hollow cursor as wide as the glyph under it. For example, if a block cursor is over a tab, it will be drawn as wide as that tab on the display. */ int x_stretch_cursor_p; /* This is a chain of structures for all the X displays currently in use. */ struct x_display_info *x_display_list; /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE), one for each element of x_display_list and in the same order. NAME is the name of the frame. FONT-LIST-CACHE records previous values returned by x-list-fonts. */ Lisp_Object x_display_name_list; /* This is display since Mac does not support multiple ones. */ struct mac_display_info one_mac_display_info; /* Frame being updated by update_frame. This is declared in term.c. This is set by update_begin and looked at by all the XT functions. It is zero while not inside an update. In that case, the XT functions assume that `selected_frame' is the frame to apply to. */ extern struct frame *updating_frame; extern int waiting_for_input; /* This is a frame waiting to be auto-raised, within XTread_socket. */ struct frame *pending_autoraise_frame; /* Nominal cursor position -- where to draw output. HPOS and VPOS are window relative glyph matrix coordinates. X and Y are window relative pixel coordinates. */ struct cursor_pos output_cursor; /* Non-zero means user is interacting with a toolkit scroll bar. */ static int toolkit_scroll_bar_interaction; /* Mouse movement. Formerly, we used PointerMotionHintMask (in standard_event_mask) so that we would have to call XQueryPointer after each MotionNotify event to ask for another such event. However, this made mouse tracking slow, and there was a bug that made it eventually stop. Simply asking for MotionNotify all the time seems to work better. In order to avoid asking for motion events and then throwing most of them away or busy-polling the server for mouse positions, we ask the server for pointer motion hints. This means that we get only one event per group of mouse movements. "Groups" are delimited by other kinds of events (focus changes and button clicks, for example), or by XQueryPointer calls; when one of these happens, we get another MotionNotify event the next time the mouse moves. This is at least as efficient as getting motion events when mouse tracking is on, and I suspect only negligibly worse when tracking is off. */ /* Where the mouse was last time we reported a mouse event. */ FRAME_PTR last_mouse_frame; static Rect last_mouse_glyph; static Lisp_Object last_mouse_press_frame; /* The scroll bar in which the last X motion event occurred. If the last X motion event occurred in a scroll bar, we set this so XTmouse_position can know whether to report a scroll bar motion or an ordinary motion. If the last X motion event didn't occur in a scroll bar, we set this to Qnil, to tell XTmouse_position to return an ordinary motion event. */ static Lisp_Object last_mouse_scroll_bar; /* This is a hack. We would really prefer that XTmouse_position would return the time associated with the position it returns, but there doesn't seem to be any way to wrest the time-stamp from the server along with the position query. So, we just keep track of the time of the last movement we received, and return that in hopes that it's somewhat accurate. */ static Time last_mouse_movement_time; enum mouse_tracking_type { mouse_tracking_none, mouse_tracking_mouse_movement, mouse_tracking_scroll_bar }; enum mouse_tracking_type mouse_tracking_in_progress = mouse_tracking_none; struct scroll_bar *tracked_scroll_bar = NULL; /* Incremented by XTread_socket whenever it really tries to read events. */ #ifdef __STDC__ static int volatile input_signal_count; #else static int input_signal_count; #endif /* Used locally within XTread_socket. */ static int x_noop_count; /* Initial values of argv and argc. */ extern char **initial_argv; extern int initial_argc; extern Lisp_Object Vcommand_line_args, Vsystem_name; /* Tells if a window manager is present or not. */ extern Lisp_Object Vx_no_window_manager; extern Lisp_Object Qface, Qmouse_face; extern int errno; /* A mask of extra modifier bits to put into every keyboard char. */ extern int extra_keyboard_modifiers; static Lisp_Object Qvendor_specific_keysyms; #if 0 extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *)); #endif extern Lisp_Object x_icon_type P_ ((struct frame *)); #if __MRC__ QDGlobals qd; /* QuickDraw global information structure. */ #endif /* Enumeration for overriding/changing the face to use for drawing glyphs in x_draw_glyphs. */ enum draw_glyphs_face { DRAW_NORMAL_TEXT, DRAW_INVERSE_VIDEO, DRAW_CURSOR, DRAW_MOUSE_FACE, DRAW_IMAGE_RAISED, DRAW_IMAGE_SUNKEN }; struct frame * x_window_to_frame (struct mac_display_info *, WindowPtr); struct mac_display_info *mac_display_info_for_display (Display *); static void x_update_window_end P_ ((struct window *, int, int)); static void frame_to_window_pixel_xy P_ ((struct window *, int *, int *)); void x_delete_display P_ ((struct x_display_info *)); static unsigned int x_mac_to_emacs_modifiers P_ ((struct x_display_info *, unsigned short)); static int fast_find_position P_ ((struct window *, int, int *, int *, int *, int *)); static void set_output_cursor P_ ((struct cursor_pos *)); static struct glyph *x_y_to_hpos_vpos P_ ((struct window *, int, int, int *, int *, int *)); static void note_mode_line_highlight P_ ((struct window *, int, int)); static void note_mouse_highlight P_ ((struct frame *, int, int)); static void note_tool_bar_highlight P_ ((struct frame *f, int, int)); static void x_handle_tool_bar_click P_ ((struct frame *, XButtonEvent *)); static void show_mouse_face P_ ((struct x_display_info *, enum draw_glyphs_face)); void clear_mouse_face P_ ((struct mac_display_info *)); static int x_io_error_quitter P_ ((Display *)); int x_catch_errors P_ ((Display *)); void x_uncatch_errors P_ ((Display *, int)); void x_lower_frame P_ ((struct frame *)); void x_scroll_bar_clear P_ ((struct frame *)); int x_had_errors_p P_ ((Display *)); void x_wm_set_size_hint P_ ((struct frame *, long, int)); void x_raise_frame P_ ((struct frame *)); void x_set_window_size P_ ((struct frame *, int, int, int)); void x_wm_set_window_state P_ ((struct frame *, int)); void x_wm_set_icon_pixmap P_ ((struct frame *, int)); void x_initialize P_ ((void)); static void x_font_min_bounds P_ ((XFontStruct *, int *, int *)); static int x_compute_min_glyph_bounds P_ ((struct frame *)); enum text_cursor_kinds x_specified_cursor_type P_ ((Lisp_Object, int *)); static void x_draw_phys_cursor_glyph P_ ((struct window *, struct glyph_row *, enum draw_glyphs_face)); static void x_update_end P_ ((struct frame *)); static void XTframe_up_to_date P_ ((struct frame *)); static void XTreassert_line_highlight P_ ((int, int)); static void x_change_line_highlight P_ ((int, int, int, int)); static void XTset_terminal_modes P_ ((void)); static void XTreset_terminal_modes P_ ((void)); static void XTcursor_to P_ ((int, int, int, int)); static void x_write_glyphs P_ ((struct glyph *, int)); static void x_clear_end_of_line P_ ((int)); static void x_clear_frame P_ ((void)); static void x_clear_cursor P_ ((struct window *)); static void frame_highlight P_ ((struct frame *)); static void frame_unhighlight P_ ((struct frame *)); static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *)); static void XTframe_rehighlight P_ ((struct frame *)); static void x_frame_rehighlight P_ ((struct x_display_info *)); static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *)); static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int)); static int x_intersect_rectangles P_ ((Rect *, Rect *, Rect *)); static void expose_frame P_ ((struct frame *, int, int, int, int)); static void expose_window_tree P_ ((struct window *, Rect *)); static void expose_window P_ ((struct window *, Rect *)); static void expose_area P_ ((struct window *, struct glyph_row *, XRectangle *, enum glyph_row_area)); static void expose_line P_ ((struct window *, struct glyph_row *, XRectangle *)); void x_display_cursor (struct window *, int, int, int, int, int); void x_update_cursor P_ ((struct frame *, int)); static void x_update_cursor_in_window_tree P_ ((struct window *, int)); static void x_update_window_cursor P_ ((struct window *, int)); static void x_erase_phys_cursor P_ ((struct window *)); void x_display_and_set_cursor P_ ((struct window *, int, int, int, int, int)); static void x_draw_bitmap P_ ((struct window *, struct glyph_row *, enum bitmap_type)); static void x_clip_to_row P_ ((struct window *, struct glyph_row *, GC, int)); static int x_phys_cursor_in_rect_p P_ ((struct window *, Rect *)); static void x_draw_row_bitmaps P_ ((struct window *, struct glyph_row *)); static void note_overwritten_text_cursor P_ ((struct window *, int, int)); static void x_flush P_ ((struct frame *f)); static void x_update_begin P_ ((struct frame *)); static void x_update_window_begin P_ ((struct window *)); static void x_draw_vertical_border P_ ((struct window *)); static void x_after_update_window_line P_ ((struct glyph_row *)); static INLINE void take_vertical_position_into_account P_ ((struct it *)); static void x_produce_stretch_glyph P_ ((struct it *)); static void activate_scroll_bars (FRAME_PTR); static void deactivate_scroll_bars (FRAME_PTR); extern int image_ascent (struct image *, struct face *); void x_set_offset (struct frame *, int, int, int); int x_bitmap_icon (struct frame *, Lisp_Object); void x_make_frame_visible (struct frame *); extern void window_scroll (Lisp_Object, int, int, int); /* Defined in macmenu.h. */ extern void menubar_selection_callback (FRAME_PTR, int); extern void set_frame_menubar (FRAME_PTR, int, int); /* X display function emulation */ /* Structure borrowed from Xlib.h to represent two-byte characters in dumpglyphs. */ typedef struct { unsigned char byte1; unsigned char byte2; } XChar2b; static void XFreePixmap (display, pixmap) Display *display; Pixmap pixmap; { PixMap *p = (PixMap *) pixmap; xfree (p->baseAddr); xfree (p); } /* Set foreground color for subsequent QuickDraw commands. Assume graphic port has already been set. */ static void mac_set_forecolor (unsigned long color) { RGBColor fg_color; fg_color.red = RED_FROM_ULONG (color) * 256; fg_color.green = GREEN_FROM_ULONG (color) * 256; fg_color.blue = BLUE_FROM_ULONG (color) * 256; RGBForeColor (&fg_color); } /* Set background color for subsequent QuickDraw commands. Assume graphic port has already been set. */ static void mac_set_backcolor (unsigned long color) { RGBColor bg_color; bg_color.red = RED_FROM_ULONG (color) * 256; bg_color.green = GREEN_FROM_ULONG (color) * 256; bg_color.blue = BLUE_FROM_ULONG (color) * 256; RGBBackColor (&bg_color); } /* Set foreground and background color for subsequent QuickDraw commands. Assume that the graphic port has already been set. */ static void mac_set_colors (GC gc) { mac_set_forecolor (gc->foreground); mac_set_backcolor (gc->background); } /* Mac version of XDrawLine. */ static void XDrawLine (display, w, gc, x1, y1, x2, y2) Display *display; WindowPtr w; GC gc; int x1, y1, x2, y2; { SetPort (w); mac_set_colors (gc); MoveTo (x1, y1); LineTo (x2, y2); } /* Mac version of XClearArea. */ void XClearArea (display, w, x, y, width, height, exposures) Display *display; WindowPtr w; int x, y; unsigned int width, height; int exposures; { struct mac_output *mwp = (mac_output *) GetWRefCon (w); Rect r; XGCValues xgc; xgc.foreground = mwp->foreground_pixel; xgc.background = mwp->background_pixel; SetPort (w); mac_set_colors (&xgc); SetRect (&r, x, y, x + width, y + height); EraseRect (&r); } /* Mac version of XClearWindow. */ static void XClearWindow (display, w) Display *display; WindowPtr w; { struct mac_output *mwp = (mac_output *) GetWRefCon (w); XGCValues xgc; xgc.foreground = mwp->foreground_pixel; xgc.background = mwp->background_pixel; SetPort (w); mac_set_colors (&xgc); EraseRect (&(w->portRect)); } /* Mac replacement for XCopyArea. */ static void mac_draw_bitmap (display, w, gc, x, y, bitmap) Display *display; WindowPtr w; GC gc; int x, y; BitMap *bitmap; { Rect r; SetPort (w); mac_set_colors (gc); SetRect (&r, x, y, x + bitmap->bounds.right, y + bitmap->bounds.bottom); CopyBits (bitmap, &(w->portBits), &(bitmap->bounds), &r, srcCopy, 0); } /* Mac replacement for XSetClipRectangles. */ static void mac_set_clip_rectangle (display, w, r) Display *display; WindowPtr w; Rect *r; { SetPort (w); ClipRect (r); } /* Mac replacement for XSetClipMask. */ static void mac_reset_clipping (display, w) Display *display; WindowPtr w; { Rect r; SetPort (w); SetRect (&r, -32767, -32767, 32767, 32767); ClipRect (&r); } /* Mac replacement for XCreateBitmapFromBitmapData. */ static void mac_create_bitmap_from_bitmap_data (bitmap, bits, w, h) BitMap *bitmap; char *bits; int w, h; { int bytes_per_row, i, j; bitmap->rowBytes = (w + 15) / 16 * 2; /* must be on word boundary */ bitmap->baseAddr = xmalloc (bitmap->rowBytes * h); if (!bitmap->baseAddr) abort (); bzero (bitmap->baseAddr, bitmap->rowBytes * h); for (i = 0; i < h; i++) for (j = 0; j < w; j++) if (BitTst (bits, i * w + j)) BitSet (bitmap->baseAddr, i * bitmap->rowBytes * 8 + j); SetRect (&(bitmap->bounds), 0, 0, w, h); } static void mac_free_bitmap (bitmap) BitMap *bitmap; { xfree (bitmap->baseAddr); } /* Mac replacement for XFillRectangle. */ static void XFillRectangle (display, w, gc, x, y, width, height) Display *display; WindowPtr w; GC gc; int x, y; unsigned int width, height; { Rect r; SetPort (w); mac_set_colors (gc); SetRect (&r, x, y, x + width, y + height); PaintRect (&r); /* using foreground color of gc */ } /* Mac replacement for XDrawRectangle: dest is a window. */ static void mac_draw_rectangle (display, w, gc, x, y, width, height) Display *display; WindowPtr w; GC gc; int x, y; unsigned int width, height; { Rect r; SetPort (w); mac_set_colors (gc); SetRect (&r, x, y, x + width + 1, y + height + 1); FrameRect (&r); /* using foreground color of gc */ } /* Mac replacement for XDrawRectangle: dest is a Pixmap. */ static void mac_draw_rectangle_to_pixmap (display, p, gc, x, y, width, height) Display *display; Pixmap p; GC gc; int x, y; unsigned int width, height; { #if 0 /* MAC_TODO: draw a rectangle in a PixMap */ Rect r; SetPort (w); mac_set_colors (gc); SetRect (&r, x, y, x + width, y + height); FrameRect (&r); /* using foreground color of gc */ #endif } static void mac_draw_string_common (display, w, gc, x, y, buf, nchars, mode, bytes_per_char) Display *display; WindowPtr w; GC gc; int x, y; char *buf; int nchars, mode, bytes_per_char; { SetPort (w); mac_set_colors (gc); TextFont (gc->font->mac_fontnum); TextSize (gc->font->mac_fontsize); TextFace (gc->font->mac_fontface); TextMode (mode); MoveTo (x, y); DrawText (buf, 0, nchars * bytes_per_char); } /* Mac replacement for XDrawString. */ static void XDrawString (display, w, gc, x, y, buf, nchars) Display *display; WindowPtr w; GC gc; int x, y; char *buf; int nchars; { mac_draw_string_common (display, w, gc, x, y, buf, nchars, srcOr, 1); } /* Mac replacement for XDrawString16. */ static void XDrawString16 (display, w, gc, x, y, buf, nchars) Display *display; WindowPtr w; GC gc; int x, y; XChar2b *buf; int nchars; { mac_draw_string_common (display, w, gc, x, y, (char *) buf, nchars, srcOr, 2); } /* Mac replacement for XDrawImageString. */ static void XDrawImageString (display, w, gc, x, y, buf, nchars) Display *display; WindowPtr w; GC gc; int x, y; char *buf; int nchars; { mac_draw_string_common (display, w, gc, x, y, buf, nchars, srcCopy, 1); } /* Mac replacement for XDrawString16. */ static void XDrawImageString16 (display, w, gc, x, y, buf, nchars) Display *display; WindowPtr w; GC gc; int x, y; XChar2b *buf; int nchars; { mac_draw_string_common (display, w, gc, x, y, (char *) buf, nchars, srcCopy, 2); } /* Mac replacement for XCopyArea: dest must be window. */ static void mac_copy_area (display, src, dest, gc, src_x, src_y, width, height, dest_x, dest_y) Display *display; Pixmap src; WindowPtr dest; GC gc; int src_x, src_y; unsigned int width, height; int dest_x, dest_y; { Rect src_r, dest_r; SetPort (dest); mac_set_colors (gc); SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); CopyBits ((BitMap *) src, &(dest->portBits), &src_r, &dest_r, srcCopy, 0); } #if 0 /* Convert a pair of local coordinates to global (screen) coordinates. Assume graphic port has been properly set. */ static void local_to_global_coord (short *h, short *v) { Point p; p.h = *h; p.v = *v; LocalToGlobal (&p); *h = p.h; *v = p.v; } #endif /* Mac replacement for XCopyArea: used only for scrolling. */ static void mac_scroll_area (display, w, gc, src_x, src_y, width, height, dest_x, dest_y) Display *display; WindowPtr w; GC gc; int src_x, src_y; unsigned int width, height; int dest_x, dest_y; { Rect src_r, dest_r; SetPort (w); #if 0 mac_set_colors (gc); #endif SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); #if 0 /* Need to use global coordinates and screenBits since src and dest areas overlap in general. */ local_to_global_coord (&src_r.left, &src_r.top); local_to_global_coord (&src_r.right, &src_r.bottom); local_to_global_coord (&dest_r.left, &dest_r.top); local_to_global_coord (&dest_r.right, &dest_r.bottom); CopyBits (&qd.screenBits, &qd.screenBits, &src_r, &dest_r, srcCopy, 0); #else /* In Color QuickDraw, set ForeColor and BackColor as follows to avoid color mapping in CopyBits. Otherwise, it will be slow. */ ForeColor (blackColor); BackColor (whiteColor); CopyBits (&(w->portBits), &(w->portBits), &src_r, &dest_r, srcCopy, 0); mac_set_colors (gc); #endif } /* Mac replacement for XCopyArea: dest must be Pixmap. */ static void mac_copy_area_to_pixmap (display, src, dest, gc, src_x, src_y, width, height, dest_x, dest_y) Display *display; Pixmap src; Pixmap dest; GC gc; int src_x, src_y; unsigned int width, height; int dest_x, dest_y; { Rect src_r, dest_r; int src_right = ((PixMap *) src)->bounds.right; int src_bottom = ((PixMap *) src)->bounds.bottom; int w = src_right - src_x; int h = src_bottom - src_y; mac_set_colors (gc); SetRect (&src_r, src_x, src_y, src_right, src_bottom); SetRect (&dest_r, dest_x, dest_y, dest_x + w, dest_y + h); CopyBits ((BitMap *) src, (BitMap *) dest, &src_r, &dest_r, srcCopy, 0); } /* Mac replacement for XChangeGC. */ static void XChangeGC (void * ignore, XGCValues* gc, unsigned long mask, XGCValues *xgcv) { if (mask & GCForeground) gc->foreground = xgcv->foreground; if (mask & GCBackground) gc->background = xgcv->background; if (mask & GCFont) gc->font = xgcv->font; } /* Mac replacement for XCreateGC. */ XGCValues * XCreateGC (void * ignore, Window window, unsigned long mask, XGCValues *xgcv) { XGCValues *gc = (XGCValues *) xmalloc (sizeof (XGCValues)); bzero (gc, sizeof (XGCValues)); XChangeGC (ignore, gc, mask, xgcv); return gc; } /* Used in xfaces.c. */ void XFreeGC (display, gc) Display *display; GC gc; { xfree (gc); } /* Mac replacement for XGetGCValues. */ static void XGetGCValues (void* ignore, XGCValues *gc, unsigned long mask, XGCValues *xgcv) { XChangeGC (ignore, xgcv, mask, gc); } /* Mac replacement for XSetForeground. */ static void XSetForeground (display, gc, color) Display *display; GC gc; unsigned long color; { gc->foreground = color; } /* Mac replacement for XSetFont. */ static void XSetFont (display, gc, font) Display *display; GC gc; XFontStruct *font; { gc->font = font; } static void XTextExtents16 (XFontStruct *font, XChar2b *text, int nchars, int *direction,int *font_ascent, int *font_descent, XCharStruct *cs) { /* MAC_TODO: Use GetTextMetrics to do this and inline it below. */ } /* x_sync is a no-op on Mac. */ void x_sync (f) void *f; { } /* Flush display of frame F, or of all frames if F is null. */ void x_flush (f) struct frame *f; { #if 0 /* Nothing to do for Mac OS (needed in OS X perhaps?). */ BLOCK_INPUT; if (f == NULL) { Lisp_Object rest, frame; FOR_EACH_FRAME (rest, frame) x_flush (XFRAME (frame)); } else if (FRAME_X_P (f)) XFlush (FRAME_MAC_DISPLAY (f)); UNBLOCK_INPUT; #endif } /* Remove calls to XFlush by defining XFlush to an empty replacement. Calls to XFlush should be unnecessary because the X output buffer is flushed automatically as needed by calls to XPending, XNextEvent, or XWindowEvent according to the XFlush man page. XTread_socket calls XPending. Removing XFlush improves performance. */ #define XFlush(DISPLAY) (void) 0 /* Return the struct mac_display_info corresponding to DPY. There's only one. */ struct mac_display_info * mac_display_info_for_display (dpy) Display *dpy; { return &one_mac_display_info; } /*********************************************************************** Starting and ending an update ***********************************************************************/ /* Start an update of frame F. This function is installed as a hook for update_begin, i.e. it is called when update_begin is called. This function is called prior to calls to x_update_window_begin for each window being updated. Currently, there is nothing to do here because all interesting stuff is done on a window basis. */ void x_update_begin (f) struct frame *f; { /* Nothing to do. */ } /* Start update of window W. Set the global variable updated_window to the window being updated and set output_cursor to the cursor position of W. */ void x_update_window_begin (w) struct window *w; { struct frame *f = XFRAME (WINDOW_FRAME (w)); struct mac_display_info *display_info = FRAME_MAC_DISPLAY_INFO (f); updated_window = w; set_output_cursor (&w->cursor); BLOCK_INPUT; if (f == display_info->mouse_face_mouse_frame) { /* Don't do highlighting for mouse motion during the update. */ display_info->mouse_face_defer = 1; /* If F needs to be redrawn, simply forget about any prior mouse highlighting. */ if (FRAME_GARBAGED_P (f)) display_info->mouse_face_window = Qnil; #if 0 /* Rows in a current matrix containing glyphs in mouse-face have their mouse_face_p flag set, which means that they are always unequal to rows in a desired matrix which never have that flag set. So, rows containing mouse-face glyphs are never scrolled, and we don't have to switch the mouse highlight off here to prevent it from being scrolled. */ /* Can we tell that this update does not affect the window where the mouse highlight is? If so, no need to turn off. Likewise, don't do anything if the frame is garbaged; in that case, the frame's current matrix that we would use is all wrong, and we will redisplay that line anyway. */ if (!NILP (display_info->mouse_face_window) && w == XWINDOW (display_info->mouse_face_window)) { int i; for (i = 0; i < w->desired_matrix->nrows; ++i) if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i)) break; if (i < w->desired_matrix->nrows) clear_mouse_face (display_info); } #endif /* 0 */ } UNBLOCK_INPUT; } /* Draw a vertical window border to the right of window W if W doesn't have vertical scroll bars. */ static void x_draw_vertical_border (w) struct window *w; { struct frame *f = XFRAME (WINDOW_FRAME (w)); /* Redraw borders between horizontally adjacent windows. Don't do it for frames with vertical scroll bars because either the right scroll bar of a window, or the left scroll bar of its neighbor will suffice as a border. */ if (!WINDOW_RIGHTMOST_P (w) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) { int x0, x1, y0, y1; window_box_edges (w, -1, &x0, &y0, &x1, &y1); x1 += FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f); y1 -= 1; XDrawLine (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), f->output_data.mac->normal_gc, x1, y0, x1, y1); } } /* End update of window W (which is equal to updated_window). Draw vertical borders between horizontally adjacent windows, and display W's cursor if CURSOR_ON_P is non-zero. MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing glyphs in mouse-face were overwritten. In that case we have to make sure that the mouse-highlight is properly redrawn. W may be a menu bar pseudo-window in case we don't have X toolkit support. Such windows don't have a cursor, so don't display it here. */ void x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p) struct window *w; int cursor_on_p, mouse_face_overwritten_p; { if (!w->pseudo_window_p) { struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (XFRAME (w->frame)); BLOCK_INPUT; /* If a row with mouse-face was overwritten, arrange for XTframe_up_to_date to redisplay the mouse highlight. */ if (mouse_face_overwritten_p) { dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; dpyinfo->mouse_face_window = Qnil; } if (cursor_on_p) x_display_and_set_cursor (w, 1, output_cursor.hpos, output_cursor.vpos, output_cursor.x, output_cursor.y); x_draw_vertical_border (w); UNBLOCK_INPUT; } updated_window = NULL; } /* End update of frame F. This function is installed as a hook in update_end. */ void x_update_end (f) struct frame *f; { /* Reset the background color of Mac OS Window to that of the frame after update so that it is used by Mac Toolbox to clear the update region before an update event is generated. */ SetPort (FRAME_MAC_WINDOW (f)); mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f)); /* Mouse highlight may be displayed again. */ FRAME_MAC_DISPLAY_INFO (f)->mouse_face_defer = 0; BLOCK_INPUT; XFlush (FRAME_MAC_DISPLAY (f)); UNBLOCK_INPUT; } /* This function is called from various places in xdisp.c whenever a complete update has been performed. The global variable updated_window is not available here. */ void XTframe_up_to_date (f) struct frame *f; { if (FRAME_X_P (f)) { struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); if (dpyinfo->mouse_face_deferred_gc || f == dpyinfo->mouse_face_mouse_frame) { BLOCK_INPUT; if (dpyinfo->mouse_face_mouse_frame) note_mouse_highlight (dpyinfo->mouse_face_mouse_frame, dpyinfo->mouse_face_mouse_x, dpyinfo->mouse_face_mouse_y); dpyinfo->mouse_face_deferred_gc = 0; UNBLOCK_INPUT; } } } /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay arrow bitmaps, or clear the areas where they would be displayed before DESIRED_ROW is made current. The window being updated is found in updated_window. This function It is called from update_window_line only if it is known that there are differences between bitmaps to be drawn between current row and DESIRED_ROW. */ void x_after_update_window_line (desired_row) struct glyph_row *desired_row; { struct window *w = updated_window; xassert (w); if (!desired_row->mode_line_p && !w->pseudo_window_p) { BLOCK_INPUT; x_draw_row_bitmaps (w, desired_row); /* When a window has disappeared, make sure that no rest of full-width rows stays visible in the internal border. */ if (windows_or_buffers_changed) { struct frame *f = XFRAME (w->frame); int width = FRAME_INTERNAL_BORDER_WIDTH (f); int height = desired_row->visible_height; int x = (window_box_right (w, -1) + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f)); int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); XClearArea (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), x, y, width, height, 0); } UNBLOCK_INPUT; } } /* Draw the bitmap WHICH in one of the areas to the left or right of window W. ROW is the glyph row for which to display the bitmap; it determines the vertical position at which the bitmap has to be drawn. */ static void x_draw_bitmap (w, row, which) struct window *w; struct glyph_row *row; enum bitmap_type which; { struct frame *f = XFRAME (WINDOW_FRAME (w)); Display *display = FRAME_MAC_DISPLAY (f); WindowPtr window = FRAME_MAC_WINDOW (f); int x, y, wd, h, dy; unsigned char *bits; BitMap bitmap; XGCValues gcv; struct face *face; /* Must clip because of partially visible lines. */ x_clip_to_row (w, row, 1); switch (which) { case LEFT_TRUNCATION_BITMAP: wd = left_width; h = left_height; bits = left_bits; x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) - wd - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); break; case OVERLAY_ARROW_BITMAP: wd = left_width; h = left_height; bits = ov_bits; x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) - wd - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); break; case RIGHT_TRUNCATION_BITMAP: wd = right_width; h = right_height; bits = right_bits; x = window_box_right (w, -1); x += (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) - wd) / 2; break; case CONTINUED_LINE_BITMAP: wd = right_width; h = right_height; bits = continued_bits; x = window_box_right (w, -1); x += (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) - wd) / 2; break; case CONTINUATION_LINE_BITMAP: wd = continuation_width; h = continuation_height; bits = continuation_bits; x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) - wd - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); break; case ZV_LINE_BITMAP: wd = zv_width; h = zv_height; bits = zv_bits; x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) - wd - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); break; default: abort (); } /* Convert to frame coordinates. Set dy to the offset in the row to start drawing the bitmap. */ y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); dy = (row->height - h) / 2; /* Draw the bitmap. I believe these small pixmaps can be cached by the server. */ face = FACE_FROM_ID (f, BITMAP_AREA_FACE_ID); mac_create_bitmap_from_bitmap_data (&bitmap, bits, wd, h); gcv.foreground = face->foreground; gcv.background = face->background; mac_draw_bitmap (display, window, &gcv, x, y + dy, &bitmap); mac_free_bitmap (&bitmap); mac_reset_clipping (display, window); } /* Draw flags bitmaps for glyph row ROW on window W. Call this function with input blocked. */ static void x_draw_row_bitmaps (w, row) struct window *w; struct glyph_row *row; { struct frame *f = XFRAME (w->frame); enum bitmap_type bitmap; struct face *face; int header_line_height = -1; xassert (interrupt_input_blocked); /* If row is completely invisible, because of vscrolling, we don't have to draw anything. */ if (row->visible_height <= 0) return; face = FACE_FROM_ID (f, BITMAP_AREA_FACE_ID); PREPARE_FACE_FOR_DISPLAY (f, face); /* Decide which bitmap to draw at the left side. */ if (row->overlay_arrow_p) bitmap = OVERLAY_ARROW_BITMAP; else if (row->truncated_on_left_p) bitmap = LEFT_TRUNCATION_BITMAP; else if (MATRIX_ROW_CONTINUATION_LINE_P (row)) bitmap = CONTINUATION_LINE_BITMAP; else if (row->indicate_empty_line_p) bitmap = ZV_LINE_BITMAP; else bitmap = NO_BITMAP; /* Clear flags area if no bitmap to draw or if bitmap doesn't fill the flags area. */ if (bitmap == NO_BITMAP || FRAME_FLAGS_BITMAP_WIDTH (f) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) || row->height > FRAME_FLAGS_BITMAP_HEIGHT (f)) { /* If W has a vertical border to its left, don't draw over it. */ int border = ((XFASTINT (w->left) > 0 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) ? 1 : 0); int left = window_box_left (w, -1); if (header_line_height < 0) header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); #if 0 /* MAC_TODO: stipple */ /* In case the same realized face is used for bitmap areas and for something displayed in the text (e.g. face `region' on mono-displays, the fill style may have been changed to FillSolid in x_draw_glyph_string_background. */ if (face->stipple) XSetFillStyle (FRAME_X_DISPLAY (f), face->gc, FillOpaqueStippled); else XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->background); XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), face->gc, (left - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) + border), WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, row->y)), FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - border, row->visible_height); if (!face->stipple) XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); #endif { XGCValues gcv; gcv.foreground = face->background; XFillRectangle (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), &gcv, (left - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) + border), WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, row->y)), FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - border, row->visible_height); } } /* Draw the left bitmap. */ if (bitmap != NO_BITMAP) x_draw_bitmap (w, row, bitmap); /* Decide which bitmap to draw at the right side. */ if (row->truncated_on_right_p) bitmap = RIGHT_TRUNCATION_BITMAP; else if (row->continued_p) bitmap = CONTINUED_LINE_BITMAP; else bitmap = NO_BITMAP; /* Clear flags area if no bitmap to draw of if bitmap doesn't fill the flags area. */ if (bitmap == NO_BITMAP || FRAME_FLAGS_BITMAP_WIDTH (f) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) || row->height > FRAME_FLAGS_BITMAP_HEIGHT (f)) { int right = window_box_right (w, -1); if (header_line_height < 0) header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); #if 0 /* MAC_TODO: stipple */ /* In case the same realized face is used for bitmap areas and for something displayed in the text (e.g. face `region' on mono-displays, the fill style may have been changed to FillSolid in x_draw_glyph_string_background. */ if (face->stipple) XSetFillStyle (FRAME_X_DISPLAY (f), face->gc, FillOpaqueStippled); else XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->background); XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), face->gc, right, WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, row->y)), FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f), row->visible_height); if (!face->stipple) XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); #endif { XGCValues gcv; gcv.foreground = face->background; XFillRectangle (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), &gcv, right, WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, row->y)), FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f), row->visible_height); } } /* Draw the right bitmap. */ if (bitmap != NO_BITMAP) x_draw_bitmap (w, row, bitmap); } /*********************************************************************** Line Highlighting ***********************************************************************/ /* External interface to control of standout mode. Not used for X frames. Aborts when called. */ void XTreassert_line_highlight (new, vpos) int new, vpos; { abort (); } /* Call this when about to modify line at position VPOS and change whether it is highlighted. Not used for X frames. Aborts when called. */ void x_change_line_highlight (new_highlight, vpos, y, first_unused_hpos) int new_highlight, vpos, y, first_unused_hpos; { abort (); } /* This is called when starting Emacs and when restarting after suspend. When starting Emacs, no X window is mapped. And nothing must be done to Emacs's own window if it is suspended (though that rarely happens). */ void XTset_terminal_modes () { } /* This is called when exiting or suspending Emacs. Exiting will make the X-windows go away, and suspending requires no action. */ void XTreset_terminal_modes () { } /*********************************************************************** Output Cursor ***********************************************************************/ /* Set the global variable output_cursor to CURSOR. All cursor positions are relative to updated_window. */ static void set_output_cursor (cursor) struct cursor_pos *cursor; { output_cursor.hpos = cursor->hpos; output_cursor.vpos = cursor->vpos; output_cursor.x = cursor->x; output_cursor.y = cursor->y; } /* Set a nominal cursor position. HPOS and VPOS are column/row positions in a window glyph matrix. X and Y are window text area relative pixel positions. If this is done during an update, updated_window will contain the window that is being updated and the position is the future output cursor position for that window. If updated_window is null, use selected_window and display the cursor at the given position. */ void XTcursor_to (vpos, hpos, y, x) int vpos, hpos, y, x; { struct window *w; /* If updated_window is not set, work on selected_window. */ if (updated_window) w = updated_window; else w = XWINDOW (selected_window); /* Set the output cursor. */ output_cursor.hpos = hpos; output_cursor.vpos = vpos; output_cursor.x = x; output_cursor.y = y; /* If not called as part of an update, really display the cursor. This will also set the cursor position of W. */ if (updated_window == NULL) { BLOCK_INPUT; x_display_cursor (w, 1, hpos, vpos, x, y); XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ())); UNBLOCK_INPUT; } } /*********************************************************************** Display Iterator ***********************************************************************/ /* Function prototypes of this page. */ static struct face *x_get_glyph_face_and_encoding P_ ((struct frame *, struct glyph *, XChar2b *, int *)); static struct face *x_get_char_face_and_encoding P_ ((struct frame *, int, int, XChar2b *, int)); static XCharStruct *x_per_char_metric P_ ((XFontStruct *, XChar2b *)); static void x_encode_char P_ ((int, XChar2b *, struct font_info *)); static void x_append_glyph P_ ((struct it *)); static void x_append_composite_glyph P_ ((struct it *)); static void x_append_stretch_glyph P_ ((struct it *it, Lisp_Object, int, int, double)); static void x_produce_glyphs P_ ((struct it *)); static void x_produce_image_glyph P_ ((struct it *it)); /* Return a pointer to per-char metric information in FONT of a character pointed by B which is a pointer to an XChar2b. */ #define PER_CHAR_METRIC(font, b) \ ((font)->per_char \ ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \ + (((font)->min_byte1 || (font)->max_byte1) \ ? (((b)->byte1 - (font)->min_byte1) \ * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \ : 0)) \ : &((font)->max_bounds)) /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B is not contained in the font. */ static INLINE XCharStruct * x_per_char_metric (font, char2b) XFontStruct *font; XChar2b *char2b; { /* The result metric information. */ XCharStruct *pcm = NULL; xassert (font && char2b); if (font->per_char != NULL) { if (font->min_byte1 == 0 && font->max_byte1 == 0) { /* min_char_or_byte2 specifies the linear character index corresponding to the first element of the per_char array, max_char_or_byte2 is the index of the last character. A character with non-zero CHAR2B->byte1 is not in the font. A character with byte2 less than min_char_or_byte2 or greater max_char_or_byte2 is not in the font. */ if (char2b->byte1 == 0 && char2b->byte2 >= font->min_char_or_byte2 && char2b->byte2 <= font->max_char_or_byte2) pcm = font->per_char + char2b->byte2 - font->min_char_or_byte2; } else { /* If either min_byte1 or max_byte1 are nonzero, both min_char_or_byte2 and max_char_or_byte2 are less than 256, and the 2-byte character index values corresponding to the per_char array element N (counting from 0) are: byte1 = N/D + min_byte1 byte2 = N\D + min_char_or_byte2 where: D = max_char_or_byte2 - min_char_or_byte2 + 1 / = integer division \ = integer modulus */ if (char2b->byte1 >= font->min_byte1 && char2b->byte1 <= font->max_byte1 && char2b->byte2 >= font->min_char_or_byte2 && char2b->byte2 <= font->max_char_or_byte2) { pcm = (font->per_char + ((font->max_char_or_byte2 - font->min_char_or_byte2 + 1) * (char2b->byte1 - font->min_byte1)) + (char2b->byte2 - font->min_char_or_byte2)); } } } else { /* If the per_char pointer is null, all glyphs between the first and last character indexes inclusive have the same information, as given by both min_bounds and max_bounds. */ if (char2b->byte2 >= font->min_char_or_byte2 && char2b->byte2 <= font->max_char_or_byte2) pcm = &font->max_bounds; } return ((pcm == NULL || (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0)) ? NULL : pcm); } /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is the two-byte form of C. Encoding is returned in *CHAR2B. */ static INLINE void x_encode_char (c, char2b, font_info) int c; XChar2b *char2b; struct font_info *font_info; { int charset = CHAR_CHARSET (c); XFontStruct *font = font_info->font; /* FONT_INFO may define a scheme by which to encode byte1 and byte2. This may be either a program in a special encoder language or a fixed encoding. */ if (font_info->font_encoder) { /* It's a program. */ struct ccl_program *ccl = font_info->font_encoder; if (CHARSET_DIMENSION (charset) == 1) { ccl->reg[0] = charset; ccl->reg[1] = char2b->byte2; } else { ccl->reg[0] = charset; ccl->reg[1] = char2b->byte1; ccl->reg[2] = char2b->byte2; } ccl_driver (ccl, NULL, NULL, 0, 0, NULL); /* We assume that MSBs are appropriately set/reset by CCL program. */ if (font->max_byte1 == 0) /* 1-byte font */ char2b->byte1 = 0, char2b->byte2 = ccl->reg[1]; else char2b->byte1 = ccl->reg[1], char2b->byte2 = ccl->reg[2]; } else if (font_info->encoding[charset]) { /* Fixed encoding scheme. See fontset.h for the meaning of the encoding numbers. */ int enc = font_info->encoding[charset]; if ((enc == 1 || enc == 2) && CHARSET_DIMENSION (charset) == 2) char2b->byte1 |= 0x80; if (enc == 1 || enc == 3) char2b->byte2 |= 0x80; if (enc == 4) { int sjis1, sjis2; ENCODE_SJIS (char2b->byte1, char2b->byte2, sjis1, sjis2); char2b->byte1 = sjis1; char2b->byte2 = sjis2; } } } /* Get face and two-byte form of character C in face FACE_ID on frame F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero means we want to display multibyte text. Value is a pointer to a realized face that is ready for display. */ static INLINE struct face * x_get_char_face_and_encoding (f, c, face_id, char2b, multibyte_p) struct frame *f; int c, face_id; XChar2b *char2b; int multibyte_p; { struct face *face = FACE_FROM_ID (f, face_id); if (!multibyte_p) { /* Unibyte case. We don't have to encode, but we have to make sure to use a face suitable for unibyte. */ char2b->byte1 = 0; char2b->byte2 = c; face_id = FACE_FOR_CHAR (f, face, c); face = FACE_FROM_ID (f, face_id); } else if (c < 128 && face_id < BASIC_FACE_ID_SENTINEL) { /* Case of ASCII in a face known to fit ASCII. */ char2b->byte1 = 0; char2b->byte2 = c; } else { int c1, c2, charset; /* Split characters into bytes. If c2 is -1 afterwards, C is really a one-byte character so that byte1 is zero. */ SPLIT_CHAR (c, charset, c1, c2); if (c2 > 0) char2b->byte1 = c1, char2b->byte2 = c2; else char2b->byte1 = 0, char2b->byte2 = c1; /* Maybe encode the character in *CHAR2B. */ if (face->font != NULL) { struct font_info *font_info = FONT_INFO_FROM_ID (f, face->font_info_id); if (font_info) x_encode_char (c, char2b, font_info); } } /* Make sure X resources of the face are allocated. */ xassert (face != NULL); PREPARE_FACE_FOR_DISPLAY (f, face); return face; } /* Get face and two-byte form of character glyph GLYPH on frame F. The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is a pointer to a realized face that is ready for display. */ static INLINE struct face * x_get_glyph_face_and_encoding (f, glyph, char2b, two_byte_p) struct frame *f; struct glyph *glyph; XChar2b *char2b; int *two_byte_p; { struct face *face; xassert (glyph->type == CHAR_GLYPH); face = FACE_FROM_ID (f, glyph->face_id); if (two_byte_p) *two_byte_p = 0; if (!glyph->multibyte_p) { /* Unibyte case. We don't have to encode, but we have to make sure to use a face suitable for unibyte. */ char2b->byte1 = 0; char2b->byte2 = glyph->u.ch; } else if (glyph->u.ch < 128 && glyph->face_id < BASIC_FACE_ID_SENTINEL) { /* Case of ASCII in a face known to fit ASCII. */ char2b->byte1 = 0; char2b->byte2 = glyph->u.ch; } else { int c1, c2, charset; /* Split characters into bytes. If c2 is -1 afterwards, C is really a one-byte character so that byte1 is zero. */ SPLIT_CHAR (glyph->u.ch, charset, c1, c2); if (c2 > 0) char2b->byte1 = c1, char2b->byte2 = c2; else char2b->byte1 = 0, char2b->byte2 = c1; /* Maybe encode the character in *CHAR2B. */ if (charset != CHARSET_ASCII) { struct font_info *font_info = FONT_INFO_FROM_ID (f, face->font_info_id); if (font_info) { x_encode_char (glyph->u.ch, char2b, font_info); if (two_byte_p) *two_byte_p = ((XFontStruct *) (font_info->font))->max_byte1 > 0; } } } /* Make sure X resources of the face are allocated. */ xassert (face != NULL); PREPARE_FACE_FOR_DISPLAY (f, face); return face; } /* Store one glyph for IT->char_to_display in IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is non-null. */ static INLINE void x_append_glyph (it) struct it *it; { struct glyph *glyph; enum glyph_row_area area = it->area; xassert (it->glyph_row); xassert (it->char_to_display != '\n' && it->char_to_display != '\t'); glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; if (glyph < it->glyph_row->glyphs[area + 1]) { glyph->charpos = CHARPOS (it->position); glyph->object = it->object; glyph->pixel_width = it->pixel_width; glyph->voffset = it->voffset; glyph->type = CHAR_GLYPH; glyph->multibyte_p = it->multibyte_p; glyph->left_box_line_p = it->start_of_box_run_p; glyph->right_box_line_p = it->end_of_box_run_p; glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent || it->phys_descent > it->descent); glyph->padding_p = 0; glyph->glyph_not_available_p = it->glyph_not_available_p; glyph->face_id = it->face_id; glyph->u.ch = it->char_to_display; ++it->glyph_row->used[area]; } } /* Store one glyph for the composition IT->cmp_id in IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is non-null. */ static INLINE void x_append_composite_glyph (it) struct it *it; { struct glyph *glyph; enum glyph_row_area area = it->area; xassert (it->glyph_row); glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; if (glyph < it->glyph_row->glyphs[area + 1]) { glyph->charpos = CHARPOS (it->position); glyph->object = it->object; glyph->pixel_width = it->pixel_width; glyph->voffset = it->voffset; glyph->type = COMPOSITE_GLYPH; glyph->multibyte_p = it->multibyte_p; glyph->left_box_line_p = it->start_of_box_run_p; glyph->right_box_line_p = it->end_of_box_run_p; glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent || it->phys_descent > it->descent); glyph->padding_p = 0; glyph->glyph_not_available_p = 0; glyph->face_id = it->face_id; glyph->u.cmp_id = it->cmp_id; ++it->glyph_row->used[area]; } } /* Change IT->ascent and IT->height according to the setting of IT->voffset. */ static INLINE void take_vertical_position_into_account (it) struct it *it; { if (it->voffset) { if (it->voffset < 0) /* Increase the ascent so that we can display the text higher in the line. */ it->ascent += abs (it->voffset); else /* Increase the descent so that we can display the text lower in the line. */ it->descent += it->voffset; } } /* Produce glyphs/get display metrics for the image IT is loaded with. See the description of struct display_iterator in dispextern.h for an overview of struct display_iterator. */ static void x_produce_image_glyph (it) struct it *it; { struct image *img; struct face *face; xassert (it->what == IT_IMAGE); face = FACE_FROM_ID (it->f, it->face_id); img = IMAGE_FROM_ID (it->f, it->image_id); xassert (img); /* Make sure X resources of the face and image are loaded. */ PREPARE_FACE_FOR_DISPLAY (it->f, face); prepare_image_for_display (it->f, img); it->ascent = it->phys_ascent = image_ascent (img, face); it->descent = it->phys_descent = img->height + 2 * img->vmargin - it->ascent; it->pixel_width = img->width + 2 * img->hmargin; it->nglyphs = 1; if (face->box != FACE_NO_BOX) { it->ascent += face->box_line_width; it->descent += face->box_line_width; if (it->start_of_box_run_p) it->pixel_width += face->box_line_width; if (it->end_of_box_run_p) it->pixel_width += face->box_line_width; } take_vertical_position_into_account (it); if (it->glyph_row) { struct glyph *glyph; enum glyph_row_area area = it->area; glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; if (glyph < it->glyph_row->glyphs[area + 1]) { glyph->charpos = CHARPOS (it->position); glyph->object = it->object; glyph->pixel_width = it->pixel_width; glyph->voffset = it->voffset; glyph->type = IMAGE_GLYPH; glyph->multibyte_p = it->multibyte_p; glyph->left_box_line_p = it->start_of_box_run_p; glyph->right_box_line_p = it->end_of_box_run_p; glyph->overlaps_vertically_p = 0; glyph->padding_p = 0; glyph->glyph_not_available_p = 0; glyph->face_id = it->face_id; glyph->u.img_id = img->id; ++it->glyph_row->used[area]; } } } /* Append a stretch glyph to IT->glyph_row. OBJECT is the source of the glyph, WIDTH and HEIGHT are the width and height of the stretch. ASCENT is the percentage/100 of HEIGHT to use for the ascent of the glyph (0 <= ASCENT <= 1). */ static void x_append_stretch_glyph (it, object, width, height, ascent) struct it *it; Lisp_Object object; int width, height; double ascent; { struct glyph *glyph; enum glyph_row_area area = it->area; xassert (ascent >= 0 && ascent <= 1); glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; if (glyph < it->glyph_row->glyphs[area + 1]) { glyph->charpos = CHARPOS (it->position); glyph->object = object; glyph->pixel_width = width; glyph->voffset = it->voffset; glyph->type = STRETCH_GLYPH; glyph->multibyte_p = it->multibyte_p; glyph->left_box_line_p = it->start_of_box_run_p; glyph->right_box_line_p = it->end_of_box_run_p; glyph->overlaps_vertically_p = 0; glyph->padding_p = 0; glyph->glyph_not_available_p = 0; glyph->face_id = it->face_id; glyph->u.stretch.ascent = height * ascent; glyph->u.stretch.height = height; ++it->glyph_row->used[area]; } } /* Produce a stretch glyph for iterator IT. IT->object is the value of the glyph property displayed. The value must be a list `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs being recognized: 1. `:width WIDTH' specifies that the space should be WIDTH * canonical char width wide. WIDTH may be an integer or floating point number. 2. `:relative-width FACTOR' specifies that the width of the stretch should be computed from the width of the first character having the `glyph' property, and should be FACTOR times that width. 3. `:align-to HPOS' specifies that the space should be wide enough to reach HPOS, a value in canonical character units. Exactly one of the above pairs must be present. 4. `:height HEIGHT' specifies that the height of the stretch produced should be HEIGHT, measured in canonical character units. 5. `:relative-height FACTOR' specifies that the height of the the stretch should be FACTOR times the height of the characters having the glyph property. Either none or exactly one of 4 or 5 must be present. 6. `:ascent ASCENT' specifies that ASCENT percent of the height of the stretch should be used for the ascent of the stretch. ASCENT must be in the range 0 <= ASCENT <= 100. */ #define NUMVAL(X) \ ((INTEGERP (X) || FLOATP (X)) \ ? XFLOATINT (X) \ : - 1) static void x_produce_stretch_glyph (it) struct it *it; { /* (space :width WIDTH :height HEIGHT. */ #if GLYPH_DEBUG extern Lisp_Object Qspace; #endif extern Lisp_Object QCwidth, QCheight, QCascent; extern Lisp_Object QCrelative_width, QCrelative_height; extern Lisp_Object QCalign_to; Lisp_Object prop, plist; double width = 0, height = 0, ascent = 0; struct face *face = FACE_FROM_ID (it->f, it->face_id); XFontStruct *font = face->font ? face->font : FRAME_FONT (it->f); PREPARE_FACE_FOR_DISPLAY (it->f, face); /* List should start with `space'. */ xassert (CONSP (it->object) && EQ (XCAR (it->object), Qspace)); plist = XCDR (it->object); /* Compute the width of the stretch. */ if (prop = Fplist_get (plist, QCwidth), NUMVAL (prop) > 0) /* Absolute width `:width WIDTH' specified and valid. */ width = NUMVAL (prop) * CANON_X_UNIT (it->f); else if (prop = Fplist_get (plist, QCrelative_width), NUMVAL (prop) > 0) { /* Relative width `:relative-width FACTOR' specified and valid. Compute the width of the characters having the `glyph' property. */ struct it it2; unsigned char *p = BYTE_POS_ADDR (IT_BYTEPOS (*it)); it2 = *it; if (it->multibyte_p) { int maxlen = ((IT_BYTEPOS (*it) >= GPT ? ZV : GPT) - IT_BYTEPOS (*it)); it2.c = STRING_CHAR_AND_LENGTH (p, maxlen, it2.len); } else it2.c = *p, it2.len = 1; it2.glyph_row = NULL; it2.what = IT_CHARACTER; x_produce_glyphs (&it2); width = NUMVAL (prop) * it2.pixel_width; } else if (prop = Fplist_get (plist, QCalign_to), NUMVAL (prop) > 0) width = NUMVAL (prop) * CANON_X_UNIT (it->f) - it->current_x; else /* Nothing specified -> width defaults to canonical char width. */ width = CANON_X_UNIT (it->f); /* Compute height. */ if (prop = Fplist_get (plist, QCheight), NUMVAL (prop) > 0) height = NUMVAL (prop) * CANON_Y_UNIT (it->f); else if (prop = Fplist_get (plist, QCrelative_height), NUMVAL (prop) > 0) height = FONT_HEIGHT (font) * NUMVAL (prop); else height = FONT_HEIGHT (font); /* Compute percentage of height used for ascent. If `:ascent ASCENT' is present and valid, use that. Otherwise, derive the ascent from the font in use. */ if (prop = Fplist_get (plist, QCascent), NUMVAL (prop) > 0 && NUMVAL (prop) <= 100) ascent = NUMVAL (prop) / 100.0; else ascent = (double) font->ascent / FONT_HEIGHT (font); if (width <= 0) width = 1; if (height <= 0) height = 1; if (it->glyph_row) { Lisp_Object object = it->stack[it->sp - 1].string; if (!STRINGP (object)) object = it->w->buffer; x_append_stretch_glyph (it, object, width, height, ascent); } it->pixel_width = width; it->ascent = it->phys_ascent = height * ascent; it->descent = it->phys_descent = height - it->ascent; it->nglyphs = 1; if (face->box != FACE_NO_BOX) { it->ascent += face->box_line_width; it->descent += face->box_line_width; if (it->start_of_box_run_p) it->pixel_width += face->box_line_width; if (it->end_of_box_run_p) it->pixel_width += face->box_line_width; } take_vertical_position_into_account (it); } /* Return proper value to be used as baseline offset of font that has ASCENT and DESCENT to draw characters by the font at the vertical center of the line of frame F. Here, out task is to find the value of BOFF in the following figure; -------------------------+-----------+- -+-+---------+-+ | | | | | | | | | | | | F_ASCENT F_HEIGHT | | | ASCENT | | HEIGHT | | | | | | | |-|-+------+-----------|------- baseline | | | | BOFF | | | |---------|-+-+ | | | | | DESCENT | | -+-+---------+-+ F_DESCENT | -------------------------+-----------+- -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT DESCENT = FONT->descent HEIGHT = FONT_HEIGHT (FONT) F_DESCENT = (F->output_data.x->font->descent - F->output_data.x->baseline_offset) F_HEIGHT = FRAME_LINE_HEIGHT (F) */ #define VCENTER_BASELINE_OFFSET(FONT, F) \ ((FONT)->descent \ + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT))) / 2 \ - ((F)->output_data.mac->font->descent - (F)->output_data.mac->baseline_offset)) /* Produce glyphs/get display metrics for the display element IT is loaded with. See the description of struct display_iterator in dispextern.h for an overview of struct display_iterator. */ void x_produce_glyphs (it) struct it *it; { it->glyph_not_available_p = 0; if (it->what == IT_CHARACTER) { XChar2b char2b; XFontStruct *font; struct face *face = FACE_FROM_ID (it->f, it->face_id); XCharStruct *pcm; int font_not_found_p; struct font_info *font_info; int boff; /* baseline offset */ /* Maybe translate single-byte characters to multibyte, or the other way. */ it->char_to_display = it->c; if (!ASCII_BYTE_P (it->c)) { if (unibyte_display_via_language_environment && SINGLE_BYTE_CHAR_P (it->c) && (it->c >= 0240 || !NILP (Vnonascii_translation_table))) { it->char_to_display = unibyte_char_to_multibyte (it->c); it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); face = FACE_FROM_ID (it->f, it->face_id); } else if (!SINGLE_BYTE_CHAR_P (it->c) && !it->multibyte_p) { it->char_to_display = multibyte_char_to_unibyte (it->c, Qnil); it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); face = FACE_FROM_ID (it->f, it->face_id); } } /* Get font to use. Encode IT->char_to_display. */ x_get_char_face_and_encoding (it->f, it->char_to_display, it->face_id, &char2b, it->multibyte_p); font = face->font; /* When no suitable font found, use the default font. */ font_not_found_p = font == NULL; if (font_not_found_p) { font = FRAME_FONT (it->f); boff = it->f->output_data.mac->baseline_offset; font_info = NULL; } else { font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); boff = font_info->baseline_offset; if (font_info->vertical_centering) boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; } if (it->char_to_display >= ' ' && (!it->multibyte_p || it->char_to_display < 128)) { /* Either unibyte or ASCII. */ int stretched_p; it->nglyphs = 1; pcm = x_per_char_metric (font, &char2b); it->ascent = font->ascent + boff; it->descent = font->descent - boff; if (pcm) { it->phys_ascent = pcm->ascent + boff; it->phys_descent = pcm->descent - boff; it->pixel_width = pcm->width; } else { it->glyph_not_available_p = 1; it->phys_ascent = font->ascent + boff; it->phys_descent = font->descent - boff; it->pixel_width = FONT_WIDTH (font); } /* If this is a space inside a region of text with `space-width' property, change its width. */ stretched_p = it->char_to_display == ' ' && !NILP (it->space_width); if (stretched_p) it->pixel_width *= XFLOATINT (it->space_width); /* If face has a box, add the box thickness to the character height. If character has a box line to the left and/or right, add the box line width to the character's width. */ if (face->box != FACE_NO_BOX) { int thick = face->box_line_width; it->ascent += thick; it->descent += thick; if (it->start_of_box_run_p) it->pixel_width += thick; if (it->end_of_box_run_p) it->pixel_width += thick; } /* If face has an overline, add the height of the overline (1 pixel) and a 1 pixel margin to the character height. */ if (face->overline_p) it->ascent += 2; take_vertical_position_into_account (it); /* If we have to actually produce glyphs, do it. */ if (it->glyph_row) { if (stretched_p) { /* Translate a space with a `space-width' property into a stretch glyph. */ double ascent = (double) font->ascent / FONT_HEIGHT (font); x_append_stretch_glyph (it, it->object, it->pixel_width, it->ascent + it->descent, ascent); } else x_append_glyph (it); /* If characters with lbearing or rbearing are displayed in this line, record that fact in a flag of the glyph row. This is used to optimize X output code. */ if (pcm && (pcm->lbearing < 0 || pcm->rbearing > pcm->width)) it->glyph_row->contains_overlapping_glyphs_p = 1; } } else if (it->char_to_display == '\n') { /* A newline has no width but we need the height of the line. */ it->pixel_width = 0; it->nglyphs = 0; it->ascent = it->phys_ascent = font->ascent + boff; it->descent = it->phys_descent = font->descent - boff; if (face->box != FACE_NO_BOX) { int thick = face->box_line_width; it->ascent += thick; it->descent += thick; } } else if (it->char_to_display == '\t') { int tab_width = it->tab_width * CANON_X_UNIT (it->f); int x = it->current_x + it->continuation_lines_width; int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; it->pixel_width = next_tab_x - x; it->nglyphs = 1; it->ascent = it->phys_ascent = font->ascent + boff; it->descent = it->phys_descent = font->descent - boff; if (it->glyph_row) { double ascent = (double) it->ascent / (it->ascent + it->descent); x_append_stretch_glyph (it, it->object, it->pixel_width, it->ascent + it->descent, ascent); } } else { /* A multi-byte character. Assume that the display width of the character is the width of the character multiplied by the width of the font. */ /* If we found a font, this font should give us the right metrics. If we didn't find a font, use the frame's default font and calculate the width of the character from the charset width; this is what old redisplay code did. */ pcm = x_per_char_metric (font, &char2b); if (font_not_found_p || !pcm) { int charset = CHAR_CHARSET (it->char_to_display); it->glyph_not_available_p = 1; it->pixel_width = (FONT_WIDTH (FRAME_FONT (it->f)) * CHARSET_WIDTH (charset)); it->phys_ascent = font->ascent + boff; it->phys_descent = font->descent - boff; } else { it->pixel_width = pcm->width; it->phys_ascent = pcm->ascent + boff; it->phys_descent = pcm->descent - boff; if (it->glyph_row && (pcm->lbearing < 0 || pcm->rbearing > pcm->width)) it->glyph_row->contains_overlapping_glyphs_p = 1; } it->nglyphs = 1; it->ascent = font->ascent + boff; it->descent = font->descent - boff; if (face->box != FACE_NO_BOX) { int thick = face->box_line_width; it->ascent += thick; it->descent += thick; if (it->start_of_box_run_p) it->pixel_width += thick; if (it->end_of_box_run_p) it->pixel_width += thick; } /* If face has an overline, add the height of the overline (1 pixel) and a 1 pixel margin to the character height. */ if (face->overline_p) it->ascent += 2; take_vertical_position_into_account (it); if (it->glyph_row) x_append_glyph (it); } } else if (it->what == IT_COMPOSITION) { /* Note: A composition is represented as one glyph in the glyph matrix. There are no padding glyphs. */ XChar2b char2b; XFontStruct *font; struct face *face = FACE_FROM_ID (it->f, it->face_id); XCharStruct *pcm; int font_not_found_p; struct font_info *font_info; int boff; /* baseline offset */ struct composition *cmp = composition_table[it->cmp_id]; /* Maybe translate single-byte characters to multibyte. */ it->char_to_display = it->c; if (unibyte_display_via_language_environment && SINGLE_BYTE_CHAR_P (it->c) && (it->c >= 0240 || (it->c >= 0200 && !NILP (Vnonascii_translation_table)))) { it->char_to_display = unibyte_char_to_multibyte (it->c); } /* Get face and font to use. Encode IT->char_to_display. */ it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); face = FACE_FROM_ID (it->f, it->face_id); x_get_char_face_and_encoding (it->f, it->char_to_display, it->face_id, &char2b, it->multibyte_p); font = face->font; /* When no suitable font found, use the default font. */ font_not_found_p = font == NULL; if (font_not_found_p) { font = FRAME_FONT (it->f); boff = it->f->output_data.mac->baseline_offset; font_info = NULL; } else { font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); boff = font_info->baseline_offset; if (font_info->vertical_centering) boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; } /* There are no padding glyphs, so there is only one glyph to produce for the composition. Important is that pixel_width, ascent and descent are the values of what is drawn by draw_glyphs (i.e. the values of the overall glyphs composed). */ it->nglyphs = 1; /* If we have not yet calculated pixel size data of glyphs of the composition for the current face font, calculate them now. Theoretically, we have to check all fonts for the glyphs, but that requires much time and memory space. So, here we check only the font of the first glyph. This leads to incorrect display very rarely, and C-l (recenter) can correct the display anyway. */ if (cmp->font != (void *) font) { /* Ascent and descent of the font of the first character of this composition (adjusted by baseline offset). Ascent and descent of overall glyphs should not be less than them respectively. */ int font_ascent = font->ascent + boff; int font_descent = font->descent - boff; /* Bounding box of the overall glyphs. */ int leftmost, rightmost, lowest, highest; int i, width, ascent, descent; cmp->font = (void *) font; /* Initialize the bounding box. */ pcm = x_per_char_metric (font, &char2b); if (pcm) { width = pcm->width; ascent = pcm->ascent; descent = pcm->descent; } else { width = FONT_WIDTH (font); ascent = font->ascent; descent = font->descent; } rightmost = width; lowest = - descent + boff; highest = ascent + boff; leftmost = 0; if (font_info && font_info->default_ascent && CHAR_TABLE_P (Vuse_default_ascent) && !NILP (Faref (Vuse_default_ascent, make_number (it->char_to_display)))) highest = font_info->default_ascent + boff; /* Draw the first glyph at the normal position. It may be shifted to right later if some other glyphs are drawn at the left. */ cmp->offsets[0] = 0; cmp->offsets[1] = boff; /* Set cmp->offsets for the remaining glyphs. */ for (i = 1; i < cmp->glyph_len; i++) { int left, right, btm, top; int ch = COMPOSITION_GLYPH (cmp, i); int face_id = FACE_FOR_CHAR (it->f, face, ch); face = FACE_FROM_ID (it->f, face_id); x_get_char_face_and_encoding (it->f, ch, face->id, &char2b, it->multibyte_p); font = face->font; if (font == NULL) { font = FRAME_FONT (it->f); boff = it->f->output_data.mac->baseline_offset; font_info = NULL; } else { font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); boff = font_info->baseline_offset; if (font_info->vertical_centering) boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; } pcm = x_per_char_metric (font, &char2b); if (pcm) { width = pcm->width; ascent = pcm->ascent; descent = pcm->descent; } else { width = FONT_WIDTH (font); ascent = font->ascent; descent = font->descent; } if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS) { /* Relative composition with or without alternate chars. */ left = (leftmost + rightmost - width) / 2; btm = - descent + boff; if (font_info && font_info->relative_compose && (! CHAR_TABLE_P (Vignore_relative_composition) || NILP (Faref (Vignore_relative_composition, make_number (ch))))) { if (- descent >= font_info->relative_compose) /* One extra pixel between two glyphs. */ btm = highest + 1; else if (ascent <= 0) /* One extra pixel between two glyphs. */ btm = lowest - 1 - ascent - descent; } } else { /* A composition rule is specified by an integer value that encodes global and new reference points (GREF and NREF). GREF and NREF are specified by numbers as below: 0---1---2 -- ascent | | | | | | 9--10--11 -- center | | ---3---4---5--- baseline | | 6---7---8 -- descent */ int rule = COMPOSITION_RULE (cmp, i); int gref, nref, grefx, grefy, nrefx, nrefy; COMPOSITION_DECODE_RULE (rule, gref, nref); grefx = gref % 3, nrefx = nref % 3; grefy = gref / 3, nrefy = nref / 3; left = (leftmost + grefx * (rightmost - leftmost) / 2 - nrefx * width / 2); btm = ((grefy == 0 ? highest : grefy == 1 ? 0 : grefy == 2 ? lowest : (highest + lowest) / 2) - (nrefy == 0 ? ascent + descent : nrefy == 1 ? descent - boff : nrefy == 2 ? 0 : (ascent + descent) / 2)); } cmp->offsets[i * 2] = left; cmp->offsets[i * 2 + 1] = btm + descent; /* Update the bounding box of the overall glyphs. */ right = left + width; top = btm + descent + ascent; if (left < leftmost) leftmost = left; if (right > rightmost) rightmost = right; if (top > highest) highest = top; if (btm < lowest) lowest = btm; } /* If there are glyphs whose x-offsets are negative, shift all glyphs to the right and make all x-offsets non-negative. */ if (leftmost < 0) { for (i = 0; i < cmp->glyph_len; i++) cmp->offsets[i * 2] -= leftmost; rightmost -= leftmost; } cmp->pixel_width = rightmost; cmp->ascent = highest; cmp->descent = - lowest; if (cmp->ascent < font_ascent) cmp->ascent = font_ascent; if (cmp->descent < font_descent) cmp->descent = font_descent; } it->pixel_width = cmp->pixel_width; it->ascent = it->phys_ascent = cmp->ascent; it->descent = it->phys_descent = cmp->descent; if (face->box != FACE_NO_BOX) { int thick = face->box_line_width; it->ascent += thick; it->descent += thick; if (it->start_of_box_run_p) it->pixel_width += thick; if (it->end_of_box_run_p) it->pixel_width += thick; } /* If face has an overline, add the height of the overline (1 pixel) and a 1 pixel margin to the character height. */ if (face->overline_p) it->ascent += 2; take_vertical_position_into_account (it); if (it->glyph_row) x_append_composite_glyph (it); } else if (it->what == IT_IMAGE) x_produce_image_glyph (it); else if (it->what == IT_STRETCH) x_produce_stretch_glyph (it); /* Accumulate dimensions. Note: can't assume that it->descent > 0 because this isn't true for images with `:ascent 100'. */ xassert (it->ascent >= 0 && it->descent >= 0); if (it->area == TEXT_AREA) it->current_x += it->pixel_width; it->descent += it->extra_line_spacing; it->max_ascent = max (it->max_ascent, it->ascent); it->max_descent = max (it->max_descent, it->descent); it->max_phys_ascent = max (it->max_phys_ascent, it->phys_ascent); it->max_phys_descent = max (it->max_phys_descent, it->phys_descent); } /* Estimate the pixel height of the mode or top line on frame F. FACE_ID specifies what line's height to estimate. */ int x_estimate_mode_line_height (f, face_id) struct frame *f; enum face_id face_id; { int height = 1; /* This function is called so early when Emacs starts that the face cache and mode line face are not yet initialized. */ if (FRAME_FACE_CACHE (f)) { struct face *face = FACE_FROM_ID (f, face_id); if (face) height = FONT_HEIGHT (face->font) + 2 * face->box_line_width; } return height; } /*********************************************************************** Glyph display ***********************************************************************/ /* A sequence of glyphs to be drawn in the same face. This data structure is not really completely X specific, so it could possibly, at least partially, be useful for other systems. It is currently not part of the external redisplay interface because it's not clear what other systems will need. */ struct glyph_string { /* X-origin of the string. */ int x; /* Y-origin and y-position of the base line of this string. */ int y, ybase; /* The width of the string, not including a face extension. */ int width; /* The width of the string, including a face extension. */ int background_width; /* The height of this string. This is the height of the line this string is drawn in, and can be different from the height of the font the string is drawn in. */ int height; /* Number of pixels this string overwrites in front of its x-origin. This number is zero if the string has an lbearing >= 0; it is -lbearing, if the string has an lbearing < 0. */ int left_overhang; /* Number of pixels this string overwrites past its right-most nominal x-position, i.e. x + width. Zero if the string's rbearing is <= its nominal width, rbearing - width otherwise. */ int right_overhang; /* The frame on which the glyph string is drawn. */ struct frame *f; /* The window on which the glyph string is drawn. */ struct window *w; /* X display and window for convenience. */ Display *display; Window window; /* The glyph row for which this string was built. It determines the y-origin and height of the string. */ struct glyph_row *row; /* The area within row. */ enum glyph_row_area area; /* Characters to be drawn, and number of characters. */ XChar2b *char2b; int nchars; /* A face-override for drawing cursors, mouse face and similar. */ enum draw_glyphs_face hl; /* Face in which this string is to be drawn. */ struct face *face; /* Font in which this string is to be drawn. */ XFontStruct *font; /* Font info for this string. */ struct font_info *font_info; /* Non-null means this string describes (part of) a composition. All characters from char2b are drawn composed. */ struct composition *cmp; /* Index of this glyph string's first character in the glyph definition of CMP. If this is zero, this glyph string describes the first character of a composition. */ int gidx; /* 1 means this glyph strings face has to be drawn to the right end of the window's drawing area. */ unsigned extends_to_end_of_line_p : 1; /* 1 means the background of this string has been drawn. */ unsigned background_filled_p : 1; /* 1 means glyph string must be drawn with 16-bit functions. */ unsigned two_byte_p : 1; /* 1 means that the original font determined for drawing this glyph string could not be loaded. The member `font' has been set to the frame's default font in this case. */ unsigned font_not_found_p : 1; /* 1 means that the face in which this glyph string is drawn has a stipple pattern. */ unsigned stippled_p : 1; /* 1 means only the foreground of this glyph string must be drawn, and we should use the physical height of the line this glyph string appears in as clip rect. */ unsigned for_overlaps_p : 1; /* The GC to use for drawing this glyph string. */ GC gc; /* A pointer to the first glyph in the string. This glyph corresponds to char2b[0]. Needed to draw rectangles if font_not_found_p is 1. */ struct glyph *first_glyph; /* Image, if any. */ struct image *img; struct glyph_string *next, *prev; }; #if 0 static void x_dump_glyph_string (s) struct glyph_string *s; { fprintf (stderr, "glyph string\n"); fprintf (stderr, " x, y, w, h = %d, %d, %d, %d\n", s->x, s->y, s->width, s->height); fprintf (stderr, " ybase = %d\n", s->ybase); fprintf (stderr, " hl = %d\n", s->hl); fprintf (stderr, " left overhang = %d, right = %d\n", s->left_overhang, s->right_overhang); fprintf (stderr, " nchars = %d\n", s->nchars); fprintf (stderr, " extends to end of line = %d\n", s->extends_to_end_of_line_p); fprintf (stderr, " font height = %d\n", FONT_HEIGHT (s->font)); fprintf (stderr, " bg width = %d\n", s->background_width); } #endif /* GLYPH_DEBUG */ static void x_append_glyph_string_lists P_ ((struct glyph_string **, struct glyph_string **, struct glyph_string *, struct glyph_string *)); static void x_prepend_glyph_string_lists P_ ((struct glyph_string **, struct glyph_string **, struct glyph_string *, struct glyph_string *)); static void x_append_glyph_string P_ ((struct glyph_string **, struct glyph_string **, struct glyph_string *)); static int x_left_overwritten P_ ((struct glyph_string *)); static int x_left_overwriting P_ ((struct glyph_string *)); static int x_right_overwritten P_ ((struct glyph_string *)); static int x_right_overwriting P_ ((struct glyph_string *)); static int x_fill_glyph_string P_ ((struct glyph_string *, int, int, int, int)); static void x_init_glyph_string P_ ((struct glyph_string *, XChar2b *, struct window *, struct glyph_row *, enum glyph_row_area, int, enum draw_glyphs_face)); static int x_draw_glyphs P_ ((struct window *, int , struct glyph_row *, enum glyph_row_area, int, int, enum draw_glyphs_face, int *, int *, int)); static void x_set_glyph_string_clipping P_ ((struct glyph_string *)); static void x_set_glyph_string_gc P_ ((struct glyph_string *)); static void x_draw_glyph_string_background P_ ((struct glyph_string *, int)); static void x_draw_glyph_string_foreground P_ ((struct glyph_string *)); static void x_draw_composite_glyph_string_foreground P_ ((struct glyph_string *)); static void x_draw_glyph_string_box P_ ((struct glyph_string *)); static void x_draw_glyph_string P_ ((struct glyph_string *)); static void x_compute_glyph_string_overhangs P_ ((struct glyph_string *)); static void x_set_cursor_gc P_ ((struct glyph_string *)); static void x_set_mode_line_face_gc P_ ((struct glyph_string *)); static void x_set_mouse_face_gc P_ ((struct glyph_string *)); static void x_get_glyph_overhangs P_ ((struct glyph *, struct frame *, int *, int *)); static void x_compute_overhangs_and_x P_ ((struct glyph_string *, int, int)); static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap, unsigned long *, double, int)); static void x_setup_relief_color P_ ((struct frame *, struct relief *, double, int, unsigned long)); static void x_setup_relief_colors P_ ((struct glyph_string *)); static void x_draw_image_glyph_string P_ ((struct glyph_string *)); static void x_draw_image_relief P_ ((struct glyph_string *)); static void x_draw_image_foreground P_ ((struct glyph_string *)); static void x_draw_image_foreground_1 P_ ((struct glyph_string *, Pixmap)); static void x_fill_image_glyph_string P_ ((struct glyph_string *)); static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int, int, int, int)); static void x_draw_relief_rect P_ ((struct frame *, int, int, int, int, int, int, int, int, XRectangle *)); static void x_draw_box_rect P_ ((struct glyph_string *, int, int, int, int, int, int, int, XRectangle *)); static void x_fix_overlapping_area P_ ((struct window *, struct glyph_row *, enum glyph_row_area)); static int x_fill_stretch_glyph_string P_ ((struct glyph_string *, struct glyph_row *, enum glyph_row_area, int, int)); #if GLYPH_DEBUG static void x_check_font P_ ((struct frame *, XFontStruct *)); #endif /* Append the list of glyph strings with head H and tail T to the list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */ static INLINE void x_append_glyph_string_lists (head, tail, h, t) struct glyph_string **head, **tail; struct glyph_string *h, *t; { if (h) { if (*head) (*tail)->next = h; else *head = h; h->prev = *tail; *tail = t; } } /* Prepend the list of glyph strings with head H and tail T to the list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */ static INLINE void x_prepend_glyph_string_lists (head, tail, h, t) struct glyph_string **head, **tail; struct glyph_string *h, *t; { if (h) { if (*head) (*head)->prev = t; else *tail = t; t->next = *head; *head = h; } } /* Append glyph string S to the list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the resulting list. */ static INLINE void x_append_glyph_string (head, tail, s) struct glyph_string **head, **tail; struct glyph_string *s; { s->next = s->prev = NULL; x_append_glyph_string_lists (head, tail, s, s); } /* Set S->gc to a suitable GC for drawing glyph string S in cursor face. */ static void x_set_cursor_gc (s) struct glyph_string *s; { if (s->font == FRAME_FONT (s->f) && s->face->background == FRAME_BACKGROUND_PIXEL (s->f) && s->face->foreground == FRAME_FOREGROUND_PIXEL (s->f) && !s->cmp) s->gc = s->f->output_data.mac->cursor_gc; else { /* Cursor on non-default face: must merge. */ XGCValues xgcv; unsigned long mask; xgcv.background = s->f->output_data.mac->cursor_pixel; xgcv.foreground = s->face->background; /* If the glyph would be invisible, try a different foreground. */ if (xgcv.foreground == xgcv.background) xgcv.foreground = s->face->foreground; if (xgcv.foreground == xgcv.background) xgcv.foreground = s->f->output_data.mac->cursor_foreground_pixel; if (xgcv.foreground == xgcv.background) xgcv.foreground = s->face->foreground; /* Make sure the cursor is distinct from text in this face. */ if (xgcv.background == s->face->background && xgcv.foreground == s->face->foreground) { xgcv.background = s->face->foreground; xgcv.foreground = s->face->background; } IF_DEBUG (x_check_font (s->f, s->font)); xgcv.font = s->font; mask = GCForeground | GCBackground | GCFont; if (FRAME_MAC_DISPLAY_INFO (s->f)->scratch_cursor_gc) XChangeGC (s->display, FRAME_MAC_DISPLAY_INFO (s->f)->scratch_cursor_gc, mask, &xgcv); else FRAME_MAC_DISPLAY_INFO (s->f)->scratch_cursor_gc = XCreateGC (s->display, s->window, mask, &xgcv); s->gc = FRAME_MAC_DISPLAY_INFO (s->f)->scratch_cursor_gc; } } /* Set up S->gc of glyph string S for drawing text in mouse face. */ static void x_set_mouse_face_gc (s) struct glyph_string *s; { int face_id; struct face *face; /* What face has to be used for the mouse face? */ face_id = FRAME_X_DISPLAY_INFO (s->f)->mouse_face_face_id; face = FACE_FROM_ID (s->f, face_id); if (s->first_glyph->type == CHAR_GLYPH) face_id = FACE_FOR_CHAR (s->f, face, s->first_glyph->u.ch); else face_id = FACE_FOR_CHAR (s->f, face, 0); s->face = FACE_FROM_ID (s->f, face_id); PREPARE_FACE_FOR_DISPLAY (s->f, s->face); /* If font in this face is same as S->font, use it. */ if (s->font == s->face->font) s->gc = s->face->gc; else { /* Otherwise construct scratch_cursor_gc with values from FACE but font FONT. */ XGCValues xgcv; unsigned long mask; xgcv.background = s->face->background; xgcv.foreground = s->face->foreground; IF_DEBUG (x_check_font (s->f, s->font)); xgcv.font = s->font; mask = GCForeground | GCBackground | GCFont; if (FRAME_MAC_DISPLAY_INFO (s->f)->scratch_cursor_gc) XChangeGC (s->display, FRAME_MAC_DISPLAY_INFO (s->f)->scratch_cursor_gc, mask, &xgcv); else FRAME_MAC_DISPLAY_INFO (s->f)->scratch_cursor_gc = XCreateGC (s->display, s->window, mask, &xgcv); s->gc = FRAME_MAC_DISPLAY_INFO (s->f)->scratch_cursor_gc; } xassert (s->gc != 0); } /* Set S->gc of glyph string S to a GC suitable for drawing a mode line. Faces to use in the mode line have already been computed when the matrix was built, so there isn't much to do, here. */ static INLINE void x_set_mode_line_face_gc (s) struct glyph_string *s; { s->gc = s->face->gc; } /* Set S->gc of glyph string S for drawing that glyph string. Set S->stippled_p to a non-zero value if the face of S has a stipple pattern. */ static INLINE void x_set_glyph_string_gc (s) struct glyph_string *s; { PREPARE_FACE_FOR_DISPLAY (s->f, s->face); if (s->hl == DRAW_NORMAL_TEXT) { s->gc = s->face->gc; s->stippled_p = s->face->stipple != 0; } else if (s->hl == DRAW_INVERSE_VIDEO) { x_set_mode_line_face_gc (s); s->stippled_p = s->face->stipple != 0; } else if (s->hl == DRAW_CURSOR) { x_set_cursor_gc (s); s->stippled_p = 0; } else if (s->hl == DRAW_MOUSE_FACE) { x_set_mouse_face_gc (s); s->stippled_p = s->face->stipple != 0; } else if (s->hl == DRAW_IMAGE_RAISED || s->hl == DRAW_IMAGE_SUNKEN) { s->gc = s->face->gc; s->stippled_p = s->face->stipple != 0; } else { s->gc = s->face->gc; s->stippled_p = s->face->stipple != 0; } /* GC must have been set. */ xassert (s->gc != 0); } /* Return in *R the clipping rectangle for glyph string S. */ static void x_get_glyph_string_clip_rect (s, r) struct glyph_string *s; Rect *r; { int r_height, r_width; if (s->row->full_width_p) { /* Draw full-width. X coordinates are relative to S->w->left. */ int canon_x = CANON_X_UNIT (s->f); r->left = WINDOW_LEFT_MARGIN (s->w) * canon_x; r_width = XFASTINT (s->w->width) * canon_x; if (FRAME_HAS_VERTICAL_SCROLL_BARS (s->f)) { int width = FRAME_SCROLL_BAR_WIDTH (s->f) * canon_x; if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s->f)) r->left -= width; } r->left += FRAME_INTERNAL_BORDER_WIDTH (s->f); /* Unless displaying a mode or menu bar line, which are always fully visible, clip to the visible part of the row. */ if (s->w->pseudo_window_p) r_height = s->row->visible_height; else r_height = s->height; } else { /* This is a text line that may be partially visible. */ r->left = WINDOW_AREA_TO_FRAME_PIXEL_X (s->w, s->area, 0); r_width = window_box_width (s->w, s->area); r_height = s->row->visible_height; } /* Don't use S->y for clipping because it doesn't take partially visible lines into account. For example, it can be negative for partially visible lines at the top of a window. */ if (!s->row->full_width_p && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s->w, s->row)) r->top = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); else r->top = max (0, s->row->y); /* If drawing a tool-bar window, draw it over the internal border at the top of the window. */ if (s->w == XWINDOW (s->f->tool_bar_window)) r->top -= s->f->output_data.mac->internal_border_width; /* If S draws overlapping rows, it's sufficient to use the top and bottom of the window for clipping because this glyph string intentionally draws over other lines. */ if (s->for_overlaps_p) { r->top = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); r_height = window_text_bottom_y (s->w) - r->top; } r->top = WINDOW_TO_FRAME_PIXEL_Y (s->w, r->top); r->bottom = r->top + r_height; r->right = r->left + r_width; } /* Set clipping for output of glyph string S. S may be part of a mode line or menu if we don't have X toolkit support. */ static INLINE void x_set_glyph_string_clipping (s) struct glyph_string *s; { Rect r; x_get_glyph_string_clip_rect (s, &r); mac_set_clip_rectangle (s->display, s->window, &r); } /* Compute left and right overhang of glyph string S. If S is a glyph string for a composition, assume overhangs don't exist. */ static INLINE void x_compute_glyph_string_overhangs (s) struct glyph_string *s; { if (s->cmp == NULL && s->first_glyph->type == CHAR_GLYPH) { XCharStruct cs; int direction, font_ascent, font_descent; XTextExtents16 (s->font, s->char2b, s->nchars, &direction, &font_ascent, &font_descent, &cs); s->right_overhang = cs.rbearing > cs.width ? cs.rbearing - cs.width : 0; s->left_overhang = cs.lbearing < 0 ? -cs.lbearing : 0; } } /* Compute overhangs and x-positions for glyph string S and its predecessors, or successors. X is the starting x-position for S. BACKWARD_P non-zero means process predecessors. */ static void x_compute_overhangs_and_x (s, x, backward_p) struct glyph_string *s; int x; int backward_p; { if (backward_p) { while (s) { x_compute_glyph_string_overhangs (s); x -= s->width; s->x = x; s = s->prev; } } else { while (s) { x_compute_glyph_string_overhangs (s); s->x = x; x += s->width; s = s->next; } } } /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on frame F. Overhangs of glyphs other than type CHAR_GLYPH are assumed to be zero. */ void x_get_glyph_overhangs (glyph, f, left, right) struct glyph *glyph; struct frame *f; int *left, *right; { *left = *right = 0; if (glyph->type == CHAR_GLYPH) { XFontStruct *font; struct face *face; struct font_info *font_info; XChar2b char2b; XCharStruct *pcm; face = x_get_glyph_face_and_encoding (f, glyph, &char2b, NULL); font = face->font; font_info = FONT_INFO_FROM_ID (f, face->font_info_id); if (font && (pcm = x_per_char_metric (font, &char2b))) { if (pcm->rbearing > pcm->width) *right = pcm->rbearing - pcm->width; if (pcm->lbearing < 0) *left = -pcm->lbearing; } } } /* Return the index of the first glyph preceding glyph string S that is overwritten by S because of S's left overhang. Value is -1 if no glyphs are overwritten. */ static int x_left_overwritten (s) struct glyph_string *s; { int k; if (s->left_overhang) { int x = 0, i; struct glyph *glyphs = s->row->glyphs[s->area]; int first = s->first_glyph - glyphs; for (i = first - 1; i >= 0 && x > -s->left_overhang; --i) x -= glyphs[i].pixel_width; k = i + 1; } else k = -1; return k; } /* Return the index of the first glyph preceding glyph string S that is overwriting S because of its right overhang. Value is -1 if no glyph in front of S overwrites S. */ static int x_left_overwriting (s) struct glyph_string *s; { int i, k, x; struct glyph *glyphs = s->row->glyphs[s->area]; int first = s->first_glyph - glyphs; k = -1; x = 0; for (i = first - 1; i >= 0; --i) { int left, right; x_get_glyph_overhangs (glyphs + i, s->f, &left, &right); if (x + right > 0) k = i; x -= glyphs[i].pixel_width; } return k; } /* Return the index of the last glyph following glyph string S that is not overwritten by S because of S's right overhang. Value is -1 if no such glyph is found. */ static int x_right_overwritten (s) struct glyph_string *s; { int k = -1; if (s->right_overhang) { int x = 0, i; struct glyph *glyphs = s->row->glyphs[s->area]; int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); int end = s->row->used[s->area]; for (i = first; i < end && s->right_overhang > x; ++i) x += glyphs[i].pixel_width; k = i; } return k; } /* Return the index of the last glyph following glyph string S that overwrites S because of its left overhang. Value is negative if no such glyph is found. */ static int x_right_overwriting (s) struct glyph_string *s; { int i, k, x; int end = s->row->used[s->area]; struct glyph *glyphs = s->row->glyphs[s->area]; int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); k = -1; x = 0; for (i = first; i < end; ++i) { int left, right; x_get_glyph_overhangs (glyphs + i, s->f, &left, &right); if (x - left < 0) k = i; x += glyphs[i].pixel_width; } return k; } /* Fill rectangle X, Y, W, H with background color of glyph string S. */ static INLINE void x_clear_glyph_string_rect (s, x, y, w, h) struct glyph_string *s; int x, y, w, h; { XGCValues xgcv; xgcv.foreground = s->gc->background; XFillRectangle (s->display, s->window, &xgcv, x, y, w, h); } /* Draw the background of glyph_string S. If S->background_filled_p is non-zero don't draw it. FORCE_P non-zero means draw the background even if it wouldn't be drawn normally. This is used when a string preceding S draws into the background of S, or S contains the first component of a composition. */ static void x_draw_glyph_string_background (s, force_p) struct glyph_string *s; int force_p; { /* Nothing to do if background has already been drawn or if it shouldn't be drawn in the first place. */ if (!s->background_filled_p) { #if 0 /* MAC_TODO: stipple */ if (s->stippled_p) { /* Fill background with a stipple pattern. */ XSetFillStyle (s->display, s->gc, FillOpaqueStippled); XFillRectangle (s->display, s->window, s->gc, s->x, s->y + s->face->box_line_width, s->background_width, s->height - 2 * s->face->box_line_width); XSetFillStyle (s->display, s->gc, FillSolid); s->background_filled_p = 1; } else #endif if (FONT_HEIGHT (s->font) < s->height - 2 * s->face->box_line_width || s->font_not_found_p || s->extends_to_end_of_line_p || force_p) { x_clear_glyph_string_rect (s, s->x, s->y + s->face->box_line_width, s->background_width, s->height - 2 * s->face->box_line_width); s->background_filled_p = 1; } } } /* Draw the foreground of glyph string S. */ static void x_draw_glyph_string_foreground (s) struct glyph_string *s; { int i, x; /* If first glyph of S has a left box line, start drawing the text of S to the right of that box line. */ if (s->face->box != FACE_NO_BOX && s->first_glyph->left_box_line_p) x = s->x + s->face->box_line_width; else x = s->x; /* Draw characters of S as rectangles if S's font could not be loaded. */ if (s->font_not_found_p) { for (i = 0; i < s->nchars; ++i) { struct glyph *g = s->first_glyph + i; mac_draw_rectangle (s->display, s->window, s->gc, x, s->y, g->pixel_width - 1, s->height - 1); x += g->pixel_width; } } else { char *char1b = (char *) s->char2b; int boff = s->font_info->baseline_offset; if (s->font_info->vertical_centering) boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff; /* If we can use 8-bit functions, condense S->char2b. */ if (!s->two_byte_p) for (i = 0; i < s->nchars; ++i) char1b[i] = s->char2b[i].byte2; /* Draw text with XDrawString if background has already been filled. Otherwise, use XDrawImageString. (Note that XDrawImageString is usually faster than XDrawString.) Always use XDrawImageString when drawing the cursor so that there is no chance that characters under a box cursor are invisible. */ if (s->for_overlaps_p || (s->background_filled_p && s->hl != DRAW_CURSOR)) { /* Draw characters with 16-bit or 8-bit functions. */ if (s->two_byte_p) XDrawString16 (s->display, s->window, s->gc, x, s->ybase - boff, s->char2b, s->nchars); else XDrawString (s->display, s->window, s->gc, x, s->ybase - boff, char1b, s->nchars); } else { if (s->two_byte_p) XDrawImageString16 (s->display, s->window, s->gc, x, s->ybase - boff, s->char2b, s->nchars); else XDrawImageString (s->display, s->window, s->gc, x, s->ybase - boff, char1b, s->nchars); } } } /* Draw the foreground of composite glyph string S. */ static void x_draw_composite_glyph_string_foreground (s) struct glyph_string *s; { int i, x; /* If first glyph of S has a left box line, start drawing the text of S to the right of that box line. */ if (s->face->box != FACE_NO_BOX && s->first_glyph->left_box_line_p) x = s->x + s->face->box_line_width; else x = s->x; /* S is a glyph string for a composition. S->gidx is the index of the first character drawn for glyphs of this composition. S->gidx == 0 means we are drawing the very first character of this composition. */ /* Draw a rectangle for the composition if the font for the very first character of the composition could not be loaded. */ if (s->font_not_found_p) { if (s->gidx == 0) mac_draw_rectangle (s->display, s->window, s->gc, x, s->y, s->width - 1, s->height - 1); } else { for (i = 0; i < s->nchars; i++, ++s->gidx) XDrawString16 (s->display, s->window, s->gc, x + s->cmp->offsets[s->gidx * 2], s->ybase - s->cmp->offsets[s->gidx * 2 + 1], s->char2b + i, 1); } } #ifdef USE_X_TOOLKIT static struct frame *x_frame_of_widget P_ ((Widget)); /* Return the frame on which widget WIDGET is used.. Abort if frame cannot be determined. */ static struct frame * x_frame_of_widget (widget) Widget widget; { struct x_display_info *dpyinfo; Lisp_Object tail; struct frame *f; dpyinfo = x_display_info_for_display (XtDisplay (widget)); /* Find the top-level shell of the widget. Note that this function can be called when the widget is not yet realized, so XtWindow (widget) == 0. That's the reason we can't simply use x_any_window_to_frame. */ while (!XtIsTopLevelShell (widget)) widget = XtParent (widget); /* Look for a frame with that top-level widget. Allocate the color on that frame to get the right gamma correction value. */ for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) if (GC_FRAMEP (XCAR (tail)) && (f = XFRAME (XCAR (tail)), (f->output_data.nothing != 1 && FRAME_X_DISPLAY_INFO (f) == dpyinfo)) && f->output_data.x->widget == widget) return f; abort (); } /* Allocate the color COLOR->pixel on the screen and display of widget WIDGET in colormap CMAP. If an exact match cannot be allocated, try the nearest color available. Value is non-zero if successful. This is called from lwlib. */ int x_alloc_nearest_color_for_widget (widget, cmap, color) Widget widget; Colormap cmap; XColor *color; { struct frame *f = x_frame_of_widget (widget); return x_alloc_nearest_color (f, cmap, color); } #endif /* USE_X_TOOLKIT */ #if 0 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap CMAP. If an exact match can't be allocated, try the nearest color available. Value is non-zero if successful. Set *COLOR to the color allocated. */ int x_alloc_nearest_color (f, cmap, color) struct frame *f; Colormap cmap; XColor *color; { Display *display = FRAME_X_DISPLAY (f); Screen *screen = FRAME_X_SCREEN (f); int rc; gamma_correct (f, color); rc = XAllocColor (display, cmap, color); if (rc == 0) { /* If we got to this point, the colormap is full, so we're going to try to get the next closest color. The algorithm used is a least-squares matching, which is what X uses for closest color matching with StaticColor visuals. */ int nearest, i; unsigned long nearest_delta = ~0; int ncells = XDisplayCells (display, XScreenNumberOfScreen (screen)); XColor *cells = (XColor *) alloca (ncells * sizeof *cells); for (i = 0; i < ncells; ++i) cells[i].pixel = i; XQueryColors (display, cmap, cells, ncells); for (nearest = i = 0; i < ncells; ++i) { long dred = (color->red >> 8) - (cells[i].red >> 8); long dgreen = (color->green >> 8) - (cells[i].green >> 8); long dblue = (color->blue >> 8) - (cells[i].blue >> 8); unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue; if (delta < nearest_delta) { nearest = i; nearest_delta = delta; } } color->red = cells[nearest].red; color->green = cells[nearest].green; color->blue = cells[nearest].blue; rc = XAllocColor (display, cmap, color); } #ifdef DEBUG_X_COLORS if (rc) register_color (color->pixel); #endif /* DEBUG_X_COLORS */ return rc; } /* Allocate color PIXEL on frame F. PIXEL must already be allocated. It's necessary to do this instead of just using PIXEL directly to get color reference counts right. */ unsigned long x_copy_color (f, pixel) struct frame *f; unsigned long pixel; { XColor color; color.pixel = pixel; BLOCK_INPUT; XQueryColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &color); XAllocColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &color); UNBLOCK_INPUT; #ifdef DEBUG_X_COLORS register_color (pixel); #endif return color.pixel; } /* Allocate color PIXEL on display DPY. PIXEL must already be allocated. It's necessary to do this instead of just using PIXEL directly to get color reference counts right. */ unsigned long x_copy_dpy_color (dpy, cmap, pixel) Display *dpy; Colormap cmap; unsigned long pixel; { XColor color; color.pixel = pixel; BLOCK_INPUT; XQueryColor (dpy, cmap, &color); XAllocColor (dpy, cmap, &color); UNBLOCK_INPUT; #ifdef DEBUG_X_COLORS register_color (pixel); #endif return color.pixel; } #endif /* Allocate a color which is lighter or darker than *COLOR by FACTOR or DELTA. Try a color with RGB values multiplied by FACTOR first. If this produces the same color as COLOR, try a color where all RGB values have DELTA added. Return the allocated color in *COLOR. DISPLAY is the X display, CMAP is the colormap to operate on. Value is non-zero if successful. */ static int mac_alloc_lighter_color (f, color, factor, delta) struct frame *f; unsigned long *color; double factor; int delta; { unsigned long new; /* Change RGB values by specified FACTOR. Avoid overflow! */ xassert (factor >= 0); new = RGB_TO_ULONG (min (0xff, (int) (factor * RED_FROM_ULONG (*color))), min (0xff, (int) (factor * GREEN_FROM_ULONG (*color))), min (0xff, (int) (factor * BLUE_FROM_ULONG (*color)))); if (new == *color) new = RGB_TO_ULONG (max (0, min (0xff, (int) (delta + RED_FROM_ULONG (*color)))), max (0, min (0xff, (int) (delta + GREEN_FROM_ULONG (*color)))), max (0, min (0xff, (int) (delta + BLUE_FROM_ULONG (*color))))); /* MAC_TODO: Map to palette and retry with delta if same? */ /* MAC_TODO: Free colors (if using palette)? */ if (new == *color) return 0; *color = new; return 1; } /* Set up the foreground color for drawing relief lines of glyph string S. RELIEF is a pointer to a struct relief containing the GC with which lines will be drawn. Use a color that is FACTOR or DELTA lighter or darker than the relief's background which is found in S->f->output_data.x->relief_background. If such a color cannot be allocated, use DEFAULT_PIXEL, instead. */ static void x_setup_relief_color (f, relief, factor, delta, default_pixel) struct frame *f; struct relief *relief; double factor; int delta; unsigned long default_pixel; { XGCValues xgcv; struct mac_output *di = f->output_data.mac; unsigned long mask = GCForeground; unsigned long pixel; unsigned long background = di->relief_background; struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); /* MAC_TODO: Free colors (if using palette)? */ /* Allocate new color. */ xgcv.foreground = default_pixel; pixel = background; if (mac_alloc_lighter_color (f, &pixel, factor, delta)) { relief->allocated_p = 1; xgcv.foreground = relief->pixel = pixel; } if (relief->gc == 0) { #if 0 /* MAC_TODO: stipple */ xgcv.stipple = dpyinfo->gray; mask |= GCStipple; #endif relief->gc = XCreateGC (NULL, FRAME_MAC_WINDOW (f), mask, &xgcv); } else XChangeGC (NULL, relief->gc, mask, &xgcv); } /* Set up colors for the relief lines around glyph string S. */ static void x_setup_relief_colors (s) struct glyph_string *s; { struct mac_output *di = s->f->output_data.mac; unsigned long color; if (s->face->use_box_color_for_shadows_p) color = s->face->box_color; else { XGCValues xgcv; /* Get the background color of the face. */ XGetGCValues (s->display, s->gc, GCBackground, &xgcv); color = xgcv.background; } if (di->white_relief.gc == 0 || color != di->relief_background) { di->relief_background = color; x_setup_relief_color (s->f, &di->white_relief, 1.2, 0x8000, WHITE_PIX_DEFAULT (s->f)); x_setup_relief_color (s->f, &di->black_relief, 0.6, 0x4000, BLACK_PIX_DEFAULT (s->f)); } } /* Draw a relief on frame F inside the rectangle given by LEFT_X, TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief to draw, it must be >= 0. RAISED_P non-zero means draw a raised relief. LEFT_P non-zero means draw a relief on the left side of the rectangle. RIGHT_P non-zero means draw a relief on the right side of the rectangle. CLIP_RECT is the clipping rectangle to use when drawing. */ static void x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, raised_p, left_p, right_p, clip_rect) struct frame *f; int left_x, top_y, right_x, bottom_y, left_p, right_p, raised_p; Rect *clip_rect; { int i; GC gc; if (raised_p) gc = f->output_data.mac->white_relief.gc; else gc = f->output_data.mac->black_relief.gc; mac_set_clip_rectangle (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), clip_rect); /* Top. */ for (i = 0; i < width; ++i) XDrawLine (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), gc, left_x + i * left_p, top_y + i, right_x + 1 - i * right_p, top_y + i); /* Left. */ if (left_p) for (i = 0; i < width; ++i) XDrawLine (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), gc, left_x + i, top_y + i, left_x + i, bottom_y - i); mac_reset_clipping (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f)); if (raised_p) gc = f->output_data.mac->black_relief.gc; else gc = f->output_data.mac->white_relief.gc; mac_set_clip_rectangle (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), clip_rect); /* Bottom. */ for (i = 0; i < width; ++i) XDrawLine (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), gc, left_x + i * left_p, bottom_y - i, right_x + 1 - i * right_p, bottom_y - i); /* Right. */ if (right_p) for (i = 0; i < width; ++i) XDrawLine (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), gc, right_x - i, top_y + i + 1, right_x - i, bottom_y - i); mac_reset_clipping (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f)); } /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to draw, it must be >= 0. LEFT_P non-zero means draw a line on the left side of the rectangle. RIGHT_P non-zero means draw a line on the right side of the rectangle. CLIP_RECT is the clipping rectangle to use when drawing. */ static void x_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, left_p, right_p, clip_rect) struct glyph_string *s; int left_x, top_y, right_x, bottom_y, left_p, right_p; Rect *clip_rect; { XGCValues xgcv; xgcv.foreground = s->face->box_color; mac_set_clip_rectangle (s->display, s->window, clip_rect); /* Top. */ XFillRectangle (s->display, s->window, &xgcv, left_x, top_y, right_x - left_x, width); /* Left. */ if (left_p) XFillRectangle (s->display, s->window, &xgcv, left_x, top_y, width, bottom_y - top_y); /* Bottom. */ XFillRectangle (s->display, s->window, &xgcv, left_x, bottom_y - width, right_x - left_x, width); /* Right. */ if (right_p) XFillRectangle (s->display, s->window, &xgcv, right_x - width, top_y, width, bottom_y - top_y); mac_reset_clipping (s->display, s->window); } /* Draw a box around glyph string S. */ static void x_draw_glyph_string_box (s) struct glyph_string *s; { int width, left_x, right_x, top_y, bottom_y, last_x, raised_p; int left_p, right_p; struct glyph *last_glyph; Rect clip_rect; last_x = window_box_right (s->w, s->area); if (s->row->full_width_p && !s->w->pseudo_window_p) { last_x += FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s->f); if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s->f)) last_x += FRAME_SCROLL_BAR_WIDTH (s->f) * CANON_X_UNIT (s->f); } /* The glyph that may have a right box line. */ last_glyph = (s->cmp || s->img ? s->first_glyph : s->first_glyph + s->nchars - 1); width = s->face->box_line_width; raised_p = s->face->box == FACE_RAISED_BOX; left_x = s->x; right_x = ((s->row->full_width_p ? last_x - 1 : min (last_x, s->x + s->background_width) - 1)); top_y = s->y; bottom_y = top_y + s->height - 1; left_p = (s->first_glyph->left_box_line_p || (s->hl == DRAW_MOUSE_FACE && (s->prev == NULL || s->prev->hl != s->hl))); right_p = (last_glyph->right_box_line_p || (s->hl == DRAW_MOUSE_FACE && (s->next == NULL || s->next->hl != s->hl))); x_get_glyph_string_clip_rect (s, &clip_rect); if (s->face->box == FACE_SIMPLE_BOX) x_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, left_p, right_p, &clip_rect); else { x_setup_relief_colors (s); x_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y, width, raised_p, left_p, right_p, &clip_rect); } } /* Draw foreground of image glyph string S. */ static void x_draw_image_foreground (s) struct glyph_string *s; { int x; int y = s->ybase - image_ascent (s->img, s->face); /* If first glyph of S has a left box line, start drawing it to the right of that line. */ if (s->face->box != FACE_NO_BOX && s->first_glyph->left_box_line_p) x = s->x + s->face->box_line_width; else x = s->x; /* If there is a margin around the image, adjust x- and y-position by that margin. */ x += s->img->hmargin; y += s->img->vmargin; if (s->img->pixmap) { #if 0 /* MAC_TODO: image mask */ if (s->img->mask) { /* We can't set both a clip mask and use XSetClipRectangles because the latter also sets a clip mask. We also can't trust on the shape extension to be available (XShapeCombineRegion). So, compute the rectangle to draw manually. */ unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | GCFunction); XGCValues xgcv; XRectangle clip_rect, image_rect, r; xgcv.clip_mask = s->img->mask; xgcv.clip_x_origin = x; xgcv.clip_y_origin = y; xgcv.function = GXcopy; XChangeGC (s->display, s->gc, mask, &xgcv); x_get_glyph_string_clip_rect (s, &clip_rect); image_rect.x = x; image_rect.y = y; image_rect.width = s->img->width; image_rect.height = s->img->height; if (x_intersect_rectangles (&clip_rect, &image_rect, &r)) XCopyArea (s->display, s->img->pixmap, s->window, s->gc, r.x - x, r.y - y, r.width, r.height, r.x, r.y); } else #endif { mac_copy_area (s->display, s->img->pixmap, s->window, s->gc, 0, 0, s->img->width, s->img->height, x, y); /* When the image has a mask, we can expect that at least part of a mouse highlight or a block cursor will be visible. If the image doesn't have a mask, make a block cursor visible by drawing a rectangle around the image. I believe it's looking better if we do nothing here for mouse-face. */ if (s->hl == DRAW_CURSOR) mac_draw_rectangle (s->display, s->window, s->gc, x, y, s->img->width - 1, s->img->height - 1); } } else /* Draw a rectangle if image could not be loaded. */ mac_draw_rectangle (s->display, s->window, s->gc, x, y, s->img->width - 1, s->img->height - 1); } /* Draw a relief around the image glyph string S. */ static void x_draw_image_relief (s) struct glyph_string *s; { int x0, y0, x1, y1, thick, raised_p; Rect r; int x; int y = s->ybase - image_ascent (s->img, s->face); /* If first glyph of S has a left box line, start drawing it to the right of that line. */ if (s->face->box != FACE_NO_BOX && s->first_glyph->left_box_line_p) x = s->x + s->face->box_line_width; else x = s->x; /* If there is a margin around the image, adjust x- and y-position by that margin. */ x += s->img->hmargin; y += s->img->vmargin; if (s->hl == DRAW_IMAGE_SUNKEN || s->hl == DRAW_IMAGE_RAISED) { thick = tool_bar_button_relief > 0 ? tool_bar_button_relief : 3; raised_p = s->hl == DRAW_IMAGE_RAISED; } else { thick = abs (s->img->relief); raised_p = s->img->relief > 0; } x0 = x - thick; y0 = y - thick; x1 = x + s->img->width + thick - 1; y1 = y + s->img->height + thick - 1; x_setup_relief_colors (s); x_get_glyph_string_clip_rect (s, &r); x_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p, 1, 1, &r); } /* Draw the foreground of image glyph string S to PIXMAP. */ static void x_draw_image_foreground_1 (s, pixmap) struct glyph_string *s; Pixmap pixmap; { int x; int y = s->ybase - s->y - image_ascent (s->img, s->face); /* If first glyph of S has a left box line, start drawing it to the right of that line. */ if (s->face->box != FACE_NO_BOX && s->first_glyph->left_box_line_p) x = s->face->box_line_width; else x = 0; /* If there is a margin around the image, adjust x- and y-position by that margin. */ x += s->img->hmargin; y += s->img->vmargin; if (s->img->pixmap) { #if 0 /* MAC_TODO: image mask */ if (s->img->mask) { /* We can't set both a clip mask and use XSetClipRectangles because the latter also sets a clip mask. We also can't trust on the shape extension to be available (XShapeCombineRegion). So, compute the rectangle to draw manually. */ unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | GCFunction); XGCValues xgcv; xgcv.clip_mask = s->img->mask; xgcv.clip_x_origin = x; xgcv.clip_y_origin = y; xgcv.function = GXcopy; XChangeGC (s->display, s->gc, mask, &xgcv); XCopyArea (s->display, s->img->pixmap, pixmap, s->gc, 0, 0, s->img->width, s->img->height, x, y); XSetClipMask (s->display, s->gc, None); } else #endif { mac_copy_area_to_pixmap (s->display, s->img->pixmap, pixmap, s->gc, 0, 0, s->img->width, s->img->height, x, y); /* When the image has a mask, we can expect that at least part of a mouse highlight or a block cursor will be visible. If the image doesn't have a mask, make a block cursor visible by drawing a rectangle around the image. I believe it's looking better if we do nothing here for mouse-face. */ if (s->hl == DRAW_CURSOR) mac_draw_rectangle_to_pixmap (s->display, pixmap, s->gc, x, y, s->img->width - 1, s->img->height - 1); } } else /* Draw a rectangle if image could not be loaded. */ mac_draw_rectangle_to_pixmap (s->display, pixmap, s->gc, x, y, s->img->width - 1, s->img->height - 1); } /* Draw part of the background of glyph string S. X, Y, W, and H give the rectangle to draw. */ static void x_draw_glyph_string_bg_rect (s, x, y, w, h) struct glyph_string *s; int x, y, w, h; { #if 0 /* MAC_TODO: stipple */ if (s->stippled_p) { /* Fill background with a stipple pattern. */ XSetFillStyle (s->display, s->gc, FillOpaqueStippled); XFillRectangle (s->display, s->window, s->gc, x, y, w, h); XSetFillStyle (s->display, s->gc, FillSolid); } else #endif x_clear_glyph_string_rect (s, x, y, w, h); } /* Draw image glyph string S. s->y s->x +------------------------- | s->face->box | | +------------------------- | | s->img->vmargin | | | | +------------------- | | | the image */ static void x_draw_image_glyph_string (s) struct glyph_string *s; { int x, y; int box_line_width = s->face->box_line_width; int height; Pixmap pixmap = 0; height = s->height - 2 * box_line_width; /* Fill background with face under the image. Do it only if row is taller than image or if image has a clip mask to reduce flickering. */ s->stippled_p = s->face->stipple != 0; if (height > s->img->height || s->img->vmargin || s->img->hmargin #if 0 /* MAC_TODO: image mask */ || s->img->mask #endif || s->img->pixmap == 0 || s->width != s->background_width) { if (box_line_width && s->first_glyph->left_box_line_p) x = s->x + box_line_width; else x = s->x; y = s->y + box_line_width; #if 0 /* MAC_TODO: image mask */ if (s->img->mask) { /* Create a pixmap as large as the glyph string Fill it with the background color. Copy the image to it, using its mask. Copy the temporary pixmap to the display. */ Screen *screen = FRAME_X_SCREEN (s->f); int depth = DefaultDepthOfScreen (screen); /* Create a pixmap as large as the glyph string. */ pixmap = XCreatePixmap (s->display, s->window, s->background_width, s->height, depth); /* Don't clip in the following because we're working on the pixmap. */ XSetClipMask (s->display, s->gc, None); /* Fill the pixmap with the background color/stipple. */ if (s->stippled_p) { /* Fill background with a stipple pattern. */ XSetFillStyle (s->display, s->gc, FillOpaqueStippled); XFillRectangle (s->display, pixmap, s->gc, 0, 0, s->background_width, s->height); XSetFillStyle (s->display, s->gc, FillSolid); } else { XGCValues xgcv; XGetGCValues (s->display, s->gc, GCForeground | GCBackground, &xgcv); XSetForeground (s->display, s->gc, xgcv.background); XFillRectangle (s->display, pixmap, s->gc, 0, 0, s->background_width, s->height); XSetForeground (s->display, s->gc, xgcv.foreground); } } else #endif /* Implementation idea: Is it possible to construct a mask? We could look at the color at the margins of the image, and say that this color is probably the background color of the image. */ x_draw_glyph_string_bg_rect (s, x, y, s->background_width, height); s->background_filled_p = 1; } /* Draw the foreground. */ if (pixmap != 0) { x_draw_image_foreground_1 (s, pixmap); x_set_glyph_string_clipping (s); mac_copy_area (s->display, pixmap, s->window, s->gc, 0, 0, s->background_width, s->height, s->x, s->y); XFreePixmap (s->display, pixmap); } else x_draw_image_foreground (s); /* If we must draw a relief around the image, do it. */ if (s->img->relief || s->hl == DRAW_IMAGE_RAISED || s->hl == DRAW_IMAGE_SUNKEN) x_draw_image_relief (s); } /* Draw stretch glyph string S. */ static void x_draw_stretch_glyph_string (s) struct glyph_string *s; { xassert (s->first_glyph->type == STRETCH_GLYPH); s->stippled_p = s->face->stipple != 0; if (s->hl == DRAW_CURSOR && !x_stretch_cursor_p) { /* If `x-stretch-block-cursor' is nil, don't draw a block cursor as wide as the stretch glyph. */ int width = min (CANON_X_UNIT (s->f), s->background_width); /* Draw cursor. */ x_draw_glyph_string_bg_rect (s, s->x, s->y, width, s->height); /* Clear rest using the GC of the original non-cursor face. */ if (width < s->background_width) { GC gc = s->face->gc; int x = s->x + width, y = s->y; int w = s->background_width - width, h = s->height; Rect r; x_get_glyph_string_clip_rect (s, &r); mac_set_clip_rectangle (s->display, s->window, &r); #if 0 /* MAC_TODO: stipple */ if (s->face->stipple) { /* Fill background with a stipple pattern. */ XSetFillStyle (s->display, gc, FillOpaqueStippled); XFillRectangle (s->display, s->window, gc, x, y, w, h); XSetFillStyle (s->display, gc, FillSolid); } else #endif { XGCValues xgcv; XGetGCValues (s->display, gc, GCForeground | GCBackground, &xgcv); XSetForeground (s->display, gc, xgcv.background); XFillRectangle (s->display, s->window, gc, x, y, w, h); XSetForeground (s->display, gc, xgcv.foreground); } } } else x_draw_glyph_string_bg_rect (s, s->x, s->y, s->background_width, s->height); s->background_filled_p = 1; } /* Draw glyph string S. */ static void x_draw_glyph_string (s) struct glyph_string *s; { /* If S draws into the background of its successor, draw the back