def hasOverlap(self): closed = [] length = len(self) for contour in self: if contour.open: length -= 1 else: closed.append(contour) glyph = self.__class__() union(closed, glyph.getPointPen()) return len(glyph) != length
def removeOverlap(self): open_, closed = [], [] for contour in self: (open_ if contour.open else closed).append(contour) self.beginUndoGroup() self.clearContours() pointPen = self.getPointPen() union(closed, pointPen) for contour in open_: contour.drawPoints(pointPen) self.endUndoGroup()
def filter(self, glyph): if not len(glyph): return False contours = list(glyph) glyph.clearContours() try: union(contours, glyph.getPointPen()) except BooleanOperationsError: logger.error("Failed to remove overlaps for %s", glyph.name) raise return True
def _removeOverlap(self, **kwargs): if len(self): contours = list(self) for contour in contours: for point in contour.points: if point.type == "qcurve": raise TypeError( "fontshell can't removeOverlap for quadratics") self.clear(contours=True, components=False, anchors=False, guidelines=False, image=False) booleanOperations.union(contours, self.getPointPen())
def test_unsupported_qcurve(): font = defcon.Font() g = font.newGlyph("test") p = g.getPointPen() p.beginPath() p.addPoint((0, 0), segmentType="line") p.addPoint((100, 0), segmentType="line") p.addPoint((100, 100), segmentType="line") p.addPoint((50, 100)) p.addPoint((0, 100), segmentType="qcurve") p.endPath() with pytest.raises(booleanOperations.exceptions.UnsupportedContourError): booleanOperations.union(g, None)
def remove_overlaps(self, ufos): """Remove overlaps in UFOs' glyphs' contours.""" from booleanOperations import union, BooleanOperationsError for ufo in ufos: font_name = self._font_name(ufo) self.info('Removing overlaps for ' + font_name) for glyph in ufo: contours = list(glyph) glyph.clearContours() try: union(contours, glyph.getPointPen()) except BooleanOperationsError: self.logger.error("Failed to remove overlaps for %s: %r", font_name, glyph.name) raise
def remove_overlaps(self, ufos, glyph_filter=lambda g: len(g)): """Remove overlaps in UFOs' glyphs' contours.""" from booleanOperations import union, BooleanOperationsError for ufo in ufos: font_name = self._font_name(ufo) logger.info("Removing overlaps for " + font_name) for glyph in ufo: if not glyph_filter(glyph): continue contours = list(glyph) glyph.clearContours() try: union(contours, glyph.getPointPen()) except BooleanOperationsError: logger.error("Failed to remove overlaps for %s: %r", font_name, glyph.name) raise
def removeOverlap(self): # TODO: disable button instead glyph = self._glyph if not glyph: return target, others = [], [] useSelection = bool(glyph.selection) for contour in glyph: if contour.open: others.append(contour) continue if useSelection and not contour.selection: others.append(contour) continue target.append(contour) glyph.beginUndoGroup() glyph.clearContours() pointPen = glyph.getPointPen() booleanOperations.union(target, pointPen) for contour in others: contour.drawPoints(pointPen) glyph.endUndoGroup()