]> code.delx.au - gnu-emacs/commitdiff
New functions for getting and setting image properties
authorLars Ingebrigtsen <larsi@gnus.org>
Sat, 20 Feb 2016 06:54:05 +0000 (17:54 +1100)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 20 Feb 2016 07:03:37 +0000 (18:03 +1100)
* doc/lispref/display.texi (Defining Images): Document
image-get/set-property.

* lisp/image.el (image-set-property): New function.
(image-get-property): Ditto.

doc/lispref/display.texi
etc/NEWS
lisp/image.el

index 17025cd199424173b4194fdeb2a385347e17d608..3758ddf72f5b7928d9f2ba90f1b3075533e9ee1b 100644 (file)
@@ -5205,7 +5205,9 @@ the size, and lower means to decrease the size.  For instance, a value
 of 0.25 will make the image a quarter size of what it originally was.
 If the scaling makes the image larger than specified by
 @code{:max-width} or @code{:max-height}, the resulting size will not
-exceed those two values.
+exceed those two values.  If both @code{:scale} and
+@code{:height}/@code{:width} are specified, the height/width will be
+adjusted by the specified scaling factor.
 
 @item :format @var{type}
 The value, @var{type}, should be a symbol specifying the type of the
@@ -5442,6 +5444,19 @@ If none of the alternatives will work, then @var{symbol} is defined
 as @code{nil}.
 @end defmac
 
+@defun image-set-property image property value
+Set the value of @var{property} in @var{image} to @var{value}.  If
+@var{value} is @code{nil}, the property is removed completely.
+
+@lisp
+(image-set-property image :height 300)
+@end lisp
+@end defun
+
+@defun image-get-property image property
+Return the value of @var{property} in @var{image}.
+@end defun
+
 @defun find-image specs
 This function provides a convenient way to find an image satisfying one
 of a list of image specifications @var{specs}.
index c3c3ebab94d5bc78eec4d863a5dd18fca47540a0..95ca8d35385dc8bb12dbbfce917cd881b86935c3 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -846,6 +846,7 @@ of `epg-gpg-program' (instead of gpg).
 `image-scaling-factor' variable (if Emacs supports scaling the images
 in question).
 
++++
 *** Images inserted with `insert-image' and related functions get a
 keymap put into the text properties (or overlays) that span the
 image.  This keymap binds keystrokes for manipulating size and
@@ -853,7 +854,13 @@ rotation, as well as saving the image to a file.
 
 +++
 *** A new library for creating and manipulating SVG images has been
-added.  See the "SVG Images" section in the lispref manual for details.
+added.  See the "SVG Images" section in the lispref manual for
+details.
+
++++
+*** New functions to access and set image parameters are provided:
+`image-get-property' and `image-set-property'.
+
 
 ** Lisp mode
 
index 855dffad2931cf6611e029f7b7d34ebec64175fc..3522c5bc75c6a1d628bb601fd61dd4990ef23a50 100644 (file)
@@ -435,6 +435,26 @@ Image file names that are not absolute are searched for in the
                        (image-compute-scaling-factor image-scaling-factor)))
            props)))
 
+(defun image-set-property (image property value)
+  "Set PROPERTY in IMAGE to VALUE.
+If VALUE is nil, PROPERTY is removed from IMAGE.  IMAGE is
+returned."
+  (if (null value)
+      (while (cdr image)
+        ;; IMAGE starts with the symbol `image', and the rest is a
+        ;; plist.  Decouple plist entries where the key matches
+        ;; the property.
+        (if (eq (cadr image) property)
+            (setcdr image (cddr image))
+          (setq image (cddr image))))
+    ;; Just enter the new value.
+    (plist-put (cdr image) property value))
+  image)
+
+(defun image-get-property (image property)
+  "Return the value of PROPERTY in IMAGE."
+  (plist-get (cdr image) property))
+
 (defun image-compute-scaling-factor (scaling)
   (cond
    ((numberp image-scaling-factor)