diff options
| author | Dmitry Antipov | 2014-07-08 18:50:45 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2014-07-08 18:50:45 +0400 |
| commit | 96f17a2f73d1a29c7cdc279daa1fb7f1b7f58aff (patch) | |
| tree | eff4991614caccccefdc7d9b10f795728070159e | |
| parent | d64a4984c147d0c4550aa1e9e3b9a5db10b3de6a (diff) | |
| download | emacs-96f17a2f73d1a29c7cdc279daa1fb7f1b7f58aff.tar.gz emacs-96f17a2f73d1a29c7cdc279daa1fb7f1b7f58aff.zip | |
* 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.
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/font.c | 28 | ||||
| -rw-r--r-- | src/font.h | 3 | ||||
| -rw-r--r-- | src/ftfont.c | 16 | ||||
| -rw-r--r-- | src/macfont.m | 16 | ||||
| -rw-r--r-- | src/xftfont.c | 16 |
6 files changed, 48 insertions, 40 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 8e79414feaf..7a29f8d803b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -5,7 +5,16 @@ | |||
| 5 | Avoid Faref and assume that args are always valid. This helps to | 5 | Avoid Faref and assume that args are always valid. This helps to |
| 6 | speedup search, which is especially important for a huge buffers. | 6 | speedup search, which is especially important for a huge buffers. |
| 7 | * lisp.h (char_table_translate): Remove prototype. | 7 | * lisp.h (char_table_translate): Remove prototype. |
| 8 | |||
| 8 | * nsfont.m (nsfont_close): Free glyphs and metrics arrays as well. | 9 | * nsfont.m (nsfont_close): Free glyphs and metrics arrays as well. |
| 10 | * font.c (font_build_object) [HAVE_XFT || HAVE_FREETYPE || HAVE_NS]: | ||
| 11 | New function, with an intention to avoid code duplication between | ||
| 12 | a few font drivers. | ||
| 13 | * font.h (font_build_object) [HAVE_XFT || HAVE_FREETYPE || HAVE_NS]: | ||
| 14 | Add prototype. | ||
| 15 | * ftfont.c (ftfont_open): | ||
| 16 | * macfont.m (macfont_open): | ||
| 17 | * xftfont.c (xftfont_open): Use it. | ||
| 9 | 18 | ||
| 10 | 2014-07-08 Paul Eggert <eggert@cs.ucla.edu> | 19 | 2014-07-08 Paul Eggert <eggert@cs.ucla.edu> |
| 11 | 20 | ||
diff --git a/src/font.c b/src/font.c index 7b9edcd3fb8..0a204cf0eea 100644 --- a/src/font.c +++ b/src/font.c | |||
| @@ -225,7 +225,33 @@ font_make_object (int size, Lisp_Object entity, int pixelsize) | |||
| 225 | return font_object; | 225 | return font_object; |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | 228 | #if defined (HAVE_XFT) || defined (HAVE_FREETYPE) || defined (HAVE_NS) | |
| 229 | |||
| 230 | /* Like above, but also set `type', `name' and `fullname' properties | ||
| 231 | of font-object. */ | ||
| 232 | |||
| 233 | Lisp_Object | ||
| 234 | font_build_object (int vectorsize, Lisp_Object type, | ||
| 235 | Lisp_Object entity, double pixelsize) | ||
| 236 | { | ||
| 237 | int len; | ||
| 238 | char name[256]; | ||
| 239 | Lisp_Object font_object = font_make_object (vectorsize, entity, pixelsize); | ||
| 240 | |||
| 241 | ASET (font_object, FONT_TYPE_INDEX, type); | ||
| 242 | len = font_unparse_xlfd (entity, pixelsize, name, sizeof name); | ||
| 243 | if (len > 0) | ||
| 244 | ASET (font_object, FONT_NAME_INDEX, make_string (name, len)); | ||
| 245 | len = font_unparse_fcname (entity, pixelsize, name, sizeof name); | ||
| 246 | if (len > 0) | ||
| 247 | ASET (font_object, FONT_FULLNAME_INDEX, make_string (name, len)); | ||
| 248 | else | ||
| 249 | ASET (font_object, FONT_FULLNAME_INDEX, | ||
| 250 | AREF (font_object, FONT_NAME_INDEX)); | ||
| 251 | return font_object; | ||
| 252 | } | ||
| 253 | |||
| 254 | #endif /* HAVE_XFT || HAVE_FREETYPE || HAVE_NS */ | ||
| 229 | 255 | ||
| 230 | static int font_pixel_size (struct frame *f, Lisp_Object); | 256 | static int font_pixel_size (struct frame *f, Lisp_Object); |
| 231 | static Lisp_Object font_open_entity (struct frame *, Lisp_Object, int); | 257 | static Lisp_Object font_open_entity (struct frame *, Lisp_Object, int); |
diff --git a/src/font.h b/src/font.h index c23b826bd46..96c030c3af1 100644 --- a/src/font.h +++ b/src/font.h | |||
| @@ -719,6 +719,9 @@ extern Lisp_Object merge_font_spec (Lisp_Object, Lisp_Object); | |||
| 719 | 719 | ||
| 720 | extern Lisp_Object font_make_entity (void); | 720 | extern Lisp_Object font_make_entity (void); |
| 721 | extern Lisp_Object font_make_object (int, Lisp_Object, int); | 721 | extern Lisp_Object font_make_object (int, Lisp_Object, int); |
| 722 | #if defined (HAVE_XFT) || defined (HAVE_FREETYPE) || defined (HAVE_NS) | ||
| 723 | extern Lisp_Object font_build_object (int, Lisp_Object, Lisp_Object, double); | ||
| 724 | #endif | ||
| 722 | 725 | ||
| 723 | extern Lisp_Object find_font_encoding (Lisp_Object); | 726 | extern Lisp_Object find_font_encoding (Lisp_Object); |
| 724 | extern int font_registry_charsets (Lisp_Object, struct charset **, | 727 | extern int font_registry_charsets (Lisp_Object, struct charset **, |
diff --git a/src/ftfont.c b/src/ftfont.c index 7c5d01208d2..2d75dc22679 100644 --- a/src/ftfont.c +++ b/src/ftfont.c | |||
| @@ -1183,8 +1183,7 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 1183 | Lisp_Object val, filename, idx, cache, font_object; | 1183 | Lisp_Object val, filename, idx, cache, font_object; |
| 1184 | bool scalable; | 1184 | bool scalable; |
| 1185 | int spacing; | 1185 | int spacing; |
| 1186 | char name[256]; | 1186 | int i; |
| 1187 | int i, len; | ||
| 1188 | int upEM; | 1187 | int upEM; |
| 1189 | 1188 | ||
| 1190 | val = assq_no_quit (QCfont_entity, AREF (entity, FONT_EXTRA_INDEX)); | 1189 | 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) | |||
| 1221 | return Qnil; | 1220 | return Qnil; |
| 1222 | } | 1221 | } |
| 1223 | 1222 | ||
| 1224 | font_object = font_make_object (VECSIZE (struct ftfont_info), entity, size); | 1223 | font_object = font_build_object (VECSIZE (struct ftfont_info), |
| 1225 | ASET (font_object, FONT_TYPE_INDEX, Qfreetype); | 1224 | Qfreetype, entity, size); |
| 1226 | len = font_unparse_xlfd (entity, size, name, 256); | ||
| 1227 | if (len > 0) | ||
| 1228 | ASET (font_object, FONT_NAME_INDEX, make_string (name, len)); | ||
| 1229 | len = font_unparse_fcname (entity, size, name, 256); | ||
| 1230 | if (len > 0) | ||
| 1231 | ASET (font_object, FONT_FULLNAME_INDEX, make_string (name, len)); | ||
| 1232 | else | ||
| 1233 | ASET (font_object, FONT_FULLNAME_INDEX, | ||
| 1234 | AREF (font_object, FONT_NAME_INDEX)); | ||
| 1235 | ASET (font_object, FONT_FILE_INDEX, filename); | 1225 | ASET (font_object, FONT_FILE_INDEX, filename); |
| 1236 | ASET (font_object, FONT_FORMAT_INDEX, ftfont_font_format (NULL, filename)); | 1226 | ASET (font_object, FONT_FORMAT_INDEX, ftfont_font_format (NULL, filename)); |
| 1237 | font = XFONT_OBJECT (font_object); | 1227 | font = XFONT_OBJECT (font_object); |
diff --git a/src/macfont.m b/src/macfont.m index 82ee54cdc63..60f261d5549 100644 --- a/src/macfont.m +++ b/src/macfont.m | |||
| @@ -2444,8 +2444,7 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) | |||
| 2444 | int size; | 2444 | int size; |
| 2445 | FontRef macfont; | 2445 | FontRef macfont; |
| 2446 | FontSymbolicTraits sym_traits; | 2446 | FontSymbolicTraits sym_traits; |
| 2447 | char name[256]; | 2447 | int i, total_width; |
| 2448 | int len, i, total_width; | ||
| 2449 | CGGlyph glyph; | 2448 | CGGlyph glyph; |
| 2450 | CGFloat ascent, descent, leading; | 2449 | CGFloat ascent, descent, leading; |
| 2451 | 2450 | ||
| @@ -2472,17 +2471,8 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) | |||
| 2472 | if (! macfont) | 2471 | if (! macfont) |
| 2473 | return Qnil; | 2472 | return Qnil; |
| 2474 | 2473 | ||
| 2475 | font_object = font_make_object (VECSIZE (struct macfont_info), entity, size); | 2474 | font_object = font_build_object (VECSIZE (struct macfont_info), |
| 2476 | ASET (font_object, FONT_TYPE_INDEX, macfont_driver.type); | 2475 | Qmac_ct, entity, size); |
| 2477 | len = font_unparse_xlfd (entity, size, name, 256); | ||
| 2478 | if (len > 0) | ||
| 2479 | ASET (font_object, FONT_NAME_INDEX, make_string (name, len)); | ||
| 2480 | len = font_unparse_fcname (entity, size, name, 256); | ||
| 2481 | if (len > 0) | ||
| 2482 | ASET (font_object, FONT_FULLNAME_INDEX, make_string (name, len)); | ||
| 2483 | else | ||
| 2484 | ASET (font_object, FONT_FULLNAME_INDEX, | ||
| 2485 | AREF (font_object, FONT_NAME_INDEX)); | ||
| 2486 | font = XFONT_OBJECT (font_object); | 2476 | font = XFONT_OBJECT (font_object); |
| 2487 | font->pixel_size = size; | 2477 | font->pixel_size = size; |
| 2488 | font->driver = &macfont_driver; | 2478 | font->driver = &macfont_driver; |
diff --git a/src/xftfont.c b/src/xftfont.c index bd3f2c92142..1ca3f92b239 100644 --- a/src/xftfont.c +++ b/src/xftfont.c | |||
| @@ -270,8 +270,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 270 | double size = 0; | 270 | double size = 0; |
| 271 | XftFont *xftfont = NULL; | 271 | XftFont *xftfont = NULL; |
| 272 | int spacing; | 272 | int spacing; |
| 273 | char name[256]; | 273 | int i; |
| 274 | int len, i; | ||
| 275 | XGlyphInfo extents; | 274 | XGlyphInfo extents; |
| 276 | FT_Face ft_face; | 275 | FT_Face ft_face; |
| 277 | FcMatrix *matrix; | 276 | FcMatrix *matrix; |
| @@ -341,17 +340,8 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 341 | 340 | ||
| 342 | /* We should not destroy PAT here because it is kept in XFTFONT and | 341 | /* We should not destroy PAT here because it is kept in XFTFONT and |
| 343 | destroyed automatically when XFTFONT is closed. */ | 342 | destroyed automatically when XFTFONT is closed. */ |
| 344 | font_object = font_make_object (VECSIZE (struct xftfont_info), entity, size); | 343 | font_object = font_build_object (VECSIZE (struct xftfont_info), |
| 345 | ASET (font_object, FONT_TYPE_INDEX, Qxft); | 344 | Qxft, entity, size); |
| 346 | len = font_unparse_xlfd (entity, size, name, 256); | ||
| 347 | if (len > 0) | ||
| 348 | ASET (font_object, FONT_NAME_INDEX, make_string (name, len)); | ||
| 349 | len = font_unparse_fcname (entity, size, name, 256); | ||
| 350 | if (len > 0) | ||
| 351 | ASET (font_object, FONT_FULLNAME_INDEX, make_string (name, len)); | ||
| 352 | else | ||
| 353 | ASET (font_object, FONT_FULLNAME_INDEX, | ||
| 354 | AREF (font_object, FONT_NAME_INDEX)); | ||
| 355 | ASET (font_object, FONT_FILE_INDEX, filename); | 345 | ASET (font_object, FONT_FILE_INDEX, filename); |
| 356 | ASET (font_object, FONT_FORMAT_INDEX, | 346 | ASET (font_object, FONT_FORMAT_INDEX, |
| 357 | ftfont_font_format (xftfont->pattern, filename)); | 347 | ftfont_font_format (xftfont->pattern, filename)); |