Subject: Re: bug#46464: 27.1; wide images are hidden partially at the right edge of window

From: Eli Zaretskii <[email-masked]>
Date: Mon, 15 Feb 2021 17:41:15 +0200

> From: [email-masked]
> Cc: [email-masked]
> Date: Mon, 15 Feb 2021 22:40:56 +0900
> 
> >> If a edge of a image is near the right edge of the window,
> >> the image is mostly hidden. It is not preferable.
> >
> > That's how Emacs behaved since v21.
> 
> If the width of the iamge is 200 pixels, typing some characters at the
> beginning of the same line, the image moves to the right and gets hidden
> gradually and is wrapped to the next visual line.
> 
> If the width of the image is 150 pixels, the entire image does not get
> hidden and it is wrapped when the image right edge is going to across
> the right edge of the window.
> 
> What is the difference?

There's a heuristic that changes behavior when the image becomes
wider than 1/4 of the window.  By default, the "emacs -Q" window is
640 pixels wide, so that's what you see.

> >> And if :margin is specified, the image may be hidden completely.
> >> 
> >> By the way, if :margin is specified, a partial image on the right edge
> >> of the window is displayed with right margin.
> >
> > I don't think I understand what you mean by that.  Can you show a test
> > case?
> 
> Evaluating the form below, four images are supposed to be displayed in
> the first visual line. But the fourth image is invisible. Similar for
> the second visual line.
> 
> If ':margin 5' is replaced with ':margin 20', three images are displayed
> in the first to third visual lines. Third image in each visual line is
> truncated at the x-coordinate 20 pixels apart from the right edge of the
> window. It looks as if the image is not truncated and is small.
> 
> (dotimes (i 10)
>   (let* ((w 200) (h 30) (sw 6)
>          (color (nth (% i 5) '("red" "green" "blue" "yellow" "orange")))
>          (svg (format "<svg width=\"%g\" height=\"%g\"
>  version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">
> <rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" stroke=\"%s\"
>  stroke-width=\"%g\" fill=\"grey\"/>
> </svg>" w h (/ sw 2) (/ sw 2) (- w sw) (- h sw) color sw)))
>     (insert-image (create-image svg 'svg t :margin 5 :scale 1))))

I will look into this and see if this is a bug or intended behavior.

In general, Lisp programs that display wide images should be careful
about these aspects to make sure images aren't clipped and appear in
their entirety.