From 38738f61bc16f5792220467730634598ac92f149 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 19 Oct 2017 00:25:22 +0200 Subject: [PATCH] Encode non-ASCII SVG texts * lisp/svg.el (svg--encode-text): Encode non-ASCII texts. --- lisp/svg.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lisp/svg.el b/lisp/svg.el index 6a0c49b4698..8639bf11243 100644 --- a/lisp/svg.el +++ b/lisp/svg.el @@ -157,7 +157,21 @@ otherwise. IMAGE-TYPE should be a MIME image type, like (dom-node 'text `(,@(svg--arguments svg args)) - text))) + (svg--encode-text text)))) + +(defun svg--encode-text (text) + ;; Apparently the SVG renderer needs to have all non-ASCII + ;; characters encoded. + (with-temp-buffer + (insert text) + (goto-char (point-min)) + (while (not (eobp)) + (let ((char (following-char))) + (if (<= char 128) + (forward-char 1) + (delete-char 1) + (insert "&#" (format "%d" char) ";")))) + (buffer-string))) (defun svg--append (svg node) (let ((old (and (dom-attr node 'id) -- 2.39.5