Rename CVTValues to arrayTools.Vector
This is generic, and useful in other cases.
This commit is contained in:
parent
974eb08810
commit
c91f0323db
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
from __future__ import print_function, division, absolute_import
|
from __future__ import print_function, division, absolute_import
|
||||||
from fontTools.misc.py23 import *
|
from fontTools.misc.py23 import *
|
||||||
|
from numbers import Number
|
||||||
import math
|
import math
|
||||||
|
|
||||||
def calcBounds(array):
|
def calcBounds(array):
|
||||||
@ -119,6 +120,38 @@ def intRect(rect1):
|
|||||||
yMax = int(math.ceil(yMax))
|
yMax = int(math.ceil(yMax))
|
||||||
return (xMin, yMin, xMax, yMax)
|
return (xMin, yMin, xMax, yMax)
|
||||||
|
|
||||||
|
class Vector(object):
|
||||||
|
"""A math-like vector."""
|
||||||
|
|
||||||
|
def __init__(self, values, keep=False):
|
||||||
|
self.values = values if keep else list(values)
|
||||||
|
|
||||||
|
def __getitem__(self, index):
|
||||||
|
return self.values[index]
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.values)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "Vector(%s)" % self.values
|
||||||
|
|
||||||
|
def __isub__(self, other):
|
||||||
|
if isinstance(other, Vector):
|
||||||
|
assert len(self.values) == len(other.values)
|
||||||
|
a = self.values
|
||||||
|
b = other.values
|
||||||
|
self.values = [a[i] - b[i] for i in range(len(self.values))]
|
||||||
|
return self
|
||||||
|
if isinstance(other, Number):
|
||||||
|
self.values = [v - other for v in self.values]
|
||||||
|
return self
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
|
def __mul__(self, other):
|
||||||
|
if isinstance(other, Number):
|
||||||
|
return Vector([v * other for v in self.values], keep=True)
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
|
|
||||||
def _test():
|
def _test():
|
||||||
"""
|
"""
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from __future__ import print_function, division, absolute_import
|
from __future__ import print_function, division, absolute_import
|
||||||
from numbers import Number
|
|
||||||
from fontTools.misc.py23 import *
|
from fontTools.misc.py23 import *
|
||||||
from fontTools.misc.textTools import safeEval
|
from fontTools.misc.textTools import safeEval
|
||||||
from . import DefaultTable
|
from . import DefaultTable
|
||||||
@ -48,34 +47,3 @@ class table__c_v_t(DefaultTable.DefaultTable):
|
|||||||
|
|
||||||
def __delitem__(self, index):
|
def __delitem__(self, index):
|
||||||
del self.values[index]
|
del self.values[index]
|
||||||
|
|
||||||
|
|
||||||
class CVTValues(object):
|
|
||||||
""" This is used in varLib for calculating control value deltas"""
|
|
||||||
|
|
||||||
def __init__(self, values):
|
|
||||||
self.values = list(values)
|
|
||||||
|
|
||||||
def __getitem__(self, index):
|
|
||||||
return self.values[index]
|
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return len(self.values)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return u"CVTValues(%s)" % self.values
|
|
||||||
|
|
||||||
def __isub__(self, other):
|
|
||||||
if isinstance(other, CVTValues):
|
|
||||||
assert len(self.values) == len(other)
|
|
||||||
self.values = [self.values[i] - other.values[i] for i in range(len(self.values))]
|
|
||||||
return self
|
|
||||||
if isinstance(other, Number):
|
|
||||||
self.values = [v - other for v in self.values]
|
|
||||||
return self
|
|
||||||
return NotImplemented
|
|
||||||
|
|
||||||
def __mul__(self, other):
|
|
||||||
if isinstance(other, Number):
|
|
||||||
return CVTValues([v * other for v in self.values])
|
|
||||||
return NotImplemented
|
|
||||||
|
@ -21,9 +21,9 @@ API *will* change in near future.
|
|||||||
from __future__ import print_function, division, absolute_import
|
from __future__ import print_function, division, absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from fontTools.misc.py23 import *
|
from fontTools.misc.py23 import *
|
||||||
|
from fontTools.misc.arrayTools import Vector
|
||||||
from fontTools.ttLib import TTFont, newTable
|
from fontTools.ttLib import TTFont, newTable
|
||||||
from fontTools.ttLib.tables._n_a_m_e import NameRecord
|
from fontTools.ttLib.tables._n_a_m_e import NameRecord
|
||||||
from fontTools.ttLib.tables._c_v_t import CVTValues
|
|
||||||
from fontTools.ttLib.tables._f_v_a_r import Axis, NamedInstance
|
from fontTools.ttLib.tables._f_v_a_r import Axis, NamedInstance
|
||||||
from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates
|
from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates
|
||||||
from fontTools.ttLib.tables.TupleVariation import TupleVariation
|
from fontTools.ttLib.tables.TupleVariation import TupleVariation
|
||||||
@ -511,7 +511,7 @@ def _add_cvar(font, model, master_ttfs, tolerance=0.5):
|
|||||||
cvar.version = 1
|
cvar.version = 1
|
||||||
cvar.variations = []
|
cvar.variations = []
|
||||||
|
|
||||||
allCVTs = [CVTValues(m["cvt "].values) for m in master_ttfs]
|
allCVTs = [Vector(m["cvt "].values) for m in master_ttfs]
|
||||||
num_cvts0 = len(allCVTs[0])
|
num_cvts0 = len(allCVTs[0])
|
||||||
|
|
||||||
if (any(len(c) != num_cvts0 for c in allCVTs)):
|
if (any(len(c) != num_cvts0 for c in allCVTs)):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user