Last active
April 10, 2021 09:16
-
-
Save alanthird/7b86dc66df1ed3b9006bcd3fddd7350f to your computer and use it in GitHub Desktop.
Use SVGs to replace text in Emacs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Score out this text | |
(require 'svg) | |
(defun replace-text (start end) | |
(let* ((str (buffer-substring start end)) | |
(scale (cadr (assoc :height (assoc 'default face-remapping-alist)))) | |
(family (face-attribute 'default :family)) | |
(height (* (aref (font-info family) 2) (if scale scale 1))) | |
(ascent (* (aref (font-info family) 8) (if scale scale 1))) | |
(img (svg-create (car (window-text-pixel-size nil start end)) | |
(line-pixel-height) | |
:font-size height | |
:font-family family))) | |
(svg-text img str :y ascent :fill "red" :textLength "100%") | |
(svg-line img 0 0 "100%" "100%" :stroke "currentColor") | |
(svg-line img "100%" 0 0 "100%" :stroke "currentColor") | |
(add-text-properties start end `(display | |
,(svg-image img :ascent 'center :scale 1) | |
rear-nonsticky t)))) | |
(replace-text 14 18) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment