Generate fontforge font files in makefile
authorPeter Colberg <peter@colberg.org>
Thu, 29 Oct 2015 23:48:49 +0000 (19:48 -0400)
committerPeter Colberg <peter@colberg.org>
Thu, 29 Oct 2015 23:48:49 +0000 (19:48 -0400)
Revise the script to directly read fontforge font files, which are
generated in the makefile. This permits overriding the fontforge path
during the build, and executing fontforge in parallel with make -j.

Avoid duplicating download URLs in the script, which ensures that the
script itself works without network access, e.g., when downloading the
data files on a developer machine with network access and executing the
script on a build machine without network access.

data/Makefile
data/charwidths.jl

index ebe67aec7e3a17b41b6861dcb9a717b58f534e3d..31e393497102386b699fc39c0aebd82d2a81faa1 100644 (file)
@@ -9,6 +9,7 @@ RUBY=ruby
 PERL=perl
 MAKE=make
 JULIA=julia
+FONTFORGE=fontforge
 CURLFLAGS = --retry 5 --location
 
 # use JuliaLang caching (https://github.com/staticfloat/cache.julialang.org)
@@ -25,14 +26,17 @@ utf8proc_data.c.new: data_generator.rb UnicodeData.txt GraphemeBreakProperty.txt
 # GNU Unifont version for font metric calculations:
 UNIFONT_VERSION=8.0.01
 
-unifont-$(UNIFONT_VERSION).ttf:
+unifont.ttf:
        $(CURL) $(CURLFLAGS) -o $@ $(URLCACHE)http://unifoundry.com/pub/unifont-$(UNIFONT_VERSION)/font-builds/unifont-$(UNIFONT_VERSION).ttf
 
-unifont_upper-$(UNIFONT_VERSION).ttf:
+unifont_upper.ttf:
        $(CURL) $(CURLFLAGS) -o $@ $(URLCACHE)http://unifoundry.com/pub/unifont-$(UNIFONT_VERSION)/font-builds/unifont_upper-$(UNIFONT_VERSION).ttf
 
-CharWidths.txt: charwidths.jl unifont-$(UNIFONT_VERSION).ttf unifont_upper-$(UNIFONT_VERSION).ttf EastAsianWidth.txt
-       UNIFONT_VERSION=$(UNIFONT_VERSION) $(JULIA) charwidths.jl > $@
+%.sfd: %.ttf
+       $(FONTFORGE) -lang=ff -c "Open(\"$<\");Save(\"$@\");Quit(0);"
+
+CharWidths.txt: charwidths.jl unifont.sfd unifont_upper.sfd EastAsianWidth.txt
+       $(JULIA) charwidths.jl > $@
 
 UnicodeData.txt:
        $(CURL) $(CURLFLAGS) -o $@ -O $(URLCACHE)http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
index 7b32a8239e0d4e0a9f8c1fce27c3f2b5cc7a8724..417483ca216d816cb279a12fe54da5377fd0ee9a 100644 (file)
@@ -51,12 +51,6 @@ end
 #############################################################################
 # Widths from GNU Unifont
 
-universion=get(ENV, "UNIFONT_VERSION", "7.0.06")
-for fontfile in ["unifont-$universion", "unifont_upper-$universion"]
-    isfile("$fontfile.ttf") || download("http://unifoundry.com/pub/unifont-$universion/font-builds/$fontfile.ttf", "$fontfile.ttf")
-    isfile("$fontfile.sfd") || run(`fontforge -lang=ff -c "Open(\"$fontfile.ttf\");Save(\"$fontfile.sfd\");Quit(0);"`)
-end
-
 #Read sfdfile for character widths
 function parsesfd(filename::String, CharWidths::Dict{Int,Int}=Dict{Int,Int}())
     state=:seekchar
@@ -87,15 +81,14 @@ function parsesfd(filename::String, CharWidths::Dict{Int,Int}=Dict{Int,Int}())
     end
     CharWidths
 end
-CharWidths=parsesfd("unifont-$universion.sfd", CharWidths)
-CharWidths=parsesfd("unifont_upper-$universion.sfd", CharWidths)
+CharWidths=parsesfd("unifont.sfd", CharWidths)
+CharWidths=parsesfd("unifont_upper.sfd", CharWidths)
 
 #############################################################################
 # Widths from UAX #11: East Asian Width
 #   .. these take precedence over the Unifont width for all codepoints
 #      listed explicitly as wide/full/narrow/half-width
 
-isfile("EastAsianWidth.txt") || download("http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt", "EastAsianWidth.txt")
 for line in readlines(open("EastAsianWidth.txt"))
     #Strip comments
     line[1] == '#' && continue