diff options
| author | Kenichi Handa | 2012-01-13 14:47:28 +0900 |
|---|---|---|
| committer | Kenichi Handa | 2012-01-13 14:47:28 +0900 |
| commit | 25ed9e61dbea0a7a4f4a84288000bc30ebd7ac87 (patch) | |
| tree | 350d6b4d923ea8c0cf03a0206496f0d8107c9d64 /src | |
| parent | 39ac32998179359c74f49be6564f11acf4db8b20 (diff) | |
| download | emacs-25ed9e61dbea0a7a4f4a84288000bc30ebd7ac87.tar.gz emacs-25ed9e61dbea0a7a4f4a84288000bc30ebd7ac87.zip | |
Take display-table into account on calculating character/string width (#Bug#9496).
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/character.c | 66 |
2 files changed, 35 insertions, 37 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 62554190500..4c657ae64ee 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2011-12-26 Kenichi Handa <handa@m17n.org> | ||
| 2 | |||
| 3 | * character.c (char_width): New function. | ||
| 4 | (Fchar_width, c_string_width, lisp_string_width): Use char_width | ||
| 5 | (Bug#9496). | ||
| 6 | |||
| 1 | 2012-01-12 Sven Joachim <svenjoac@gmx.de> | 7 | 2012-01-12 Sven Joachim <svenjoac@gmx.de> |
| 2 | 8 | ||
| 3 | * s/gnu-linux.h: Use CRT_DIR. | 9 | * s/gnu-linux.h: Use CRT_DIR. |
diff --git a/src/character.c b/src/character.c index 75ec720aecd..0409f30dc0e 100644 --- a/src/character.c +++ b/src/character.c | |||
| @@ -361,6 +361,31 @@ usage: (char-bytes CHAR) */) | |||
| 361 | return make_number (1); | 361 | return make_number (1); |
| 362 | } | 362 | } |
| 363 | 363 | ||
| 364 | |||
| 365 | /* Return width (columns) of C considering the buffer display table DP. */ | ||
| 366 | |||
| 367 | static int | ||
| 368 | char_width (int c, struct Lisp_Char_Table *dp) | ||
| 369 | { | ||
| 370 | int width = CHAR_WIDTH (c); | ||
| 371 | |||
| 372 | if (dp) | ||
| 373 | { | ||
| 374 | Lisp_Object disp = DISP_CHAR_VECTOR (dp, c), ch; | ||
| 375 | int i; | ||
| 376 | |||
| 377 | if (VECTORP (disp)) | ||
| 378 | for (i = 0, width = 0; i < ASIZE (disp); i++) | ||
| 379 | { | ||
| 380 | ch = AREF (disp, i); | ||
| 381 | if (CHARACTERP (ch)) | ||
| 382 | width += CHAR_WIDTH (XFASTINT (ch)); | ||
| 383 | } | ||
| 384 | } | ||
| 385 | return width; | ||
| 386 | } | ||
| 387 | |||
| 388 | |||
| 364 | DEFUN ("char-width", Fchar_width, Schar_width, 1, 1, 0, | 389 | DEFUN ("char-width", Fchar_width, Schar_width, 1, 1, 0, |
| 365 | doc: /* Return width of CHAR when displayed in the current buffer. | 390 | doc: /* Return width of CHAR when displayed in the current buffer. |
| 366 | The width is measured by how many columns it occupies on the screen. | 391 | The width is measured by how many columns it occupies on the screen. |
| @@ -369,21 +394,12 @@ usage: (char-width CHAR) */) | |||
| 369 | (ch) | 394 | (ch) |
| 370 | Lisp_Object ch; | 395 | Lisp_Object ch; |
| 371 | { | 396 | { |
| 372 | Lisp_Object disp; | ||
| 373 | int c, width; | 397 | int c, width; |
| 374 | struct Lisp_Char_Table *dp = buffer_display_table (); | ||
| 375 | 398 | ||
| 376 | CHECK_CHARACTER (ch); | 399 | CHECK_CHARACTER (ch); |
| 377 | c = XINT (ch); | 400 | c = XINT (ch); |
| 378 | 401 | ||
| 379 | /* Get the way the display table would display it. */ | 402 | width = char_width (c, buffer_display_table ()); |
| 380 | disp = dp ? DISP_CHAR_VECTOR (dp, c) : Qnil; | ||
| 381 | |||
| 382 | if (VECTORP (disp)) | ||
| 383 | width = ASIZE (disp); | ||
| 384 | else | ||
| 385 | width = CHAR_WIDTH (c); | ||
| 386 | |||
| 387 | return make_number (width); | 403 | return make_number (width); |
| 388 | } | 404 | } |
| 389 | 405 | ||
| @@ -403,22 +419,9 @@ c_string_width (const unsigned char *str, int len, int precision, int *nchars, i | |||
| 403 | 419 | ||
| 404 | while (i_byte < len) | 420 | while (i_byte < len) |
| 405 | { | 421 | { |
| 406 | int bytes, thiswidth; | 422 | int bytes; |
| 407 | Lisp_Object val; | ||
| 408 | int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes); | 423 | int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes); |
| 409 | 424 | int thiswidth = char_width (c, dp); | |
| 410 | if (dp) | ||
| 411 | { | ||
| 412 | val = DISP_CHAR_VECTOR (dp, c); | ||
| 413 | if (VECTORP (val)) | ||
| 414 | thiswidth = XVECTOR_SIZE (val); | ||
| 415 | else | ||
| 416 | thiswidth = CHAR_WIDTH (c); | ||
| 417 | } | ||
| 418 | else | ||
| 419 | { | ||
| 420 | thiswidth = CHAR_WIDTH (c); | ||
| 421 | } | ||
| 422 | 425 | ||
| 423 | if (precision > 0 | 426 | if (precision > 0 |
| 424 | && (width + thiswidth > precision)) | 427 | && (width + thiswidth > precision)) |
| @@ -499,18 +502,7 @@ lisp_string_width (string, precision, nchars, nbytes) | |||
| 499 | else | 502 | else |
| 500 | c = str[i_byte], bytes = 1; | 503 | c = str[i_byte], bytes = 1; |
| 501 | chars = 1; | 504 | chars = 1; |
| 502 | if (dp) | 505 | thiswidth = char_width (c, dp); |
| 503 | { | ||
| 504 | val = DISP_CHAR_VECTOR (dp, c); | ||
| 505 | if (VECTORP (val)) | ||
| 506 | thiswidth = XVECTOR_SIZE (val); | ||
| 507 | else | ||
| 508 | thiswidth = CHAR_WIDTH (c); | ||
| 509 | } | ||
| 510 | else | ||
| 511 | { | ||
| 512 | thiswidth = CHAR_WIDTH (c); | ||
| 513 | } | ||
| 514 | } | 506 | } |
| 515 | 507 | ||
| 516 | if (precision > 0 | 508 | if (precision > 0 |