diff options
| author | Robert Pluim | 2019-01-26 12:31:02 +0100 |
|---|---|---|
| committer | Robert Pluim | 2019-02-08 09:05:11 +0100 |
| commit | 9e0d69b5a17a0fa3b0dd099a51584a85f3ddb5bf (patch) | |
| tree | b6dcbce3d3d4ff5a6719814d26a95747118b4f67 /src | |
| parent | 24905e92179c2ee8cd02c26b4a7058fbd238ece7 (diff) | |
| download | emacs-9e0d69b5a17a0fa3b0dd099a51584a85f3ddb5bf.tar.gz emacs-9e0d69b5a17a0fa3b0dd099a51584a85f3ddb5bf.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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ftcrfont.c | 43 | ||||
| -rw-r--r-- | src/ftfont.c | 59 | ||||
| -rw-r--r-- | src/ftfont.h | 37 | ||||
| -rw-r--r-- | src/xftfont.c | 45 |
4 files changed, 75 insertions, 109 deletions
diff --git a/src/ftcrfont.c b/src/ftcrfont.c index 7c18e04b743..3a98e78d63e 100644 --- a/src/ftcrfont.c +++ b/src/ftcrfont.c | |||
| @@ -28,34 +28,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 28 | #include "ftfont.h" | 28 | #include "ftfont.h" |
| 29 | #include "pdumper.h" | 29 | #include "pdumper.h" |
| 30 | 30 | ||
| 31 | /* FTCR font driver. */ | ||
| 32 | |||
| 33 | /* The actual structure for FTCR font. A pointer to this structure | ||
| 34 | can be cast to struct font *. */ | ||
| 35 | |||
| 36 | struct ftcrfont_info | ||
| 37 | { | ||
| 38 | struct font font; | ||
| 39 | /* The following members up to and including 'matrix' must be here | ||
| 40 | in this order to be compatible with struct ftfont_info (in | ||
| 41 | ftfont.c). */ | ||
| 42 | #ifdef HAVE_LIBOTF | ||
| 43 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ | ||
| 44 | OTF *otf; | ||
| 45 | #endif /* HAVE_LIBOTF */ | ||
| 46 | FT_Size ft_size; | ||
| 47 | int index; | ||
| 48 | FT_Matrix matrix; | ||
| 49 | |||
| 50 | cairo_font_face_t *cr_font_face; | ||
| 51 | /* To prevent cairo from cluttering the activated FT_Size maintained | ||
| 52 | in ftfont.c, we activate this special FT_Size before drawing. */ | ||
| 53 | FT_Size ft_size_draw; | ||
| 54 | /* Font metrics cache. */ | ||
| 55 | struct font_metrics **metrics; | ||
| 56 | short metrics_nrows; | ||
| 57 | }; | ||
| 58 | |||
| 59 | #define METRICS_NCOLS_PER_ROW (128) | 31 | #define METRICS_NCOLS_PER_ROW (128) |
| 60 | 32 | ||
| 61 | enum metrics_status | 33 | enum metrics_status |
| @@ -72,7 +44,7 @@ ftcrfont_glyph_extents (struct font *font, | |||
| 72 | unsigned glyph, | 44 | unsigned glyph, |
| 73 | struct font_metrics *metrics) | 45 | struct font_metrics *metrics) |
| 74 | { | 46 | { |
| 75 | struct ftcrfont_info *ftcrfont_info = (struct ftcrfont_info *) font; | 47 | struct font_info *ftcrfont_info = (struct font_info *) font; |
| 76 | int row, col; | 48 | int row, col; |
| 77 | struct font_metrics *cache; | 49 | struct font_metrics *cache; |
| 78 | 50 | ||
| @@ -134,7 +106,7 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 134 | { | 106 | { |
| 135 | Lisp_Object font_object; | 107 | Lisp_Object font_object; |
| 136 | struct font *font; | 108 | struct font *font; |
| 137 | struct ftcrfont_info *ftcrfont_info; | 109 | struct font_info *ftcrfont_info; |
| 138 | FT_Face ft_face; | 110 | FT_Face ft_face; |
| 139 | FT_UInt size; | 111 | FT_UInt size; |
| 140 | 112 | ||
| @@ -142,14 +114,14 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 142 | size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX)); | 114 | size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX)); |
| 143 | if (size == 0) | 115 | if (size == 0) |
| 144 | size = pixel_size; | 116 | size = pixel_size; |
| 145 | font_object = font_build_object (VECSIZE (struct ftcrfont_info), | 117 | font_object = font_build_object (VECSIZE (struct font_info), |
| 146 | Qftcr, entity, size); | 118 | Qftcr, entity, size); |
| 147 | font_object = ftfont_open2 (f, entity, pixel_size, font_object); | 119 | font_object = ftfont_open2 (f, entity, pixel_size, font_object); |
| 148 | if (NILP (font_object)) return Qnil; | 120 | if (NILP (font_object)) return Qnil; |
| 149 | 121 | ||
| 150 | font = XFONT_OBJECT (font_object); | 122 | font = XFONT_OBJECT (font_object); |
| 151 | font->driver = &ftcrfont_driver; | 123 | font->driver = &ftcrfont_driver; |
| 152 | ftcrfont_info = (struct ftcrfont_info *) font; | 124 | ftcrfont_info = (struct font_info *) font; |
| 153 | ft_face = ftcrfont_info->ft_size->face; | 125 | ft_face = ftcrfont_info->ft_size->face; |
| 154 | FT_New_Size (ft_face, &ftcrfont_info->ft_size_draw); | 126 | FT_New_Size (ft_face, &ftcrfont_info->ft_size_draw); |
| 155 | FT_Activate_Size (ftcrfont_info->ft_size_draw); | 127 | FT_Activate_Size (ftcrfont_info->ft_size_draw); |
| @@ -169,7 +141,7 @@ ftcrfont_close (struct font *font) | |||
| 169 | if (font_data_structures_may_be_ill_formed ()) | 141 | if (font_data_structures_may_be_ill_formed ()) |
| 170 | return; | 142 | return; |
| 171 | 143 | ||
| 172 | struct ftcrfont_info *ftcrfont_info = (struct ftcrfont_info *) font; | 144 | struct font_info *ftcrfont_info = (struct font_info *) font; |
| 173 | int i; | 145 | int i; |
| 174 | 146 | ||
| 175 | block_input (); | 147 | block_input (); |
| @@ -225,7 +197,7 @@ ftcrfont_draw (struct glyph_string *s, | |||
| 225 | { | 197 | { |
| 226 | struct frame *f = s->f; | 198 | struct frame *f = s->f; |
| 227 | struct face *face = s->face; | 199 | struct face *face = s->face; |
| 228 | struct ftcrfont_info *ftcrfont_info = (struct ftcrfont_info *) s->font; | 200 | struct font_info *ftcrfont_info = (struct font_info *) s->font; |
| 229 | cairo_t *cr; | 201 | cairo_t *cr; |
| 230 | cairo_glyph_t *glyphs; | 202 | cairo_glyph_t *glyphs; |
| 231 | cairo_surface_t *surface; | 203 | cairo_surface_t *surface; |
| @@ -316,9 +288,6 @@ struct font_driver const ftcrfont_driver = | |||
| 316 | void | 288 | void |
| 317 | syms_of_ftcrfont (void) | 289 | syms_of_ftcrfont (void) |
| 318 | { | 290 | { |
| 319 | if (ftfont_info_size != offsetof (struct ftcrfont_info, cr_font_face)) | ||
| 320 | abort (); | ||
| 321 | |||
| 322 | DEFSYM (Qftcr, "ftcr"); | 291 | DEFSYM (Qftcr, "ftcr"); |
| 323 | pdumper_do_now_and_after_load (syms_of_ftcrfont_for_pdumper); | 292 | pdumper_do_now_and_after_load (syms_of_ftcrfont_for_pdumper); |
| 324 | } | 293 | } |
diff --git a/src/ftfont.c b/src/ftfont.c index bcc3460cb74..3e820f583ff 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" |
| @@ -50,26 +61,6 @@ static Lisp_Object freetype_font_cache; | |||
| 50 | /* Cache for FT_Face and FcCharSet. */ | 61 | /* Cache for FT_Face and FcCharSet. */ |
| 51 | static Lisp_Object ft_face_cache; | 62 | static Lisp_Object ft_face_cache; |
| 52 | 63 | ||
| 53 | /* The actual structure for FreeType font that can be cast to struct | ||
| 54 | font. */ | ||
| 55 | |||
| 56 | struct ftfont_info | ||
| 57 | { | ||
| 58 | struct font font; | ||
| 59 | #ifdef HAVE_LIBOTF | ||
| 60 | /* The following members up to and including 'matrix' must be here in | ||
| 61 | this order to be compatible with struct xftfont_info (in | ||
| 62 | xftfont.c). */ | ||
| 63 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ | ||
| 64 | OTF *otf; | ||
| 65 | #endif /* HAVE_LIBOTF */ | ||
| 66 | FT_Size ft_size; | ||
| 67 | int index; | ||
| 68 | FT_Matrix matrix; | ||
| 69 | }; | ||
| 70 | |||
| 71 | size_t ftfont_info_size = sizeof (struct ftfont_info); | ||
| 72 | |||
| 73 | enum ftfont_cache_for | 64 | enum ftfont_cache_for |
| 74 | { | 65 | { |
| 75 | FTFONT_CACHE_FOR_FACE, | 66 | FTFONT_CACHE_FOR_FACE, |
| @@ -454,7 +445,7 @@ ftfont_get_fc_charset (Lisp_Object entity) | |||
| 454 | 445 | ||
| 455 | #ifdef HAVE_LIBOTF | 446 | #ifdef HAVE_LIBOTF |
| 456 | static OTF * | 447 | static OTF * |
| 457 | ftfont_get_otf (struct ftfont_info *ftfont_info) | 448 | ftfont_get_otf (struct font_info *ftfont_info) |
| 458 | { | 449 | { |
| 459 | OTF *otf; | 450 | OTF *otf; |
| 460 | 451 | ||
| @@ -1095,7 +1086,7 @@ ftfont_open2 (struct frame *f, | |||
| 1095 | int pixel_size, | 1086 | int pixel_size, |
| 1096 | Lisp_Object font_object) | 1087 | Lisp_Object font_object) |
| 1097 | { | 1088 | { |
| 1098 | struct ftfont_info *ftfont_info; | 1089 | struct font_info *ftfont_info; |
| 1099 | struct font *font; | 1090 | struct font *font; |
| 1100 | struct ftfont_cache_data *cache_data; | 1091 | struct ftfont_cache_data *cache_data; |
| 1101 | FT_Face ft_face; | 1092 | FT_Face ft_face; |
| @@ -1146,7 +1137,7 @@ ftfont_open2 (struct frame *f, | |||
| 1146 | 1137 | ||
| 1147 | ASET (font_object, FONT_FILE_INDEX, filename); | 1138 | ASET (font_object, FONT_FILE_INDEX, filename); |
| 1148 | font = XFONT_OBJECT (font_object); | 1139 | font = XFONT_OBJECT (font_object); |
| 1149 | ftfont_info = (struct ftfont_info *) font; | 1140 | ftfont_info = (struct font_info *) font; |
| 1150 | ftfont_info->ft_size = ft_face->size; | 1141 | ftfont_info->ft_size = ft_face->size; |
| 1151 | ftfont_info->index = XFIXNUM (idx); | 1142 | ftfont_info->index = XFIXNUM (idx); |
| 1152 | #ifdef HAVE_LIBOTF | 1143 | #ifdef HAVE_LIBOTF |
| @@ -1236,7 +1227,7 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 1236 | size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX)); | 1227 | size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX)); |
| 1237 | if (size == 0) | 1228 | if (size == 0) |
| 1238 | size = pixel_size; | 1229 | size = pixel_size; |
| 1239 | font_object = font_build_object (VECSIZE (struct ftfont_info), | 1230 | font_object = font_build_object (VECSIZE (struct font_info), |
| 1240 | Qfreetype, entity, size); | 1231 | Qfreetype, entity, size); |
| 1241 | return ftfont_open2 (f, entity, pixel_size, font_object); | 1232 | return ftfont_open2 (f, entity, pixel_size, font_object); |
| 1242 | } | 1233 | } |
| @@ -1247,7 +1238,7 @@ ftfont_close (struct font *font) | |||
| 1247 | if (font_data_structures_may_be_ill_formed ()) | 1238 | if (font_data_structures_may_be_ill_formed ()) |
| 1248 | return; | 1239 | return; |
| 1249 | 1240 | ||
| 1250 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1241 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1251 | Lisp_Object val, cache; | 1242 | Lisp_Object val, cache; |
| 1252 | 1243 | ||
| 1253 | val = Fcons (font->props[FONT_FILE_INDEX], make_fixnum (ftfont_info->index)); | 1244 | val = Fcons (font->props[FONT_FILE_INDEX], make_fixnum (ftfont_info->index)); |
| @@ -1291,9 +1282,9 @@ ftfont_has_char (Lisp_Object font, int c) | |||
| 1291 | } | 1282 | } |
| 1292 | else | 1283 | else |
| 1293 | { | 1284 | { |
| 1294 | struct ftfont_info *ftfont_info; | 1285 | struct font_info *ftfont_info; |
| 1295 | 1286 | ||
| 1296 | ftfont_info = (struct ftfont_info *) XFONT_OBJECT (font); | 1287 | ftfont_info = (struct font_info *) XFONT_OBJECT (font); |
| 1297 | return (FT_Get_Char_Index (ftfont_info->ft_size->face, (FT_ULong) c) | 1288 | return (FT_Get_Char_Index (ftfont_info->ft_size->face, (FT_ULong) c) |
| 1298 | != 0); | 1289 | != 0); |
| 1299 | } | 1290 | } |
| @@ -1302,7 +1293,7 @@ ftfont_has_char (Lisp_Object font, int c) | |||
| 1302 | unsigned | 1293 | unsigned |
| 1303 | ftfont_encode_char (struct font *font, int c) | 1294 | ftfont_encode_char (struct font *font, int c) |
| 1304 | { | 1295 | { |
| 1305 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1296 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1306 | FT_Face ft_face = ftfont_info->ft_size->face; | 1297 | FT_Face ft_face = ftfont_info->ft_size->face; |
| 1307 | FT_ULong charcode = c; | 1298 | FT_ULong charcode = c; |
| 1308 | FT_UInt code = FT_Get_Char_Index (ft_face, charcode); | 1299 | FT_UInt code = FT_Get_Char_Index (ft_face, charcode); |
| @@ -1314,7 +1305,7 @@ void | |||
| 1314 | ftfont_text_extents (struct font *font, unsigned int *code, | 1305 | ftfont_text_extents (struct font *font, unsigned int *code, |
| 1315 | int nglyphs, struct font_metrics *metrics) | 1306 | int nglyphs, struct font_metrics *metrics) |
| 1316 | { | 1307 | { |
| 1317 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1308 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1318 | FT_Face ft_face = ftfont_info->ft_size->face; | 1309 | FT_Face ft_face = ftfont_info->ft_size->face; |
| 1319 | int i, width = 0; | 1310 | int i, width = 0; |
| 1320 | bool first; | 1311 | bool first; |
| @@ -1357,7 +1348,7 @@ ftfont_text_extents (struct font *font, unsigned int *code, | |||
| 1357 | int | 1348 | int |
| 1358 | ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bitmap, int bits_per_pixel) | 1349 | ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bitmap, int bits_per_pixel) |
| 1359 | { | 1350 | { |
| 1360 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1351 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1361 | FT_Face ft_face = ftfont_info->ft_size->face; | 1352 | FT_Face ft_face = ftfont_info->ft_size->face; |
| 1362 | FT_Int32 load_flags = FT_LOAD_RENDER; | 1353 | FT_Int32 load_flags = FT_LOAD_RENDER; |
| 1363 | 1354 | ||
| @@ -1401,7 +1392,7 @@ int | |||
| 1401 | ftfont_anchor_point (struct font *font, unsigned int code, int idx, | 1392 | ftfont_anchor_point (struct font *font, unsigned int code, int idx, |
| 1402 | int *x, int *y) | 1393 | int *x, int *y) |
| 1403 | { | 1394 | { |
| 1404 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1395 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1405 | FT_Face ft_face = ftfont_info->ft_size->face; | 1396 | FT_Face ft_face = ftfont_info->ft_size->face; |
| 1406 | 1397 | ||
| 1407 | if (ftfont_info->ft_size != ft_face->size) | 1398 | if (ftfont_info->ft_size != ft_face->size) |
| @@ -1466,7 +1457,7 @@ ftfont_otf_features (OTF_GSUB_GPOS *gsub_gpos) | |||
| 1466 | Lisp_Object | 1457 | Lisp_Object |
| 1467 | ftfont_otf_capability (struct font *font) | 1458 | ftfont_otf_capability (struct font *font) |
| 1468 | { | 1459 | { |
| 1469 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 1460 | struct font_info *ftfont_info = (struct font_info *) font; |
| 1470 | OTF *otf = ftfont_get_otf (ftfont_info); | 1461 | OTF *otf = ftfont_get_otf (ftfont_info); |
| 1471 | Lisp_Object gsub_gpos; | 1462 | Lisp_Object gsub_gpos; |
| 1472 | 1463 | ||
| @@ -2616,7 +2607,7 @@ Lisp_Object | |||
| 2616 | ftfont_shape (Lisp_Object lgstring) | 2607 | ftfont_shape (Lisp_Object lgstring) |
| 2617 | { | 2608 | { |
| 2618 | struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); | 2609 | struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); |
| 2619 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 2610 | struct font_info *ftfont_info = (struct font_info *) font; |
| 2620 | OTF *otf = ftfont_get_otf (ftfont_info); | 2611 | OTF *otf = ftfont_get_otf (ftfont_info); |
| 2621 | 2612 | ||
| 2622 | return ftfont_shape_by_flt (lgstring, font, ftfont_info->ft_size->face, otf, | 2613 | return ftfont_shape_by_flt (lgstring, font, ftfont_info->ft_size->face, otf, |
| @@ -2630,7 +2621,7 @@ ftfont_shape (Lisp_Object lgstring) | |||
| 2630 | int | 2621 | int |
| 2631 | ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256]) | 2622 | ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256]) |
| 2632 | { | 2623 | { |
| 2633 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | 2624 | struct font_info *ftfont_info = (struct font_info *) font; |
| 2634 | OTF *otf = ftfont_get_otf (ftfont_info); | 2625 | OTF *otf = ftfont_get_otf (ftfont_info); |
| 2635 | 2626 | ||
| 2636 | if (! otf) | 2627 | if (! otf) |
diff --git a/src/ftfont.h b/src/ftfont.h index 4201b2c2d67..b6b0c5ba47b 100644 --- a/src/ftfont.h +++ b/src/ftfont.h | |||
| @@ -26,13 +26,13 @@ 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_LIBOTF | 32 | #ifdef HAVE_LIBOTF |
| 33 | #include <otf.h> | 33 | # include <otf.h> |
| 34 | #ifdef HAVE_M17N_FLT | 34 | #ifdef HAVE_M17N_FLT |
| 35 | #include <m17n-flt.h> | 35 | # include <m17n-flt.h> |
| 36 | #endif /* HAVE_M17N_FLT */ | 36 | #endif /* HAVE_M17N_FLT */ |
| 37 | #endif /* HAVE_LIBOTF */ | 37 | #endif /* HAVE_LIBOTF */ |
| 38 | 38 | ||
| @@ -41,6 +41,35 @@ extern Lisp_Object ftfont_open2 (struct frame *f, | |||
| 41 | Lisp_Object entity, | 41 | Lisp_Object entity, |
| 42 | int pixel_size, | 42 | int pixel_size, |
| 43 | Lisp_Object font_object); | 43 | Lisp_Object font_object); |
| 44 | extern size_t ftfont_info_size; | 44 | |
| 45 | /* This struct is shared by the XFT, Freetype, and Cairo font | ||
| 46 | backends. Members up to and including 'matrix' are common, the | ||
| 47 | rest depend on which backend is in use. */ | ||
| 48 | struct font_info | ||
| 49 | { | ||
| 50 | struct font font; | ||
| 51 | #ifdef HAVE_LIBOTF | ||
| 52 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ | ||
| 53 | OTF *otf; | ||
| 54 | #endif /* HAVE_LIBOTF */ | ||
| 55 | FT_Size ft_size; | ||
| 56 | int index; | ||
| 57 | FT_Matrix matrix; | ||
| 58 | |||
| 59 | #ifdef USE_CAIRO | ||
| 60 | cairo_font_face_t *cr_font_face; | ||
| 61 | /* To prevent cairo from cluttering the activated FT_Size maintained | ||
| 62 | in ftfont.c, we activate this special FT_Size before drawing. */ | ||
| 63 | FT_Size ft_size_draw; | ||
| 64 | /* Font metrics cache. */ | ||
| 65 | struct font_metrics **metrics; | ||
| 66 | short metrics_nrows; | ||
| 67 | #else | ||
| 68 | /* These are used by the XFT backend. */ | ||
| 69 | Display *display; | ||
| 70 | XftFont *xftfont; | ||
| 71 | unsigned x_display_id; | ||
| 72 | #endif | ||
| 73 | }; | ||
| 45 | 74 | ||
| 46 | #endif /* EMACS_FTFONT_H */ | 75 | #endif /* EMACS_FTFONT_H */ |
diff --git a/src/xftfont.c b/src/xftfont.c index ea8572f4242..8a4516f7f91 100644 --- a/src/xftfont.c +++ b/src/xftfont.c | |||
| @@ -36,29 +36,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 36 | 36 | ||
| 37 | /* Xft font driver. */ | 37 | /* Xft font driver. */ |
| 38 | 38 | ||
| 39 | |||
| 40 | /* The actual structure for Xft font that can be cast to struct | ||
| 41 | font. */ | ||
| 42 | |||
| 43 | struct xftfont_info | ||
| 44 | { | ||
| 45 | struct font font; | ||
| 46 | /* The following members up to and including 'matrix' must be here | ||
| 47 | in this order to be compatible with struct ftfont_info (in | ||
| 48 | ftfont.c). */ | ||
| 49 | #ifdef HAVE_LIBOTF | ||
| 50 | bool maybe_otf; /* Flag to tell if this may be OTF or not. */ | ||
| 51 | OTF *otf; | ||
| 52 | #endif /* HAVE_LIBOTF */ | ||
| 53 | FT_Size ft_size; | ||
| 54 | int index; | ||
| 55 | FT_Matrix matrix; | ||
| 56 | |||
| 57 | Display *display; | ||
| 58 | XftFont *xftfont; | ||
| 59 | unsigned x_display_id; | ||
| 60 | }; | ||
| 61 | |||
| 62 | /* Structure pointed by (struct face *)->extra */ | 39 | /* Structure pointed by (struct face *)->extra */ |
| 63 | 40 | ||
| 64 | struct xftface_info | 41 | struct xftface_info |
| @@ -258,7 +235,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 258 | Display *display = FRAME_X_DISPLAY (f); | 235 | Display *display = FRAME_X_DISPLAY (f); |
| 259 | Lisp_Object val, filename, idx, font_object; | 236 | Lisp_Object val, filename, idx, font_object; |
| 260 | FcPattern *pat = NULL, *match; | 237 | FcPattern *pat = NULL, *match; |
| 261 | struct xftfont_info *xftfont_info = NULL; | 238 | struct font_info *xftfont_info = NULL; |
| 262 | struct font *font; | 239 | struct font *font; |
| 263 | double size = 0; | 240 | double size = 0; |
| 264 | XftFont *xftfont = NULL; | 241 | XftFont *xftfont = NULL; |
| @@ -333,7 +310,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 333 | 310 | ||
| 334 | /* We should not destroy PAT here because it is kept in XFTFONT and | 311 | /* We should not destroy PAT here because it is kept in XFTFONT and |
| 335 | destroyed automatically when XFTFONT is closed. */ | 312 | destroyed automatically when XFTFONT is closed. */ |
| 336 | font_object = font_build_object (VECSIZE (struct xftfont_info), | 313 | font_object = font_build_object (VECSIZE (struct font_info), |
| 337 | Qxft, entity, size); | 314 | Qxft, entity, size); |
| 338 | ASET (font_object, FONT_FILE_INDEX, filename); | 315 | ASET (font_object, FONT_FILE_INDEX, filename); |
| 339 | font = XFONT_OBJECT (font_object); | 316 | font = XFONT_OBJECT (font_object); |
| @@ -341,7 +318,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 341 | font->driver = &xftfont_driver; | 318 | font->driver = &xftfont_driver; |
| 342 | font->encoding_charset = font->repertory_charset = -1; | 319 | font->encoding_charset = font->repertory_charset = -1; |
| 343 | 320 | ||
| 344 | xftfont_info = (struct xftfont_info *) font; | 321 | xftfont_info = (struct font_info *) font; |
| 345 | xftfont_info->display = display; | 322 | xftfont_info->display = display; |
| 346 | xftfont_info->xftfont = xftfont; | 323 | xftfont_info->xftfont = xftfont; |
| 347 | xftfont_info->x_display_id = FRAME_DISPLAY_INFO (f)->x_id; | 324 | xftfont_info->x_display_id = FRAME_DISPLAY_INFO (f)->x_id; |
| @@ -463,7 +440,7 @@ static void | |||
| 463 | xftfont_close (struct font *font) | 440 | xftfont_close (struct font *font) |
| 464 | { | 441 | { |
| 465 | struct x_display_info *xdi; | 442 | struct x_display_info *xdi; |
| 466 | struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | 443 | struct font_info *xftfont_info = (struct font_info *) font; |
| 467 | 444 | ||
| 468 | #ifdef HAVE_LIBOTF | 445 | #ifdef HAVE_LIBOTF |
| 469 | if (xftfont_info->otf) | 446 | if (xftfont_info->otf) |
| @@ -529,7 +506,7 @@ xftfont_done_face (struct frame *f, struct face *face) | |||
| 529 | static int | 506 | static int |
| 530 | xftfont_has_char (Lisp_Object font, int c) | 507 | xftfont_has_char (Lisp_Object font, int c) |
| 531 | { | 508 | { |
| 532 | struct xftfont_info *xftfont_info; | 509 | struct font_info *xftfont_info; |
| 533 | struct charset *cs = NULL; | 510 | struct charset *cs = NULL; |
| 534 | 511 | ||
| 535 | if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qja) | 512 | if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qja) |
| @@ -543,7 +520,7 @@ xftfont_has_char (Lisp_Object font, int c) | |||
| 543 | 520 | ||
| 544 | if (FONT_ENTITY_P (font)) | 521 | if (FONT_ENTITY_P (font)) |
| 545 | return ftfont_has_char (font, c); | 522 | return ftfont_has_char (font, c); |
| 546 | xftfont_info = (struct xftfont_info *) XFONT_OBJECT (font); | 523 | xftfont_info = (struct font_info *) XFONT_OBJECT (font); |
| 547 | return (XftCharExists (xftfont_info->display, xftfont_info->xftfont, | 524 | return (XftCharExists (xftfont_info->display, xftfont_info->xftfont, |
| 548 | (FcChar32) c) == FcTrue); | 525 | (FcChar32) c) == FcTrue); |
| 549 | } | 526 | } |
| @@ -551,7 +528,7 @@ xftfont_has_char (Lisp_Object font, int c) | |||
| 551 | static unsigned | 528 | static unsigned |
| 552 | xftfont_encode_char (struct font *font, int c) | 529 | xftfont_encode_char (struct font *font, int c) |
| 553 | { | 530 | { |
| 554 | struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | 531 | struct font_info *xftfont_info = (struct font_info *) font; |
| 555 | unsigned code = XftCharIndex (xftfont_info->display, xftfont_info->xftfont, | 532 | unsigned code = XftCharIndex (xftfont_info->display, xftfont_info->xftfont, |
| 556 | (FcChar32) c); | 533 | (FcChar32) c); |
| 557 | 534 | ||
| @@ -562,7 +539,7 @@ static void | |||
| 562 | xftfont_text_extents (struct font *font, unsigned int *code, | 539 | xftfont_text_extents (struct font *font, unsigned int *code, |
| 563 | int nglyphs, struct font_metrics *metrics) | 540 | int nglyphs, struct font_metrics *metrics) |
| 564 | { | 541 | { |
| 565 | struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | 542 | struct font_info *xftfont_info = (struct font_info *) font; |
| 566 | XGlyphInfo extents; | 543 | XGlyphInfo extents; |
| 567 | 544 | ||
| 568 | block_input (); | 545 | block_input (); |
| @@ -604,7 +581,7 @@ xftfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 604 | 581 | ||
| 605 | struct frame *f = s->f; | 582 | struct frame *f = s->f; |
| 606 | struct face *face = s->face; | 583 | struct face *face = s->face; |
| 607 | struct xftfont_info *xftfont_info = (struct xftfont_info *) s->font; | 584 | struct font_info *xftfont_info = (struct font_info *) s->font; |
| 608 | struct xftface_info *xftface_info = NULL; | 585 | struct xftface_info *xftface_info = NULL; |
| 609 | XftDraw *xft_draw = xftfont_get_xft_draw (f); | 586 | XftDraw *xft_draw = xftfont_get_xft_draw (f); |
| 610 | FT_UInt *code; | 587 | FT_UInt *code; |
| @@ -667,7 +644,7 @@ static Lisp_Object | |||
| 667 | xftfont_shape (Lisp_Object lgstring) | 644 | xftfont_shape (Lisp_Object lgstring) |
| 668 | { | 645 | { |
| 669 | struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); | 646 | struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); |
| 670 | struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | 647 | struct font_info *xftfont_info = (struct font_info *) font; |
| 671 | FT_Face ft_face = XftLockFace (xftfont_info->xftfont); | 648 | FT_Face ft_face = XftLockFace (xftfont_info->xftfont); |
| 672 | xftfont_info->ft_size = ft_face->size; | 649 | xftfont_info->ft_size = ft_face->size; |
| 673 | Lisp_Object val = ftfont_shape (lgstring); | 650 | Lisp_Object val = ftfont_shape (lgstring); |
| @@ -711,7 +688,7 @@ static bool | |||
| 711 | xftfont_cached_font_ok (struct frame *f, Lisp_Object font_object, | 688 | xftfont_cached_font_ok (struct frame *f, Lisp_Object font_object, |
| 712 | Lisp_Object entity) | 689 | Lisp_Object entity) |
| 713 | { | 690 | { |
| 714 | struct xftfont_info *info = (struct xftfont_info *) XFONT_OBJECT (font_object); | 691 | struct font_info *info = (struct font_info *) XFONT_OBJECT (font_object); |
| 715 | FcPattern *oldpat = info->xftfont->pattern; | 692 | FcPattern *oldpat = info->xftfont->pattern; |
| 716 | Display *display = FRAME_X_DISPLAY (f); | 693 | Display *display = FRAME_X_DISPLAY (f); |
| 717 | FcPattern *pat = FcPatternCreate (); | 694 | FcPattern *pat = FcPatternCreate (); |