Use "ASET (a, i, v)" rather than "AREF (a, i) = v".
[bpt/emacs.git] / src / font.c
index 27abbe2..b5e3841 100644 (file)
@@ -59,10 +59,6 @@ Lisp_Object Qascii_0, Qiso8859_1, Qiso10646_1, Qunicode_bmp, Qunicode_sip;
 /* Unicode category `Cf'.  */
 static Lisp_Object QCf;
 
-/* Special vector of zero length.  This is repeatedly used by (struct
-   font_driver *)->list when a specified font is not found. */
-static Lisp_Object null_vector;
-
 /* Vector of Vfont_weight_table, Vfont_slant_table, and Vfont_width_table. */
 static Lisp_Object font_style_table;
 
@@ -264,18 +260,12 @@ font_intern_prop (const char *str, ptrdiff_t len, int force_symbol)
        }
     }
 
-  /* The following code is copied from the function intern (in
-     lread.c), and modified to suit our purpose.  */
-  obarray = Vobarray;
-  if (!VECTORP (obarray) || ASIZE (obarray) == 0)
-    obarray = check_obarray (obarray);
+  /* This code is similar to intern function from lread.c.  */
+  obarray = check_obarray (Vobarray);
   parse_str_as_multibyte ((unsigned char *) str, len, &nchars, &nbytes);
-  if (len == nchars || len != nbytes)
-    /* CONTENTS contains no multibyte sequences or contains an invalid
-       multibyte sequence.  We'll make a unibyte string.  */
-    tem = oblookup (obarray, str, len, len);
-  else
-    tem = oblookup (obarray, str, nchars, len);
+  tem = oblookup (obarray, str,
+                 (len == nchars || len != nbytes) ? len : nchars, len);
+
   if (SYMBOLP (tem))
     return tem;
   if (len == nchars || len != nbytes)
@@ -1199,7 +1189,7 @@ font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font)
    length), and return the name length.  If FONT_SIZE_INDEX of FONT is
    0, use PIXEL_SIZE instead.  */
 
-int
+ptrdiff_t
 font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
 {
   char *p;
@@ -1827,7 +1817,7 @@ check_otf_features (Lisp_Object otf_features)
   otf_features = XCDR (otf_features);
   for (val = Fcar (otf_features); CONSP (val); val = XCDR (val))
     {
-      CHECK_SYMBOL (Fcar (val));
+      CHECK_SYMBOL (XCAR (val));
       if (SBYTES (SYMBOL_NAME (XCAR (val))) > 4)
        error ("Invalid OTF GSUB feature: %s",
               SDATA (SYMBOL_NAME (XCAR (val))));
@@ -1835,7 +1825,7 @@ check_otf_features (Lisp_Object otf_features)
   otf_features = XCDR (otf_features);
   for (val = Fcar (otf_features); CONSP (val); val = XCDR (val))
     {
-      CHECK_SYMBOL (Fcar (val));
+      CHECK_SYMBOL (XCAR (val));
       if (SBYTES (SYMBOL_NAME (XCAR (val))) > 4)
        error ("Invalid OTF GPOS feature: %s",
               SDATA (SYMBOL_NAME (XCAR (val))));
@@ -2642,15 +2632,18 @@ font_delete_unmatched (Lisp_Object vec, Lisp_Object spec, int size)
       if (! NILP (Vface_ignored_fonts))
        {
          char name[256];
+         ptrdiff_t namelen;
          Lisp_Object tail, regexp;
 
-         if (font_unparse_xlfd (entity, 0, name, 256) >= 0)
+         namelen = font_unparse_xlfd (entity, 0, name, 256);
+         if (namelen >= 0)
            {
              for (tail = Vface_ignored_fonts; CONSP (tail); tail = XCDR (tail))
                {
                  regexp = XCAR (tail);
                  if (STRINGP (regexp)
-                     && fast_c_string_match_ignore_case (regexp, name) >= 0)
+                     && fast_c_string_match_ignore_case (regexp, name,
+                                                         namelen) >= 0)
                    break;
                }
              if (CONSP (tail))
@@ -2751,7 +2744,7 @@ font_list_entities (Lisp_Object frame, Lisp_Object spec)
 
            val = driver_list->driver->list (frame, scratch_font_spec);
            if (NILP (val))
-             val = null_vector;
+             val = zero_vector;
            else
              val = Fvconcat (1, &val);
            copy = copy_font_spec (scratch_font_spec);
@@ -3107,10 +3100,10 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
     {
       registry[0] = DEFAULT_ENCODING;
       registry[1] = Qascii_0;
-      registry[2] = null_vector;
+      registry[2] = zero_vector;
     }
   else
-    registry[1] = null_vector;
+    registry[1] = zero_vector;
 
   if (c >= 0 && ! NILP (AREF (spec, FONT_REGISTRY_INDEX)))
     {
@@ -3139,20 +3132,20 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
   ASET (work, FONT_SIZE_INDEX, Qnil);
   foundry[0] = AREF (work, FONT_FOUNDRY_INDEX);
   if (! NILP (foundry[0]))
-    foundry[1] = null_vector;
+    foundry[1] = zero_vector;
   else if (STRINGP (attrs[LFACE_FOUNDRY_INDEX]))
     {
       val = attrs[LFACE_FOUNDRY_INDEX];
       foundry[0] = font_intern_prop (SSDATA (val), SBYTES (val), 1);
       foundry[1] = Qnil;
-      foundry[2] = null_vector;
+      foundry[2] = zero_vector;
     }
   else
-    foundry[0] = Qnil, foundry[1] = null_vector;
+    foundry[0] = Qnil, foundry[1] = zero_vector;
 
   adstyle[0] = AREF (work, FONT_ADSTYLE_INDEX);
   if (! NILP (adstyle[0]))
-    adstyle[1] = null_vector;
+    adstyle[1] = zero_vector;
   else if (FONTP (attrs[LFACE_FONT_INDEX]))
     {
       Lisp_Object face_font = attrs[LFACE_FONT_INDEX];
@@ -3161,13 +3154,13 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
        {
          adstyle[0] = AREF (face_font, FONT_ADSTYLE_INDEX);
          adstyle[1] = Qnil;
-         adstyle[2] = null_vector;
+         adstyle[2] = zero_vector;
        }
       else
-       adstyle[0] = Qnil, adstyle[1] = null_vector;
+       adstyle[0] = Qnil, adstyle[1] = zero_vector;
     }
   else
-    adstyle[0] = Qnil, adstyle[1] = null_vector;
+    adstyle[0] = Qnil, adstyle[1] = zero_vector;
 
 
   val = AREF (work, FONT_FAMILY_INDEX);
@@ -3180,7 +3173,7 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
     {
       family = alloca ((sizeof family[0]) * 2);
       family[0] = Qnil;
-      family[1] = null_vector; /* terminator.  */
+      family[1] = zero_vector; /* terminator.  */
     }
   else
     {
@@ -3195,7 +3188,7 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
            family[i] = XCAR (alters);
          if (NILP (AREF (spec, FONT_FAMILY_INDEX)))
            family[i++] = Qnil;
-         family[i] = null_vector;
+         family[i] = zero_vector;
        }
       else
        {
@@ -3204,7 +3197,7 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
          family[i++] = val;
          if (NILP (AREF (spec, FONT_FAMILY_INDEX)))
            family[i++] = Qnil;
-         family[i] = null_vector;
+         family[i] = zero_vector;
        }
     }
 
@@ -3357,13 +3350,13 @@ font_open_by_spec (FRAME_PTR f, Lisp_Object spec)
    found, return Qnil.  */
 
 Lisp_Object
-font_open_by_name (FRAME_PTR f, const char *name, ptrdiff_t len)
+font_open_by_name (FRAME_PTR f, Lisp_Object name)
 {
   Lisp_Object args[2];
   Lisp_Object spec, ret;
 
   args[0] = QCname;
-  args[1] = make_unibyte_string (name, len);
+  args[1] = name;
   spec = Ffont_spec (2, args);
   ret = font_open_by_spec (f, spec);
   /* Do not lose name originally put in.  */
@@ -3672,7 +3665,7 @@ font_at (int c, ptrdiff_t pos, struct face *face, struct window *w,
        }
     }
 
-  f = XFRAME (w->frame);
+  f = XFRAME (WVAR (w, frame));
   if (! FRAME_WINDOW_P (f))
     return Qnil;
   if (! face)
@@ -3730,7 +3723,7 @@ font_range (ptrdiff_t pos, ptrdiff_t *limit, struct window *w, struct face *face
 
          face_id = face_at_buffer_position (w, pos, 0, 0, &ignore,
                                             *limit, 0, -1);
-         face = FACE_FROM_ID (XFRAME (w->frame), face_id);
+         face = FACE_FROM_ID (XFRAME (WVAR (w, frame)), face_id);
        }
     }
   else
@@ -4729,7 +4722,7 @@ the corresponding element is nil.  */)
          Lisp_Object elt = AREF (object, XFASTINT (from) + i);
          CHECK_CHARACTER (elt);
        }
-      chars = &(AREF (object, XFASTINT (from)));
+      chars = aref_addr (object, XFASTINT (from));
     }
 
   vec = Fmake_vector (make_number (len), Qnil);
@@ -4885,7 +4878,7 @@ If the named font is not yet loaded, return nil.  */)
 
       if (fontset >= 0)
        name = fontset_ascii (fontset);
-      font_object = font_open_by_name (f, SSDATA (name), SBYTES (name));
+      font_object = font_open_by_name (f, name);
     }
   else if (FONT_OBJECT_P (name))
     font_object = name;
@@ -5098,9 +5091,6 @@ syms_of_font (void)
 
   DEFSYM (QCuser_spec, "user-spec");
 
-  staticpro (&null_vector);
-  null_vector = Fmake_vector (make_number (0), Qnil);
-
   staticpro (&scratch_font_spec);
   scratch_font_spec = Ffont_spec (0, NULL);
   staticpro (&scratch_font_prefer);