diff options
| author | Po Lu | 2021-12-18 18:48:11 +0800 |
|---|---|---|
| committer | Po Lu | 2021-12-18 19:16:16 +0800 |
| commit | 43c4cc2ea29fa93de17d35e9cce4949eae171c45 (patch) | |
| tree | b66c52d80819c53bf8487c517224be2de757af6d /src | |
| parent | 3fea95b79f7a80fc84f0aee38e1f31234ed7c657 (diff) | |
| download | emacs-43c4cc2ea29fa93de17d35e9cce4949eae171c45.tar.gz emacs-43c4cc2ea29fa93de17d35e9cce4949eae171c45.zip | |
Add new argument `ignore-line-at-end' to `window-text-pixel-size'
* doc/lispref/display.texi (Size of Displayed Text): Update
documentation.
* etc/NEWS: Announce new argument.
* src/xdisp.c (window_text_pixel_size): Allow controlling if
the iterator's ascent and descent will be appended to the
pixel height returned. All callers changed.
(Fwindow_text_pixel_size): New argument `ignore-line-at-end'.
All callers changed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/haikufns.c | 3 | ||||
| -rw-r--r-- | src/w32fns.c | 3 | ||||
| -rw-r--r-- | src/xdisp.c | 42 | ||||
| -rw-r--r-- | src/xfns.c | 3 |
4 files changed, 38 insertions, 13 deletions
diff --git a/src/haikufns.c b/src/haikufns.c index 868fc71f979..737b0338994 100644 --- a/src/haikufns.c +++ b/src/haikufns.c | |||
| @@ -1970,7 +1970,8 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, | |||
| 1970 | try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE); | 1970 | try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE); |
| 1971 | /* Calculate size of tooltip window. */ | 1971 | /* Calculate size of tooltip window. */ |
| 1972 | size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil, | 1972 | size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil, |
| 1973 | make_fixnum (w->pixel_height), Qnil); | 1973 | make_fixnum (w->pixel_height), Qnil, |
| 1974 | Qnil); | ||
| 1974 | /* Add the frame's internal border to calculated size. */ | 1975 | /* Add the frame's internal border to calculated size. */ |
| 1975 | width = XFIXNUM (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); | 1976 | width = XFIXNUM (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); |
| 1976 | height = XFIXNUM (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); | 1977 | height = XFIXNUM (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); |
diff --git a/src/w32fns.c b/src/w32fns.c index 65463b52616..02a6d78b51c 100644 --- a/src/w32fns.c +++ b/src/w32fns.c | |||
| @@ -7525,7 +7525,8 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, | |||
| 7525 | try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE); | 7525 | try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE); |
| 7526 | /* Calculate size of tooltip window. */ | 7526 | /* Calculate size of tooltip window. */ |
| 7527 | size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil, | 7527 | size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil, |
| 7528 | make_fixnum (w->pixel_height), Qnil); | 7528 | make_fixnum (w->pixel_height), Qnil, |
| 7529 | Qnil); | ||
| 7529 | /* Add the frame's internal border to calculated size. */ | 7530 | /* Add the frame's internal border to calculated size. */ |
| 7530 | width = XFIXNUM (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); | 7531 | width = XFIXNUM (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); |
| 7531 | height = XFIXNUM (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); | 7532 | height = XFIXNUM (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); |
diff --git a/src/xdisp.c b/src/xdisp.c index e74411c8178..473c9f3f143 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -10833,7 +10833,7 @@ in_display_vector_p (struct it *it) | |||
| 10833 | argument. */ | 10833 | argument. */ |
| 10834 | static Lisp_Object | 10834 | static Lisp_Object |
| 10835 | window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Lisp_Object x_limit, | 10835 | window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Lisp_Object x_limit, |
| 10836 | Lisp_Object y_limit, Lisp_Object mode_lines) | 10836 | Lisp_Object y_limit, Lisp_Object mode_lines, Lisp_Object ignore_line_at_end) |
| 10837 | { | 10837 | { |
| 10838 | struct window *w = decode_live_window (window); | 10838 | struct window *w = decode_live_window (window); |
| 10839 | struct it it; | 10839 | struct it it; |
| @@ -10841,6 +10841,7 @@ window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Li | |||
| 10841 | struct text_pos startp; | 10841 | struct text_pos startp; |
| 10842 | void *itdata = NULL; | 10842 | void *itdata = NULL; |
| 10843 | int c, max_x = 0, max_y = 0, x = 0, y = 0; | 10843 | int c, max_x = 0, max_y = 0, x = 0, y = 0; |
| 10844 | int doff = 0; | ||
| 10844 | 10845 | ||
| 10845 | if (NILP (from)) | 10846 | if (NILP (from)) |
| 10846 | { | 10847 | { |
| @@ -10969,8 +10970,18 @@ window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Li | |||
| 10969 | if (IT_CHARPOS (it) == end) | 10970 | if (IT_CHARPOS (it) == end) |
| 10970 | { | 10971 | { |
| 10971 | x += it.pixel_width; | 10972 | x += it.pixel_width; |
| 10972 | it.max_ascent = max (it.max_ascent, it.ascent); | 10973 | |
| 10973 | it.max_descent = max (it.max_descent, it.descent); | 10974 | /* DTRT if ignore_line_at_end is t. */ |
| 10975 | if (!NILP (ignore_line_at_end)) | ||
| 10976 | { | ||
| 10977 | doff = (max (it.max_ascent, it.ascent) | ||
| 10978 | + max (it.max_descent, it.descent)); | ||
| 10979 | } | ||
| 10980 | else | ||
| 10981 | { | ||
| 10982 | it.max_ascent = max (it.max_ascent, it.ascent); | ||
| 10983 | it.max_descent = max (it.max_descent, it.descent); | ||
| 10984 | } | ||
| 10974 | } | 10985 | } |
| 10975 | } | 10986 | } |
| 10976 | else | 10987 | else |
| @@ -10991,8 +11002,14 @@ window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Li | |||
| 10991 | 11002 | ||
| 10992 | /* Subtract height of header-line and tab-line which was counted | 11003 | /* Subtract height of header-line and tab-line which was counted |
| 10993 | automatically by start_display. */ | 11004 | automatically by start_display. */ |
| 10994 | y = it.current_y + it.max_ascent + it.max_descent | 11005 | if (!NILP (ignore_line_at_end)) |
| 10995 | - WINDOW_TAB_LINE_HEIGHT (w) - WINDOW_HEADER_LINE_HEIGHT (w); | 11006 | y = (it.current_y + doff |
| 11007 | - WINDOW_TAB_LINE_HEIGHT (w) | ||
| 11008 | - WINDOW_HEADER_LINE_HEIGHT (w)); | ||
| 11009 | else | ||
| 11010 | y = (it.current_y + it.max_ascent + it.max_descent + doff | ||
| 11011 | - WINDOW_TAB_LINE_HEIGHT (w) - WINDOW_HEADER_LINE_HEIGHT (w)); | ||
| 11012 | |||
| 10996 | /* Don't return more than Y-LIMIT. */ | 11013 | /* Don't return more than Y-LIMIT. */ |
| 10997 | if (y > max_y) | 11014 | if (y > max_y) |
| 10998 | y = max_y; | 11015 | y = max_y; |
| @@ -11039,7 +11056,7 @@ window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Li | |||
| 11039 | return Fcons (make_fixnum (x - start_x), make_fixnum (y)); | 11056 | return Fcons (make_fixnum (x - start_x), make_fixnum (y)); |
| 11040 | } | 11057 | } |
| 11041 | 11058 | ||
| 11042 | DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size, Swindow_text_pixel_size, 0, 6, 0, | 11059 | DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size, Swindow_text_pixel_size, 0, 7, 0, |
| 11043 | doc: /* Return the size of the text of WINDOW's buffer in pixels. | 11060 | doc: /* Return the size of the text of WINDOW's buffer in pixels. |
| 11044 | WINDOW must be a live window and defaults to the selected one. The | 11061 | WINDOW must be a live window and defaults to the selected one. The |
| 11045 | return value is a cons of the maximum pixel-width of any text line | 11062 | return value is a cons of the maximum pixel-width of any text line |
| @@ -11086,9 +11103,12 @@ Optional argument MODE-LINES nil or omitted means do not include the | |||
| 11086 | height of the mode-, tab- or header-line of WINDOW in the return value. | 11103 | height of the mode-, tab- or header-line of WINDOW in the return value. |
| 11087 | If it is the symbol `mode-line', 'tab-line' or `header-line', include | 11104 | If it is the symbol `mode-line', 'tab-line' or `header-line', include |
| 11088 | only the height of that line, if present, in the return value. If t, | 11105 | only the height of that line, if present, in the return value. If t, |
| 11089 | include the height of any of these, if present, in the return value. */) | 11106 | include the height of any of these, if present, in the return value. |
| 11107 | |||
| 11108 | IGNORE-LINE-AT-END means to not add the height of the screen line at | ||
| 11109 | TO to the returned height. */) | ||
| 11090 | (Lisp_Object window, Lisp_Object from, Lisp_Object to, Lisp_Object x_limit, | 11110 | (Lisp_Object window, Lisp_Object from, Lisp_Object to, Lisp_Object x_limit, |
| 11091 | Lisp_Object y_limit, Lisp_Object mode_lines) | 11111 | Lisp_Object y_limit, Lisp_Object mode_lines, Lisp_Object ignore_line_at_end) |
| 11092 | { | 11112 | { |
| 11093 | struct window *w = decode_live_window (window); | 11113 | struct window *w = decode_live_window (window); |
| 11094 | struct buffer *b = XBUFFER (w->contents); | 11114 | struct buffer *b = XBUFFER (w->contents); |
| @@ -11101,7 +11121,8 @@ include the height of any of these, if present, in the return value. */) | |||
| 11101 | set_buffer_internal_1 (b); | 11121 | set_buffer_internal_1 (b); |
| 11102 | } | 11122 | } |
| 11103 | 11123 | ||
| 11104 | value = window_text_pixel_size (window, from, to, x_limit, y_limit, mode_lines); | 11124 | value = window_text_pixel_size (window, from, to, x_limit, y_limit, mode_lines, |
| 11125 | ignore_line_at_end); | ||
| 11105 | 11126 | ||
| 11106 | if (old_b) | 11127 | if (old_b) |
| 11107 | set_buffer_internal_1 (old_b); | 11128 | set_buffer_internal_1 (old_b); |
| @@ -11151,7 +11172,8 @@ WINDOW. */) | |||
| 11151 | set_marker_both (w->old_pointm, buffer, BEG, BEG_BYTE); | 11172 | set_marker_both (w->old_pointm, buffer, BEG, BEG_BYTE); |
| 11152 | } | 11173 | } |
| 11153 | 11174 | ||
| 11154 | value = window_text_pixel_size (window, Qnil, Qnil, x_limit, y_limit, Qnil); | 11175 | value = window_text_pixel_size (window, Qnil, Qnil, x_limit, y_limit, Qnil, |
| 11176 | Qnil); | ||
| 11155 | 11177 | ||
| 11156 | unbind_to (count, Qnil); | 11178 | unbind_to (count, Qnil); |
| 11157 | 11179 | ||
diff --git a/src/xfns.c b/src/xfns.c index dc25d7bfca2..30ed358fb28 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -7169,7 +7169,8 @@ Text larger than the specified size is clipped. */) | |||
| 7169 | try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE); | 7169 | try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE); |
| 7170 | /* Calculate size of tooltip window. */ | 7170 | /* Calculate size of tooltip window. */ |
| 7171 | size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil, | 7171 | size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil, |
| 7172 | make_fixnum (w->pixel_height), Qnil); | 7172 | make_fixnum (w->pixel_height), Qnil, |
| 7173 | Qnil); | ||
| 7173 | /* Add the frame's internal border to calculated size. */ | 7174 | /* Add the frame's internal border to calculated size. */ |
| 7174 | width = XFIXNUM (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); | 7175 | width = XFIXNUM (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); |
| 7175 | height = XFIXNUM (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); | 7176 | height = XFIXNUM (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f); |