[smc-discuss] [Git][smc/meera-tamil][master] Update build scripts

Santhosh Thottingal gitlab at mg.gitlab.com
Fri Mar 25 21:53:04 PDT 2016


Santhosh Thottingal pushed to branch master at SMC / Meera-Tamil


Commits:
24247a60 by Santhosh Thottingal at 2016-03-26T10:22:22+05:30
Update build scripts

- - - - -


5 changed files:

- Makefile
- README.md
- MeeraTamil.fea → features/features.fea
- tools/build.py
- + tools/requirements.txt


Changes:

=====================================
Makefile
=====================================
--- a/Makefile
+++ b/Makefile
@@ -2,24 +2,17 @@
 
 fontpath=/usr/share/fonts/truetype/malayalam
 fonts=MeeraTamil
-feature=MeeraTamil.fea
+feature=features/features.fea
 PY=python2.7
 buildscript=tools/build.py
+version=2.0
 default: compile
-all: compile webfonts
+all: compile
 
-compile:
+compile: clean
 	@for font in `echo ${fonts}`;do \
 		echo "Generating $$font.ttf";\
-		$(PY) $(buildscript) $$font.sfd $(feature);\
-	done;
-
-webfonts:compile
-	@echo "Generating webfonts";
-	@for font in `echo ${fonts}`;do \
-		sfntly -w $${font}.ttf $${font}.woff;\
-		sfntly -e -x $${font}.ttf $${font}.eot;\
-		[ -x `which woff2_compress` ] && woff2_compress $${font}.ttf;\
+		$(PY) $(buildscript) $$font.sfd $(feature) $(version);\
 	done;
 
 install: compile
@@ -33,3 +26,9 @@ test: compile
 		echo "Testing font $${font}";\
 		hb-view $${font}.ttf --text-file tests/tests.txt --output-file tests/$${font}.pdf;\
 	done;
+dist:
+	@for font in `echo ${fonts}`;do \
+		cp $${font}.ttf ttf/$${font}.ttf;\
+	done;
+clean:
+	@rm -rf *.ttf *.sfd-* *.woff* *.eot
\ No newline at end of file


=====================================
README.md
=====================================
--- a/README.md
+++ b/README.md
@@ -16,3 +16,14 @@ License:
 
 This Font is licensed under the SIL Open Font License, Version 1.1. See http://scripts.sil.org/OFL
 
+Building from source
+--------------------
+1. Install fontforge and python-fontforge
+2. Install the python libraries required for build script:
+    ```
+    pip install -r tools/requirements.txt
+    ```
+3. Build the ttf, woff, woff2 files: 
+   ``` 
+   make
+   ```
\ No newline at end of file


=====================================
MeeraTamil.fea → features/features.fea
=====================================
--- a/MeeraTamil.fea
+++ b/features/features.fea


=====================================
tools/build.py
=====================================
--- a/tools/build.py
+++ b/tools/build.py
@@ -1,22 +1,143 @@
+#!/usr/bin/python
+# coding=utf-8
+#
+# Font build utility
+#
+
 import sys
 import time
+import os
 import fontforge
-font = fontforge.open(sys.argv[1])
+import psMat
+from tempfile import mkstemp
+from fontTools.ttLib import TTFont
+from fontTools.ttx import makeOutputFileName
+
+
+def flattenNestedReferences(font, ref, new_transform=(1, 0, 0, 1, 0, 0)):
+    """Flattens nested references by replacing them with the ultimate reference
+    and applying any transformation matrices involved, so that the final font
+    has only simple composite glyphs. This to work around what seems to be an
+    Apple bug that results in ignoring transformation matrix of nested
+    references."""
+
+    name = ref[0]
+    transform = ref[1]
+    glyph = font[name]
+    new_ref = []
+    if glyph.references and glyph.foreground.isEmpty():
+        for nested_ref in glyph.references:
+            for i in flattenNestedReferences(font, nested_ref, transform):
+                matrix = psMat.compose(i[1], new_transform)
+                new_ref.append((i[0], matrix))
+    else:
+        matrix = psMat.compose(transform, new_transform)
+        new_ref.append((name, matrix))
+
+    return new_ref
+
+
+def validateGlyphs(font):
+    """Fixes some common FontForge validation warnings, currently handles:
+        * wrong direction
+        * flipped references
+    In addition to flattening nested references."""
+
+    wrong_dir = 0x8
+    flipped_ref = 0x10
+    for glyph in font.glyphs():
+        state = glyph.validate(True)
+        refs = []
+
+        if state & flipped_ref:
+            glyph.unlinkRef()
+            glyph.correctDirection()
+        if state & wrong_dir:
+            glyph.correctDirection()
+
+        for ref in glyph.references:
+            for i in flattenNestedReferences(font, ref):
+                refs.append(i)
+        if refs:
+            glyph.references = refs
+
+infont = sys.argv[1]
+font = fontforge.open(infont)
+outfont = infont.replace(".sfd", ".ttf")
+tmpfont = mkstemp(suffix=os.path.basename(outfont))[1]
+
 # Remove all GSUB lookups
 for lookup in font.gsub_lookups:
-	font.removeLookup(lookup)
+    font.removeLookup(lookup)
 
-# Remove all GPOS lookups 
+# Remove all GPOS lookups
 for lookup in font.gpos_lookups:
-	font.removeLookup(lookup)        
+    font.removeLookup(lookup)
 
-# Merge the new featurefile 
+# Merge the new featurefile
 font.mergeFeature(sys.argv[2])
-font.version = time.strftime('%Y%m%d')
+font.version = sys.argv[3]
+font.appendSFNTName('English (US)', 'Version',
+                    sys.argv[3] + '.0+' + time.strftime('%Y%m%d'))
 font.selection.all()
-#font.simplify()
-#font.addExtrema()
-font.round()
-font.autoHint()
-font.generate(sys.argv[1].replace(".sfd",".ttf"), flags=("omit-instructions", "round", "opentype"))
-font.close() 
+font.addExtrema()
+font.removeOverlap()
+font.correctReferences()
+font.simplify()
+font.selection.none()
+# fix some common font issues
+validateGlyphs(font)
+font.generate(tmpfont, flags=("omit-instructions", "round", "opentype", "no-hints"))
+font.close()
+# now open in fontTools
+font = TTFont(tmpfont, recalcBBoxes=0)
+
+# our 'name' table is a bit bulky, and of almost no use in for web fonts,
+# so we strip all unnecessary entries.
+name = font['name']
+names = []
+for record in name.names:
+    platID = record.platformID
+    langID = record.langID
+    nameID = record.nameID
+
+    # we keep only en_US entries in Windows and Mac platform id, every
+    # thing else is dropped
+    if (platID == 1 and langID == 0) or (platID == 3 and langID == 1033):
+        if nameID == 13:
+            # the full OFL text is too much, replace it with a simple
+            # string
+            if platID == 3:
+                # MS strings are UTF-16 encoded
+                text = 'OFL v1.1'.encode('utf_16_be')
+            else:
+                text = 'OFL v1.1'
+            record.string = text
+            names.append(record)
+        # keep every thing else except Descriptor, Sample Text
+        elif nameID not in (10, 19):
+            names.append(record)
+
+name.names = names
+
+# FFTM is FontForge specific, remove it
+del(font['FFTM'])
+# force compiling GPOS/GSUB tables by fontTools, saves few tens of KBs
+for tag in ('GPOS', 'GSUB'):
+    font[tag].compile(font)
+
+font.save(outfont)
+# Generate WOFF
+woffFileName = makeOutputFileName(infont, outputDir=None, extension='.woff')
+print("Processing %s => %s" % (infont, woffFileName))
+font.flavor = "woff"
+font.save(woffFileName, reorderTables=False)
+# Generate WOFF2
+woff2FileName = makeOutputFileName(infont, outputDir=None, extension='.woff2')
+print("Processing %s => %s" % (infont, woff2FileName))
+font.flavor = "woff2"
+font.save(woff2FileName, reorderTables=False)
+
+font.close()
+
+os.remove(tmpfont)


=====================================
tools/requirements.txt
=====================================
--- /dev/null
+++ b/tools/requirements.txt
@@ -0,0 +1,2 @@
+git+https://github.com/google/brotli@v0.3.0#egg=Brotli
+fonttools >= 3.0
\ No newline at end of file



View it on GitLab: https://gitlab.com/smc/meera-tamil/commit/24247a602dfe3e4fc02abe85b77caf5ad374bbad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.smc.org.in/pipermail/discuss-smc.org.in/attachments/20160326/3041594a/attachment.html>


More information about the discuss mailing list