summaryrefslogtreecommitdiff
path: root/src/charset.c
diff options
context:
space:
mode:
authorKenichi Handa <handa@m17n.org>2000-09-07 02:35:08 +0000
committerKenichi Handa <handa@m17n.org>2000-09-07 02:35:08 +0000
commit3f62427c0c1a2357fa85dde79db5f6a15717858f (patch)
tree8c1a4647b2212a10645c542f710df0e9652c8072 /src/charset.c
parentd69864bf3ee0b990101fee34f3dc857cf3f13ea4 (diff)
downloademacs-3f62427c0c1a2357fa85dde79db5f6a15717858f.tar.gz
Include composite.h
(lisp_string_width): New function. (Fstring_width): Call lisp_string_width instead of strwidth.
Diffstat (limited to 'src/charset.c')
-rw-r--r--src/charset.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/charset.c b/src/charset.c
index 76dde15f7ab..329f7fd0221 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -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"
@@ -1261,6 +1262,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 +1313,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;
}