]> de.git.xonotic.org Git - xonotic/mediasource.git/blobdiff - fonts/xolonium/tools/make-font.py
Update Xolonium sources to version 4.2
[xonotic/mediasource.git] / fonts / xolonium / tools / make-font.py
diff --git a/fonts/xolonium/tools/make-font.py b/fonts/xolonium/tools/make-font.py
new file mode 100755 (executable)
index 0000000..944390b
--- /dev/null
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+# Compiles font with FontForge.
+
+import re
+import sys
+import time
+import fontforge
+import htic
+
+
+# Read arguments
+SOURCE       = sys.argv[1] # *.sfd
+COMMON       = sys.argv[2] # *.sfd
+FEATURES     = sys.argv[3] # *.fea
+INSTRUCTIONS = sys.argv[4] # *.hti
+VERSION      = sys.argv[5] # [0-9].[0-9]
+TARGET       = sys.argv[6] # *.otf|*.ttf
+
+
+# Set constants
+EXT   = TARGET.split(".")[-1]
+MAJOR = int(VERSION[0])
+MINOR = int(VERSION[2])
+DATE  = time.strftime("%Y-%m-%d")
+
+
+# Prepare font
+font = fontforge.open(SOURCE)
+font.mergeFonts(COMMON)
+font.mergeFeature(FEATURES)
+font.version = VERSION
+font.appendSFNTName("English (US)", "UniqueID",
+       "{} {} {}".format(font.fullname, font.version, DATE))
+
+
+# Generate font
+if EXT == "otf":
+
+       # Unlink composite glyphs
+       for glyph in font.glyphs():
+               if glyph.references:
+                       glyph.manualHints = True
+                       glyph.unlinkRef()
+                       glyph.removeOverlap()
+                       glyph.round()
+                       glyph.simplify()
+                       glyph.correctDirection()
+                       glyph.canonicalStart()
+                       glyph.canonicalContours()
+
+       # Remove glyphs that are only required for TrueType
+       font['.null'].clear()
+       font['nonmarkingreturn'].clear()
+       for glyph in font.glyphs():
+               if glyph.glyphname.endswith(".tt"):
+                       glyph.clear()
+
+       # Generate
+       font.generate(TARGET, flags=("opentype", "old-kern", "dummy-dsig"))
+
+elif EXT == "ttf":
+
+       # Convert to quadratic outlines
+       font.layers['Fore'].is_quadratic = True
+
+       for glyph in font.glyphs():
+               # If available, use custom quadratic
+               # outlines from background layer
+               if not glyph.background.isEmpty():
+                       glyph.foreground = glyph.background
+
+               # Remove .tt mark from TrueType exclusive glyphs
+               if glyph.glyphname.endswith(".tt"):
+                       glyph.glyphname = glyph.glyphname[:-3]
+
+       # Add instructions
+       htic.toFontforge(INSTRUCTIONS, font)
+
+       # Generate
+       font.generate(TARGET, flags=("opentype", "old-kern", "dummy-dsig"))
+
+
+# Done
+font.close()