/[emacs]/emacs/src/xfaces.c
ViewVC logotype

Diff of /emacs/src/xfaces.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.250.2.3 by fx, Thu May 9 17:57:26 2002 UTC revision 1.250.2.4 by handa, Fri Jul 26 04:07:39 2002 UTC
# Line 197  Boston, MA 02111-1307, USA.  */ Line 197  Boston, MA 02111-1307, USA.  */
197    
198  #include "lisp.h"  #include "lisp.h"
199  #include "character.h"  #include "character.h"
200    #include "charset.h"
201  #include "keyboard.h"  #include "keyboard.h"
202  #include "frame.h"  #include "frame.h"
203    
# Line 517  static int load_pixmap P_ ((struct frame Line 518  static int load_pixmap P_ ((struct frame
518  static unsigned char *xstrlwr P_ ((unsigned char *));  static unsigned char *xstrlwr P_ ((unsigned char *));
519  static void signal_error P_ ((char *, Lisp_Object));  static void signal_error P_ ((char *, Lisp_Object));
520  static struct frame *frame_or_selected_frame P_ ((Lisp_Object, int));  static struct frame *frame_or_selected_frame P_ ((Lisp_Object, int));
521  static void load_face_font P_ ((struct frame *, struct face *, int));  static void load_face_font P_ ((struct frame *, struct face *));
522  static void load_face_colors P_ ((struct frame *, struct face *, Lisp_Object *));  static void load_face_colors P_ ((struct frame *, struct face *, Lisp_Object *));
523  static void free_face_colors P_ ((struct frame *, struct face *));  static void free_face_colors P_ ((struct frame *, struct face *));
524  static int face_color_gray_p P_ ((struct frame *, char *));  static int face_color_gray_p P_ ((struct frame *, char *));
# Line 530  static int font_list_1 P_ ((struct frame Line 531  static int font_list_1 P_ ((struct frame
531                              Lisp_Object, struct font_name **));                              Lisp_Object, struct font_name **));
532  static int font_list P_ ((struct frame *, Lisp_Object, Lisp_Object,  static int font_list P_ ((struct frame *, Lisp_Object, Lisp_Object,
533                            Lisp_Object, struct font_name **));                            Lisp_Object, struct font_name **));
534  static int try_font_list P_ ((struct frame *, Lisp_Object *,  static int try_font_list P_ ((struct frame *, Lisp_Object,
535                                Lisp_Object, Lisp_Object, struct font_name **));                                Lisp_Object, Lisp_Object, struct font_name **));
536  static int try_alternative_families P_ ((struct frame *f, Lisp_Object,  static int try_alternative_families P_ ((struct frame *f, Lisp_Object,
537                                           Lisp_Object, struct font_name **));                                           Lisp_Object, struct font_name **));
538  static int cmp_font_names P_ ((const void *, const void *));  static int cmp_font_names P_ ((const void *, const void *));
539  static struct face *realize_face P_ ((struct face_cache *, Lisp_Object *, int,  static struct face *realize_face P_ ((struct face_cache *, Lisp_Object *,
540                                        struct face *, int));                                        int));
541  static struct face *realize_x_face P_ ((struct face_cache *,  static struct face *realize_non_ascii_face P_ ((struct frame *, int,
542                                          Lisp_Object *, int, struct face *));                                                  struct face *));
543  static struct face *realize_tty_face P_ ((struct face_cache *,  
544                                            Lisp_Object *, int));  static struct face *realize_x_face P_ ((struct face_cache *, Lisp_Object *));
545    static struct face *realize_tty_face P_ ((struct face_cache *, Lisp_Object *));
546  static int realize_basic_faces P_ ((struct frame *));  static int realize_basic_faces P_ ((struct frame *));
547  static int realize_default_face P_ ((struct frame *));  static int realize_default_face P_ ((struct frame *));
548  static void realize_named_face P_ ((struct frame *, Lisp_Object, int));  static void realize_named_face P_ ((struct frame *, Lisp_Object, int));
# Line 556  static int face_numeric_weight P_ ((Lisp Line 558  static int face_numeric_weight P_ ((Lisp
558  static int face_numeric_slant P_ ((Lisp_Object));  static int face_numeric_slant P_ ((Lisp_Object));
559  static int face_numeric_swidth P_ ((Lisp_Object));  static int face_numeric_swidth P_ ((Lisp_Object));
560  static int face_fontset P_ ((Lisp_Object *));  static int face_fontset P_ ((Lisp_Object *));
 static char *choose_face_font P_ ((struct frame *, Lisp_Object *,  
                                    struct face *, int));  
561  static void merge_face_vectors P_ ((struct frame *, Lisp_Object *, Lisp_Object*, Lisp_Object));  static void merge_face_vectors P_ ((struct frame *, Lisp_Object *, Lisp_Object*, Lisp_Object));
562  static void merge_face_inheritance P_ ((struct frame *f, Lisp_Object,  static void merge_face_inheritance P_ ((struct frame *f, Lisp_Object,
563                                          Lisp_Object *, Lisp_Object));                                          Lisp_Object *, Lisp_Object));
# Line 1251  frame_update_line_height (f) Line 1251  frame_update_line_height (f)
1251    
1252  #ifdef HAVE_WINDOW_SYSTEM  #ifdef HAVE_WINDOW_SYSTEM
1253    
1254  /* Load font of face FACE which is used on frame F to display  /* 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     characters.  The name of the font to load is determined by lface
1256     and fontset of FACE.  */     and fontset of FACE.  */
1257    
1258  static void  static void
1259  load_face_font (f, face, c)  load_face_font (f, face)
1260       struct frame *f;       struct frame *f;
1261       struct face *face;       struct face *face;
      int c;  
1262  {  {
1263    struct font_info *font_info = NULL;    struct font_info *font_info = NULL;
1264    char *font_name;    char *font_name;
1265    
1266    face->font_info_id = -1;    face->font_info_id = -1;
1267    face->font = NULL;    face->font = NULL;
1268      face->font_name = NULL;
1269    
1270    font_name = choose_face_font (f, face->lface, face, c);    font_name = choose_face_font (f, face->lface, Qnil);
1271    
1272    if (!font_name)    if (!font_name)
1273      return;      return;
# Line 2112  face_numeric_swidth (width) Line 2112  face_numeric_swidth (width)
2112  }  }
2113    
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    
2120  Lisp_Object  Lisp_Object
2121  generate_ascii_font (name, ascii_spec)  generate_ascii_font_name (name, ascii_spec)
2122       Lisp_Object name, ascii_spec;       Lisp_Object name, ascii_spec;
2123  {  {
2124    struct font_name font;    struct font_name font;
# Line 2167  generate_ascii_font (name, ascii_spec) Line 2172  generate_ascii_font (name, ascii_spec)
2172  }  }
2173    
2174    
2175    Lisp_Object
2176    font_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    
2190  #ifdef HAVE_WINDOW_SYSTEM  #ifdef HAVE_WINDOW_SYSTEM
2191    
2192  /* Return non-zero if FONT is the name of a fixed-pitch font.  */  /* Return non-zero if FONT is the name of a fixed-pitch font.  */
# Line 2610  cmp_font_names (a, b) Line 2630  cmp_font_names (a, b)
2630  }  }
2631    
2632    
2633  /* Get a sorted list of fonts of family FAMILY on frame F.  If PATTERN  /* Get a sorted list of fonts matching PATTERN.  If PATTERN is nil,
2634     is non-nil list fonts matching that pattern.  Otherwise, if     list fonts matching FAMILY and REGISTRY.  FAMILY is a family name
2635     REGISTRY is non-nil return only fonts with that registry, otherwise     string or nil.  REGISTRY is a registry name string.  Set *FONTS to
2636     return fonts of any registry.  Set *FONTS to a vector of font_name     a vector of font_name structures allocated from the heap containing
2637     structures allocated from the heap containing the fonts found.     the fonts found.  Value is the number of fonts found.  */
    Value is the number of fonts found.  */  
2638    
2639  static int  static int
2640  font_list_1 (f, pattern, family, registry, fonts)  font_list_1 (f, pattern, family, registry, fonts)
# Line 2676  concat_font_list (fonts1, nfonts1, fonts Line 2695  concat_font_list (fonts1, nfonts1, fonts
2695    
2696  /* Get a sorted list of fonts of family FAMILY on frame F.  /* Get a sorted list of fonts of family FAMILY on frame F.
2697    
2698     If PATTERN is non-nil list fonts matching that pattern.     If PATTERN is non-nil, list fonts matching that pattern.
2699    
2700     If REGISTRY is non-nil, return fonts with that registry and the     If REGISTRY is non-nil, return fonts with that registry and the
2701     alternative registries from Vface_alternative_font_registry_alist.     alternative registries from Vface_alternative_font_registry_alist.
# Line 2916  the WIDTH times as wide as FACE on FRAME Line 2935  the WIDTH times as wide as FACE on FRAME
2935      {      {
2936        /* This is of limited utility since it works with character        /* This is of limited utility since it works with character
2937           widths.  Keep it for compatibility.  --gerd.  */           widths.  Keep it for compatibility.  --gerd.  */
2938        int face_id = lookup_named_face (f, face, 0);        int face_id = lookup_named_face (f, face);
2939        struct face *face = (face_id < 0        struct face *face = (face_id < 0
2940                             ? NULL                             ? NULL
2941                             : FACE_FROM_ID (f, face_id));                             : FACE_FROM_ID (f, face_id));
# Line 3176  lface_fully_specified_p (attrs) Line 3195  lface_fully_specified_p (attrs)
3195     If the fullname is not in a valid XLFD format,     If the fullname is not in a valid XLFD format,
3196          return 0 if MAY_FAIL_P is non-zero, otherwise set normal values          return 0 if MAY_FAIL_P is non-zero, otherwise set normal values
3197          in LFACE and return 1.          in LFACE and return 1.
3198     Otherwise, return 1.  */     Otherwise, return 1.
3199    
3200       Currently this function is always called with both FORCE_P and
3201       MAIL_FAIL_P non-zero.  */
3202    
3203  static int  static int
3204  set_lface_from_font_name (f, lface, fontname, force_p, may_fail_p)  set_lface_from_font_name (f, lface, fontname, force_p, may_fail_p)
# Line 4307  set_font_frame_param (frame, lface) Line 4329  set_font_frame_param (frame, lface)
4329            /* Choose a font name that reflects LFACE's attributes and has            /* Choose a font name that reflects LFACE's attributes and has
4330               the registry and encoding pattern specified in the default               the registry and encoding pattern specified in the default
4331               fontset (3rd arg: -1) for ASCII characters (4th arg: 0).  */               fontset (3rd arg: -1) for ASCII characters (4th arg: 0).  */
4332            font = choose_face_font (f, XVECTOR (lface)->contents, NULL, 0);            font = choose_face_font (f, XVECTOR (lface)->contents, Qnil);
4333            if (!font)            if (!font)
4334              error ("No font matches the specified attribute");              error ("No font matches the specified attribute");
4335            font_name = build_string (font);            font_name = build_string (font);
# Line 4784  If FRAME is omitted or nil, use the sele Line 4806  If FRAME is omitted or nil, use the sele
4806    else    else
4807      {      {
4808        struct frame *f = frame_or_selected_frame (frame, 1);        struct frame *f = frame_or_selected_frame (frame, 1);
4809        int face_id = lookup_named_face (f, face, 0);        int face_id = lookup_named_face (f, face);
4810        struct face *face = FACE_FROM_ID (f, face_id);        struct face *face = FACE_FROM_ID (f, face_id);
4811        return face ? build_string (face->font_name) : Qnil;        return face ? build_string (face->font_name) : Qnil;
4812      }      }
# Line 5248  free_face_cache (c) Line 5270  free_face_cache (c)
5270    
5271    
5272  /* Cache realized face FACE in face cache C.  HASH is the hash value  /* Cache realized face FACE in face cache C.  HASH is the hash value
5273     of FACE.  If FACE->fontset >= 0, add the new face to the end of the     of FACE.  If FACE is for ASCII characters (i.e. FACE->ascii_face ==
5274     collision list of the face hash table of C.  This is done because     FACE), insert the new face to the beginning of the collision list
5275     otherwise lookup_face would find FACE for every character, even if     of the face hash table of C.  Otherwise, add the new face to the
5276     faces with the same attributes but for specific characters exist.  */     end of the collision list.  This way, lookup_face can quickly find
5277       that a requested face is not cached.  */
5278    
5279  static void  static void
5280  cache_face (c, face, hash)  cache_face (c, face, hash)
# Line 5263  cache_face (c, face, hash) Line 5286  cache_face (c, face, hash)
5286    
5287    face->hash = hash;    face->hash = hash;
5288    
5289    if (face->fontset >= 0)    if (face->ascii_face != face)
5290      {      {
5291        struct face *last = c->buckets[i];        struct face *last = c->buckets[i];
5292        if (last)        if (last)
# Line 5350  uncache_face (c, face) Line 5373  uncache_face (c, face)
5373    
5374    
5375  /* Look up a realized face with face attributes ATTR in the face cache  /* Look up a realized face with face attributes ATTR in the face cache
5376     of frame F.  The face will be used to display character C.  Value     of frame F.  The face will be used to display ASCII characters.
5377     is the ID of the face found.  If no suitable face is found, realize     Value is the ID of the face found.  If no suitable face is found,
5378     a new one.  In that case, if C is a multibyte character, BASE_FACE     realize a new one.  */
    is a face that has the same attributes.  */  
5379    
5380  INLINE int  INLINE int
5381  lookup_face (f, attr, c, base_face)  lookup_face (f, attr)
5382       struct frame *f;       struct frame *f;
5383       Lisp_Object *attr;       Lisp_Object *attr;
      int c;  
      struct face *base_face;  
5384  {  {
5385    struct face_cache *cache = FRAME_FACE_CACHE (f);    struct face_cache *cache = FRAME_FACE_CACHE (f);
5386    unsigned hash;    unsigned hash;
# Line 5375  lookup_face (f, attr, c, base_face) Line 5395  lookup_face (f, attr, c, base_face)
5395    i = hash % FACE_CACHE_BUCKETS_SIZE;    i = hash % FACE_CACHE_BUCKETS_SIZE;
5396    
5397    for (face = cache->buckets[i]; face; face = face->next)    for (face = cache->buckets[i]; face; face = face->next)
5398      if (face->hash == hash      {
5399          && (!FRAME_WINDOW_P (f)        if (face->ascii_face != face)
5400              || FACE_SUITABLE_FOR_CHAR_P (face, c))          {
5401          && lface_equal_p (face->lface, attr))            /* There's no more ASCII face.  */
5402        break;            face = NULL;
5403              break;
5404            }
5405          if (face->hash == hash
5406              && lface_equal_p (face->lface, attr))
5407            break;
5408        }
5409    
5410    /* If not found, realize a new face.  */    /* If not found, realize a new face.  */
5411    if (face == NULL)    if (face == NULL)
5412      face = realize_face (cache, attr, c, base_face, -1);      face = realize_face (cache, attr, -1);
5413    
5414  #if GLYPH_DEBUG  #if GLYPH_DEBUG
5415    xassert (face == FACE_FROM_ID (f, face->id));    xassert (face == FACE_FROM_ID (f, face->id));
5416    #endif /* GLYPH_DEBUG */
5417    
5418  /* When this function is called from face_for_char (in this case, C is    return face->id;
5419     a multibyte character), a fontset of a face returned by  }
5420     realize_face is not yet set, i.e. FACE_SUITABLE_FOR_CHAR_P (FACE,  
5421     C) is not sutisfied.  The fontset is set for this face by  
5422     face_for_char later.  */  /* Look up a realized face that has the same attributes as BASE_FACE
5423  #if 0     except for the font in the face cache of frame F.  If FONT_ID is
5424    if (FRAME_WINDOW_P (f))     not negative, it is an ID number of an already opened font that is
5425      xassert (FACE_SUITABLE_FOR_CHAR_P (face, c));     used by the face.  If FONT_ID is negative, the face has no font.
5426  #endif     Value is the ID of the face found.  If no suitable face is found,
5427       realize a new one.  */
5428    
5429    INLINE int
5430    lookup_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));
5460  #endif /* GLYPH_DEBUG */  #endif /* GLYPH_DEBUG */
5461    
5462    return face->id;    return face->id;
# Line 5404  lookup_face (f, attr, c, base_face) Line 5464  lookup_face (f, attr, c, base_face)
5464    
5465    
5466  /* Return the face id of the realized face for named face SYMBOL on  /* Return the face id of the realized face for named face SYMBOL on
5467     frame F suitable for displaying character C.  Value is -1 if the     frame F suitable for displaying ASCII characters.  Value is -1 if
5468     face couldn't be determined, which might happen if the default face     the face couldn't be determined, which might happen if the default
5469     isn't realized and cannot be realized.  */     face isn't realized and cannot be realized.  */
5470    
5471  int  int
5472  lookup_named_face (f, symbol, c)  lookup_named_face (f, symbol)
5473       struct frame *f;       struct frame *f;
5474       Lisp_Object symbol;       Lisp_Object symbol;
      int c;  
5475  {  {
5476    Lisp_Object attrs[LFACE_VECTOR_SIZE];    Lisp_Object attrs[LFACE_VECTOR_SIZE];
5477    Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];    Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];
# Line 5428  lookup_named_face (f, symbol, c) Line 5487  lookup_named_face (f, symbol, c)
5487    get_lface_attributes (f, symbol, symbol_attrs, 1);    get_lface_attributes (f, symbol, symbol_attrs, 1);
5488    bcopy (default_face->lface, attrs, sizeof attrs);    bcopy (default_face->lface, attrs, sizeof attrs);
5489    merge_face_vectors (f, symbol_attrs, attrs, Qnil);    merge_face_vectors (f, symbol_attrs, attrs, Qnil);
5490    return lookup_face (f, attrs, c, NULL);    return lookup_face (f, attrs);
5491  }  }
5492    
5493    
# Line 5445  ascii_face_of_lisp_face (f, lface_id) Line 5504  ascii_face_of_lisp_face (f, lface_id)
5504    if (lface_id >= 0 && lface_id < lface_id_to_name_size)    if (lface_id >= 0 && lface_id < lface_id_to_name_size)
5505      {      {
5506        Lisp_Object face_name = lface_id_to_name[lface_id];        Lisp_Object face_name = lface_id_to_name[lface_id];
5507        face_id = lookup_named_face (f, face_name, 0);        face_id = lookup_named_face (f, face_name);
5508      }      }
5509    else    else
5510      face_id = -1;      face_id = -1;
# Line 5493  smaller_face (f, face_id, steps) Line 5552  smaller_face (f, face_id, steps)
5552        /* Look up a face for a slightly smaller/larger font.  */        /* Look up a face for a slightly smaller/larger font.  */
5553        pt += delta;        pt += delta;
5554        attrs[LFACE_HEIGHT_INDEX] = make_number (pt);        attrs[LFACE_HEIGHT_INDEX] = make_number (pt);
5555        new_face_id = lookup_face (f, attrs, 0, NULL);        new_face_id = lookup_face (f, attrs);
5556        new_face = FACE_FROM_ID (f, new_face_id);        new_face = FACE_FROM_ID (f, new_face_id);
5557    
5558        /* If height changes, count that as one step.  */        /* If height changes, count that as one step.  */
# Line 5536  face_with_height (f, face_id, height) Line 5595  face_with_height (f, face_id, height)
5595    face = FACE_FROM_ID (f, face_id);    face = FACE_FROM_ID (f, face_id);
5596    bcopy (face->lface, attrs, sizeof attrs);    bcopy (face->lface, attrs, sizeof attrs);
5597    attrs[LFACE_HEIGHT_INDEX] = make_number (height);    attrs[LFACE_HEIGHT_INDEX] = make_number (height);
5598    face_id = lookup_face (f, attrs, 0, NULL);    face_id = lookup_face (f, attrs);
5599  #endif /* HAVE_WINDOW_SYSTEM */  #endif /* HAVE_WINDOW_SYSTEM */
5600    
5601    return face_id;    return face_id;
# Line 5544  face_with_height (f, face_id, height) Line 5603  face_with_height (f, face_id, height)
5603    
5604    
5605  /* Return the face id of the realized face for named face SYMBOL on  /* Return the face id of the realized face for named face SYMBOL on
5606     frame F suitable for displaying character C, and use attributes of     frame F suitable for displaying ASCII characters, and use
5607     the face FACE_ID for attributes that aren't completely specified by     attributes of the face FACE_ID for attributes that aren't
5608     SYMBOL.  This is like lookup_named_face, except that the default     completely specified by SYMBOL.  This is like lookup_named_face,
5609     attributes come from FACE_ID, not from the default face.  FACE_ID     except that the default attributes come from FACE_ID, not from the
5610     is assumed to be already realized.  */     default face.  FACE_ID is assumed to be already realized.  */
5611    
5612  int  int
5613  lookup_derived_face (f, symbol, c, face_id)  lookup_derived_face (f, symbol, face_id)
5614       struct frame *f;       struct frame *f;
5615       Lisp_Object symbol;       Lisp_Object symbol;
      int c;  
5616       int face_id;       int face_id;
5617  {  {
5618    Lisp_Object attrs[LFACE_VECTOR_SIZE];    Lisp_Object attrs[LFACE_VECTOR_SIZE];
# Line 5567  lookup_derived_face (f, symbol, c, face_ Line 5625  lookup_derived_face (f, symbol, c, face_
5625    get_lface_attributes (f, symbol, symbol_attrs, 1);    get_lface_attributes (f, symbol, symbol_attrs, 1);
5626    bcopy (default_face->lface, attrs, sizeof attrs);    bcopy (default_face->lface, attrs, sizeof attrs);
5627    merge_face_vectors (f, symbol_attrs, attrs, Qnil);    merge_face_vectors (f, symbol_attrs, attrs, Qnil);
5628    return lookup_face (f, attrs, c, default_face);    return lookup_face (f, attrs);
5629  }  }
5630    
5631  DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector,  DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector,
# Line 6051  try_alternative_families (f, family, reg Line 6109  try_alternative_families (f, family, reg
6109    
6110  /* Get a list of matching fonts on frame F.  /* Get a list of matching fonts on frame F.
6111    
6112     FAMILY, if a string, specifies a font family derived from the fontset.     PATTERN, if a string, specifies a font name pattern to match while
6113     It is only used if the face does not specify any family in ATTRS or     ignoring FAMILY and REGISTRY.
    if we cannot find any font of the face's family.  
6114    
6115     REGISTRY, if a string, specifies a font registry and encoding to     FAMILY, if a list, specifies a list of font families to try.
6116     match.  A value of nil means include fonts of any registry and  
6117     encoding.     REGISTRY, if a list, specifies a list of font registries and
6118       encodinging to try.
6119        
6120     Return in *FONTS a pointer to a vector of font_name structures for     Return in *FONTS a pointer to a vector of font_name structures for
6121     the fonts matched.  Value is the number of fonts found.  */     the fonts matched.  Value is the number of fonts found.  */
6122    
6123  static int  static int
6124  try_font_list (f, attrs, family, registry, fonts)  try_font_list (f, pattern, family, registry, fonts)
6125       struct frame *f;       struct frame *f;
      Lisp_Object *attrs;  
6126       Lisp_Object family, registry;       Lisp_Object family, registry;
6127       struct font_name **fonts;       struct font_name **fonts;
6128  {  {
6129    int nfonts = 0;    int nfonts = 0;
   Lisp_Object face_family = attrs[LFACE_FAMILY_INDEX];  
   
   if (!NILP (family))  
     nfonts = try_alternative_families (f, family, registry, fonts);  
   
   if (nfonts == 0 && STRINGP (face_family))  
     nfonts = try_alternative_families (f, face_family, registry, fonts);  
6130    
6131    /* Try font family of the default face or "fixed".  */    if (STRINGP (pattern))
6132    if (nfonts == 0)      nfonts = font_list (f, pattern, Qnil, Qnil, fonts);
6133      else
6134      {      {
6135        struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);        Lisp_Object tail;
6136        if (default_face)  
6137          family = default_face->lface[LFACE_FAMILY_INDEX];        if (NILP (family))
6138            nfonts = font_list (f, Qnil, Qnil, registry, fonts);
6139        else        else
6140          family = build_string ("fixed");          for (tail = family; ! nfonts && CONSP (tail); tail = XCDR (tail))
6141        nfonts = font_list (f, Qnil, family, registry, fonts);            nfonts = try_alternative_families (f, XCAR (tail), registry, fonts);
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            }
6153                
6154    /* Try any family with the given registry.  */        /* Try any family with the given registry.  */
6155    if (nfonts == 0)        if (nfonts == 0 && !NILP (family))
6156      nfonts = font_list (f, Qnil, Qnil, registry, fonts);          nfonts = font_list (f, Qnil, Qnil, registry, fonts);
6157        }
6158    
6159    return nfonts;    return nfonts;
6160  }  }
# Line 6114  face_fontset (attrs) Line 6177  face_fontset (attrs)
6177  }  }
6178    
6179    
6180  /* Choose a name of font to use on frame F to display character C with  /* Choose a name of font to use on frame F to display characters with
6181     Lisp face attributes specified by ATTRS.  The font name is     Lisp face attributes specified by ATTRS.  The font name is
6182     determined by the font-related attributes in ATTRS and the name     determined by the font-related attributes in ATTRS and FONT-SPEC
6183     pattern for C in FACE->fontset (or Vdefault_fontset if FACE is     (if specified).
    null).  Value is the font name which is allocated from the heap and  
    must be freed by the caller, or NULL if we can get no information  
    about the font name of C.  It is assured that we always get some  
    information for a single byte character.  */  
6184    
6185  static char *     When we are choosing a font for ASCII characters, FONT-SPEC is
6186  choose_face_font (f, attrs, face, c)     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    
6193    char *
6194    choose_face_font (f, attrs, font_spec)
6195       struct frame *f;       struct frame *f;
6196       Lisp_Object *attrs;       Lisp_Object *attrs;
6197       struct face *face;       Lisp_Object font_spec;
      int c;  
6198  {  {
6199    Lisp_Object val;    Lisp_Object val;
6200    Lisp_Object pattern, family, registry;    Lisp_Object pattern, family, adstyle, registry;
6201    Lisp_Object new_attrs[LFACE_VECTOR_SIZE];    Lisp_Object new_attrs[LFACE_VECTOR_SIZE];
6202    char *font_name = NULL;    char *font_name = NULL;
6203    struct font_name *fonts;    struct font_name *fonts;
6204    int nfonts, width_ratio;    int nfonts;
   
   /* Get font spec of a font for C.  */  
   pattern = fontset_font_pattern (f, face, c);  
   if (NILP (pattern))  
     {  
       xassert (!SINGLE_BYTE_CHAR_P (c));  
       return NULL;  
     }  
     
   /* If what we got is a name pattern, return it.  */  
   if (STRINGP (pattern))  
     return xstrdup (XSTRING (pattern)->data);  
   
   family = AREF (pattern, FONT_SPEC_FAMILY_INDEX);  
   registry = AREF (pattern, FONT_SPEC_REGISTRY_INDEX);  
   
   bcopy (attrs, new_attrs, sizeof (Lisp_Object) * LFACE_VECTOR_SIZE);  
6205    
6206      /* If we are choosing an ASCII font and a font name is explicitly
6207         specified in ATTRS, return it.  */
6208  #if 0  #if 0
6209    /* This doesn't work well for the moment.  */    if (NILP (font_spec) && STRINGP (attrs[LFACE_FONT_INDEX]))
6210    if (! NILP (AREF (pattern, FONT_SPEC_WEIGHT_INDEX)))      return xstrdup (XSTRING (attrs[LFACE_FONT_INDEX])->data);
     new_attrs[LFACE_WEIGHT_INDEX] = AREF (pattern, FONT_SPEC_WEIGHT_INDEX);  
   if (! NILP (AREF (pattern, FONT_SPEC_SLANT_INDEX)))  
     new_attrs[LFACE_SLANT_INDEX] = AREF (pattern, FONT_SPEC_SLANT_INDEX);  
   if (! NILP (AREF (pattern, FONT_SPEC_SWIDTH_INDEX)))  
     new_attrs[LFACE_SWIDTH_INDEX] = AREF (pattern, FONT_SPEC_SWIDTH_INDEX);  
6211  #endif  #endif
6212    
6213    /* If C is an ASCII character, family name in ATTRS has higher    if (NILP (attrs[LFACE_FAMILY_INDEX]))
      priority than what specified in the fontset.  */  
   if (STRINGP (attrs[LFACE_FAMILY_INDEX])  
       && ASCII_CHAR_P (c))  
6214      family = Qnil;      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        }
6239    
6240    /* Get a list of fonts matching that pattern and choose the    /* Get a list of fonts matching that pattern and choose the
6241       best match for the specified face attributes from it.  */       best match for the specified face attributes from it.  */
6242    nfonts = try_font_list (f, new_attrs, family, registry, &fonts);    nfonts = try_font_list (f, pattern, family, registry, &fonts);
6243    width_ratio = (ASCII_CHAR_P (c)    font_name = best_matching_font (f, attrs, fonts, nfonts, NILP (font_spec));
                  ? 1  
                  : CHAR_WIDTH (c));  
   font_name = best_matching_font (f, new_attrs, fonts, nfonts, width_ratio);  
6244    return font_name;    return font_name;
6245  }  }
6246    
# Line 6334  realize_default_face (f) Line 6398  realize_default_face (f)
6398    xassert (lface_fully_specified_p (XVECTOR (lface)->contents));    xassert (lface_fully_specified_p (XVECTOR (lface)->contents));
6399    check_lface (lface);    check_lface (lface);
6400    bcopy (XVECTOR (lface)->contents, attrs, sizeof attrs);    bcopy (XVECTOR (lface)->contents, attrs, sizeof attrs);
6401    face = realize_face (c, attrs, 0, NULL, DEFAULT_FACE_ID);    face = realize_face (c, attrs, DEFAULT_FACE_ID);
6402    return 1;    return 1;
6403  }  }
6404    
# Line 6373  realize_named_face (f, symbol, id) Line 6437  realize_named_face (f, symbol, id)
6437    merge_face_vectors (f, symbol_attrs, attrs, Qnil);    merge_face_vectors (f, symbol_attrs, attrs, Qnil);
6438    
6439    /* Realize the face.  */    /* Realize the face.  */
6440    new_face = realize_face (c, attrs, 0, NULL, id);    new_face = realize_face (c, attrs, id);
6441  }  }
6442    
6443    
6444  /* Realize the fully-specified face with attributes ATTRS in face  /* Realize the fully-specified face with attributes ATTRS in face
6445     cache CACHE for character C.  If C is a multibyte character,     cache CACHE for ASCII characters.  If FORMER_FACE_ID is
6446     BASE_FACE is a face that has the same attributes.  Otherwise,     non-negative, it is an ID of face to remove before caching the new
6447     BASE_FACE is ignored.  If FORMER_FACE_ID is non-negative, it is an     face.  Value is a pointer to the newly created realized face.  */
    ID of face to remove before caching the new face.  Value is a  
    pointer to the newly created realized face.  */  
6448    
6449  static struct face *  static struct face *
6450  realize_face (cache, attrs, c, base_face, former_face_id)  realize_face (cache, attrs, former_face_id)
6451       struct face_cache *cache;       struct face_cache *cache;
6452       Lisp_Object *attrs;       Lisp_Object *attrs;
      int c;  
      struct face *base_face;  
6453       int former_face_id;       int former_face_id;
6454  {  {
6455    struct face *face;    struct face *face;
# Line 6407  realize_face (cache, attrs, c, base_face Line 6467  realize_face (cache, attrs, c, base_face
6467      }      }
6468    
6469    if (FRAME_WINDOW_P (cache->f))    if (FRAME_WINDOW_P (cache->f))
6470      face = realize_x_face (cache, attrs, c, base_face);      face = realize_x_face (cache, attrs);
6471    else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f))    else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f))
6472      face = realize_tty_face (cache, attrs, c);      face = realize_tty_face (cache, attrs);
6473    else    else
6474      abort ();      abort ();
6475    
6476    /* Insert the new face.  */    /* Insert the new face.  */
6477    cache_face (cache, face, lface_hash (attrs));    cache_face (cache, face, lface_hash (attrs));
6478  #ifdef HAVE_WINDOW_SYSTEM    return face;
6479    if (FRAME_WINDOW_P (cache->f) && face->font == NULL)  }
6480      load_face_font (cache->f, face, c);  
6481  #endif  /* HAVE_WINDOW_SYSTEM */  
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    
6488    static struct face *
6489    realize_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    
6522    return face;    return face;
6523  }  }
6524    
6525    
6526  /* Realize the fully-specified face with attributes ATTRS in face  /* Realize the fully-specified face with attributes ATTRS in face
6527     cache CACHE for character C.  Do it for X frame CACHE->f.  If C is     cache CACHE for ASCII characters.  Do it for X frame CACHE->f.  If
6528     a multibyte character, BASE_FACE is a face that has the same     the new face doesn't share font with the default face, a fontname
6529     attributes.  Otherwise, BASE_FACE is ignored.  If the new face     is allocated from the heap and set in `font_name' of the new face,
6530     doesn't share font with the default face, a fontname is allocated     but it is not yet loaded here.  Value is a pointer to the newly
6531     from the heap and set in `font_name' of the new face, but it is not     created realized face.  */
    yet loaded here.  Value is a pointer to the newly created realized  
    face.  */  
6532    
6533  static struct face *  static struct face *
6534  realize_x_face (cache, attrs, c, base_face)  realize_x_face (cache, attrs)
6535       struct face_cache *cache;       struct face_cache *cache;
6536       Lisp_Object *attrs;       Lisp_Object *attrs;
      int c;  
      struct face *base_face;  
6537  {  {
6538  #ifdef HAVE_WINDOW_SYSTEM  #ifdef HAVE_WINDOW_SYSTEM
6539    struct face *face, *default_face;    struct face *face, *default_face;
# Line 6445  realize_x_face (cache, attrs, c, base_fa Line 6541  realize_x_face (cache, attrs, c, base_fa
6541    Lisp_Object stipple, overline, strike_through, box;    Lisp_Object stipple, overline, strike_through, box;
6542    
6543    xassert (FRAME_WINDOW_P (cache->f));    xassert (FRAME_WINDOW_P (cache->f));
   xassert (SINGLE_BYTE_CHAR_P (c)  
            || base_face);  
6544    
6545    /* Allocate a new realized face.  */    /* Allocate a new realized face.  */
6546    face = make_realized_face (attrs);    face = make_realized_face (attrs);
6547      face->ascii_face = face;
6548    
6549    f = cache->f;    f = cache->f;
6550    
   /* If C is a non-ASCII character, we share all face attirbutes with  
      BASE_FACE including the realized fontset.  But, we must load a  
      different font.  */  
   if (! ASCII_CHAR_P (c))  
     {  
       bcopy (base_face, face, sizeof *face);  
       face->gc = 0;  
   
       /* Don't try to free the colors copied bitwise from BASE_FACE.  */  
       face->colors_copied_bitwise_p = 1;  
   
       /* to force realize_face to load font */  
       face->font = NULL;  
       return face;  
     }  
   
   /* Now we are realizing a face for ASCII (and unibyte) characters.  */  
   
6551    /* Determine the font to use.  Most of the time, the font will be    /* Determine the font to use.  Most of the time, the font will be
6552       the same as the font of the default face, so try that first.  */       the same as the font of the default face, so try that first.  */
6553    default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);    default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
6554    if (default_face    if (default_face
       && FACE_SUITABLE_FOR_CHAR_P (default_face, c)  
6555        && lface_same_font_attributes_p (default_face->lface, attrs))        && lface_same_font_attributes_p (default_face->lface, attrs))
6556      {      {
6557        face->font = default_face->font;        face->font = default_face->font;
       face->fontset = default_face->fontset;  
6558        face->font_info_id = default_face->font_info_id;        face->font_info_id = default_face->font_info_id;
6559        face->font_name = default_face->font_name;        face->font_name = default_face->font_name;
       face->ascii_face = face;  
   
       /* But, as we can't share the fontset, make a new realized  
          fontset that has the same base fontset as of the default  
          face.  */  
6560        face->fontset        face->fontset
6561          = make_fontset_for_ascii_face (f, default_face->fontset);          = make_fontset_for_ascii_face (f, default_face->fontset, face);
6562      }      }
6563    else    else
6564      {      {
# Line 6500  realize_x_face (cache, attrs, c, base_fa Line 6570  realize_x_face (cache, attrs, c, base_fa
6570           are constructed from ATTRS.  */           are constructed from ATTRS.  */
6571        int fontset = face_fontset (attrs);        int fontset = face_fontset (attrs);
6572    
6573        if ((fontset == -1) && default_face)        /* 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)
6578          fontset = default_face->fontset;          fontset = default_face->fontset;
6579        face->fontset = make_fontset_for_ascii_face (f, fontset);        if (fontset == -1)
6580            abort ();
6581        face->font = NULL;        /* to force realize_face to load font */        face->font = NULL;        /* to force realize_face to load font */
6582    
6583  #ifdef macintosh  #ifdef macintosh
# Line 6516  realize_x_face (cache, attrs, c, base_fa Line 6591  realize_x_face (cache, attrs, c, base_fa
6591              face->font = font_info->font;              face->font = font_info->font;
6592          }          }
6593  #endif  #endif
6594          if (! face->font)
6595            load_face_font (f, face);
6596          face->fontset = make_fontset_for_ascii_face (f, fontset, face);
6597      }      }
6598    
6599    /* Load colors, and set remaining attributes.  */    /* Load colors, and set remaining attributes.  */
# Line 6740  map_tty_color (f, face, idx, defaulted) Line 6818  map_tty_color (f, face, idx, defaulted)
6818    
6819    
6820  /* Realize the fully-specified face with attributes ATTRS in face  /* Realize the fully-specified face with attributes ATTRS in face
6821     cache CACHE for character C.  Do it for TTY frame CACHE->f.  Value is a     cache CACHE for ASCII characters.  Do it for TTY frame CACHE->f.
6822     pointer to the newly created realized face.  */     Value is a pointer to the newly created realized face.  */
6823    
6824  static struct face *  static struct face *
6825  realize_tty_face (cache, attrs, c)  realize_tty_face (cache, attrs)
6826       struct face_cache *cache;       struct face_cache *cache;
6827       Lisp_Object *attrs;       Lisp_Object *attrs;
      int c;  
6828  {  {
6829    struct face *face;    struct face *face;
6830    int weight, slant;    int weight, slant;
# Line 6845  compute_char_face (f, ch, prop) Line 6922  compute_char_face (f, ch, prop)
6922    else    else
6923      {      {
6924        Lisp_Object attrs[LFACE_VECTOR_SIZE];        Lisp_Object attrs[LFACE_VECTOR_SIZE];
6925        struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);        struct face *face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
6926        bcopy (default_face->lface, attrs, sizeof attrs);        bcopy (face->lface, attrs, sizeof attrs);
6927        merge_face_vector_with_property (f, attrs, prop);        merge_face_vector_with_property (f, attrs, prop);
6928        face_id = lookup_face (f, attrs, ch, NULL);        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            }
6934      }      }
6935    
6936    return face_id;    return face_id;
# Line 6982  face_at_buffer_position (w, pos, region_ Line 7064  face_at_buffer_position (w, pos, region_
7064    
7065    /* Look up a realized face with the given face attributes,    /* Look up a realized face with the given face attributes,
7066       or realize a new one for ASCII characters.  */       or realize a new one for ASCII characters.  */
7067    return lookup_face (f, attrs, 0, NULL);    return lookup_face (f, attrs);
7068  }  }
7069    
7070    
# Line 7081  face_at_string_position (w, string, pos, Line 7163  face_at_string_position (w, string, pos,
7163    
7164    /* Look up a realized face with the given face attributes,    /* Look up a realized face with the given face attributes,
7165       or realize a new one for ASCII characters.  */       or realize a new one for ASCII characters.  */
7166    return lookup_face (f, attrs, 0, NULL);    return lookup_face (f, attrs);
7167  }  }
7168    
7169    
# Line 7120  dump_realized_face (face) Line 7202  dump_realized_face (face)
7202             face->underline_p,             face->underline_p,
7203             XSTRING (Fsymbol_name (face->lface[LFACE_UNDERLINE_INDEX]))->data);             XSTRING (Fsymbol_name (face->lface[LFACE_UNDERLINE_INDEX]))->data);
7204    fprintf (stderr, "hash: %d\n", face->hash);    fprintf (stderr, "hash: %d\n", face->hash);
   fprintf (stderr, "charset: %d\n", face->charset);  
7205  }  }
7206    
7207    

Legend:
Removed from v.1.250.2.3  
changed lines
  Added in v.1.250.2.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26