diff options
| author | Lars Ingebrigtsen | 2019-10-02 13:19:17 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-10-03 16:15:22 +0200 |
| commit | 0b5fe611e996a609866c3d84ee6c2d1e5dffd812 (patch) | |
| tree | 901dfb281dd674fd662f0aef3d3f3c7500a50644 | |
| parent | e7e55e5e4dad95c5e605553d4ad3daa1422d0ea3 (diff) | |
| download | emacs-0b5fe611e996a609866c3d84ee6c2d1e5dffd812.tar.gz emacs-0b5fe611e996a609866c3d84ee6c2d1e5dffd812.zip | |
Fix up previous SVG-multibyte fix
* lisp/net/shr.el (shr-dom-to-xml): For SVG images, take an
optional charset parameter to return unibyte data.
(shr-parse-image-data): Use it.
(shr-tag-svg): Ditto.
(svg--wrap-svg): Revert previous kludge.
| -rw-r--r-- | lisp/net/shr.el | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el index ef236bf7c48..cf32763a4f1 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el | |||
| @@ -1146,14 +1146,13 @@ width/height instead." | |||
| 1146 | 1146 | ||
| 1147 | ;; url-cache-extract autoloads url-cache. | 1147 | ;; url-cache-extract autoloads url-cache. |
| 1148 | (declare-function url-cache-create-filename "url-cache" (url)) | 1148 | (declare-function url-cache-create-filename "url-cache" (url)) |
| 1149 | (autoload 'mm-disable-multibyte "mm-util") | ||
| 1150 | (autoload 'browse-url-mail "browse-url") | 1149 | (autoload 'browse-url-mail "browse-url") |
| 1151 | 1150 | ||
| 1152 | (defun shr-get-image-data (url) | 1151 | (defun shr-get-image-data (url) |
| 1153 | "Get image data for URL. | 1152 | "Get image data for URL. |
| 1154 | Return a string with image data." | 1153 | Return a string with image data." |
| 1155 | (with-temp-buffer | 1154 | (with-temp-buffer |
| 1156 | (mm-disable-multibyte) | 1155 | (set-buffer-multibyte nil) |
| 1157 | (when (ignore-errors | 1156 | (when (ignore-errors |
| 1158 | (url-cache-extract (url-cache-create-filename (shr-encode-url url))) | 1157 | (url-cache-extract (url-cache-create-filename (shr-encode-url url))) |
| 1159 | t) | 1158 | t) |
| @@ -1183,7 +1182,7 @@ Return a string with image data." | |||
| 1183 | ;; Note that libxml2 doesn't parse everything perfectly, | 1182 | ;; Note that libxml2 doesn't parse everything perfectly, |
| 1184 | ;; so glitches may occur during this transformation. | 1183 | ;; so glitches may occur during this transformation. |
| 1185 | (shr-dom-to-xml | 1184 | (shr-dom-to-xml |
| 1186 | (libxml-parse-xml-region (point) (point-max))))) | 1185 | (libxml-parse-xml-region (point) (point-max)) 'utf-8))) |
| 1187 | ;; SVG images often do not have a specified foreground/background | 1186 | ;; SVG images often do not have a specified foreground/background |
| 1188 | ;; color, so wrap them in styles. | 1187 | ;; color, so wrap them in styles. |
| 1189 | (when (eq content-type 'image/svg+xml) | 1188 | (when (eq content-type 'image/svg+xml) |
| @@ -1199,9 +1198,7 @@ Return a string with image data." | |||
| 1199 | "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xi=\"http://www.w3.org/2001/XInclude\" style=\"color: %s;\" viewBox=\"0 0 %d %d\"> <xi:include href=\"data:image/svg+xml;base64,%s\"></xi:include></svg>" | 1198 | "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xi=\"http://www.w3.org/2001/XInclude\" style=\"color: %s;\" viewBox=\"0 0 %d %d\"> <xi:include href=\"data:image/svg+xml;base64,%s\"></xi:include></svg>" |
| 1200 | (face-foreground 'default) | 1199 | (face-foreground 'default) |
| 1201 | (car size) (cdr size) | 1200 | (car size) (cdr size) |
| 1202 | (base64-encode-string (encode-coding-string | 1201 | (base64-encode-string data t))) |
| 1203 | data (car (detect-coding-string data))) | ||
| 1204 | t))) | ||
| 1205 | (buffer-string)))) | 1202 | (buffer-string)))) |
| 1206 | 1203 | ||
| 1207 | (defun shr-image-displayer (content-function) | 1204 | (defun shr-image-displayer (content-function) |
| @@ -1341,9 +1338,11 @@ ones, in case fg and bg are nil." | |||
| 1341 | (defun shr-tag-comment (_dom) | 1338 | (defun shr-tag-comment (_dom) |
| 1342 | ) | 1339 | ) |
| 1343 | 1340 | ||
| 1344 | (defun shr-dom-to-xml (dom) | 1341 | (defun shr-dom-to-xml (dom &optional charset) |
| 1345 | (with-temp-buffer | 1342 | (with-temp-buffer |
| 1346 | (shr-dom-print dom) | 1343 | (shr-dom-print dom) |
| 1344 | (when charset | ||
| 1345 | (encode-coding-region (point-min) (point-max) charset)) | ||
| 1347 | (buffer-string))) | 1346 | (buffer-string))) |
| 1348 | 1347 | ||
| 1349 | (defun shr-dom-print (dom) | 1348 | (defun shr-dom-print (dom) |
| @@ -1376,7 +1375,8 @@ ones, in case fg and bg are nil." | |||
| 1376 | (not shr-inhibit-images) | 1375 | (not shr-inhibit-images) |
| 1377 | (dom-attr dom 'width) | 1376 | (dom-attr dom 'width) |
| 1378 | (dom-attr dom 'height)) | 1377 | (dom-attr dom 'height)) |
| 1379 | (funcall shr-put-image-function (list (shr-dom-to-xml dom) 'image/svg+xml) | 1378 | (funcall shr-put-image-function (list (shr-dom-to-xml dom 'utf-8) |
| 1379 | 'image/svg+xml) | ||
| 1380 | "SVG Image"))) | 1380 | "SVG Image"))) |
| 1381 | 1381 | ||
| 1382 | (defun shr-tag-sup (dom) | 1382 | (defun shr-tag-sup (dom) |