subset: move _add_method and _uniq_sort to subset/util submodule
This commit is contained in:
parent
0dc2f820bd
commit
425e1afd36
@ -8,6 +8,7 @@ from fontTools.ttLib.tables import otTables
|
||||
from fontTools.otlLib.maxContextCalc import maxCtxFont
|
||||
from fontTools.pens.basePen import NullPen
|
||||
from fontTools.misc.loggingTools import Timer
|
||||
from fontTools.subset.util import _add_method, _uniq_sort
|
||||
from fontTools.subset.cff import *
|
||||
import sys
|
||||
import struct
|
||||
@ -363,26 +364,6 @@ log.glyphs = MethodType(_log_glyphs, log)
|
||||
timer = Timer(logger=logging.getLogger("fontTools.subset.timer"))
|
||||
|
||||
|
||||
def _add_method(*clazzes):
|
||||
"""Returns a decorator function that adds a new method to one or
|
||||
more classes."""
|
||||
def wrapper(method):
|
||||
done = []
|
||||
for clazz in clazzes:
|
||||
if clazz in done: continue # Support multiple names of a clazz
|
||||
done.append(clazz)
|
||||
assert clazz.__name__ != 'DefaultTable', \
|
||||
'Oops, table class not found.'
|
||||
assert not hasattr(clazz, method.__name__), \
|
||||
"Oops, class '%s' has method '%s'." % (clazz.__name__,
|
||||
method.__name__)
|
||||
setattr(clazz, method.__name__, method)
|
||||
return None
|
||||
return wrapper
|
||||
|
||||
def _uniq_sort(l):
|
||||
return sorted(set(l))
|
||||
|
||||
def _dict_subset(d, glyphs):
|
||||
return {g:d[g] for g in glyphs}
|
||||
|
||||
|
@ -3,26 +3,8 @@ from fontTools import ttLib
|
||||
from fontTools.pens.basePen import NullPen
|
||||
from fontTools.misc.roundTools import otRound
|
||||
from fontTools.varLib.varStore import VarStoreInstancer
|
||||
from fontTools.subset.util import _add_method, _uniq_sort
|
||||
|
||||
def _add_method(*clazzes):
|
||||
"""Returns a decorator function that adds a new method to one or
|
||||
more classes."""
|
||||
def wrapper(method):
|
||||
done = []
|
||||
for clazz in clazzes:
|
||||
if clazz in done: continue # Support multiple names of a clazz
|
||||
done.append(clazz)
|
||||
assert clazz.__name__ != 'DefaultTable', \
|
||||
'Oops, table class not found.'
|
||||
assert not hasattr(clazz, method.__name__), \
|
||||
"Oops, class '%s' has method '%s'." % (clazz.__name__,
|
||||
method.__name__)
|
||||
setattr(clazz, method.__name__, method)
|
||||
return None
|
||||
return wrapper
|
||||
|
||||
def _uniq_sort(l):
|
||||
return sorted(set(l))
|
||||
|
||||
class _ClosureGlyphsT2Decompiler(psCharStrings.SimpleT2Decompiler):
|
||||
|
||||
|
25
Lib/fontTools/subset/util.py
Normal file
25
Lib/fontTools/subset/util.py
Normal file
@ -0,0 +1,25 @@
|
||||
"""Private utility methods used by the subset modules"""
|
||||
|
||||
|
||||
def _add_method(*clazzes):
|
||||
"""Returns a decorator function that adds a new method to one or
|
||||
more classes."""
|
||||
|
||||
def wrapper(method):
|
||||
done = []
|
||||
for clazz in clazzes:
|
||||
if clazz in done:
|
||||
continue # Support multiple names of a clazz
|
||||
done.append(clazz)
|
||||
assert clazz.__name__ != "DefaultTable", "Oops, table class not found."
|
||||
assert not hasattr(
|
||||
clazz, method.__name__
|
||||
), "Oops, class '%s' has method '%s'." % (clazz.__name__, method.__name__)
|
||||
setattr(clazz, method.__name__, method)
|
||||
return None
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def _uniq_sort(l):
|
||||
return sorted(set(l))
|
Loading…
x
Reference in New Issue
Block a user