/* xfaces.c -- "Face" primitives.
- Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2003
+ Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004
Free Software Foundation.
This file is part of GNU Emacs.
used to fill in unspecified attributes of the default face. */
#include <config.h>
+#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif /* HAVE_X_WINDOWS */
-#include <stdio.h>
#include <ctype.h>
#define abs(X) ((X) < 0 ? -(X) : (X))
XColor not_used;
XSETFRAME (frame, f);
- return (FRAME_WINDOW_P (f)
- ? (!NILP (Fxw_display_color_p (frame))
- || xstricmp (color_name, "black") == 0
- || xstricmp (color_name, "white") == 0
- || (background_p
- && face_color_gray_p (f, color_name))
- || (!NILP (Fx_display_grayscale_p (frame))
- && face_color_gray_p (f, color_name)))
- : tty_defined_color (f, color_name, ¬_used, 0));
+ return
+#ifdef HAVE_X_WINDOWS
+ FRAME_WINDOW_P (f)
+ ? (!NILP (Fxw_display_color_p (frame))
+ || xstricmp (color_name, "black") == 0
+ || xstricmp (color_name, "white") == 0
+ || (background_p
+ && face_color_gray_p (f, color_name))
+ || (!NILP (Fx_display_grayscale_p (frame))
+ && face_color_gray_p (f, color_name)))
+ :
+#endif
+ tty_defined_color (f, color_name, ¬_used, 0);
}
}
+/* Check if a font matching pattern_offset_t on frame F is available
+ or not. PATTERN may be a cons (FAMILY . REGISTRY), in which case,
+ a font name pattern is generated from FAMILY and REGISTRY. */
+
+int
+face_font_available_p (f, pattern)
+ struct frame *f;
+ Lisp_Object pattern;
+{
+ Lisp_Object fonts;
+
+ if (! STRINGP (pattern))
+ {
+ Lisp_Object family, registry;
+ char *family_str, *registry_str, *pattern_str;
+
+ CHECK_CONS (pattern);
+ family = XCAR (pattern);
+ if (NILP (family))
+ family_str = "*";
+ else
+ {
+ CHECK_STRING (family);
+ family_str = (char *) SDATA (family);
+ }
+ registry = XCDR (pattern);
+ if (NILP (registry))
+ registry_str = "*";
+ else
+ {
+ CHECK_STRING (registry);
+ registry_str = (char *) SDATA (registry);
+ }
+
+ pattern_str = (char *) alloca (strlen (family_str)
+ + strlen (registry_str)
+ + 10);
+ strcpy (pattern_str, index (family_str, '-') ? "-" : "-*-");
+ strcat (pattern_str, family_str);
+ strcat (pattern_str, "-*-");
+ strcat (pattern_str, registry_str);
+ if (!index (registry_str, '-'))
+ {
+ if (registry_str[strlen (registry_str) - 1] == '*')
+ strcat (pattern_str, "-*");
+ else
+ strcat (pattern_str, "*-*");
+ }
+ pattern = build_string (pattern_str);
+ }
+
+ /* Get the list of fonts matching PATTERN. */
+#ifdef WINDOWSNT
+ BLOCK_INPUT;
+ fonts = w32_list_fonts (f, pattern, 0, 1);
+ UNBLOCK_INPUT;
+#else
+ fonts = x_list_fonts (f, pattern, -1, 1);
+#endif
+ return XINT (Flength (fonts));
+}
+
+
/* Determine fonts matching PATTERN on frame F. Sort resulting fonts
using comparison function CMPFN. Value is the number of fonts
found. If value is non-zero, *FONTS is set to a vector of
to[LFACE_INHERIT_INDEX] = Qnil;
}
-
-/* Checks the `cycle check' variable CHECK to see if it indicates that
- EL is part of a cycle; CHECK must be either Qnil or a value returned
- by an earlier use of CYCLE_CHECK. SUSPICIOUS is the number of
- elements after which a cycle might be suspected; after that many
- elements, this macro begins consing in order to keep more precise
- track of elements.
-
- Returns nil if a cycle was detected, otherwise a new value for CHECK
- that includes EL.
-
- CHECK is evaluated multiple times, EL and SUSPICIOUS 0 or 1 times, so
- the caller should make sure that's ok. */
-
-#define CYCLE_CHECK(check, el, suspicious) \
- (NILP (check) \
- ? make_number (0) \
- : (INTEGERP (check) \
- ? (XFASTINT (check) < (suspicious) \
- ? make_number (XFASTINT (check) + 1) \
- : Fcons (el, Qnil)) \
- : (!NILP (Fmemq ((el), (check))) \
- ? Qnil \
- : Fcons ((el), (check)))))
-
-
/* Merge face attributes from the face on frame F whose name is
INHERITS, into the vector of face attributes TO; INHERITS may also be
a list of face names, in which case they are applied in order.
face->id = i;
/* Maybe enlarge C->faces_by_id. */
- if (i == c->used && c->used == c->size)
+ if (i == c->used)
{
- int new_size = 2 * c->size;
- int sz = new_size * sizeof *c->faces_by_id;
- c->faces_by_id = (struct face **) xrealloc (c->faces_by_id, sz);
- c->size = new_size;
+ if (c->used == c->size)
+ {
+ int new_size, sz;
+ new_size = min (2 * c->size, MAX_FACE_ID);
+ if (new_size == c->size)
+ abort (); /* Alternatives? ++kfs */
+ sz = new_size * sizeof *c->faces_by_id;
+ c->faces_by_id = (struct face **) xrealloc (c->faces_by_id, sz);
+ c->size = new_size;
+ }
+ c->used++;
}
#if GLYPH_DEBUG
#endif /* GLYPH_DEBUG */
c->faces_by_id[i] = face;
- if (i == c->used)
- ++c->used;
}