Hello,
I am trying to put together a little script that would convert a line to a curve.
There may be a simpler way to do it but, the way I found looks like this:
Problem is I can’t figure out how to position the offCurve (control points) correctly. Any help would be greatly appreciated.
def getDist(a_list):
if a_list:
return max(a_list) - min(a_list)
else:
return 0
def convertToCurve():
reference_glyph = CurrentGlyph()
if reference_glyph and reference_glyph.selection != []:
reference_glyph.prepareUndo()
for contourIndex in range(len(reference_glyph.contours)):
reference_contour = reference_glyph.contours[contourIndex]
a_list_x = []
a_list_y = []
for i in range(len(reference_contour.segments)):
reference_segment = reference_contour[i]
if reference_segment.selected and reference_segment.type == "line":
#last point of previous segment
initPoint = reference_contour[i-1][0]
print initPoint
#end point of current segment
endPoint = reference_contour[i][0]
print endPoint
a_list_x = [initPoint.x, endPoint.x]
a_list_y = [initPoint.y, endPoint.y]
firstThird_x = int(getDist(a_list_x) / 3)
firstThird_y = int(getDist(a_list_y) / 3)
#print initPoint, endPoint
print firstThird_x, firstThird_y
reference_segment.type = "curve"
print reference_contour[i].points
reference_contour[i].points[0].x = initPoint.x + firstThird_x
reference_contour[i].points[0].y = initPoint.y + firstThird_y
reference_contour[i].points[1].x = endPoint.x - firstThird_x
reference_contour[i].points[1].y = endPoint.y - firstThird_y
reference_glyph.update()