Progress. The latest patch had two small hunks fail (see below), but they were simple enough that I was able to insert them by hand and recompile. The good news is that this patch does on my end fix all the problems with the generated SVGs buffer from my recent test, at all window widths. Unfortunately, checking my original file where this issue was revealed, there are still quite a few “false zero height above” reports. Happily in that file there are no longer any of the “overly large height” variety, so this particular issue has apparently has been fixed by your patch. I’ve placed a new test that generates a minimal buffer with a single :file-based SVG overlay at the same gist, and copied/attached them below, for posterity. I’ve also fixed the bug in my/check-buffer-pixel-values which caused the report buffer not to appear (due to end-of-buffer being signaled), so please update that. And please note the new svg_test.svg file, to be placed in the same directory. I don’t think there should be anything special about this particular SVG file; it was automatically generated from the underlying latex fragment. But it seems to be confusing the display engine somehow (as do many others). One thing to note about these SVG files is that they have transparent backgrounds, but I don’t think that’s anything unusual. ++++++++ New test: ++++++++ (let ((buf "svg-file-pixel-zero-demo")) (with-current-buffer (get-buffer-create buf) (erase-buffer) (visual-line-mode 1) (insert "\nProin quam nisl, tincidunt et, mattis eget, convallis nec, purus. $\\chi(y) = \\exp\\left(\\sqrt{\\tan(y)}\\right)$ Nullam tempus.") (goto-char (point-min)) (when (re-search-forward (rx ?$ (* (not ?$)) ?$)) (let ((ov (make-overlay (match-beginning 0) (match-end 0)))) (overlay-put ov 'display `(image :type svg :file ,(expand-file-name "svg_test.svg") :ascent center))))) (pop-to-buffer buf) (my/check-buffer-pixel-values)) ++++++++++++++ Buffer check code ++++++++++++++ (eval-when-compile (require 'cl-lib)) (defun my/check-buffer-pixel-values () (interactive) (goto-char (point-min)) (let ((line-heights (vconcat (save-excursion (cl-loop while (< (point) (point-max)) collect (line-pixel-height) do (vertical-motion 1))))) (line 0) vmax) (with-output-to-temp-buffer "svg-pixel-demo-report" (princ (format "SVG Position analysis for %s (width %d, %s)\n\n" (current-buffer) (window-width) (if (next-single-property-change (point-min) 'display) "text-properties" "overlays"))) (while (not (eobp)) (beginning-of-visual-line) (vertical-motion 1) (setq vmax (save-excursion (end-of-visual-line) (point))) (save-excursion (while (and (<= (point) vmax) (not (eobp))) (let* ((ps (window-text-pixel-size nil (cons (point) -1) (point) nil nil nil t)) (h (nth 1 ps))) (unless (= h (aref line-heights line)) (princ (format "Incorrect at point=%3d: line %2d at %12S (%5s): expected %2d got %2d\n" (point) (+ line 2) (posn-x-y (posn-at-point)) (if (or (overlays-at (point)) (get-text-property (point) 'display)) "image" (char-to-string (char-after (point)))) (aref line-heights line) h)))) (forward-char))) (cl-incf line))))) ++++++++++ Failed hunks: ++++++++++ @ -11436,7 +11436,7 @@ /* Start at the beginning of the line containing FROM. Otherwise IT.current_x will be incorrectly set to zero at some arbitrary non-zero X coordinate. */ - reseat_at_previous_visible_line_start (&it); + move_it_by_lines (&it, 0); it.current_x = it.hpos = 0; if (IT_CHARPOS (it) != start) { @@ -11513,6 +11513,8 @@ the width of the last buffer position manually. */ if (IT_CHARPOS (it) > end) { + int end_y = it.current_y; + end--; RESTORE_IT (&it, &it2, it2data); x = move_it_to (&it, end, to_x, max_y, -1, move_op);