aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1997-05-15 18:26:28 +0000
committerRichard M. Stallman1997-05-15 18:26:28 +0000
commit859f2b3c0288f29f8c23197a4ccbf2ad65f254c6 (patch)
tree5d6620f55245962d28b067be08abbd9202f678e3 /src
parent9e96f9415fe31e4325aabbf73da3c7e3c7635296 (diff)
downloademacs-859f2b3c0288f29f8c23197a4ccbf2ad65f254c6.tar.gz
emacs-859f2b3c0288f29f8c23197a4ccbf2ad65f254c6.zip
(strwidth, Fchar_width): Handle display table.
Diffstat (limited to 'src')
-rw-r--r--src/charset.c71
1 files changed, 46 insertions, 25 deletions
diff --git a/src/charset.c b/src/charset.c
index 3a4eec181a8..3b599e1fe69 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.")
740 (ch) 740 (ch)
741 Lisp_Object ch; 741 Lisp_Object ch;
742{ 742{
743 Lisp_Object val; 743 Lisp_Object val, disp;
744 int c; 744 int c;
745 745
746 CHECK_NUMBER (ch, 0); 746 CHECK_NUMBER (ch, 0);
747 747
748 c = XFASTINT (ch); 748 c = XINT (ch);
749 if (SINGLE_BYTE_CHAR_P (c)) 749
750 XSETFASTINT (val, ONE_BYTE_CHAR_WIDTH (c)); 750 /* Get the way the display table would display it. */
751 disp = DISP_CHAR_VECTOR (buffer_display_table (current_buffer), (c));
752
753 if (VECTORP (disp))
754 XSETINT (val, XVECTOR (disp)->size);
755 else if (SINGLE_BYTE_CHAR_P (c))
756 XSETINT (val, ONE_BYTE_CHAR_WIDTH (c));
751 else if (COMPOSITE_CHAR_P (c)) 757 else if (COMPOSITE_CHAR_P (c))
752 { 758 {
753 int id = COMPOSITE_CHAR_ID (XFASTINT (ch)); 759 int id = COMPOSITE_CHAR_ID (XFASTINT (ch));
@@ -765,6 +771,7 @@ The width is measured by how many columns it occupies on the screen.")
765/* Return width of string STR of length LEN when displayed in the 771/* Return width of string STR of length LEN when displayed in the
766 current buffer. The width is measured by how many columns it 772 current buffer. The width is measured by how many columns it
767 occupies on the screen. */ 773 occupies on the screen. */
774
768int 775int
769strwidth (str, len) 776strwidth (str, len)
770 unsigned char *str; 777 unsigned char *str;
@@ -772,29 +779,43 @@ strwidth (str, len)
772{ 779{
773 unsigned char *endp = str + len; 780 unsigned char *endp = str + len;
774 int width = 0; 781 int width = 0;
782 struct Lisp_Char_Table *dp = buffer_display_table (current_buffer);
775 783
776 while (str < endp) { 784 while (str < endp)
777 if (*str == LEADING_CODE_COMPOSITION) 785 {
778 { 786 if (*str == LEADING_CODE_COMPOSITION)
779 int id = str_cmpchar_id (str, endp - str); 787 {
788 int id = str_cmpchar_id (str, endp - str);
780 789
781 if (id < 0) 790 if (id < 0)
782 { 791 {
783 width += 4; 792 width += 4;
784 str++; 793 str++;
785 } 794 }
786 else 795 else
787 { 796 {
788 width += cmpchar_table[id]->width; 797 width += cmpchar_table[id]->width;
789 str += cmpchar_table[id]->len; 798 str += cmpchar_table[id]->len;
790 } 799 }
791 } 800 }
792 else 801 else
793 { 802 {
794 width += ONE_BYTE_CHAR_WIDTH (*str); 803 Lisp_Object disp;
795 str += BYTES_BY_CHAR_HEAD (*str); 804 int thiswidth;
796 } 805 int c = STRING_CHAR (str, endp - str);
797 } 806
807 /* Get the way the display table would display it. */
808 disp = DISP_CHAR_VECTOR (dp, c);
809
810 if (VECTORP (disp))
811 thiswidth = XVECTOR (disp)->size;
812 else
813 thiswidth = ONE_BYTE_CHAR_WIDTH (*str);
814
815 width += thiswidth;
816 str += BYTES_BY_CHAR_HEAD (*str);
817 }
818 }
798 return width; 819 return width;
799} 820}
800 821