]> code.delx.au - gnu-emacs/blobdiff - src/fontset.c
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-34
[gnu-emacs] / src / fontset.c
index 84384c06d8c5360eb13ab0e2ae7ecdaa6a2c7503..9cebcfe11609f56d20f8b9cbe4db07804dafa0a0 100644 (file)
@@ -1,11 +1,12 @@
 /* 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
@@ -20,8 +21,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 */
 
@@ -774,6 +775,22 @@ make_fontset (frame, name, base)
 }
 
 
+/* 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 **********/
 
@@ -1069,16 +1086,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 == '?')
@@ -1097,31 +1132,35 @@ 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 (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;
            }
        }
     }
@@ -1136,7 +1175,7 @@ fs_query_fontset (name, regexpp)
        continue;
 
       this_name = FONTSET_NAME (fontset);
-      if (regexpp
+      if (name_pattern == 1
          ? fast_string_match (name, this_name) >= 0
          : !strcmp (SDATA (name), SDATA (this_name)))
        return i;
@@ -1266,7 +1305,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);
@@ -1384,7 +1427,7 @@ appended.  By default, FONT-SPEC overrides the previous settings.  */)
      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;
@@ -1415,16 +1458,13 @@ appended.  By default, FONT-SPEC overrides the previous settings.  */)
            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);
 
@@ -1448,7 +1488,7 @@ appended.  By default, FONT-SPEC overrides the previous settings.  */)
   if (STRINGP (font_spec))
     encoding = find_font_encoding (font_spec);
   else
-    encoding = find_font_encoding (registry);
+    encoding = find_font_encoding (concat2 (family, registry));
   if (SYMBOLP (encoding))
     {
       CHECK_CHARSET (encoding);
@@ -2106,21 +2146,6 @@ syms_of_fontset ()
   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;