X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/cf14fd6ec4f2a953eb796c9d42917a01a0c97973..c615a00cdaae92bb335275e74c0a7f57cf077322:/src/fontset.c diff --git a/src/fontset.c b/src/fontset.c index 41c8c80749..130ab402cc 100644 --- a/src/fontset.c +++ b/src/fontset.c @@ -1,6 +1,7 @@ /* Fontset handler. Copyright (C) 1995, 1997, 2000 Electrotechnical Laboratory, JAPAN. Licensed to the Free Software Foundation. + Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -16,8 +17,8 @@ GNU General Public License for more details. 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 */ @@ -352,7 +353,11 @@ fontset_set (fontset, c, newelt) for (i = 0; code[i] > 0; i++) { if (!SUB_CHAR_TABLE_P (*elt)) - *elt = make_sub_char_table (*elt); + { + Lisp_Object val = *elt; + *elt = make_sub_char_table (Qnil); + XCHAR_TABLE (*elt)->defalt = val; + } elt = &XCHAR_TABLE (*elt)->contents[code[i]]; } if (SUB_CHAR_TABLE_P (*elt)) @@ -653,7 +658,7 @@ fs_load_font (f, c, fontname, id, face) struct face *face; { Lisp_Object fontset; - Lisp_Object list, elt; + Lisp_Object list, elt, fullname; int size = 0; struct font_info *fontp; int charset = CHAR_CHARSET (c); @@ -699,10 +704,11 @@ fs_load_font (f, c, fontname, id, face) font_info structure that are not set by (*load_font_func). */ fontp->charset = charset; + fullname = build_string (fontp->full_name); fontp->vertical_centering = (STRINGP (Vvertical_centering_font_regexp) - && (fast_c_string_match_ignore_case - (Vvertical_centering_font_regexp, fontp->full_name) >= 0)); + && (fast_string_match_ignore_case + (Vvertical_centering_font_regexp, fullname) >= 0)); if (fontp->encoding[1] != FONT_ENCODING_NOT_DECIDED) { @@ -719,7 +725,6 @@ fs_load_font (f, c, fontname, id, face) /* The font itself doesn't have information about encoding. */ int i; - fontname = fontp->full_name; /* By default, encoding of ASCII chars is 0 (i.e. 0x00..0x7F), others is 1 (i.e. 0x80..0xFF). */ fontp->encoding[0] = 0; @@ -731,8 +736,7 @@ fs_load_font (f, c, fontname, id, face) elt = XCAR (list); if (CONSP (elt) && STRINGP (XCAR (elt)) && CONSP (XCDR (elt)) - && (fast_c_string_match_ignore_case (XCAR (elt), fontname) - >= 0)) + && (fast_string_match_ignore_case (XCAR (elt), fullname) >= 0)) { Lisp_Object tmp; @@ -764,6 +768,23 @@ fs_load_font (f, c, fontname, id, face) #pragma optimize("", on) #endif +/* 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 (! CONSP (FONTSET_ASCII (Vdefault_fontset))) + { + int id = fs_query_fontset (fontname, 2); + + if (id >= 0) + fontname = XCDR (FONTSET_ASCII (FONTSET_FROM_ID (id))); + FONTSET_ASCII (Vdefault_fontset) + = Fcons (make_number (0), fontname); + } +} + /* Cache data used by fontset_pattern_regexp. The car part is a pattern string containing at least one wild card, the cdr part is @@ -789,16 +810,34 @@ fontset_pattern_regexp (pattern) || 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 == '?') @@ -817,47 +856,50 @@ fontset_pattern_regexp (pattern) } /* 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 (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; - const 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; @@ -911,19 +953,18 @@ list_fontsets (f, pattern, size) for (id = 0; id < ASIZE (Vfontset_table); id++) { - Lisp_Object fontset; - const 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 (!NILP (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; if (size) @@ -947,6 +988,7 @@ FONTLIST is an alist of charsets vs corresponding font name patterns. */) { Lisp_Object fontset, elements, ascii_font; Lisp_Object tem, tail, elt; + int id; (*check_window_system_func) (); @@ -954,10 +996,14 @@ FONTLIST is an alist of charsets vs corresponding font name patterns. */) CHECK_LIST (fontlist); name = Fdowncase (name); - tem = Fquery_fontset (name, Qnil); - if (!NILP (tem)) - error ("Fontset `%s' matches the existing fontset `%s'", - SDATA (name), SDATA (tem)); + id = fs_query_fontset (name, 2); + if (id >= 0) + { + fontset = FONTSET_FROM_ID (id); + tem = FONTSET_NAME (fontset); + error ("Fontset `%s' matches the existing fontset `%s'", + SDATA (name), SDATA (tem)); + } /* Check the validity of FONTLIST while creating a template for fontset elements. */ @@ -1032,7 +1078,11 @@ check_fontset_name (name) 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); @@ -1084,7 +1134,6 @@ name of a font, REGISTRY is a registry name of a font. */) Lisp_Object realized; int from, to; int id; - Lisp_Object family, registry; fontset = check_fontset_name (name); @@ -1599,19 +1648,6 @@ syms_of_fontset () FONTSET_ID (Vdefault_fontset) = make_number (0); FONTSET_NAME (Vdefault_fontset) = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default"); -#if defined (MAC_OS) - FONTSET_ASCII (Vdefault_fontset) - = Fcons (make_number (0), - build_string ("-apple-monaco-medium-r-*--*-120-*-*-*-*-mac-roman")); -#elif defined (WINDOWSNT) - FONTSET_ASCII (Vdefault_fontset) - = Fcons (make_number (0), - build_string ("-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1")); -#else - FONTSET_ASCII (Vdefault_fontset) - = Fcons (make_number (0), - build_string ("-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1")); -#endif AREF (Vfontset_table, 0) = Vdefault_fontset; next_fontset_id = 1;