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

From: Eli Zaretskii <[email-masked]>
Date: Wed, 06 Aug 2014 19:30:09 +0300

> Date: Wed, 06 Aug 2014 18:15:00 +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 probably did no understand it.  I do not want to select any font.  The
> application has to know which font the overlay should appear in.

If the popped up text overlays existing buffer display, it should
ideally use the same fonts as the overlaid text uses.  But if that
overlaid text uses several different fonts, shadowing that in the
overlay is all but trivial.

> If its the font of the buffer where the overlay finally appears, it
> should take this.  If it wants to use any other font, it should take
> that.

I'm talking about "fonts", plural.  When the buffer text uses several
different fonts, selection of font for the overlay is complicated at
best.

>  >> 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.
> 
> But as I explained in my mail to Dmitry this is the problem of the
> application.  Whatever it wants to do in the target window it has to
> emulate in the temporary buffer: Put the original text there, apply any
> font or property settings from the original buffer to that buffer, put
> any overlays there, apply any font or property settings for the overlays
> there, and have move_it_to get the overall height.  What am I missing?

You are talking about things that are possible only on the C level,
not from Lisp.  My point was that we don't expose enough APIs to Lisp
to allow such applications, and you now agreed with me.