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 /src/xftfont.c | |
| 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.
Diffstat (limited to 'src/xftfont.c')
| -rw-r--r-- | src/xftfont.c | 79 |
1 files changed, 44 insertions, 35 deletions
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 | } |