summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/fonts/amiri/tools
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/doc/fonts/amiri/tools')
-rwxr-xr-xMaster/texmf-dist/doc/fonts/amiri/tools/build.py81
-rwxr-xr-xMaster/texmf-dist/doc/fonts/amiri/tools/runtest.py2
2 files changed, 50 insertions, 33 deletions
diff --git a/Master/texmf-dist/doc/fonts/amiri/tools/build.py b/Master/texmf-dist/doc/fonts/amiri/tools/build.py
index 58d37a2d107..6caa7290f63 100755
--- a/Master/texmf-dist/doc/fonts/amiri/tools/build.py
+++ b/Master/texmf-dist/doc/fonts/amiri/tools/build.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# coding=utf-8
#
# build.py - Amiri font build utility
@@ -13,20 +13,13 @@
# with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
-# minimum required FontForge version
-min_ff_version = "20120702"
-
script_lang = (('latn', ('dflt', 'TRK ')), ('arab', ('dflt', 'ARA ', 'URD ', 'SND ')), ('DFLT', ('dflt',)))
-import fontforge
-import psMat
+from sortsmill import ffcompat as fontforge
+from sortsmill import psMat
import sys
import os
-import getopt
-import math
-import unicodedata
from tempfile import mkstemp
-from fontTools.ttLib import TTFont
def genCSS(font, base):
"""Generates a CSS snippet for webfont usage based on:
@@ -130,6 +123,8 @@ def validateGlyphs(font):
if refs:
glyph.references = refs
+ glyph.round()
+
def setVersion(font, version):
font.version = "%07.3f" % float(version)
for name in font.sfnt_names:
@@ -196,9 +191,23 @@ def generateFont(font, outfile):
# fix some common font issues
validateGlyphs(font)
- font.generate(outfile, flags=flags)
+ tmpfile = mkstemp(suffix=os.path.basename(outfile))[1]
+ font.generate(tmpfile, flags=flags)
font.close()
+ # now open in fontTools
+ from fontTools.ttLib import TTFont
+ ftfont = TTFont(tmpfile)
+
+ # force compiling tables by fontTools, saves few tens of KBs
+ for tag in ftfont.keys():
+ if hasattr(ftfont[tag], "compile"):
+ ftfont[tag].compile(ftfont)
+
+ ftfont.save(outfile)
+ ftfont.close()
+ os.remove(tmpfile)
+
def drawOverUnderline(font, name, uni, glyphclass, pos, thickness, width):
glyph = font.createChar(uni, name)
glyph.width = 0
@@ -246,7 +255,7 @@ def makeOverUnderline(font, over=True, under=True, o_pos=None, u_pos=None):
markset = "%s %s" %(over and o_base.glyphname or "", under and u_base.glyphname or "")
- font.addMarkClass("OverUnderSet", markset)
+ font.addMarkSet("OverUnderSet", markset)
context_lookup_name = 'OverUnderLine'
font.addLookup(context_lookup_name, 'gsub_contextchain', ('OverUnderSet'), (('mark', script_lang),), font.gsub_lookups[-1])
@@ -314,6 +323,7 @@ def buildComposition(font, glyphnames):
font.addLookup("Latin composition", 'gsub_ligature', (), (('ccmp', script_lang),))
font.addLookupSubtable("Latin composition", "Latin composition subtable")
+ import unicodedata
for name in glyphnames:
u = fontforge.unicodeFromName(name)
if 0 < u < 0xfb00:
@@ -482,14 +492,15 @@ def mergeLatin(font, feafile, italic=False, glyphs=None, quran=False):
for name in digits:
pname = name + ".prop"
+ glyph = latinfont[pname]
+ glyph.glyphname = name + '.ltr.prop'
+ glyph.unicode = -1
upright.selection.select(pname)
upright.copy()
latinfont.createChar(-1, pname)
latinfont.selection.select(pname)
latinfont.paste()
- for name in digits:
- pname = name + ".prop"
rtl = latinfont.createChar(-1, name + ".rtl" + ".prop")
rtl.addReference(pname, italic)
rtl.useRefsMetrics(pname)
@@ -596,16 +607,17 @@ def makeWeb(infile, outfile):
font.removeGlyph(glyph)
break
- tmpfont = mkstemp(suffix=os.path.basename(outfile))[1]
- font.generate(tmpfont, flags=flags)
+ tmpfile = mkstemp(suffix=os.path.basename(outfile))[1]
+ font.generate(tmpfile, flags=flags)
font.close()
# now open in fontTools
- font = TTFont(tmpfont, recalcBBoxes=0)
+ from fontTools.ttLib import TTFont
+ ftfont = TTFont(tmpfile)
# 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']
+ name = ftfont['name']
names = []
for record in name.names:
platID = record.platformID
@@ -631,32 +643,36 @@ def makeWeb(infile, outfile):
name.names = names
- # FFTM is FontForge specific, remove it
- del(font['FFTM'])
+ # force compiling tables by fontTools, saves few tens of KBs
+ for tag in ftfont.keys():
+ if hasattr(ftfont[tag], "compile"):
+ ftfont[tag].compile(ftfont)
- # force compiling GPOS/GSUB tables by fontTools, saves few tens of KBs
- for tag in ('GPOS', 'GSUB'):
- font[tag].compile(font)
+ ftfont.save(outfile)
+ ftfont.close()
- font.save(outfile)
- font.close()
-
- os.remove(tmpfont)
+ os.remove(tmpfile)
def makeSlanted(infile, outfile, feafile, version, slant):
font = makeDesktop(infile, outfile, feafile, version, False, False)
# compute amout of skew, magic formula copied from fontforge sources
+ import math
skew = psMat.skew(-slant * math.pi/180.0)
+ # Remove Arabic math alphanumerics, they are upright-only.
+ font.selection.select(["ranges"], "u1EE00", "u1EEFF")
+ for glyph in font.selection.byGlyphs:
+ font.removeGlyph(glyph)
+
font.selection.all()
punct = ("period", "guillemotleft", "guillemotright", "braceleft", "bar",
"braceright", "bracketleft", "bracketright", "parenleft",
"parenright", "slash", "backslash", "brokenbar", "uni061F")
for name in punct:
- font.selection.select(("less", None), name)
+ font.selection.select(["less"], name)
font.transform(skew)
@@ -781,7 +797,7 @@ def makeQuran(infile, outfile, feafile, version):
def makeDesktop(infile, outfile, feafile, version, latin=True, generate=True):
font = fontforge.open(infile)
- font.encoding = "UnicodeBmp" # avoid a crash if compact was set
+ font.encoding = "UnicodeFull" # avoid a crash if compact was set
if version:
setVersion(font, version)
@@ -831,10 +847,11 @@ Options:
sys.exit(code)
if __name__ == "__main__":
- if fontforge.version() < min_ff_version:
- print "You need FontForge %s or newer to build Amiri fonts" %min_ff_version
- sys.exit(-1)
+ #if fontforge.version() < min_ff_version:
+ # print "You need FontForge %s or newer to build Amiri fonts" %min_ff_version
+ # sys.exit(-1)
+ import getopt
try:
opts, args = getopt.gnu_getopt(sys.argv[1:],
"h",
diff --git a/Master/texmf-dist/doc/fonts/amiri/tools/runtest.py b/Master/texmf-dist/doc/fonts/amiri/tools/runtest.py
index 86e663246cf..d82887993a9 100755
--- a/Master/texmf-dist/doc/fonts/amiri/tools/runtest.py
+++ b/Master/texmf-dist/doc/fonts/amiri/tools/runtest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
import sys
import os