Mercurial > emacs
comparison src/font.c @ 91236:e3ba579aab1f
(font_at): Handle the case that the arg C is negative.
Handle the unibyte case.
(Ffont_at): Call font_at with the arg C -1.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 14 Dec 2007 11:16:47 +0000 |
parents | bcad98389aeb |
children | b2febf77e71c |
comparison
equal
deleted
inserted
replaced
91235:4f6b5b90d755 | 91236:e3ba579aab1f |
---|---|
2852 return list->data; | 2852 return list->data; |
2853 } | 2853 } |
2854 | 2854 |
2855 | 2855 |
2856 /* Return the font used to draw character C by FACE at buffer position | 2856 /* Return the font used to draw character C by FACE at buffer position |
2857 POS in window W. If OBJECT is non-nil, it is a string containing C | 2857 POS in window W. If STRING is non-nil, it is a string containing C |
2858 at index POS. */ | 2858 at index POS. If C is negative, get C from the current buffer or |
2859 STRING. */ | |
2859 | 2860 |
2860 Lisp_Object | 2861 Lisp_Object |
2861 font_at (c, pos, face, w, object) | 2862 font_at (c, pos, face, w, string) |
2862 int c; | 2863 int c; |
2863 EMACS_INT pos; | 2864 EMACS_INT pos; |
2864 struct face *face; | 2865 struct face *face; |
2865 struct window *w; | 2866 struct window *w; |
2866 Lisp_Object object; | 2867 Lisp_Object string; |
2867 { | 2868 { |
2868 FRAME_PTR f; | 2869 FRAME_PTR f; |
2869 int face_id; | 2870 int multibyte; |
2870 int dummy; | 2871 |
2872 if (c < 0) | |
2873 { | |
2874 if (NILP (string)) | |
2875 { | |
2876 multibyte = ! NILP (current_buffer->enable_multibyte_characters); | |
2877 if (multibyte) | |
2878 { | |
2879 EMACS_INT pos_byte = CHAR_TO_BYTE (pos); | |
2880 | |
2881 c = FETCH_CHAR (pos_byte); | |
2882 } | |
2883 else | |
2884 c = FETCH_BYTE (pos); | |
2885 } | |
2886 else | |
2887 { | |
2888 unsigned char *str; | |
2889 | |
2890 multibyte = STRING_MULTIBYTE (string); | |
2891 if (multibyte) | |
2892 { | |
2893 EMACS_INT pos_byte = string_char_to_byte (string, pos); | |
2894 | |
2895 str = SDATA (string) + pos_byte; | |
2896 c = STRING_CHAR (str, 0); | |
2897 } | |
2898 else | |
2899 c = SDATA (string)[pos]; | |
2900 } | |
2901 } | |
2871 | 2902 |
2872 f = XFRAME (w->frame); | 2903 f = XFRAME (w->frame); |
2873 if (! FRAME_WINDOW_P (f)) | 2904 if (! FRAME_WINDOW_P (f)) |
2874 return Qnil; | 2905 return Qnil; |
2875 if (! face) | 2906 if (! face) |
2876 { | 2907 { |
2877 if (STRINGP (object)) | 2908 int face_id; |
2878 face_id = face_at_string_position (w, object, pos, 0, -1, -1, &dummy, | 2909 int endptr; |
2910 | |
2911 if (STRINGP (string)) | |
2912 face_id = face_at_string_position (w, string, pos, 0, -1, -1, &endptr, | |
2879 DEFAULT_FACE_ID, 0); | 2913 DEFAULT_FACE_ID, 0); |
2880 else | 2914 else |
2881 face_id = face_at_buffer_position (w, pos, -1, -1, &dummy, | 2915 face_id = face_at_buffer_position (w, pos, -1, -1, &endptr, |
2882 pos + 100, 0); | 2916 pos + 100, 0); |
2883 face = FACE_FROM_ID (f, face_id); | 2917 face = FACE_FROM_ID (f, face_id); |
2884 } | 2918 } |
2885 face_id = FACE_FOR_CHAR (f, face, c, pos, object); | 2919 if (multibyte) |
2886 face = FACE_FROM_ID (f, face_id); | 2920 { |
2921 int face_id = FACE_FOR_CHAR (f, face, c, pos, string); | |
2922 face = FACE_FROM_ID (f, face_id); | |
2923 } | |
2887 if (! face->font_info) | 2924 if (! face->font_info) |
2888 return Qnil; | 2925 return Qnil; |
2889 return font_find_object ((struct font *) face->font_info); | 2926 return font_find_object ((struct font *) face->font_info); |
2890 } | 2927 } |
2891 | 2928 |
3757 the current buffer. It defaults to the currently selected window. */) | 3794 the current buffer. It defaults to the currently selected window. */) |
3758 (position, window, string) | 3795 (position, window, string) |
3759 Lisp_Object position, window, string; | 3796 Lisp_Object position, window, string; |
3760 { | 3797 { |
3761 struct window *w; | 3798 struct window *w; |
3762 EMACS_INT pos, pos_byte; | 3799 EMACS_INT pos; |
3763 int c; | |
3764 | 3800 |
3765 if (NILP (string)) | 3801 if (NILP (string)) |
3766 { | 3802 { |
3767 CHECK_NUMBER_COERCE_MARKER (position); | 3803 CHECK_NUMBER_COERCE_MARKER (position); |
3768 pos = XINT (position); | 3804 pos = XINT (position); |
3769 if (pos < BEGV || pos >= ZV) | 3805 if (pos < BEGV || pos >= ZV) |
3770 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV)); | 3806 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV)); |
3771 pos_byte = CHAR_TO_BYTE (pos); | |
3772 c = FETCH_CHAR (pos_byte); | |
3773 } | 3807 } |
3774 else | 3808 else |
3775 { | 3809 { |
3776 EMACS_INT len; | 3810 EMACS_INT len; |
3777 unsigned char *str; | 3811 unsigned char *str; |
3779 CHECK_NUMBER (position); | 3813 CHECK_NUMBER (position); |
3780 CHECK_STRING (string); | 3814 CHECK_STRING (string); |
3781 pos = XINT (position); | 3815 pos = XINT (position); |
3782 if (pos < 0 || pos >= SCHARS (string)) | 3816 if (pos < 0 || pos >= SCHARS (string)) |
3783 args_out_of_range (string, position); | 3817 args_out_of_range (string, position); |
3784 pos_byte = string_char_to_byte (string, pos); | |
3785 str = SDATA (string) + pos_byte; | |
3786 len = SBYTES (string) - pos_byte; | |
3787 c = STRING_CHAR (str, eln); | |
3788 } | 3818 } |
3789 if (NILP (window)) | 3819 if (NILP (window)) |
3790 window = selected_window; | 3820 window = selected_window; |
3791 CHECK_LIVE_WINDOW (window); | 3821 CHECK_LIVE_WINDOW (window); |
3792 w = XWINDOW (selected_window); | 3822 w = XWINDOW (selected_window); |
3793 | 3823 |
3794 return font_at (c, pos, NULL, w, Qnil); | 3824 return font_at (-1, pos, NULL, w, Qnil); |
3795 } | 3825 } |
3796 | 3826 |
3797 #if 0 | 3827 #if 0 |
3798 DEFUN ("draw-string", Fdraw_string, Sdraw_string, 2, 2, 0, | 3828 DEFUN ("draw-string", Fdraw_string, Sdraw_string, 2, 2, 0, |
3799 doc: /* Draw STRING by FONT-OBJECT on the top left corner of the current frame. | 3829 doc: /* Draw STRING by FONT-OBJECT on the top left corner of the current frame. |