aboutsummaryrefslogtreecommitdiffstats
path: root/src/character.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/character.c')
-rw-r--r--src/character.c69
1 files changed, 30 insertions, 39 deletions
diff --git a/src/character.c b/src/character.c
index 88b1f11b96b..593fbcece0b 100644
--- a/src/character.c
+++ b/src/character.c
@@ -1,6 +1,6 @@
1/* Basic character support. 1/* Basic character support.
2 2
3Copyright (C) 2001-2011 Free Software Foundation, Inc. 3Copyright (C) 2001-2012 Free Software Foundation, Inc.
4Copyright (C) 1995, 1997, 1998, 2001 Electrotechnical Laboratory, JAPAN. 4Copyright (C) 1995, 1997, 1998, 2001 Electrotechnical Laboratory, JAPAN.
5 Licensed to the Free Software Foundation. 5 Licensed to the Free Software Foundation.
6Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 6Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
@@ -308,6 +308,31 @@ If the multibyte character does not represent a byte, return -1. */)
308 } 308 }
309} 309}
310 310
311
312/* Return width (columns) of C considering the buffer display table DP. */
313
314static int
315char_width (int c, struct Lisp_Char_Table *dp)
316{
317 int width = CHAR_WIDTH (c);
318
319 if (dp)
320 {
321 Lisp_Object disp = DISP_CHAR_VECTOR (dp, c), ch;
322 int i;
323
324 if (VECTORP (disp))
325 for (i = 0, width = 0; i < ASIZE (disp); i++)
326 {
327 ch = AREF (disp, i);
328 if (CHARACTERP (ch))
329 width += CHAR_WIDTH (XFASTINT (ch));
330 }
331 }
332 return width;
333}
334
335
311DEFUN ("char-width", Fchar_width, Schar_width, 1, 1, 0, 336DEFUN ("char-width", Fchar_width, Schar_width, 1, 1, 0,
312 doc: /* Return width of CHAR when displayed in the current buffer. 337 doc: /* Return width of CHAR when displayed in the current buffer.
313The width is measured by how many columns it occupies on the screen. 338The width is measured by how many columns it occupies on the screen.
@@ -315,21 +340,11 @@ Tab is taken to occupy `tab-width' columns.
315usage: (char-width CHAR) */) 340usage: (char-width CHAR) */)
316 (Lisp_Object ch) 341 (Lisp_Object ch)
317{ 342{
318 Lisp_Object disp;
319 int c, width; 343 int c, width;
320 struct Lisp_Char_Table *dp = buffer_display_table ();
321 344
322 CHECK_CHARACTER (ch); 345 CHECK_CHARACTER (ch);
323 c = XINT (ch); 346 c = XINT (ch);
324 347 width = char_width (c, buffer_display_table ());
325 /* Get the way the display table would display it. */
326 disp = dp ? DISP_CHAR_VECTOR (dp, c) : Qnil;
327
328 if (VECTORP (disp))
329 width = sanitize_char_width (ASIZE (disp));
330 else
331 width = CHAR_WIDTH (c);
332
333 return make_number (width); 348 return make_number (width);
334} 349}
335 350
@@ -350,22 +365,9 @@ c_string_width (const unsigned char *str, EMACS_INT len, int precision,
350 365
351 while (i_byte < len) 366 while (i_byte < len)
352 { 367 {
353 int bytes, thiswidth; 368 int bytes;
354 Lisp_Object val;
355 int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes); 369 int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes);
356 370 int thiswidth = char_width (c, dp);
357 if (dp)
358 {
359 val = DISP_CHAR_VECTOR (dp, c);
360 if (VECTORP (val))
361 thiswidth = sanitize_char_width (ASIZE (val));
362 else
363 thiswidth = CHAR_WIDTH (c);
364 }
365 else
366 {
367 thiswidth = CHAR_WIDTH (c);
368 }
369 371
370 if (precision > 0 372 if (precision > 0
371 && (width + thiswidth > precision)) 373 && (width + thiswidth > precision))
@@ -447,18 +449,7 @@ lisp_string_width (Lisp_Object string, EMACS_INT precision,
447 else 449 else
448 c = str[i_byte], bytes = 1; 450 c = str[i_byte], bytes = 1;
449 chars = 1; 451 chars = 1;
450 if (dp) 452 thiswidth = char_width (c, dp);
451 {
452 val = DISP_CHAR_VECTOR (dp, c);
453 if (VECTORP (val))
454 thiswidth = sanitize_char_width (ASIZE (val));
455 else
456 thiswidth = CHAR_WIDTH (c);
457 }
458 else
459 {
460 thiswidth = CHAR_WIDTH (c);
461 }
462 } 453 }
463 454
464 if (precision <= 0) 455 if (precision <= 0)