From d385788ff67d5afa3c703a753b3de0f5ece28563 Mon Sep 17 00:00:00 2001 From: Nikita Prokopov Date: Mon, 9 Sep 2019 17:15:37 +0300 Subject: [PATCH] Fixed glyphs file serializer to match Glyphs nuances --- FiraCode.glyphs | 6 ++---- clojure/glyphs.clj | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/FiraCode.glyphs b/FiraCode.glyphs index f0e97f9..aa5b6d0 100644 --- a/FiraCode.glyphs +++ b/FiraCode.glyphs @@ -1,7 +1,7 @@ { .appVersion = "1131"; DisplayStrings = ( -"flask\012Flask\012fiber\012fj\012/f_l.liga lflask\012Tla\012/f_t.liga" +"flask\012Flask\012fiber\012fji\012Tla" ); classes = ( { @@ -97,7 +97,6 @@ value = 1; { name = fsType; value = ( - ); }, { @@ -114923,7 +114922,6 @@ unitsPerEm = 1950; userData = { GSDimensionPlugin.Dimensions = { "B67F0F2D-EC95-4CB8-966E-23AE86958A69" = { - }; "BF448B58-7A35-489E-A1C9-12628F60690C" = { HH = 141; @@ -114947,4 +114945,4 @@ oV = 98; }; versionMajor = 1; versionMinor = 207; -} \ No newline at end of file +} diff --git a/clojure/glyphs.clj b/clojure/glyphs.clj index 8dfa2f7..fd36520 100755 --- a/clojure/glyphs.clj +++ b/clojure/glyphs.clj @@ -109,7 +109,7 @@ (def escape-re #"[\n\"\\]") -(defn serialize [form] +(defn- serialize-impl [form] (cond (string? form) (if (re-matches #"[a-zA-Z0-9._/]+" form) form @@ -118,14 +118,21 @@ (number? form) (str form) (instance? clojure.lang.MapEntry form) (str - (serialize (key form)) + (serialize-impl (key form)) " = " (if (= ".appVersion" (key form)) ;; https://github.com/googlefonts/glyphsLib/issues/209 (str \" (val form) \") - (serialize (val form))) + (serialize-impl (val form))) ";") - (sequential? form) (str "(\n" (str/join ",\n" (map serialize form)) "\n)") - (map? form) (str "{\n" (str/join "\n" (map serialize form)) "\n}"))) + (sequential? form) (if (empty? form) + "(\n)" + (str "(\n" (str/join ",\n" (map serialize-impl form)) "\n)")) + (map? form) (if (empty? form) + "{\n}" + (str "{\n" (str/join "\n" (map serialize-impl form)) "\n}")))) + +(defn serialize [font] + (str (serialize-impl font) "\n")) ; (-> (slurp "FiraCode.glyphs") parse serialize (->> (spit "FiraCode_saved.glyphs")))