/* Fontset handler.
- Copyright (C) 2004 Free Software Foundation, Inc.
- Copyright (C) 1995, 1997, 2000 Electrotechnical Laboratory, JAPAN.
- Licensed to the Free Software Foundation.
+ Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1997, 1998, 2000, 2003, 2004, 2005
+ National Institute of Advanced Industrial Science and Technology (AIST)
+ Registration Number H14PRO021
Copyright (C) 2003
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H13PRO009
-
+
This file is part of GNU Emacs.
GNU Emacs is free software; you can redistribute it and/or modify
You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
/* #define FONTSET_DEBUG */
static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object));
static void accumulate_script_ranges P_ ((Lisp_Object, Lisp_Object,
Lisp_Object));
-static Lisp_Object find_font_encoding P_ ((char *));
+static Lisp_Object find_font_encoding P_ ((Lisp_Object));
static void set_fontset_font P_ ((Lisp_Object, Lisp_Object));
}
+/* Set the ASCII font of the default fontset to FONTNAME if that is
+ not yet set. */
+void
+set_default_ascii_font (fontname)
+ Lisp_Object fontname;
+{
+ if (! STRINGP (FONTSET_ASCII (Vdefault_fontset)))
+ {
+ int id = fs_query_fontset (fontname, 2);
+
+ if (id >= 0)
+ fontname = FONTSET_ASCII (FONTSET_FROM_ID (id));
+ FONTSET_ASCII (Vdefault_fontset)= fontname;
+ }
+}
+
\f
/********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
int charset;
{
struct font_info *fontp;
+ Lisp_Object fullname;
if (!fontname)
/* No way to get fontname. */
return fontp;
fontname = fontp->full_name;
+ fullname = build_string (fontp->full_name);
if (charset < 0)
{
Lisp_Object charset_symbol;
- charset_symbol = find_font_encoding (fontname);
+ charset_symbol = find_font_encoding (fullname);
if (CONSP (charset_symbol))
charset_symbol = XCAR (charset_symbol);
charset = XINT (CHARSET_SYMBOL_ID (charset_symbol));
{
fontp->vertical_centering
= (STRINGP (Vvertical_centering_font_regexp)
- && (fast_c_string_match_ignore_case
- (Vvertical_centering_font_regexp, fontname) >= 0));
+ && (fast_string_match_ignore_case
+ (Vvertical_centering_font_regexp, fullname) >= 0));
if (find_ccl_program_func)
(*find_ccl_program_func) (fontp);
static Lisp_Object
find_font_encoding (fontname)
- char *fontname;
+ Lisp_Object fontname;
{
Lisp_Object tail, elt;
elt = XCAR (tail);
if (CONSP (elt)
&& STRINGP (XCAR (elt))
- && fast_c_string_match_ignore_case (XCAR (elt), fontname) >= 0
+ && fast_string_match_ignore_case (XCAR (elt), fontname) >= 0
&& (SYMBOLP (XCDR (elt))
? CHARSETP (XCDR (elt))
: CONSP (XCDR (elt)) && CHARSETP (XCAR (XCDR (elt)))))
|| strcmp (SDATA (pattern), CACHED_FONTSET_NAME))
{
/* We must at first update the cached data. */
- char *regex = (char *) alloca (SCHARS (pattern) * 2 + 3);
- char *p0, *p1 = regex;
+ unsigned char *regex, *p0, *p1;
+ int ndashes = 0, nstars = 0;
+
+ for (p0 = SDATA (pattern); *p0; p0++)
+ {
+ if (*p0 == '-')
+ ndashes++;
+ else if (*p0 == '*')
+ nstars++;
+ }
+
+ /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
+ we convert "*" to "[^-]*" which is much faster in regular
+ expression matching. */
+ if (ndashes < 14)
+ p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 1);
+ else
+ p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 1);
- /* Convert "*" to ".*", "?" to ".". */
*p1++ = '^';
- for (p0 = (char *) SDATA (pattern); *p0; p0++)
+ for (p0 = SDATA (pattern); *p0; p0++)
{
if (*p0 == '*')
{
- *p1++ = '.';
+ if (ndashes < 14)
+ *p1++ = '.';
+ else
+ *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']';
*p1++ = '*';
}
else if (*p0 == '?')
}
/* Return ID of the base fontset named NAME. If there's no such
- fontset, return -1. */
+ fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
+ 0: pattern containing '*' and '?' as wildcards
+ 1: regular expression
+ 2: literal fontset name
+*/
int
-fs_query_fontset (name, regexpp)
+fs_query_fontset (name, name_pattern)
Lisp_Object name;
- int regexpp;
+ int name_pattern;
{
Lisp_Object tem;
int i;
name = Fdowncase (name);
- if (!regexpp)
+ if (name_pattern != 1)
{
tem = Frassoc (name, Vfontset_alias_alist);
if (NILP (tem))
tem = Fassoc (name, Vfontset_alias_alist);
if (CONSP (tem) && STRINGP (XCAR (tem)))
name = XCAR (tem);
- else
+ else if (name_pattern == 0)
{
tem = fontset_pattern_regexp (name);
if (STRINGP (tem))
{
name = tem;
- regexpp = 1;
+ name_pattern = 1;
}
}
}
for (i = 0; i < ASIZE (Vfontset_table); i++)
{
- Lisp_Object fontset;
- unsigned char *this_name;
+ Lisp_Object fontset, this_name;
fontset = FONTSET_FROM_ID (i);
if (NILP (fontset)
|| !BASE_FONTSET_P (fontset))
continue;
- this_name = SDATA (FONTSET_NAME (fontset));
- if (regexpp
- ? fast_c_string_match_ignore_case (name, this_name) >= 0
- : !strcmp (SDATA (name), this_name))
+ this_name = FONTSET_NAME (fontset);
+ if (name_pattern == 1
+ ? fast_string_match (name, this_name) >= 0
+ : !strcmp (SDATA (name), SDATA (this_name)))
return i;
}
return -1;
for (id = 0; id < ASIZE (Vfontset_table); id++)
{
- Lisp_Object fontset;
- unsigned char *name;
+ Lisp_Object fontset, name;
fontset = FONTSET_FROM_ID (id);
if (NILP (fontset)
|| !BASE_FONTSET_P (fontset)
|| !EQ (frame, FONTSET_FRAME (fontset)))
continue;
- name = SDATA (FONTSET_NAME (fontset));
+ name = FONTSET_NAME (fontset);
if (STRINGP (regexp)
- ? (fast_c_string_match_ignore_case (regexp, name) < 0)
- : strcmp (SDATA (pattern), name))
+ ? (fast_string_match (regexp, name) < 0)
+ : strcmp (SDATA (pattern), SDATA (name)))
continue;
val = Fcons (Fcopy_sequence (FONTSET_NAME (fontset)), val);
return Vdefault_fontset;
CHECK_STRING (name);
- id = fs_query_fontset (name, 0);
+ /* First try NAME as literal. */
+ id = fs_query_fontset (name, 2);
+ if (id < 0)
+ /* For backward compatibility, try again NAME as pattern. */
+ id = fs_query_fontset (name, 0);
if (id < 0)
error ("Fontset `%s' does not exist", SDATA (name));
return FONTSET_FROM_ID (id);
Lisp_Object name, target, font_spec, frame, add;
{
Lisp_Object fontset;
- Lisp_Object font_def, registry;
+ Lisp_Object font_def, registry, family;
Lisp_Object encoding, repertory;
Lisp_Object range_list;
struct charset *charset = NULL;
CHECK_STRING (AREF (font_spec, j));
ASET (font_spec, j, Fdowncase (AREF (font_spec, j)));
}
+ family = AREF (font_spec, FONT_SPEC_FAMILY_INDEX);
/* REGISTRY should not be omitted. */
CHECK_STRING (AREF (font_spec, FONT_SPEC_REGISTRY_INDEX));
- registry = Fdowncase (AREF (font_spec, FONT_SPEC_REGISTRY_INDEX));
- ASET (font_spec, FONT_SPEC_REGISTRY_INDEX, registry);
-
+ registry = AREF (font_spec, FONT_SPEC_REGISTRY_INDEX);
}
else if (CONSP (font_spec))
{
- Lisp_Object family;
-
family = XCAR (font_spec);
registry = XCDR (font_spec);
}
if (STRINGP (font_spec))
- encoding = find_font_encoding ((char *) SDATA (font_spec));
+ encoding = find_font_encoding (font_spec);
else
- encoding = find_font_encoding ((char *) SDATA (registry));
+ encoding = find_font_encoding (concat2 (family, registry));
if (SYMBOLP (encoding))
{
CHECK_CHARSET (encoding);
FONTSET_ID (Vdefault_fontset) = make_number (0);
FONTSET_NAME (Vdefault_fontset)
= build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
- {
- Lisp_Object default_ascii_font;
-
-#if defined (macintosh)
- default_ascii_font
- = build_string ("-apple-monaco-medium-r-*--*-120-*-*-*-*-mac-roman");
-#elif defined (WINDOWSNT)
- default_ascii_font
- = build_string ("-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
-#else
- default_ascii_font
- = build_string ("-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
-#endif
- FONTSET_ASCII (Vdefault_fontset) = default_ascii_font;
- }
AREF (Vfontset_table, 0) = Vdefault_fontset;
next_fontset_id = 1;