emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r113853: Make shr feed Content-Type to the image-cre


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] trunk r113853: Make shr feed Content-Type to the image-creating libraries
Date: Tue, 13 Aug 2013 18:09:53 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 113853
revision-id: address@hidden
parent: address@hidden
committer: Lars Magne Ingebrigtsen <address@hidden>
branch nick: trunk
timestamp: Tue 2013-08-13 20:09:50 +0200
message:
  Make shr feed Content-Type to the image-creating libraries
  
  This finally makes it possible to display icons.
  
  * net/eww.el (eww-display-image): Ditto.
  
  * net/shr.el (shr-parse-image-data): New function to grab both the
  data itself and the Content-Type.
  (shr-put-image): Use it.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/net/eww.el                eww.el-20130610114603-80ap3gwnw4x4m5ix-1
  lisp/net/shr.el                shr.el-20101002102929-yfzewk55rsg0mn93-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-08-13 17:45:34 +0000
+++ b/lisp/ChangeLog    2013-08-13 18:09:50 +0000
@@ -1,5 +1,11 @@
 2013-08-13  Lars Magne Ingebrigtsen  <address@hidden>
 
+       * net/shr.el (shr-parse-image-data): New function to grab both the
+       data itself and the Content-Type.
+       (shr-put-image): Use it.
+
+       * net/eww.el (eww-display-image): Ditto.
+
        * image.el (image-content-type-suffixes): New variable.
 
 2013-08-13  Fabián Ezequiel Gallina  <address@hidden>

=== modified file 'lisp/net/eww.el'
--- a/lisp/net/eww.el   2013-08-11 21:51:10 +0000
+++ b/lisp/net/eww.el   2013-08-13 18:09:50 +0000
@@ -304,7 +304,7 @@
     (goto-char (point-min))))
 
 (defun eww-display-image ()
-  (let ((data (buffer-substring (point) (point-max))))
+  (let ((data (shr-parse-image-data)))
     (eww-setup-buffer)
     (let ((inhibit-read-only t))
       (shr-put-image data nil))

=== modified file 'lisp/net/shr.el'
--- a/lisp/net/shr.el   2013-08-13 07:18:50 +0000
+++ b/lisp/net/shr.el   2013-08-13 18:09:50 +0000
@@ -705,7 +705,7 @@
       (url-store-in-cache image-buffer)
       (when (or (search-forward "\n\n" nil t)
                (search-forward "\r\n\r\n" nil t))
-       (let ((data (buffer-substring (point) (point-max))))
+       (let ((data (shr-parse-image-data)))
          (with-current-buffer buffer
            (save-excursion
              (let ((alt (buffer-substring start end))
@@ -732,20 +732,28 @@
        (setq payload (base64-decode-string payload)))
       payload)))
 
-(defun shr-put-image (data alt &optional flags)
-  "Put image DATA with a string ALT.  Return image."
+(defun shr-put-image (spec alt &optional flags)
+  "Insert image SPEC with a string ALT.  Return image.
+SPEC is either an image data blob, or a list where the first
+element is the data blob and the second element is the content-type."
   (if (display-graphic-p)
       (let* ((size (cdr (assq 'size flags)))
+            (data (if (consp spec)
+                      (car spec)
+                    spec))
+            (content-type (and (consp spec)
+                               (cadr spec)))
             (start (point))
             (image (cond
                     ((eq size 'original)
-                     (create-image data nil t :ascent 100))
+                     (create-image data nil t :ascent 100
+                                   :content-type content-type))
                     ((eq size 'full)
                      (ignore-errors
-                       (shr-rescale-image data t)))
+                       (shr-rescale-image data t content-type)))
                     (t
                      (ignore-errors
-                       (shr-rescale-image data))))))
+                       (shr-rescale-image data nil content-type))))))
         (when image
          ;; When inserting big-ish pictures, put them at the
          ;; beginning of the line.
@@ -767,7 +775,7 @@
        image)
     (insert alt)))
 
-(defun shr-rescale-image (data &optional force)
+(defun shr-rescale-image (data &optional force content-type)
   "Rescale DATA, if too big, to fit the current buffer.
 If FORCE, rescale the image anyway."
   (if (or (not (fboundp 'imagemagick-types))
@@ -782,7 +790,8 @@
        :max-width (truncate (* shr-max-image-proportion
                               (- (nth 2 edges) (nth 0 edges))))
        :max-height (truncate (* shr-max-image-proportion
-                               (- (nth 3 edges) (nth 1 edges))))))))
+                               (- (nth 3 edges) (nth 1 edges))))
+       :content-type content-type))))
 
 ;; url-cache-extract autoloads url-cache.
 (declare-function url-cache-create-filename "url-cache" (url))
@@ -799,7 +808,17 @@
            t)
       (when (or (search-forward "\n\n" nil t)
                (search-forward "\r\n\r\n" nil t))
-       (buffer-substring (point) (point-max))))))
+       (shr-parse-image-data)))))
+
+(defun shr-parse-image-data ()
+  (list
+   (buffer-substring (point) (point-max))
+   (save-excursion
+     (save-restriction
+       (narrow-to-region (point-min) (point))
+       (let ((content-type (mail-fetch-field "content-type")))
+        (and content-type
+             (intern content-type obarray)))))))
 
 (defun shr-image-displayer (content-function)
   "Return a function to display an image.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]