aboutsummaryrefslogtreecommitdiff
path: root/Lib/fontTools/otlLib/maxContextCalc.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/fontTools/otlLib/maxContextCalc.py')
-rw-r--r--Lib/fontTools/otlLib/maxContextCalc.py49
1 files changed, 22 insertions, 27 deletions
diff --git a/Lib/fontTools/otlLib/maxContextCalc.py b/Lib/fontTools/otlLib/maxContextCalc.py
index 5659310f..03e7561b 100644
--- a/Lib/fontTools/otlLib/maxContextCalc.py
+++ b/Lib/fontTools/otlLib/maxContextCalc.py
@@ -1,13 +1,11 @@
-from __future__ import print_function, division, absolute_import, unicode_literals
-
-__all__ = ['maxCtxFont']
+__all__ = ["maxCtxFont"]
def maxCtxFont(font):
"""Calculate the usMaxContext value for an entire font."""
maxCtx = 0
- for tag in ('GSUB', 'GPOS'):
+ for tag in ("GSUB", "GPOS"):
if tag not in font:
continue
table = font[tag].table
@@ -25,62 +23,59 @@ def maxCtxSubtable(maxCtx, tag, lookupType, st):
"""
# single positioning, single / multiple substitution
- if (tag == 'GPOS' and lookupType == 1) or (
- tag == 'GSUB' and lookupType in (1, 2, 3)):
+ if (tag == "GPOS" and lookupType == 1) or (
+ tag == "GSUB" and lookupType in (1, 2, 3)
+ ):
maxCtx = max(maxCtx, 1)
# pair positioning
- elif tag == 'GPOS' and lookupType == 2:
+ elif tag == "GPOS" and lookupType == 2:
maxCtx = max(maxCtx, 2)
# ligatures
- elif tag == 'GSUB' and lookupType == 4:
+ elif tag == "GSUB" and lookupType == 4:
for ligatures in st.ligatures.values():
for ligature in ligatures:
maxCtx = max(maxCtx, ligature.CompCount)
# context
- elif (tag == 'GPOS' and lookupType == 7) or (
- tag == 'GSUB' and lookupType == 5):
- maxCtx = maxCtxContextualSubtable(
- maxCtx, st, 'Pos' if tag == 'GPOS' else 'Sub')
+ elif (tag == "GPOS" and lookupType == 7) or (tag == "GSUB" and lookupType == 5):
+ maxCtx = maxCtxContextualSubtable(maxCtx, st, "Pos" if tag == "GPOS" else "Sub")
# chained context
- elif (tag == 'GPOS' and lookupType == 8) or (
- tag == 'GSUB' and lookupType == 6):
+ elif (tag == "GPOS" and lookupType == 8) or (tag == "GSUB" and lookupType == 6):
maxCtx = maxCtxContextualSubtable(
- maxCtx, st, 'Pos' if tag == 'GPOS' else 'Sub', 'Chain')
+ maxCtx, st, "Pos" if tag == "GPOS" else "Sub", "Chain"
+ )
# extensions
- elif (tag == 'GPOS' and lookupType == 9) or (
- tag == 'GSUB' and lookupType == 7):
- maxCtx = maxCtxSubtable(
- maxCtx, tag, st.ExtensionLookupType, st.ExtSubTable)
+ elif (tag == "GPOS" and lookupType == 9) or (tag == "GSUB" and lookupType == 7):
+ maxCtx = maxCtxSubtable(maxCtx, tag, st.ExtensionLookupType, st.ExtSubTable)
# reverse-chained context
- elif tag == 'GSUB' and lookupType == 8:
- maxCtx = maxCtxContextualRule(maxCtx, st, 'Reverse')
+ elif tag == "GSUB" and lookupType == 8:
+ maxCtx = maxCtxContextualRule(maxCtx, st, "Reverse")
return maxCtx
-def maxCtxContextualSubtable(maxCtx, st, ruleType, chain=''):
+def maxCtxContextualSubtable(maxCtx, st, ruleType, chain=""):
"""Calculate usMaxContext based on a contextual feature subtable."""
if st.Format == 1:
- for ruleset in getattr(st, '%s%sRuleSet' % (chain, ruleType)):
+ for ruleset in getattr(st, "%s%sRuleSet" % (chain, ruleType)):
if ruleset is None:
continue
- for rule in getattr(ruleset, '%s%sRule' % (chain, ruleType)):
+ for rule in getattr(ruleset, "%s%sRule" % (chain, ruleType)):
if rule is None:
continue
maxCtx = maxCtxContextualRule(maxCtx, rule, chain)
elif st.Format == 2:
- for ruleset in getattr(st, '%s%sClassSet' % (chain, ruleType)):
+ for ruleset in getattr(st, "%s%sClassSet" % (chain, ruleType)):
if ruleset is None:
continue
- for rule in getattr(ruleset, '%s%sClassRule' % (chain, ruleType)):
+ for rule in getattr(ruleset, "%s%sClassRule" % (chain, ruleType)):
if rule is None:
continue
maxCtx = maxCtxContextualRule(maxCtx, rule, chain)
@@ -96,6 +91,6 @@ def maxCtxContextualRule(maxCtx, st, chain):
if not chain:
return max(maxCtx, st.GlyphCount)
- elif chain == 'Reverse':
+ elif chain == "Reverse":
return max(maxCtx, st.GlyphCount + st.LookAheadGlyphCount)
return max(maxCtx, st.InputGlyphCount + st.LookAheadGlyphCount)