blob: 2068b2555fb59403af2d17d058939ccf17b7292b [file] [log] [blame]
from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from fontTools.pens.basePen import BasePen
from import Path
__all__ = ["ReportLabPen"]
class ReportLabPen(BasePen):
"""A pen for drawing onto a object."""
def __init__(self, glyphSet, path=None):
BasePen.__init__(self, glyphSet)
if path is None:
path = Path()
self.path = path
def _moveTo(self, p):
(x,y) = p
def _lineTo(self, p):
(x,y) = p
def _curveToOne(self, p1, p2, p3):
(x1,y1) = p1
(x2,y2) = p2
(x3,y3) = p3
self.path.curveTo(x1, y1, x2, y2, x3, y3)
def _closePath(self):
if __name__=="__main__":
import sys
if len(sys.argv) < 3:
print("Usage: <OTF/TTF font> <glyphname> [<image file to create>]")
print(" If no image file name is created, by default <glyphname>.png is created.")
print(" example: Arial.TTF R test.png")
print(" (The file format will be PNG, regardless of the image file name supplied)")
from fontTools.ttLib import TTFont
from reportlab.lib import colors
path = sys.argv[1]
glyphName = sys.argv[2]
if (len(sys.argv) > 3):
imageFile = sys.argv[3]
imageFile = "%s.png" % glyphName
font = TTFont(path) # it would work just as well with fontTools.t1Lib.T1Font
gs = font.getGlyphSet()
pen = ReportLabPen(gs, Path(, strokeWidth=5))
g = gs[glyphName]
w, h = g.width, 1000
from import renderPM
from import Group, Drawing, scale
# Everything is wrapped in a group to allow transformations.
g = Group(pen.path)
g.translate(0, 200)
g.scale(0.3, 0.3)
d = Drawing(w, h)
renderPM.drawToFile(d, imageFile, fmt="PNG")