Example #1
0
def calculate_pathop(pen1, pen2, operation):
    if USE_SKIA_PATHOPS:
        p1 = Path()
        pen1.replay(p1.getPen())
        if operation == BooleanOp.Simplify:
            # ignore pen2
            p1.simplify(fix_winding=True, keep_starting_points=True)
            d0 = RecordingPen()
            p1.draw(d0)
            return d0.value
        if pen2:
            p2 = Path()
            pen2.replay(p2.getPen())
        builder = OpBuilder(fix_winding=True, keep_starting_points=True)
        builder.add(p1, PathOp.UNION)
        if pen2:
            builder.add(p2, BooleanOp.Skia(operation))
        result = builder.resolve()
        d0 = RecordingPen()
        result.draw(d0)
        return d0.value
    else:
        bg2 = BooleanGlyph()
        if pen2:
            pen2.replay(bg2.getPen())
        bg = BooleanGlyph()
        pen1.replay(bg.getPen())
        bg = bg._booleanMath(BooleanOp.BooleanGlyphMethod(operation), bg2)
        dp = RecordingPen()
        bg.draw(dp)
        return dp.value
Example #2
0
 def removeOverlap(self):
     bGlyph = BooleanGlyph(self).removeOverlap()
     # TODO: we're halting removeOverlap for collinear vector diffs (changes
     # point count, not contour), is this what we want to do?
     if len(bGlyph.contours) != len(self):
         self.prepareUndo()
         self.clearContours()
         bGlyph.draw(self.getPen())
         self.dirty = True
Example #3
0
 def removeOverlap(self):
     bGlyph = BooleanGlyph(self).removeOverlap()
     # TODO: we're halting removeOverlap for collinear vector diffs (changes
     # point count, not contour), is this what we want to do?
     if len(bGlyph.contours) != len(self):
         self.prepareUndo()
         self.clearContours()
         bGlyph.draw(self.getPen())
         self.dirty = True
Example #4
0
def mergeContours(glyph):
    # remember stuff that get's lost when drawing to a fontforge glyph
    width = glyph.width
    vwidth = glyph.vwidth
    anchorPoints = tuple(glyph.anchorPoints)

    # make a defcon glyph
    dcGlyph = defcon.Glyph()
    dcGlyphPen = dcGlyph.getPen()

    # draw to dcGlyph
    glyph.draw(dcGlyphPen)

    # union of dcGlyph
    result = BooleanGlyph(dcGlyph).removeOverlap()
    targetPen = glyph.glyphPen()
    result.draw(targetPen)

    # restore stuff that a pen should rather not change automagically
    # in fact, the pen should not reset anything besides outline and components.
    glyph.width = width
    glyph.vwidth = vwidth
    [glyph.addAnchorPoint(*p) for p in anchorPoints]