aboutsummaryrefslogtreecommitdiffstats
path: root/src/charset.c
diff options
context:
space:
mode:
authorRichard M. Stallman <[email protected]>1997-05-15 18:26:28 +0000
committerRichard M. Stallman <[email protected]>1997-05-15 18:26:28 +0000
commit859f2b3c0288f29f8c23197a4ccbf2ad65f254c6 (patch)
tree5d6620f55245962d28b067be08abbd9202f678e3 /src/charset.c
parent9e96f9415fe31e4325aabbf73da3c7e3c7635296 (diff)
(strwidth, Fchar_width): Handle display table.
Diffstat (limited to 'src/charset.c')
-rw-r--r--src/charset.c71
1 files changed, 46 insertions, 25 deletions
diff --git a/src/charset.c b/src/charset.c
index 3a4eec181a..3b599e1fe6 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -740,14 +740,20 @@ The width is measured by how many columns it occupies on the screen.")
(ch)
Lisp_Object ch;
{
- Lisp_Object val;
+ Lisp_Object val, disp;
int c;
CHECK_NUMBER (ch, 0);
- c = XFASTINT (ch);
- if (SINGLE_BYTE_CHAR_P (c))
- XSETFASTINT (val, ONE_BYTE_CHAR_WIDTH (c));
+ c = XINT (ch);
+
+ /* Get the way the display table would display it. */
+ disp = DISP_CHAR_VECTOR (buffer_display_table (current_buffer), (c));
+
+ if (VECTORP (disp))
+ XSETINT (val, XVECTOR (disp)->size);
+ else if (SINGLE_BYTE_CHAR_P (c))
+ XSETINT (val, ONE_BYTE_CHAR_WIDTH (c));
else if (COMPOSITE_CHAR_P (c))
{
int id = COMPOSITE_CHAR_ID (XFASTINT (ch));
@@ -765,6 +771,7 @@ The width is measured by how many columns it occupies on the screen.")
/* Return width of string STR of length LEN when displayed in the
current buffer. The width is measured by how many columns it
occupies on the screen. */
+
int
strwidth (str, len)
unsigned char *str;
@@ -772,29 +779,43 @@ strwidth (str, len)
{
unsigned char *endp = str + len;
int width = 0;
+ struct Lisp_Char_Table *dp = buffer_display_table (current_buffer);
- while (str < endp) {
- if (*str == LEADING_CODE_COMPOSITION)
- {
- int id = str_cmpchar_id (str, endp - str);
+ while (str < endp)
+ {
+ if (*str == LEADING_CODE_COMPOSITION)
+ {
+ int id = str_cmpchar_id (str, endp - str);
- if (id < 0)
- {
- width += 4;
- str++;
- }
- else
- {
- width += cmpchar_table[id]->width;
- str += cmpchar_table[id]->len;
- }
- }
- else
- {
- width += ONE_BYTE_CHAR_WIDTH (*str);
- str += BYTES_BY_CHAR_HEAD (*str);
- }
- }
+ if (id < 0)
+ {
+ width += 4;
+ str++;
+ }
+ else
+ {
+ width += cmpchar_table[id]->width;
+ str += cmpchar_table[id]->len;
+ }
+ }
+ else
+ {
+ Lisp_Object disp;
+ int thiswidth;
+ int c = STRING_CHAR (str, endp - str);
+
+ /* Get the way the display table would display it. */
+ disp = DISP_CHAR_VECTOR (dp, c);
+
+ if (VECTORP (disp))
+ thiswidth = XVECTOR (disp)->size;
+ else
+ thiswidth = ONE_BYTE_CHAR_WIDTH (*str);
+
+ width += thiswidth;
+ str += BYTES_BY_CHAR_HEAD (*str);
+ }
+ }
return width;
}