/[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 by rms, Wed Feb 13 16:21:07 2002 UTC revision 1.250.2.1 by handa, Fri Mar 1 01:49:55 2002 UTC
# Line 196  Boston, MA 02111-1307, USA.  */ Line 196  Boston, MA 02111-1307, USA.  */
196  #include <sys/stat.h>  #include <sys/stat.h>
197    
198  #include "lisp.h"  #include "lisp.h"
199  #include "charset.h"  #include "character.h"
200  #include "keyboard.h"  #include "keyboard.h"
201  #include "frame.h"  #include "frame.h"
202    
# Line 550  static unsigned hash_string_case_insensi Line 550  static unsigned hash_string_case_insensi
550  static unsigned lface_hash P_ ((Lisp_Object *));  static unsigned lface_hash P_ ((Lisp_Object *));
551  static int lface_same_font_attributes_p P_ ((Lisp_Object *, Lisp_Object *));  static int lface_same_font_attributes_p P_ ((Lisp_Object *, Lisp_Object *));
552  static struct face_cache *make_face_cache P_ ((struct frame *));  static struct face_cache *make_face_cache P_ ((struct frame *));
 static void free_realized_face P_ ((struct frame *, struct face *));  
553  static void clear_face_gcs P_ ((struct face_cache *));  static void clear_face_gcs P_ ((struct face_cache *));
554  static void free_face_cache P_ ((struct face_cache *));  static void free_face_cache P_ ((struct face_cache *));
555  static int face_numeric_weight P_ ((Lisp_Object));  static int face_numeric_weight P_ ((Lisp_Object));
556  static int face_numeric_slant P_ ((Lisp_Object));  static int face_numeric_slant P_ ((Lisp_Object));
557  static int face_numeric_swidth P_ ((Lisp_Object));  static int face_numeric_swidth P_ ((Lisp_Object));
558  static int face_fontset P_ ((Lisp_Object *));  static int face_fontset P_ ((Lisp_Object *));
559  static char *choose_face_font P_ ((struct frame *, Lisp_Object *, int, int));  static char *choose_face_font P_ ((struct frame *, Lisp_Object *,
560                                       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 567  static int set_lface_from_font_name P_ ( Line 567  static int set_lface_from_font_name P_ (
567                                           Lisp_Object, int, int));                                           Lisp_Object, int, int));
568  static Lisp_Object lface_from_face_name P_ ((struct frame *, Lisp_Object, int));  static Lisp_Object lface_from_face_name P_ ((struct frame *, Lisp_Object, int));
569  static struct face *make_realized_face P_ ((Lisp_Object *));  static struct face *make_realized_face P_ ((Lisp_Object *));
 static void free_realized_faces P_ ((struct face_cache *));  
570  static char *best_matching_font P_ ((struct frame *, Lisp_Object *,  static char *best_matching_font P_ ((struct frame *, Lisp_Object *,
571                                       struct font_name *, int, int));                                       struct font_name *, int, int));
572  static void cache_face P_ ((struct face_cache *, struct face *, unsigned));  static void cache_face P_ ((struct face_cache *, struct face *, unsigned));
# Line 1268  load_face_font (f, face, c) Line 1267  load_face_font (f, face, c)
1267    face->font_info_id = -1;    face->font_info_id = -1;
1268    face->font = NULL;    face->font = NULL;
1269    
1270    font_name = choose_face_font (f, face->lface, face->fontset, c);    font_name = choose_face_font (f, face->lface, face, c);
1271    
1272    if (!font_name)    if (!font_name)
1273      return;      return;
1274    
1275    BLOCK_INPUT;    BLOCK_INPUT;
1276    font_info = FS_LOAD_FACE_FONT (f, c, font_name, face);    font_info = FS_LOAD_FONT (f, font_name);
1277    UNBLOCK_INPUT;    UNBLOCK_INPUT;
1278    
1279    if (font_info)    if (font_info)
# Line 2112  face_numeric_swidth (width) Line 2112  face_numeric_swidth (width)
2112  }  }
2113    
2114    
2115    Lisp_Object
2116    generate_ascii_font (name, ascii_spec)
2117         Lisp_Object name;
2118    {
2119      struct font_name font;
2120      char *p;
2121    
2122      font.name = LSTRDUPA (name);
2123      if (! split_font_name (NULL, &font, 0))
2124        return Qnil;
2125    
2126      if (STRINGP (AREF (ascii_spec, FONT_SPEC_FAMILY_INDEX)))
2127        {
2128          p = LSTRDUPA (AREF (ascii_spec, FONT_SPEC_FAMILY_INDEX));
2129          font.fields[XLFD_FOUNDRY] = p;
2130          while (*p != '-') p++;
2131          if (*p)
2132            {
2133              *p++ = 0;
2134              font.fields[XLFD_FAMILY] = p;
2135            }
2136          else
2137            {
2138              font.fields[XLFD_FAMILY] = font.fields[XLFD_FOUNDRY];
2139              font.fields[XLFD_FOUNDRY] = "*";
2140            }
2141        }
2142      if (STRINGP (AREF (ascii_spec, FONT_SPEC_WEIGHT_INDEX)))
2143        font.fields[XLFD_WEIGHT]
2144          = XSTRING (AREF (ascii_spec, FONT_SPEC_WEIGHT_INDEX))->data;
2145      if (STRINGP (AREF (ascii_spec, FONT_SPEC_SLANT_INDEX)))
2146        font.fields[XLFD_SLANT]
2147          = XSTRING (AREF (ascii_spec, FONT_SPEC_SLANT_INDEX))->data;
2148      if (STRINGP (AREF (ascii_spec, FONT_SPEC_SWIDTH_INDEX)))
2149        font.fields[XLFD_SWIDTH]
2150          = XSTRING (AREF (ascii_spec, FONT_SPEC_SWIDTH_INDEX))->data;
2151      if (STRINGP (AREF (ascii_spec, FONT_SPEC_ADSTYLE_INDEX)))
2152        font.fields[XLFD_ADSTYLE]
2153          = XSTRING (AREF (ascii_spec, FONT_SPEC_ADSTYLE_INDEX))->data;
2154      p = LSTRDUPA (AREF (ascii_spec, FONT_SPEC_REGISTRY_INDEX));
2155      font.fields[XLFD_REGISTRY] = p;
2156      while (*p != '-') p++;
2157      if (*p)
2158        *p++ = 0;
2159      else
2160        p = "*";
2161      font.fields[XLFD_ENCODING] = p;
2162    
2163      p = build_font_name (&font);
2164      name = build_string (p);
2165      xfree (p);
2166      return name;
2167    }
2168    
2169    
2170  #ifdef HAVE_WINDOW_SYSTEM  #ifdef HAVE_WINDOW_SYSTEM
2171    
2172  /* 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 3149  set_lface_from_font_name (f, lface, font Line 3204  set_lface_from_font_name (f, lface, font
3204       caching it now is not futail because we anyway load the font       caching it now is not futail because we anyway load the font
3205       later.  */       later.  */
3206    BLOCK_INPUT;    BLOCK_INPUT;
3207    font_info = FS_LOAD_FONT (f, 0, font_name, -1);    font_info = FS_LOAD_FONT (f, font_name);
3208    UNBLOCK_INPUT;    UNBLOCK_INPUT;
3209    
3210    if (!font_info)    if (!font_info)
# Line 4252  set_font_frame_param (frame, lface) Line 4307  set_font_frame_param (frame, lface)
4307            /* Choose a font name that reflects LFACE's attributes and has            /* Choose a font name that reflects LFACE's attributes and has
4308               the registry and encoding pattern specified in the default               the registry and encoding pattern specified in the default
4309               fontset (3rd arg: -1) for ASCII characters (4th arg: 0).  */               fontset (3rd arg: -1) for ASCII characters (4th arg: 0).  */
4310            font = choose_face_font (f, XVECTOR (lface)->contents, -1, 0);            font = choose_face_font (f, XVECTOR (lface)->contents, NULL, 0);
4311            if (!font)            if (!font)
4312              error ("No font matches the specified attribute");              error ("No font matches the specified attribute");
4313            font_name = build_string (font);            font_name = build_string (font);
# Line 4938  make_realized_face (attr) Line 4993  make_realized_face (attr)
4993  /* Free realized face FACE, including its X resources.  FACE may  /* Free realized face FACE, including its X resources.  FACE may
4994     be null.  */     be null.  */
4995    
4996  static void  void
4997  free_realized_face (f, face)  free_realized_face (f, face)
4998       struct frame *f;       struct frame *f;
4999       struct face *face;       struct face *face;
# Line 5116  free_realized_faces (c) Line 5171  free_realized_faces (c)
5171  }  }
5172    
5173    
5174  /* Free all faces realized for multibyte characters on frame F that  /* Free all realized faces that are using FONTSET on frame F.  */
    has FONTSET.  */  
5175    
5176  void  void
5177  free_realized_multibyte_face (f, fontset)  free_realized_faces_for_fontset (f, fontset)
5178       struct frame *f;       struct frame *f;
5179       int fontset;       int fontset;
5180  {  {
# Line 5137  free_realized_multibyte_face (f, fontset Line 5191  free_realized_multibyte_face (f, fontset
5191      {      {
5192        face = cache->faces_by_id[i];        face = cache->faces_by_id[i];
5193        if (face        if (face
           && face != face->ascii_face  
5194            && face->fontset == fontset)            && face->fontset == fontset)
5195          {          {
5196            uncache_face (cache, face);            uncache_face (cache, face);
# Line 6064  face_fontset (attrs) Line 6117  face_fontset (attrs)
6117  /* 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 character C with
6118     Lisp face attributes specified by ATTRS.  The font name is     Lisp face attributes specified by ATTRS.  The font name is
6119     determined by the font-related attributes in ATTRS and the name     determined by the font-related attributes in ATTRS and the name
6120     pattern for C in FONTSET.  Value is the font name which is     pattern for C in FACE->fontset (or Vdefault_fontset if FACE is
6121     allocated from the heap and must be freed by the caller, or NULL if     null).  Value is the font name which is allocated from the heap and
6122     we can get no information about the font name of C.  It is assured     must be freed by the caller, or NULL if we can get no information
6123     that we always get some information for a single byte     about the font name of C.  It is assured that we always get some
6124     character.  */     information for a single byte character.  */
6125    
6126  static char *  static char *
6127  choose_face_font (f, attrs, fontset, c)  choose_face_font (f, attrs, face, c)
6128       struct frame *f;       struct frame *f;
6129       Lisp_Object *attrs;       Lisp_Object *attrs;
6130       int fontset, c;       struct face *face;
6131         int c;
6132  {  {
6133    Lisp_Object pattern;    Lisp_Object val;
6134      Lisp_Object pattern, family, registry;
6135      Lisp_Object new_attrs[LFACE_VECTOR_SIZE];
6136    char *font_name = NULL;    char *font_name = NULL;
6137    struct font_name *fonts;    struct font_name *fonts;
6138    int nfonts, width_ratio;    int nfonts, width_ratio;
6139    
6140    /* Get (foundry and) family name and registry (and encoding) name of    /* Get font spec of a font for C.  */
6141       a font for C.  */    pattern = fontset_font_pattern (f, face, c);
   pattern = fontset_font_pattern (f, fontset, c);  
6142    if (NILP (pattern))    if (NILP (pattern))
6143      {      {
6144        xassert (!SINGLE_BYTE_CHAR_P (c));        xassert (!SINGLE_BYTE_CHAR_P (c));
# Line 6094  choose_face_font (f, attrs, fontset, c) Line 6149  choose_face_font (f, attrs, fontset, c)
6149    if (STRINGP (pattern))    if (STRINGP (pattern))
6150      return xstrdup (XSTRING (pattern)->data);      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    
6157    #if 0
6158      /* This doesn't work well for the moment.  */
6159      if (! NILP (AREF (pattern, FONT_SPEC_WEIGHT_INDEX)))
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
6166    
6167      /* If C is an ASCII character, family name in ATTRS has higher
6168         priority than what specified in the fontset.  */
6169      if (STRINGP (attrs[LFACE_FAMILY_INDEX])
6170          && ASCII_CHAR_P (c))
6171        family = Qnil;
6172    
6173    /* Get a list of fonts matching that pattern and choose the    /* Get a list of fonts matching that pattern and choose the
6174       best match for the specified face attributes from it.  */       best match for the specified face attributes from it.  */
6175    nfonts = try_font_list (f, attrs, XCAR (pattern), XCDR (pattern), &fonts);    nfonts = try_font_list (f, new_attrs, family, registry, &fonts);
6176    width_ratio = (SINGLE_BYTE_CHAR_P (c)    width_ratio = (ASCII_CHAR_P (c)
6177                   ? 1                   ? 1
6178                   : CHARSET_WIDTH (CHAR_CHARSET (c)));                   : CHAR_WIDTH (c));
6179    font_name = best_matching_font (f, attrs, fonts, nfonts, width_ratio);    font_name = best_matching_font (f, new_attrs, fonts, nfonts, width_ratio);
6180    return font_name;    return font_name;
6181  }  }
6182    
# Line 6377  realize_x_face (cache, attrs, c, base_fa Line 6453  realize_x_face (cache, attrs, c, base_fa
6453    
6454    f = cache->f;    f = cache->f;
6455    
6456    /* If C is a multibyte character, we share all face attirbutes with    /* 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       BASE_FACE including the realized fontset.  But, we must load a
6458       different font.  */       different font.  */
6459    if (!SINGLE_BYTE_CHAR_P (c))    if (! ASCII_CHAR_P (c))
6460      {      {
6461        bcopy (base_face, face, sizeof *face);        bcopy (base_face, face, sizeof *face);
6462        face->gc = 0;        face->gc = 0;
# Line 6435  realize_x_face (cache, attrs, c, base_fa Line 6511  realize_x_face (cache, attrs, c, base_fa
6511        if (STRINGP (attrs[LFACE_FONT_INDEX]))        if (STRINGP (attrs[LFACE_FONT_INDEX]))
6512          {          {
6513            struct font_info *font_info =            struct font_info *font_info =
6514              FS_LOAD_FONT (f, 0, XSTRING (attrs[LFACE_FONT_INDEX])->data, -1);              FS_LOAD_FONT (f, XSTRING (attrs[LFACE_FONT_INDEX])->data);
6515            if (font_info)            if (font_info)
6516              face->font = font_info->font;              face->font = font_info->font;
6517          }          }

Legend:
Removed from v.1.250  
changed lines
  Added in v.1.250.2.1

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