aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/net/shr.el
diff options
context:
space:
mode:
authorAlan Mackenzie2017-02-12 10:59:03 +0000
committerAlan Mackenzie2017-02-12 10:59:03 +0000
commitf4d5b687150810129b7a1d5b006e31ccf82b691b (patch)
tree4229b13800349032697daae3904dc3773e6b7a80 /lisp/net/shr.el
parentd5514332d4a6092673ce1f78fadcae0c57f7be64 (diff)
parent148100d98319499f0ac6f57b8be08cbd14884a5c (diff)
downloademacs-comment-cache.tar.gz
emacs-comment-cache.zip
Merge branch 'master' into comment-cachecomment-cache
Diffstat (limited to 'lisp/net/shr.el')
-rw-r--r--lisp/net/shr.el32
1 files changed, 21 insertions, 11 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index e0bb3dbb2b7..b7c48288494 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -96,8 +96,9 @@ If nil, don't draw horizontal table lines."
96(defcustom shr-width nil 96(defcustom shr-width nil
97 "Frame width to use for rendering. 97 "Frame width to use for rendering.
98May either be an integer specifying a fixed width in characters, 98May either be an integer specifying a fixed width in characters,
99or nil, meaning that the full width of the window should be 99or nil, meaning that the full width of the window should be used.
100used." 100If `shr-use-fonts' is set, the mean character width is used to
101compute the pixel width, which is used instead."
101 :version "25.1" 102 :version "25.1"
102 :type '(choice (integer :tag "Fixed width in characters") 103 :type '(choice (integer :tag "Fixed width in characters")
103 (const :tag "Use the width of the window" nil)) 104 (const :tag "Use the width of the window" nil))
@@ -978,7 +979,7 @@ element is the data blob and the second element is the content-type."
978 (create-image data nil t :ascent 100 979 (create-image data nil t :ascent 100
979 :format content-type)) 980 :format content-type))
980 ((eq content-type 'image/svg+xml) 981 ((eq content-type 'image/svg+xml)
981 (create-image data 'svg t :ascent 100)) 982 (create-image data 'imagemagick t :ascent 100))
982 ((eq size 'full) 983 ((eq size 'full)
983 (ignore-errors 984 (ignore-errors
984 (shr-rescale-image data content-type 985 (shr-rescale-image data content-type
@@ -1011,18 +1012,25 @@ element is the data blob and the second element is the content-type."
1011 image) 1012 image)
1012 (insert (or alt "")))) 1013 (insert (or alt ""))))
1013 1014
1014(defun shr-rescale-image (data content-type width height) 1015(defun shr-rescale-image (data content-type width height
1016 &optional max-width max-height)
1015 "Rescale DATA, if too big, to fit the current buffer. 1017 "Rescale DATA, if too big, to fit the current buffer.
1016WIDTH and HEIGHT are the sizes given in the HTML data, if any." 1018WIDTH and HEIGHT are the sizes given in the HTML data, if any.
1019
1020The size of the displayed image will not exceed
1021MAX-WIDTH/MAX-HEIGHT. If not given, use the current window
1022width/height instead."
1017 (if (or (not (fboundp 'imagemagick-types)) 1023 (if (or (not (fboundp 'imagemagick-types))
1018 (not (get-buffer-window (current-buffer)))) 1024 (not (get-buffer-window (current-buffer))))
1019 (create-image data nil t :ascent 100) 1025 (create-image data nil t :ascent 100)
1020 (let* ((edges (window-inside-pixel-edges 1026 (let* ((edges (window-inside-pixel-edges
1021 (get-buffer-window (current-buffer)))) 1027 (get-buffer-window (current-buffer))))
1022 (max-width (truncate (* shr-max-image-proportion 1028 (max-width (truncate (* shr-max-image-proportion
1023 (- (nth 2 edges) (nth 0 edges))))) 1029 (or max-width
1030 (- (nth 2 edges) (nth 0 edges))))))
1024 (max-height (truncate (* shr-max-image-proportion 1031 (max-height (truncate (* shr-max-image-proportion
1025 (- (nth 3 edges) (nth 1 edges))))) 1032 (or max-height
1033 (- (nth 3 edges) (nth 1 edges))))))
1026 (scaling (image-compute-scaling-factor image-scaling-factor))) 1034 (scaling (image-compute-scaling-factor image-scaling-factor)))
1027 (when (or (and width 1035 (when (or (and width
1028 (> width max-width)) 1036 (> width max-width))
@@ -1059,8 +1067,7 @@ Return a string with image data."
1059 (when (ignore-errors 1067 (when (ignore-errors
1060 (url-cache-extract (url-cache-create-filename (shr-encode-url url))) 1068 (url-cache-extract (url-cache-create-filename (shr-encode-url url)))
1061 t) 1069 t)
1062 (when (or (search-forward "\n\n" nil t) 1070 (when (re-search-forward "\r?\n\r?\n" nil t)
1063 (search-forward "\r\n\r\n" nil t))
1064 (shr-parse-image-data))))) 1071 (shr-parse-image-data)))))
1065 1072
1066(declare-function libxml-parse-xml-region "xml.c" 1073(declare-function libxml-parse-xml-region "xml.c"
@@ -1079,9 +1086,12 @@ Return a string with image data."
1079 obarray))))))) 1086 obarray)))))))
1080 ;; SVG images may contain references to further images that we may 1087 ;; SVG images may contain references to further images that we may
1081 ;; want to block. So special-case these by parsing the XML data 1088 ;; want to block. So special-case these by parsing the XML data
1082 ;; and remove the blocked bits. 1089 ;; and remove anything that looks like a blocked bit.
1083 (when (eq content-type 'image/svg+xml) 1090 (when (and shr-blocked-images
1091 (eq content-type 'image/svg+xml))
1084 (setq data 1092 (setq data
1093 ;; Note that libxml2 doesn't parse everything perfectly,
1094 ;; so glitches may occur during this transformation.
1085 (shr-dom-to-xml 1095 (shr-dom-to-xml
1086 (libxml-parse-xml-region (point) (point-max))))) 1096 (libxml-parse-xml-region (point) (point-max)))))
1087 (list data content-type))) 1097 (list data content-type)))