From: Paul Eggert Date: Fri, 2 Dec 2016 05:47:12 +0000 (-0800) Subject: Make struct font_drivers read-only X-Git-Tag: emacs-26.0.90~1236 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ebb96114d88af64cbb72f42052cb359ba8010aa2;p=emacs.git Make struct font_drivers read-only This simplifies the code a bit, and makes the structs more shareable and less likely to become corrupt. * src/alloc.c (cleanup_vector): * src/font.c (valid_font_driver, font_prepare_cache) (font_finish_cache, font_get_cache, font_clear_cache) (register_font_driver, font_update_drivers): * src/font.h (struct font, struct font_driver_list) (valid_font_driver): struct font_drivers are now const. * src/font.c, src/ftcrfont.c, src/ftfont.c, src/nsfont.m, src/xfont.c: Omit no-longer-necessary decls. * src/ftcrfont.c (syms_of_ftcrfont): * src/ftxfont.c (syms_of_ftxfont): * src/xftfont.c (syms_of_xftfont): Omit no-longer-necessary initialization code. * src/ftcrfont.c (ftcrfont_driver): * src/ftfont.c (ftfont_driver): * src/ftxfont.c (ftxfont_driver): * src/macfont.m (macfont_driver): * src/nsfont.m (nsfont_driver): * src/xfont.c (xfont_driver): * src/xftfont.c (xftfont_driver): Use C99-style initializer for ease of maintenance, and make it const. * src/ftcrfont.c, src/ftxfont.c, src/xftfont.c: Refer to functions like ftfont_text_extents directly. * src/ftfont.c (ftfont_get_cache, ftfont_list, ftfont_list_family) (ftfont_has_char, ftfont_encode_char, ftfont_text_extents) (ftfont_get_bitmap, ftfont_anchor_point, ftfont_otf_capability) (ftfont_variation_glyphs, ftfont_filter_properties) (ftfont_combining_capability): * src/xfont.c (xfont_get_cache): Now extern, so that other modules’ struct font_drivers can use them directly. * src/macfont.m (macfont_descriptor_entity): * src/nsfont.m (nsfont_open): Use constant directly; this is clearer. --- diff --git a/src/alloc.c b/src/alloc.c index 175dcab2487..ae32400708a 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3201,7 +3201,7 @@ cleanup_vector (struct Lisp_Vector *vector) && ((vector->header.size & PSEUDOVECTOR_SIZE_MASK) == FONT_OBJECT_MAX)) { - struct font_driver *drv = ((struct font *) vector)->driver; + struct font_driver const *drv = ((struct font *) vector)->driver; /* The font driver might sometimes be NULL, e.g. if Emacs was interrupted before it had time to set it up. */ diff --git a/src/font.c b/src/font.c index ce632335256..9fe7c26ea9c 100644 --- a/src/font.c +++ b/src/font.c @@ -132,7 +132,7 @@ static struct font_driver_list *font_driver_list; /* Used to catch bogus pointers in font objects. */ bool -valid_font_driver (struct font_driver *drv) +valid_font_driver (struct font_driver const *drv) { Lisp_Object tail, frame; struct font_driver_list *fdl; @@ -2543,14 +2543,11 @@ font_match_p (Lisp_Object spec, Lisp_Object font) is a number frames sharing this cache, and FONT-CACHE-DATA is a cons (FONT-SPEC . [FONT-ENTITY ...]). */ -static void font_prepare_cache (struct frame *, struct font_driver *); -static void font_finish_cache (struct frame *, struct font_driver *); -static Lisp_Object font_get_cache (struct frame *, struct font_driver *); static void font_clear_cache (struct frame *, Lisp_Object, - struct font_driver *); + struct font_driver const *); static void -font_prepare_cache (struct frame *f, struct font_driver *driver) +font_prepare_cache (struct frame *f, struct font_driver const *driver) { Lisp_Object cache, val; @@ -2572,7 +2569,7 @@ font_prepare_cache (struct frame *f, struct font_driver *driver) static void -font_finish_cache (struct frame *f, struct font_driver *driver) +font_finish_cache (struct frame *f, struct font_driver const *driver) { Lisp_Object cache, val, tmp; @@ -2593,7 +2590,7 @@ font_finish_cache (struct frame *f, struct font_driver *driver) static Lisp_Object -font_get_cache (struct frame *f, struct font_driver *driver) +font_get_cache (struct frame *f, struct font_driver const *driver) { Lisp_Object val = driver->get_cache (f); Lisp_Object type = driver->type; @@ -2608,7 +2605,8 @@ font_get_cache (struct frame *f, struct font_driver *driver) static void -font_clear_cache (struct frame *f, Lisp_Object cache, struct font_driver *driver) +font_clear_cache (struct frame *f, Lisp_Object cache, + struct font_driver const *driver) { Lisp_Object tail, elt; Lisp_Object entity; @@ -3463,7 +3461,7 @@ font_open_by_name (struct frame *f, Lisp_Object name) (e.g. syms_of_xfont). */ void -register_font_driver (struct font_driver *driver, struct frame *f) +register_font_driver (struct font_driver const *driver, struct frame *f) { struct font_driver_list *root = f ? f->font_driver_list : font_driver_list; struct font_driver_list *prev, *list; @@ -3524,7 +3522,7 @@ font_update_drivers (struct frame *f, Lisp_Object new_drivers) drivers. */ for (list = f->font_driver_list; list; list = list->next) { - struct font_driver *driver = list->driver; + struct font_driver const *driver = list->driver; if ((EQ (new_drivers, Qt) || ! NILP (Fmemq (driver->type, new_drivers))) != list->on) { @@ -3587,7 +3585,7 @@ font_update_drivers (struct frame *f, Lisp_Object new_drivers) and then use it under w32 or ns. */ for (list = f->font_driver_list; list; list = list->next) { - struct font_driver *driver = list->driver; + struct font_driver const *driver = list->driver; eassert (! list->on); if (! driver->start_for_frame || driver->start_for_frame (f) == 0) diff --git a/src/font.h b/src/font.h index c14823bc1eb..af0214c3f23 100644 --- a/src/font.h +++ b/src/font.h @@ -380,7 +380,7 @@ struct font #endif /* HAVE_WINDOW_SYSTEM */ /* Font-driver for the font. */ - struct font_driver *driver; + struct font_driver const *driver; /* There are more members in this structure, but they are private to the font-driver. */ @@ -783,7 +783,7 @@ struct font_driver_list font driver list.*/ bool on; /* Pointer to the font driver. */ - struct font_driver *driver; + struct font_driver const *driver; /* Pointer to the next element of the chain. */ struct font_driver_list *next; }; @@ -841,13 +841,13 @@ extern void font_parse_family_registry (Lisp_Object family, extern int font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font); extern ptrdiff_t font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int bytes); -extern void register_font_driver (struct font_driver *driver, struct frame *f); +extern void register_font_driver (struct font_driver const *, struct frame *); extern void free_font_driver_list (struct frame *f); #ifdef ENABLE_CHECKING -extern bool valid_font_driver (struct font_driver *); +extern bool valid_font_driver (struct font_driver const *); #else INLINE bool -valid_font_driver (struct font_driver *d) +valid_font_driver (struct font_driver const *d) { return true; } @@ -874,18 +874,37 @@ extern void font_filter_properties (Lisp_Object font, extern void font_drop_xrender_surfaces (struct frame *f); #ifdef HAVE_FREETYPE -extern struct font_driver ftfont_driver; +extern int ftfont_anchor_point (struct font *, unsigned int, int, + int *, int *); +extern int ftfont_get_bitmap (struct font *, unsigned int, + struct font_bitmap *, int); +extern int ftfont_has_char (Lisp_Object, int); +extern int ftfont_variation_glyphs (struct font *, int, unsigned[256]); +extern Lisp_Object ftfont_combining_capability (struct font *); +extern Lisp_Object ftfont_get_cache (struct frame *); +extern Lisp_Object ftfont_list (struct frame *, Lisp_Object); +extern Lisp_Object ftfont_list_family (struct frame *); +extern Lisp_Object ftfont_match (struct frame *, Lisp_Object); +extern Lisp_Object ftfont_open (struct frame *, Lisp_Object, int); +extern Lisp_Object ftfont_otf_capability (struct font *); +extern Lisp_Object ftfont_shape (Lisp_Object); +extern unsigned ftfont_encode_char (struct font *, int); +extern void ftfont_close (struct font *); +extern void ftfont_filter_properties (Lisp_Object, Lisp_Object); +extern void ftfont_text_extents (struct font *, unsigned *, int, + struct font_metrics *); extern void syms_of_ftfont (void); #endif /* HAVE_FREETYPE */ #ifdef HAVE_X_WINDOWS -extern struct font_driver xfont_driver; +extern struct font_driver const xfont_driver; +extern Lisp_Object xfont_get_cache (struct frame *); extern void syms_of_xfont (void); extern void syms_of_ftxfont (void); #ifdef HAVE_XFT -extern struct font_driver xftfont_driver; +extern struct font_driver const xftfont_driver; #endif #if defined HAVE_FREETYPE || defined HAVE_XFT -extern struct font_driver ftxfont_driver; +extern struct font_driver const ftxfont_driver; extern void syms_of_xftfont (void); #endif #ifdef HAVE_BDFFONT @@ -898,12 +917,12 @@ extern struct font_driver uniscribe_font_driver; extern void syms_of_w32font (void); #endif /* HAVE_NTGUI */ #ifdef HAVE_NS -extern struct font_driver nsfont_driver; +extern struct font_driver const nsfont_driver; extern void syms_of_nsfont (void); extern void syms_of_macfont (void); #endif /* HAVE_NS */ #ifdef USE_CAIRO -extern struct font_driver ftcrfont_driver; +extern struct font_driver const ftcrfont_driver; extern void syms_of_ftcrfont (void); #endif diff --git a/src/ftcrfont.c b/src/ftcrfont.c index 2676502705d..f62b40f41c4 100644 --- a/src/ftcrfont.c +++ b/src/ftcrfont.c @@ -65,8 +65,6 @@ enum metrics_status #define METRICS_SET_STATUS(metrics, status) \ ((metrics)->ascent = 0, (metrics)->descent = (status)) -struct font_driver ftcrfont_driver; - static int ftcrfont_glyph_extents (struct font *font, unsigned glyph, @@ -101,7 +99,7 @@ ftcrfont_glyph_extents (struct font *font, cache = ftcrfont_info->metrics[row] + col; if (METRICS_STATUS (cache) == METRICS_INVALID) - ftfont_driver.text_extents (font, &glyph, 1, cache); + ftfont_text_extents (font, &glyph, 1, cache); if (metrics) *metrics = *cache; @@ -112,7 +110,7 @@ ftcrfont_glyph_extents (struct font *font, static Lisp_Object ftcrfont_list (struct frame *f, Lisp_Object spec) { - Lisp_Object list = ftfont_driver.list (f, spec), tail; + Lisp_Object list = ftfont_list (f, spec), tail; for (tail = list; CONSP (tail); tail = XCDR (tail)) ASET (XCAR (tail), FONT_TYPE_INDEX, Qftcr); @@ -122,15 +120,13 @@ ftcrfont_list (struct frame *f, Lisp_Object spec) static Lisp_Object ftcrfont_match (struct frame *f, Lisp_Object spec) { - Lisp_Object entity = ftfont_driver.match (f, spec); + Lisp_Object entity = ftfont_match (f, spec); if (VECTORP (entity)) ASET (entity, FONT_TYPE_INDEX, Qftcr); return entity; } -extern FT_Face ftfont_get_ft_face (Lisp_Object); - static Lisp_Object ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size) { @@ -181,7 +177,7 @@ ftcrfont_close (struct font *font) cairo_font_face_destroy (ftcrfont_info->cr_font_face); unblock_input (); - ftfont_driver.close (font); + ftfont_close (font); } static void @@ -282,6 +278,34 @@ ftcrfont_draw (struct glyph_string *s, +struct font_driver const ftcrfont_driver = + { + type: LISPSYM_INITIALLY (Qftcr), + get_cache: ftfont_get_cache, + list: ftcrfont_list, + match: ftcrfont_match, + list_family: ftfont_list_family, + open: ftcrfont_open, + close: ftcrfont_close, + has_char: ftfont_has_char, + encode_char: ftfont_encode_char, + text_extents: ftcrfont_text_extents, + draw: ftcrfont_draw, + get_bitmap: ftfont_get_bitmap, + anchor_point: ftfont_anchor_point, +#ifdef HAVE_LIBOTF + otf_capability: ftfont_otf_capability, +#endif +#if defined HAVE_M17N_FLT && defined HAVE_LIBOTF + shape: ftfont_shape, +#endif +#ifdef HAVE_OTF_GET_VARIATION_GLYPHS + get_variation_glyphs: ftfont_variation_glyphs, +#endif + filter_properties: ftfont_filter_properties, + combining_capability: ftfont_combining_capability, + }; + void syms_of_ftcrfont (void) { @@ -289,14 +313,5 @@ syms_of_ftcrfont (void) abort (); DEFSYM (Qftcr, "ftcr"); - - ftcrfont_driver = ftfont_driver; - ftcrfont_driver.type = Qftcr; - ftcrfont_driver.list = ftcrfont_list; - ftcrfont_driver.match = ftcrfont_match; - ftcrfont_driver.open = ftcrfont_open; - ftcrfont_driver.close = ftcrfont_close; - ftcrfont_driver.text_extents = ftcrfont_text_extents; - ftcrfont_driver.draw = ftcrfont_draw; register_font_driver (&ftcrfont_driver, NULL); } diff --git a/src/ftfont.c b/src/ftfont.c index 17fe66828fa..768b524f0a6 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -35,6 +35,8 @@ along with GNU Emacs. If not, see . */ #include "font.h" #include "ftfont.h" +static struct font_driver const ftfont_driver; + /* Flag to tell if FcInit is already called or not. */ static bool fc_initialized; @@ -73,17 +75,9 @@ enum ftfont_cache_for FTFONT_CACHE_FOR_ENTITY }; -static Lisp_Object ftfont_pattern_entity (FcPattern *, Lisp_Object); - -static Lisp_Object ftfont_resolve_generic_family (Lisp_Object, - FcPattern *); static Lisp_Object ftfont_lookup_cache (Lisp_Object, enum ftfont_cache_for); -static void ftfont_filter_properties (Lisp_Object font, Lisp_Object alist); - -static Lisp_Object ftfont_combining_capability (struct font *); - #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM)) static struct @@ -480,83 +474,7 @@ ftfont_get_otf (struct ftfont_info *ftfont_info) } #endif /* HAVE_LIBOTF */ -static Lisp_Object ftfont_get_cache (struct frame *); -static Lisp_Object ftfont_list (struct frame *, Lisp_Object); -static Lisp_Object ftfont_match (struct frame *, Lisp_Object); -static Lisp_Object ftfont_list_family (struct frame *); -static Lisp_Object ftfont_open (struct frame *, Lisp_Object, int); -static void ftfont_close (struct font *); -static int ftfont_has_char (Lisp_Object, int); -static unsigned ftfont_encode_char (struct font *, int); -static void ftfont_text_extents (struct font *, unsigned *, int, - struct font_metrics *); -static int ftfont_get_bitmap (struct font *, unsigned, - struct font_bitmap *, int); -static int ftfont_anchor_point (struct font *, unsigned, int, - int *, int *); -#ifdef HAVE_LIBOTF -static Lisp_Object ftfont_otf_capability (struct font *); -# ifdef HAVE_M17N_FLT -static Lisp_Object ftfont_shape (Lisp_Object); -# endif -#endif - -#ifdef HAVE_OTF_GET_VARIATION_GLYPHS -static int ftfont_variation_glyphs (struct font *, int c, - unsigned variations[256]); -#endif /* HAVE_OTF_GET_VARIATION_GLYPHS */ - -struct font_driver ftfont_driver = - { - LISPSYM_INITIALLY (Qfreetype), - 0, /* case insensitive */ - ftfont_get_cache, - ftfont_list, - ftfont_match, - ftfont_list_family, - NULL, /* free_entity */ - ftfont_open, - ftfont_close, - /* We can't draw a text without device dependent functions. */ - NULL, /* prepare_face */ - NULL, /* done_face */ - ftfont_has_char, - ftfont_encode_char, - ftfont_text_extents, - /* We can't draw a text without device dependent functions. */ - NULL, /* draw */ - ftfont_get_bitmap, - NULL, /* free_bitmap */ - ftfont_anchor_point, -#ifdef HAVE_LIBOTF - ftfont_otf_capability, -#else /* not HAVE_LIBOTF */ - NULL, -#endif /* not HAVE_LIBOTF */ - NULL, /* otf_drive */ - NULL, /* start_for_frame */ - NULL, /* end_for_frame */ -#if defined (HAVE_M17N_FLT) && defined (HAVE_LIBOTF) - ftfont_shape, -#else /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */ - NULL, -#endif /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */ - NULL, /* check */ - -#ifdef HAVE_OTF_GET_VARIATION_GLYPHS - ftfont_variation_glyphs, -#else - NULL, -#endif - - ftfont_filter_properties, /* filter_properties */ - - NULL, /* cached_font_ok */ - - ftfont_combining_capability, - }; - -static Lisp_Object +Lisp_Object ftfont_get_cache (struct frame *f) { return freetype_font_cache; @@ -873,7 +791,7 @@ ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **ots return pattern; } -static Lisp_Object +Lisp_Object ftfont_list (struct frame *f, Lisp_Object spec) { Lisp_Object val = Qnil, family, adstyle; @@ -1072,7 +990,7 @@ ftfont_list (struct frame *f, Lisp_Object spec) return val; } -static Lisp_Object +Lisp_Object ftfont_match (struct frame *f, Lisp_Object spec) { Lisp_Object entity = Qnil; @@ -1122,7 +1040,7 @@ ftfont_match (struct frame *f, Lisp_Object spec) return entity; } -static Lisp_Object +Lisp_Object ftfont_list_family (struct frame *f) { Lisp_Object list = Qnil; @@ -1301,7 +1219,7 @@ ftfont_open2 (struct frame *f, return font_object; } -static Lisp_Object +Lisp_Object ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) { Lisp_Object font_object; @@ -1314,7 +1232,7 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) return ftfont_open2 (f, entity, pixel_size, font_object); } -static void +void ftfont_close (struct font *font) { /* FIXME: Although this function can be called while garbage-collecting, @@ -1344,7 +1262,7 @@ ftfont_close (struct font *font) FT_Done_Size (ftfont_info->ft_size); } -static int +int ftfont_has_char (Lisp_Object font, int c) { struct charset *cs = NULL; @@ -1374,7 +1292,7 @@ ftfont_has_char (Lisp_Object font, int c) } } -static unsigned +unsigned ftfont_encode_char (struct font *font, int c) { struct ftfont_info *ftfont_info = (struct ftfont_info *) font; @@ -1385,7 +1303,7 @@ ftfont_encode_char (struct font *font, int c) return (code > 0 ? code : FONT_INVALID_CODE); } -static void +void ftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct font_metrics *metrics) { @@ -1429,7 +1347,7 @@ ftfont_text_extents (struct font *font, unsigned int *code, metrics->width = width; } -static int +int ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bitmap, int bits_per_pixel) { struct ftfont_info *ftfont_info = (struct ftfont_info *) font; @@ -1472,7 +1390,7 @@ ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bit return 0; } -static int +int ftfont_anchor_point (struct font *font, unsigned int code, int idx, int *x, int *y) { @@ -1538,7 +1456,7 @@ ftfont_otf_features (OTF_GSUB_GPOS *gsub_gpos) } -static Lisp_Object +Lisp_Object ftfont_otf_capability (struct font *font) { struct ftfont_info *ftfont_info = (struct ftfont_info *) font; @@ -2701,7 +2619,7 @@ ftfont_shape (Lisp_Object lgstring) #ifdef HAVE_OTF_GET_VARIATION_GLYPHS -static int +int ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256]) { struct ftfont_info *ftfont_info = (struct ftfont_info *) font; @@ -2759,14 +2677,14 @@ static const char *const ftfont_non_booleans [] = { NULL, }; -static void +void ftfont_filter_properties (Lisp_Object font, Lisp_Object alist) { font_filter_properties (font, alist, ftfont_booleans, ftfont_non_booleans); } -static Lisp_Object +Lisp_Object ftfont_combining_capability (struct font *font) { #ifdef HAVE_M17N_FLT @@ -2776,6 +2694,34 @@ ftfont_combining_capability (struct font *font) #endif } +static struct font_driver const ftfont_driver = + { + /* We can't draw a text without device dependent functions. */ + type: LISPSYM_INITIALLY (Qfreetype), + get_cache: ftfont_get_cache, + list: ftfont_list, + match: ftfont_match, + list_family: ftfont_list_family, + open: ftfont_open, + close: ftfont_close, + has_char: ftfont_has_char, + encode_char: ftfont_encode_char, + text_extents: ftfont_text_extents, + get_bitmap: ftfont_get_bitmap, + anchor_point: ftfont_anchor_point, +#ifdef HAVE_LIBOTF + otf_capability: ftfont_otf_capability, +#endif +#if defined HAVE_M17N_FLT && defined HAVE_LIBOTF + shape: ftfont_shape, +#endif +#ifdef HAVE_OTF_GET_VARIATION_GLYPHS + get_variation_glyphs: ftfont_variation_glyphs, +#endif + filter_properties: ftfont_filter_properties, + combining_capability: ftfont_combining_capability, + }; + void syms_of_ftfont (void) { diff --git a/src/ftxfont.c b/src/ftxfont.c index bfdeb4051b9..d8792ac27bd 100644 --- a/src/ftxfont.c +++ b/src/ftxfont.c @@ -31,8 +31,6 @@ along with GNU Emacs. If not, see . */ /* FTX font driver. */ -struct font_driver ftxfont_driver; - struct ftxfont_frame_data { /* Background and foreground colors. */ @@ -125,7 +123,7 @@ ftxfont_draw_bitmap (struct frame *f, GC gc_fore, GC *gcs, struct font *font, unsigned char *b; int i, j; - if (ftfont_driver.get_bitmap (font, code, &bitmap, size > 0x100 ? 1 : 8) < 0) + if (ftfont_get_bitmap (font, code, &bitmap, size > 0x100 ? 1 : 8) < 0) return 0; if (size > 0x100) { @@ -188,8 +186,7 @@ ftxfont_draw_bitmap (struct frame *f, GC gc_fore, GC *gcs, struct font *font, } } - if (ftfont_driver.free_bitmap) - ftfont_driver.free_bitmap (font, &bitmap); + /* There is no ftfont_free_bitmap, so do not try to free BITMAP. */ return bitmap.advance; } @@ -211,7 +208,7 @@ ftxfont_draw_background (struct frame *f, struct font *font, GC gc, int x, int y static Lisp_Object ftxfont_list (struct frame *f, Lisp_Object spec) { - Lisp_Object list = ftfont_driver.list (f, spec), tail; + Lisp_Object list = ftfont_list (f, spec), tail; for (tail = list; CONSP (tail); tail = XCDR (tail)) ASET (XCAR (tail), FONT_TYPE_INDEX, Qftx); @@ -221,7 +218,7 @@ ftxfont_list (struct frame *f, Lisp_Object spec) static Lisp_Object ftxfont_match (struct frame *f, Lisp_Object spec) { - Lisp_Object entity = ftfont_driver.match (f, spec); + Lisp_Object entity = ftfont_match (f, spec); if (VECTORP (entity)) ASET (entity, FONT_TYPE_INDEX, Qftx); @@ -231,13 +228,10 @@ ftxfont_match (struct frame *f, Lisp_Object spec) static Lisp_Object ftxfont_open (struct frame *f, Lisp_Object entity, int pixel_size) { - Lisp_Object font_object; - struct font *font; - - font_object = ftfont_driver.open (f, entity, pixel_size); + Lisp_Object font_object = ftfont_open (f, entity, pixel_size); if (NILP (font_object)) return Qnil; - font = XFONT_OBJECT (font_object); + struct font *font = XFONT_OBJECT (font_object); font->driver = &ftxfont_driver; return font_object; } @@ -245,7 +239,7 @@ ftxfont_open (struct frame *f, Lisp_Object entity, int pixel_size) static void ftxfont_close (struct font *font) { - ftfont_driver.close (font); + ftfont_close (font); } static int @@ -345,18 +339,39 @@ ftxfont_end_for_frame (struct frame *f) +struct font_driver const ftxfont_driver = + { + /* We can't draw a text without device dependent functions. */ + type: LISPSYM_INITIALLY (Qftx), + get_cache: ftfont_get_cache, + list: ftxfont_list, + match: ftxfont_match, + list_family: ftfont_list_family, + open: ftxfont_open, + close: ftxfont_close, + has_char: ftfont_has_char, + encode_char: ftfont_encode_char, + text_extents: ftfont_text_extents, + draw: ftxfont_draw, + get_bitmap: ftfont_get_bitmap, + anchor_point: ftfont_anchor_point, +#ifdef HAVE_LIBOTF + otf_capability: ftfont_otf_capability, +#endif + end_for_frame: ftxfont_end_for_frame, +#if defined HAVE_M17N_FLT && defined HAVE_LIBOTF + shape: ftfont_shape, +#endif +#ifdef HAVE_OTF_GET_VARIATION_GLYPHS + get_variation_glyphs: ftfont_variation_glyphs, +#endif + filter_properties: ftfont_filter_properties, + combining_capability: ftfont_combining_capability, + }; + void syms_of_ftxfont (void) { DEFSYM (Qftx, "ftx"); - - ftxfont_driver = ftfont_driver; - ftxfont_driver.type = Qftx; - ftxfont_driver.list = ftxfont_list; - ftxfont_driver.match = ftxfont_match; - ftxfont_driver.open = ftxfont_open; - ftxfont_driver.close = ftxfont_close; - ftxfont_driver.draw = ftxfont_draw; - ftxfont_driver.end_for_frame = ftxfont_end_for_frame; register_font_driver (&ftxfont_driver, NULL); } diff --git a/src/macfont.m b/src/macfont.m index b3a2fb84205..b2f3dff3097 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -38,8 +38,6 @@ Original author: YAMAMOTO Mitsuharu #include -static struct font_driver macfont_driver; - static double mac_font_get_advance_width_for_glyph (CTFontRef, CGGlyph); static CGRect mac_font_get_bounding_rect_for_glyph (CTFontRef, CGGlyph); static CFArrayRef mac_font_create_available_families (void); @@ -893,7 +891,7 @@ macfont_descriptor_entity (CTFontDescriptorRef desc, Lisp_Object extra, entity = font_make_entity (); - ASET (entity, FONT_TYPE_INDEX, macfont_driver.type); + ASET (entity, FONT_TYPE_INDEX, Qmac_ct); ASET (entity, FONT_REGISTRY_INDEX, Qiso10646_1); macfont_store_descriptor_attributes (desc, entity); @@ -1663,34 +1661,23 @@ static int macfont_variation_glyphs (struct font *, int c, unsigned variations[256]); static void macfont_filter_properties (Lisp_Object, Lisp_Object); -static struct font_driver macfont_driver = +static struct font_driver const macfont_driver = { - LISPSYM_INITIALLY (Qmac_ct), - 0, /* case insensitive */ - macfont_get_cache, - macfont_list, - macfont_match, - macfont_list_family, - macfont_free_entity, - macfont_open, - macfont_close, - NULL, /* prepare_face */ - NULL, /* done_face */ - macfont_has_char, - macfont_encode_char, - macfont_text_extents, - macfont_draw, - NULL, /* get_bitmap */ - NULL, /* free_bitmap */ - NULL, /* anchor_point */ - NULL, /* otf_capability */ - NULL, /* otf_drive */ - NULL, /* start_for_frame */ - NULL, /* end_for_frame */ - macfont_shape, - NULL, /* check */ - macfont_variation_glyphs, - macfont_filter_properties, + type: LISPSYM_INITIALLY (Qmac_ct), + get_cache: macfont_get_cache, + list: macfont_list, + match: macfont_match, + list_family: macfont_list_family, + free_entity: macfont_free_entity, + open: macfont_open, + close: macfont_close, + has_char: macfont_has_char, + encode_char: macfont_encode_char, + text_extents: macfont_text_extents, + draw: macfont_draw, + shape: macfont_shape, + get_variation_glyphs: macfont_variation_glyphs, + filter_properties: macfont_filter_properties, }; static Lisp_Object diff --git a/src/nsfont.m b/src/nsfont.m index c4c3c8dce7e..d14c362eddf 100644 --- a/src/nsfont.m +++ b/src/nsfont.m @@ -610,43 +610,6 @@ ns_findfonts (Lisp_Object font_spec, BOOL isMatch) ========================================================================== */ -static Lisp_Object nsfont_get_cache (struct frame *frame); -static Lisp_Object nsfont_list (struct frame *, Lisp_Object); -static Lisp_Object nsfont_match (struct frame *, Lisp_Object); -static Lisp_Object nsfont_list_family (struct frame *); -static Lisp_Object nsfont_open (struct frame *f, Lisp_Object font_entity, - int pixel_size); -static void nsfont_close (struct font *font); -static int nsfont_has_char (Lisp_Object entity, int c); -static unsigned int nsfont_encode_char (struct font *font, int c); -static void nsfont_text_extents (struct font *font, unsigned int *code, - int nglyphs, struct font_metrics *metrics); -static int nsfont_draw (struct glyph_string *s, int from, int to, int x, int y, - bool with_background); - -struct font_driver nsfont_driver = - { - LISPSYM_INITIALLY (Qns), - 1, /* case sensitive */ - nsfont_get_cache, - nsfont_list, - nsfont_match, - nsfont_list_family, - NULL, /*free_entity */ - nsfont_open, - nsfont_close, - NULL, /* prepare_face */ - NULL, /* done_face */ - nsfont_has_char, - nsfont_encode_char, - nsfont_text_extents, - nsfont_draw, - /* excluded: get_bitmap, free_bitmap, - anchor_point, otf_capability, otf_driver, - start_for_frame, end_for_frame, shape */ - }; - - /* Return a cache of font-entities on FRAME. The cache must be a cons whose cdr part is the actual cache area. */ static Lisp_Object @@ -788,7 +751,7 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size) font_object = font_make_object (VECSIZE (struct nsfont_info), font_entity, pixel_size); - ASET (font_object, FONT_TYPE_INDEX, nsfont_driver.type); + ASET (font_object, FONT_TYPE_INDEX, Qns); font_info = (struct nsfont_info *) XFONT_OBJECT (font_object); font = (struct font *) font_info; if (!font) @@ -1520,6 +1483,21 @@ ns_dump_glyphstring (struct glyph_string *s) fprintf (stderr, "\n"); } +struct font_driver const nsfont_driver = + { + type: LISPSYM_INITIALLY (Qns), + case_sensitive: true, + get_cache: nsfont_get_cache, + list: nsfont_list, + match: nsfont_match, + list_family: nsfont_list_family, + open: nsfont_open, + close: nsfont_close, + has_char: nsfont_has_char, + encode_char: nsfont_encode_char, + text_extents: nsfont_text_extents, + draw: nsfont_draw, + }; void syms_of_nsfont (void) diff --git a/src/xfont.c b/src/xfont.c index ccb8f070626..5999f6715cc 100644 --- a/src/xfont.c +++ b/src/xfont.c @@ -113,44 +113,7 @@ xfont_get_pcm (XFontStruct *xfont, XChar2b *char2b) ? NULL : pcm); } -static Lisp_Object xfont_get_cache (struct frame *); -static Lisp_Object xfont_list (struct frame *, Lisp_Object); -static Lisp_Object xfont_match (struct frame *, Lisp_Object); -static Lisp_Object xfont_list_family (struct frame *); -static Lisp_Object xfont_open (struct frame *, Lisp_Object, int); -static void xfont_close (struct font *); -static void xfont_prepare_face (struct frame *, struct face *); -static int xfont_has_char (Lisp_Object, int); -static unsigned xfont_encode_char (struct font *, int); -static void xfont_text_extents (struct font *, unsigned *, int, - struct font_metrics *); -static int xfont_draw (struct glyph_string *, int, int, int, int, bool); -static int xfont_check (struct frame *, struct font *); - -struct font_driver xfont_driver = - { - LISPSYM_INITIALLY (Qx), - false, /* case insensitive */ - xfont_get_cache, - xfont_list, - xfont_match, - xfont_list_family, - NULL, - xfont_open, - xfont_close, - xfont_prepare_face, - NULL, - xfont_has_char, - xfont_encode_char, - xfont_text_extents, - xfont_draw, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - xfont_check, - NULL, /* get_variation_glyphs */ - NULL, /* filter_properties */ - }; - -static Lisp_Object +Lisp_Object xfont_get_cache (struct frame *f) { Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f); @@ -1113,6 +1076,24 @@ xfont_check (struct frame *f, struct font *font) } + +struct font_driver const xfont_driver = + { + type: LISPSYM_INITIALLY (Qx), + get_cache: xfont_get_cache, + list: xfont_list, + match: xfont_match, + list_family: xfont_list_family, + open: xfont_open, + close: xfont_close, + prepare_face: xfont_prepare_face, + has_char: xfont_has_char, + encode_char: xfont_encode_char, + text_extents: xfont_text_extents, + draw: xfont_draw, + check: xfont_check, + }; + void syms_of_xfont (void) { diff --git a/src/xftfont.c b/src/xftfont.c index 861ad80da5c..74f5ec66e74 100644 --- a/src/xftfont.c +++ b/src/xftfont.c @@ -125,15 +125,12 @@ xftfont_get_colors (struct frame *f, struct face *face, GC gc, } } - -struct font_driver xftfont_driver; - static Lisp_Object xftfont_list (struct frame *f, Lisp_Object spec) { - Lisp_Object list = ftfont_driver.list (f, spec), tail; + Lisp_Object list = ftfont_list (f, spec); - for (tail = list; CONSP (tail); tail = XCDR (tail)) + for (Lisp_Object tail = list; CONSP (tail); tail = XCDR (tail)) ASET (XCAR (tail), FONT_TYPE_INDEX, Qxft); return list; } @@ -141,7 +138,7 @@ xftfont_list (struct frame *f, Lisp_Object spec) static Lisp_Object xftfont_match (struct frame *f, Lisp_Object spec) { - Lisp_Object entity = ftfont_driver.match (f, spec); + Lisp_Object entity = ftfont_match (f, spec); if (! NILP (entity)) ASET (entity, FONT_TYPE_INDEX, Qxft); @@ -542,7 +539,7 @@ xftfont_has_char (Lisp_Object font, int c) return (ENCODE_CHAR (cs, c) != CHARSET_INVALID_CODE (cs)); if (FONT_ENTITY_P (font)) - return ftfont_driver.has_char (font, c); + return ftfont_has_char (font, c); xftfont_info = (struct xftfont_info *) XFONT_OBJECT (font); return (XftCharExists (xftfont_info->display, xftfont_info->xftfont, (FcChar32) c) == FcTrue); @@ -668,12 +665,9 @@ xftfont_shape (Lisp_Object lgstring) { struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); struct xftfont_info *xftfont_info = (struct xftfont_info *) font; - FT_Face ft_face; - Lisp_Object val; - - ft_face = XftLockFace (xftfont_info->xftfont); + FT_Face ft_face = XftLockFace (xftfont_info->xftfont); xftfont_info->ft_size = ft_face->size; - val = ftfont_driver.shape (lgstring); + Lisp_Object val = ftfont_shape (lgstring); XftUnlockFace (xftfont_info->xftfont); return val; } @@ -697,6 +691,10 @@ xftfont_end_for_frame (struct frame *f) return 0; } +/* When using X double buffering, the XftDraw structure we build + seems to be useless once a frame is resized, so recreate it on + ConfigureNotify and in some other cases. */ + static void xftfont_drop_xrender_surfaces (struct frame *f) { @@ -751,6 +749,40 @@ xftfont_cached_font_ok (struct frame *f, Lisp_Object font_object, return ok; } +struct font_driver const xftfont_driver = + { + /* We can't draw a text without device dependent functions. */ + type: LISPSYM_INITIALLY (Qxft), + get_cache: xfont_get_cache, + list: xftfont_list, + match: xftfont_match, + list_family: ftfont_list_family, + open: xftfont_open, + close: xftfont_close, + prepare_face: xftfont_prepare_face, + done_face: xftfont_done_face, + has_char: xftfont_has_char, + encode_char: xftfont_encode_char, + text_extents: xftfont_text_extents, + draw: xftfont_draw, + get_bitmap: ftfont_get_bitmap, + anchor_point: ftfont_anchor_point, +#ifdef HAVE_LIBOTF + otf_capability: ftfont_otf_capability, +#endif + end_for_frame: xftfont_end_for_frame, +#if defined HAVE_M17N_FLT && defined HAVE_LIBOTF + shape: xftfont_shape, +#endif +#ifdef HAVE_OTF_GET_VARIATION_GLYPHS + get_variation_glyphs: ftfont_variation_glyphs, +#endif + filter_properties: ftfont_filter_properties, + cached_font_ok: xftfont_cached_font_ok, + combining_capability: ftfont_combining_capability, + drop_xrender_surfaces: xftfont_drop_xrender_surfaces, + }; + void syms_of_xftfont (void) { @@ -770,28 +802,5 @@ This is needed with some fonts to correct vertical overlap of glyphs. */); ascii_printable[0] = 0; - xftfont_driver = ftfont_driver; - xftfont_driver.type = Qxft; - xftfont_driver.get_cache = xfont_driver.get_cache; - xftfont_driver.list = xftfont_list; - xftfont_driver.match = xftfont_match; - xftfont_driver.open = xftfont_open; - xftfont_driver.close = xftfont_close; - xftfont_driver.prepare_face = xftfont_prepare_face; - xftfont_driver.done_face = xftfont_done_face; - xftfont_driver.has_char = xftfont_has_char; - xftfont_driver.encode_char = xftfont_encode_char; - xftfont_driver.text_extents = xftfont_text_extents; - xftfont_driver.draw = xftfont_draw; - xftfont_driver.end_for_frame = xftfont_end_for_frame; - xftfont_driver.cached_font_ok = xftfont_cached_font_ok; -#if defined (HAVE_M17N_FLT) && defined (HAVE_LIBOTF) - xftfont_driver.shape = xftfont_shape; -#endif - /* When using X double buffering, the XftDraw structure we build - seems to be useless once a frame is resized, so recreate it on - ConfigureNotify and in some other cases. */ - xftfont_driver.drop_xrender_surfaces = xftfont_drop_xrender_surfaces; - register_font_driver (&xftfont_driver, NULL); }