Skip to content

Instantly share code, notes, and snippets.

@rougier
Last active October 3, 2020 13:24
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rougier/5580df295571f7445db2ca8282d79c56 to your computer and use it in GitHub Desktop.
Save rougier/5580df295571f7445db2ca8282d79c56 to your computer and use it in GitHub Desktop.
SVG Rounded box for Emacs
(require 'svg)
;; Rounded boxes using SVG:
;; This could be made into a function but size of text needs to be computed
(defun tag (text &optional foreground background font-size)
(let* ((font-size (or font-size 12))
;; The char-width ratio depends on the font family
(char-width (* font-size 0.58))
(char-height (+ font-size 1))
(hmargin char-width)
(vmargin (* font-size 0.175))
(radius (/ font-size 4))
(background (or background "blue"))
(foreground (or foreground "white"))
(width (+ (* char-width (length text)) (* hmargin 2)))
(height (+ char-height (* vmargin 2)))
(svg (svg-create width height)))
(svg-rectangle svg 0 0 width height :fill background :rx radius)
(svg-text svg text
:font-family "Roboto Mono" :font-weight "light"
:font-size font-size :fill foreground
:x hmargin :y char-height)
(insert-image (svg-image svg :ascent 'center)))
)
(tag "IMPORTANT" "white" "blue" 12)
(tag "WARNING" "white" "orange" 12)
(tag "DANGER" "white" "red" 24)
;; Important:
;; Warning:
;; Danger:
@rougier
Copy link
Author

rougier commented Jun 1, 2020

Screenshot 2020-06-01 at 17 24 21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment