def test_rotate(self): t = Transform() assert t.rotate(math.pi / 2) == Transform(0, 1, -1, 0, 0, 0) t = Transform() assert t.rotate(-math.pi / 2) == Transform(0, -1, 1, 0, 0, 0) t = Transform() assert tuple(t.rotate(math.radians(30))) == pytest.approx( tuple(Transform(0.866025, 0.5, -0.5, 0.866025, 0, 0)))
def distributeOnPath(self, path, offset=0, cc=None, notfound=None): if cc: cutter = cc else: cutter = CurveCutter(path) limit = len(self.pens) for idx, p in enumerate(self.pens): f = p.getFrame() bs = f.y ow = offset + f.x + f.w / 2 #if ow < 0: # if notfound: # notfound(p) if ow > cutter.length: limit = min(idx, limit) else: _p, tangent = cutter.subsegmentPoint(end=ow) x_shift = bs * math.cos(math.radians(tangent)) y_shift = bs * math.sin(math.radians(tangent)) t = Transform() t = t.translate(_p[0] + x_shift - f.x, _p[1] + y_shift - f.y) t = t.translate(f.x, f.y) t = t.rotate(math.radians(tangent - 90)) t = t.translate(-f.x, -f.y) t = t.translate(-f.w * 0.5) p.transform(t) if limit < len(self.pens): self.pens = self.pens[0:limit] return self
def getKernel(radius, amplitude=1, depth=50, angle=0): """ >>> a = getKernel(5) >>> a[(0,0)] 0.03662899097662087 >>> a[(2,0)] 0.02371649522786113 """ t = Transform() t = t.rotate(angle) lines = getCircle(0, 0, radius) sigma = (radius+1) / math.sqrt(2*math.log(depth)) grid = {} total = 0 for y, (xMin, xMax) in lines.items(): for x in range(xMin, xMax+1, 1): g = xyGaussian(x,y, amplitude, 0, 0, sigma, sigma) grid[(x,y)]=grid.get((x,y), 0)+g total += g # scale the amplitude based on the total grid = {k: float(v)/total for k, v in grid.items()} # rotate the grid grid = grid new = {} for k, v in grid.items(): k_ = t.transformPoint(k) new[k_] = v grid = new return grid
def rotate(self, degrees, point=None): t = Transform() if not point: point = self.point("C") t = t.translate(point.x, point.y) t = t.rotate(math.radians(degrees)) t = t.translate(-point.x, -point.y) return self.transform(t)
def makeTransform(x, y, rotation, scalex, scaley, tcenterx, tcentery, scaleUsesCenter=True): rotation = math.radians(rotation) if not scaleUsesCenter: tcenterx *= scalex tcentery *= scaley t = Transform() t = t.translate(x + tcenterx, y + tcentery) t = t.rotate(rotation) t = t.translate(-tcenterx, -tcentery) t = t.scale(scalex, scaley) else: t = Transform() t = t.translate(x + tcenterx, y + tcentery) t = t.rotate(rotation) t = t.scale(scalex, scaley) t = t.translate(-tcenterx, -tcentery) return t
def makeTransform(x, y, rotation, scalex, scaley, tcenterx, tcentery): rotation = math.radians(rotation) t = Transform() t = t.translate(x + tcenterx, y + tcentery) t = t.rotate(rotation) t = t.scale(scalex, scaley) t = t.translate(-tcenterx, -tcentery) return t
def rotate(self, degrees, point=None): """Rotate this shape by a degree (in 360-scale, counterclockwise).""" t = Transform() if not point: point = self.bounds().point("C") # maybe should be getFrame()? t = t.translate(point.x, point.y) t = t.rotate(math.radians(degrees)) t = t.translate(-point.x, -point.y) return self.transform(t, transformFrame=False)
def makeTransformVarCo(x, y, rotation, scalex, scaley, skewx, skewy, tcenterx, tcentery): t = Transform() t = t.translate(x + tcenterx, y + tcentery) t = t.rotate(math.radians(rotation)) t = t.scale(scalex, scaley) t = t.skew(math.radians(skewx), math.radians(skewy)) t = t.translate(-tcenterx, -tcentery) return t
def rotate(self, degrees, point=None): if Transform: t = Transform() if not point: point = self.mid t = t.translate(point.x, point.y) t = t.rotate(math.radians(degrees)) t = t.translate(-point.x, -point.y) return self.transform(t) else: raise Exception("fontTools not installed")
def rotate(self, angle, center=(0, 0)): t = Transform() t = t.rotate(math.radians(angle)) self.transform(t, center=center)
from fontTools.misc.transform import Transform size(200, 200) with savedState(): rotate(15, center=(50, 50)) rect(25, 25, 50, 50) with savedState(): scale(1.2, center=(150, 50)) rect(125, 25, 50, 50) with savedState(): skew(15, 10, center=(50, 150)) rect(25, 125, 50, 50) with savedState(): t = Transform() t = t.scale(0.9, 1.1) t = t.rotate(0.2) transform(t, center=(150, 150)) rect(125, 125, 50, 50)