Skip to content

Commit

Permalink
Version 1.4.8 update
Browse files Browse the repository at this point in the history
Synchronize with fontTools v3.15.0.
Add fixMaxp() into Fixer class.
  • Loading branch information
Pal3love committed Aug 17, 2017
1 parent 8149ccc commit 7b8c9de
Show file tree
Hide file tree
Showing 34 changed files with 816 additions and 216 deletions.
2 changes: 1 addition & 1 deletion Package/otRebuilder/Dep/fontTools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

log = logging.getLogger(__name__)

version = __version__ = "3.14.0"
version = __version__ = "3.15.0"

__all__ = ["version", "log", "configLogger"]
21 changes: 21 additions & 0 deletions Package/otRebuilder/Dep/fontTools/cffLib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from fontTools.misc.py23 import *
from fontTools.misc import sstruct
from fontTools.misc import psCharStrings
from fontTools.misc.arrayTools import unionRect, intRect
from fontTools.misc.textTools import safeEval
from fontTools.ttLib import TTFont
from fontTools.ttLib.tables.otBase import OTTableWriter
Expand Down Expand Up @@ -101,6 +102,11 @@ def compile(self, file, otFont, isCFF2=None):
# use current 'major' value to determine output format
assert self.major in (1, 2), "Unknown CFF format"
isCFF2 = self.major == 2

if otFont.recalcBBoxes and not isCFF2:
for topDict in self.topDictIndex:
topDict.recalcFontBBox()

if not isCFF2:
strings = IndexedStrings()
else:
Expand Down Expand Up @@ -2313,6 +2319,21 @@ def decompileAllCharStrings(self, progress):
progress.increment(0) # update
i = i + 1

def recalcFontBBox(self):
fontBBox = None
for charString in self.CharStrings.values():
bounds = charString.calcBounds()
if bounds is not None:
if fontBBox is not None:
fontBBox = unionRect(fontBBox, bounds)
else:
fontBBox = bounds

if fontBBox is None:
self.FontBBox = self.defaults['FontBBox'][:]
else:
self.FontBBox = list(intRect(fontBBox))


class FontDict(BaseDict):
#
Expand Down
2 changes: 1 addition & 1 deletion Package/otRebuilder/Dep/fontTools/feaLib/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def next_(self):
else:
raise FeatureLibError("Expected '\"' to terminate string",
location)
raise FeatureLibError("Unexpected character: '%s'" % cur_char,
raise FeatureLibError("Unexpected character: %r" % cur_char,
location)

def scan_over_(self, valid):
Expand Down
6 changes: 6 additions & 0 deletions Package/otRebuilder/Dep/fontTools/misc/psCharStrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from fontTools.misc.fixedTools import fixedToFloat
from fontTools.pens.boundsPen import BoundsPen
import struct
import logging

Expand Down Expand Up @@ -977,6 +978,11 @@ def draw(self, pen):
extractor.execute(self)
self.width = extractor.width

def calcBounds(self):
boundsPen = BoundsPen(None)
self.draw(boundsPen)
return boundsPen.bounds

def check_program(self, program, isCFF2=False):
if isCFF2:
if self.program:
Expand Down
6 changes: 5 additions & 1 deletion Package/otRebuilder/Dep/fontTools/misc/testTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def parseXML(xmlSnippet):
class FakeFont:
def __init__(self, glyphs):
self.glyphOrder_ = glyphs
self.reverseGlyphOrderDict_ = {g:i for i,g in enumerate(glyphs)}
self.lazy = False
self.tables = {}

Expand All @@ -50,7 +51,7 @@ def get(self, tag, default=None):
return self.tables.get(tag, default)

def getGlyphID(self, name):
return self.glyphOrder_.index(name)
return self.reverseGlyphOrderDict_[name]

def getGlyphName(self, glyphID):
if glyphID < len(self.glyphOrder_):
Expand All @@ -61,6 +62,9 @@ def getGlyphName(self, glyphID):
def getGlyphOrder(self):
return self.glyphOrder_

def getReverseGlyphMap(self):
return self.reverseGlyphOrderDict_


class TestXMLReader_(object):
def __init__(self):
Expand Down
104 changes: 82 additions & 22 deletions Package/otRebuilder/Dep/fontTools/subset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@
set of OpenType layout feature tags that will be preserved.
Glyph variants used by the preserved features are added to the
specified subset glyph set. By default, 'calt', 'ccmp', 'clig', 'curs',
'kern', 'liga', 'locl', 'mark', 'mkmk', 'rclt', 'rlig' and all features
required for script shaping are preserved. To see the full list, try
'--layout-features=?'. Use '*' to keep all features.
'dnom', 'frac', 'kern', 'liga', 'locl', 'mark', 'mkmk', 'numr', 'rclt',
'rlig', 'rvrn', and all features required for script shaping are
preserved. To see the full list, try '--layout-features=?'.
Use '*' to keep all features.
Multiple --layout-features options can be provided if necessary.
Examples:
--layout-features+=onum,pnum,ss01
Expand Down Expand Up @@ -1182,8 +1183,7 @@ def subset_lookups(self, lookup_indices):

@_add_method(otTables.Lookup)
def collect_lookups(self):
return _uniq_sort(sum((st.collect_lookups() for st in self.SubTable
if st), []))
return sum((st.collect_lookups() for st in self.SubTable if st), [])

@_add_method(otTables.Lookup)
def may_have_non_1to1(self):
Expand Down Expand Up @@ -1219,6 +1219,7 @@ def neuter_lookups(self, lookup_indices):

@_add_method(otTables.LookupList)
def closure_lookups(self, lookup_indices):
"""Returns sorted index of all lookups reachable from lookup_indices."""
lookup_indices = _uniq_sort(lookup_indices)
recurse = lookup_indices
while True:
Expand All @@ -1234,6 +1235,7 @@ def closure_lookups(self, lookup_indices):

@_add_method(otTables.Feature)
def subset_lookups(self, lookup_indices):
""""Returns True if feature is non-empty afterwards."""
self.LookupListIndex = [l for l in self.LookupListIndex
if l in lookup_indices]
# Now map them.
Expand All @@ -1242,28 +1244,22 @@ def subset_lookups(self, lookup_indices):
self.LookupCount = len(self.LookupListIndex)
return self.LookupCount or self.FeatureParams

@_add_method(otTables.Feature)
def collect_lookups(self):
return self.LookupListIndex[:]

@_add_method(otTables.FeatureList)
def subset_lookups(self, lookup_indices):
"""Returns the indices of nonempty features."""
# Note: Never ever drop feature 'pref', even if it's empty.
# HarfBuzz chooses shaper for Khmer based on presence of this
# feature. See thread at:
# http://lists.freedesktop.org/archives/harfbuzz/2012-November/002660.html
feature_indices = [i for i,f in enumerate(self.FeatureRecord)
if (f.Feature.subset_lookups(lookup_indices) or
f.FeatureTag == 'pref')]
self.subset_features(feature_indices)
return feature_indices
return [i for i,f in enumerate(self.FeatureRecord)
if (f.Feature.subset_lookups(lookup_indices) or
f.FeatureTag == 'pref')]

@_add_method(otTables.FeatureList)
def collect_lookups(self, feature_indices):
return _uniq_sort(sum((self.FeatureRecord[i].Feature.collect_lookups()
for i in feature_indices
if i < self.FeatureCount), []))
return sum((self.FeatureRecord[i].Feature.LookupListIndex
for i in feature_indices
if i < self.FeatureCount), [])

@_add_method(otTables.FeatureList)
def subset_features(self, feature_indices):
Expand All @@ -1272,6 +1268,41 @@ def subset_features(self, feature_indices):
self.FeatureCount = len(self.FeatureRecord)
return bool(self.FeatureCount)

@_add_method(otTables.FeatureTableSubstitution)
def subset_lookups(self, lookup_indices):
"""Returns the indices of nonempty features."""
return [r.FeatureIndex for r in self.SubstitutionRecord
if r.Feature.subset_lookups(lookup_indices)]

@_add_method(otTables.FeatureVariations)
def subset_lookups(self, lookup_indices):
"""Returns the indices of nonempty features."""
return sum((f.FeatureTableSubstitution.subset_lookups(lookup_indices)
for f in self.FeatureVariationRecord), [])

@_add_method(otTables.FeatureVariations)
def collect_lookups(self, feature_indices):
return sum((r.Feature.LookupListIndex
for vr in self.FeatureVariationRecord
for r in vr.FeatureTableSubstitution.SubstitutionRecord
if r.FeatureIndex in feature_indices), [])

@_add_method(otTables.FeatureTableSubstitution)
def subset_features(self, feature_indices):
self.ensureDecompiled()
self.SubstitutionRecord = [r for r in self.SubstitutionRecord
if r.FeatureIndex in feature_indices]
self.SubstitutionCount = len(self.SubstitutionRecord)
return bool(self.SubstitutionCount)

@_add_method(otTables.FeatureVariations)
def subset_features(self, feature_indices):
self.ensureDecompiled()
self.FeaturVariationRecord = [r for r in self.FeatureVariationRecord
if r.FeatureTableSubstitution.subset_features(feature_indices)]
self.FeatureVariationCount = len(self.FeatureVariationRecord)
return bool(self.FeatureVariationCount)

@_add_method(otTables.DefaultLangSys,
otTables.LangSys)
def subset_features(self, feature_indices):
Expand All @@ -1295,9 +1326,10 @@ def collect_features(self):
return _uniq_sort(feature_indices)

@_add_method(otTables.Script)
def subset_features(self, feature_indices):
def subset_features(self, feature_indices, keepEmptyDefaultLangSys=False):
if(self.DefaultLangSys and
not self.DefaultLangSys.subset_features(feature_indices)):
not self.DefaultLangSys.subset_features(feature_indices) and
not keepEmptyDefaultLangSys):
self.DefaultLangSys = None
self.LangSysRecord = [l for l in self.LangSysRecord
if l.LangSys.subset_features(feature_indices)]
Expand All @@ -1313,8 +1345,10 @@ def collect_features(self):

@_add_method(otTables.ScriptList)
def subset_features(self, feature_indices, retain_empty):
# https://bugzilla.mozilla.org/show_bug.cgi?id=1331737#c32
self.ScriptRecord = [s for s in self.ScriptRecord
if s.Script.subset_features(feature_indices) or retain_empty]
if s.Script.subset_features(feature_indices, s.ScriptTag=='DFLT') or
retain_empty]
self.ScriptCount = len(self.ScriptRecord)
return bool(self.ScriptCount)

Expand Down Expand Up @@ -1352,6 +1386,9 @@ def closure_glyphs(self, s):
lookup_indices = self.table.FeatureList.collect_lookups(feature_indices)
else:
lookup_indices = []
if getattr(self.table, 'FeatureVariations', None):
lookup_indices += self.table.FeatureVariations.collect_lookups(feature_indices)
lookup_indices = _uniq_sort(lookup_indices)
if self.table.LookupList:
while True:
orig_glyphs = frozenset(s.glyphs)
Expand Down Expand Up @@ -1395,6 +1432,13 @@ def subset_lookups(self, lookup_indices):
feature_indices = self.table.FeatureList.subset_lookups(lookup_indices)
else:
feature_indices = []
if getattr(self.table, 'FeatureVariations', None):
feature_indices += self.table.FeatureVariations.subset_lookups(lookup_indices)
feature_indices = _uniq_sort(feature_indices)
if self.table.FeatureList:
self.table.FeatureList.subset_features(feature_indices)
if getattr(self.table, 'FeatureVariations', None):
self.table.FeatureVariations.subset_features(feature_indices)
if self.table.ScriptList:
self.table.ScriptList.subset_features(feature_indices, self.retain_empty_scripts())

Expand All @@ -1417,6 +1461,9 @@ def prune_lookups(self, remap=True):
lookup_indices = self.table.FeatureList.collect_lookups(feature_indices)
else:
lookup_indices = []
if getattr(self.table, 'FeatureVariations', None):
lookup_indices += self.table.FeatureVariations.collect_lookups(feature_indices)
lookup_indices = _uniq_sort(lookup_indices)
if self.table.LookupList:
lookup_indices = self.table.LookupList.closure_lookups(lookup_indices)
else:
Expand All @@ -1427,13 +1474,15 @@ def prune_lookups(self, remap=True):
self.neuter_lookups(lookup_indices)

@_add_method(ttLib.getTableClass('GSUB'),
ttLib.getTableClass('GPOS'))
ttLib.getTableClass('GPOS'))
def subset_feature_tags(self, feature_tags):
if self.table.FeatureList:
feature_indices = \
[i for i,f in enumerate(self.table.FeatureList.FeatureRecord)
if f.FeatureTag in feature_tags]
self.table.FeatureList.subset_features(feature_indices)
if getattr(self.table, 'FeatureVariations', None):
self.table.FeatureVariations.subset_features(feature_indices)
else:
feature_indices = []
if self.table.ScriptList:
Expand All @@ -1449,6 +1498,8 @@ def prune_features(self):
feature_indices = []
if self.table.FeatureList:
self.table.FeatureList.subset_features(feature_indices)
if getattr(self.table, 'FeatureVariations', None):
self.table.FeatureVariations.subset_features(feature_indices)
if self.table.ScriptList:
self.table.ScriptList.subset_features(feature_indices, self.retain_empty_scripts())

Expand Down Expand Up @@ -1511,6 +1562,7 @@ def prune_post_subset(self, options):
if not table.LookupList:
table.FeatureList = None


if table.FeatureList:
self.remove_redundant_langsys()
# Remove unreferenced features
Expand All @@ -1528,6 +1580,13 @@ def prune_post_subset(self, options):
#if table.ScriptList and not table.ScriptList.ScriptRecord:
# table.ScriptList = None

if not table.FeatureList and hasattr(table, 'FeatureVariations'):
table.FeatureVariations = None

if hasattr(table, 'FeatureVariations') and not table.FeatureVariations:
if table.Version == 0x00010001:
table.Version = 0x00010000

return True

@_add_method(ttLib.getTableClass('GDEF'))
Expand Down Expand Up @@ -2434,7 +2493,8 @@ class UnknownOptionError(OptionError): pass
# Based on HarfBuzz shapers
_layout_features_groups = {
# Default shaper
'common': ['ccmp', 'liga', 'locl', 'mark', 'mkmk', 'rlig'],
'common': ['rvrn', 'ccmp', 'liga', 'locl', 'mark', 'mkmk', 'rlig'],
'fractions': ['frac', 'numr', 'dnom'],
'horizontal': ['calt', 'clig', 'curs', 'kern', 'rclt'],
'vertical': ['valt', 'vert', 'vkrn', 'vpal', 'vrt2'],
'ltr': ['ltra', 'ltrm'],
Expand Down
8 changes: 5 additions & 3 deletions Package/otRebuilder/Dep/fontTools/ttLib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ def __init__(self, file=None, res_name_or_index=None,
If the recalcBBoxes argument is false, a number of things will *not*
be recalculated upon save/compile:
1) glyph bounding boxes
2) maxp font bounding box
3) hhea min/max values
1) 'glyf' glyph bounding boxes
2) 'CFF ' font bounding box
3) 'head' font bounding box
4) 'hhea' min/max values
5) 'vhea' min/max values
(1) is needed for certain kinds of CJK fonts (ask Werner Lemberg ;-).
Additionally, upon importing an TTX file, this option cause glyphs
to be compiled right away. This should reduce memory consumption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def toXML(self, writer, axisTags):
for axis in axisTags:
value = self.axes.get(axis)
if value is not None:
minValue, value, maxValue = value
minValue, value, maxValue = (float(v) for v in value)
defaultMinValue = min(value, 0.0) # -0.3 --> -0.3; 0.7 --> 0.0
defaultMaxValue = max(value, 0.0) # -0.3 --> 0.0; 0.7 --> 0.7
if minValue == defaultMinValue and maxValue == defaultMaxValue:
Expand Down
1 change: 1 addition & 0 deletions Package/otRebuilder/Dep/fontTools/ttLib/tables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def _moduleFinderHint():
from . import _h_h_e_a
from . import _h_m_t_x
from . import _k_e_r_n
from . import _l_c_a_r
from . import _l_o_c_a
from . import _l_t_a_g
from . import _m_a_x_p
Expand Down
4 changes: 4 additions & 0 deletions Package/otRebuilder/Dep/fontTools/ttLib/tables/_a_v_a_r.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def toXML(self, writer, ttFont, progress=None):
writer.begintag("segment", axis=axis)
writer.newline()
for key, value in sorted(self.segments[axis].items()):
# roundtrip float -> fixed -> float to normalize TTX output
# as dumped after decompiling or straight from varLib
key = fixedToFloat(floatToFixed(key, 14), 14)
value = fixedToFloat(floatToFixed(value, 14), 14)
writer.simpletag("mapping", **{"from": key, "to": value})
writer.newline()
writer.endtag("segment")
Expand Down
Loading

0 comments on commit 7b8c9de

Please sign in to comment.