Convert Line to Curve

RoboFont Forums Help / General Convert Line to Curve

This topic contains 2 replies, has 2 voices, and was last updated by  frederik 6 years, 7 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #5801

    Jeremie
    Member

    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()
    
    #5806

    Jeremie
    Member

    I actually found the solution by myself with robofab insertSegment method…
    In case anyone is interested it is available here: https://github.com/sansplomb/RobofontTools/tree/master/ConvertSegments

    #5807

    frederik
    Keymaster

    super, thanks

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.