Esempio n. 1
0
def DrawGlyph(f, glyph, PSCommands, xoffset, yoffset, ratio, fillcolour,
              strokecolour, strokewidth, dashed):
    if not PSCommands:
        layer = glyph.layers[0]
        p = layer.drawBezierPath
        transform = NSAffineTransform.new()
        transform.translateXBy_yBy_(xoffset * mm, yoffset * mm)
        transform.scaleBy_(ratio)
        p.transformUsingAffineTransform_(transform)
    else:
        p = NSBezierPath.bezierPath()

        for command in PSCommands:

            if command[0] == 'moveTo':
                try:
                    p.close()
                except:
                    pass

                x = xoffset * mm + command[1][0] * ratio
                y = yoffset * mm + command[1][1] * ratio
                p.moveToPoint_((x, y))
                #print "('moveTo', (%s, %s))," % (command[1][0], command[1][1])

            if command[0] == 'lineTo':
                x = xoffset * mm + command[1][0] * ratio
                y = yoffset * mm + command[1][1] * ratio
                p.lineToPoint_((x, y))
                #print "('lineTo', (%s, %s))," % (command[1][0], command[1][1])

            if command[0] == 'curveTo':

                points = []

                for point in command[1:]:
                    points.append((xoffset * mm + point[0] * ratio,
                                   yoffset * mm + point[1] * ratio))

                p.curveToPoint_controlPoint1_controlPoint2_(
                    points[0], points[1], points[2])
        p.closePath()

    if fillcolour:
        NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(
            fillcolour[0], fillcolour[1], fillcolour[2], fillcolour[3],
            1).set()
        p.fill()
    if strokecolour:
        NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(
            strokecolour[0], strokecolour[1], strokecolour[2], strokecolour[3],
            1).set()
        if dashed:
            p.setLineDash_count_phase_(dashed, 2, 0.0)
        p.setLineWidth_(strokewidth)
        p.stroke()
def DrawGlyph(f, glyph, PSCommands, xoffset, yoffset, ratio, fillcolour, strokecolour, strokewidth, dashed):
	if not PSCommands:
		layer = glyph.layers[0]
		p = layer.drawBezierPath
		transform = NSAffineTransform.new()
		transform.translateXBy_yBy_(xoffset*mm, yoffset*mm)
		transform.scaleBy_(ratio)
		p.transformUsingAffineTransform_(transform)
	else:
		p = NSBezierPath.bezierPath()
		
		for command in PSCommands:
		
			if command[0] == 'moveTo':
				try:
					p.close()
				except:
					pass
	
				x = xoffset*mm + command[1][0] * ratio
				y = yoffset*mm + command[1][1] * ratio
				p.moveToPoint_((x, y))
				#print "('moveTo', (%s, %s))," % (command[1][0], command[1][1])
	
			if command[0] == 'lineTo':
				x = xoffset*mm + command[1][0] * ratio
				y = yoffset*mm + command[1][1] * ratio
				p.lineToPoint_((x, y))
				#print "('lineTo', (%s, %s))," % (command[1][0], command[1][1])
	
			if command[0] == 'curveTo':
	
				points = []
				
				for point in command[1:]:
					points.append( (xoffset*mm + point[0] * ratio, yoffset*mm + point[1] * ratio) )
				
				p.curveToPoint_controlPoint1_controlPoint2_(points[0], points[1], points[2])
		p.closePath()
	
	if fillcolour:
		NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(fillcolour[0], fillcolour[1], fillcolour[2], fillcolour[3], 1).set()
		p.fill()
	if strokecolour:
		NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(strokecolour[0], strokecolour[1], strokecolour[2], strokecolour[3], 1).set()
		if dashed:
			p.setLineDash_count_phase_(dashed, 2, 0.0)
		p.setLineWidth_(strokewidth)
		p.stroke()