diff options
| author | Khaled Hosny | 2018-06-05 03:25:35 +0200 |
|---|---|---|
| committer | Khaled Hosny | 2018-12-10 00:08:50 +0200 |
| commit | ca0b6e90f8a943825b728d00c60456bc55d42a25 (patch) | |
| tree | 253cfbda1db10489dc80a129da32526709c4a61c /src | |
| parent | 9014e05fcb1bdfee3d4a0d10129bd1f9cf6a85ab (diff) | |
| download | emacs-ca0b6e90f8a943825b728d00c60456bc55d42a25.tar.gz emacs-ca0b6e90f8a943825b728d00c60456bc55d42a25.zip | |
Cache hb_font_t
Not sure if the xftfont.c changes are really needed, but followed the
libotf code just in case.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ftfont.c | 65 | ||||
| -rw-r--r-- | src/xftfont.c | 13 |
2 files changed, 58 insertions, 20 deletions
diff --git a/src/ftfont.c b/src/ftfont.c index d98652f379c..0990e84ddab 100644 --- a/src/ftfont.c +++ b/src/ftfont.c | |||
| @@ -61,6 +61,9 @@ struct ftfont_info | |||
| 61 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ | 61 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ |
| 62 | OTF *otf; | 62 | OTF *otf; |
| 63 | #endif /* HAVE_LIBOTF */ | 63 | #endif /* HAVE_LIBOTF */ |
| 64 | #ifdef HAVE_HARFBUZZ | ||
| 65 | hb_font_t *hb_font; | ||
| 66 | #endif /* HAVE_HARFBUZZ */ | ||
| 64 | FT_Size ft_size; | 67 | FT_Size ft_size; |
| 65 | int index; | 68 | int index; |
| 66 | FT_Matrix matrix; | 69 | FT_Matrix matrix; |
| @@ -473,6 +476,35 @@ ftfont_get_otf (struct ftfont_info *ftfont_info) | |||
| 473 | } | 476 | } |
| 474 | #endif /* HAVE_LIBOTF */ | 477 | #endif /* HAVE_LIBOTF */ |
| 475 | 478 | ||
| 479 | #ifdef HAVE_HARFBUZZ | ||
| 480 | |||
| 481 | #ifndef HAVE_HB_FT_FONT_CREATE_REFERENCED | ||
| 482 | static void | ||
| 483 | ft_face_destroy (void *data) | ||
| 484 | { | ||
| 485 | FT_Done_Face ((FT_Face) data); | ||
| 486 | } | ||
| 487 | #endif | ||
| 488 | |||
| 489 | static hb_font_t * | ||
| 490 | ftfont_get_hb_font (struct ftfont_info *ftfont_info) | ||
| 491 | { | ||
| 492 | if (! ftfont_info->hb_font) | ||
| 493 | { | ||
| 494 | hb_font_t *hb_font; | ||
| 495 | #ifdef HAVE_HB_FT_FONT_CREATE_REFERENCED | ||
| 496 | hb_font = hb_ft_font_create_referenced (ftfont_info->ft_size->face); | ||
| 497 | #else | ||
| 498 | FT_Reference_Face (ftfont_info->ft_size->face); | ||
| 499 | hb_font = hb_ft_font_create (ftfont_info->ft_size->face, ft_face_destroy); | ||
| 500 | #endif | ||
| 501 | ftfont_info->hb_font = hb_font; | ||
| 502 | } | ||
| 503 | return ftfont_info->hb_font; | ||
| 504 | } | ||
| 505 | |||
| 506 | #endif /* HAVE_HARFBUZZ */ | ||
| 507 | |||
| 476 | Lisp_Object | 508 | Lisp_Object |
| 477 | ftfont_get_cache (struct frame *f) | 509 | ftfont_get_cache (struct frame *f) |
| 478 | { | 510 | { |
| @@ -1153,6 +1185,9 @@ ftfont_open2 (struct frame *f, | |||
| 1153 | ftfont_info->maybe_otf = (ft_face->face_flags & FT_FACE_FLAG_SFNT) != 0; | 1185 | ftfont_info->maybe_otf = (ft_face->face_flags & FT_FACE_FLAG_SFNT) != 0; |
| 1154 | ftfont_info->otf = NULL; | 1186 | ftfont_info->otf = NULL; |
| 1155 | #endif /* HAVE_LIBOTF */ | 1187 | #endif /* HAVE_LIBOTF */ |
| 1188 | #ifdef HAVE_HARFBUZZ | ||
| 1189 | ftfont_info->hb_font = NULL; | ||
| 1190 | #endif /* HAVE_HARFBUZZ */ | ||
| 1156 | /* This means that there's no need of transformation. */ | 1191 | /* This means that there's no need of transformation. */ |
| 1157 | ftfont_info->matrix.xx = 0; | 1192 | ftfont_info->matrix.xx = 0; |
| 1158 | font->pixel_size = size; | 1193 | font->pixel_size = size; |
| @@ -1263,6 +1298,10 @@ ftfont_close (struct font *font) | |||
| 1263 | if (ftfont_info->otf) | 1298 | if (ftfont_info->otf) |
| 1264 | OTF_close (ftfont_info->otf); | 1299 | OTF_close (ftfont_info->otf); |
| 1265 | #endif | 1300 | #endif |
| 1301 | #ifdef HAVE_HARFBUZZ | ||
| 1302 | if (ftfont_info->hb_font) | ||
| 1303 | hb_font_destroy (ftfont_info->hb_font); | ||
| 1304 | #endif | ||
| 1266 | cache_data->ft_face = NULL; | 1305 | cache_data->ft_face = NULL; |
| 1267 | } | 1306 | } |
| 1268 | else | 1307 | else |
| @@ -2648,17 +2687,9 @@ ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256]) | |||
| 2648 | 2687 | ||
| 2649 | #ifdef HAVE_HARFBUZZ | 2688 | #ifdef HAVE_HARFBUZZ |
| 2650 | 2689 | ||
| 2651 | #ifndef HAVE_HB_FT_FONT_CREATE_REFERENCED | ||
| 2652 | static void | ||
| 2653 | ft_face_destroy (void *data) | ||
| 2654 | { | ||
| 2655 | FT_Done_Face ((FT_Face) data); | ||
| 2656 | } | ||
| 2657 | #endif | ||
| 2658 | |||
| 2659 | static Lisp_Object | 2690 | static Lisp_Object |
| 2660 | ftfont_shape_by_hb (Lisp_Object lgstring, | 2691 | ftfont_shape_by_hb (Lisp_Object lgstring, FT_Face ft_face, hb_font_t *hb_font, |
| 2661 | FT_Face ft_face, FT_Matrix *matrix) | 2692 | FT_Matrix *matrix) |
| 2662 | { | 2693 | { |
| 2663 | ptrdiff_t glyph_len = 0, text_len = LGSTRING_GLYPH_LEN (lgstring); | 2694 | ptrdiff_t glyph_len = 0, text_len = LGSTRING_GLYPH_LEN (lgstring); |
| 2664 | ptrdiff_t i; | 2695 | ptrdiff_t i; |
| @@ -2666,15 +2697,8 @@ ftfont_shape_by_hb (Lisp_Object lgstring, | |||
| 2666 | hb_glyph_info_t *info; | 2697 | hb_glyph_info_t *info; |
| 2667 | hb_glyph_position_t *pos; | 2698 | hb_glyph_position_t *pos; |
| 2668 | 2699 | ||
| 2669 | /* FIXME: cache the buffer and the font */ | 2700 | /* FIXME: cache the buffer */ |
| 2670 | hb_buffer_t *hb_buffer = hb_buffer_create (); | 2701 | hb_buffer_t *hb_buffer = hb_buffer_create (); |
| 2671 | #ifdef HAVE_HB_FT_FONT_CREATE_REFERENCED | ||
| 2672 | hb_font_t *hb_font = hb_ft_font_create_referenced (ft_face); | ||
| 2673 | #else | ||
| 2674 | FT_Reference_Face (ft_face); | ||
| 2675 | hb_font_t *hb_font = hb_ft_font_create (ft_face, ft_face_destroy); | ||
| 2676 | #endif | ||
| 2677 | |||
| 2678 | hb_buffer_pre_allocate (hb_buffer, text_len); | 2702 | hb_buffer_pre_allocate (hb_buffer, text_len); |
| 2679 | 2703 | ||
| 2680 | for (i = 0; i < text_len; i++) | 2704 | for (i = 0; i < text_len; i++) |
| @@ -2768,7 +2792,6 @@ ftfont_shape_by_hb (Lisp_Object lgstring, | |||
| 2768 | } | 2792 | } |
| 2769 | 2793 | ||
| 2770 | done: | 2794 | done: |
| 2771 | hb_font_destroy (hb_font); | ||
| 2772 | hb_buffer_destroy (hb_buffer); | 2795 | hb_buffer_destroy (hb_buffer); |
| 2773 | 2796 | ||
| 2774 | return make_fixnum (glyph_len); | 2797 | return make_fixnum (glyph_len); |
| @@ -2786,8 +2809,10 @@ ftfont_shape (Lisp_Object lgstring) | |||
| 2786 | #ifdef HAVE_HARFBUZZ | 2809 | #ifdef HAVE_HARFBUZZ |
| 2787 | if (getenv ("EMACS_NO_HARFBUZZ") == NULL) | 2810 | if (getenv ("EMACS_NO_HARFBUZZ") == NULL) |
| 2788 | { | 2811 | { |
| 2812 | hb_font_t *hb_font = ftfont_get_hb_font (ftfont_info); | ||
| 2813 | |||
| 2789 | return ftfont_shape_by_hb (lgstring, ftfont_info->ft_size->face, | 2814 | return ftfont_shape_by_hb (lgstring, ftfont_info->ft_size->face, |
| 2790 | &ftfont_info->matrix); | 2815 | hb_font, &ftfont_info->matrix); |
| 2791 | } | 2816 | } |
| 2792 | else | 2817 | else |
| 2793 | #endif /* HAVE_HARFBUZZ */ | 2818 | #endif /* HAVE_HARFBUZZ */ |
diff --git a/src/xftfont.c b/src/xftfont.c index 7650de3a779..e0bd243467a 100644 --- a/src/xftfont.c +++ b/src/xftfont.c | |||
| @@ -48,6 +48,9 @@ struct xftfont_info | |||
| 48 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ | 48 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ |
| 49 | OTF *otf; | 49 | OTF *otf; |
| 50 | #endif /* HAVE_LIBOTF */ | 50 | #endif /* HAVE_LIBOTF */ |
| 51 | #ifdef HAVE_HARFBUZZ | ||
| 52 | hb_font_t *hb_font; | ||
| 53 | #endif /* HAVE_HARFBUZZ */ | ||
| 51 | FT_Size ft_size; | 54 | FT_Size ft_size; |
| 52 | int index; | 55 | int index; |
| 53 | FT_Matrix matrix; | 56 | FT_Matrix matrix; |
| @@ -430,6 +433,9 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 430 | xftfont_info->maybe_otf = (ft_face->face_flags & FT_FACE_FLAG_SFNT) != 0; | 433 | xftfont_info->maybe_otf = (ft_face->face_flags & FT_FACE_FLAG_SFNT) != 0; |
| 431 | xftfont_info->otf = NULL; | 434 | xftfont_info->otf = NULL; |
| 432 | #endif /* HAVE_LIBOTF */ | 435 | #endif /* HAVE_LIBOTF */ |
| 436 | #ifdef HAVE_HARFBUZZ | ||
| 437 | xftfont_info->hb_font = NULL; | ||
| 438 | #endif /* HAVE_HARFBUZZ */ | ||
| 433 | xftfont_info->ft_size = ft_face->size; | 439 | xftfont_info->ft_size = ft_face->size; |
| 434 | 440 | ||
| 435 | font->baseline_offset = 0; | 441 | font->baseline_offset = 0; |
| @@ -469,6 +475,13 @@ xftfont_close (struct font *font) | |||
| 469 | xftfont_info->otf = NULL; | 475 | xftfont_info->otf = NULL; |
| 470 | } | 476 | } |
| 471 | #endif | 477 | #endif |
| 478 | #ifdef HAVE_HARFBUZZ | ||
| 479 | if (xftfont_info->hb_font) | ||
| 480 | { | ||
| 481 | hb_font_destroy (xftfont_info->hb_font); | ||
| 482 | xftfont_info->hb_font = NULL; | ||
| 483 | } | ||
| 484 | #endif | ||
| 472 | 485 | ||
| 473 | /* See comment in xfont_close. */ | 486 | /* See comment in xfont_close. */ |
| 474 | if (xftfont_info->xftfont | 487 | if (xftfont_info->xftfont |