Skip to content

Commit

Permalink
Generate CSS file
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Oct 11, 2023
1 parent 0dde5b7 commit bfa4ec5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rebuild-index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
git -C ~/gh-pages commit -qm "CI index rebuild." || echo "Nothing to commit."
git -C ~/gh-pages push -q origin gh-pages
env:
FILES: index.html glyphs.json chars.txt PromptFont.ttf PromptFont.otf
FILES: index.html glyphs.json chars.txt PromptFont.ttf PromptFont.otf PromptFont.css
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.sfd-*
index.html
chars.txt
chars.txt
PromptFont.css
36 changes: 33 additions & 3 deletions compile.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,46 @@ exec sbcl \
collect (list :name name
:glyphs (sort glyphs #'< :key (lambda (a) (getf a :codepoint)))))))

(defun web (&key (input (file "index" "ctml")) (output (file "index" "html")))
(defun web (&optional (input (file "index" "ctml")) (output (file "index" "html")))
(let ((sections (parse-glyphs)))
(with-open-file (stream output :direction :output :if-exists :supersede)
(plump:serialize (clip:process input :sections sections) stream))))

(defun txt (&key (file (file "glyphs" "json")) (output (file "chars" "txt")))
(defun txt (&optional (file (file "glyphs" "json")) (output (file "chars" "txt")))
(with-open-file (stream output :direction :output :if-exists :supersede)
(loop for glyph across (with-open-file (stream file)
(shasht:read-json stream))
do (write-string (gethash "character" glyph) stream))))

(defun fixup (&optional (file (merge-pathnames "glyphs.json" *here*)))
(defun css-safe-name (name)
(with-output-to-string (out)
(let ((was-dash T))
(labels ((process (name)
(loop for char across name
do (cond ((find char " -_/")
(unless was-dash
(write-char #\- out)
(setf was-dash T)))
((find char "()"))
((alphanumericp char)
(setf was-dash NIL)
(write-char (char-downcase char) out))
(T
(process (char-name char)))))))
(process name)))))

(defun css (&optional (file (file "glyphs" "json")) (output (file "PromptFont" "css")))
(with-open-file (stream output :direction :output :if-exists :supersede)
(format stream "~&@font-face{font-family:'promptfont'; src:url('PromptFont.ttf');}~%")
(format stream "~&.pf{font-family:promptfont;}~%")
(loop for entry across (with-open-file (stream file)
(shasht:read-json stream))
unless (string= "alphabet" (gethash "category" entry))
do (format stream "~&.pf-~a::after{content:'\\u~x';}~%"
(css-safe-name (gethash "name" entry))
(gethash "codepoint" entry)))))

(defun fixup (&optional (file (file "glyphs" "json")))
(let ((data (with-open-file (stream file)
(shasht:read-json stream)))
(names (make-hash-table :test 'equalp)))
Expand All @@ -61,6 +89,7 @@ exec sbcl \
(defun all ()
(fixup)
(txt)
(css)
(web))

(defun help ()
Expand All @@ -71,6 +100,7 @@ Commands:
all --- Performs all below commands. This is run by default
fixup --- Fixes up the glyphs.json file
txt --- Generates the chars.txt file
css --- Generates the PromptFont.css file
web --- Generates the index.html file
You typically do not need this utility as it is run automatically by
Expand Down

0 comments on commit bfa4ec5

Please sign in to comment.