]> code.delx.au - gnu-emacs/blobdiff - src/fontset.c
(get_keyelt): Handle an indirect entry with meta char.
[gnu-emacs] / src / fontset.c
index 7d88e90ae899ee2b8b5b4da59dcbd9c855139c35..840555b427df0bb2af876908aa4f5666e9e12963 100644 (file)
@@ -1,22 +1,24 @@
 /* Fontset handler.
    Ver.1.0
-
    Copyright (C) 1995 Free Software Foundation, Inc.
    Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
 
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
+This file is part of GNU Emacs.
+
+GNU Emacs is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+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.  */
 
 #include <config.h>
 #if HAVE_ALLOCA_H
 #include "frame.h"
 
 Lisp_Object Vglobal_fontset_alist;
-
 Lisp_Object Vfont_encoding_alist;
+Lisp_Object Vuse_default_ascent;
+Lisp_Object Valternative_fontname_alist;
+Lisp_Object Vfontset_alias_alist;
+Lisp_Object Vhighlight_wrong_size_font;
+Lisp_Object Vclip_large_size_font;
 
 /* We had better have our own strcasecmp function because some system
    doesn't have it.  */
@@ -93,7 +99,7 @@ free_fontset_data (fontset_data)
       int j;
 
       xfree (fontset_data->fontset_table[i]->name);
-      for (j = 0; j < MAX_CHARSET; j++)
+      for (j = 0; j <= MAX_CHARSET; j++)
        if (fontset_data->fontset_table[i]->fontname[j])
          xfree (fontset_data->fontset_table[i]->fontname[j]);
       xfree (fontset_data->fontset_table[i]);
@@ -169,7 +175,7 @@ fs_load_font (f, font_table, charset, fontname, fontset)
       int i;
 
       fontp->encoding[0] = fontp->encoding[1];
-      for (i = MIN_CHARSET_OFFICIAL_DIMENSION1; i < MAX_CHARSET; i++)
+      for (i = MIN_CHARSET_OFFICIAL_DIMENSION1; i <= MAX_CHARSET; i++)
        fontp->encoding[i] = fontp->encoding[1];
     }
   else
@@ -179,7 +185,7 @@ fs_load_font (f, font_table, charset, fontname, fontset)
 
       /* At first, set 1 (means 0xA0..0xFF) as the default.  */
       fontp->encoding[0] = 1;
-      for (i = MIN_CHARSET_OFFICIAL_DIMENSION1; i < MAX_CHARSET; i++)
+      for (i = MIN_CHARSET_OFFICIAL_DIMENSION1; i <= MAX_CHARSET; i++)
        fontp->encoding[i] = 1;
       /* Then override them by a specification in Vfont_encoding_alist.  */
       for (list = Vfont_encoding_alist; CONSP (list); list = XCONS (list)->cdr)
@@ -194,7 +200,6 @@ fs_load_font (f, font_table, charset, fontname, fontset)
 
              for (tmp = XCONS (elt)->cdr; CONSP (tmp); tmp = XCONS (tmp)->cdr)
                if (CONSP (XCONS (tmp)->car)
-                   && INTEGERP (XCONS (XCONS (tmp)->car)->car)
                    && ((i = get_charset_id (XCONS (XCONS (tmp)->car)->car))
                        >= 0)
                    && INTEGERP (XCONS (XCONS (tmp)->car)->cdr)
@@ -240,7 +245,7 @@ fs_load_font (f, font_table, charset, fontname, fontset)
 
          fontsetp->size = fontp->size;
          fontsetp->height = fontp->height;
-         for (i = CHARSET_ASCII + 1; i < MAX_CHARSET; i++)
+         for (i = CHARSET_ASCII + 1; i <= MAX_CHARSET; i++)
            {
              font_idx = fontsetp->font_indexes[i];
              if (font_idx >= 0)
@@ -249,8 +254,12 @@ fs_load_font (f, font_table, charset, fontname, fontset)
 
                  if (fontp2->size != fontp->size * CHARSET_WIDTH (i))
                    fontsetp->font_indexes[i] = FONT_NOT_OPENED;
+                 /* The following code should be disabled until Emacs
+                    supports variable height lines.  */
+#if 0
                  else if (fontsetp->height < fontp->height)
                    fontsetp->height = fontp->height;
+#endif
                }
            }
        }
@@ -311,7 +320,7 @@ fs_register_fontset (f, fontset_info)
 
   fontsetp->size = fontsetp->height = 0;
 
-  for (i = 0; i < MAX_CHARSET; i++)
+  for (i = 0; i <= MAX_CHARSET; i++)
     {
       fontsetp->fontname[i] = (char *) 0;
       fontsetp->font_indexes[i] = FONT_NOT_OPENED;
@@ -376,50 +385,31 @@ Lisp_Object
 fontset_pattern_regexp (pattern)
      Lisp_Object pattern;
 {
-  int nickname = 0;
-
   if (!index (XSTRING (pattern)->data, '*')
       && !index (XSTRING (pattern)->data, '?'))
     /* PATTERN does not contain any wild cards.  */
-    {
-      if (XSTRING (pattern)->size > 8
-         && ! bcmp (XSTRING (pattern)->data, "fontset-", 8))
-       /* Just a nickname of a fontset is specified.  */
-       nickname = 1;
-      else
-       return Qnil;
-    }
+    return Qnil;
 
   if (!CONSP (Vcached_fontset_data)
       || strcmp (XSTRING (pattern)->data, CACHED_FONTSET_NAME))
     {
       /* We must at first update the cached data.  */
-      char *regex = (char *) alloca (XSTRING (pattern)->size * 2 + 3);
+      char *regex = (char *) alloca (XSTRING (pattern)->size * 2);
       char *p0, *p1 = regex;
 
-      if (nickname)
+      /* Convert "*" to ".*", "?" to ".".  */
+      *p1++ = '^';
+      for (p0 = XSTRING (pattern)->data; *p0; p0++)
        {
-         /* Just prepend ".*-" to PATTERN.  */
-         *p1++= '.'; *p1++= '*', *p1++= '-';
-         bcopy (XSTRING (pattern)->data, p1, XSTRING (pattern)->size);
-         p1 += XSTRING (pattern)->size;
-       }
-      else
-       {
-         /* Convert "*" to ".*", "?" to ".".  */
-         *p1++ = '^';
-         for (p0 = XSTRING (pattern)->data; *p0; p0++)
+         if (*p0 == '*')
            {
-             if (*p0 == '*')
-               {
-                 *p1++ = '.';
-                 *p1++ = '*';
-               }
-             else if (*p0 == '?')
-               *p1++ == '.';
-             else
-               *p1++ = *p0;
+             *p1++ = '.';
+             *p1++ = '*';
            }
+         else if (*p0 == '?')
+           *p1++ == '.';
+         else
+           *p1++ = *p0;
        }
       *p1++ = '$';
       *p1++ = 0;
@@ -447,6 +437,10 @@ just like X's font name matching algorithm allows.")
   if (XSTRING (pattern)->size == 0)
     return Qnil;
 
+  tem = Frassoc (pattern, Vfontset_alias_alist);
+  if (!NILP (tem))
+    return Fcar (tem);
+
   regexp = fontset_pattern_regexp (pattern);
 
   for (tem = Vglobal_fontset_alist; CONSP (tem); tem = XCONS (tem)->cdr)
@@ -515,7 +509,7 @@ list_fontsets (f, pattern, size)
                 one with SIZE.  */
              int j;
 
-             for (j = 0; j < MAX_CHARSET; j++)
+             for (j = 0; j <= MAX_CHARSET; j++)
                if (fontsetp->fontname[j])
                  {
                    if ((*load_font_func) (f, fontsetp->fontname[j], size))
@@ -611,11 +605,12 @@ If FRAME is omitted or nil, all frames are affected.")
   if (NILP (frame))
     {
       Lisp_Object fontset_info = Fassoc (fullname, Vglobal_fontset_alist);
-      Lisp_Object tem = Fassq (charset, XCONS (fontset_info)->cdr);
+      Lisp_Object tem = Fassq (charset_symbol, XCONS (fontset_info)->cdr);
 
       if (NILP (tem))
        XCONS (fontset_info)->cdr
-         = Fcons (Fcons (charset, fontname), XCONS (fontset_info)->cdr);
+         = Fcons (Fcons (charset_symbol, fontname),
+                  XCONS (fontset_info)->cdr);
       else
        XCONS (tem)->cdr = fontname;
     }
@@ -634,13 +629,13 @@ If FRAME is omitted or nil, all frames are affected.")
          struct fontset_info *fontsetp
            = FRAME_FONTSET_DATA (f)->fontset_table[fontset];
 
-         if (fontsetp->fontname[XINT (charset)])
-           xfree (fontsetp->fontname[XINT (charset)]);
-         fontsetp->fontname[XINT (charset)]
+         if (fontsetp->fontname[charset])
+           xfree (fontsetp->fontname[charset]);
+         fontsetp->fontname[charset]
            = (char *) xmalloc (XSTRING (fontname)->size + 1);
-         bcopy (XSTRING (fontname)->data, fontsetp->fontname[XINT (charset)],
+         bcopy (XSTRING (fontname)->data, fontsetp->fontname[charset],
                 XSTRING (fontname)->size + 1);
-         fontsetp->font_indexes[XINT (charset)] = FONT_NOT_OPENED;
+         fontsetp->font_indexes[charset] = FONT_NOT_OPENED;
 
          if (charset == CHARSET_ASCII)
            {
@@ -665,7 +660,7 @@ DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0,
   "Return information about a font named NAME on frame FRAME.\n\
 If FRAME is omitted or nil, use the selected frame.\n\
 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,\n\
-  HEIGHT, BASELINE-OFFSET, and RELATIVE-COMPOSE,\n\
+  HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,\n\
 where\n\
   OPENED-NAME is the name used for opening the font,\n\
   FULL-NAME is the full name of the font,\n\
@@ -673,7 +668,8 @@ where\n\
   SIZE is the minimum bound width of the font,\n\
   HEIGHT is the height of the font,\n\
   BASELINE-OFFSET is the upward offset pixels from ASCII baseline,\n\
-  RELATIVE-COMPOSE is the number controlling how to compose characters.\n\
+  RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling\n\
+    how to compose characters.\n\
 If the named font is not yet loaded, return nil.")
   (name, frame)
      Lisp_Object name, frame;
@@ -700,7 +696,7 @@ If the named font is not yet loaded, return nil.")
   if (!fontp)
     return Qnil;
 
-  info = Fmake_vector (make_number (6), Qnil);
+  info = Fmake_vector (make_number (7), Qnil);
 
   XVECTOR (info)->contents[0] = build_string (fontp->name);
   XVECTOR (info)->contents[1] = build_string (fontp->full_name);
@@ -709,6 +705,7 @@ If the named font is not yet loaded, return nil.")
   XVECTOR (info)->contents[4] = make_number (fontp->height);
   XVECTOR (info)->contents[5] = make_number (fontp->baseline_offset);
   XVECTOR (info)->contents[6] = make_number (fontp->relative_compose);
+  XVECTOR (info)->contents[7] = make_number (fontp->default_ascent);
 
   return info;
 }
@@ -755,7 +752,7 @@ loading failed.")
   XVECTOR (info)->contents[0] = make_number (fontsetp->size);
   XVECTOR (info)->contents[1] = make_number (fontsetp->height);
   val = Qnil;
-  for (i = 0; i < MAX_CHARSET; i++)
+  for (i = 0; i <= MAX_CHARSET; i++)
     if (fontsetp->fontname[i])
       {
        int font_idx = fontsetp->font_indexes[i];
@@ -788,6 +785,7 @@ syms_of_fontset ()
     /* Window system initializer should have set proper functions.  */
     abort ();
 
+  Qfontset = intern ("fontset");
   staticpro (&Qfontset);
 
   Vcached_fontset_data = Qnil;
@@ -811,6 +809,42 @@ ENCODING is one of the following integer values:\n\
        3: code points 0xA020..0xFF7F are used.");
   Vfont_encoding_alist = Qnil;
 
+  DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent,
+     "Char table of characters of which ascent values should be ignored.\n\
+If an entry for a character is non-nil, the ascent value of the glyph\n\
+is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.");
+  Vuse_default_ascent = Qnil;
+
+  DEFVAR_LISP ("alternative-fontname-alist", &Valternative_fontname_alist,
+     "Alist of fontname vs list of the alternative fontnames.\n\
+When no font can be opened by a fontname, the corresponding\n\
+alternative fontnames are tried.");
+  Valternative_fontname_alist = Qnil;
+
+  DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist,
+     "Alist of fontset names vs the aliases.");
+  Vfontset_alias_alist = Qnil;
+
+  DEFVAR_LISP ("highlight-wrong-size-font", &Vhighlight_wrong_size_font,
+     "*Non-nil means highlight characters shown in wrong size fonts somehow.\n\
+The way to highlight them depends on window system on which Emacs runs.\n\
+On X window, a rectangle is shown around each such character.");
+  Vhighlight_wrong_size_font = Qt;
+
+  DEFVAR_LISP ("clip-large-size-font", &Vclip_large_size_font,
+     "*Non-nil means characters shown in large size fonts are clipped.\n\
+The height of clipping area is the same as that of an ASCII character.\n\
+The width of the area is the same as that of an ASCII character or\n\
+twice wider than that of an ASCII character depending on\n\
+the width (i.e. column numbers occupied on screen) of the character set\n\
+of the character.\n\
+\n\
+In the case that you only have too large size font for a specific\n\
+charscter set, and clipping characters of the character set makes them\n\
+almost unreadable, you can set this variable to t to see the\n\
+characters in exchage for garbage dots left on your screen.");
+  Vclip_large_size_font = Qt;
+
   defsubr (&Squery_fontset);
   defsubr (&Snew_fontset);
   defsubr (&Sset_fontset_font);