From 55a7b2ea1220cdf7d0aa511e4f65b0d021162b44 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sun, 23 Jun 2024 17:27:24 -0700 Subject: [PATCH 2/2] Support rescaling sliced images in EWW via 'text-scale-mode' * src/xdisp.c (find_display_property): When the property value has multiple elements, return the whole list. * lisp/net/eww.el (eww--rescale-images): Use 'get-display-property'. * doc/lispref/display.texi (Display Property): Describe the new 'get-display-property' behavior. --- doc/lispref/display.texi | 6 ++++-- lisp/net/eww.el | 9 +++++++-- src/xdisp.c | 24 ++++++++++++++++++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 34096196df4..67b64df75fd 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -5182,8 +5182,10 @@ Display Property This convenience function can be used to get a specific display property, no matter whether the @code{display} property is a vector, a list or a simple property. This is like @code{get-text-property} -(@pxref{Examining Properties}), but works on the @code{display} -property only. +(@pxref{Examining Properties}), but works on the @code{display} property +only. For properties with a single value (e.g.@: @code{height}, this +returns the value itself; for properties with a list of values (e.g.@: +@code{slice}), this returns the list of values. @var{position} is the position in the buffer or string to examine, and @var{prop} is the @code{display} property to return. The optional diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 94bfd333fa9..907b35f8565 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -1370,8 +1370,13 @@ eww--rescale-images (save-excursion (goto-char (point-min)) (while-let ((match (text-property-search-forward - 'display nil (lambda (_ value) (imagep value))))) - (let* ((image (prop-match-value match)) + 'display nil + (lambda (_ value) + (and value (get-display-property + nil 'image nil value)))))) + (let* ((image (cons 'image + (get-display-property nil 'image nil + (prop-match-value match)))) (original-scale (or (image-property image :original-scale) (setf (image-property image :original-scale) (or (image-property image :scale) diff --git a/src/xdisp.c b/src/xdisp.c index 18ac5b69d7e..8c7e8e5cb43 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -5549,6 +5549,7 @@ setup_for_ellipsis (struct it *it, int len) static Lisp_Object find_display_property (Lisp_Object disp, Lisp_Object prop) { + Lisp_Object elem; if (NILP (disp)) return Qnil; /* We have a vector of display specs. */ @@ -5556,11 +5557,11 @@ find_display_property (Lisp_Object disp, Lisp_Object prop) { for (ptrdiff_t i = 0; i < ASIZE (disp); i++) { - Lisp_Object elem = AREF (disp, i); + elem = AREF (disp, i); if (CONSP (elem) && CONSP (XCDR (elem)) && EQ (XCAR (elem), prop)) - return XCAR (XCDR (elem)); + goto found; } return Qnil; } @@ -5570,11 +5571,11 @@ find_display_property (Lisp_Object disp, Lisp_Object prop) { while (!NILP (disp)) { - Lisp_Object elem = XCAR (disp); + elem = XCAR (disp); if (CONSP (elem) && CONSP (XCDR (elem)) && EQ (XCAR (elem), prop)) - return XCAR (XCDR (elem)); + goto found; /* Check that we have a proper list before going to the next element. */ @@ -5589,9 +5590,20 @@ find_display_property (Lisp_Object disp, Lisp_Object prop) else if (CONSP (disp) && CONSP (XCDR (disp)) && EQ (XCAR (disp), prop)) - return XCAR (XCDR (disp)); + { + elem = disp; + goto found; + } + + return Qnil; + + found: + /* If the property value is a list of one element, just return the + CAR. */ + if (NILP (XCDR (XCDR (elem)))) + return XCAR (XCDR (elem)); else - return Qnil; + return XCDR (elem); } static Lisp_Object -- 2.25.1