aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/xfaces.c499
1 files changed, 290 insertions, 209 deletions
diff --git a/src/xfaces.c b/src/xfaces.c
index 1f7c9067297..705fce20486 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -197,6 +197,7 @@ Boston, MA 02111-1307, USA. */
197 197
198#include "lisp.h" 198#include "lisp.h"
199#include "character.h" 199#include "character.h"
200#include "charset.h"
200#include "keyboard.h" 201#include "keyboard.h"
201#include "frame.h" 202#include "frame.h"
202 203
@@ -517,7 +518,7 @@ static int load_pixmap P_ ((struct frame *, Lisp_Object, unsigned *, unsigned *)
517static unsigned char *xstrlwr P_ ((unsigned char *)); 518static unsigned char *xstrlwr P_ ((unsigned char *));
518static void signal_error P_ ((char *, Lisp_Object)); 519static void signal_error P_ ((char *, Lisp_Object));
519static struct frame *frame_or_selected_frame P_ ((Lisp_Object, int)); 520static struct frame *frame_or_selected_frame P_ ((Lisp_Object, int));
520static void load_face_font P_ ((struct frame *, struct face *, int)); 521static void load_face_font P_ ((struct frame *, struct face *));
521static void load_face_colors P_ ((struct frame *, struct face *, Lisp_Object *)); 522static void load_face_colors P_ ((struct frame *, struct face *, Lisp_Object *));
522static void free_face_colors P_ ((struct frame *, struct face *)); 523static void free_face_colors P_ ((struct frame *, struct face *));
523static int face_color_gray_p P_ ((struct frame *, char *)); 524static int face_color_gray_p P_ ((struct frame *, char *));
@@ -530,17 +531,18 @@ static int font_list_1 P_ ((struct frame *, Lisp_Object, Lisp_Object,
530 Lisp_Object, struct font_name **)); 531 Lisp_Object, struct font_name **));
531static int font_list P_ ((struct frame *, Lisp_Object, Lisp_Object, 532static int font_list P_ ((struct frame *, Lisp_Object, Lisp_Object,
532 Lisp_Object, struct font_name **)); 533 Lisp_Object, struct font_name **));
533static int try_font_list P_ ((struct frame *, Lisp_Object *, 534static int try_font_list P_ ((struct frame *, Lisp_Object,
534 Lisp_Object, Lisp_Object, struct font_name **)); 535 Lisp_Object, Lisp_Object, struct font_name **));
535static int try_alternative_families P_ ((struct frame *f, Lisp_Object, 536static int try_alternative_families P_ ((struct frame *f, Lisp_Object,
536 Lisp_Object, struct font_name **)); 537 Lisp_Object, struct font_name **));
537static int cmp_font_names P_ ((const void *, const void *)); 538static int cmp_font_names P_ ((const void *, const void *));
538static struct face *realize_face P_ ((struct face_cache *, Lisp_Object *, int, 539static struct face *realize_face P_ ((struct face_cache *, Lisp_Object *,
539 struct face *, int)); 540 int));
540static struct face *realize_x_face P_ ((struct face_cache *, 541static struct face *realize_non_ascii_face P_ ((struct frame *, int,
541 Lisp_Object *, int, struct face *)); 542 struct face *));
542static struct face *realize_tty_face P_ ((struct face_cache *, 543
543 Lisp_Object *, int)); 544static struct face *realize_x_face P_ ((struct face_cache *, Lisp_Object *));
545static struct face *realize_tty_face P_ ((struct face_cache *, Lisp_Object *));
544static int realize_basic_faces P_ ((struct frame *)); 546static int realize_basic_faces P_ ((struct frame *));
545static int realize_default_face P_ ((struct frame *)); 547static int realize_default_face P_ ((struct frame *));
546static void realize_named_face P_ ((struct frame *, Lisp_Object, int)); 548static void realize_named_face P_ ((struct frame *, Lisp_Object, int));
@@ -556,8 +558,6 @@ static int face_numeric_weight P_ ((Lisp_Object));
556static int face_numeric_slant P_ ((Lisp_Object)); 558static int face_numeric_slant P_ ((Lisp_Object));
557static int face_numeric_swidth P_ ((Lisp_Object)); 559static int face_numeric_swidth P_ ((Lisp_Object));
558static int face_fontset P_ ((Lisp_Object *)); 560static int face_fontset P_ ((Lisp_Object *));
559static char *choose_face_font P_ ((struct frame *, Lisp_Object *,
560 struct face *, int));
561static void merge_face_vectors P_ ((struct frame *, Lisp_Object *, Lisp_Object*, Lisp_Object)); 561static void merge_face_vectors P_ ((struct frame *, Lisp_Object *, Lisp_Object*, Lisp_Object));
562static void merge_face_inheritance P_ ((struct frame *f, Lisp_Object, 562static void merge_face_inheritance P_ ((struct frame *f, Lisp_Object,
563 Lisp_Object *, Lisp_Object)); 563 Lisp_Object *, Lisp_Object));
@@ -1251,23 +1251,23 @@ frame_update_line_height (f)
1251 1251
1252#ifdef HAVE_WINDOW_SYSTEM 1252#ifdef HAVE_WINDOW_SYSTEM
1253 1253
1254/* Load font of face FACE which is used on frame F to display 1254/* Load font of face FACE which is used on frame F to display ASCII
1255 character C. The name of the font to load is determined by lface 1255 characters. The name of the font to load is determined by lface
1256 and fontset of FACE. */ 1256 and fontset of FACE. */
1257 1257
1258static void 1258static void
1259load_face_font (f, face, c) 1259load_face_font (f, face)
1260 struct frame *f; 1260 struct frame *f;
1261 struct face *face; 1261 struct face *face;
1262 int c;
1263{ 1262{
1264 struct font_info *font_info = NULL; 1263 struct font_info *font_info = NULL;
1265 char *font_name; 1264 char *font_name;
1266 1265
1267 face->font_info_id = -1; 1266 face->font_info_id = -1;
1268 face->font = NULL; 1267 face->font = NULL;
1268 face->font_name = NULL;
1269 1269
1270 font_name = choose_face_font (f, face->lface, face, c); 1270 font_name = choose_face_font (f, face->lface, Qnil);
1271 1271
1272 if (!font_name) 1272 if (!font_name)
1273 return; 1273 return;
@@ -2112,8 +2112,13 @@ face_numeric_swidth (width)
2112} 2112}
2113 2113
2114 2114
2115/* Return an ASCII font name generated from fontset name NAME and
2116 ASCII font specification ASCII_SPEC. NAME is a string conforming
2117 to XLFD. ASCII_SPEC is a vector:
2118 [FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY]. */
2119
2115Lisp_Object 2120Lisp_Object
2116generate_ascii_font (name, ascii_spec) 2121generate_ascii_font_name (name, ascii_spec)
2117 Lisp_Object name, ascii_spec; 2122 Lisp_Object name, ascii_spec;
2118{ 2123{
2119 struct font_name font; 2124 struct font_name font;
@@ -2167,6 +2172,21 @@ generate_ascii_font (name, ascii_spec)
2167} 2172}
2168 2173
2169 2174
2175Lisp_Object
2176font_name_registry (fontname)
2177 Lisp_Object fontname;
2178{
2179 Lisp_Object registry;
2180 struct font_name font;
2181 char *p;
2182
2183 font.name = LSTRDUPA (fontname);
2184 if (! split_font_name (NULL, &font, 0))
2185 return Qnil;
2186 font.fields[XLFD_ENCODING][-1] = '-';
2187 return build_string (font.fields[XLFD_REGISTRY]);
2188}
2189
2170#ifdef HAVE_WINDOW_SYSTEM 2190#ifdef HAVE_WINDOW_SYSTEM
2171 2191
2172/* Return non-zero if FONT is the name of a fixed-pitch font. */ 2192/* Return non-zero if FONT is the name of a fixed-pitch font. */
@@ -2610,12 +2630,11 @@ cmp_font_names (a, b)
2610} 2630}
2611 2631
2612 2632
2613/* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN 2633/* Get a sorted list of fonts matching PATTERN. If PATTERN is nil,
2614 is non-nil list fonts matching that pattern. Otherwise, if 2634 list fonts matching FAMILY and REGISTRY. FAMILY is a family name
2615 REGISTRY is non-nil return only fonts with that registry, otherwise 2635 string or nil. REGISTRY is a registry name string. Set *FONTS to
2616 return fonts of any registry. Set *FONTS to a vector of font_name 2636 a vector of font_name structures allocated from the heap containing
2617 structures allocated from the heap containing the fonts found. 2637 the fonts found. Value is the number of fonts found. */
2618 Value is the number of fonts found. */
2619 2638
2620static int 2639static int
2621font_list_1 (f, pattern, family, registry, fonts) 2640font_list_1 (f, pattern, family, registry, fonts)
@@ -2676,7 +2695,7 @@ concat_font_list (fonts1, nfonts1, fonts2, nfonts2)
2676 2695
2677/* Get a sorted list of fonts of family FAMILY on frame F. 2696/* Get a sorted list of fonts of family FAMILY on frame F.
2678 2697
2679 If PATTERN is non-nil list fonts matching that pattern. 2698 If PATTERN is non-nil, list fonts matching that pattern.
2680 2699
2681 If REGISTRY is non-nil, return fonts with that registry and the 2700 If REGISTRY is non-nil, return fonts with that registry and the
2682 alternative registries from Vface_alternative_font_registry_alist. 2701 alternative registries from Vface_alternative_font_registry_alist.
@@ -2916,7 +2935,7 @@ the WIDTH times as wide as FACE on FRAME. */)
2916 { 2935 {
2917 /* This is of limited utility since it works with character 2936 /* This is of limited utility since it works with character
2918 widths. Keep it for compatibility. --gerd. */ 2937 widths. Keep it for compatibility. --gerd. */
2919 int face_id = lookup_named_face (f, face, 0); 2938 int face_id = lookup_named_face (f, face);
2920 struct face *face = (face_id < 0 2939 struct face *face = (face_id < 0
2921 ? NULL 2940 ? NULL
2922 : FACE_FROM_ID (f, face_id)); 2941 : FACE_FROM_ID (f, face_id));
@@ -3176,7 +3195,10 @@ lface_fully_specified_p (attrs)
3176 If the fullname is not in a valid XLFD format, 3195 If the fullname is not in a valid XLFD format,
3177 return 0 if MAY_FAIL_P is non-zero, otherwise set normal values 3196 return 0 if MAY_FAIL_P is non-zero, otherwise set normal values
3178 in LFACE and return 1. 3197 in LFACE and return 1.
3179 Otherwise, return 1. */ 3198 Otherwise, return 1.
3199
3200 Currently this function is always called with both FORCE_P and
3201 MAIL_FAIL_P non-zero. */
3180 3202
3181static int 3203static int
3182set_lface_from_font_name (f, lface, fontname, force_p, may_fail_p) 3204set_lface_from_font_name (f, lface, fontname, force_p, may_fail_p)
@@ -4307,7 +4329,7 @@ set_font_frame_param (frame, lface)
4307 /* Choose a font name that reflects LFACE's attributes and has 4329 /* Choose a font name that reflects LFACE's attributes and has
4308 the registry and encoding pattern specified in the default 4330 the registry and encoding pattern specified in the default
4309 fontset (3rd arg: -1) for ASCII characters (4th arg: 0). */ 4331 fontset (3rd arg: -1) for ASCII characters (4th arg: 0). */
4310 font = choose_face_font (f, XVECTOR (lface)->contents, NULL, 0); 4332 font = choose_face_font (f, XVECTOR (lface)->contents, Qnil);
4311 if (!font) 4333 if (!font)
4312 error ("No font matches the specified attribute"); 4334 error ("No font matches the specified attribute");
4313 font_name = build_string (font); 4335 font_name = build_string (font);
@@ -4784,7 +4806,7 @@ If FRAME is omitted or nil, use the selected frame. */)
4784 else 4806 else
4785 { 4807 {
4786 struct frame *f = frame_or_selected_frame (frame, 1); 4808 struct frame *f = frame_or_selected_frame (frame, 1);
4787 int face_id = lookup_named_face (f, face, 0); 4809 int face_id = lookup_named_face (f, face);
4788 struct face *face = FACE_FROM_ID (f, face_id); 4810 struct face *face = FACE_FROM_ID (f, face_id);
4789 return face ? build_string (face->font_name) : Qnil; 4811 return face ? build_string (face->font_name) : Qnil;
4790 } 4812 }
@@ -5248,10 +5270,11 @@ free_face_cache (c)
5248 5270
5249 5271
5250/* Cache realized face FACE in face cache C. HASH is the hash value 5272/* Cache realized face FACE in face cache C. HASH is the hash value
5251 of FACE. If FACE->fontset >= 0, add the new face to the end of the 5273 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
5252 collision list of the face hash table of C. This is done because 5274 FACE), insert the new face to the beginning of the collision list
5253 otherwise lookup_face would find FACE for every character, even if 5275 of the face hash table of C. Otherwise, add the new face to the
5254 faces with the same attributes but for specific characters exist. */ 5276 end of the collision list. This way, lookup_face can quickly find
5277 that a requested face is not cached. */
5255 5278
5256static void 5279static void
5257cache_face (c, face, hash) 5280cache_face (c, face, hash)
@@ -5263,7 +5286,7 @@ cache_face (c, face, hash)
5263 5286
5264 face->hash = hash; 5287 face->hash = hash;
5265 5288
5266 if (face->fontset >= 0) 5289 if (face->ascii_face != face)
5267 { 5290 {
5268 struct face *last = c->buckets[i]; 5291 struct face *last = c->buckets[i];
5269 if (last) 5292 if (last)
@@ -5350,17 +5373,14 @@ uncache_face (c, face)
5350 5373
5351 5374
5352/* Look up a realized face with face attributes ATTR in the face cache 5375/* Look up a realized face with face attributes ATTR in the face cache
5353 of frame F. The face will be used to display character C. Value 5376 of frame F. The face will be used to display ASCII characters.
5354 is the ID of the face found. If no suitable face is found, realize 5377 Value is the ID of the face found. If no suitable face is found,
5355 a new one. In that case, if C is a multibyte character, BASE_FACE 5378 realize a new one. */
5356 is a face that has the same attributes. */
5357 5379
5358INLINE int 5380INLINE int
5359lookup_face (f, attr, c, base_face) 5381lookup_face (f, attr)
5360 struct frame *f; 5382 struct frame *f;
5361 Lisp_Object *attr; 5383 Lisp_Object *attr;
5362 int c;
5363 struct face *base_face;
5364{ 5384{
5365 struct face_cache *cache = FRAME_FACE_CACHE (f); 5385 struct face_cache *cache = FRAME_FACE_CACHE (f);
5366 unsigned hash; 5386 unsigned hash;
@@ -5375,28 +5395,68 @@ lookup_face (f, attr, c, base_face)
5375 i = hash % FACE_CACHE_BUCKETS_SIZE; 5395 i = hash % FACE_CACHE_BUCKETS_SIZE;
5376 5396
5377 for (face = cache->buckets[i]; face; face = face->next) 5397 for (face = cache->buckets[i]; face; face = face->next)
5378 if (face->hash == hash 5398 {
5379 && (!FRAME_WINDOW_P (f) 5399 if (face->ascii_face != face)
5380 || FACE_SUITABLE_FOR_CHAR_P (face, c)) 5400 {
5381 && lface_equal_p (face->lface, attr)) 5401 /* There's no more ASCII face. */
5382 break; 5402 face = NULL;
5403 break;
5404 }
5405 if (face->hash == hash
5406 && lface_equal_p (face->lface, attr))
5407 break;
5408 }
5383 5409
5384 /* If not found, realize a new face. */ 5410 /* If not found, realize a new face. */
5385 if (face == NULL) 5411 if (face == NULL)
5386 face = realize_face (cache, attr, c, base_face, -1); 5412 face = realize_face (cache, attr, -1);
5387 5413
5388#if GLYPH_DEBUG 5414#if GLYPH_DEBUG
5389 xassert (face == FACE_FROM_ID (f, face->id)); 5415 xassert (face == FACE_FROM_ID (f, face->id));
5416#endif /* GLYPH_DEBUG */
5390 5417
5391/* When this function is called from face_for_char (in this case, C is 5418 return face->id;
5392 a multibyte character), a fontset of a face returned by 5419}
5393 realize_face is not yet set, i.e. FACE_SUITABLE_FOR_CHAR_P (FACE, 5420
5394 C) is not sutisfied. The fontset is set for this face by 5421
5395 face_for_char later. */ 5422/* Look up a realized face that has the same attributes as BASE_FACE
5396#if 0 5423 except for the font in the face cache of frame F. If FONT_ID is
5397 if (FRAME_WINDOW_P (f)) 5424 not negative, it is an ID number of an already opened font that is
5398 xassert (FACE_SUITABLE_FOR_CHAR_P (face, c)); 5425 used by the face. If FONT_ID is negative, the face has no font.
5399#endif 5426 Value is the ID of the face found. If no suitable face is found,
5427 realize a new one. */
5428
5429INLINE int
5430lookup_non_ascii_face (f, font_id, base_face)
5431 struct frame *f;
5432 int font_id;
5433 struct face *base_face;
5434{
5435 struct face_cache *cache = FRAME_FACE_CACHE (f);
5436 unsigned hash;
5437 int i;
5438 struct face *face;
5439
5440 xassert (cache != NULL);
5441 base_face = base_face->ascii_face;
5442 hash = lface_hash (base_face->lface);
5443 i = hash % FACE_CACHE_BUCKETS_SIZE;
5444
5445 for (face = cache->buckets[i]; face; face = face->next)
5446 {
5447 if (face->ascii_face == face)
5448 continue;
5449 if (face->ascii_face == base_face
5450 && face->font_info_id == font_id)
5451 break;
5452 }
5453
5454 /* If not found, realize a new face. */
5455 if (face == NULL)
5456 face = realize_non_ascii_face (f, font_id, base_face);
5457
5458#if GLYPH_DEBUG
5459 xassert (face == FACE_FROM_ID (f, face->id));
5400#endif /* GLYPH_DEBUG */ 5460#endif /* GLYPH_DEBUG */
5401 5461
5402 return face->id; 5462 return face->id;
@@ -5404,15 +5464,14 @@ lookup_face (f, attr, c, base_face)
5404 5464
5405 5465
5406/* Return the face id of the realized face for named face SYMBOL on 5466/* Return the face id of the realized face for named face SYMBOL on
5407 frame F suitable for displaying character C. Value is -1 if the 5467 frame F suitable for displaying ASCII characters. Value is -1 if
5408 face couldn't be determined, which might happen if the default face 5468 the face couldn't be determined, which might happen if the default
5409 isn't realized and cannot be realized. */ 5469 face isn't realized and cannot be realized. */
5410 5470
5411int 5471int
5412lookup_named_face (f, symbol, c) 5472lookup_named_face (f, symbol)
5413 struct frame *f; 5473 struct frame *f;
5414 Lisp_Object symbol; 5474 Lisp_Object symbol;
5415 int c;
5416{ 5475{
5417 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 5476 Lisp_Object attrs[LFACE_VECTOR_SIZE];
5418 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; 5477 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];
@@ -5428,7 +5487,7 @@ lookup_named_face (f, symbol, c)
5428 get_lface_attributes (f, symbol, symbol_attrs, 1); 5487 get_lface_attributes (f, symbol, symbol_attrs, 1);
5429 bcopy (default_face->lface, attrs, sizeof attrs); 5488 bcopy (default_face->lface, attrs, sizeof attrs);
5430 merge_face_vectors (f, symbol_attrs, attrs, Qnil); 5489 merge_face_vectors (f, symbol_attrs, attrs, Qnil);
5431 return lookup_face (f, attrs, c, NULL); 5490 return lookup_face (f, attrs);
5432} 5491}
5433 5492
5434 5493
@@ -5445,7 +5504,7 @@ ascii_face_of_lisp_face (f, lface_id)
5445 if (lface_id >= 0 && lface_id < lface_id_to_name_size) 5504 if (lface_id >= 0 && lface_id < lface_id_to_name_size)
5446 { 5505 {
5447 Lisp_Object face_name = lface_id_to_name[lface_id]; 5506 Lisp_Object face_name = lface_id_to_name[lface_id];
5448 face_id = lookup_named_face (f, face_name, 0); 5507 face_id = lookup_named_face (f, face_name);
5449 } 5508 }
5450 else 5509 else
5451 face_id = -1; 5510 face_id = -1;
@@ -5493,7 +5552,7 @@ smaller_face (f, face_id, steps)
5493 /* Look up a face for a slightly smaller/larger font. */ 5552 /* Look up a face for a slightly smaller/larger font. */
5494 pt += delta; 5553 pt += delta;
5495 attrs[LFACE_HEIGHT_INDEX] = make_number (pt); 5554 attrs[LFACE_HEIGHT_INDEX] = make_number (pt);
5496 new_face_id = lookup_face (f, attrs, 0, NULL); 5555 new_face_id = lookup_face (f, attrs);
5497 new_face = FACE_FROM_ID (f, new_face_id); 5556 new_face = FACE_FROM_ID (f, new_face_id);
5498 5557
5499 /* If height changes, count that as one step. */ 5558 /* If height changes, count that as one step. */
@@ -5536,7 +5595,7 @@ face_with_height (f, face_id, height)
5536 face = FACE_FROM_ID (f, face_id); 5595 face = FACE_FROM_ID (f, face_id);
5537 bcopy (face->lface, attrs, sizeof attrs); 5596 bcopy (face->lface, attrs, sizeof attrs);
5538 attrs[LFACE_HEIGHT_INDEX] = make_number (height); 5597 attrs[LFACE_HEIGHT_INDEX] = make_number (height);
5539 face_id = lookup_face (f, attrs, 0, NULL); 5598 face_id = lookup_face (f, attrs);
5540#endif /* HAVE_WINDOW_SYSTEM */ 5599#endif /* HAVE_WINDOW_SYSTEM */
5541 5600
5542 return face_id; 5601 return face_id;
@@ -5544,17 +5603,16 @@ face_with_height (f, face_id, height)
5544 5603
5545 5604
5546/* Return the face id of the realized face for named face SYMBOL on 5605/* Return the face id of the realized face for named face SYMBOL on
5547 frame F suitable for displaying character C, and use attributes of 5606 frame F suitable for displaying ASCII characters, and use
5548 the face FACE_ID for attributes that aren't completely specified by 5607 attributes of the face FACE_ID for attributes that aren't
5549 SYMBOL. This is like lookup_named_face, except that the default 5608 completely specified by SYMBOL. This is like lookup_named_face,
5550 attributes come from FACE_ID, not from the default face. FACE_ID 5609 except that the default attributes come from FACE_ID, not from the
5551 is assumed to be already realized. */ 5610 default face. FACE_ID is assumed to be already realized. */
5552 5611
5553int 5612int
5554lookup_derived_face (f, symbol, c, face_id) 5613lookup_derived_face (f, symbol, face_id)
5555 struct frame *f; 5614 struct frame *f;
5556 Lisp_Object symbol; 5615 Lisp_Object symbol;
5557 int c;
5558 int face_id; 5616 int face_id;
5559{ 5617{
5560 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 5618 Lisp_Object attrs[LFACE_VECTOR_SIZE];
@@ -5567,7 +5625,7 @@ lookup_derived_face (f, symbol, c, face_id)
5567 get_lface_attributes (f, symbol, symbol_attrs, 1); 5625 get_lface_attributes (f, symbol, symbol_attrs, 1);
5568 bcopy (default_face->lface, attrs, sizeof attrs); 5626 bcopy (default_face->lface, attrs, sizeof attrs);
5569 merge_face_vectors (f, symbol_attrs, attrs, Qnil); 5627 merge_face_vectors (f, symbol_attrs, attrs, Qnil);
5570 return lookup_face (f, attrs, c, default_face); 5628 return lookup_face (f, attrs);
5571} 5629}
5572 5630
5573DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector, 5631DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector,
@@ -6051,47 +6109,52 @@ try_alternative_families (f, family, registry, fonts)
6051 6109
6052/* Get a list of matching fonts on frame F. 6110/* Get a list of matching fonts on frame F.
6053 6111
6054 FAMILY, if a string, specifies a font family derived from the fontset. 6112 PATTERN, if a string, specifies a font name pattern to match while
6055 It is only used if the face does not specify any family in ATTRS or 6113 ignoring FAMILY and REGISTRY.
6056 if we cannot find any font of the face's family.
6057 6114
6058 REGISTRY, if a string, specifies a font registry and encoding to 6115 FAMILY, if a list, specifies a list of font families to try.
6059 match. A value of nil means include fonts of any registry and 6116
6060 encoding. 6117 REGISTRY, if a list, specifies a list of font registries and
6118 encodinging to try.
6061 6119
6062 Return in *FONTS a pointer to a vector of font_name structures for 6120 Return in *FONTS a pointer to a vector of font_name structures for
6063 the fonts matched. Value is the number of fonts found. */ 6121 the fonts matched. Value is the number of fonts found. */
6064 6122
6065static int 6123static int
6066try_font_list (f, attrs, family, registry, fonts) 6124try_font_list (f, pattern, family, registry, fonts)
6067 struct frame *f; 6125 struct frame *f;
6068 Lisp_Object *attrs;
6069 Lisp_Object family, registry; 6126 Lisp_Object family, registry;
6070 struct font_name **fonts; 6127 struct font_name **fonts;
6071{ 6128{
6072 int nfonts = 0; 6129 int nfonts = 0;
6073 Lisp_Object face_family = attrs[LFACE_FAMILY_INDEX];
6074
6075 if (!NILP (family))
6076 nfonts = try_alternative_families (f, family, registry, fonts);
6077
6078 if (nfonts == 0 && STRINGP (face_family))
6079 nfonts = try_alternative_families (f, face_family, registry, fonts);
6080 6130
6081 /* Try font family of the default face or "fixed". */ 6131 if (STRINGP (pattern))
6082 if (nfonts == 0) 6132 nfonts = font_list (f, pattern, Qnil, Qnil, fonts);
6133 else
6083 { 6134 {
6084 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); 6135 Lisp_Object tail;
6085 if (default_face) 6136
6086 family = default_face->lface[LFACE_FAMILY_INDEX]; 6137 if (NILP (family))
6138 nfonts = font_list (f, Qnil, Qnil, registry, fonts);
6087 else 6139 else
6088 family = build_string ("fixed"); 6140 for (tail = family; ! nfonts && CONSP (tail); tail = XCDR (tail))
6089 nfonts = font_list (f, Qnil, family, registry, fonts); 6141 nfonts = try_alternative_families (f, XCAR (tail), registry, fonts);
6090 } 6142
6143 /* Try font family of the default face or "fixed". */
6144 if (nfonts == 0 && !NILP (family))
6145 {
6146 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
6147 if (default_face)
6148 family = default_face->lface[LFACE_FAMILY_INDEX];
6149 else
6150 family = build_string ("fixed");
6151 nfonts = font_list (f, Qnil, family, registry, fonts);
6152 }
6091 6153
6092 /* Try any family with the given registry. */ 6154 /* Try any family with the given registry. */
6093 if (nfonts == 0) 6155 if (nfonts == 0 && !NILP (family))
6094 nfonts = font_list (f, Qnil, Qnil, registry, fonts); 6156 nfonts = font_list (f, Qnil, Qnil, registry, fonts);
6157 }
6095 6158
6096 return nfonts; 6159 return nfonts;
6097} 6160}
@@ -6114,69 +6177,70 @@ face_fontset (attrs)
6114} 6177}
6115 6178
6116 6179
6117/* Choose a name of font to use on frame F to display character C with 6180/* Choose a name of font to use on frame F to display characters with
6118 Lisp face attributes specified by ATTRS. The font name is 6181 Lisp face attributes specified by ATTRS. The font name is
6119 determined by the font-related attributes in ATTRS and the name 6182 determined by the font-related attributes in ATTRS and FONT-SPEC
6120 pattern for C in FACE->fontset (or Vdefault_fontset if FACE is 6183 (if specified).
6121 null). Value is the font name which is allocated from the heap and
6122 must be freed by the caller, or NULL if we can get no information
6123 about the font name of C. It is assured that we always get some
6124 information for a single byte character. */
6125 6184
6126static char * 6185 When we are choosing a font for ASCII characters, FONT-SPEC is
6127choose_face_font (f, attrs, face, c) 6186 always nil. Otherwise FONT-SPEC is a list
6187 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
6188 or a string specifying a font name pattern.
6189
6190 Value is the font name which is allocated from the heap and must be
6191 freed by the caller. */
6192
6193char *
6194choose_face_font (f, attrs, font_spec)
6128 struct frame *f; 6195 struct frame *f;
6129 Lisp_Object *attrs; 6196 Lisp_Object *attrs;
6130 struct face *face; 6197 Lisp_Object font_spec;
6131 int c;
6132{ 6198{
6133 Lisp_Object val; 6199 Lisp_Object val;
6134 Lisp_Object pattern, family, registry; 6200 Lisp_Object pattern, family, adstyle, registry;
6135 Lisp_Object new_attrs[LFACE_VECTOR_SIZE]; 6201 Lisp_Object new_attrs[LFACE_VECTOR_SIZE];
6136 char *font_name = NULL; 6202 char *font_name = NULL;
6137 struct font_name *fonts; 6203 struct font_name *fonts;
6138 int nfonts, width_ratio; 6204 int nfonts;
6139
6140 /* Get font spec of a font for C. */
6141 pattern = fontset_font_pattern (f, face, c);
6142 if (NILP (pattern))
6143 {
6144 xassert (!SINGLE_BYTE_CHAR_P (c));
6145 return NULL;
6146 }
6147
6148 /* If what we got is a name pattern, return it. */
6149 if (STRINGP (pattern))
6150 return xstrdup (XSTRING (pattern)->data);
6151
6152 family = AREF (pattern, FONT_SPEC_FAMILY_INDEX);
6153 registry = AREF (pattern, FONT_SPEC_REGISTRY_INDEX);
6154
6155 bcopy (attrs, new_attrs, sizeof (Lisp_Object) * LFACE_VECTOR_SIZE);
6156 6205
6206 /* If we are choosing an ASCII font and a font name is explicitly
6207 specified in ATTRS, return it. */
6157#if 0 6208#if 0
6158 /* This doesn't work well for the moment. */ 6209 if (NILP (font_spec) && STRINGP (attrs[LFACE_FONT_INDEX]))
6159 if (! NILP (AREF (pattern, FONT_SPEC_WEIGHT_INDEX))) 6210 return xstrdup (XSTRING (attrs[LFACE_FONT_INDEX])->data);
6160 new_attrs[LFACE_WEIGHT_INDEX] = AREF (pattern, FONT_SPEC_WEIGHT_INDEX);
6161 if (! NILP (AREF (pattern, FONT_SPEC_SLANT_INDEX)))
6162 new_attrs[LFACE_SLANT_INDEX] = AREF (pattern, FONT_SPEC_SLANT_INDEX);
6163 if (! NILP (AREF (pattern, FONT_SPEC_SWIDTH_INDEX)))
6164 new_attrs[LFACE_SWIDTH_INDEX] = AREF (pattern, FONT_SPEC_SWIDTH_INDEX);
6165#endif 6211#endif
6166 6212
6167 /* If C is an ASCII character, family name in ATTRS has higher 6213 if (NILP (attrs[LFACE_FAMILY_INDEX]))
6168 priority than what specified in the fontset. */
6169 if (STRINGP (attrs[LFACE_FAMILY_INDEX])
6170 && ASCII_CHAR_P (c))
6171 family = Qnil; 6214 family = Qnil;
6215 else
6216 family = Fcons (attrs[LFACE_FAMILY_INDEX], Qnil);
6217
6218 if (VECTORP (font_spec))
6219 {
6220 pattern = Qnil;
6221 if (STRINGP (AREF (font_spec, FONT_SPEC_FAMILY_INDEX)))
6222 family = Fcons (AREF (font_spec, FONT_SPEC_FAMILY_INDEX), family);
6223 adstyle = AREF (font_spec, FONT_SPEC_ADSTYLE_INDEX);
6224 registry = AREF (font_spec, FONT_SPEC_REGISTRY_INDEX);
6225 }
6226 else if (STRINGP (font_spec))
6227 {
6228 pattern = font_spec;
6229 family = Qnil;
6230 adstyle = Qnil;
6231 registry = Qnil;
6232 }
6233 else
6234 {
6235 pattern = Qnil;
6236 adstyle = Qnil;
6237 registry = build_string ("iso8859-1");
6238 }
6172 6239
6173 /* Get a list of fonts matching that pattern and choose the 6240 /* Get a list of fonts matching that pattern and choose the
6174 best match for the specified face attributes from it. */ 6241 best match for the specified face attributes from it. */
6175 nfonts = try_font_list (f, new_attrs, family, registry, &fonts); 6242 nfonts = try_font_list (f, pattern, family, registry, &fonts);
6176 width_ratio = (ASCII_CHAR_P (c) 6243 font_name = best_matching_font (f, attrs, fonts, nfonts, NILP (font_spec));
6177 ? 1
6178 : CHAR_WIDTH (c));
6179 font_name = best_matching_font (f, new_attrs, fonts, nfonts, width_ratio);
6180 return font_name; 6244 return font_name;
6181} 6245}
6182 6246
@@ -6334,7 +6398,7 @@ realize_default_face (f)
6334 xassert (lface_fully_specified_p (XVECTOR (lface)->contents)); 6398 xassert (lface_fully_specified_p (XVECTOR (lface)->contents));
6335 check_lface (lface); 6399 check_lface (lface);
6336 bcopy (XVECTOR (lface)->contents, attrs, sizeof attrs); 6400 bcopy (XVECTOR (lface)->contents, attrs, sizeof attrs);
6337 face = realize_face (c, attrs, 0, NULL, DEFAULT_FACE_ID); 6401 face = realize_face (c, attrs, DEFAULT_FACE_ID);
6338 return 1; 6402 return 1;
6339} 6403}
6340 6404
@@ -6373,23 +6437,19 @@ realize_named_face (f, symbol, id)
6373 merge_face_vectors (f, symbol_attrs, attrs, Qnil); 6437 merge_face_vectors (f, symbol_attrs, attrs, Qnil);
6374 6438
6375 /* Realize the face. */ 6439 /* Realize the face. */
6376 new_face = realize_face (c, attrs, 0, NULL, id); 6440 new_face = realize_face (c, attrs, id);
6377} 6441}
6378 6442
6379 6443
6380/* Realize the fully-specified face with attributes ATTRS in face 6444/* Realize the fully-specified face with attributes ATTRS in face
6381 cache CACHE for character C. If C is a multibyte character, 6445 cache CACHE for ASCII characters. If FORMER_FACE_ID is
6382 BASE_FACE is a face that has the same attributes. Otherwise, 6446 non-negative, it is an ID of face to remove before caching the new
6383 BASE_FACE is ignored. If FORMER_FACE_ID is non-negative, it is an 6447 face. Value is a pointer to the newly created realized face. */
6384 ID of face to remove before caching the new face. Value is a
6385 pointer to the newly created realized face. */
6386 6448
6387static struct face * 6449static struct face *
6388realize_face (cache, attrs, c, base_face, former_face_id) 6450realize_face (cache, attrs, former_face_id)
6389 struct face_cache *cache; 6451 struct face_cache *cache;
6390 Lisp_Object *attrs; 6452 Lisp_Object *attrs;
6391 int c;
6392 struct face *base_face;
6393 int former_face_id; 6453 int former_face_id;
6394{ 6454{
6395 struct face *face; 6455 struct face *face;
@@ -6407,37 +6467,73 @@ realize_face (cache, attrs, c, base_face, former_face_id)
6407 } 6467 }
6408 6468
6409 if (FRAME_WINDOW_P (cache->f)) 6469 if (FRAME_WINDOW_P (cache->f))
6410 face = realize_x_face (cache, attrs, c, base_face); 6470 face = realize_x_face (cache, attrs);
6411 else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f)) 6471 else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f))
6412 face = realize_tty_face (cache, attrs, c); 6472 face = realize_tty_face (cache, attrs);
6413 else 6473 else
6414 abort (); 6474 abort ();
6415 6475
6416 /* Insert the new face. */ 6476 /* Insert the new face. */
6417 cache_face (cache, face, lface_hash (attrs)); 6477 cache_face (cache, face, lface_hash (attrs));
6418#ifdef HAVE_WINDOW_SYSTEM 6478 return face;
6419 if (FRAME_WINDOW_P (cache->f) && face->font == NULL) 6479}
6420 load_face_font (cache->f, face, c); 6480
6421#endif /* HAVE_WINDOW_SYSTEM */ 6481
6482/* Realize the fully-specified face that has the same attributes as
6483 BASE_FACE except for the font on frame F. If FONT_ID is not
6484 negative, it is an ID number of an already opened font that should
6485 be used by the face. If FONT_ID is negative, the face has no font,
6486 i.e., characters are displayed by empty boxes. */
6487
6488static struct face *
6489realize_non_ascii_face (f, font_id, base_face)
6490 struct frame *f;
6491 int font_id;
6492 struct face *base_face;
6493{
6494 struct face_cache *cache = FRAME_FACE_CACHE (f);
6495 struct face *face;
6496 struct font_info *font_info;
6497
6498 face = (struct face *) xmalloc (sizeof *face);
6499 *face = *base_face;
6500 face->gc = 0;
6501
6502 /* Don't try to free the colors copied bitwise from BASE_FACE. */
6503 face->colors_copied_bitwise_p = 1;
6504
6505 face->font_info_id = font_id;
6506 if (font_id >= 0)
6507 {
6508 font_info = FONT_INFO_FROM_ID (f, font_id);
6509 face->font = font_info->font;
6510 face->font_name = font_info->full_name;
6511 }
6512 else
6513 {
6514 face->font = NULL;
6515 face->font_name = NULL;
6516 }
6517
6518 face->gc = 0;
6519
6520 cache_face (cache, face, face->hash);
6521
6422 return face; 6522 return face;
6423} 6523}
6424 6524
6425 6525
6426/* Realize the fully-specified face with attributes ATTRS in face 6526/* Realize the fully-specified face with attributes ATTRS in face
6427 cache CACHE for character C. Do it for X frame CACHE->f. If C is 6527 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
6428 a multibyte character, BASE_FACE is a face that has the same 6528 the new face doesn't share font with the default face, a fontname
6429 attributes. Otherwise, BASE_FACE is ignored. If the new face 6529 is allocated from the heap and set in `font_name' of the new face,
6430 doesn't share font with the default face, a fontname is allocated 6530 but it is not yet loaded here. Value is a pointer to the newly
6431 from the heap and set in `font_name' of the new face, but it is not 6531 created realized face. */
6432 yet loaded here. Value is a pointer to the newly created realized
6433 face. */
6434 6532
6435static struct face * 6533static struct face *
6436realize_x_face (cache, attrs, c, base_face) 6534realize_x_face (cache, attrs)
6437 struct face_cache *cache; 6535 struct face_cache *cache;
6438 Lisp_Object *attrs; 6536 Lisp_Object *attrs;
6439 int c;
6440 struct face *base_face;
6441{ 6537{
6442#ifdef HAVE_WINDOW_SYSTEM 6538#ifdef HAVE_WINDOW_SYSTEM
6443 struct face *face, *default_face; 6539 struct face *face, *default_face;
@@ -6445,50 +6541,24 @@ realize_x_face (cache, attrs, c, base_face)
6445 Lisp_Object stipple, overline, strike_through, box; 6541 Lisp_Object stipple, overline, strike_through, box;
6446 6542
6447 xassert (FRAME_WINDOW_P (cache->f)); 6543 xassert (FRAME_WINDOW_P (cache->f));
6448 xassert (SINGLE_BYTE_CHAR_P (c)
6449 || base_face);
6450 6544
6451 /* Allocate a new realized face. */ 6545 /* Allocate a new realized face. */
6452 face = make_realized_face (attrs); 6546 face = make_realized_face (attrs);
6547 face->ascii_face = face;
6453 6548
6454 f = cache->f; 6549 f = cache->f;
6455 6550
6456 /* If C is a non-ASCII character, we share all face attirbutes with
6457 BASE_FACE including the realized fontset. But, we must load a
6458 different font. */
6459 if (! ASCII_CHAR_P (c))
6460 {
6461 bcopy (base_face, face, sizeof *face);
6462 face->gc = 0;
6463
6464 /* Don't try to free the colors copied bitwise from BASE_FACE. */
6465 face->colors_copied_bitwise_p = 1;
6466
6467 /* to force realize_face to load font */
6468 face->font = NULL;
6469 return face;
6470 }
6471
6472 /* Now we are realizing a face for ASCII (and unibyte) characters. */
6473
6474 /* Determine the font to use. Most of the time, the font will be 6551 /* Determine the font to use. Most of the time, the font will be
6475 the same as the font of the default face, so try that first. */ 6552 the same as the font of the default face, so try that first. */
6476 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); 6553 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
6477 if (default_face 6554 if (default_face
6478 && FACE_SUITABLE_FOR_CHAR_P (default_face, c)
6479 && lface_same_font_attributes_p (default_face->lface, attrs)) 6555 && lface_same_font_attributes_p (default_face->lface, attrs))
6480 { 6556 {
6481 face->font = default_face->font; 6557 face->font = default_face->font;
6482 face->fontset = default_face->fontset;
6483 face->font_info_id = default_face->font_info_id; 6558 face->font_info_id = default_face->font_info_id;
6484 face->font_name = default_face->font_name; 6559 face->font_name = default_face->font_name;
6485 face->ascii_face = face;
6486
6487 /* But, as we can't share the fontset, make a new realized
6488 fontset that has the same base fontset as of the default
6489 face. */
6490 face->fontset 6560 face->fontset
6491 = make_fontset_for_ascii_face (f, default_face->fontset); 6561 = make_fontset_for_ascii_face (f, default_face->fontset, face);
6492 } 6562 }
6493 else 6563 else
6494 { 6564 {
@@ -6500,9 +6570,14 @@ realize_x_face (cache, attrs, c, base_face)
6500 are constructed from ATTRS. */ 6570 are constructed from ATTRS. */
6501 int fontset = face_fontset (attrs); 6571 int fontset = face_fontset (attrs);
6502 6572
6503 if ((fontset == -1) && default_face) 6573 /* If we are realizing the default face, ATTRS should specify a
6574 fontset. In other words, if FONTSET is -1, we are not
6575 realizing the default face, thus the default face should have
6576 already been realized. */
6577 if (fontset == -1)
6504 fontset = default_face->fontset; 6578 fontset = default_face->fontset;
6505 face->fontset = make_fontset_for_ascii_face (f, fontset); 6579 if (fontset == -1)
6580 abort ();
6506 face->font = NULL; /* to force realize_face to load font */ 6581 face->font = NULL; /* to force realize_face to load font */
6507 6582
6508#ifdef macintosh 6583#ifdef macintosh
@@ -6516,6 +6591,9 @@ realize_x_face (cache, attrs, c, base_face)
6516 face->font = font_info->font; 6591 face->font = font_info->font;
6517 } 6592 }
6518#endif 6593#endif
6594 if (! face->font)
6595 load_face_font (f, face);
6596 face->fontset = make_fontset_for_ascii_face (f, fontset, face);
6519 } 6597 }
6520 6598
6521 /* Load colors, and set remaining attributes. */ 6599 /* Load colors, and set remaining attributes. */
@@ -6740,14 +6818,13 @@ map_tty_color (f, face, idx, defaulted)
6740 6818
6741 6819
6742/* Realize the fully-specified face with attributes ATTRS in face 6820/* Realize the fully-specified face with attributes ATTRS in face
6743 cache CACHE for character C. Do it for TTY frame CACHE->f. Value is a 6821 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
6744 pointer to the newly created realized face. */ 6822 Value is a pointer to the newly created realized face. */
6745 6823
6746static struct face * 6824static struct face *
6747realize_tty_face (cache, attrs, c) 6825realize_tty_face (cache, attrs)
6748 struct face_cache *cache; 6826 struct face_cache *cache;
6749 Lisp_Object *attrs; 6827 Lisp_Object *attrs;
6750 int c;
6751{ 6828{
6752 struct face *face; 6829 struct face *face;
6753 int weight, slant; 6830 int weight, slant;
@@ -6845,10 +6922,15 @@ compute_char_face (f, ch, prop)
6845 else 6922 else
6846 { 6923 {
6847 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 6924 Lisp_Object attrs[LFACE_VECTOR_SIZE];
6848 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); 6925 struct face *face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
6849 bcopy (default_face->lface, attrs, sizeof attrs); 6926 bcopy (face->lface, attrs, sizeof attrs);
6850 merge_face_vector_with_property (f, attrs, prop); 6927 merge_face_vector_with_property (f, attrs, prop);
6851 face_id = lookup_face (f, attrs, ch, NULL); 6928 face_id = lookup_face (f, attrs);
6929 if (! ASCII_CHAR_P (ch))
6930 {
6931 face = FACE_FROM_ID (f, face_id);
6932 face_id = FACE_FOR_CHAR (f, face, ch);
6933 }
6852 } 6934 }
6853 6935
6854 return face_id; 6936 return face_id;
@@ -6982,7 +7064,7 @@ face_at_buffer_position (w, pos, region_beg, region_end,
6982 7064
6983 /* Look up a realized face with the given face attributes, 7065 /* Look up a realized face with the given face attributes,
6984 or realize a new one for ASCII characters. */ 7066 or realize a new one for ASCII characters. */
6985 return lookup_face (f, attrs, 0, NULL); 7067 return lookup_face (f, attrs);
6986} 7068}
6987 7069
6988 7070
@@ -7081,7 +7163,7 @@ face_at_string_position (w, string, pos, bufpos, region_beg,
7081 7163
7082 /* Look up a realized face with the given face attributes, 7164 /* Look up a realized face with the given face attributes,
7083 or realize a new one for ASCII characters. */ 7165 or realize a new one for ASCII characters. */
7084 return lookup_face (f, attrs, 0, NULL); 7166 return lookup_face (f, attrs);
7085} 7167}
7086 7168
7087 7169
@@ -7120,7 +7202,6 @@ dump_realized_face (face)
7120 face->underline_p, 7202 face->underline_p,
7121 XSTRING (Fsymbol_name (face->lface[LFACE_UNDERLINE_INDEX]))->data); 7203 XSTRING (Fsymbol_name (face->lface[LFACE_UNDERLINE_INDEX]))->data);
7122 fprintf (stderr, "hash: %d\n", face->hash); 7204 fprintf (stderr, "hash: %d\n", face->hash);
7123 fprintf (stderr, "charset: %d\n", face->charset);
7124} 7205}
7125 7206
7126 7207