all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Tony Zorman <tonyzorman@mailbox.org>
Cc: 59080@debbugs.gnu.org
Subject: bug#59080: 29.0.50; preview-get-dpi produces surprising result on vertical monitor
Date: Mon, 07 Nov 2022 09:30:16 +0800	[thread overview]
Message-ID: <87r0yf8sbb.fsf@yahoo.com> (raw)
In-Reply-To: <87mt94aylx.fsf@hyperspace> (Tony Zorman's message of "Sun, 06 Nov 2022 16:31:22 +0100")

Tony Zorman <tonyzorman@mailbox.org> writes:

> Hi,
>
> tl;dr: the `preview-get-dpi' function compares the wrong values for
> horizontal monitors (i.e., ones that are flipped by 90/270 degrees).
>
> When previewing LaTeX fragments via AUCTeX's `preview.el' library,
> things get quite messed up when one or more monitors are set up in
> "portrait mode".  I have attached three images that show this; bug1.png
> shows a rendered equation for two vertical monitors, bug2.png for a
> single one, and horiz.png displays that same equation being rendered on
> a horizontal monitor (i.e., this is the expected result).
>
> Looking into `preview.el', it seems like that `preview-get-dpi' (called
> by `preview-get-geometry', which is in turn called by
> `preview-generate-preview') calculates the wrong "resolution".  The
> relevant implementation is
>
>     (defun preview-get-dpi ()
>       (let* ((monitor-attrs (frame-monitor-attributes))
>              (mm-dims (cdr (assoc 'mm-size monitor-attrs)))
>              (mm-width (nth 0 mm-dims))
>              (mm-height (nth 1 mm-dims))
>              (pixel-dims (cl-cdddr (assoc 'geometry monitor-attrs)))
>              (pixel-width (nth 0 pixel-dims))
>              (pixel-height (nth 1 pixel-dims)))
>         (cons (/ (* 25.4 pixel-width) mm-width)
>               (/ (* 25.4 pixel-height) mm-height))))
>
> An example output of `frame-monitor-attributes' for a horizontal
> monitor:
>
>     '((name . "DP1")
>       (geometry 0 0 1920 1080)
>       (workarea 0 0 1920 1080)
>       (mm-size 530 300)
>       (frames <<omitted>>)
>       (source . "XRandR 1.5"))
>
> The same monitor in "vertical-mode" returns:
>
>     '((name . "DP1")
>       (geometry 0 0 1080 1920)
>       (workarea 0 0 1080 1920)
>       (mm-size 530 300)
>       (frames <<omitted>>)
>       (source . "XRandR 1.5"))
>
> Crucially, the returned physical width and height of the monitor don't
> change, but the geometry—what will be the pixel width and height—does.
> However, turning the monitor by 90 degrees obviously switches the
> physical width an height around as well, although that perhaps can't be
> reported property.  In such a situation, we actually compare the pixel
> _width_ of the monitor with its physical _height_, as well as its pixel
> height with its width.  Naturally, and depending on the specific setup,
> this produces too narrow or too wide previews.
>
> I have fixed this locally by only comparing comparable values; i.e.,
> instead of
>
>     (cons (/ (* 25.4 pixel-width) mm-width)
>           (/ (* 25.4 pixel-height) mm-height))
>
> I wrote something like
>
>     (cons (/ (* 25.4 (max pixel-width pixel-height)) (max mm-width mm-height))
>           (/ (* 25.4 (min pixel-width pixel-height)) (min mm-width mm-height)))
>
> This fixed the problem for me, but I don't know if there is some
> situation (or strange resolution) in which it would be correct to
> compare some other combination of values.
>
> Hopefully this was comprehensible.  If not, feel free to ask for more
> information.
>
> Best,
>   Tony

Thanks.

The problem here is under version 1.5 of the RandR extension, monitors
can have multiple outputs attached to multiple CRTCs, each with its own
transform.  So the X server has to stretch itself very hard to calculate
the actual width and height of the monitor area.

I suggest filing a bug under xorgproto asking to clarify how the
physical width and height of a monitor can be reconciled with the
transforms of each of its outputs CRT controllers.

Under version 1.3 of the extension, Emacs should flip the physical
monitor width and height itself.  Unfortunately, version 1.3 is obsolete
and does not really take modern features (such as outputs that do not
display desktop contents) into account.





      reply	other threads:[~2022-11-07  1:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-06 15:31 bug#59080: 29.0.50; preview-get-dpi produces surprising result on vertical monitor Tony Zorman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-07  1:30 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r0yf8sbb.fsf@yahoo.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=59080@debbugs.gnu.org \
    --cc=luangruo@yahoo.com \
    --cc=tonyzorman@mailbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.