From ab02e4ff0c6b286c81bedaff7bf33808a38119d0 Mon Sep 17 00:00:00 2001
From: David Fifield <fifield@eecs.berkeley.edu>
Date: Tue, 27 May 2014 18:11:40 -0700
Subject: [PATCH] Build WOFF files.

This is just a mechanical replacement of "woff" for "ttf" in the TTF
targets.
---
 font/Makefile         | 108 +++++++++++++++++++++++++++++++++++++++--
 font/woffsrc/Makefile | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 237 insertions(+), 3 deletions(-)
 create mode 100644 font/woffsrc/Makefile

diff --git a/font/Makefile b/font/Makefile
index 2037f6e..0b463aa 100644
--- a/font/Makefile
+++ b/font/Makefile
@@ -41,6 +41,7 @@ CONSOLEDEST = $(DESTDIR)/usr/share/consolefonts
 FONTDEST    = $(DESTDIR)/usr/share/fonts
 PCFDEST     = $(FONTDEST)/X11/misc
 TTFDEST     = $(FONTDEST)/truetype/unifont
+# WOFFDEST    = $(FONTDEST)/woff/unifont
 #
 # destination directory for compiled fonts
 #
@@ -105,20 +106,25 @@ COMBINING = plane00/bmp-combining.txt
 
 UPPER_COMBINING = plane0[0-E]/*combining*.txt
 
-VPATH = plane00 ttfsrc
+VPATH = plane00 ttfsrc woffsrc
 
 #
 # Location of  TTF source directory, where TTF font is built.
 #
 TTFSRC = ttfsrc
 
+#
+# Location of  WOFF source directory, where WOFF font is built.
+#
+WOFFSRC = woffsrc
+
 
 all: compiled
 
 compiled: $(UNIFILES) $(COMBINING) $(UPPER_FILES) $(UPPER_COMBINING)
 	make compiled-files
 
-compiled-files: pcf psf bmp ttf csurttf upperttf uppercsurttf bigpic coverage
+compiled-files: pcf psf bmp ttf csurttf upperttf uppercsurttf woff csurwoff upperwoff uppercsurwoff bigpic coverage
 	install -p index.html $(COMPILED_DIR)/index.html
 
 #
@@ -347,6 +353,85 @@ uppercsurttf:
 		$(COMPILED_DIR)/unifont_upper_csur-$(VERSION).ttf 
 	gzip -f -9 $(COMPILED_DIR)/unifont_upper_csur-$(VERSION).sfd 
 
+woff:
+	# First copy the ordinary version, to make a WOFF font.
+	install -p \
+		$(COMPILED_DIR)/unifont-$(VERSION).hex \
+		$(WOFFSRC)/unifont.hex
+	install -p \
+		$(HEXDIR)/bmp-combining.txt \
+		$(WOFFSRC)/combining.txt
+	cd $(WOFFSRC) ; \
+	   make FONTFILE="unifont" COMBINING="combining" \
+		FONTNAME="Unifont" PSNAME="Unifont"
+	mv $(WOFFSRC)/unifont.sfd $(COMPILED_DIR)/unifont-$(VERSION).sfd 
+	mv $(WOFFSRC)/unifont.woff \
+		$(COMPILED_DIR)/unifont-$(VERSION).woff 
+	# Second copy unifont_sample.bdf, to make an SBIT font.
+	install -p \
+		$(COMPILED_DIR)/unifont_sample-$(VERSION).bdf \
+		$(WOFFSRC)/unifont_sample.bdf
+	cd $(WOFFSRC) ; \
+	   make sbit FONTFILE="unifont_sample" COMBINING="" \
+		FONTNAME="Unifont Sample" PSNAME="UnifontSample"
+	mv $(WOFFSRC)/unifont_sample.woff \
+		$(COMPILED_DIR)/unifont_sample-$(VERSION).woff 
+	gzip -f -9 $(COMPILED_DIR)/unifont-$(VERSION).sfd 
+
+#
+# Now build the ConScript Unicode Registry PUA font.
+#
+csurwoff:
+	install -p \
+		$(COMPILED_DIR)/unifont_csur-$(VERSION).hex \
+		$(WOFFSRC)/unifont_csur.hex
+	sort -u plane00csur/csur-combining.txt $(HEXDIR)/bmp-combining.txt \
+		> $(WOFFSRC)/combining_csur.txt
+	cd $(WOFFSRC) ; \
+	   make outline FONTFILE="unifont_csur" COMBINING="combining_csur" \
+		FONTNAME="Unifont CSUR" PSNAME="UnifontCSUR"
+	mv $(WOFFSRC)/unifont_csur.sfd \
+		$(COMPILED_DIR)/unifont_csur-$(VERSION).sfd 
+	mv $(WOFFSRC)/unifont_csur.woff \
+		$(COMPILED_DIR)/unifont_csur-$(VERSION).woff 
+	gzip -f -9 $(COMPILED_DIR)/unifont_csur-$(VERSION).sfd 
+
+#
+# Now build the ConScript Unicode Registry PUA font.
+#
+upperwoff:
+	install -p \
+		$(COMPILED_DIR)/unifont_upper-$(VERSION).hex \
+		$(WOFFSRC)/unifont_upper.hex
+	sort -u $(UPPER_COMBINING) > $(WOFFSRC)/combining_upper.txt
+	cd $(WOFFSRC) ; \
+	   make outline FONTFILE="unifont_upper" COMBINING="combining_upper" \
+		FONTNAME="Unifont Upper" PSNAME="UnifontUpper"
+	mv $(WOFFSRC)/unifont_upper.sfd \
+		$(COMPILED_DIR)/unifont_upper-$(VERSION).sfd 
+	mv $(WOFFSRC)/unifont_upper.woff \
+		$(COMPILED_DIR)/unifont_upper-$(VERSION).woff 
+	gzip -f -9 $(COMPILED_DIR)/unifont_upper-$(VERSION).sfd 
+
+
+#
+# ConScript Unicode Registry PUA font beyond Plane 0.
+#
+uppercsurwoff:
+	install -p \
+		$(COMPILED_DIR)/unifont_upper_csur-$(VERSION).hex \
+		$(WOFFSRC)/unifont_upper_csur.hex
+	sort -u plane0[1-F]csur/*combining*.txt \
+		> $(WOFFSRC)/combining_upper_csur.txt
+	cd $(WOFFSRC) ; \
+	   make outline FONTFILE="unifont_upper_csur" COMBINING="combining_upper_csur" \
+		FONTNAME="Unifont Upper CSUR" PSNAME="UnifontUpperCSUR"
+	mv $(WOFFSRC)/unifont_upper_csur.sfd \
+		$(COMPILED_DIR)/unifont_upper_csur-$(VERSION).sfd 
+	mv $(WOFFSRC)/unifont_upper_csur.woff \
+		$(COMPILED_DIR)/unifont_upper_csur-$(VERSION).woff 
+	gzip -f -9 $(COMPILED_DIR)/unifont_upper_csur-$(VERSION).sfd 
+
 #
 #
 # Copy the newly created files from $(COMPILED_DIR) to the precompiled/
@@ -361,22 +446,27 @@ precompiled: all
 	                  $(COMPILED_DIR)/unifont-$(VERSION).pcf.gz \
 	                  $(COMPILED_DIR)/Unifont-APL8x16-$(VERSION).psf.gz \
 	                  $(COMPILED_DIR)/unifont-$(VERSION).ttf \
+	                  $(COMPILED_DIR)/unifont-$(VERSION).woff \
 	                  $(COMPILED_DIR)/unifont_csur-$(VERSION).pcf.gz \
 	                  $(COMPILED_DIR)/unifont_csur-$(VERSION).ttf \
+	                  $(COMPILED_DIR)/unifont_csur-$(VERSION).woff \
 	                  $(COMPILED_DIR)/unifont_sample-$(VERSION).hex \
 	                  $(COMPILED_DIR)/unifont_sample-$(VERSION).bdf.gz \
 	                  $(COMPILED_DIR)/unifont_sample-$(VERSION).pcf.gz \
 	                  $(COMPILED_DIR)/unifont_sample-$(VERSION).ttf \
+	                  $(COMPILED_DIR)/unifont_sample-$(VERSION).woff \
 	                  $(COMPILED_DIR)/coverage.txt \
 	                  $(COMPILED_DIR)/unifont-$(VERSION).bmp \
 	                  $(COMPILED_DIR)/unifont_upper-$(VERSION).hex \
 	                  $(COMPILED_DIR)/unifont_upper-$(VERSION).bdf.gz \
 	                  $(COMPILED_DIR)/unifont_upper-$(VERSION).pcf.gz \
 	                  $(COMPILED_DIR)/unifont_upper-$(VERSION).ttf \
+	                  $(COMPILED_DIR)/unifont_upper-$(VERSION).woff \
 	                  $(COMPILED_DIR)/unifont_upper_csur-$(VERSION).hex \
 	                  $(COMPILED_DIR)/unifont_upper_csur-$(VERSION).bdf.gz \
 	                  $(COMPILED_DIR)/unifont_upper_csur-$(VERSION).pcf.gz \
 	                  $(COMPILED_DIR)/unifont_upper_csur-$(VERSION).ttf \
+	                  $(COMPILED_DIR)/unifont_upper_csur-$(VERSION).woff \
 	   precompiled
 
 #
@@ -404,6 +494,7 @@ install:
 	$(INSTALL) -m0755 -d $(CONSOLEDEST)
 	$(INSTALL) -m0755 -d $(PCFDEST)
 	$(INSTALL) -m0755 -d $(TTFDEST)
+	# $(INSTALL) -m0755 -d $(WOFFDEST)
 	if [ ! -d $(COMPILED_DIR) ] ; then \
 	   $(INSTALL) -m0644 -p $(CURDIR)/precompiled/Unifont-APL8x16-$(VERSION).psf.gz $(CONSOLEDEST)/Unifont-APL8x16.psf.gz ; \
 	   $(INSTALL) -m0644 -p $(CURDIR)/precompiled/unifont-$(VERSION).pcf.gz $(PCFDEST)/unifont.pcf.gz ; \
@@ -414,6 +505,11 @@ install:
 	   $(INSTALL) -m0644 -p $(CURDIR)/precompiled/unifont_csur-$(VERSION).ttf        $(TTFDEST)/unifont_csur.ttf ; \
 	   $(INSTALL) -m0644 -p $(CURDIR)/precompiled/unifont_upper-$(VERSION).ttf       $(TTFDEST)/unifont_upper.ttf ; \
 	   $(INSTALL) -m0644 -p $(CURDIR)/precompiled/unifont_upper_csur-$(VERSION).ttf  $(TTFDEST)/unifont_upper_csur.ttf ; \
+	   # $(INSTALL) -m0644 -p $(CURDIR)/precompiled/unifont-$(VERSION).woff             $(TTFDEST)/unifont.woff ; \
+	   # $(INSTALL) -m0644 -p $(CURDIR)/precompiled/unifont_sample-$(VERSION).woff      $(TTFDEST)/unifont_sample.woff ; \
+	   # $(INSTALL) -m0644 -p $(CURDIR)/precompiled/unifont_csur-$(VERSION).woff        $(TTFDEST)/unifont_csur.woff ; \
+	   # $(INSTALL) -m0644 -p $(CURDIR)/precompiled/unifont_upper-$(VERSION).woff       $(TTFDEST)/unifont_upper.woff ; \
+	   # $(INSTALL) -m0644 -p $(CURDIR)/precompiled/unifont_upper_csur-$(VERSION).woff  $(TTFDEST)/unifont_upper_csur.woff ; \
 	else \
 	   $(INSTALL) -m0644 -p $(CURDIR)/$(COMPILED_DIR)/Unifont-APL8x16-$(VERSION).psf.gz $(CONSOLEDEST)/Unifont-APL8x16.psf.gz ; \
 	   $(INSTALL) -m0644 -p $(CURDIR)/$(COMPILED_DIR)/unifont-$(VERSION).pcf.gz $(PCFDEST)/unifont.pcf.gz ; \
@@ -424,6 +520,11 @@ install:
 	   $(INSTALL) -m0644 -p $(CURDIR)/$(COMPILED_DIR)/unifont_csur-$(VERSION).ttf         $(TTFDEST)/unifont_csur.ttf ; \
 	   $(INSTALL) -m0644 -p $(CURDIR)/$(COMPILED_DIR)/unifont_upper-$(VERSION).ttf        $(TTFDEST)/unifont_upper.ttf ; \
 	   $(INSTALL) -m0644 -p $(CURDIR)/$(COMPILED_DIR)/unifont_upper_csur-$(VERSION).ttf   $(TTFDEST)/unifont_upper_csur.ttf ; \
+	   # $(INSTALL) -m0644 -p $(CURDIR)/$(COMPILED_DIR)/unifont-$(VERSION).woff              $(TTFDEST)/unifont.woff ; \
+	   # $(INSTALL) -m0644 -p $(CURDIR)/$(COMPILED_DIR)/unifont_sample-$(VERSION).woff       $(TTFDEST)/unifont_sample.woff ; \
+	   # $(INSTALL) -m0644 -p $(CURDIR)/$(COMPILED_DIR)/unifont_csur-$(VERSION).woff         $(TTFDEST)/unifont_csur.woff ; \
+	   # $(INSTALL) -m0644 -p $(CURDIR)/$(COMPILED_DIR)/unifont_upper-$(VERSION).woff        $(TTFDEST)/unifont_upper.woff ; \
+	   # $(INSTALL) -m0644 -p $(CURDIR)/$(COMPILED_DIR)/unifont_upper_csur-$(VERSION).woff   $(TTFDEST)/unifont_upper_csur.woff ; \
 	fi
 
 clean:
@@ -440,8 +541,9 @@ clean:
 distclean:
 	\rm -rf $(COMPILED_DIR)
 	$(MAKE) -C ttfsrc distclean
+	$(MAKE) -C woffsrc distclean
 	\rm -f *~
 	\rm -rf .DS* ._.DS*
 
-.PHONY: all hex bdf pcf coverage pagecount bmp bigpic csurttf upper ttf \
+.PHONY: all hex bdf pcf coverage pagecount bmp bigpic csurttf upper ttf csurwoff woff \
 	precompiled install clean distclean 
diff --git a/font/woffsrc/Makefile b/font/woffsrc/Makefile
new file mode 100644
index 0000000..100414f
--- /dev/null
+++ b/font/woffsrc/Makefile
@@ -0,0 +1,132 @@
+
+SHELL = /bin/sh
+
+BINDIR = ../../bin
+
+FONTFORGE = fontforge
+
+#
+# Default values, if not set on the command line when make is invoked:
+#
+# FONTFILE:  Prefix of the file name for input and output files.
+# FONTNAME:  Name of the font inside a WOFF file.
+# PSNAME:    PostScript name of the font inside a WOFF file; can't have spaces.
+# COMBINING: Prefix of the file containing a list of combining characters.
+#
+FONTFILE="unifont"
+FONTNAME="Unifont"
+PSNAME="Unifont"
+COMBINING="combining"
+
+#
+# The PostScript name of a font can't contain spaces--remove them.
+# Could also use bash string replacement if you know you're using bash.
+#
+
+COPYRIGHT = "Copyright (C) 2014 Roman Czyborra, Paul Hardy, Qianqian Fang, \
+Andrew Miller, et al.  \
+Licensed under the GNU General Public License; either version 2, or \
+(at your option) a later version, with the GNU Font Embedding Exception."
+
+VERSION = 6.3.20140214
+
+#
+# How to build unifont.woff from GNU Unifont's unifont.hex
+# -------------------------------------------------------
+# Based on ttfsrc/Makefile
+# Written by Luis Alejandro Gonzalez Miranda - http://www.lgm.cl/
+#
+
+#
+# 2008 - Paul Hardy created this Makefile from Luis' original
+# howto-build.sh and other bash scripts.  Those original scripts
+# don't appear in this archive, but they can be retrieved from
+# http://www.lgm.cl/.
+#
+
+# First of all, you need a Perl interpreter and FontForge.
+#
+# I don't remember all the steps, but I think it was as described by
+# this script.
+
+# This division is done only so the Simplify and RemoveOverlap
+# operations don't use up too much memory, and because
+# a .sfd generated from the whole unifont.hex would be too big to
+# process all at once.
+
+all: outline
+
+#
+# Commented out this operation on SFD file because not all applications
+# correctly interpreted the settings:
+#
+#	    SetFontNames("UnifontMedium", "GNU", "Unifont", "Medium", $(COPYRIGHT), "$(VERSION)"); \
+#
+# Convert unifont.hex to unifont.sfd as a single file, then generate
+# an outline TrueType font.
+#
+outline: $(FONTFILE).hex $(BINDIR)/hex2sfd
+	echo "Converting font as a single file."
+	$(BINDIR)/hex2sfd $(COMBINING).txt < $(FONTFILE).hex > $(FONTFILE).sfd
+	$(FONTFORGE) -lang=ff -c \
+	   'Open($$1); \
+	    SetFontNames("$(PSNAME)Medium", \
+		"$(FONTNAME)", "$(FONTNAME)", "Medium", \
+		$(COPYRIGHT), "$(VERSION)"); \
+	    SelectAll(); \
+	    RemoveOverlap(); \
+	    Simplify(64,1); \
+	    Save($$1);' \
+	   $(FONTFILE).sfd
+	echo "Converting .sfd font into .woff font"
+	$(FONTFORGE) -lang=ff -c \
+	   'Open($$1); \
+	    Generate($$2)' $(FONTFILE).sfd $(FONTFILE).woff
+	\rm -f $(FONTFILE).hex $(COMBINING).txt
+
+#
+# This fontforge script reads a BDF font file and generates an SBIT font file.
+# Author: written by Qianqian Fang, given to Paul Hardy in 2008.
+# The SBIT font is far smaller than the default outline TrueType font
+# and takes far less time to build than the outline font.  However, it
+# isn't scalable.  An SBIT font could be created and merged with the
+# larger WOFF font using fontforge, but I (Paul Hardy) haven't noticed
+# any degradation in the screen rendering of just the outline WOFF font
+# that this Makefile produces as its final product.  This is with
+# daily use of this Makefile's default TrueType font.
+#
+# This builds an SBIT font from the unifont_sample BDF font.  The
+# BDF font already contains font name, etc., so they don't need to
+# be set using SetFontNames; those parameters are left null so the
+# existing font's values will be preserved.  However, Fontforge
+# does not read the FONT_VERSION property so Paul Hardy added the
+# the SetFontNames call.
+#
+# Commented out because not all applications correctly interpreted
+# the settings:
+#
+#	    SetFontNames("","","","","","$(VERSION)"); \
+
+sbit: $(FONTFILE).bdf
+	$(FONTFORGE) -lang=ff -c \
+	   'New(); \
+	    Import($$1); \
+	    SetFontNames("","","","","","$(VERSION)"); \
+	    Generate($$2, "woff"); \
+	    Close()' \
+	   $(FONTFILE).bdf $(FONTFILE).woff
+	\rm -f $(FONTFILE).bdf
+
+#
+# Delete files copied into this directory to build WOFF fonts.
+#
+clean:
+	\rm -f *.bdf *.hex *.txt
+
+#
+# Delete files created within this directory while building WOFF fonts.
+#
+distclean: clean
+	\rm -f *.sfd *.woff
+
+.PHONY: all outline sbit clean distclean
-- 
2.0.0.rc2

