Last active
October 3, 2020 13:24
-
-
Save rougier/5580df295571f7445db2ca8282d79c56 to your computer and use it in GitHub Desktop.
SVG Rounded box for 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
(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: |
Author
rougier
commented
Jun 1, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment