diff options
| author | Robert Pluim | 2019-02-08 15:36:56 +0100 |
|---|---|---|
| committer | Robert Pluim | 2019-02-08 15:36:56 +0100 |
| commit | 015a6e1df2772bd43680df5cbeaffccf98a881da (patch) | |
| tree | beb0f733dc04259d9fdf896ece841bce859b2c1e /src | |
| parent | 066a2b4914592478153983b587a36d226061dd89 (diff) | |
| download | emacs-015a6e1df2772bd43680df5cbeaffccf98a881da.tar.gz emacs-015a6e1df2772bd43680df5cbeaffccf98a881da.zip | |
Unify three font info structures
* src/ftfont.h (struct font_info): New type, unifies similar types
from ftcrfont.c, ftfont.c and xftfont.c
* src/xftfont.c (struct xftfont_info): Remove, replace with struct
font_info. Adjust all uses.
* src/ftcrfont.c (struct ftcrfont_info): Likewise.
* src/ftfont.c (struct ftfont_info): Likewise.
(cherry picked from commit 9e0d69b5a17a0fa3b0dd099a51584a85f3ddb5bf)
Diffstat (limited to 'src')
| -rw-r--r-- | src/ftcrfont.c | 45 | ||||
| -rw-r--r-- | src/ftfont.c | 63 | ||||
| -rw-r--r-- | src/ftfont.h | 40 | ||||
| -rw-r--r-- | src/xftfont.c | 46 |
4 files changed, 79 insertions, 115 deletions
diff --git a/src/ftcrfont.c b/src/ftcrfont.c index 95ff89328d6..45e526d24a4 100644 --- a/src/ftcrfont.c +++ b/src/ftcrfont.c | |||
| @@ -27,36 +27,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 27 | #include "font.h" | 27 | #include "font.h" |
| 28 | #include "ftfont.h" | 28 | #include "ftfont.h" |
| 29 | 29 | ||
| 30 | /* FTCR font driver. */ | ||
| 31 | |||
| 32 | /* The actual structure for FTCR font. A pointer to this structure | ||
| 33 | can be cast to struct font *. */ | ||
| 34 | |||
| 35 | struct ftcrfont_info | ||
| 36 | { | ||
| 37 | struct font font; | ||
| 38 | /* The following six members must be here in this order to be | ||
| 39 | compatible with struct ftfont_info (in ftfont.c). */ | ||
| 40 | #ifdef HAVE_LIBOTF | ||
| 41 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ | ||
| 42 | OTF *otf; | ||
| 43 | #endif /* HAVE_LIBOTF */ | ||
| 44 | #ifdef HAVE_HARFBUZZ | ||
| 45 | hb_font_t *hb_font; | ||
| 46 | #endif /* HAVE_HARFBUZZ */ | ||
| 47 | FT_Size ft_size; | ||
| 48 | int index; | ||
| 49 | FT_Matrix matrix; | ||
| 50 | |||
| 51 | cairo_font_face_t *cr_font_face; | ||
| 52 | /* To prevent cairo from cluttering the activated FT_Size maintained | ||
| 53 | in ftfont.c, we activate this special FT_Size before drawing. */ | ||
| 54 | FT_Size ft_size_draw; | ||
| 55 | /* Font metrics cache. */ | ||
| 56 | struct font_metrics **metrics; | ||
| 57 | short metrics_nrows; | ||
| 58 | }; | ||
| 59 | |||
| 60 | #define METRICS_NCOLS_PER_ROW (128) | 30 | #define METRICS_NCOLS_PER_ROW (128) |
| 61 | 31 | ||
| 62 | enum metrics_status | 32 | enum metrics_status |
| @@ -73,7 +43,7 @@ ftcrfont_glyph_extents (struct font *font, | |||
| 73 | unsigned glyph, | 43 | unsigned glyph, |
| 74 | struct font_metrics *metrics) | 44 | struct font_metrics *metrics) |
| 75 | { | 45 | { |
| 76 | struct ftcrfont_info *ftcrfont_info = (struct ftcrfont_info *) font; | 46 | struct font_info *ftcrfont_info = (struct font_info *) font; |
| 77 | int row, col; | 47 | int row, col; |
| 78 | struct font_metrics *cache; | 48 | struct font_metrics *cache; |
| 79 | 49 | ||
| @@ -135,7 +105,7 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 135 | { | 105 | { |
| 136 | Lisp_Object font_object; | 106 | Lisp_Object font_object; |
| 137 | struct font *font; | 107 | struct font *font; |
| 138 | struct ftcrfont_info *ftcrfont_info; | 108 | struct font_info *ftcrfont_info; |
| 139 | FT_Face ft_face; | 109 | FT_Face ft_face; |
| 140 | FT_UInt size; | 110 | FT_UInt size; |
| 141 | 111 | ||
| @@ -143,14 +113,14 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 143 | size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX)); | 113 | size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX)); |
| 144 | if (size == 0) | 114 | if (size == 0) |
| 145 | size = pixel_size; | 115 | size = pixel_size; |
| 146 | font_object = font_build_object (VECSIZE (struct ftcrfont_info), | 116 | font_object = font_build_object (VECSIZE (struct font_info), |
| 147 | Qftcr, entity, size); | 117 | Qftcr, entity, size); |
| 148 | font_object = ftfont_open2 (f, entity, pixel_size, font_object); | 118 | font_object = ftfont_open2 (f, entity, pixel_size, font_object); |
| 149 | if (NILP (font_object)) return Qnil; | 119 | if (NILP (font_object)) return Qnil; |
| 150 | 120 | ||
| 151 | font = XFONT_OBJECT (font_object); | 121 | font = XFONT_OBJECT (font_object); |
| 152 | font->driver = &ftcrfont_driver; | 122 | font->driver = &ftcrfont_driver; |
| 153 | ftcrfont_info = (struct ftcrfont_info *) font; | 123 | ftcrfont_info = (struct font_info *) font; |
| 154 | ft_face = ftcrfont_info->ft_size->face; | 124 | ft_face = ftcrfont_info->ft_size->face; |
| 155 | FT_New_Size (ft_face, &ftcrfont_info->ft_size_draw); | 125 | FT_New_Size (ft_face, &ftcrfont_info->ft_size_draw); |
| 156 | FT_Activate_Size (ftcrfont_info->ft_size_draw); | 126 | FT_Activate_Size (ftcrfont_info->ft_size_draw); |
| @@ -170,7 +140,7 @@ ftcrfont_close (struct font *font) | |||
| 170 | if (font_data_structures_may_be_ill_formed ()) | 140 | if (font_data_structures_may_be_ill_formed ()) |
| 171 | return; | 141 | return; |
| 172 | 142 | ||
| 173 | struct ftcrfont_info *ftcrfont_info = (struct ftcrfont_info *) font; | 143 | struct font_info *ftcrfont_info = (struct font_info *) font; |
| 174 | int i; | 144 | int i; |
| 175 | 145 | ||
| 176 | block_input (); | 146 | block_input (); |
| @@ -226,7 +196,7 @@ ftcrfont_draw (struct glyph_string *s, | |||
| 226 | { | 196 | { |
| 227 | struct frame *f = s->f; | 197 | struct frame *f = s->f; |
| 228 | struct face *face = s->face; | 198 | struct face *face = s->face; |
| 229 | struct ftcrfont_info *ftcrfont_info = (struct ftcrfont_info *) s->font; | 199 | struct font_info *ftcrfont_info = (struct font_info *) s->font; |
| 230 | cairo_t *cr; | 200 | cairo_t *cr; |
| 231 | cairo_glyph_t *glyphs; | 201 | cairo_glyph_t *glyphs; |
| 232 | cairo_surface_t *surface; | 202 | cairo_surface_t *surface; |
| @@ -315,9 +285,6 @@ struct font_driver const ftcrfont_driver = | |||
| 315 | void | 285 | void |
| 316 | syms_of_ftcrfont (void) | 286 | syms_of_ftcrfont (void) |
| 317 | { | 287 | { |
| 318 | if (ftfont_info_size != offsetof (struct ftcrfont_info, cr_font_face)) | ||
| 319 | abort (); | ||
| 320 | |||
| 321 | DEFSYM (Qftcr, "ftcr"); | 288 | DEFSYM (Qftcr, "ftcr"); |
| 322 | register_font_driver (&ftcrfont_driver, NULL); | 289 | register_font_driver (&ftcrfont_driver, NULL); |
| 323 | } | 290 | } |
diff --git a/src/ftfont.c b/src/ftfont.c index c2662875f8b..63df123001f 100644 --- a/src/ftfont.c +++ b/src/ftfont.c | |||
| @@ -24,6 +24,17 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 24 | #include <fontconfig/fontconfig.h> | 24 | #include <fontconfig/fontconfig.h> |
| 25 | #include <fontconfig/fcfreetype.h> | 25 | #include <fontconfig/fcfreetype.h> |
| 26 | 26 | ||
| 27 | /* These two blocks are here because this file is built when using XFT | ||
| 28 | and when using Cairo, so struct font_info in ftfont.h needs access | ||
| 29 | to the appropriate types. */ | ||
| 30 | #ifdef HAVE_XFT | ||
| 31 | # include <X11/Xlib.h> | ||
| 32 | # include <X11/Xft/Xft.h> | ||
| 33 | #endif | ||
| 34 | #ifdef USE_CAIRO | ||
| 35 | # include <cairo-ft.h> | ||
| 36 | #endif | ||
| 37 | |||
| 27 | #include <c-strcase.h> | 38 | #include <c-strcase.h> |
| 28 | 39 | ||
| 29 | #include "lisp.h" | 40 | #include "lisp.h" |
| @@ -49,28 +60,6 @@ static Lisp_Object freetype_font_cache; | |||
| 49 | /* Cache for FT_Face and FcCharSet. */ | 60 | /* Cache for FT_Face and FcCharSet. */ |
| 50 | static Lisp_Object ft_face_cache; | 61 | static Lisp_Object ft_face_cache; |
| 51 | 62 | ||
| 52 | /* The actual structure for FreeType font that can be cast to struct | ||
| 53 | font. */ | ||
| 54 | |||
| 55 | struct ftfont_info | ||
| 56 | { | ||
| 57 | struct font font; | ||
| 58 | #ifdef HAVE_LIBOTF | ||
| 59 | /* The following four members must be here in this order to be | ||
| 60 | compatible with struct xftfont_info (in xftfont.c). */ | ||
| 61 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ | ||
| 62 | OTF *otf; | ||
| 63 | #endif /* HAVE_LIBOTF */ | ||
| 64 | #ifdef HAVE_HARFBUZZ | ||
| 65 | hb_font_t *hb_font; | ||
| 66 | #endif /* HAVE_HARFBUZZ */ | ||
| 67 | FT_Size ft_size; | ||
| 68 | int index; | ||
| 69 | FT_Matrix matrix; | ||
| 70 | }; | ||
| 71 | |||
| 72 | size_t ftfont_info_size = sizeof (struct ftfont_info); | ||
| 73 | |||
| 74 | enum ftfont_cache_for | 63 | enum ftfont_cache_for |
| 75 | { | 64 | { |
| 76 | FTFONT_CACHE_FOR_FACE, | 65 | FTFONT_CACHE_FOR_FACE, |
| @@ -455,7 +444,7 @@ ftfont_get_fc_charset (Lisp_Object entity) | |||
| 455 | 444 | ||
| 456 | #ifdef HAVE_LIBOTF | 445 | #ifdef HAVE_LIBOTF |
| 457 | static OTF * | 446 | static OTF * |
| 458 | ftfont_get_otf (struct ftfont_info *ftfont_info) | 447 | ftfont_get_otf (struct font_info *ftfont_info) |
| 459 | { | 448 | { |
| 460 | OTF *otf; | 449 | OTF *otf; |
| 461 | 450 | ||
| @@ -479,7 +468,7 @@ ftfont_get_otf (struct ftfont_info *ftfont_info) | |||
| 479 | #ifdef HAVE_HARFBUZZ | 468 | #ifdef HAVE_HARFBUZZ |
| 480 | 469 | ||
| 481 | static hb_font_t * | 470 | static hb_font_t * |
| 482 | ftfont_get_hb_font (struct ftfont_info *ftfont_info) | 471 | ftfont_get_hb_font (struct font_info *ftfont_info) |
| 483 | { | 472 | { |
| 484 | if (! ftfont_info->hb_font) | 473 | if (! ftfont_info->hb_font) |
| 485 | ftfont_info->hb_font | 474 | ftfont_info->hb_font |
| @@ -1111,7 +1100,7 @@ ftfont_open2 (struct frame *f, | |||
| 1111 | int pixel_size, | 1100 | int pixel_size, |
| 1112 | Lisp_Object font_object) | 1101 | Lisp_Object font_object) |
| 1113 | { | 1102 | { |
| 1114 | struct ftfont_info *ftfont_info; | 1103 | struct font_info *ftfont_info; |
| 1115 | struct font *font; | 1104 | struct font *font; |
| 1116 | struct ftfont_cache_data *cache_data; | 1105 | struct ftfont_cache_data *cache_data; |
| 1117 | FT_Face ft_face; | 1106 | FT_Face ft_face; |
| @@ -1162,7 +1151,7 @@ ftfont_open2 (struct frame *f, | |||
| 1162 | 1151 | ||
| 1163 | ASET (font_object, FONT_FILE_INDEX, filename); | 1152 | ASET (font_object, FONT_FILE_INDEX, filename); |
| 1164 | font = XFONT_OBJECT (font_object); | 1153 | font = XFONT_OBJECT (font_object); |
| 1165 | ftfont_info = (struct ftfont_info *) font; | 1154 | ftfont_info = (struct font_info *) font; |
| 1166 | ftfont_info->ft_size = ft_face->size; | 1155 | ftfont_info->ft_size = ft_face->size; |
| 1167 | ftfont_info->index = XFIXNUM (idx); | 1156 | ftfont_info->index = XFIXNUM (idx); |
| 1168 | #ifdef HAVE_LIBOTF | 1157 | #ifdef HAVE_LIBOTF |
| @@ -1255,7 +1244,7 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 1255 | size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX)); | 1244 | size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX)); |
| 1256 | if (size == 0) | 1245 | if (size == 0) |
| 1257 | size = pixel_size; | 1246 | size = pixel_size; |
| 1258 | font_object = font_build_object (VECSIZE (struct ftfont_info), | 1247 | font_object = font_build_object (VECSIZE (struct font_info), |
| 1259 | Qfreetype, entity, size); | 1248 | Qfreetype, entity, size); |
| 1260 | return ftfont_open2 (f, entity, pixel_size, font_object); | 1249 | return ftfont_open2 (f, entity, pixel_size, font_object); |
| 1261 | } | 1250 | } |
| @@ -1266,7 +1255,7 @@ ftfont_close (struct font *font) | |||
| 1266 | if (font_data_structures_may_be_ill_formed ()) | 1255 | if (font_data_structures_may_be_ill_formed ()) |
| 1267 | return; | 1256 | return; |
| 1268 | 1257 | ||
| 1269 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1258 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1270 | Lisp_Object val, cache; | 1259 | Lisp_Object val, cache; |
| 1271 | 1260 | ||
| 1272 | val = Fcons (font->props[FONT_FILE_INDEX], make_fixnum (ftfont_info->index)); | 1261 | val = Fcons (font->props[FONT_FILE_INDEX], make_fixnum (ftfont_info->index)); |
| @@ -1314,9 +1303,9 @@ ftfont_has_char (Lisp_Object font, int c) | |||
| 1314 | } | 1303 | } |
| 1315 | else | 1304 | else |
| 1316 | { | 1305 | { |
| 1317 | struct ftfont_info *ftfont_info; | 1306 | struct font_info *ftfont_info; |
| 1318 | 1307 | ||
| 1319 | ftfont_info = (struct ftfont_info *) XFONT_OBJECT (font); | 1308 | ftfont_info = (struct font_info *) XFONT_OBJECT (font); |
| 1320 | return (FT_Get_Char_Index (ftfont_info->ft_size->face, (FT_ULong) c) | 1309 | return (FT_Get_Char_Index (ftfont_info->ft_size->face, (FT_ULong) c) |
| 1321 | != 0); | 1310 | != 0); |
| 1322 | } | 1311 | } |
| @@ -1325,7 +1314,7 @@ ftfont_has_char (Lisp_Object font, int c) | |||
| 1325 | unsigned | 1314 | unsigned |
| 1326 | ftfont_encode_char (struct font *font, int c) | 1315 | ftfont_encode_char (struct font *font, int c) |
| 1327 | { | 1316 | { |
| 1328 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1317 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1329 | FT_Face ft_face = ftfont_info->ft_size->face; | 1318 | FT_Face ft_face = ftfont_info->ft_size->face; |
| 1330 | FT_ULong charcode = c; | 1319 | FT_ULong charcode = c; |
| 1331 | FT_UInt code = FT_Get_Char_Index (ft_face, charcode); | 1320 | FT_UInt code = FT_Get_Char_Index (ft_face, charcode); |
| @@ -1355,7 +1344,7 @@ void | |||
| 1355 | ftfont_text_extents (struct font *font, unsigned int *code, | 1344 | ftfont_text_extents (struct font *font, unsigned int *code, |
| 1356 | int nglyphs, struct font_metrics *metrics) | 1345 | int nglyphs, struct font_metrics *metrics) |
| 1357 | { | 1346 | { |
| 1358 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1347 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1359 | FT_Face ft_face = ftfont_info->ft_size->face; | 1348 | FT_Face ft_face = ftfont_info->ft_size->face; |
| 1360 | int i, width = 0; | 1349 | int i, width = 0; |
| 1361 | bool first; | 1350 | bool first; |
| @@ -1396,7 +1385,7 @@ ftfont_text_extents (struct font *font, unsigned int *code, | |||
| 1396 | int | 1385 | int |
| 1397 | ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bitmap, int bits_per_pixel) | 1386 | ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bitmap, int bits_per_pixel) |
| 1398 | { | 1387 | { |
| 1399 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1388 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1400 | FT_Face ft_face = ftfont_info->ft_size->face; | 1389 | FT_Face ft_face = ftfont_info->ft_size->face; |
| 1401 | FT_Int32 load_flags = FT_LOAD_RENDER; | 1390 | FT_Int32 load_flags = FT_LOAD_RENDER; |
| 1402 | 1391 | ||
| @@ -1440,7 +1429,7 @@ int | |||
| 1440 | ftfont_anchor_point (struct font *font, unsigned int code, int idx, | 1429 | ftfont_anchor_point (struct font *font, unsigned int code, int idx, |
| 1441 | int *x, int *y) | 1430 | int *x, int *y) |
| 1442 | { | 1431 | { |
| 1443 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1432 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1444 | FT_Face ft_face = ftfont_info->ft_size->face; | 1433 | FT_Face ft_face = ftfont_info->ft_size->face; |
| 1445 | 1434 | ||
| 1446 | if (ftfont_info->ft_size != ft_face->size) | 1435 | if (ftfont_info->ft_size != ft_face->size) |
| @@ -1505,7 +1494,7 @@ ftfont_otf_features (OTF_GSUB_GPOS *gsub_gpos) | |||
| 1505 | Lisp_Object | 1494 | Lisp_Object |
| 1506 | ftfont_otf_capability (struct font *font) | 1495 | ftfont_otf_capability (struct font *font) |
| 1507 | { | 1496 | { |
| 1508 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1497 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1509 | OTF *otf = ftfont_get_otf (ftfont_info); | 1498 | OTF *otf = ftfont_get_otf (ftfont_info); |
| 1510 | Lisp_Object gsub_gpos; | 1499 | Lisp_Object gsub_gpos; |
| 1511 | 1500 | ||
| @@ -2658,7 +2647,7 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, | |||
| 2658 | int | 2647 | int |
| 2659 | ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256]) | 2648 | ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256]) |
| 2660 | { | 2649 | { |
| 2661 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 2650 | struct font_info *ftfont_info = (struct font_info *) font; |
| 2662 | OTF *otf = ftfont_get_otf (ftfont_info); | 2651 | OTF *otf = ftfont_get_otf (ftfont_info); |
| 2663 | 2652 | ||
| 2664 | if (! otf) | 2653 | if (! otf) |
| @@ -2946,7 +2935,7 @@ Lisp_Object | |||
| 2946 | ftfont_shape (Lisp_Object lgstring, Lisp_Object direction) | 2935 | ftfont_shape (Lisp_Object lgstring, Lisp_Object direction) |
| 2947 | { | 2936 | { |
| 2948 | struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); | 2937 | struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); |
| 2949 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 2938 | struct font_info *ftfont_info = (struct font_info *) font; |
| 2950 | #ifdef HAVE_HARFBUZZ | 2939 | #ifdef HAVE_HARFBUZZ |
| 2951 | if (getenv ("EMACS_NO_HARFBUZZ") == NULL) | 2940 | if (getenv ("EMACS_NO_HARFBUZZ") == NULL) |
| 2952 | { | 2941 | { |
diff --git a/src/ftfont.h b/src/ftfont.h index d856c106183..3bbcbfb5d70 100644 --- a/src/ftfont.h +++ b/src/ftfont.h | |||
| @@ -26,7 +26,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 26 | #include FT_FREETYPE_H | 26 | #include FT_FREETYPE_H |
| 27 | #include FT_SIZES_H | 27 | #include FT_SIZES_H |
| 28 | #ifdef FT_BDF_H | 28 | #ifdef FT_BDF_H |
| 29 | #include FT_BDF_H | 29 | # include FT_BDF_H |
| 30 | #endif | 30 | #endif |
| 31 | 31 | ||
| 32 | #ifdef HAVE_HARFBUZZ | 32 | #ifdef HAVE_HARFBUZZ |
| @@ -35,9 +35,9 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 35 | #endif /* HAVE_HARFBUZZ */ | 35 | #endif /* HAVE_HARFBUZZ */ |
| 36 | 36 | ||
| 37 | #ifdef HAVE_LIBOTF | 37 | #ifdef HAVE_LIBOTF |
| 38 | #include <otf.h> | 38 | # include <otf.h> |
| 39 | #ifdef HAVE_M17N_FLT | 39 | #ifdef HAVE_M17N_FLT |
| 40 | #include <m17n-flt.h> | 40 | # include <m17n-flt.h> |
| 41 | #endif /* HAVE_M17N_FLT */ | 41 | #endif /* HAVE_M17N_FLT */ |
| 42 | #endif /* HAVE_LIBOTF */ | 42 | #endif /* HAVE_LIBOTF */ |
| 43 | 43 | ||
| @@ -46,6 +46,38 @@ extern Lisp_Object ftfont_open2 (struct frame *f, | |||
| 46 | Lisp_Object entity, | 46 | Lisp_Object entity, |
| 47 | int pixel_size, | 47 | int pixel_size, |
| 48 | Lisp_Object font_object); | 48 | Lisp_Object font_object); |
| 49 | extern size_t ftfont_info_size; | 49 | |
| 50 | /* This struct is shared by the XFT, Freetype, and Cairo font | ||
| 51 | backends. Members up to and including 'matrix' are common, the | ||
| 52 | rest depend on which backend is in use. */ | ||
| 53 | struct font_info | ||
| 54 | { | ||
| 55 | struct font font; | ||
| 56 | #ifdef HAVE_LIBOTF | ||
| 57 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ | ||
| 58 | OTF *otf; | ||
| 59 | #endif /* HAVE_LIBOTF */ | ||
| 60 | FT_Size ft_size; | ||
| 61 | int index; | ||
| 62 | FT_Matrix matrix; | ||
| 63 | #ifdef HAVE_HARFBUZZ | ||
| 64 | hb_font_t *hb_font; | ||
| 65 | #endif /* HAVE_HARFBUZZ */ | ||
| 66 | |||
| 67 | #ifdef USE_CAIRO | ||
| 68 | cairo_font_face_t *cr_font_face; | ||
| 69 | /* To prevent cairo from cluttering the activated FT_Size maintained | ||
| 70 | in ftfont.c, we activate this special FT_Size before drawing. */ | ||
| 71 | FT_Size ft_size_draw; | ||
| 72 | /* Font metrics cache. */ | ||
| 73 | struct font_metrics **metrics; | ||
| 74 | short metrics_nrows; | ||
| 75 | #else | ||
| 76 | /* These are used by the XFT backend. */ | ||
| 77 | Display *display; | ||
| 78 | XftFont *xftfont; | ||
| 79 | unsigned x_display_id; | ||
| 80 | #endif | ||
| 81 | }; | ||
| 50 | 82 | ||
| 51 | #endif /* EMACS_FTFONT_H */ | 83 | #endif /* EMACS_FTFONT_H */ |
diff --git a/src/xftfont.c b/src/xftfont.c index 6f56c053bb7..6531929e0d1 100644 --- a/src/xftfont.c +++ b/src/xftfont.c | |||
| @@ -35,30 +35,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 35 | 35 | ||
| 36 | /* Xft font driver. */ | 36 | /* Xft font driver. */ |
| 37 | 37 | ||
| 38 | |||
| 39 | /* The actual structure for Xft font that can be cast to struct | ||
| 40 | font. */ | ||
| 41 | |||
| 42 | struct xftfont_info | ||
| 43 | { | ||
| 44 | struct font font; | ||
| 45 | /* The following five members must be here in this order to be | ||
| 46 | compatible with struct ftfont_info (in ftfont.c). */ | ||
| 47 | #ifdef HAVE_LIBOTF | ||
| 48 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ | ||
| 49 | OTF *otf; | ||
| 50 | #endif /* HAVE_LIBOTF */ | ||
| 51 | #ifdef HAVE_HARFBUZZ | ||
| 52 | hb_font_t *hb_font; | ||
| 53 | #endif /* HAVE_HARFBUZZ */ | ||
| 54 | FT_Size ft_size; | ||
| 55 | int index; | ||
| 56 | FT_Matrix matrix; | ||
| 57 | Display *display; | ||
| 58 | XftFont *xftfont; | ||
| 59 | unsigned x_display_id; | ||
| 60 | }; | ||
| 61 | |||
| 62 | /* Structure pointed by (struct face *)->extra */ | 38 | /* Structure pointed by (struct face *)->extra */ |
| 63 | 39 | ||
| 64 | struct xftface_info | 40 | struct xftface_info |
| @@ -258,7 +234,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 258 | Display *display = FRAME_X_DISPLAY (f); | 234 | Display *display = FRAME_X_DISPLAY (f); |
| 259 | Lisp_Object val, filename, idx, font_object; | 235 | Lisp_Object val, filename, idx, font_object; |
| 260 | FcPattern *pat = NULL, *match; | 236 | FcPattern *pat = NULL, *match; |
| 261 | struct xftfont_info *xftfont_info = NULL; | 237 | struct font_info *xftfont_info = NULL; |
| 262 | struct font *font; | 238 | struct font *font; |
| 263 | double size = 0; | 239 | double size = 0; |
| 264 | XftFont *xftfont = NULL; | 240 | XftFont *xftfont = NULL; |
| @@ -333,7 +309,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 333 | 309 | ||
| 334 | /* We should not destroy PAT here because it is kept in XFTFONT and | 310 | /* We should not destroy PAT here because it is kept in XFTFONT and |
| 335 | destroyed automatically when XFTFONT is closed. */ | 311 | destroyed automatically when XFTFONT is closed. */ |
| 336 | font_object = font_build_object (VECSIZE (struct xftfont_info), | 312 | font_object = font_build_object (VECSIZE (struct font_info), |
| 337 | Qxft, entity, size); | 313 | Qxft, entity, size); |
| 338 | ASET (font_object, FONT_FILE_INDEX, filename); | 314 | ASET (font_object, FONT_FILE_INDEX, filename); |
| 339 | font = XFONT_OBJECT (font_object); | 315 | font = XFONT_OBJECT (font_object); |
| @@ -341,7 +317,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 341 | font->driver = &xftfont_driver; | 317 | font->driver = &xftfont_driver; |
| 342 | font->encoding_charset = font->repertory_charset = -1; | 318 | font->encoding_charset = font->repertory_charset = -1; |
| 343 | 319 | ||
| 344 | xftfont_info = (struct xftfont_info *) font; | 320 | xftfont_info = (struct font_info *) font; |
| 345 | xftfont_info->display = display; | 321 | xftfont_info->display = display; |
| 346 | xftfont_info->xftfont = xftfont; | 322 | xftfont_info->xftfont = xftfont; |
| 347 | xftfont_info->x_display_id = FRAME_DISPLAY_INFO (f)->x_id; | 323 | xftfont_info->x_display_id = FRAME_DISPLAY_INFO (f)->x_id; |
| @@ -466,7 +442,7 @@ static void | |||
| 466 | xftfont_close (struct font *font) | 442 | xftfont_close (struct font *font) |
| 467 | { | 443 | { |
| 468 | struct x_display_info *xdi; | 444 | struct x_display_info *xdi; |
| 469 | struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | 445 | struct font_info *xftfont_info = (struct font_info *) font; |
| 470 | 446 | ||
| 471 | #ifdef HAVE_LIBOTF | 447 | #ifdef HAVE_LIBOTF |
| 472 | if (xftfont_info->otf) | 448 | if (xftfont_info->otf) |
| @@ -539,7 +515,7 @@ xftfont_done_face (struct frame *f, struct face *face) | |||
| 539 | static int | 515 | static int |
| 540 | xftfont_has_char (Lisp_Object font, int c) | 516 | xftfont_has_char (Lisp_Object font, int c) |
| 541 | { | 517 | { |
| 542 | struct xftfont_info *xftfont_info; | 518 | struct font_info *xftfont_info; |
| 543 | struct charset *cs = NULL; | 519 | struct charset *cs = NULL; |
| 544 | 520 | ||
| 545 | if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qja) | 521 | if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qja) |
| @@ -553,7 +529,7 @@ xftfont_has_char (Lisp_Object font, int c) | |||
| 553 | 529 | ||
| 554 | if (FONT_ENTITY_P (font)) | 530 | if (FONT_ENTITY_P (font)) |
| 555 | return ftfont_has_char (font, c); | 531 | return ftfont_has_char (font, c); |
| 556 | xftfont_info = (struct xftfont_info *) XFONT_OBJECT (font); | 532 | xftfont_info = (struct font_info *) XFONT_OBJECT (font); |
| 557 | return (XftCharExists (xftfont_info->display, xftfont_info->xftfont, | 533 | return (XftCharExists (xftfont_info->display, xftfont_info->xftfont, |
| 558 | (FcChar32) c) == FcTrue); | 534 | (FcChar32) c) == FcTrue); |
| 559 | } | 535 | } |
| @@ -561,7 +537,7 @@ xftfont_has_char (Lisp_Object font, int c) | |||
| 561 | static unsigned | 537 | static unsigned |
| 562 | xftfont_encode_char (struct font *font, int c) | 538 | xftfont_encode_char (struct font *font, int c) |
| 563 | { | 539 | { |
| 564 | struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | 540 | struct font_info *xftfont_info = (struct font_info *) font; |
| 565 | unsigned code = XftCharIndex (xftfont_info->display, xftfont_info->xftfont, | 541 | unsigned code = XftCharIndex (xftfont_info->display, xftfont_info->xftfont, |
| 566 | (FcChar32) c); | 542 | (FcChar32) c); |
| 567 | 543 | ||
| @@ -572,7 +548,7 @@ static void | |||
| 572 | xftfont_text_extents (struct font *font, unsigned int *code, | 548 | xftfont_text_extents (struct font *font, unsigned int *code, |
| 573 | int nglyphs, struct font_metrics *metrics) | 549 | int nglyphs, struct font_metrics *metrics) |
| 574 | { | 550 | { |
| 575 | struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | 551 | struct font_info *xftfont_info = (struct font_info *) font; |
| 576 | XGlyphInfo extents; | 552 | XGlyphInfo extents; |
| 577 | 553 | ||
| 578 | block_input (); | 554 | block_input (); |
| @@ -614,7 +590,7 @@ xftfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 614 | 590 | ||
| 615 | struct frame *f = s->f; | 591 | struct frame *f = s->f; |
| 616 | struct face *face = s->face; | 592 | struct face *face = s->face; |
| 617 | struct xftfont_info *xftfont_info = (struct xftfont_info *) s->font; | 593 | struct font_info *xftfont_info = (struct font_info *) s->font; |
| 618 | struct xftface_info *xftface_info = NULL; | 594 | struct xftface_info *xftface_info = NULL; |
| 619 | XftDraw *xft_draw = xftfont_get_xft_draw (f); | 595 | XftDraw *xft_draw = xftfont_get_xft_draw (f); |
| 620 | FT_UInt *code; | 596 | FT_UInt *code; |
| @@ -677,7 +653,7 @@ static Lisp_Object | |||
| 677 | xftfont_shape (Lisp_Object lgstring, Lisp_Object direction) | 653 | xftfont_shape (Lisp_Object lgstring, Lisp_Object direction) |
| 678 | { | 654 | { |
| 679 | struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); | 655 | struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); |
| 680 | struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | 656 | struct font_info *xftfont_info = (struct font_info *) font; |
| 681 | FT_Face ft_face = XftLockFace (xftfont_info->xftfont); | 657 | FT_Face ft_face = XftLockFace (xftfont_info->xftfont); |
| 682 | xftfont_info->ft_size = ft_face->size; | 658 | xftfont_info->ft_size = ft_face->size; |
| 683 | Lisp_Object val = ftfont_shape (lgstring, direction); | 659 | Lisp_Object val = ftfont_shape (lgstring, direction); |
| @@ -721,7 +697,7 @@ static bool | |||
| 721 | xftfont_cached_font_ok (struct frame *f, Lisp_Object font_object, | 697 | xftfont_cached_font_ok (struct frame *f, Lisp_Object font_object, |
| 722 | Lisp_Object entity) | 698 | Lisp_Object entity) |
| 723 | { | 699 | { |
| 724 | struct xftfont_info *info = (struct xftfont_info *) XFONT_OBJECT (font_object); | 700 | struct font_info *info = (struct font_info *) XFONT_OBJECT (font_object); |
| 725 | FcPattern *oldpat = info->xftfont->pattern; | 701 | FcPattern *oldpat = info->xftfont->pattern; |
| 726 | Display *display = FRAME_X_DISPLAY (f); | 702 | Display *display = FRAME_X_DISPLAY (f); |
| 727 | FcPattern *pat = FcPatternCreate (); | 703 | FcPattern *pat = FcPatternCreate (); |