summaryrefslogtreecommitdiff
path: root/src/ftfont.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-12-01 21:47:12 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2016-12-01 21:48:30 -0800
commitebb96114d88af64cbb72f42052cb359ba8010aa2 (patch)
tree88795f2e9bc74b5c1a96c04c8cfe069b7d5f601f /src/ftfont.c
parentdd4b913153a818dbd42cb395d2c36f216e09a8ec (diff)
downloademacs-ebb96114d88af64cbb72f42052cb359ba8010aa2.tar.gz
emacs-ebb96114d88af64cbb72f42052cb359ba8010aa2.tar.bz2
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/ftfont.c')
-rw-r--r--src/ftfont.c144
1 files changed, 45 insertions, 99 deletions
diff --git a/src/ftfont.c b/src/ftfont.c
index 17fe66828fa..768b524f0a6 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -35,6 +35,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "font.h"
#include "ftfont.h"
+static struct font_driver const ftfont_driver;
+
/* Flag to tell if FcInit is already called or not. */
static bool fc_initialized;
@@ -73,17 +75,9 @@ enum ftfont_cache_for
FTFONT_CACHE_FOR_ENTITY
};
-static Lisp_Object ftfont_pattern_entity (FcPattern *, Lisp_Object);
-
-static Lisp_Object ftfont_resolve_generic_family (Lisp_Object,
- FcPattern *);
static Lisp_Object ftfont_lookup_cache (Lisp_Object,
enum ftfont_cache_for);
-static void ftfont_filter_properties (Lisp_Object font, Lisp_Object alist);
-
-static Lisp_Object ftfont_combining_capability (struct font *);
-
#define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM))
static struct
@@ -480,83 +474,7 @@ ftfont_get_otf (struct ftfont_info *ftfont_info)
}
#endif /* HAVE_LIBOTF */
-static Lisp_Object ftfont_get_cache (struct frame *);
-static Lisp_Object ftfont_list (struct frame *, Lisp_Object);
-static Lisp_Object ftfont_match (struct frame *, Lisp_Object);
-static Lisp_Object ftfont_list_family (struct frame *);
-static Lisp_Object ftfont_open (struct frame *, Lisp_Object, int);
-static void ftfont_close (struct font *);
-static int ftfont_has_char (Lisp_Object, int);
-static unsigned ftfont_encode_char (struct font *, int);
-static void ftfont_text_extents (struct font *, unsigned *, int,
- struct font_metrics *);
-static int ftfont_get_bitmap (struct font *, unsigned,
- struct font_bitmap *, int);
-static int ftfont_anchor_point (struct font *, unsigned, int,
- int *, int *);
-#ifdef HAVE_LIBOTF
-static Lisp_Object ftfont_otf_capability (struct font *);
-# ifdef HAVE_M17N_FLT
-static Lisp_Object ftfont_shape (Lisp_Object);
-# endif
-#endif
-
-#ifdef HAVE_OTF_GET_VARIATION_GLYPHS
-static int ftfont_variation_glyphs (struct font *, int c,
- unsigned variations[256]);
-#endif /* HAVE_OTF_GET_VARIATION_GLYPHS */
-
-struct font_driver ftfont_driver =
- {
- LISPSYM_INITIALLY (Qfreetype),
- 0, /* case insensitive */
- ftfont_get_cache,
- ftfont_list,
- ftfont_match,
- ftfont_list_family,
- NULL, /* free_entity */
- ftfont_open,
- ftfont_close,
- /* We can't draw a text without device dependent functions. */
- NULL, /* prepare_face */
- NULL, /* done_face */
- ftfont_has_char,
- ftfont_encode_char,
- ftfont_text_extents,
- /* We can't draw a text without device dependent functions. */
- NULL, /* draw */
- ftfont_get_bitmap,
- NULL, /* free_bitmap */
- ftfont_anchor_point,
-#ifdef HAVE_LIBOTF
- ftfont_otf_capability,
-#else /* not HAVE_LIBOTF */
- NULL,
-#endif /* not HAVE_LIBOTF */
- NULL, /* otf_drive */
- NULL, /* start_for_frame */
- NULL, /* end_for_frame */
-#if defined (HAVE_M17N_FLT) && defined (HAVE_LIBOTF)
- ftfont_shape,
-#else /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */
- NULL,
-#endif /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */
- NULL, /* check */
-
-#ifdef HAVE_OTF_GET_VARIATION_GLYPHS
- ftfont_variation_glyphs,
-#else
- NULL,
-#endif
-
- ftfont_filter_properties, /* filter_properties */
-
- NULL, /* cached_font_ok */
-
- ftfont_combining_capability,
- };
-
-static Lisp_Object
+Lisp_Object
ftfont_get_cache (struct frame *f)
{
return freetype_font_cache;
@@ -873,7 +791,7 @@ ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **ots
return pattern;
}
-static Lisp_Object
+Lisp_Object
ftfont_list (struct frame *f, Lisp_Object spec)
{
Lisp_Object val = Qnil, family, adstyle;
@@ -1072,7 +990,7 @@ ftfont_list (struct frame *f, Lisp_Object spec)
return val;
}
-static Lisp_Object
+Lisp_Object
ftfont_match (struct frame *f, Lisp_Object spec)
{
Lisp_Object entity = Qnil;
@@ -1122,7 +1040,7 @@ ftfont_match (struct frame *f, Lisp_Object spec)
return entity;
}
-static Lisp_Object
+Lisp_Object
ftfont_list_family (struct frame *f)
{
Lisp_Object list = Qnil;
@@ -1301,7 +1219,7 @@ ftfont_open2 (struct frame *f,
return font_object;
}
-static Lisp_Object
+Lisp_Object
ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
{
Lisp_Object font_object;
@@ -1314,7 +1232,7 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
return ftfont_open2 (f, entity, pixel_size, font_object);
}
-static void
+void
ftfont_close (struct font *font)
{
/* FIXME: Although this function can be called while garbage-collecting,
@@ -1344,7 +1262,7 @@ ftfont_close (struct font *font)
FT_Done_Size (ftfont_info->ft_size);
}
-static int
+int
ftfont_has_char (Lisp_Object font, int c)
{
struct charset *cs = NULL;
@@ -1374,7 +1292,7 @@ ftfont_has_char (Lisp_Object font, int c)
}
}
-static unsigned
+unsigned
ftfont_encode_char (struct font *font, int c)
{
struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
@@ -1385,7 +1303,7 @@ ftfont_encode_char (struct font *font, int c)
return (code > 0 ? code : FONT_INVALID_CODE);
}
-static void
+void
ftfont_text_extents (struct font *font, unsigned int *code,
int nglyphs, struct font_metrics *metrics)
{
@@ -1429,7 +1347,7 @@ ftfont_text_extents (struct font *font, unsigned int *code,
metrics->width = width;
}
-static int
+int
ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bitmap, int bits_per_pixel)
{
struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
@@ -1472,7 +1390,7 @@ ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bit
return 0;
}
-static int
+int
ftfont_anchor_point (struct font *font, unsigned int code, int idx,
int *x, int *y)
{
@@ -1538,7 +1456,7 @@ ftfont_otf_features (OTF_GSUB_GPOS *gsub_gpos)
}
-static Lisp_Object
+Lisp_Object
ftfont_otf_capability (struct font *font)
{
struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
@@ -2701,7 +2619,7 @@ ftfont_shape (Lisp_Object lgstring)
#ifdef HAVE_OTF_GET_VARIATION_GLYPHS
-static int
+int
ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256])
{
struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
@@ -2759,14 +2677,14 @@ static const char *const ftfont_non_booleans [] = {
NULL,
};
-static void
+void
ftfont_filter_properties (Lisp_Object font, Lisp_Object alist)
{
font_filter_properties (font, alist, ftfont_booleans, ftfont_non_booleans);
}
-static Lisp_Object
+Lisp_Object
ftfont_combining_capability (struct font *font)
{
#ifdef HAVE_M17N_FLT
@@ -2776,6 +2694,34 @@ ftfont_combining_capability (struct font *font)
#endif
}
+static struct font_driver const ftfont_driver =
+ {
+ /* We can't draw a text without device dependent functions. */
+ type: LISPSYM_INITIALLY (Qfreetype),
+ get_cache: ftfont_get_cache,
+ list: ftfont_list,
+ match: ftfont_match,
+ list_family: ftfont_list_family,
+ open: ftfont_open,
+ close: ftfont_close,
+ has_char: ftfont_has_char,
+ encode_char: ftfont_encode_char,
+ text_extents: ftfont_text_extents,
+ get_bitmap: ftfont_get_bitmap,
+ anchor_point: ftfont_anchor_point,
+#ifdef HAVE_LIBOTF
+ otf_capability: ftfont_otf_capability,
+#endif
+#if defined HAVE_M17N_FLT && defined HAVE_LIBOTF
+ shape: ftfont_shape,
+#endif
+#ifdef HAVE_OTF_GET_VARIATION_GLYPHS
+ get_variation_glyphs: ftfont_variation_glyphs,
+#endif
+ filter_properties: ftfont_filter_properties,
+ combining_capability: ftfont_combining_capability,
+ };
+
void
syms_of_ftfont (void)
{