#include "lisp.h"
#include "buffer.h"
#include "charset.h"
+#include "composite.h"
#include "coding.h"
#include "disptab.h"
*p++ = c + 0x20;
}
}
- else if (CHAR_VALID_P (c))
+ else if (CHAR_VALID_P (c, 0))
{
int charset, c1, c2;
char_printable_p (c)
int c;
{
- int charset, c1, c2, chars;
+ int charset, c1, c2;
if (ASCII_BYTE_P (c))
return 1;
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++)
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\
"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\
}
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);
}
(ch)
Lisp_Object ch;
{
- Lisp_Object val;
int c, charset, c1, c2;
CHECK_NUMBER (ch, 0);
(ch)
Lisp_Object ch;
{
- Lisp_Object val;
-
CHECK_NUMBER (ch, 0);
return make_number (1);
}
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\
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;
}
{
unsigned char *p = str, *endp = str + bytes;
unsigned char *to;
- int c;
while (p < endp && (*p < 0x80 || *p >= 0xA0)) p++;
if (p == endp)