diff options
| author | Lars Ingebrigtsen | 2016-02-20 17:54:05 +1100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2016-02-20 18:03:37 +1100 |
| commit | 0883e988ac950b2da2893e64822041ca0e6133a0 (patch) | |
| tree | c456f1fa43bdafced9a92b0c19c38c381b145815 | |
| parent | 10c0e1ca40237224aa229c538fe49983ec905748 (diff) | |
| download | emacs-0883e988ac950b2da2893e64822041ca0e6133a0.tar.gz emacs-0883e988ac950b2da2893e64822041ca0e6133a0.zip | |
New functions for getting and setting image properties
* doc/lispref/display.texi (Defining Images): Document
image-get/set-property.
* lisp/image.el (image-set-property): New function.
(image-get-property): Ditto.
| -rw-r--r-- | doc/lispref/display.texi | 17 | ||||
| -rw-r--r-- | etc/NEWS | 9 | ||||
| -rw-r--r-- | lisp/image.el | 20 |
3 files changed, 44 insertions, 2 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 17025cd1994..3758ddf72f5 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -5205,7 +5205,9 @@ the size, and lower means to decrease the size. For instance, a value | |||
| 5205 | of 0.25 will make the image a quarter size of what it originally was. | 5205 | of 0.25 will make the image a quarter size of what it originally was. |
| 5206 | If the scaling makes the image larger than specified by | 5206 | If the scaling makes the image larger than specified by |
| 5207 | @code{:max-width} or @code{:max-height}, the resulting size will not | 5207 | @code{:max-width} or @code{:max-height}, the resulting size will not |
| 5208 | exceed those two values. | 5208 | exceed those two values. If both @code{:scale} and |
| 5209 | @code{:height}/@code{:width} are specified, the height/width will be | ||
| 5210 | adjusted by the specified scaling factor. | ||
| 5209 | 5211 | ||
| 5210 | @item :format @var{type} | 5212 | @item :format @var{type} |
| 5211 | The value, @var{type}, should be a symbol specifying the type of the | 5213 | 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 | |||
| 5442 | as @code{nil}. | 5444 | as @code{nil}. |
| 5443 | @end defmac | 5445 | @end defmac |
| 5444 | 5446 | ||
| 5447 | @defun image-set-property image property value | ||
| 5448 | Set the value of @var{property} in @var{image} to @var{value}. If | ||
| 5449 | @var{value} is @code{nil}, the property is removed completely. | ||
| 5450 | |||
| 5451 | @lisp | ||
| 5452 | (image-set-property image :height 300) | ||
| 5453 | @end lisp | ||
| 5454 | @end defun | ||
| 5455 | |||
| 5456 | @defun image-get-property image property | ||
| 5457 | Return the value of @var{property} in @var{image}. | ||
| 5458 | @end defun | ||
| 5459 | |||
| 5445 | @defun find-image specs | 5460 | @defun find-image specs |
| 5446 | This function provides a convenient way to find an image satisfying one | 5461 | This function provides a convenient way to find an image satisfying one |
| 5447 | of a list of image specifications @var{specs}. | 5462 | of a list of image specifications @var{specs}. |
| @@ -846,6 +846,7 @@ of `epg-gpg-program' (instead of gpg). | |||
| 846 | `image-scaling-factor' variable (if Emacs supports scaling the images | 846 | `image-scaling-factor' variable (if Emacs supports scaling the images |
| 847 | in question). | 847 | in question). |
| 848 | 848 | ||
| 849 | +++ | ||
| 849 | *** Images inserted with `insert-image' and related functions get a | 850 | *** Images inserted with `insert-image' and related functions get a |
| 850 | keymap put into the text properties (or overlays) that span the | 851 | keymap put into the text properties (or overlays) that span the |
| 851 | image. This keymap binds keystrokes for manipulating size and | 852 | image. This keymap binds keystrokes for manipulating size and |
| @@ -853,7 +854,13 @@ rotation, as well as saving the image to a file. | |||
| 853 | 854 | ||
| 854 | +++ | 855 | +++ |
| 855 | *** A new library for creating and manipulating SVG images has been | 856 | *** A new library for creating and manipulating SVG images has been |
| 856 | added. See the "SVG Images" section in the lispref manual for details. | 857 | added. See the "SVG Images" section in the lispref manual for |
| 858 | details. | ||
| 859 | |||
| 860 | +++ | ||
| 861 | *** New functions to access and set image parameters are provided: | ||
| 862 | `image-get-property' and `image-set-property'. | ||
| 863 | |||
| 857 | 864 | ||
| 858 | ** Lisp mode | 865 | ** Lisp mode |
| 859 | 866 | ||
diff --git a/lisp/image.el b/lisp/image.el index 855dffad293..3522c5bc75c 100644 --- a/lisp/image.el +++ b/lisp/image.el | |||
| @@ -435,6 +435,26 @@ Image file names that are not absolute are searched for in the | |||
| 435 | (image-compute-scaling-factor image-scaling-factor))) | 435 | (image-compute-scaling-factor image-scaling-factor))) |
| 436 | props))) | 436 | props))) |
| 437 | 437 | ||
| 438 | (defun image-set-property (image property value) | ||
| 439 | "Set PROPERTY in IMAGE to VALUE. | ||
| 440 | If VALUE is nil, PROPERTY is removed from IMAGE. IMAGE is | ||
| 441 | returned." | ||
| 442 | (if (null value) | ||
| 443 | (while (cdr image) | ||
| 444 | ;; IMAGE starts with the symbol `image', and the rest is a | ||
| 445 | ;; plist. Decouple plist entries where the key matches | ||
| 446 | ;; the property. | ||
| 447 | (if (eq (cadr image) property) | ||
| 448 | (setcdr image (cddr image)) | ||
| 449 | (setq image (cddr image)))) | ||
| 450 | ;; Just enter the new value. | ||
| 451 | (plist-put (cdr image) property value)) | ||
| 452 | image) | ||
| 453 | |||
| 454 | (defun image-get-property (image property) | ||
| 455 | "Return the value of PROPERTY in IMAGE." | ||
| 456 | (plist-get (cdr image) property)) | ||
| 457 | |||
| 438 | (defun image-compute-scaling-factor (scaling) | 458 | (defun image-compute-scaling-factor (scaling) |
| 439 | (cond | 459 | (cond |
| 440 | ((numberp image-scaling-factor) | 460 | ((numberp image-scaling-factor) |