Skip to content

Instantly share code, notes, and snippets.

@copyninja
Created October 1, 2013 18:26
Show Gist options
  • Save copyninja/6782850 to your computer and use it in GitHub Desktop.
Save copyninja/6782850 to your computer and use it in GitHub Desktop.
(import [os [popen]]
[os.path [exists]]
[sys]
[re])
(defun get-font-metadata [ fontfile]
"Given the font file function checks for its existence then runs the
otfinfo tool from lcdf-typetools package to extract metadata
information and returns the parsed dict."
(if (not (exists fontfile))
(kwapply (print "Please give existent font file")
{"file" sys.stderr}))
(let [[cmd (.format "/usr/bin/otfinfo -i {}" fontfile)]
[fd (kwapply (popen cmd) {"mode" "r"})]
[regexp (.compile re "([a-zA-Z\s]+):\s*(.*)")]
[metadict {}]
[copyright-text []]]
(foreach [line (.readlines fd)]
(let [[regmatch (.match regexp line)]]
(if (!= regmatch None)
(assoc metadict (.group regmatch 1)
(.group regmatch 2))
(.append copyright-text line))))
(print copyright-text)
(if (in "Copyright" metadict)
(assoc metadict "Copyright"
(.format "{}\n{}"
(get metadict "Copyright")
(.join "" copyright-text))))
metadict))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment