transformPen.py :  » GUI » TTX-FontTools » fonttools-2.3 » Lib » fontTools » pens » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » TTX FontTools 
TTX FontTools » fonttools 2.3 » Lib » fontTools » pens » transformPen.py
from fontTools.pens.basePen import AbstractPen


__all__ = ["TransformPen"]


class TransformPen(AbstractPen):

  """Pen that transforms all coordinates using a Affine transformation,
  and passes them to another pen.
  """

  def __init__(self, outPen, transformation):
    """The 'outPen' argument is another pen object. It will receive the
    transformed coordinates. The 'transformation' argument can either
    be a six-tuple, or a fontTools.misc.transform.Transform object.
    """
    if not hasattr(transformation, "transformPoint"):
      from fontTools.misc.transform import Transform
      transformation = Transform(*transformation)
    self._transformation = transformation
    self._transformPoint = transformation.transformPoint
    self._outPen = outPen
    self._stack = []

  def moveTo(self, pt):
    self._outPen.moveTo(self._transformPoint(pt))

  def lineTo(self, pt):
    self._outPen.lineTo(self._transformPoint(pt))

  def curveTo(self, *points):
    self._outPen.curveTo(*self._transformPoints(points))

  def qCurveTo(self, *points):
    if points[-1] is None:
      points = self._transformPoints(points[:-1]) + [None]
    else:
      points = self._transformPoints(points)
    self._outPen.qCurveTo(*points)

  def _transformPoints(self, points):
    new = []
    transformPoint = self._transformPoint
    for pt in points:
      new.append(transformPoint(pt))
    return new

  def closePath(self):
    self._outPen.closePath()

  def addComponent(self, glyphName, transformation):
    transformation = self._transformation.transform(transformation)
    self._outPen.addComponent(glyphName, transformation)


if __name__ == "__main__":
  from fontTools.pens.basePen import _TestPen
  pen = TransformPen(_TestPen(None), (2, 0, 0.5, 2, -10, 0))
  pen.moveTo((0, 0))
  pen.lineTo((0, 100))
  pen.curveTo((50, 75), (60, 50), (50, 25), (0, 0))
  pen.closePath()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.