Created
February 2, 2022 21:51
-
-
Save vlaaad/953d060de1946a66128ec0377697f214 to your computer and use it in GitHub Desktop.
This file contains 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
;; deps are: | |
;; {org.apache.xmlgraphics/batik-codec {:mvn/version "1.9.1"} | |
;; clj-http/clj-http {:mvn/version "3.12.3"} | |
;; org.clojure/data.json {:mvn/version "2.4.0"}} | |
(import '[org.apache.batik.svggen SVGGraphics2D] | |
'[org.apache.batik.dom GenericDOMImplementation] | |
'[java.awt Font]) | |
(require '[clj-http.client :as http] | |
'[clojure.data.json :as json]) | |
(def doc (.createDocument (GenericDOMImplementation/getDOMImplementation) "http://www.w3.org/2000/svg" "svg" nil)) | |
(def font (Font. "Courier New" 0 14)) | |
(def g (doto (SVGGraphics2D. doc) | |
(.setFont font))) | |
(def fm (.getFontMetrics g)) | |
(def svg | |
(let [repo "cognitect-labs/test-runner" | |
{:keys [ref object]} (-> (http/get (str "https://api.github.com/repos/" repo "/git/refs/tags")) | |
:body | |
(json/read-str :key-fn keyword) | |
peek) | |
tag (subs ref 10) | |
sha (subs (:sha object) 0 7) | |
text (str "io.github." repo " {:git/tag \"" tag "\" :git/sha \"" sha "\"}") | |
b (.getStringBounds fm text g)] | |
(str "<svg width=\"" | |
(int (Math/ceil (.getWidth b))) | |
"\" height=\"" | |
(int (Math/ceil (.getHeight b))) | |
"\"><text fill=\"black\" x=\"0\" y=\"" | |
(.getAscent fm) | |
"\" font-family=\"" | |
(.getFamily font) | |
"\" font-size=\"" (.getSize font) "\">" | |
text | |
"</text></svg>"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment