Subject: Re: bug#18195: 24.3.92; window-screen-lines is not accurate

From: Eli Zaretskii <[email-masked]>
Date: Wed, 06 Aug 2014 17:39:18 +0300

> Date: Wed, 06 Aug 2014 11:41:26 +0200
> From: martin rudalics <[email-masked]>
> CC: [email-masked], [email-masked]
> 
> >> This would have to be done on the Lisp level by selecting some font
> >> before calculating the size of the overlay.
> >
> > Which font would you select?

You didn't answer this question.  The only trivial answer is the font
of the default face, a choice which has the problems described below.

> > I'm talking about a situation where the text over which the
> > candidate list will be popped uses several different fonts, and so
> > each line of the buffer text has a different height.
> 
> I would pop up that list in a temporary buffer and run
> `window-text-pixel-size' over it.

And therein lies the problem.  You will get the size of the text under
the assumption that the text will be displayed using a single font,
the one used by the frame's 'default' face.  But if the text in the
region over which you will pop the candidate list uses a different
font, or shows images on some of the lines, the pixel height needed to
display the popped list will be different.  That's because the
candidates are displayed by Company by putting overlays on consecutive
lines of text, each overlay showing one candidate.  However,
displaying such overlays in the middle of a line of buffer text cannot
decrease the height of the line, it can only increase it.  Therefore,
if the line of buffer text was taller than what is required for the
default face's font, the displayed overlay string will take up more
pixels than what you measured in the temporary buffer.