Given a face using a proportional font, can an accurate pixel width of a single row of text be measured in Emacs?
Note: not monospaced text.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
The following function returns the size in pixels of text as if it were displayed in a given window.
window-text-pixel-size &optional window from to x-limit y-limit mode-and-header-line
This function returns the size of the text of window’s buffer in pixels.
windowmust 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 and the maximum pixel-height of all text lines.
The optional argument
from, if non-nil, specifies the first text position to consider and defaults to the minimum accessible position of the buffer. If
t, it uses the minimum accessible position that is not a newline character. The optional argument
to, if non-nil, specifies the last text position to consider and defaults to the maximum accessible position of the buffer. If
t, it uses the maximum accessible position that is not a newline character.
See the documentation for full details on the other parameters.
Please Note: window-text-pixel-size is a function introduced in emacs 24.4