Function: window-lines-pixel-dimensions

window-lines-pixel-dimensions is a function defined in window.c.

Signature

(window-lines-pixel-dimensions &optional WINDOW FIRST LAST BODY INVERSE LEFT)

Documentation

Return pixel dimensions of WINDOW's lines.

The return value is a list of the x- and y-coordinates of the lower right corner of the last character of each line. Return nil if the current glyph matrix of WINDOW is not up-to-date.

Optional argument WINDOW specifies the window whose lines' dimensions shall be returned. Nil or omitted means to return the dimensions for the selected window.

FIRST, if non-nil, specifies the index of the first line whose dimensions shall be returned. If FIRST is nil and BODY is non-nil, start with the first text line of WINDOW. Otherwise, start with the first line of WINDOW.

LAST, if non-nil, specifies the last line whose dimensions shall be returned. If LAST is nil and BODY is non-nil, the last line is the last line of the body (text area) of WINDOW. Otherwise, last is the last line of WINDOW.

INVERSE, if nil, means that the y-pixel value returned for a specific line specifies the distance in pixels from the left edge (body edge if BODY is non-nil) of WINDOW to the right edge of the last glyph of that line. INVERSE non-nil means that the y-pixel value returned for a specific line specifies the distance in pixels from the right edge of the last glyph of that line to the right edge (body edge if BODY is non-nil) of WINDOW.

LEFT non-nil means to return the x- and y-coordinates of the lower left corner of the leftmost character on each line. This is the value that should be used for buffers that mostly display text from right to left.

If LEFT is non-nil and INVERSE is nil, this means that the y-pixel value returned for a specific line specifies the distance in pixels from the left edge of the last (leftmost) glyph of that line to the right edge
(body edge if BODY is non-nil) of WINDOW. If LEFT and INVERSE are both
non-nil, the y-pixel value returned for a specific line specifies the distance in pixels from the left edge (body edge if BODY is non-nil) of WINDOW to the left edge of the last (leftmost) glyph of that line.

Normally, the value of this function is not available while Emacs is busy, for example, when processing a command. It should be retrievable though when run from an idle timer with a delay of zero seconds.

Probably introduced at or before Emacs version 26.1.

Source Code

// Defined in /usr/src/emacs/src/window.c
{
  struct window *w = decode_live_window (window);
  struct buffer *b;
  struct glyph_row *row, *end_row;
  int max_y = NILP (body) ? WINDOW_PIXEL_HEIGHT (w) : window_text_bottom_y (w);
  Lisp_Object rows = Qnil;
  int window_width = NILP (body) ? w->pixel_width : window_body_width (w, true);
  int tab_line_height = WINDOW_TAB_LINE_HEIGHT (w);
  int header_line_height = WINDOW_HEADER_LINE_HEIGHT (w);
  int subtract = NILP (body) ? 0 : (tab_line_height + header_line_height);
  bool invert = !NILP (inverse);
  bool left_flag = !NILP (left);

  if (noninteractive || w->pseudo_window_p)
    return Qnil;

  CHECK_BUFFER (w->contents);
  b = XBUFFER (w->contents);

  /* Fail if current matrix is not up-to-date.  */
  if (!w->window_end_valid
      || windows_or_buffers_changed
      || b->clip_changed
      || b->prevent_redisplay_optimizations_p
      || window_outdated (w))
    return Qnil;

  row = (!NILP (first)
	 ? MATRIX_ROW (w->current_matrix,
		       check_integer_range (first, 0,
					    w->current_matrix->nrows))
	 : NILP (body)
	 ? MATRIX_ROW (w->current_matrix, 0)
	 : MATRIX_FIRST_TEXT_ROW (w->current_matrix));
  end_row = (!NILP (last)
	     ? MATRIX_ROW (w->current_matrix,
			   check_integer_range (last, 0,
						w->current_matrix->nrows))
	     : NILP (body)
	     ? MATRIX_ROW (w->current_matrix, w->current_matrix->nrows)
	     : MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w));

  while (row <= end_row && row->enabled_p
	 && row->y + row->height < max_y)
    {

      if (left_flag)
	{
	  struct glyph *glyph = row->glyphs[TEXT_AREA];

	  rows = Fcons (Fcons (make_fixnum
			       (invert
				? glyph->pixel_width
				: window_width - glyph->pixel_width),
			       make_fixnum (row->y + row->height - subtract)),
			rows);
	}
      else
	rows = Fcons (Fcons (make_fixnum
			     (invert
			      ? window_width - row->pixel_width
			      : row->pixel_width),
			     make_fixnum (row->y + row->height - subtract)),
		      rows);
      row++;
    }

  return Fnreverse (rows);
}