to compute the width of @var{string} (in pixels).
@end defun
+@defun window-char-pixel-width &optional window face
+Return the average character width for the font used by @var{face} in
+@var{window}. If @var{face} is @code{nil} or omitted, the
+@code{default} face is used. If @var{windows} is @code{nil} or
+omitted, the currently selected window is used.
+@end defun
+
+@defun window-char-pixel-height &optional window face
+Return the average character height for the font used by @var{face} in
+@var{window}. If @var{face} is @code{nil} or omitted, the
+@code{default} face is used. If @var{windows} is @code{nil} or
+omitted, the currently selected window is used.
+@end defun
+
@defun line-pixel-height
This function returns the height in pixels of the line at point in the
selected window. The value includes the line spacing of the line
argument @var{round} behaves as it does for @code{window-total-height}.
@end defun
+@defun window-max-characters-per-line &optional window face
+The maximum width of a line that can be displayed in a window (without
+breaking the line) depends on many things, like the font used on the
+line, and whether there are fringes around the window. This
+convenience function can be used to calculate that number. If
+@var{window} isn't given, this defaults to the currently selected
+window. if @var{var} isn't given, the @code{default} face is used.
+@end defun
+
@defun window-total-size &optional window horizontal round
This function returns either the total height in lines or the total
width in columns of the window @var{window}. If @var{horizontal} is
(put 'shrink-window-horizontally 'repeat-map 'resize-window-repeat-map)
(put 'shrink-window 'repeat-map 'resize-window-repeat-map)
+(defun window-char-pixel-width (&optional window face)
+ "Return average character width for the font of FACE used in WINDOW.
+WINDOW must be a live window and defaults to the selected one.
+
+If FACE is nil or omitted, the default face is used. If FACE is
+remapped (see `face-remapping-alist'), the function returns the
+information for the remapped face."
+ (with-selected-window (window-normalize-window window t)
+ (let* ((face (if face face 'default))
+ (info (font-info (face-font face)))
+ (width (aref info 11)))
+ (if (> width 0)
+ width
+ (aref info 10)))))
+
+(defun window-char-pixel-height (&optional window face)
+ "Return character height for the font of FACE used in WINDOW.
+WINDOW must be a live window and defaults to the selected one.
+
+If FACE is nil or omitted, the default face is used. If FACE is
+remapped (see `face-remapping-alist'), the function returns the
+information for the remapped face."
+ (with-selected-window (window-normalize-window window t)
+ (let* ((face (if face face 'default))
+ (info (font-info (face-font face))))
+ (aref info 3))))
+
+(defun window-max-characters-per-line (&optional window face)
+ "Return the number of characters that can be displayed on one line in WINDOW.
+WINDOW must be a live window and defaults to the selected one.
+
+The character width of FACE is used for the calculation. If FACE
+is nil or omitted, the default face is used. If FACE is
+remapped (see `face-remapping-alist'), the function uses the
+remapped face.
+
+This function is different from `window-body-width' in two
+ways. First, it accounts for the portions of the line reserved
+for the continuation glyph. Second, it accounts for the size of
+the font, which may have been adjusted, e.g., using
+`text-scale-increase')."
+ (with-selected-window (window-normalize-window window t)
+ (let* ((window-width (window-body-width window t))
+ (font-width (window-char-pixel-width window face))
+ (ncols (/ window-width font-width)))
+ (if (and (display-graphic-p)
+ overflow-newline-into-fringe
+ (/= (frame-parameter nil 'left-fringe) 0)
+ (/= (frame-parameter nil 'right-fringe) 0))
+ ncols
+ (1- ncols)))))
+
(provide 'window)
;;; window.el ends here