Commit 96f17a2f authored by Dmitry Antipov's avatar Dmitry Antipov

* font.c (font_build_object) [HAVE_XFT || HAVE_FREETYPE || HAVE_NS]:

New function, with an intention to avoid code duplication between
a few font drivers.
* font.h (font_build_object) [HAVE_XFT || HAVE_FREETYPE || HAVE_NS]:
Add prototype.
* ftfont.c (ftfont_open):
* macfont.m (macfont_open):
* xftfont.c (xftfont_open): Use it.
parent d64a4984
......@@ -5,7 +5,16 @@
Avoid Faref and assume that args are always valid. This helps to
speedup search, which is especially important for a huge buffers.
* lisp.h (char_table_translate): Remove prototype.
* nsfont.m (nsfont_close): Free glyphs and metrics arrays as well.
* font.c (font_build_object) [HAVE_XFT || HAVE_FREETYPE || HAVE_NS]:
New function, with an intention to avoid code duplication between
a few font drivers.
* font.h (font_build_object) [HAVE_XFT || HAVE_FREETYPE || HAVE_NS]:
Add prototype.
* ftfont.c (ftfont_open):
* macfont.m (macfont_open):
* xftfont.c (xftfont_open): Use it.
2014-07-08 Paul Eggert <eggert@cs.ucla.edu>
......
......@@ -225,7 +225,33 @@ font_make_object (int size, Lisp_Object entity, int pixelsize)
return font_object;
}
#if defined (HAVE_XFT) || defined (HAVE_FREETYPE) || defined (HAVE_NS)
/* Like above, but also set `type', `name' and `fullname' properties
of font-object. */
Lisp_Object
font_build_object (int vectorsize, Lisp_Object type,
Lisp_Object entity, double pixelsize)
{
int len;
char name[256];
Lisp_Object font_object = font_make_object (vectorsize, entity, pixelsize);
ASET (font_object, FONT_TYPE_INDEX, type);
len = font_unparse_xlfd (entity, pixelsize, name, sizeof name);
if (len > 0)
ASET (font_object, FONT_NAME_INDEX, make_string (name, len));
len = font_unparse_fcname (entity, pixelsize, name, sizeof name);
if (len > 0)
ASET (font_object, FONT_FULLNAME_INDEX, make_string (name, len));
else
ASET (font_object, FONT_FULLNAME_INDEX,
AREF (font_object, FONT_NAME_INDEX));
return font_object;
}
#endif /* HAVE_XFT || HAVE_FREETYPE || HAVE_NS */
static int font_pixel_size (struct frame *f, Lisp_Object);
static Lisp_Object font_open_entity (struct frame *, Lisp_Object, int);
......
......@@ -719,6 +719,9 @@ extern Lisp_Object merge_font_spec (Lisp_Object, Lisp_Object);
extern Lisp_Object font_make_entity (void);
extern Lisp_Object font_make_object (int, Lisp_Object, int);
#if defined (HAVE_XFT) || defined (HAVE_FREETYPE) || defined (HAVE_NS)
extern Lisp_Object font_build_object (int, Lisp_Object, Lisp_Object, double);
#endif
extern Lisp_Object find_font_encoding (Lisp_Object);
extern int font_registry_charsets (Lisp_Object, struct charset **,
......
......@@ -1183,8 +1183,7 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
Lisp_Object val, filename, idx, cache, font_object;
bool scalable;
int spacing;
char name[256];
int i, len;
int i;
int upEM;
val = assq_no_quit (QCfont_entity, AREF (entity, FONT_EXTRA_INDEX));
......@@ -1221,17 +1220,8 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
return Qnil;
}
font_object = font_make_object (VECSIZE (struct ftfont_info), entity, size);
ASET (font_object, FONT_TYPE_INDEX, Qfreetype);
len = font_unparse_xlfd (entity, size, name, 256);
if (len > 0)
ASET (font_object, FONT_NAME_INDEX, make_string (name, len));
len = font_unparse_fcname (entity, size, name, 256);
if (len > 0)
ASET (font_object, FONT_FULLNAME_INDEX, make_string (name, len));
else
ASET (font_object, FONT_FULLNAME_INDEX,
AREF (font_object, FONT_NAME_INDEX));
font_object = font_build_object (VECSIZE (struct ftfont_info),
Qfreetype, entity, size);
ASET (font_object, FONT_FILE_INDEX, filename);
ASET (font_object, FONT_FORMAT_INDEX, ftfont_font_format (NULL, filename));
font = XFONT_OBJECT (font_object);
......
......@@ -2444,8 +2444,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
int size;
FontRef macfont;
FontSymbolicTraits sym_traits;
char name[256];
int len, i, total_width;
int i, total_width;
CGGlyph glyph;
CGFloat ascent, descent, leading;
......@@ -2472,17 +2471,8 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
if (! macfont)
return Qnil;
font_object = font_make_object (VECSIZE (struct macfont_info), entity, size);
ASET (font_object, FONT_TYPE_INDEX, macfont_driver.type);
len = font_unparse_xlfd (entity, size, name, 256);
if (len > 0)
ASET (font_object, FONT_NAME_INDEX, make_string (name, len));
len = font_unparse_fcname (entity, size, name, 256);
if (len > 0)
ASET (font_object, FONT_FULLNAME_INDEX, make_string (name, len));
else
ASET (font_object, FONT_FULLNAME_INDEX,
AREF (font_object, FONT_NAME_INDEX));
font_object = font_build_object (VECSIZE (struct macfont_info),
Qmac_ct, entity, size);
font = XFONT_OBJECT (font_object);
font->pixel_size = size;
font->driver = &macfont_driver;
......
......@@ -270,8 +270,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
double size = 0;
XftFont *xftfont = NULL;
int spacing;
char name[256];
int len, i;
int i;
XGlyphInfo extents;
FT_Face ft_face;
FcMatrix *matrix;
......@@ -341,17 +340,8 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
/* We should not destroy PAT here because it is kept in XFTFONT and
destroyed automatically when XFTFONT is closed. */
font_object = font_make_object (VECSIZE (struct xftfont_info), entity, size);
ASET (font_object, FONT_TYPE_INDEX, Qxft);
len = font_unparse_xlfd (entity, size, name, 256);
if (len > 0)
ASET (font_object, FONT_NAME_INDEX, make_string (name, len));
len = font_unparse_fcname (entity, size, name, 256);
if (len > 0)
ASET (font_object, FONT_FULLNAME_INDEX, make_string (name, len));
else
ASET (font_object, FONT_FULLNAME_INDEX,
AREF (font_object, FONT_NAME_INDEX));
font_object = font_build_object (VECSIZE (struct xftfont_info),
Qxft, entity, size);
ASET (font_object, FONT_FILE_INDEX, filename);
ASET (font_object, FONT_FORMAT_INDEX,
ftfont_font_format (xftfont->pattern, filename));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment