Subject: bug#67533: SVG images confound position pixel measurements

From: JD Smith <[email-masked]>
Date: Sat, 2 Dec 2023 08:36:07 -0500

> On Dec 2, 2023, at 2:30 AM, Eli Zaretskii <[email-masked]> wrote:
> 
>> From: JD Smith <[email-masked]>
>> Date: Fri, 1 Dec 2023 17:04:59 -0500
>> 
>> On Dec 1, 2023, at 2:08 AM, Eli Zaretskii <[email-masked]> wrote:
>> 
>> Thanks, but I need recipes I could reproduce on my system, and
>> reproduce relatively easily.  
>> 
>> Please find a stand-alone reproduction code which can separately test both text-property and overlay
>> inline SVGs at this gist.  See the header for instructions.  
> 
> Thanks, but I'd appreciate more focused pointers to specific problems,
> see below.  I also seem to be unable to reproduce the problems(?).

Strange.  Both of my ports here (NS and Mac) show the same issue.  Did you check the svg-pixel-demo-report buffer the header mentions, where the mismatch measurement information gets reported?  The specific problems encountered are listed in the report buffer, updated with my/check-buffer-pixel-values.  For example, at a standard width of 80 characters, I get this report:

SVG Position analysis for svg-pixel-demo (width 80, text-properties)

Incorrect at point= 34: line  2 at   (224 . 14) (image): expected 14 got 28
Incorrect at point= 99: line  3 at   (244 . 43) (image): expected 29 got 46
Incorrect at point=126: line  4 at    (42 . 75) (image): expected 32 got 46
Incorrect at point=162: line  4 at   (345 . 75) (image): expected 32 got 52
Incorrect at point=210: line  5 at  (133 . 110) (image): expected 35 got 49

So in this case, 5 of the image locations (of 7) are showing sizes of entities one pixel above them as too large (with sizes sometimes not matching any line height).  At small window widths (like 25-30 characters) many zero heights start showing up.   Running the check in a normal text window produces an empty report (no errors). 

> When I run "M-x my/check-buffer-pixel-values" in the buffer created by
> "M-x my/test-svg-positions", all I see is a single message "End of
> buffer", nothing else.  

Perhaps you did not check the report buffer? I usually am opening that in another frame. 

> Also, your test file doesn't use lexical-binding -- should it?  Or
> does it not matter for the purposes of reproducing these issues?

I neglected that.  I don’t think it makes a difference, but have now included it, and fixed a couple of resulting unused variable complaints.  Please re-download the gist <https://gist.github.com/jdtsmith/ad765047a6afe20f353de573d8c07da9> and try it again to be sure.

>> The one bug in my original org file I haven’t been able to reproduce is random text characters (usually
>> on a line with a bad image) misreporting pixel measurements.
> 
> Misreporting pixel measurements of what?

Same thing as for the images: the pixel heights of the entity at an offset of -1 pixels.  In the demo code I’ve written, this seems to occur only on characters with image 'display (overlay/text-property).  In my (much larger) org mode with latex preview file, it sometimes happens on regular text characters.  I’m hoping/expecting whatever fix we find for this problem corrects that too. 

>> BTW, I haven’t tested it, but I do not think this misbehavior is specific to SVG images.
> 
> I don't think it is.  The display engine has no idea about the source
> of the image data, all it cares about is that it is an image of a
> given size and given attributes.

Makes sense.  That comports with the fact that I’ve seen similar issues with PNG overlays.