#FLM: Slice line coords Draw
# mod for FL canvas
# line equation
# draws thick line in Fontlab
# Does not change outlines, its safe to use.
# not tested on PC
# v.6 Anton Koovit 01.2011
from FL import *
from robofab.world import CurrentGlyph, CurrentFont
import math
import sys
glyph = CurrentGlyph()
#if currentglyph == none:
# YOUR simple line defined by 2 points
ptone = 0, 0 # type your coordinates
pttwo = 600, 900
# how many boxes on the line?
step = 25
size = 4
# Functions
def drawCanv(canvas, x, y, s):
canvas.pen_style = cPEN_NULL #canvas.brush_style = cPEN_NULL #pen style?
canvas.brush_color = 0x11ddff #can put CLR here
#canvas.pen_color = 0x00bb00 # pen = stroke
size = s
q = s * 0.9
canvas.Rectangle(0, x-q, y-q, x + q, y + q)
def lenLine((x1, y1), (x2, y2)): #Thank you Fred Berlaen!
from math import sqrt
return sqrt((x2 - x1)**2 + (y2 - y1)**2)
def m_form (y, mu, pty, ptx): # lets make line into Equation
x = mu*(y- pty) + ptx
return x
# program
if glyph is not None:
myPen = glyph.getPen()
canvas = fl.GetCanvas()
xDiff = pttwo[0] - ptone[0]
yDiff = pttwo[1] - ptone[1]
length = lenLine(ptone, pttwo)
#print "diffs:", abs(yDiff) , abs(xDiff)
# find m. The slope coeficent
mu = float(xDiff)/yDiff #nasty division py probl
# TO DO:
# still problem with horizontal. Then yDiff == 0 !!!
divided = length / step #divide hypothenuse
#circN = int(divided) #how many circles. Mida lamedam nurk seda rohkem
propstep = abs(yDiff) / divided # aproximate the amount of circles on a line
#divide a line
# If its upright ...til sloping check y
# if ydiff smaller; check x
dividea = abs(yDiff) / step #how many blobs on line
#print "propstep", propstep
#lets get REAL not imaginary pt on a line Y dir!
# range wants smaller nr to be on left!
if ptone[1] < pttwo[1]: # lets organize them!
#print "blaaf"
lopt = ptone[1]
hipt = pttwo[1]
else:
lopt = pttwo[1]
hipt = ptone[1]
for y in range (lopt, hipt, int(propstep)):
x = m_form (y, mu, ptone[1], ptone[0])
#print x, y
p1 = fl.GlyphToScreen(Point(x, y))
#print p1
ptx = p1.x
pty = p1.y
drawCanv(canvas, ptx, pty, size)
print "drawn"
else:
print "open font, and glyph"
#sys.exit(1) #haha kill FL
'''
#print "zeroCoord", zeroCoord
'''