Skip to content

Commit 1c4866e

Browse files
committed
Updated Clojure generator to Glyphs formatVersion 3
1 parent c74dd80 commit 1c4866e

49 files changed

Lines changed: 373 additions & 165 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

FiraCode.glyphs

Lines changed: 251 additions & 67 deletions
Large diffs are not rendered by default.

clojure/fira_code/calt.clj

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
;; try to match last N glyphs in `prefix` with N first in `liga`
2424
N (range (count liga) 0 -1)
2525
:when (= (take-last N prefix) (take N liga))]
26-
(str " ignore sub"
26+
(str
27+
" ignore sub"
2728
" " (str/join " " (drop-last N prefix))
2829
" " (first liga) "'"
2930
" " (str/join " " (drop 1 liga))
@@ -237,7 +238,8 @@
237238
(str
238239
"lookup 1_2 {\n"
239240
(when-not (skip-ignores? liga)
240-
(str " ignore sub 1 1' 2;\n"
241+
(str
242+
" ignore sub 1 1' 2;\n"
241243
" ignore sub 1' 2 2;\n"))
242244
(gen-ignore-prefixes liga)
243245
(get ignores liga)
@@ -251,7 +253,8 @@
251253
(str
252254
"lookup 1_2_3 {\n"
253255
(when-not (skip-ignores? liga)
254-
(str " ignore sub 1 1' 2 3;\n"
256+
(str
257+
" ignore sub 1 1' 2 3;\n"
255258
" ignore sub 1' 2 3 3;\n"))
256259
(gen-ignore-prefixes liga)
257260
(get ignores liga)
@@ -266,7 +269,8 @@
266269
(str
267270
"lookup 1_2_3_4 {\n"
268271
(when-not (skip-ignores? liga)
269-
(str " ignore sub 1 1' 2 3 4;\n"
272+
(str
273+
" ignore sub 1 1' 2 3 4;\n"
270274
" ignore sub 1' 2 3 4 4;\n"))
271275
(gen-ignore-prefixes liga)
272276
(get ignores liga)
@@ -282,7 +286,8 @@
282286
(str
283287
"lookup 1_2_3_4_5 {\n"
284288
(when-not (skip-ignores? liga)
285-
(str " ignore sub 1 1' 2 3 4 5;\n"
289+
(str
290+
" ignore sub 1 1' 2 3 4 5;\n"
286291
" ignore sub 1' 2 3 4 4 5;\n"))
287292
(gen-ignore-prefixes liga)
288293
(get ignores liga)
@@ -335,4 +340,4 @@
335340
(get counts 4) " quadruples, "
336341
(count ligas') " total" #_")"))
337342

338-
(glyphs/update-code font :features "calt" (constantly calt))))
343+
(glyphs/update-code font :features :tag "calt" (constantly calt))))

clojure/fira_code/features.clj

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,30 @@
77
(:import
88
[java.io File]))
99

10+
(defn trim [s]
11+
(-> s
12+
(str/replace #"(?m) +$" "")
13+
(str/trim)))
14+
1015
(defn append-calt [font]
1116
(let [features (->> (files/find "features/calt" #"features/calt/[^/]+\.fea")
1217
(map slurp)
13-
(map str/trim)
18+
(map trim)
1419
(str/join "\n\n"))]
1520
(println " appending to feature calt" (glyphs/lines features) "lines")
16-
(glyphs/update-code font :features "calt"
17-
#(str % "\n\n" features))))
21+
(glyphs/update-code font :features :tag "calt" #(str % "\n\n" features))))
1822

1923
(defn fill-feature [font file]
20-
(let [[_ name] (re-matches #"([^.]+)\.fea" (File/.getName file))
21-
code (slurp file)
22-
[_ notes code'] (re-matches #"(?s)#([^\n]+)\n(.*)" code)
23-
feature (cond-> {:code (str/trim (or code' code))
24-
:name name}
25-
notes
26-
(assoc :notes (str/trim notes)))]
27-
(glyphs/set-feature font name feature)))
24+
(let [[_ tag] (re-matches #"([^.]+)\.fea" (File/.getName file))
25+
code (slurp file)
26+
[_ name code'] (re-matches #"(?s)###[ ]*([^\n]*[^\n ])[ ]*\n(.*)" code)
27+
code (trim (or code' code))
28+
feature (cond-> {:code code}
29+
name (assoc :labels
30+
[{:language "dflt"
31+
:value name}])
32+
true (assoc :tag tag))]
33+
(glyphs/set-feature font tag feature)))
2834

2935
(defn fill-features [font]
3036
(reduce fill-feature font (files/find "features" #"features/[^/]+\.fea")))

clojure/fira_code/glyphs.clj

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -106,34 +106,51 @@
106106
*pos (atom 0)]
107107
(parse-anything!)))
108108

109-
(def escapes
110-
{"\"" "\\\""
111-
"\\" "\\\\"})
112-
113-
(def escape-re
114-
#"[\n\"\\]")
115-
116109
(defn- serialize-impl [form]
117110
(cond
118-
(string? form) (if (re-matches #"[a-zA-Z0-9._/]+" form)
119-
form
120-
(str \" (str/replace form escape-re escapes) \"))
121-
(keyword? form) (name form)
122-
(number? form) (str form)
111+
(string? form)
112+
(if (re-matches #"[a-zA-Z0-9._/]+" form)
113+
form
114+
(str \" (str/replace form #"[\"\\]" {"\"" "\\\""
115+
"\\" "\\\\"}) \"))
116+
117+
(keyword? form)
118+
(name form)
119+
120+
(number? form)
121+
(str form)
122+
123123
(instance? clojure.lang.MapEntry form)
124-
(str
125-
(serialize-impl (key form))
126-
" = "
127-
(if (= ".appVersion" (key form)) ;; https://github.com/googlefonts/glyphsLib/issues/209
128-
(str \" (val form) \")
129-
(serialize-impl (val form)))
130-
";")
131-
(sequential? form) (if (empty? form)
132-
"(\n)"
133-
(str "(\n" (str/join ",\n" (map serialize-impl form)) "\n)"))
134-
(map? form) (if (empty? form)
135-
"{\n}"
136-
(str "{\n" (str/join "\n" (map serialize-impl form)) "\n}"))))
124+
(str
125+
(serialize-impl (key form))
126+
" = "
127+
(case (key form)
128+
;; https://github.com/googlefonts/glyphsLib/issues/209
129+
".appVersion"
130+
(str \" (val form) \")
131+
132+
;; ¯\_(ツ)_/¯
133+
(:stemValues "stemValues")
134+
(str "(\n" (str/join ",\n" (val form)) "\n)")
135+
136+
;; else
137+
(serialize-impl (val form)))
138+
";")
139+
140+
(and (sequential? form) (empty? form))
141+
"(\n)"
142+
143+
(and (sequential? form) (<= 2 (count form) 3) (not (coll? (first form))))
144+
(str "(" (str/join "," (map serialize-impl form)) ")")
145+
146+
(sequential? form)
147+
(str "(\n" (str/join ",\n" (map serialize-impl form)) "\n)")
148+
149+
(and (map? form) (empty? form))
150+
"{\n}"
151+
152+
(map? form)
153+
(str "{\n" (str/join "\n" (map serialize-impl form)) "\n}")))
137154

138155
(defn serialize [font]
139156
(str (serialize-impl font) "\n"))
@@ -154,9 +171,9 @@
154171
(binding [*out* os]
155172
(fipp/pprint font {:width 200})))))
156173

157-
(defn update-code [font key name f & args]
158-
(let [idx (coll/index-of #(= (:tag %) name) (get font key))]
159-
(assert (>= idx 0) (str "Can’t find " key " tag=" name ", got " (str/join ", " (map :name (get font key)))))
174+
(defn update-code [font key name-attr name f & args]
175+
(let [idx (coll/index-of #(= (get % name-attr) name) (get font key))]
176+
(assert (>= idx 0) (str "Can’t find " key " tag=" name ", got " (str/join ", " (map #(get % name-attr) (get font key)))))
160177
(apply update-in font [key idx :code] f args)))
161178

162179
(defn lines [s]
@@ -166,7 +183,7 @@
166183
(count (re-seq #"[^\s]+" s)))
167184

168185
(defn set-feature [font name feature]
169-
(let [idx (coll/index-of #(= (:name %) name) (:features font))]
186+
(let [idx (coll/index-of #(= (:tag %) name) (:features font))]
170187
(if (pos? idx)
171188
(do
172189
(println " replacing feature" name "with" (lines (:code feature)) "lines")

clojure/fira_code/main.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
(spacers/add-spacers ligas)
2929
(not-space/regen-not-space)
3030
(checks/widths))]
31-
(glyphs/save! path font')
32-
(println)))
31+
(glyphs/save! (or (second args) path) font')
32+
(println)))

clojure/fira_code/not_space.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
(map :glyphname)
1111
(sort))]
1212
(println " regenerated NotSpace:" (count not-spaces) "glyphs")
13-
(glyphs/update-code font :classes "NotSpace" (constantly (str/join " " not-spaces)))))
13+
(glyphs/update-code font :classes :name "NotSpace" (constantly (str/join " " not-spaces)))))

features/cv01.fea

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# alternate lowercase a
1+
### Alternate lowercase a
22

33
sub a by a.cv01;
44
sub aacute by aacute.cv01;

features/cv02.fea

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# single storey lowercase g
1+
### Single storey lowercase g
22

33
sub g by g.cv02;
44
sub gbreve by gbreve.cv02;

features/cv03.fea

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# lowercase I without any horizontal decorations
1+
### Lowercase I without any horizontal decorations
22

33
sub i by i.cv03;
44
sub idotless by idotless.cv03;

features/cv04.fea

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# lowercase I with horizontal left line at the top
1+
### Lowercase I with horizontal left line at the top
22

33
sub i by i.cv04;
44
sub idotless by idotless.cv04;

0 commit comments

Comments
 (0)