#!/usr/bin/python
import Image, ImageFont, ImageDraw

mytext='Test'

raster = 2.0
offset_x = 2.0
offset_y = 60.0

def raster_positions(text):
    result = list()
    font = ImageFont.truetype("/usr/share/fonts/truetype/msttcorefonts/arial.ttf", 28)
    dims = font.getsize(mytext)
    iii = Image.new('1', dims)
    draw = ImageDraw.Draw(iii)
    draw.text((0, 0), mytext, font=font, fill=1 )
    for y in range(dims[1]):
        for x in range(dims[0]):
            if iii.getpixel((x,y)):
                result.append((x,y))
    return result

def pos(p):
    x,y = p
    xx = x * raster + offset_x
    yy = y * -1.0 * raster + offset_y
    return xx, yy

if __name__ == '__main__':
    commands = list()
    points = raster_positions(mytext)
    i = 1
    for p in points:
        part = 'LED%d' % i
        po = pos(p)
        command = 'move %s (%f %f); rotate R45 \'%s\'' % (part, po[0], po[1], part)
        commands.append(command)
        i = i + 1
    print ';'.join(commands)
    
