]> code.delx.au - gnu-emacs/blobdiff - src/charset.c
* xfns.c (xpm_load) [!ALLOC_XPM_COLORS]: Declare local variable I in inner block.
[gnu-emacs] / src / charset.c
index f350572a9d2389ac97a5e9fb2baa1f1732ed41ed..38683dc5c0fe571dcd449b3d83b91c5fc99557d5 100644 (file)
@@ -34,6 +34,7 @@ Boston, MA 02111-1307, USA.  */
 #include "lisp.h"
 #include "buffer.h"
 #include "charset.h"
+#include "composite.h"
 #include "coding.h"
 #include "disptab.h"
 
@@ -221,7 +222,7 @@ char_to_string (c, str)
          *p++ = c + 0x20;
        }
     }
-  else if (CHAR_VALID_P (c))
+  else if (CHAR_VALID_P (c, 0))
     {
       int charset, c1, c2;
 
@@ -315,7 +316,7 @@ int
 char_printable_p (c)
      int c;
 {
-  int charset, c1, c2, chars;
+  int charset, c1, c2;
 
   if (ASCII_BYTE_P (c))
     return 1;
@@ -596,17 +597,13 @@ get_new_private_charset_id (dimension, width)
 
   if (dimension == 1)
     {
-      if (width == 1)
-       from = LEADING_CODE_EXT_11, to = LEADING_CODE_EXT_12;
-      else
-       from = LEADING_CODE_EXT_12, to = LEADING_CODE_EXT_21;
+      from = LEADING_CODE_EXT_11;
+      to = LEADING_CODE_EXT_21;
     }
   else
     {
-      if (width == 1)
-       from = LEADING_CODE_EXT_21, to = LEADING_CODE_EXT_22;
-      else
-       from = LEADING_CODE_EXT_22, to = LEADING_CODE_EXT_MAX + 1;
+      from = LEADING_CODE_EXT_21;
+      to = LEADING_CODE_EXT_MAX + 1;
     }
 
   for (charset = from; charset < to; charset++)
@@ -849,7 +846,7 @@ DEFUN ("find-charset-region", Ffind_charset_region, Sfind_charset_region,
 BEG and END are buffer positions.\n\
 Optional arg TABLE if non-nil is a translation table to look up.\n\
 \n\
-If the region contains invalid multiybte characters,\n\
+If the region contains invalid multibyte characters,\n\
 `unknown' is included in the returned list.\n\
 \n\
 If the current buffer is unibyte, the returned list may contain\n\
@@ -905,7 +902,7 @@ DEFUN ("find-charset-string", Ffind_charset_string, Sfind_charset_string,
   "Return a list of charsets in STR.\n\
 Optional arg TABLE if non-nil is a translation table to look up.\n\
 \n\
-If the region contains invalid multiybte characters,\n\
+If the string contains invalid multibyte characters,\n\
 `unknown' is included in the returned list.\n\
 \n\
 If STR is unibyte, the returned list may contain\n\
@@ -970,13 +967,17 @@ DEFUN ("make-char-internal", Fmake_char_internal, Smake_char_internal, 1, 3, 0,
     }
   else if (charset_id == CHARSET_8_BIT_CONTROL)
     {
-      if (c1 < 0x80 || c1 > 0x9F)
+      if (NILP (code1))
+       c1 = 0x80;
+      else if (c1 < 0x80 || c1 > 0x9F)
        goto invalid_code_posints;
       return make_number (c1);
     }
   else if (charset_id == CHARSET_8_BIT_GRAPHIC)
     {
-      if (c1 < 0xA0 || c1 > 0xFF)
+      if (NILP (code1))
+       c1 = 0xA0;
+      else if (c1 < 0xA0 || c1 > 0xFF)
        goto invalid_code_posints;
       return make_number (c1);
     }
@@ -1003,7 +1004,6 @@ return a list of symbol `unknown' and CHAR.")
   (ch)
      Lisp_Object ch;
 {
-  Lisp_Object val;
   int c, charset, c1, c2;
 
   CHECK_NUMBER (ch, 0);
@@ -1154,8 +1154,6 @@ This is now an obsolete function.  We keep it just for backward compatibility.")
   (ch)
      Lisp_Object ch;
 {
-  Lisp_Object val;
-
   CHECK_NUMBER (ch, 0);
   return make_number (1);
 }
@@ -1261,6 +1259,44 @@ strwidth (str, len)
   return width;
 }
 
+int
+lisp_string_width (str)
+     Lisp_Object str;
+{
+  int len = XSTRING (str)->size, len_byte = STRING_BYTES (XSTRING (str));
+  int i = 0, i_byte;
+  int width = 0;
+  int start, end, start_byte;
+  Lisp_Object prop;
+  int cmp_id;
+
+  while (i < len)
+    {
+      if (find_composition (i, len, &start, &end, &prop, str))
+       {
+         start_byte = string_char_to_byte (str, start);
+         if (i < start)
+           {
+             i_byte = string_char_to_byte (str, i);
+             width += strwidth (XSTRING (str)->data + i_byte,
+                                start_byte - i_byte);
+           }
+         cmp_id
+           = get_composition_id (start, start_byte, end - start, prop, str);
+         if (cmp_id >= 0)
+           width += composition_table[cmp_id]->width;
+         i = end;
+       }
+      else
+       {
+         i_byte = string_char_to_byte (str, i);
+         width += strwidth (XSTRING (str)->data + i_byte, len_byte - i_byte);
+         i = len;
+       }
+    }
+  return width;
+}
+
 DEFUN ("string-width", Fstring_width, Sstring_width, 1, 1, 0,
   "Return width of STRING when displayed in the current buffer.\n\
 Width is measured by how many columns it occupies on the screen.\n\
@@ -1274,8 +1310,7 @@ taken to occupy `tab-width' columns.")
   Lisp_Object val;
 
   CHECK_STRING (str, 0);
-  XSETFASTINT (val, strwidth (XSTRING (str)->data,
-                             STRING_BYTES (XSTRING (str))));
+  XSETFASTINT (val, lisp_string_width (str));
   return val;
 }
 
@@ -1440,7 +1475,6 @@ str_to_multibyte (str, len, bytes)
 {
   unsigned char *p = str, *endp = str + bytes;
   unsigned char *to;
-  int c;
 
   while (p < endp && (*p < 0x80 || *p >= 0xA0)) p++;
   if (p == endp)