SOLVED How to perform pathfinder like operations in roboFont via Python?



  • Hello,
    Please I have such object and I need to cut another shape inside
    rectangle of periods overlapping rectangle of O's

    OOOOOO
    OOOOOO
    OOOO.....
    OOOO.....
        .....
        .....
    

    expected result is rectangle of O's without the overlapped part

    OOOOOO
    OOOOOO
    OOOO
    OOOO
    

    Thanks!



  • @frederik this is indeed fixed! Sorry for that


  • admin

    Are you using the latest booleanOperation version?

    I cannot reproduce this issue or see it in the code

    thanks



  • @frederik I believe that there is some sort of bug on line 60 in BooleanOperationManager

    in the second loop iterator is j thought contourCount=i

        for i, subjectContour in enumerate(subjectContours):
            _addContour(clipperPath=pc, contour=subjectContour, fillType=pyclipper.PT_SUBJECT, contourCount=i)
    
        for j, clipContour in enumerate(clipContours):
            _addContour(clipperPath=pc, contour=clipContour, fillType=pyclipper.PT_CLIP, contourCount=i)
    

    Thanks for help, I went for dividing into two glyphs. I found that handy for removing "multi-overlap".
    Screenshot 2019-10-31 at 18.20.30.png


  • admin

    It does indeed not work on contour level. There are several options:

    from booleanOperations import BooleanOperationManager
    # create a manager
    manager = BooleanOperationManager()
    # get the glyph and contours
    g = CurrentGlyph()
    c1 = g[0]
    c2 = g[1]
    
    # create an empty result layer
    result = g.getLayer("result")
    result.clear()
    # perform the difference and draw in to the result point pen
    manager.difference([c1], [c2], result.getPointPen())
    

    also see and read the source of this extension: https://github.com/typemytype/pathOperatorRoboFontExtension

    good luck!



  • Hello @gferreira,

    I expected this to work the same way like with glyphs, but it doesn't. Is there a different approach when working with contours in one glyph? Thanks

    g = CurrentGlyph()
    c1 = g[0]
    c2 = g[1]
    c3 = c1 % c2
    
    Traceback (most recent call last):
      File "<untitled>", line 6, in <module>
    TypeError: unsupported operand type(s) for %: 'RContour' and 'RContour'
    


  • Hi Gustavo, thanks! Perfect



  • hello @jansindl3r,

    have a look at Boolean Glyph Math.

    cheers!


Log in to reply