aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-09-14 16:48:21 +0200
committerLars Ingebrigtsen2019-09-14 16:48:21 +0200
commit5a0ab88cc984e8a5e66f85cb5acfa362fc66bdb6 (patch)
tree610a3ce904d493686bc621e90af4e813e3e4eaa0
parent568f1488a69e8cb0961571ff8f158df8891c3c44 (diff)
downloademacs-5a0ab88cc984e8a5e66f85cb5acfa362fc66bdb6.tar.gz
emacs-5a0ab88cc984e8a5e66f85cb5acfa362fc66bdb6.zip
Add default foreground colours to SVG images
* lisp/net/shr.el (svg--wrap-svg): Add a default foreground colour to SVG images (bug#37159). This helps with images like the ones in https://en.wikipedia.org/wiki/Banach_fixed-point_theorem that specify no foreground or background colours. (shr-parse-image-data): Use it.
-rw-r--r--lisp/net/shr.el16
1 files changed, 16 insertions, 0 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 81c3fb4aa52..1dff129b9dc 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1180,8 +1180,24 @@ Return a string with image data."
1180 ;; so glitches may occur during this transformation. 1180 ;; so glitches may occur during this transformation.
1181 (shr-dom-to-xml 1181 (shr-dom-to-xml
1182 (libxml-parse-xml-region (point) (point-max))))) 1182 (libxml-parse-xml-region (point) (point-max)))))
1183 ;; SVG images often do not have a specified foreground/background
1184 ;; color, so wrap them in styles.
1185 (when (eq content-type 'image/svg+xml)
1186 (setq data (svg--wrap-svg data)))
1183 (list data content-type))) 1187 (list data content-type)))
1184 1188
1189(defun svg--wrap-svg (data)
1190 "Add a default foreground colour to SVG images."
1191 (with-temp-buffer
1192 (insert "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" "
1193 "xmlns:xi=\"http://www.w3.org/2001/XInclude\" "
1194 "style=\"color: "
1195 (face-foreground 'default) ";\">"
1196 "<xi:include href=\"data:image/svg+xml;base64,"
1197 (base64-encode-string data t)
1198 "\"></xi:include></svg>")
1199 (buffer-string)))
1200
1185(defun shr-image-displayer (content-function) 1201(defun shr-image-displayer (content-function)
1186 "Return a function to display an image. 1202 "Return a function to display an image.
1187CONTENT-FUNCTION is a function to retrieve an image for a cid url that 1203CONTENT-FUNCTION is a function to retrieve an image for a cid url that