(-windowDidResize:): Avoid inf-loop under GNUStep.
[bpt/emacs.git] / src / xfaces.c
index 64cd4a0..152a1d6 100644 (file)
@@ -1,6 +1,6 @@
 /* xfaces.c -- "Face" primitives.
    Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+                 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -1816,11 +1816,13 @@ DEFUN ("x-list-fonts", Fx_list_fonts, Sx_list_fonts, 1, 5, 0,
        doc: /* Return a list of the names of available fonts matching PATTERN.
 If optional arguments FACE and FRAME are specified, return only fonts
 the same size as FACE on FRAME.
-PATTERN is a string, perhaps with wildcard characters;
+
+PATTERN should be a string containing a font name in the XLFD,
+Fontconfig, or GTK format.  A font name given in the XLFD format may
+contain wildcard characters:
   the * character matches any substring, and
   the ? character matches any single character.
   PATTERN is case-insensitive.
-FACE is a face name--a symbol.
 
 The return value is a list of strings, suitable as arguments to
 `set-face-font'.
@@ -1892,6 +1894,9 @@ the WIDTH times as wide as FACE on FRAME.  */)
     Lisp_Object args[2], tail;
 
     font_spec = font_spec_from_name (pattern);
+    if (!FONTP (font_spec))
+      signal_error ("Invalid font name", pattern);
+
     if (size)
       {
        Ffont_put (font_spec, QCsize, make_number (size));
@@ -1899,7 +1904,22 @@ the WIDTH times as wide as FACE on FRAME.  */)
       }
     args[0] = Flist_fonts (font_spec, frame, maximum, font_spec);
     for (tail = args[0]; CONSP (tail); tail = XCDR (tail))
-      XSETCAR (tail, Ffont_xlfd_name (XCAR (tail), Qnil));
+      {
+       Lisp_Object font_entity;
+
+       font_entity = XCAR (tail);
+       if ((NILP (AREF (font_entity, FONT_SIZE_INDEX))
+            || XINT (AREF (font_entity, FONT_SIZE_INDEX)) == 0)
+           && ! NILP (AREF (font_spec, FONT_SIZE_INDEX)))
+         {
+           /* This is a scalable font.  For backward compatibility,
+              we set the specified size. */
+           font_entity = Fcopy_font_spec (font_entity);
+           ASET (font_entity, FONT_SIZE_INDEX,
+                 AREF (font_spec, FONT_SIZE_INDEX));
+         }
+       XSETCAR (tail, Ffont_xlfd_name (font_entity, Qnil));
+      }
     if (NILP (frame))
       /* We don't have to check fontsets.  */
       return args[0];
@@ -1910,27 +1930,6 @@ the WIDTH times as wide as FACE on FRAME.  */)
 
 #endif /* HAVE_WINDOW_SYSTEM */
 
-#if defined(HAVE_WINDOW_SYSTEM) || defined(__MSDOS__)
-
-DEFUN ("x-font-family-list", Fx_font_family_list, Sx_font_family_list,
-       0, 1, 0,
-       doc: /* Return a list of available font families on FRAME.
-If FRAME is omitted or nil, use the selected frame.
-Value is a list of conses (FAMILY . FIXED-P) where FAMILY
-is a font family, and FIXED-P is non-nil if fonts of that family
-are fixed-pitch.  */)
-     (frame)
-     Lisp_Object frame;
-{
-#ifdef __MSDOS__
-  return Fcons (Fcons (build_string ("default"), Qt), Qnil);
-#else
-  return Ffont_family_list (frame);
-#endif
-}
-
-#endif /* HAVE_WINDOW_SYSTEM || __MSDOS__ */
-
 \f
 /***********************************************************************
                              Lisp Faces
@@ -2389,9 +2388,7 @@ set_lface_from_font (f, lface, font_object, force_p)
    merged height.  If FROM is an invalid height, then INVALID is
    returned instead.  FROM and TO may be either absolute face heights or
    `relative' heights; the returned value is always an absolute height
-   unless both FROM and TO are relative.  GCPRO is a lisp value that
-   will be protected from garbage-collection if this function makes a
-   call into lisp.  */
+   unless both FROM and TO are relative.  */
 
 Lisp_Object
 merge_face_heights (from, to, invalid)
@@ -2467,6 +2464,16 @@ merge_face_vectors (f, from, to, named_merge_points)
        to[i] = Fmerge_font_spec (from[i], to[i]);
       else
        to[i] = Fcopy_font_spec (from[i]);
+      if (! NILP (AREF (to[i], FONT_FOUNDRY_INDEX)))
+       to[LFACE_FOUNDRY_INDEX] = SYMBOL_NAME (AREF (to[i], FONT_FOUNDRY_INDEX));
+      if (! NILP (AREF (to[i], FONT_FAMILY_INDEX)))
+       to[LFACE_FAMILY_INDEX] = SYMBOL_NAME (AREF (to[i], FONT_FAMILY_INDEX));
+      if (! NILP (AREF (to[i], FONT_WEIGHT_INDEX)))
+       to[LFACE_WEIGHT_INDEX] = FONT_WEIGHT_FOR_FACE (to[i]);
+      if (! NILP (AREF (to[i], FONT_SLANT_INDEX)))
+       to[LFACE_SLANT_INDEX] = FONT_SLANT_FOR_FACE (to[i]);
+      if (! NILP (AREF (to[i], FONT_WIDTH_INDEX)))
+       to[LFACE_SWIDTH_INDEX] = FONT_WIDTH_FOR_FACE (to[i]);
       ASET (to[i], FONT_SIZE_INDEX, Qnil);
     }
 
@@ -2478,7 +2485,8 @@ merge_face_vectors (f, from, to, named_merge_points)
            to[i] = merge_face_heights (from[i], to[i], to[i]);
            font_clear_prop (to, FONT_SIZE_INDEX);
          }
-       else if (i != LFACE_FONT_INDEX)
+       else if (i != LFACE_FONT_INDEX
+                && ! EQ (to[i], from[i]))
          {
            to[i] = from[i];
            if (i >= LFACE_FAMILY_INDEX && i <=LFACE_SLANT_INDEX)
@@ -2492,11 +2500,6 @@ merge_face_vectors (f, from, to, named_merge_points)
          }
       }
 
-  /* If `font' attribute is specified, reflect the font properties in
-     it to the other attributes.  */
-  if (0 && !UNSPECIFIEDP (to[LFACE_FONT_INDEX]))
-    font_update_lface (f, to);
-
   /* TO is always an absolute face, which should inherit from nothing.
      We blindly copy the :inherit attribute above and fix it up here.  */
   to[LFACE_INHERIT_INDEX] = Qnil;
@@ -3280,11 +3283,14 @@ FRAME 0 means change the face on all frames, and change the default
                {
                  if (STRINGP (value))
                    {
-                     int fontset = fs_query_fontset (value, 0);
+                     Lisp_Object name = value;
+                     int fontset = fs_query_fontset (name, 0);
 
                      if (fontset >= 0)
-                       value = fontset_ascii (fontset);
-                     value = font_spec_from_name (value);
+                       name = fontset_ascii (fontset);
+                     value = font_spec_from_name (name);
+                     if (!FONTP (value))
+                       signal_error ("Invalid font name", name);
                    }
                  else
                    signal_error ("Invalid font or font-spec", value);
@@ -5383,7 +5389,7 @@ face for italic.  */)
                            Font selection
  ***********************************************************************/
 
- DEFUN ("internal-set-font-selection-order",
+DEFUN ("internal-set-font-selection-order",
        Finternal_set_font_selection_order,
        Sinternal_set_font_selection_order, 1, 1, 0,
        doc: /* Set font selection order for face font selection to ORDER.
@@ -6245,17 +6251,21 @@ compute_char_face (f, ch, prop)
 
    If MOUSE is non-zero, use the character's mouse-face, not its face.
 
+   BASE_FACE_ID, if non-negative, specifies a base face id to use
+   instead of DEFAULT_FACE_ID.
+
    The face returned is suitable for displaying ASCII characters.  */
 
 int
 face_at_buffer_position (w, pos, region_beg, region_end,
-                        endptr, limit, mouse)
+                        endptr, limit, mouse, base_face_id)
      struct window *w;
      EMACS_INT pos;
      EMACS_INT region_beg, region_end;
      EMACS_INT *endptr;
      EMACS_INT limit;
      int mouse;
+     int base_face_id;
 {
   struct frame *f = XFRAME (w->frame);
   Lisp_Object attrs[LFACE_VECTOR_SIZE];
@@ -6298,12 +6308,9 @@ face_at_buffer_position (w, pos, region_beg, region_end,
 
   *endptr = endpos;
 
-
-  /* Perhaps remap BASE_FACE_ID to a user-specified alternative.  */
-  if (NILP (Vface_remapping_alist))
-    default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
-  else
-    default_face = FACE_FROM_ID (f, lookup_basic_face (f, DEFAULT_FACE_ID));
+  default_face = FACE_FROM_ID (f, base_face_id >= 0 ? base_face_id
+                              : NILP (Vface_remapping_alist) ? DEFAULT_FACE_ID
+                              : lookup_basic_face (f, DEFAULT_FACE_ID));
 
   /* Optimize common cases where we can use the default face.  */
   if (noverlays == 0
@@ -7017,9 +7024,6 @@ a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point.  */);
   defsubr (&Sinternal_face_x_get_resource);
   defsubr (&Sx_family_fonts);
 #endif
-#if defined(HAVE_WINDOW_SYSTEM) || defined(__MSDOS__)
-  defsubr (&Sx_font_family_list);
-#endif /* HAVE_WINDOW_SYSTEM || __MSDOS__ */
 }
 
 /* arch-tag: 8a0f7598-5517-408d-9ab3-1da6fcd4c749