Example #1
0
def copyContours(glyph):
    glyphCopy = RGlyph()
    glyphCopy.width = glyph.width
    pen = glyphCopy.getPen()
    glyph.draw(pen)
    glyphCopy.unicode = glyph.unicode
    glyphCopy.name = glyph.name
    return glyphCopy
Example #2
0
def copyContours(glyph):
    glyphCopy = RGlyph()
    glyphCopy.width = glyph.width
    pen = glyphCopy.getPen()
    glyph.draw(pen)
    glyphCopy.unicode = glyph.unicode
    glyphCopy.name = glyph.name
    return glyphCopy
        def filterGroup(glyph, font=None, **overrideGlobalArguments):
            globalArguments = {self.splitSubfilterArgumentName(argumentName): self.arguments[argumentName] for argumentName in self.arguments}
            for key in overrideGlobalArguments:
                _subfilterName_, _overrideArgumentName_, _filterOrder_ = self.splitSubfilterArgumentName(key)
                if (_subfilterName_, _overrideArgumentName_) != (None, None):
                    globalArguments[(_subfilterName_, _overrideArgumentName_, _filterOrder_)] = overrideGlobalArguments[key]

            subfilters = [(self.getSubfilter(subfilterName), mode, source) for subfilterName, mode, source in self.subfilters]
            error = False
            canvasGlyph = RGlyph()
            canvasPen = canvasGlyph.getPen()
            canvasGlyph.width = glyph.width
            glyph.draw(canvasPen)

            steps = []

            for i, (currentFilter, mode, source) in enumerate(subfilters):

                if error == True:
                    continue

                if source is None:
                    sourceGlyph = canvasGlyph
                else:
                    try:
                        sourceGlyph = steps[source]
                    except:
                        layerGlyph = glyph.getLayer(source)
                        if len(layerGlyph) > 0:
                            sourceGlyph = RGlyph()
                            pen = sourceGlyph.getPen()
                            layerGlyph.draw(pen)
                        else:
                            sourceGlyph = canvasGlyph

                sourceGlyph.name = glyph.name

                arguments = {argumentName: globalArguments[(subfilterName, argumentName, filterOrder)] for subfilterName, argumentName, filterOrder in globalArguments if subfilterName == currentFilter.name and filterOrder == i}
                processedGlyph = currentFilter.filterGlyph(sourceGlyph, arguments)

                steps.append(processedGlyph)

                if mode in ['union', 'difference', 'intersection', 'xor']:
                    try:
                        b1 = BooleanGlyph(canvasGlyph)
                        b2 = BooleanGlyph(processedGlyph)
                        operation = getattr(b1, mode)
                        processedGlyph = operation(b2)
                    except:
                        error = True

                if mode != 'add':
                    canvasGlyph.clear()

                processedGlyph.draw(canvasPen)

            if error == True:
                canvasGlyph = ErrorGlyph()
            elif error == False:
                canvasGlyph.name = glyph.name

            canvasGlyph.unicode = glyph.unicode
            if canvasGlyph.width is None:
                canvasGlyph.width = glyph.width
            return canvasGlyph
        def filterGroup(glyph, font=None, **overrideGlobalArguments):
            globalArguments = {
                self.splitSubfilterArgumentName(argumentName):
                self.arguments[argumentName]
                for argumentName in self.arguments
            }
            for key in overrideGlobalArguments:
                _subfilterName_, _overrideArgumentName_, _filterOrder_ = self.splitSubfilterArgumentName(
                    key)
                if (_subfilterName_, _overrideArgumentName_) != (None, None):
                    globalArguments[(
                        _subfilterName_, _overrideArgumentName_,
                        _filterOrder_)] = overrideGlobalArguments[key]

            subfilters = [(self.getSubfilter(subfilterName), mode, source)
                          for subfilterName, mode, source in self.subfilters]
            error = False
            canvasGlyph = RGlyph()
            canvasPen = canvasGlyph.getPen()
            canvasGlyph.width = glyph.width
            glyph.draw(canvasPen)

            steps = []

            for i, (currentFilter, mode, source) in enumerate(subfilters):

                if error == True:
                    continue

                if not source:
                    sourceGlyph = canvasGlyph
                else:
                    try:
                        sourceGlyph = steps[source - 1]
                    except:
                        layerGlyph = glyph.getLayer(source)
                        if len(layerGlyph) > 0:
                            sourceGlyph = RGlyph()
                            pen = sourceGlyph.getPen()
                            layerGlyph.draw(pen)
                        else:
                            sourceGlyph = canvasGlyph

                sourceGlyph.name = glyph.name

                arguments = {
                    argumentName:
                    globalArguments[(subfilterName, argumentName, filterOrder)]
                    for subfilterName, argumentName, filterOrder in
                    globalArguments
                    if subfilterName == currentFilter.name and filterOrder == i
                }
                processedGlyph = currentFilter.filterGlyph(
                    sourceGlyph, arguments)

                if mode in ['union', 'difference', 'intersection', 'xor']:
                    try:
                        # collectedComponents = [component for component in processedGlyph.components]
                        b1 = BooleanGlyph(canvasGlyph)
                        b2 = BooleanGlyph(processedGlyph)
                        operation = getattr(b1, mode)
                        b3 = operation(b2)
                        processedGlyph = RGlyph()
                        processedPen = processedGlyph.getPen()
                        b3.draw(processedPen)
                        # for component in collectedComponents:
                        #     processedGlyph.appendComponent(component.baseGlyph, component.offset, component.scale)
                    except:
                        error = True

                steps.append(processedGlyph)

                if mode == 'ignore' and len(steps) > 1:
                    processedGlyph = steps[-2]
                elif mode == 'ignore':
                    processedGlyph = sourceGlyph

                if mode != 'add':
                    canvasGlyph.clear()

                processedGlyph.draw(canvasPen)

                if processedGlyph.width:
                    canvasGlyph.width = processedGlyph.width

            if error == True:
                canvasGlyph = ErrorGlyph()
            elif error == False:
                cleanPen = FilterPointPen(font)
                canvasGlyph.drawPoints(cleanPen)
                canvasGlyph.clearContours()
                canvasPointPen = canvasGlyph.getPointPen()
                cleanPen.extract(canvasPointPen)
                canvasGlyph.name = glyph.name

            canvasGlyph.unicode = glyph.unicode
            if canvasGlyph.width is None:
                canvasGlyph.width = glyph.width
            return canvasGlyph
Example #5
0
        def filterGroup(glyph, font=None, **overrideGlobalArguments):
            globalArguments = {
                self.splitSubfilterArgumentName(argumentName):
                self.arguments[argumentName]
                for argumentName in self.arguments
            }
            for key in overrideGlobalArguments:
                _subfilterName_, _overrideArgumentName_, _filterOrder_ = self.splitSubfilterArgumentName(
                    key)
                if (_subfilterName_, _overrideArgumentName_) != (None, None):
                    globalArguments[(
                        _subfilterName_, _overrideArgumentName_,
                        _filterOrder_)] = overrideGlobalArguments[key]

            subfilters = [(self.getSubfilter(subfilterName), mode, source)
                          for subfilterName, mode, source in self.subfilters]
            error = False
            canvasGlyph = RGlyph()
            canvasPen = canvasGlyph.getPen()
            canvasGlyph.width = glyph.width
            glyph.draw(canvasPen)

            steps = []

            for i, (currentFilter, mode, source) in enumerate(subfilters):

                if error == True:
                    continue

                if source is None:
                    sourceGlyph = canvasGlyph
                else:
                    try:
                        sourceGlyph = steps[source]
                    except:
                        layerGlyph = glyph.getLayer(source)
                        if len(layerGlyph) > 0:
                            sourceGlyph = RGlyph()
                            pen = sourceGlyph.getPen()
                            layerGlyph.draw(pen)
                        else:
                            sourceGlyph = canvasGlyph

                sourceGlyph.name = glyph.name

                arguments = {
                    argumentName:
                    globalArguments[(subfilterName, argumentName, filterOrder)]
                    for subfilterName, argumentName, filterOrder in
                    globalArguments
                    if subfilterName == currentFilter.name and filterOrder == i
                }
                processedGlyph = currentFilter.filterGlyph(
                    sourceGlyph, arguments)

                steps.append(processedGlyph)

                if mode in ['union', 'difference', 'intersection', 'xor']:
                    try:
                        b1 = BooleanGlyph(canvasGlyph)
                        b2 = BooleanGlyph(processedGlyph)
                        operation = getattr(b1, mode)
                        processedGlyph = operation(b2)
                    except:
                        error = True

                if mode != 'add':
                    canvasGlyph.clear()

                processedGlyph.draw(canvasPen)

            if error == True:
                canvasGlyph = ErrorGlyph()
            elif error == False:
                canvasGlyph.name = glyph.name

            canvasGlyph.unicode = glyph.unicode
            if canvasGlyph.width is None:
                canvasGlyph.width = glyph.width
            return canvasGlyph
        def filterGroup(glyph, font=None, **overrideGlobalArguments):
            globalArguments = {self.splitSubfilterArgumentName(argumentName): self.arguments[argumentName] for argumentName in self.arguments}
            for key in overrideGlobalArguments:
                _subfilterName_, _overrideArgumentName_, _filterOrder_ = self.splitSubfilterArgumentName(key)
                if (_subfilterName_, _overrideArgumentName_) != (None, None):
                    globalArguments[(_subfilterName_, _overrideArgumentName_, _filterOrder_)] = overrideGlobalArguments[key]

            subfilters = [(self.getSubfilter(subfilterName), mode, source) for subfilterName, mode, source in self.subfilters]
            error = False
            canvasGlyph = RGlyph()
            canvasPen = canvasGlyph.getPen()
            canvasGlyph.width = glyph.width
            glyph.draw(canvasPen)

            steps = []

            for i, (currentFilter, mode, source) in enumerate(subfilters):

                if error == True:
                    continue

                if not source:
                    sourceGlyph = canvasGlyph
                else:
                    try:
                        sourceGlyph = steps[source-1]
                    except:
                        layerGlyph = glyph.getLayer(source)
                        if len(layerGlyph) > 0:
                            sourceGlyph = RGlyph()
                            pen = sourceGlyph.getPen()
                            layerGlyph.draw(pen)
                        else:
                            sourceGlyph = canvasGlyph

                sourceGlyph.name = glyph.name

                arguments = {argumentName: globalArguments[(subfilterName, argumentName, filterOrder)] for subfilterName, argumentName, filterOrder in globalArguments if subfilterName == currentFilter.name and filterOrder == i}
                processedGlyph = currentFilter.filterGlyph(sourceGlyph, arguments)

                if mode in ['union', 'difference', 'intersection', 'xor']:
                    try:
                        # collectedComponents = [component for component in processedGlyph.components]
                        b1 = BooleanGlyph(canvasGlyph)
                        b2 = BooleanGlyph(processedGlyph)
                        operation = getattr(b1, mode)
                        b3 = operation(b2)
                        processedGlyph = RGlyph()
                        processedPen = processedGlyph.getPen()
                        b3.draw(processedPen)
                        # for component in collectedComponents:
                        #     processedGlyph.appendComponent(component.baseGlyph, component.offset, component.scale)
                    except:
                        error = True

                steps.append(processedGlyph)

                if mode == 'ignore' and len(steps) > 1:
                    processedGlyph = steps[-2]
                elif mode == 'ignore':
                    processedGlyph = sourceGlyph

                if mode != 'add':
                    canvasGlyph.clear()

                processedGlyph.draw(canvasPen)

                if processedGlyph.width:
                    canvasGlyph.width = processedGlyph.width

            if error == True:
                canvasGlyph = ErrorGlyph()
            elif error == False:
                cleanPen = FilterPointPen(font)
                canvasGlyph.drawPoints(cleanPen)
                canvasGlyph.clearContours()
                canvasPointPen = canvasGlyph.getPointPen()
                cleanPen.extract(canvasPointPen)
                canvasGlyph.name = glyph.name


            canvasGlyph.unicode = glyph.unicode
            if canvasGlyph.width is None:
                canvasGlyph.width = glyph.width
            return canvasGlyph