aboutsummaryrefslogtreecommitdiffstats
path: root/src/ftfont.c
diff options
context:
space:
mode:
authorRobert Pluim2019-02-08 15:36:56 +0100
committerRobert Pluim2019-02-08 15:36:56 +0100
commit015a6e1df2772bd43680df5cbeaffccf98a881da (patch)
treebeb0f733dc04259d9fdf896ece841bce859b2c1e /src/ftfont.c
parent066a2b4914592478153983b587a36d226061dd89 (diff)
downloademacs-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/ftfont.c')
-rw-r--r--src/ftfont.c63
1 files changed, 26 insertions, 37 deletions
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. */
50static Lisp_Object ft_face_cache; 61static Lisp_Object ft_face_cache;
51 62
52/* The actual structure for FreeType font that can be cast to struct
53 font. */
54
55struct 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
72size_t ftfont_info_size = sizeof (struct ftfont_info);
73
74enum ftfont_cache_for 63enum 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
457static OTF * 446static OTF *
458ftfont_get_otf (struct ftfont_info *ftfont_info) 447ftfont_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
481static hb_font_t * 470static hb_font_t *
482ftfont_get_hb_font (struct ftfont_info *ftfont_info) 471ftfont_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)
1325unsigned 1314unsigned
1326ftfont_encode_char (struct font *font, int c) 1315ftfont_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
1355ftfont_text_extents (struct font *font, unsigned int *code, 1344ftfont_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,
1396int 1385int
1397ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bitmap, int bits_per_pixel) 1386ftfont_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
1440ftfont_anchor_point (struct font *font, unsigned int code, int idx, 1429ftfont_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)
1505Lisp_Object 1494Lisp_Object
1506ftfont_otf_capability (struct font *font) 1495ftfont_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,
2658int 2647int
2659ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256]) 2648ftfont_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
2946ftfont_shape (Lisp_Object lgstring, Lisp_Object direction) 2935ftfont_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 {