def _transformBy(self, matrix, **kwargs): """ Subclasses may override this method. """ t = transform.Transform(*matrix) transformation = t.transform(self.transformation) self.transformation = tuple(transformation)
def extractComposites(glyph): """Return a new glyph with outline copies of each composite from the source glyph.""" decomposedComposites = RGlyph() if len(glyph.components): font = glyph.layer for comp in reversed(glyph.components): # obtain source data baseGlyphName = comp.baseGlyph baseGlyph = font[baseGlyphName] t = transform.Transform(*comp.transformation) # create a temporary glyph on which to draw the decomposed composite single_decomposedComposite = RGlyph() decompPen = single_decomposedComposite.getPen() baseGlyph.draw(decompPen) single_decomposedComposite.transformBy(tuple(t)) # add single composite to the returned glyph decomposedComposites.appendGlyph(single_decomposedComposite) return decomposedComposites
def _transformBy(self, matrix, **kwargs): """ This is the environment implementation of :meth:`BaseAnchor.transformBy`. **matrix** will be a :ref:`type-transformation`. that has been normalized with :func:`normalizers.normalizeTransformationMatrix`. Subclasses may override this method. """ t = transform.Transform(*matrix) x, y = t.transformPoint((self.x, self.y)) self.x = x self.y = y
def _transformBy(self, matrix, **kwargs): """ Subclasses may override this method. """ anchor = self.anchor bcpIn = absoluteBCPIn(anchor, self.bcpIn) bcpOut = absoluteBCPOut(anchor, self.bcpOut) points = [bcpIn, anchor, bcpOut] t = transform.Transform(*matrix) bcpIn, anchor, bcpOut = t.transformPoints(points) x, y = anchor self._point.x = x self._point.y = y self.bcpIn = relativeBCPIn(anchor, bcpIn) self.bcpOut = relativeBCPOut(anchor, bcpOut)
def _transformBy(self, matrix, **kwargs): """ This is the environment implementation of :meth:`BaseGuideline.transformBy`. **matrix** will be a :ref:`type-transformation`. that has been normalized with :func:`normalizers.normalizeTransformationMatrix`. Subclasses may override this method. """ t = transform.Transform(*matrix) # coordinates x, y = t.transformPoint((self.x, self.y)) self.x = x self.y = y # angle angle = math.radians(self.angle) dx = math.cos(angle) dy = math.sin(angle) tdx, tdy = t.transformPoint((dx, dy)) ta = math.atan2(tdy, tdx) self.angle = math.degrees(ta)
def transformBy(self, matrix, origin=None): """ Transform the object. >>> obj.transformBy((0.5, 0, 0, 2.0, 10, 0)) >>> obj.transformBy((0.5, 0, 0, 2.0, 10, 0), origin=(500, 500)) **matrix** must be a :ref:`type-transformation`. **origin** defines the point at with the transformation should originate. It must be a :ref:`type-coordinate` or ``None``. The default is ``(0, 0)``. """ matrix = normalizers.normalizeTransformationMatrix(matrix) if origin is None: origin = (0, 0) origin = normalizers.normalizeCoordinateTuple(origin) if origin is not None: t = transform.Transform() oX, oY = origin t = t.translate(oX, oY) t = t.transform(matrix) t = t.translate(-oX, -oY) matrix = tuple(t) self._transformBy(matrix)