migrated gen_calt to parse_glyphs

pull/671/head
Nikita Prokopov 2018-09-30 17:43:03 +03:00
rodzic 24daff0fca
commit 76d08bbb6c
5 zmienionych plików z 33 dodań i 53 usunięć

3
.gitignore vendored
Wyświetl plik

@ -3,4 +3,5 @@ FiraCode_liga.glyphs
FiraCode_mess.glyphs
target
clojure/*.edn
FiraCode\ (Autosaved).glyphs
FiraCode\ (Autosaved).glyphs
.cpcache

Wyświetl plik

@ -1,34 +1,7 @@
#^:shebang '[
exec java -cp "$HOME/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar" clojure.main "$0" "$@"]
(require '[clojure.string :as str])
(def file "FiraCode.glyphs")
(println "Looking for ligatures in" file "...\n")
;; [ ["dash" "greater" "greater"] ... ]
(def ligas (->> (slurp file)
(re-seq #"glyphname = ([a-z_]+)\.liga;")
(map second)
set
(mapv #(vec (str/split % #"_")))))
; (def ligas
; [ ["hyphen" "greater"]
; ["greater" "equal"]
; ["equal" "greater"]
; ["hyphen" "hyphen" "greater"]
; ["equal" "equal" "greater"]
; ["greater" "hyphen"]])
; (def ligas
; [ ["slash" "asterisk"]
; ["slash" "asterisk" "asterisk"]
; ["asterisk" "asterisk"]
; ["asterisk" "asterisk" "asterisk"]])
(ns gen-calt
(:require
[clojure.string :as str]
[parse-glyphs :as parse]))
(def ignores
{ ["slash" "asterisk"]
@ -50,7 +23,6 @@
(str
" ignore sub slash asterisk' asterisk asterisk;\n"
" ignore sub asterisk' asterisk asterisk slash;\n")
})
(defn liga->rule
@ -92,16 +64,27 @@
" sub 1' 2 3 4 by LIG;\n"
" } 1_2_3_4;")
#"\d" {"1" a "2" b "3" c "4" d}))))
(println "### start of generated calt\n")
(println (->> ligas (sort-by count) (reverse) (map liga->rule) (str/join "\n\n")))
(println "\n### end of generated calt\n")
(defn -main [& args]
(let [file (or (first args) "FiraCode.glyphs")
_ (println "Looking for ligatures in" file "...\n")
font (parse/parse (slurp file))
ligas (for [g (:glyphs font)
:let [name (:glyphname g)]
:when (str/ends-with? name ".liga")
:let [[_ liga] (re-matches #"([a-z_]+)\.liga" name)]]
(str/split liga #"_"))] ;; [ ["dash" "greater" "greater"] ... ]
(println "Total ligatures count:" (count ligas))
(println " " (->> ligas
(group-by count)
(sort-by first)
(map (fn [[k v]] (str (count v) (case k 2 " pairs", 3 " triples", 4 " quadruples"))))
(str/join ", ")))
(println)
(println "### start of generated calt\n")
(println (->> ligas (sort-by count) (reverse) (map liga->rule) (str/join "\n\n")))
(println "\n### end of generated calt\n")
(println "Total ligatures count:" (count ligas))
(println " " (->> ligas
(group-by count)
(sort-by first)
(map (fn [[k v]] (str (count v) (case k 2 " pairs", 3 " triples", 4 " quadruples"))))
(str/join ", ")))
(println)))
;; (-main)

Wyświetl plik

@ -103,8 +103,8 @@
(defn layer [l]
{ :id (case (:layerId l)
(:Regular weights) "Regular"
(:Bold weights) "Bold"
((:Regular weights)) "Regular"
((:Bold weights)) "Bold"
(:layerId l))
:width (:width l) })

3
deps.edn 100644
Wyświetl plik

@ -0,0 +1,3 @@
{:paths ["clojure"]
:deps {org.clojure/clojure {:mvn/version "1.10.0-alpha8"}
fipp/fipp {:mvn/version "0.6.12"}}}

Wyświetl plik

@ -1,7 +0,0 @@
(defproject org.example/sample "1.0.0-SNAPSHOT"
:dependencies [
[org.clojure/clojure "1.10.0-alpha8"]
[fipp "0.6.12"]
]
:source-paths ["clojure"]
)