Subject: Re: bug#72771: 31.0.50; shr html renderer throwing "Specified window is not displaying the current buffer"

From: Eli Zaretskii <[email-masked]>
Date: Sat, 24 Aug 2024 09:08:32 +0300

> Date: Fri, 23 Aug 2024 15:39:00 -0700
> Cc: Rob Stewart <[email-masked]>, [email-masked]
> From: Jim Porter <[email-masked]>
> 
> Here's a patch. I've tested this in a few configurations (in the current 
> window, in a buffer that's not being displayed, in a terminal Emacs) and 
> it all seems to work.
> 
> One question, Eli: is there a better way than I'm using to get the font 
> that would be used for a character in the buffer? When the buffer is 
> being displayed in a window, '(font-at position window)' works, but that 
> doesn't address this bug, where the buffer isn't displayed. (The font 
> that we get back doesn't have to be 100% accurate; just a good guess 
> should be fine for this case.)

AFAIU, the code needs the width of the space character of a font used
to show some text, is that correct?

And the patch solves the problem of font-at by pretending that the
relevant text is displayed in the current window, is that correct?

Alternatives to the solution in the patch are:

 . temporarily display the buffer in some window (if there is already
   a window showing the buffer, use with-selected-window)
 . use buffer-text-pixel-size or string-pixel-width to measure the
   width of a string of a single SPC character
 . use the font obtained from (face-font 'default) (or the actual face
   of the text, if you can get at it easily), like this:

      (aref (font-info (face-font 'default)) 10)