org-latex-preview: Robustify DPI calculation

* lisp/org-latex-preview.el (org-latex-preview--get-display-dpi): It was
reported that on a WSLg system using pgtk that
`org-latex-preview--get-display-dpi' produced an arithmetic overflow
error.  Inspecting the calculation performed and docstrings of functions
involved, it seems we need to be more careful of the `display-mm-height'
output.  We now guard against it being zero or nil, which should make
the DPI calculation more robust.

Simply falling back to a guessed DPI of 140 is non-ideal, but probably
the best we can reasonably do here.
This commit is contained in:
TEC 2024-01-06 18:09:14 +08:00
parent c20bf88205
commit 5e7af27352
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 5 additions and 2 deletions

View File

@ -2405,8 +2405,11 @@ color information for this run."
The function assumes that the display has the same pixel width in The function assumes that the display has the same pixel width in
the horizontal and vertical directions." the horizontal and vertical directions."
(if (display-graphic-p) (if (display-graphic-p)
(round (/ (display-pixel-height) (let ((mm-height (or (display-mm-height) 0))
(/ (display-mm-height) 25.4))) (mm-per-inch 25.4))
(if (= 0 mm-height)
140 ; Fallback reasonable DPI
(round (/ (display-pixel-height) (/ mm-height mm-per-inch)))))
(error "Attempt to calculate the dpi of a non-graphic display"))) (error "Attempt to calculate the dpi of a non-graphic display")))
(defun org-latex-preview--attr-color (attr) (defun org-latex-preview--attr-color (attr)