OTF file: accessing contours & segments



  • Hello,

    Is there any way I could use a BezierPath() generated from an OTF file in an approach like FontParts does with UFO files?

    I would like to access more than contours, segments and points of that BezierPath() and get more attributes of it.

    Thanks!



  • hello @RicardGarcia,

    a BezierPath is similar to a glyph. here’s how you can access the contours, segments and points:

    B = BezierPath()
    B.text('a', font='Menlo-Bold', fontSize=1000)
    
    for contour in B.contours:
        print(contour)
        for segment in contour:
            print(segment) # a segment is a list of points
        print()
    

    there’s also points, onCurvePoints and offCurvePoints.

    I hope this is what you’re looking for… cheers!



  • Thanks a lot, @gferreira!

    I knew about these attributes of a BezierPath() but since I want to know from each segment if it is a line or a curve I thought I could use a module and apply it to this BezierPath(). Anyway, I think I found a way to get this information by counting the amount of points in a segment so that, if there are 2 points it would be a straight line and if there are 3 a curve. Does this make sense?

    Thanks a lot again, Gustavo.



  • hi @RicardGarcia,

    Anyway, I think I found a way to get this information by counting the amount of points in a segment so that, if there are 2 points it would be a straight line and if there are 3 a curve. Does this make sense?

    yes, except there is only 1 point in a straight segment (and 3 in a curve). the first point in a segment is always the last point from the previous one – have a look at this example.

    enjoy!



  • Thank you so much again, Gustavo!


Log in to reply