diff options
| author | Paul Eggert | 2016-12-01 21:47:12 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-12-01 21:48:30 -0800 |
| commit | ebb96114d88af64cbb72f42052cb359ba8010aa2 (patch) | |
| tree | 88795f2e9bc74b5c1a96c04c8cfe069b7d5f601f | |
| parent | dd4b913153a818dbd42cb395d2c36f216e09a8ec (diff) | |
| download | emacs-ebb96114d88af64cbb72f42052cb359ba8010aa2.tar.gz emacs-ebb96114d88af64cbb72f42052cb359ba8010aa2.zip | |
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.
| -rw-r--r-- | src/alloc.c | 2 | ||||
| -rw-r--r-- | src/font.c | 22 | ||||
| -rw-r--r-- | src/font.h | 41 | ||||
| -rw-r--r-- | src/ftcrfont.c | 49 | ||||
| -rw-r--r-- | src/ftfont.c | 144 | ||||
| -rw-r--r-- | src/ftxfont.c | 59 | ||||
| -rw-r--r-- | src/macfont.m | 47 | ||||
| -rw-r--r-- | src/nsfont.m | 54 | ||||
| -rw-r--r-- | src/xfont.c | 57 | ||||
| -rw-r--r-- | src/xftfont.c | 79 |
10 files changed, 251 insertions, 303 deletions
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) | |||
| 3201 | && ((vector->header.size & PSEUDOVECTOR_SIZE_MASK) | 3201 | && ((vector->header.size & PSEUDOVECTOR_SIZE_MASK) |
| 3202 | == FONT_OBJECT_MAX)) | 3202 | == FONT_OBJECT_MAX)) |
| 3203 | { | 3203 | { |
| 3204 | struct font_driver *drv = ((struct font *) vector)->driver; | 3204 | struct font_driver const *drv = ((struct font *) vector)->driver; |
| 3205 | 3205 | ||
| 3206 | /* The font driver might sometimes be NULL, e.g. if Emacs was | 3206 | /* The font driver might sometimes be NULL, e.g. if Emacs was |
| 3207 | interrupted before it had time to set it up. */ | 3207 | 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; | |||
| 132 | /* Used to catch bogus pointers in font objects. */ | 132 | /* Used to catch bogus pointers in font objects. */ |
| 133 | 133 | ||
| 134 | bool | 134 | bool |
| 135 | valid_font_driver (struct font_driver *drv) | 135 | valid_font_driver (struct font_driver const *drv) |
| 136 | { | 136 | { |
| 137 | Lisp_Object tail, frame; | 137 | Lisp_Object tail, frame; |
| 138 | struct font_driver_list *fdl; | 138 | struct font_driver_list *fdl; |
| @@ -2543,14 +2543,11 @@ font_match_p (Lisp_Object spec, Lisp_Object font) | |||
| 2543 | is a number frames sharing this cache, and FONT-CACHE-DATA is a | 2543 | is a number frames sharing this cache, and FONT-CACHE-DATA is a |
| 2544 | cons (FONT-SPEC . [FONT-ENTITY ...]). */ | 2544 | cons (FONT-SPEC . [FONT-ENTITY ...]). */ |
| 2545 | 2545 | ||
| 2546 | static void font_prepare_cache (struct frame *, struct font_driver *); | ||
| 2547 | static void font_finish_cache (struct frame *, struct font_driver *); | ||
| 2548 | static Lisp_Object font_get_cache (struct frame *, struct font_driver *); | ||
| 2549 | static void font_clear_cache (struct frame *, Lisp_Object, | 2546 | static void font_clear_cache (struct frame *, Lisp_Object, |
| 2550 | struct font_driver *); | 2547 | struct font_driver const *); |
| 2551 | 2548 | ||
| 2552 | static void | 2549 | static void |
| 2553 | font_prepare_cache (struct frame *f, struct font_driver *driver) | 2550 | font_prepare_cache (struct frame *f, struct font_driver const *driver) |
| 2554 | { | 2551 | { |
| 2555 | Lisp_Object cache, val; | 2552 | Lisp_Object cache, val; |
| 2556 | 2553 | ||
| @@ -2572,7 +2569,7 @@ font_prepare_cache (struct frame *f, struct font_driver *driver) | |||
| 2572 | 2569 | ||
| 2573 | 2570 | ||
| 2574 | static void | 2571 | static void |
| 2575 | font_finish_cache (struct frame *f, struct font_driver *driver) | 2572 | font_finish_cache (struct frame *f, struct font_driver const *driver) |
| 2576 | { | 2573 | { |
| 2577 | Lisp_Object cache, val, tmp; | 2574 | Lisp_Object cache, val, tmp; |
| 2578 | 2575 | ||
| @@ -2593,7 +2590,7 @@ font_finish_cache (struct frame *f, struct font_driver *driver) | |||
| 2593 | 2590 | ||
| 2594 | 2591 | ||
| 2595 | static Lisp_Object | 2592 | static Lisp_Object |
| 2596 | font_get_cache (struct frame *f, struct font_driver *driver) | 2593 | font_get_cache (struct frame *f, struct font_driver const *driver) |
| 2597 | { | 2594 | { |
| 2598 | Lisp_Object val = driver->get_cache (f); | 2595 | Lisp_Object val = driver->get_cache (f); |
| 2599 | Lisp_Object type = driver->type; | 2596 | Lisp_Object type = driver->type; |
| @@ -2608,7 +2605,8 @@ font_get_cache (struct frame *f, struct font_driver *driver) | |||
| 2608 | 2605 | ||
| 2609 | 2606 | ||
| 2610 | static void | 2607 | static void |
| 2611 | font_clear_cache (struct frame *f, Lisp_Object cache, struct font_driver *driver) | 2608 | font_clear_cache (struct frame *f, Lisp_Object cache, |
| 2609 | struct font_driver const *driver) | ||
| 2612 | { | 2610 | { |
| 2613 | Lisp_Object tail, elt; | 2611 | Lisp_Object tail, elt; |
| 2614 | Lisp_Object entity; | 2612 | Lisp_Object entity; |
| @@ -3463,7 +3461,7 @@ font_open_by_name (struct frame *f, Lisp_Object name) | |||
| 3463 | (e.g. syms_of_xfont). */ | 3461 | (e.g. syms_of_xfont). */ |
| 3464 | 3462 | ||
| 3465 | void | 3463 | void |
| 3466 | register_font_driver (struct font_driver *driver, struct frame *f) | 3464 | register_font_driver (struct font_driver const *driver, struct frame *f) |
| 3467 | { | 3465 | { |
| 3468 | struct font_driver_list *root = f ? f->font_driver_list : font_driver_list; | 3466 | struct font_driver_list *root = f ? f->font_driver_list : font_driver_list; |
| 3469 | struct font_driver_list *prev, *list; | 3467 | struct font_driver_list *prev, *list; |
| @@ -3524,7 +3522,7 @@ font_update_drivers (struct frame *f, Lisp_Object new_drivers) | |||
| 3524 | drivers. */ | 3522 | drivers. */ |
| 3525 | for (list = f->font_driver_list; list; list = list->next) | 3523 | for (list = f->font_driver_list; list; list = list->next) |
| 3526 | { | 3524 | { |
| 3527 | struct font_driver *driver = list->driver; | 3525 | struct font_driver const *driver = list->driver; |
| 3528 | if ((EQ (new_drivers, Qt) || ! NILP (Fmemq (driver->type, new_drivers))) | 3526 | if ((EQ (new_drivers, Qt) || ! NILP (Fmemq (driver->type, new_drivers))) |
| 3529 | != list->on) | 3527 | != list->on) |
| 3530 | { | 3528 | { |
| @@ -3587,7 +3585,7 @@ font_update_drivers (struct frame *f, Lisp_Object new_drivers) | |||
| 3587 | and then use it under w32 or ns. */ | 3585 | and then use it under w32 or ns. */ |
| 3588 | for (list = f->font_driver_list; list; list = list->next) | 3586 | for (list = f->font_driver_list; list; list = list->next) |
| 3589 | { | 3587 | { |
| 3590 | struct font_driver *driver = list->driver; | 3588 | struct font_driver const *driver = list->driver; |
| 3591 | eassert (! list->on); | 3589 | eassert (! list->on); |
| 3592 | if (! driver->start_for_frame | 3590 | if (! driver->start_for_frame |
| 3593 | || driver->start_for_frame (f) == 0) | 3591 | || 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 | |||
| 380 | #endif /* HAVE_WINDOW_SYSTEM */ | 380 | #endif /* HAVE_WINDOW_SYSTEM */ |
| 381 | 381 | ||
| 382 | /* Font-driver for the font. */ | 382 | /* Font-driver for the font. */ |
| 383 | struct font_driver *driver; | 383 | struct font_driver const *driver; |
| 384 | 384 | ||
| 385 | /* There are more members in this structure, but they are private | 385 | /* There are more members in this structure, but they are private |
| 386 | to the font-driver. */ | 386 | to the font-driver. */ |
| @@ -783,7 +783,7 @@ struct font_driver_list | |||
| 783 | font driver list.*/ | 783 | font driver list.*/ |
| 784 | bool on; | 784 | bool on; |
| 785 | /* Pointer to the font driver. */ | 785 | /* Pointer to the font driver. */ |
| 786 | struct font_driver *driver; | 786 | struct font_driver const *driver; |
| 787 | /* Pointer to the next element of the chain. */ | 787 | /* Pointer to the next element of the chain. */ |
| 788 | struct font_driver_list *next; | 788 | struct font_driver_list *next; |
| 789 | }; | 789 | }; |
| @@ -841,13 +841,13 @@ extern void font_parse_family_registry (Lisp_Object family, | |||
| 841 | extern int font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font); | 841 | extern int font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font); |
| 842 | extern ptrdiff_t font_unparse_xlfd (Lisp_Object font, int pixel_size, | 842 | extern ptrdiff_t font_unparse_xlfd (Lisp_Object font, int pixel_size, |
| 843 | char *name, int bytes); | 843 | char *name, int bytes); |
| 844 | extern void register_font_driver (struct font_driver *driver, struct frame *f); | 844 | extern void register_font_driver (struct font_driver const *, struct frame *); |
| 845 | extern void free_font_driver_list (struct frame *f); | 845 | extern void free_font_driver_list (struct frame *f); |
| 846 | #ifdef ENABLE_CHECKING | 846 | #ifdef ENABLE_CHECKING |
| 847 | extern bool valid_font_driver (struct font_driver *); | 847 | extern bool valid_font_driver (struct font_driver const *); |
| 848 | #else | 848 | #else |
| 849 | INLINE bool | 849 | INLINE bool |
| 850 | valid_font_driver (struct font_driver *d) | 850 | valid_font_driver (struct font_driver const *d) |
| 851 | { | 851 | { |
| 852 | return true; | 852 | return true; |
| 853 | } | 853 | } |
| @@ -874,18 +874,37 @@ extern void font_filter_properties (Lisp_Object font, | |||
| 874 | extern void font_drop_xrender_surfaces (struct frame *f); | 874 | extern void font_drop_xrender_surfaces (struct frame *f); |
| 875 | 875 | ||
| 876 | #ifdef HAVE_FREETYPE | 876 | #ifdef HAVE_FREETYPE |
| 877 | extern struct font_driver ftfont_driver; | 877 | extern int ftfont_anchor_point (struct font *, unsigned int, int, |
| 878 | int *, int *); | ||
| 879 | extern int ftfont_get_bitmap (struct font *, unsigned int, | ||
| 880 | struct font_bitmap *, int); | ||
| 881 | extern int ftfont_has_char (Lisp_Object, int); | ||
| 882 | extern int ftfont_variation_glyphs (struct font *, int, unsigned[256]); | ||
| 883 | extern Lisp_Object ftfont_combining_capability (struct font *); | ||
| 884 | extern Lisp_Object ftfont_get_cache (struct frame *); | ||
| 885 | extern Lisp_Object ftfont_list (struct frame *, Lisp_Object); | ||
| 886 | extern Lisp_Object ftfont_list_family (struct frame *); | ||
| 887 | extern Lisp_Object ftfont_match (struct frame *, Lisp_Object); | ||
| 888 | extern Lisp_Object ftfont_open (struct frame *, Lisp_Object, int); | ||
| 889 | extern Lisp_Object ftfont_otf_capability (struct font *); | ||
| 890 | extern Lisp_Object ftfont_shape (Lisp_Object); | ||
| 891 | extern unsigned ftfont_encode_char (struct font *, int); | ||
| 892 | extern void ftfont_close (struct font *); | ||
| 893 | extern void ftfont_filter_properties (Lisp_Object, Lisp_Object); | ||
| 894 | extern void ftfont_text_extents (struct font *, unsigned *, int, | ||
| 895 | struct font_metrics *); | ||
| 878 | extern void syms_of_ftfont (void); | 896 | extern void syms_of_ftfont (void); |
| 879 | #endif /* HAVE_FREETYPE */ | 897 | #endif /* HAVE_FREETYPE */ |
| 880 | #ifdef HAVE_X_WINDOWS | 898 | #ifdef HAVE_X_WINDOWS |
| 881 | extern struct font_driver xfont_driver; | 899 | extern struct font_driver const xfont_driver; |
| 900 | extern Lisp_Object xfont_get_cache (struct frame *); | ||
| 882 | extern void syms_of_xfont (void); | 901 | extern void syms_of_xfont (void); |
| 883 | extern void syms_of_ftxfont (void); | 902 | extern void syms_of_ftxfont (void); |
| 884 | #ifdef HAVE_XFT | 903 | #ifdef HAVE_XFT |
| 885 | extern struct font_driver xftfont_driver; | 904 | extern struct font_driver const xftfont_driver; |
| 886 | #endif | 905 | #endif |
| 887 | #if defined HAVE_FREETYPE || defined HAVE_XFT | 906 | #if defined HAVE_FREETYPE || defined HAVE_XFT |
| 888 | extern struct font_driver ftxfont_driver; | 907 | extern struct font_driver const ftxfont_driver; |
| 889 | extern void syms_of_xftfont (void); | 908 | extern void syms_of_xftfont (void); |
| 890 | #endif | 909 | #endif |
| 891 | #ifdef HAVE_BDFFONT | 910 | #ifdef HAVE_BDFFONT |
| @@ -898,12 +917,12 @@ extern struct font_driver uniscribe_font_driver; | |||
| 898 | extern void syms_of_w32font (void); | 917 | extern void syms_of_w32font (void); |
| 899 | #endif /* HAVE_NTGUI */ | 918 | #endif /* HAVE_NTGUI */ |
| 900 | #ifdef HAVE_NS | 919 | #ifdef HAVE_NS |
| 901 | extern struct font_driver nsfont_driver; | 920 | extern struct font_driver const nsfont_driver; |
| 902 | extern void syms_of_nsfont (void); | 921 | extern void syms_of_nsfont (void); |
| 903 | extern void syms_of_macfont (void); | 922 | extern void syms_of_macfont (void); |
| 904 | #endif /* HAVE_NS */ | 923 | #endif /* HAVE_NS */ |
| 905 | #ifdef USE_CAIRO | 924 | #ifdef USE_CAIRO |
| 906 | extern struct font_driver ftcrfont_driver; | 925 | extern struct font_driver const ftcrfont_driver; |
| 907 | extern void syms_of_ftcrfont (void); | 926 | extern void syms_of_ftcrfont (void); |
| 908 | #endif | 927 | #endif |
| 909 | 928 | ||
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 | |||
| 65 | #define METRICS_SET_STATUS(metrics, status) \ | 65 | #define METRICS_SET_STATUS(metrics, status) \ |
| 66 | ((metrics)->ascent = 0, (metrics)->descent = (status)) | 66 | ((metrics)->ascent = 0, (metrics)->descent = (status)) |
| 67 | 67 | ||
| 68 | struct font_driver ftcrfont_driver; | ||
| 69 | |||
| 70 | static int | 68 | static int |
| 71 | ftcrfont_glyph_extents (struct font *font, | 69 | ftcrfont_glyph_extents (struct font *font, |
| 72 | unsigned glyph, | 70 | unsigned glyph, |
| @@ -101,7 +99,7 @@ ftcrfont_glyph_extents (struct font *font, | |||
| 101 | cache = ftcrfont_info->metrics[row] + col; | 99 | cache = ftcrfont_info->metrics[row] + col; |
| 102 | 100 | ||
| 103 | if (METRICS_STATUS (cache) == METRICS_INVALID) | 101 | if (METRICS_STATUS (cache) == METRICS_INVALID) |
| 104 | ftfont_driver.text_extents (font, &glyph, 1, cache); | 102 | ftfont_text_extents (font, &glyph, 1, cache); |
| 105 | 103 | ||
| 106 | if (metrics) | 104 | if (metrics) |
| 107 | *metrics = *cache; | 105 | *metrics = *cache; |
| @@ -112,7 +110,7 @@ ftcrfont_glyph_extents (struct font *font, | |||
| 112 | static Lisp_Object | 110 | static Lisp_Object |
| 113 | ftcrfont_list (struct frame *f, Lisp_Object spec) | 111 | ftcrfont_list (struct frame *f, Lisp_Object spec) |
| 114 | { | 112 | { |
| 115 | Lisp_Object list = ftfont_driver.list (f, spec), tail; | 113 | Lisp_Object list = ftfont_list (f, spec), tail; |
| 116 | 114 | ||
| 117 | for (tail = list; CONSP (tail); tail = XCDR (tail)) | 115 | for (tail = list; CONSP (tail); tail = XCDR (tail)) |
| 118 | ASET (XCAR (tail), FONT_TYPE_INDEX, Qftcr); | 116 | ASET (XCAR (tail), FONT_TYPE_INDEX, Qftcr); |
| @@ -122,15 +120,13 @@ ftcrfont_list (struct frame *f, Lisp_Object spec) | |||
| 122 | static Lisp_Object | 120 | static Lisp_Object |
| 123 | ftcrfont_match (struct frame *f, Lisp_Object spec) | 121 | ftcrfont_match (struct frame *f, Lisp_Object spec) |
| 124 | { | 122 | { |
| 125 | Lisp_Object entity = ftfont_driver.match (f, spec); | 123 | Lisp_Object entity = ftfont_match (f, spec); |
| 126 | 124 | ||
| 127 | if (VECTORP (entity)) | 125 | if (VECTORP (entity)) |
| 128 | ASET (entity, FONT_TYPE_INDEX, Qftcr); | 126 | ASET (entity, FONT_TYPE_INDEX, Qftcr); |
| 129 | return entity; | 127 | return entity; |
| 130 | } | 128 | } |
| 131 | 129 | ||
| 132 | extern FT_Face ftfont_get_ft_face (Lisp_Object); | ||
| 133 | |||
| 134 | static Lisp_Object | 130 | static Lisp_Object |
| 135 | ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | 131 | ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size) |
| 136 | { | 132 | { |
| @@ -181,7 +177,7 @@ ftcrfont_close (struct font *font) | |||
| 181 | cairo_font_face_destroy (ftcrfont_info->cr_font_face); | 177 | cairo_font_face_destroy (ftcrfont_info->cr_font_face); |
| 182 | unblock_input (); | 178 | unblock_input (); |
| 183 | 179 | ||
| 184 | ftfont_driver.close (font); | 180 | ftfont_close (font); |
| 185 | } | 181 | } |
| 186 | 182 | ||
| 187 | static void | 183 | static void |
| @@ -282,6 +278,34 @@ ftcrfont_draw (struct glyph_string *s, | |||
| 282 | 278 | ||
| 283 | 279 | ||
| 284 | 280 | ||
| 281 | struct font_driver const ftcrfont_driver = | ||
| 282 | { | ||
| 283 | type: LISPSYM_INITIALLY (Qftcr), | ||
| 284 | get_cache: ftfont_get_cache, | ||
| 285 | list: ftcrfont_list, | ||
| 286 | match: ftcrfont_match, | ||
| 287 | list_family: ftfont_list_family, | ||
| 288 | open: ftcrfont_open, | ||
| 289 | close: ftcrfont_close, | ||
| 290 | has_char: ftfont_has_char, | ||
| 291 | encode_char: ftfont_encode_char, | ||
| 292 | text_extents: ftcrfont_text_extents, | ||
| 293 | draw: ftcrfont_draw, | ||
| 294 | get_bitmap: ftfont_get_bitmap, | ||
| 295 | anchor_point: ftfont_anchor_point, | ||
| 296 | #ifdef HAVE_LIBOTF | ||
| 297 | otf_capability: ftfont_otf_capability, | ||
| 298 | #endif | ||
| 299 | #if defined HAVE_M17N_FLT && defined HAVE_LIBOTF | ||
| 300 | shape: ftfont_shape, | ||
| 301 | #endif | ||
| 302 | #ifdef HAVE_OTF_GET_VARIATION_GLYPHS | ||
| 303 | get_variation_glyphs: ftfont_variation_glyphs, | ||
| 304 | #endif | ||
| 305 | filter_properties: ftfont_filter_properties, | ||
| 306 | combining_capability: ftfont_combining_capability, | ||
| 307 | }; | ||
| 308 | |||
| 285 | void | 309 | void |
| 286 | syms_of_ftcrfont (void) | 310 | syms_of_ftcrfont (void) |
| 287 | { | 311 | { |
| @@ -289,14 +313,5 @@ syms_of_ftcrfont (void) | |||
| 289 | abort (); | 313 | abort (); |
| 290 | 314 | ||
| 291 | DEFSYM (Qftcr, "ftcr"); | 315 | DEFSYM (Qftcr, "ftcr"); |
| 292 | |||
| 293 | ftcrfont_driver = ftfont_driver; | ||
| 294 | ftcrfont_driver.type = Qftcr; | ||
| 295 | ftcrfont_driver.list = ftcrfont_list; | ||
| 296 | ftcrfont_driver.match = ftcrfont_match; | ||
| 297 | ftcrfont_driver.open = ftcrfont_open; | ||
| 298 | ftcrfont_driver.close = ftcrfont_close; | ||
| 299 | ftcrfont_driver.text_extents = ftcrfont_text_extents; | ||
| 300 | ftcrfont_driver.draw = ftcrfont_draw; | ||
| 301 | register_font_driver (&ftcrfont_driver, NULL); | 316 | register_font_driver (&ftcrfont_driver, NULL); |
| 302 | } | 317 | } |
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 <http://www.gnu.org/licenses/>. */ | |||
| 35 | #include "font.h" | 35 | #include "font.h" |
| 36 | #include "ftfont.h" | 36 | #include "ftfont.h" |
| 37 | 37 | ||
| 38 | static struct font_driver const ftfont_driver; | ||
| 39 | |||
| 38 | /* Flag to tell if FcInit is already called or not. */ | 40 | /* Flag to tell if FcInit is already called or not. */ |
| 39 | static bool fc_initialized; | 41 | static bool fc_initialized; |
| 40 | 42 | ||
| @@ -73,17 +75,9 @@ enum ftfont_cache_for | |||
| 73 | FTFONT_CACHE_FOR_ENTITY | 75 | FTFONT_CACHE_FOR_ENTITY |
| 74 | }; | 76 | }; |
| 75 | 77 | ||
| 76 | static Lisp_Object ftfont_pattern_entity (FcPattern *, Lisp_Object); | ||
| 77 | |||
| 78 | static Lisp_Object ftfont_resolve_generic_family (Lisp_Object, | ||
| 79 | FcPattern *); | ||
| 80 | static Lisp_Object ftfont_lookup_cache (Lisp_Object, | 78 | static Lisp_Object ftfont_lookup_cache (Lisp_Object, |
| 81 | enum ftfont_cache_for); | 79 | enum ftfont_cache_for); |
| 82 | 80 | ||
| 83 | static void ftfont_filter_properties (Lisp_Object font, Lisp_Object alist); | ||
| 84 | |||
| 85 | static Lisp_Object ftfont_combining_capability (struct font *); | ||
| 86 | |||
| 87 | #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM)) | 81 | #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM)) |
| 88 | 82 | ||
| 89 | static struct | 83 | static struct |
| @@ -480,83 +474,7 @@ ftfont_get_otf (struct ftfont_info *ftfont_info) | |||
| 480 | } | 474 | } |
| 481 | #endif /* HAVE_LIBOTF */ | 475 | #endif /* HAVE_LIBOTF */ |
| 482 | 476 | ||
| 483 | static Lisp_Object ftfont_get_cache (struct frame *); | 477 | Lisp_Object |
| 484 | static Lisp_Object ftfont_list (struct frame *, Lisp_Object); | ||
| 485 | static Lisp_Object ftfont_match (struct frame *, Lisp_Object); | ||
| 486 | static Lisp_Object ftfont_list_family (struct frame *); | ||
| 487 | static Lisp_Object ftfont_open (struct frame *, Lisp_Object, int); | ||
| 488 | static void ftfont_close (struct font *); | ||
| 489 | static int ftfont_has_char (Lisp_Object, int); | ||
| 490 | static unsigned ftfont_encode_char (struct font *, int); | ||
| 491 | static void ftfont_text_extents (struct font *, unsigned *, int, | ||
| 492 | struct font_metrics *); | ||
| 493 | static int ftfont_get_bitmap (struct font *, unsigned, | ||
| 494 | struct font_bitmap *, int); | ||
| 495 | static int ftfont_anchor_point (struct font *, unsigned, int, | ||
| 496 | int *, int *); | ||
| 497 | #ifdef HAVE_LIBOTF | ||
| 498 | static Lisp_Object ftfont_otf_capability (struct font *); | ||
| 499 | # ifdef HAVE_M17N_FLT | ||
| 500 | static Lisp_Object ftfont_shape (Lisp_Object); | ||
| 501 | # endif | ||
| 502 | #endif | ||
| 503 | |||
| 504 | #ifdef HAVE_OTF_GET_VARIATION_GLYPHS | ||
| 505 | static int ftfont_variation_glyphs (struct font *, int c, | ||
| 506 | unsigned variations[256]); | ||
| 507 | #endif /* HAVE_OTF_GET_VARIATION_GLYPHS */ | ||
| 508 | |||
| 509 | struct font_driver ftfont_driver = | ||
| 510 | { | ||
| 511 | LISPSYM_INITIALLY (Qfreetype), | ||
| 512 | 0, /* case insensitive */ | ||
| 513 | ftfont_get_cache, | ||
| 514 | ftfont_list, | ||
| 515 | ftfont_match, | ||
| 516 | ftfont_list_family, | ||
| 517 | NULL, /* free_entity */ | ||
| 518 | ftfont_open, | ||
| 519 | ftfont_close, | ||
| 520 | /* We can't draw a text without device dependent functions. */ | ||
| 521 | NULL, /* prepare_face */ | ||
| 522 | NULL, /* done_face */ | ||
| 523 | ftfont_has_char, | ||
| 524 | ftfont_encode_char, | ||
| 525 | ftfont_text_extents, | ||
| 526 | /* We can't draw a text without device dependent functions. */ | ||
| 527 | NULL, /* draw */ | ||
| 528 | ftfont_get_bitmap, | ||
| 529 | NULL, /* free_bitmap */ | ||
| 530 | ftfont_anchor_point, | ||
| 531 | #ifdef HAVE_LIBOTF | ||
| 532 | ftfont_otf_capability, | ||
| 533 | #else /* not HAVE_LIBOTF */ | ||
| 534 | NULL, | ||
| 535 | #endif /* not HAVE_LIBOTF */ | ||
| 536 | NULL, /* otf_drive */ | ||
| 537 | NULL, /* start_for_frame */ | ||
| 538 | NULL, /* end_for_frame */ | ||
| 539 | #if defined (HAVE_M17N_FLT) && defined (HAVE_LIBOTF) | ||
| 540 | ftfont_shape, | ||
| 541 | #else /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */ | ||
| 542 | NULL, | ||
| 543 | #endif /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */ | ||
| 544 | NULL, /* check */ | ||
| 545 | |||
| 546 | #ifdef HAVE_OTF_GET_VARIATION_GLYPHS | ||
| 547 | ftfont_variation_glyphs, | ||
| 548 | #else | ||
| 549 | NULL, | ||
| 550 | #endif | ||
| 551 | |||
| 552 | ftfont_filter_properties, /* filter_properties */ | ||
| 553 | |||
| 554 | NULL, /* cached_font_ok */ | ||
| 555 | |||
| 556 | ftfont_combining_capability, | ||
| 557 | }; | ||
| 558 | |||
| 559 | static Lisp_Object | ||
| 560 | ftfont_get_cache (struct frame *f) | 478 | ftfont_get_cache (struct frame *f) |
| 561 | { | 479 | { |
| 562 | return freetype_font_cache; | 480 | return freetype_font_cache; |
| @@ -873,7 +791,7 @@ ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **ots | |||
| 873 | return pattern; | 791 | return pattern; |
| 874 | } | 792 | } |
| 875 | 793 | ||
| 876 | static Lisp_Object | 794 | Lisp_Object |
| 877 | ftfont_list (struct frame *f, Lisp_Object spec) | 795 | ftfont_list (struct frame *f, Lisp_Object spec) |
| 878 | { | 796 | { |
| 879 | Lisp_Object val = Qnil, family, adstyle; | 797 | Lisp_Object val = Qnil, family, adstyle; |
| @@ -1072,7 +990,7 @@ ftfont_list (struct frame *f, Lisp_Object spec) | |||
| 1072 | return val; | 990 | return val; |
| 1073 | } | 991 | } |
| 1074 | 992 | ||
| 1075 | static Lisp_Object | 993 | Lisp_Object |
| 1076 | ftfont_match (struct frame *f, Lisp_Object spec) | 994 | ftfont_match (struct frame *f, Lisp_Object spec) |
| 1077 | { | 995 | { |
| 1078 | Lisp_Object entity = Qnil; | 996 | Lisp_Object entity = Qnil; |
| @@ -1122,7 +1040,7 @@ ftfont_match (struct frame *f, Lisp_Object spec) | |||
| 1122 | return entity; | 1040 | return entity; |
| 1123 | } | 1041 | } |
| 1124 | 1042 | ||
| 1125 | static Lisp_Object | 1043 | Lisp_Object |
| 1126 | ftfont_list_family (struct frame *f) | 1044 | ftfont_list_family (struct frame *f) |
| 1127 | { | 1045 | { |
| 1128 | Lisp_Object list = Qnil; | 1046 | Lisp_Object list = Qnil; |
| @@ -1301,7 +1219,7 @@ ftfont_open2 (struct frame *f, | |||
| 1301 | return font_object; | 1219 | return font_object; |
| 1302 | } | 1220 | } |
| 1303 | 1221 | ||
| 1304 | static Lisp_Object | 1222 | Lisp_Object |
| 1305 | ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | 1223 | ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) |
| 1306 | { | 1224 | { |
| 1307 | Lisp_Object font_object; | 1225 | Lisp_Object font_object; |
| @@ -1314,7 +1232,7 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 1314 | return ftfont_open2 (f, entity, pixel_size, font_object); | 1232 | return ftfont_open2 (f, entity, pixel_size, font_object); |
| 1315 | } | 1233 | } |
| 1316 | 1234 | ||
| 1317 | static void | 1235 | void |
| 1318 | ftfont_close (struct font *font) | 1236 | ftfont_close (struct font *font) |
| 1319 | { | 1237 | { |
| 1320 | /* FIXME: Although this function can be called while garbage-collecting, | 1238 | /* FIXME: Although this function can be called while garbage-collecting, |
| @@ -1344,7 +1262,7 @@ ftfont_close (struct font *font) | |||
| 1344 | FT_Done_Size (ftfont_info->ft_size); | 1262 | FT_Done_Size (ftfont_info->ft_size); |
| 1345 | } | 1263 | } |
| 1346 | 1264 | ||
| 1347 | static int | 1265 | int |
| 1348 | ftfont_has_char (Lisp_Object font, int c) | 1266 | ftfont_has_char (Lisp_Object font, int c) |
| 1349 | { | 1267 | { |
| 1350 | struct charset *cs = NULL; | 1268 | struct charset *cs = NULL; |
| @@ -1374,7 +1292,7 @@ ftfont_has_char (Lisp_Object font, int c) | |||
| 1374 | } | 1292 | } |
| 1375 | } | 1293 | } |
| 1376 | 1294 | ||
| 1377 | static unsigned | 1295 | unsigned |
| 1378 | ftfont_encode_char (struct font *font, int c) | 1296 | ftfont_encode_char (struct font *font, int c) |
| 1379 | { | 1297 | { |
| 1380 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1298 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; |
| @@ -1385,7 +1303,7 @@ ftfont_encode_char (struct font *font, int c) | |||
| 1385 | return (code > 0 ? code : FONT_INVALID_CODE); | 1303 | return (code > 0 ? code : FONT_INVALID_CODE); |
| 1386 | } | 1304 | } |
| 1387 | 1305 | ||
| 1388 | static void | 1306 | void |
| 1389 | ftfont_text_extents (struct font *font, unsigned int *code, | 1307 | ftfont_text_extents (struct font *font, unsigned int *code, |
| 1390 | int nglyphs, struct font_metrics *metrics) | 1308 | int nglyphs, struct font_metrics *metrics) |
| 1391 | { | 1309 | { |
| @@ -1429,7 +1347,7 @@ ftfont_text_extents (struct font *font, unsigned int *code, | |||
| 1429 | metrics->width = width; | 1347 | metrics->width = width; |
| 1430 | } | 1348 | } |
| 1431 | 1349 | ||
| 1432 | static int | 1350 | int |
| 1433 | ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bitmap, int bits_per_pixel) | 1351 | ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bitmap, int bits_per_pixel) |
| 1434 | { | 1352 | { |
| 1435 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1353 | 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 | |||
| 1472 | return 0; | 1390 | return 0; |
| 1473 | } | 1391 | } |
| 1474 | 1392 | ||
| 1475 | static int | 1393 | int |
| 1476 | ftfont_anchor_point (struct font *font, unsigned int code, int idx, | 1394 | ftfont_anchor_point (struct font *font, unsigned int code, int idx, |
| 1477 | int *x, int *y) | 1395 | int *x, int *y) |
| 1478 | { | 1396 | { |
| @@ -1538,7 +1456,7 @@ ftfont_otf_features (OTF_GSUB_GPOS *gsub_gpos) | |||
| 1538 | } | 1456 | } |
| 1539 | 1457 | ||
| 1540 | 1458 | ||
| 1541 | static Lisp_Object | 1459 | Lisp_Object |
| 1542 | ftfont_otf_capability (struct font *font) | 1460 | ftfont_otf_capability (struct font *font) |
| 1543 | { | 1461 | { |
| 1544 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1462 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; |
| @@ -2701,7 +2619,7 @@ ftfont_shape (Lisp_Object lgstring) | |||
| 2701 | 2619 | ||
| 2702 | #ifdef HAVE_OTF_GET_VARIATION_GLYPHS | 2620 | #ifdef HAVE_OTF_GET_VARIATION_GLYPHS |
| 2703 | 2621 | ||
| 2704 | static int | 2622 | int |
| 2705 | ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256]) | 2623 | ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256]) |
| 2706 | { | 2624 | { |
| 2707 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 2625 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; |
| @@ -2759,14 +2677,14 @@ static const char *const ftfont_non_booleans [] = { | |||
| 2759 | NULL, | 2677 | NULL, |
| 2760 | }; | 2678 | }; |
| 2761 | 2679 | ||
| 2762 | static void | 2680 | void |
| 2763 | ftfont_filter_properties (Lisp_Object font, Lisp_Object alist) | 2681 | ftfont_filter_properties (Lisp_Object font, Lisp_Object alist) |
| 2764 | { | 2682 | { |
| 2765 | font_filter_properties (font, alist, ftfont_booleans, ftfont_non_booleans); | 2683 | font_filter_properties (font, alist, ftfont_booleans, ftfont_non_booleans); |
| 2766 | } | 2684 | } |
| 2767 | 2685 | ||
| 2768 | 2686 | ||
| 2769 | static Lisp_Object | 2687 | Lisp_Object |
| 2770 | ftfont_combining_capability (struct font *font) | 2688 | ftfont_combining_capability (struct font *font) |
| 2771 | { | 2689 | { |
| 2772 | #ifdef HAVE_M17N_FLT | 2690 | #ifdef HAVE_M17N_FLT |
| @@ -2776,6 +2694,34 @@ ftfont_combining_capability (struct font *font) | |||
| 2776 | #endif | 2694 | #endif |
| 2777 | } | 2695 | } |
| 2778 | 2696 | ||
| 2697 | static struct font_driver const ftfont_driver = | ||
| 2698 | { | ||
| 2699 | /* We can't draw a text without device dependent functions. */ | ||
| 2700 | type: LISPSYM_INITIALLY (Qfreetype), | ||
| 2701 | get_cache: ftfont_get_cache, | ||
| 2702 | list: ftfont_list, | ||
| 2703 | match: ftfont_match, | ||
| 2704 | list_family: ftfont_list_family, | ||
| 2705 | open: ftfont_open, | ||
| 2706 | close: ftfont_close, | ||
| 2707 | has_char: ftfont_has_char, | ||
| 2708 | encode_char: ftfont_encode_char, | ||
| 2709 | text_extents: ftfont_text_extents, | ||
| 2710 | get_bitmap: ftfont_get_bitmap, | ||
| 2711 | anchor_point: ftfont_anchor_point, | ||
| 2712 | #ifdef HAVE_LIBOTF | ||
| 2713 | otf_capability: ftfont_otf_capability, | ||
| 2714 | #endif | ||
| 2715 | #if defined HAVE_M17N_FLT && defined HAVE_LIBOTF | ||
| 2716 | shape: ftfont_shape, | ||
| 2717 | #endif | ||
| 2718 | #ifdef HAVE_OTF_GET_VARIATION_GLYPHS | ||
| 2719 | get_variation_glyphs: ftfont_variation_glyphs, | ||
| 2720 | #endif | ||
| 2721 | filter_properties: ftfont_filter_properties, | ||
| 2722 | combining_capability: ftfont_combining_capability, | ||
| 2723 | }; | ||
| 2724 | |||
| 2779 | void | 2725 | void |
| 2780 | syms_of_ftfont (void) | 2726 | syms_of_ftfont (void) |
| 2781 | { | 2727 | { |
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 <http://www.gnu.org/licenses/>. */ | |||
| 31 | 31 | ||
| 32 | /* FTX font driver. */ | 32 | /* FTX font driver. */ |
| 33 | 33 | ||
| 34 | struct font_driver ftxfont_driver; | ||
| 35 | |||
| 36 | struct ftxfont_frame_data | 34 | struct ftxfont_frame_data |
| 37 | { | 35 | { |
| 38 | /* Background and foreground colors. */ | 36 | /* Background and foreground colors. */ |
| @@ -125,7 +123,7 @@ ftxfont_draw_bitmap (struct frame *f, GC gc_fore, GC *gcs, struct font *font, | |||
| 125 | unsigned char *b; | 123 | unsigned char *b; |
| 126 | int i, j; | 124 | int i, j; |
| 127 | 125 | ||
| 128 | if (ftfont_driver.get_bitmap (font, code, &bitmap, size > 0x100 ? 1 : 8) < 0) | 126 | if (ftfont_get_bitmap (font, code, &bitmap, size > 0x100 ? 1 : 8) < 0) |
| 129 | return 0; | 127 | return 0; |
| 130 | if (size > 0x100) | 128 | if (size > 0x100) |
| 131 | { | 129 | { |
| @@ -188,8 +186,7 @@ ftxfont_draw_bitmap (struct frame *f, GC gc_fore, GC *gcs, struct font *font, | |||
| 188 | } | 186 | } |
| 189 | } | 187 | } |
| 190 | 188 | ||
| 191 | if (ftfont_driver.free_bitmap) | 189 | /* There is no ftfont_free_bitmap, so do not try to free BITMAP. */ |
| 192 | ftfont_driver.free_bitmap (font, &bitmap); | ||
| 193 | 190 | ||
| 194 | return bitmap.advance; | 191 | return bitmap.advance; |
| 195 | } | 192 | } |
| @@ -211,7 +208,7 @@ ftxfont_draw_background (struct frame *f, struct font *font, GC gc, int x, int y | |||
| 211 | static Lisp_Object | 208 | static Lisp_Object |
| 212 | ftxfont_list (struct frame *f, Lisp_Object spec) | 209 | ftxfont_list (struct frame *f, Lisp_Object spec) |
| 213 | { | 210 | { |
| 214 | Lisp_Object list = ftfont_driver.list (f, spec), tail; | 211 | Lisp_Object list = ftfont_list (f, spec), tail; |
| 215 | 212 | ||
| 216 | for (tail = list; CONSP (tail); tail = XCDR (tail)) | 213 | for (tail = list; CONSP (tail); tail = XCDR (tail)) |
| 217 | ASET (XCAR (tail), FONT_TYPE_INDEX, Qftx); | 214 | ASET (XCAR (tail), FONT_TYPE_INDEX, Qftx); |
| @@ -221,7 +218,7 @@ ftxfont_list (struct frame *f, Lisp_Object spec) | |||
| 221 | static Lisp_Object | 218 | static Lisp_Object |
| 222 | ftxfont_match (struct frame *f, Lisp_Object spec) | 219 | ftxfont_match (struct frame *f, Lisp_Object spec) |
| 223 | { | 220 | { |
| 224 | Lisp_Object entity = ftfont_driver.match (f, spec); | 221 | Lisp_Object entity = ftfont_match (f, spec); |
| 225 | 222 | ||
| 226 | if (VECTORP (entity)) | 223 | if (VECTORP (entity)) |
| 227 | ASET (entity, FONT_TYPE_INDEX, Qftx); | 224 | ASET (entity, FONT_TYPE_INDEX, Qftx); |
| @@ -231,13 +228,10 @@ ftxfont_match (struct frame *f, Lisp_Object spec) | |||
| 231 | static Lisp_Object | 228 | static Lisp_Object |
| 232 | ftxfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | 229 | ftxfont_open (struct frame *f, Lisp_Object entity, int pixel_size) |
| 233 | { | 230 | { |
| 234 | Lisp_Object font_object; | 231 | Lisp_Object font_object = ftfont_open (f, entity, pixel_size); |
| 235 | struct font *font; | ||
| 236 | |||
| 237 | font_object = ftfont_driver.open (f, entity, pixel_size); | ||
| 238 | if (NILP (font_object)) | 232 | if (NILP (font_object)) |
| 239 | return Qnil; | 233 | return Qnil; |
| 240 | font = XFONT_OBJECT (font_object); | 234 | struct font *font = XFONT_OBJECT (font_object); |
| 241 | font->driver = &ftxfont_driver; | 235 | font->driver = &ftxfont_driver; |
| 242 | return font_object; | 236 | return font_object; |
| 243 | } | 237 | } |
| @@ -245,7 +239,7 @@ ftxfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 245 | static void | 239 | static void |
| 246 | ftxfont_close (struct font *font) | 240 | ftxfont_close (struct font *font) |
| 247 | { | 241 | { |
| 248 | ftfont_driver.close (font); | 242 | ftfont_close (font); |
| 249 | } | 243 | } |
| 250 | 244 | ||
| 251 | static int | 245 | static int |
| @@ -345,18 +339,39 @@ ftxfont_end_for_frame (struct frame *f) | |||
| 345 | 339 | ||
| 346 | 340 | ||
| 347 | 341 | ||
| 342 | struct font_driver const ftxfont_driver = | ||
| 343 | { | ||
| 344 | /* We can't draw a text without device dependent functions. */ | ||
| 345 | type: LISPSYM_INITIALLY (Qftx), | ||
| 346 | get_cache: ftfont_get_cache, | ||
| 347 | list: ftxfont_list, | ||
| 348 | match: ftxfont_match, | ||
| 349 | list_family: ftfont_list_family, | ||
| 350 | open: ftxfont_open, | ||
| 351 | close: ftxfont_close, | ||
| 352 | has_char: ftfont_has_char, | ||
| 353 | encode_char: ftfont_encode_char, | ||
| 354 | text_extents: ftfont_text_extents, | ||
| 355 | draw: ftxfont_draw, | ||
| 356 | get_bitmap: ftfont_get_bitmap, | ||
| 357 | anchor_point: ftfont_anchor_point, | ||
| 358 | #ifdef HAVE_LIBOTF | ||
| 359 | otf_capability: ftfont_otf_capability, | ||
| 360 | #endif | ||
| 361 | end_for_frame: ftxfont_end_for_frame, | ||
| 362 | #if defined HAVE_M17N_FLT && defined HAVE_LIBOTF | ||
| 363 | shape: ftfont_shape, | ||
| 364 | #endif | ||
| 365 | #ifdef HAVE_OTF_GET_VARIATION_GLYPHS | ||
| 366 | get_variation_glyphs: ftfont_variation_glyphs, | ||
| 367 | #endif | ||
| 368 | filter_properties: ftfont_filter_properties, | ||
| 369 | combining_capability: ftfont_combining_capability, | ||
| 370 | }; | ||
| 371 | |||
| 348 | void | 372 | void |
| 349 | syms_of_ftxfont (void) | 373 | syms_of_ftxfont (void) |
| 350 | { | 374 | { |
| 351 | DEFSYM (Qftx, "ftx"); | 375 | DEFSYM (Qftx, "ftx"); |
| 352 | |||
| 353 | ftxfont_driver = ftfont_driver; | ||
| 354 | ftxfont_driver.type = Qftx; | ||
| 355 | ftxfont_driver.list = ftxfont_list; | ||
| 356 | ftxfont_driver.match = ftxfont_match; | ||
| 357 | ftxfont_driver.open = ftxfont_open; | ||
| 358 | ftxfont_driver.close = ftxfont_close; | ||
| 359 | ftxfont_driver.draw = ftxfont_draw; | ||
| 360 | ftxfont_driver.end_for_frame = ftxfont_end_for_frame; | ||
| 361 | register_font_driver (&ftxfont_driver, NULL); | 376 | register_font_driver (&ftxfont_driver, NULL); |
| 362 | } | 377 | } |
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 | |||
| 38 | 38 | ||
| 39 | #include <libkern/OSByteOrder.h> | 39 | #include <libkern/OSByteOrder.h> |
| 40 | 40 | ||
| 41 | static struct font_driver macfont_driver; | ||
| 42 | |||
| 43 | static double mac_font_get_advance_width_for_glyph (CTFontRef, CGGlyph); | 41 | static double mac_font_get_advance_width_for_glyph (CTFontRef, CGGlyph); |
| 44 | static CGRect mac_font_get_bounding_rect_for_glyph (CTFontRef, CGGlyph); | 42 | static CGRect mac_font_get_bounding_rect_for_glyph (CTFontRef, CGGlyph); |
| 45 | static CFArrayRef mac_font_create_available_families (void); | 43 | static CFArrayRef mac_font_create_available_families (void); |
| @@ -893,7 +891,7 @@ macfont_descriptor_entity (CTFontDescriptorRef desc, Lisp_Object extra, | |||
| 893 | 891 | ||
| 894 | entity = font_make_entity (); | 892 | entity = font_make_entity (); |
| 895 | 893 | ||
| 896 | ASET (entity, FONT_TYPE_INDEX, macfont_driver.type); | 894 | ASET (entity, FONT_TYPE_INDEX, Qmac_ct); |
| 897 | ASET (entity, FONT_REGISTRY_INDEX, Qiso10646_1); | 895 | ASET (entity, FONT_REGISTRY_INDEX, Qiso10646_1); |
| 898 | 896 | ||
| 899 | macfont_store_descriptor_attributes (desc, entity); | 897 | macfont_store_descriptor_attributes (desc, entity); |
| @@ -1663,34 +1661,23 @@ static int macfont_variation_glyphs (struct font *, int c, | |||
| 1663 | unsigned variations[256]); | 1661 | unsigned variations[256]); |
| 1664 | static void macfont_filter_properties (Lisp_Object, Lisp_Object); | 1662 | static void macfont_filter_properties (Lisp_Object, Lisp_Object); |
| 1665 | 1663 | ||
| 1666 | static struct font_driver macfont_driver = | 1664 | static struct font_driver const macfont_driver = |
| 1667 | { | 1665 | { |
| 1668 | LISPSYM_INITIALLY (Qmac_ct), | 1666 | type: LISPSYM_INITIALLY (Qmac_ct), |
| 1669 | 0, /* case insensitive */ | 1667 | get_cache: macfont_get_cache, |
| 1670 | macfont_get_cache, | 1668 | list: macfont_list, |
| 1671 | macfont_list, | 1669 | match: macfont_match, |
| 1672 | macfont_match, | 1670 | list_family: macfont_list_family, |
| 1673 | macfont_list_family, | 1671 | free_entity: macfont_free_entity, |
| 1674 | macfont_free_entity, | 1672 | open: macfont_open, |
| 1675 | macfont_open, | 1673 | close: macfont_close, |
| 1676 | macfont_close, | 1674 | has_char: macfont_has_char, |
| 1677 | NULL, /* prepare_face */ | 1675 | encode_char: macfont_encode_char, |
| 1678 | NULL, /* done_face */ | 1676 | text_extents: macfont_text_extents, |
| 1679 | macfont_has_char, | 1677 | draw: macfont_draw, |
| 1680 | macfont_encode_char, | 1678 | shape: macfont_shape, |
| 1681 | macfont_text_extents, | 1679 | get_variation_glyphs: macfont_variation_glyphs, |
| 1682 | macfont_draw, | 1680 | filter_properties: macfont_filter_properties, |
| 1683 | NULL, /* get_bitmap */ | ||
| 1684 | NULL, /* free_bitmap */ | ||
| 1685 | NULL, /* anchor_point */ | ||
| 1686 | NULL, /* otf_capability */ | ||
| 1687 | NULL, /* otf_drive */ | ||
| 1688 | NULL, /* start_for_frame */ | ||
| 1689 | NULL, /* end_for_frame */ | ||
| 1690 | macfont_shape, | ||
| 1691 | NULL, /* check */ | ||
| 1692 | macfont_variation_glyphs, | ||
| 1693 | macfont_filter_properties, | ||
| 1694 | }; | 1681 | }; |
| 1695 | 1682 | ||
| 1696 | static Lisp_Object | 1683 | 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) | |||
| 610 | ========================================================================== */ | 610 | ========================================================================== */ |
| 611 | 611 | ||
| 612 | 612 | ||
| 613 | static Lisp_Object nsfont_get_cache (struct frame *frame); | ||
| 614 | static Lisp_Object nsfont_list (struct frame *, Lisp_Object); | ||
| 615 | static Lisp_Object nsfont_match (struct frame *, Lisp_Object); | ||
| 616 | static Lisp_Object nsfont_list_family (struct frame *); | ||
| 617 | static Lisp_Object nsfont_open (struct frame *f, Lisp_Object font_entity, | ||
| 618 | int pixel_size); | ||
| 619 | static void nsfont_close (struct font *font); | ||
| 620 | static int nsfont_has_char (Lisp_Object entity, int c); | ||
| 621 | static unsigned int nsfont_encode_char (struct font *font, int c); | ||
| 622 | static void nsfont_text_extents (struct font *font, unsigned int *code, | ||
| 623 | int nglyphs, struct font_metrics *metrics); | ||
| 624 | static int nsfont_draw (struct glyph_string *s, int from, int to, int x, int y, | ||
| 625 | bool with_background); | ||
| 626 | |||
| 627 | struct font_driver nsfont_driver = | ||
| 628 | { | ||
| 629 | LISPSYM_INITIALLY (Qns), | ||
| 630 | 1, /* case sensitive */ | ||
| 631 | nsfont_get_cache, | ||
| 632 | nsfont_list, | ||
| 633 | nsfont_match, | ||
| 634 | nsfont_list_family, | ||
| 635 | NULL, /*free_entity */ | ||
| 636 | nsfont_open, | ||
| 637 | nsfont_close, | ||
| 638 | NULL, /* prepare_face */ | ||
| 639 | NULL, /* done_face */ | ||
| 640 | nsfont_has_char, | ||
| 641 | nsfont_encode_char, | ||
| 642 | nsfont_text_extents, | ||
| 643 | nsfont_draw, | ||
| 644 | /* excluded: get_bitmap, free_bitmap, | ||
| 645 | anchor_point, otf_capability, otf_driver, | ||
| 646 | start_for_frame, end_for_frame, shape */ | ||
| 647 | }; | ||
| 648 | |||
| 649 | |||
| 650 | /* Return a cache of font-entities on FRAME. The cache must be a | 613 | /* Return a cache of font-entities on FRAME. The cache must be a |
| 651 | cons whose cdr part is the actual cache area. */ | 614 | cons whose cdr part is the actual cache area. */ |
| 652 | static Lisp_Object | 615 | static Lisp_Object |
| @@ -788,7 +751,7 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size) | |||
| 788 | 751 | ||
| 789 | font_object = font_make_object (VECSIZE (struct nsfont_info), | 752 | font_object = font_make_object (VECSIZE (struct nsfont_info), |
| 790 | font_entity, pixel_size); | 753 | font_entity, pixel_size); |
| 791 | ASET (font_object, FONT_TYPE_INDEX, nsfont_driver.type); | 754 | ASET (font_object, FONT_TYPE_INDEX, Qns); |
| 792 | font_info = (struct nsfont_info *) XFONT_OBJECT (font_object); | 755 | font_info = (struct nsfont_info *) XFONT_OBJECT (font_object); |
| 793 | font = (struct font *) font_info; | 756 | font = (struct font *) font_info; |
| 794 | if (!font) | 757 | if (!font) |
| @@ -1520,6 +1483,21 @@ ns_dump_glyphstring (struct glyph_string *s) | |||
| 1520 | fprintf (stderr, "\n"); | 1483 | fprintf (stderr, "\n"); |
| 1521 | } | 1484 | } |
| 1522 | 1485 | ||
| 1486 | struct font_driver const nsfont_driver = | ||
| 1487 | { | ||
| 1488 | type: LISPSYM_INITIALLY (Qns), | ||
| 1489 | case_sensitive: true, | ||
| 1490 | get_cache: nsfont_get_cache, | ||
| 1491 | list: nsfont_list, | ||
| 1492 | match: nsfont_match, | ||
| 1493 | list_family: nsfont_list_family, | ||
| 1494 | open: nsfont_open, | ||
| 1495 | close: nsfont_close, | ||
| 1496 | has_char: nsfont_has_char, | ||
| 1497 | encode_char: nsfont_encode_char, | ||
| 1498 | text_extents: nsfont_text_extents, | ||
| 1499 | draw: nsfont_draw, | ||
| 1500 | }; | ||
| 1523 | 1501 | ||
| 1524 | void | 1502 | void |
| 1525 | syms_of_nsfont (void) | 1503 | 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) | |||
| 113 | ? NULL : pcm); | 113 | ? NULL : pcm); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | static Lisp_Object xfont_get_cache (struct frame *); | 116 | Lisp_Object |
| 117 | static Lisp_Object xfont_list (struct frame *, Lisp_Object); | ||
| 118 | static Lisp_Object xfont_match (struct frame *, Lisp_Object); | ||
| 119 | static Lisp_Object xfont_list_family (struct frame *); | ||
| 120 | static Lisp_Object xfont_open (struct frame *, Lisp_Object, int); | ||
| 121 | static void xfont_close (struct font *); | ||
| 122 | static void xfont_prepare_face (struct frame *, struct face *); | ||
| 123 | static int xfont_has_char (Lisp_Object, int); | ||
| 124 | static unsigned xfont_encode_char (struct font *, int); | ||
| 125 | static void xfont_text_extents (struct font *, unsigned *, int, | ||
| 126 | struct font_metrics *); | ||
| 127 | static int xfont_draw (struct glyph_string *, int, int, int, int, bool); | ||
| 128 | static int xfont_check (struct frame *, struct font *); | ||
| 129 | |||
| 130 | struct font_driver xfont_driver = | ||
| 131 | { | ||
| 132 | LISPSYM_INITIALLY (Qx), | ||
| 133 | false, /* case insensitive */ | ||
| 134 | xfont_get_cache, | ||
| 135 | xfont_list, | ||
| 136 | xfont_match, | ||
| 137 | xfont_list_family, | ||
| 138 | NULL, | ||
| 139 | xfont_open, | ||
| 140 | xfont_close, | ||
| 141 | xfont_prepare_face, | ||
| 142 | NULL, | ||
| 143 | xfont_has_char, | ||
| 144 | xfont_encode_char, | ||
| 145 | xfont_text_extents, | ||
| 146 | xfont_draw, | ||
| 147 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | ||
| 148 | xfont_check, | ||
| 149 | NULL, /* get_variation_glyphs */ | ||
| 150 | NULL, /* filter_properties */ | ||
| 151 | }; | ||
| 152 | |||
| 153 | static Lisp_Object | ||
| 154 | xfont_get_cache (struct frame *f) | 117 | xfont_get_cache (struct frame *f) |
| 155 | { | 118 | { |
| 156 | Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f); | 119 | Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f); |
| @@ -1113,6 +1076,24 @@ xfont_check (struct frame *f, struct font *font) | |||
| 1113 | } | 1076 | } |
| 1114 | 1077 | ||
| 1115 | 1078 | ||
| 1079 | |||
| 1080 | struct font_driver const xfont_driver = | ||
| 1081 | { | ||
| 1082 | type: LISPSYM_INITIALLY (Qx), | ||
| 1083 | get_cache: xfont_get_cache, | ||
| 1084 | list: xfont_list, | ||
| 1085 | match: xfont_match, | ||
| 1086 | list_family: xfont_list_family, | ||
| 1087 | open: xfont_open, | ||
| 1088 | close: xfont_close, | ||
| 1089 | prepare_face: xfont_prepare_face, | ||
| 1090 | has_char: xfont_has_char, | ||
| 1091 | encode_char: xfont_encode_char, | ||
| 1092 | text_extents: xfont_text_extents, | ||
| 1093 | draw: xfont_draw, | ||
| 1094 | check: xfont_check, | ||
| 1095 | }; | ||
| 1096 | |||
| 1116 | void | 1097 | void |
| 1117 | syms_of_xfont (void) | 1098 | syms_of_xfont (void) |
| 1118 | { | 1099 | { |
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, | |||
| 125 | } | 125 | } |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | |||
| 129 | struct font_driver xftfont_driver; | ||
| 130 | |||
| 131 | static Lisp_Object | 128 | static Lisp_Object |
| 132 | xftfont_list (struct frame *f, Lisp_Object spec) | 129 | xftfont_list (struct frame *f, Lisp_Object spec) |
| 133 | { | 130 | { |
| 134 | Lisp_Object list = ftfont_driver.list (f, spec), tail; | 131 | Lisp_Object list = ftfont_list (f, spec); |
| 135 | 132 | ||
| 136 | for (tail = list; CONSP (tail); tail = XCDR (tail)) | 133 | for (Lisp_Object tail = list; CONSP (tail); tail = XCDR (tail)) |
| 137 | ASET (XCAR (tail), FONT_TYPE_INDEX, Qxft); | 134 | ASET (XCAR (tail), FONT_TYPE_INDEX, Qxft); |
| 138 | return list; | 135 | return list; |
| 139 | } | 136 | } |
| @@ -141,7 +138,7 @@ xftfont_list (struct frame *f, Lisp_Object spec) | |||
| 141 | static Lisp_Object | 138 | static Lisp_Object |
| 142 | xftfont_match (struct frame *f, Lisp_Object spec) | 139 | xftfont_match (struct frame *f, Lisp_Object spec) |
| 143 | { | 140 | { |
| 144 | Lisp_Object entity = ftfont_driver.match (f, spec); | 141 | Lisp_Object entity = ftfont_match (f, spec); |
| 145 | 142 | ||
| 146 | if (! NILP (entity)) | 143 | if (! NILP (entity)) |
| 147 | ASET (entity, FONT_TYPE_INDEX, Qxft); | 144 | ASET (entity, FONT_TYPE_INDEX, Qxft); |
| @@ -542,7 +539,7 @@ xftfont_has_char (Lisp_Object font, int c) | |||
| 542 | return (ENCODE_CHAR (cs, c) != CHARSET_INVALID_CODE (cs)); | 539 | return (ENCODE_CHAR (cs, c) != CHARSET_INVALID_CODE (cs)); |
| 543 | 540 | ||
| 544 | if (FONT_ENTITY_P (font)) | 541 | if (FONT_ENTITY_P (font)) |
| 545 | return ftfont_driver.has_char (font, c); | 542 | return ftfont_has_char (font, c); |
| 546 | xftfont_info = (struct xftfont_info *) XFONT_OBJECT (font); | 543 | xftfont_info = (struct xftfont_info *) XFONT_OBJECT (font); |
| 547 | return (XftCharExists (xftfont_info->display, xftfont_info->xftfont, | 544 | return (XftCharExists (xftfont_info->display, xftfont_info->xftfont, |
| 548 | (FcChar32) c) == FcTrue); | 545 | (FcChar32) c) == FcTrue); |
| @@ -668,12 +665,9 @@ xftfont_shape (Lisp_Object lgstring) | |||
| 668 | { | 665 | { |
| 669 | struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); | 666 | struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); |
| 670 | struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | 667 | struct xftfont_info *xftfont_info = (struct xftfont_info *) font; |
| 671 | FT_Face ft_face; | 668 | FT_Face ft_face = XftLockFace (xftfont_info->xftfont); |
| 672 | Lisp_Object val; | ||
| 673 | |||
| 674 | ft_face = XftLockFace (xftfont_info->xftfont); | ||
| 675 | xftfont_info->ft_size = ft_face->size; | 669 | xftfont_info->ft_size = ft_face->size; |
| 676 | val = ftfont_driver.shape (lgstring); | 670 | Lisp_Object val = ftfont_shape (lgstring); |
| 677 | XftUnlockFace (xftfont_info->xftfont); | 671 | XftUnlockFace (xftfont_info->xftfont); |
| 678 | return val; | 672 | return val; |
| 679 | } | 673 | } |
| @@ -697,6 +691,10 @@ xftfont_end_for_frame (struct frame *f) | |||
| 697 | return 0; | 691 | return 0; |
| 698 | } | 692 | } |
| 699 | 693 | ||
| 694 | /* When using X double buffering, the XftDraw structure we build | ||
| 695 | seems to be useless once a frame is resized, so recreate it on | ||
| 696 | ConfigureNotify and in some other cases. */ | ||
| 697 | |||
| 700 | static void | 698 | static void |
| 701 | xftfont_drop_xrender_surfaces (struct frame *f) | 699 | xftfont_drop_xrender_surfaces (struct frame *f) |
| 702 | { | 700 | { |
| @@ -751,6 +749,40 @@ xftfont_cached_font_ok (struct frame *f, Lisp_Object font_object, | |||
| 751 | return ok; | 749 | return ok; |
| 752 | } | 750 | } |
| 753 | 751 | ||
| 752 | struct font_driver const xftfont_driver = | ||
| 753 | { | ||
| 754 | /* We can't draw a text without device dependent functions. */ | ||
| 755 | type: LISPSYM_INITIALLY (Qxft), | ||
| 756 | get_cache: xfont_get_cache, | ||
| 757 | list: xftfont_list, | ||
| 758 | match: xftfont_match, | ||
| 759 | list_family: ftfont_list_family, | ||
| 760 | open: xftfont_open, | ||
| 761 | close: xftfont_close, | ||
| 762 | prepare_face: xftfont_prepare_face, | ||
| 763 | done_face: xftfont_done_face, | ||
| 764 | has_char: xftfont_has_char, | ||
| 765 | encode_char: xftfont_encode_char, | ||
| 766 | text_extents: xftfont_text_extents, | ||
| 767 | draw: xftfont_draw, | ||
| 768 | get_bitmap: ftfont_get_bitmap, | ||
| 769 | anchor_point: ftfont_anchor_point, | ||
| 770 | #ifdef HAVE_LIBOTF | ||
| 771 | otf_capability: ftfont_otf_capability, | ||
| 772 | #endif | ||
| 773 | end_for_frame: xftfont_end_for_frame, | ||
| 774 | #if defined HAVE_M17N_FLT && defined HAVE_LIBOTF | ||
| 775 | shape: xftfont_shape, | ||
| 776 | #endif | ||
| 777 | #ifdef HAVE_OTF_GET_VARIATION_GLYPHS | ||
| 778 | get_variation_glyphs: ftfont_variation_glyphs, | ||
| 779 | #endif | ||
| 780 | filter_properties: ftfont_filter_properties, | ||
| 781 | cached_font_ok: xftfont_cached_font_ok, | ||
| 782 | combining_capability: ftfont_combining_capability, | ||
| 783 | drop_xrender_surfaces: xftfont_drop_xrender_surfaces, | ||
| 784 | }; | ||
| 785 | |||
| 754 | void | 786 | void |
| 755 | syms_of_xftfont (void) | 787 | syms_of_xftfont (void) |
| 756 | { | 788 | { |
| @@ -770,28 +802,5 @@ This is needed with some fonts to correct vertical overlap of glyphs. */); | |||
| 770 | 802 | ||
| 771 | ascii_printable[0] = 0; | 803 | ascii_printable[0] = 0; |
| 772 | 804 | ||
| 773 | xftfont_driver = ftfont_driver; | ||
| 774 | xftfont_driver.type = Qxft; | ||
| 775 | xftfont_driver.get_cache = xfont_driver.get_cache; | ||
| 776 | xftfont_driver.list = xftfont_list; | ||
| 777 | xftfont_driver.match = xftfont_match; | ||
| 778 | xftfont_driver.open = xftfont_open; | ||
| 779 | xftfont_driver.close = xftfont_close; | ||
| 780 | xftfont_driver.prepare_face = xftfont_prepare_face; | ||
| 781 | xftfont_driver.done_face = xftfont_done_face; | ||
| 782 | xftfont_driver.has_char = xftfont_has_char; | ||
| 783 | xftfont_driver.encode_char = xftfont_encode_char; | ||
| 784 | xftfont_driver.text_extents = xftfont_text_extents; | ||
| 785 | xftfont_driver.draw = xftfont_draw; | ||
| 786 | xftfont_driver.end_for_frame = xftfont_end_for_frame; | ||
| 787 | xftfont_driver.cached_font_ok = xftfont_cached_font_ok; | ||
| 788 | #if defined (HAVE_M17N_FLT) && defined (HAVE_LIBOTF) | ||
| 789 | xftfont_driver.shape = xftfont_shape; | ||
| 790 | #endif | ||
| 791 | /* When using X double buffering, the XftDraw structure we build | ||
| 792 | seems to be useless once a frame is resized, so recreate it on | ||
| 793 | ConfigureNotify and in some other cases. */ | ||
| 794 | xftfont_driver.drop_xrender_surfaces = xftfont_drop_xrender_surfaces; | ||
| 795 | |||
| 796 | register_font_driver (&xftfont_driver, NULL); | 805 | register_font_driver (&xftfont_driver, NULL); |
| 797 | } | 806 | } |