]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new argument `ignore-line-at-end' to `window-text-pixel-size'
authorPo Lu <luangruo@yahoo.com>
Sat, 18 Dec 2021 10:48:11 +0000 (18:48 +0800)
committerPo Lu <luangruo@yahoo.com>
Sat, 18 Dec 2021 11:16:16 +0000 (19:16 +0800)
* 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.

doc/lispref/display.texi
etc/NEWS
src/haikufns.c
src/w32fns.c
src/xdisp.c
src/xfns.c

index b82473f9c206093e405932ee67e4cb23f2dc59f2..92bfd2fea196fb883e2acba41a743d30fd1c3d85 100644 (file)
@@ -2086,7 +2086,7 @@ displayed in a given window.  This function is used by
 (@pxref{Resizing Windows}) to make a window exactly as large as the text
 it contains.
 
-@defun window-text-pixel-size &optional window from to x-limit y-limit mode-lines
+@defun window-text-pixel-size &optional window from to x-limit y-limit mode-lines ignore-line-at-end
 This function returns the size of the text of @var{window}'s buffer in
 pixels.  @var{window} must be a live window and defaults to the
 selected one.  The return value is a cons of the maximum pixel-width
@@ -2136,6 +2136,10 @@ line, if present, in the return value.  If it is @code{t}, include the
 height of all of these lines, if present, in the return value.
 @end defun
 
+The optional argument @var{ignore-line-at-end} controls whether or
+not to count the height of text in @var{to}'s screen line as part of
+the returned pixel-height.
+
 @code{window-text-pixel-size} treats the text displayed in a window as a
 whole and does not care about the size of individual lines.  The
 following function does.
index bd1ed4da00c3ca0ad7946f5129bb48bf9eec4d58..20056b30c58289e3b7f60bf677c7d3ab22a39c5a 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -984,6 +984,11 @@ when they have changed.
 This can be used to check whether a specific font has a glyph for a
 character.
 
++++
+** 'window-text-pixel-size' now accepts a new argument `ignore-line-at-end'.
+This controls whether or not the screen line at the end of the
+measured area will be counted during the height calculation.
+
 ** XDG support
 
 *** New function 'xdg-state-home' returns 'XDG_STATE_HOME' environment variable.
index 868fc71f9795bf7cc39981e8d8bcc09e6e29fb33..737b0338994fe6022c89d440c15412fd0feab7c4 100644 (file)
@@ -1970,7 +1970,8 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
   try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
   /* Calculate size of tooltip window.  */
   size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil,
-                                 make_fixnum (w->pixel_height), Qnil);
+                                 make_fixnum (w->pixel_height), Qnil,
+                                 Qnil);
   /* Add the frame's internal border to calculated size.  */
   width = XFIXNUM (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
   height = XFIXNUM (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
index 65463b526165aff3571a02aa33cdb9bb6c3ec82e..02a6d78b51cd17e4ee8f0f481bf3c8294a32dfa6 100644 (file)
@@ -7525,7 +7525,8 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
   try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
   /* Calculate size of tooltip window.  */
   size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil,
-                                 make_fixnum (w->pixel_height), Qnil);
+                                 make_fixnum (w->pixel_height), Qnil,
+                                 Qnil);
   /* Add the frame's internal border to calculated size.  */
   width = XFIXNUM (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
   height = XFIXNUM (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
index e74411c8178466832db5770f0d096f727806a81a..473c9f3f1436715052d50e6fb5860fb83287d747 100644 (file)
@@ -10833,7 +10833,7 @@ in_display_vector_p (struct it *it)
    argument.  */
 static Lisp_Object
 window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Lisp_Object x_limit,
-                       Lisp_Object y_limit, Lisp_Object mode_lines)
+                       Lisp_Object y_limit, Lisp_Object mode_lines, Lisp_Object ignore_line_at_end)
 {
   struct window *w = decode_live_window (window);
   struct it it;
@@ -10841,6 +10841,7 @@ window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Li
   struct text_pos startp;
   void *itdata = NULL;
   int c, max_x = 0, max_y = 0, x = 0, y = 0;
+  int doff = 0;
 
   if (NILP (from))
     {
@@ -10969,8 +10970,18 @@ window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Li
       if (IT_CHARPOS (it) == end)
        {
          x += it.pixel_width;
-         it.max_ascent = max (it.max_ascent, it.ascent);
-         it.max_descent = max (it.max_descent, it.descent);
+
+         /* DTRT if ignore_line_at_end is t.  */
+         if (!NILP (ignore_line_at_end))
+           {
+             doff = (max (it.max_ascent, it.ascent)
+                     + max (it.max_descent, it.descent));
+           }
+         else
+           {
+             it.max_ascent = max (it.max_ascent, it.ascent);
+             it.max_descent = max (it.max_descent, it.descent);
+           }
        }
     }
   else
@@ -10991,8 +11002,14 @@ window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Li
 
   /* Subtract height of header-line and tab-line which was counted
      automatically by start_display.  */
-  y = it.current_y + it.max_ascent + it.max_descent
-    - WINDOW_TAB_LINE_HEIGHT (w) - WINDOW_HEADER_LINE_HEIGHT (w);
+  if (!NILP (ignore_line_at_end))
+    y = (it.current_y + doff
+        - WINDOW_TAB_LINE_HEIGHT (w)
+        - WINDOW_HEADER_LINE_HEIGHT (w));
+  else
+    y = (it.current_y + it.max_ascent + it.max_descent + doff
+        - WINDOW_TAB_LINE_HEIGHT (w) - WINDOW_HEADER_LINE_HEIGHT (w));
+
   /* Don't return more than Y-LIMIT.  */
   if (y > max_y)
     y = max_y;
@@ -11039,7 +11056,7 @@ window_text_pixel_size (Lisp_Object window, Lisp_Object from, Lisp_Object to, Li
   return Fcons (make_fixnum (x - start_x), make_fixnum (y));
 }
 
-DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size, Swindow_text_pixel_size, 0, 6, 0,
+DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size, Swindow_text_pixel_size, 0, 7, 0,
        doc: /* Return the size of the text of WINDOW's buffer in pixels.
 WINDOW must be a live window and defaults to the selected one.  The
 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
 height of the mode-, tab- or header-line of WINDOW in the return value.
 If it is the symbol `mode-line', 'tab-line' or `header-line', include
 only the height of that line, if present, in the return value.  If t,
-include the height of any of these, if present, in the return value.  */)
+include the height of any of these, if present, in the return value.
+
+IGNORE-LINE-AT-END means to not add the height of the screen line at
+TO to the returned height.  */)
   (Lisp_Object window, Lisp_Object from, Lisp_Object to, Lisp_Object x_limit,
-   Lisp_Object y_limit, Lisp_Object mode_lines)
+   Lisp_Object y_limit, Lisp_Object mode_lines, Lisp_Object ignore_line_at_end)
 {
   struct window *w = decode_live_window (window);
   struct buffer *b = XBUFFER (w->contents);
@@ -11101,7 +11121,8 @@ include the height of any of these, if present, in the return value.  */)
       set_buffer_internal_1 (b);
     }
 
-  value = window_text_pixel_size (window, from, to, x_limit, y_limit, mode_lines);
+  value = window_text_pixel_size (window, from, to, x_limit, y_limit, mode_lines,
+                                 ignore_line_at_end);
 
   if (old_b)
     set_buffer_internal_1 (old_b);
@@ -11151,7 +11172,8 @@ WINDOW.  */)
       set_marker_both (w->old_pointm, buffer, BEG, BEG_BYTE);
     }
 
-  value = window_text_pixel_size (window, Qnil, Qnil, x_limit, y_limit, Qnil);
+  value = window_text_pixel_size (window, Qnil, Qnil, x_limit, y_limit, Qnil,
+                                 Qnil);
 
   unbind_to (count, Qnil);
 
index dc25d7bfca29f3c7cc056ab169bf41626b62cfdf..30ed358fb2865b6c0d4c5f35fef0b62d6974befc 100644 (file)
@@ -7169,7 +7169,8 @@ Text larger than the specified size is clipped.  */)
   try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
   /* Calculate size of tooltip window.  */
   size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil,
-                                 make_fixnum (w->pixel_height), Qnil);
+                                 make_fixnum (w->pixel_height), Qnil,
+                                 Qnil);
   /* Add the frame's internal border to calculated size.  */
   width = XFIXNUM (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
   height = XFIXNUM (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);