def cleanOutline(self, glyph):

        for contour in glyph:
    
            for i in range(len(contour.points)):
        
                if i > 0:

                    if i < len(contour.points)-1:
                
                        if (contour.points[i-1].x == contour.points[i].x) and (contour.points[i+1].x == contour.points[i].x) and (contour.points[i].type == "line") and (contour.points[i-1].type == "line") and (contour.points[i+1].type == "line"):
                            contour.points[i].y = contour.points[i-1].y
                        if (contour.points[i-1].y == contour.points[i].y) and (contour.points[i+1].y == contour.points[i].y) and (contour.points[i].type == "line") and (contour.points[i-1].type == "line") and (contour.points[i+1].type == "line"):
                            contour.points[i].x = contour.points[i-1].x
                    
        thresholdGlyph(glyph, threshold)
from robofab.pens.filterPen import thresholdGlyph
g = CurrentGlyph()

# Set minimun Distance
distance = 20

# Antes
contornos_antes = len(g)
puntos_antes = 0
i = 0
for contour in g.contours:
    puntos_antes = puntos_antes + len(g[i].points)
    i = i + 1

# Cleanup
thresholdGlyph(g, distance)

# Eliminar Contornos Chiquitos
for contour in g:
    for contourIndex in reversed(range(len(g))):
        contour = g[contourIndex]
        if len(contour) <= 2:
            g.removeContour(contourIndex)

# Despues
contornos_despues = len(g)
puntos_despues = 0
i = 0
for contour in g.contours:
    puntos_despues = puntos_despues + len(g[i].points)
    i = i + 1
Beispiel #3
0
from robofab.world import CurrentGlyph
from robofab.pens.filterPen import thresholdGlyph
d = 10
thresholdGlyph(CurrentGlyph(), d)
from robofab.pens.filterPen import thresholdGlyph
g = CurrentGlyph()

# Set minimun Distance
distance = 20

# Antes
contornos_antes = len(g)
puntos_antes = 0
i = 0
for contour in g.contours:
	puntos_antes = puntos_antes + len(g[i].points)
	i = i + 1

# Cleanup
thresholdGlyph(g, distance)

# Eliminar Contornos Chiquitos
for contour in g:
    for contourIndex in reversed(range(len(g))):
        contour = g[contourIndex]
        if len(contour) <= 2:
            g.removeContour(contourIndex)

# Despues
contornos_despues = len(g)
puntos_despues = 0
i = 0
for contour in g.contours:
	puntos_despues = puntos_despues + len(g[i].points)
	i = i + 1
        font_source = OpenFont("U+2194_Matriz.ufo", showUI=False)
        font_dest = NewFont()
        font_dest.info.familyName = family_name
        font_dest.info.styleName = "%s %s" % (behavior, weight)
        font_dest.info.fullName = "%s %s %s" % (family_name, behavior, weight)

        for font_source_glyph in font_source:

            # cria um glifo "temporario"
            work_glyph = font_source[font_source_glyph.name]

            # reparte e achata todos os segmentos de acordo com a distância
            flattenGlyph(work_glyph, flatten_distance)
            if th is True:
                thresholdGlyph(work_glyph, threshold_distance)

            # gera uma lista de pontos por contorno formatada em tuplas
            work_glyph_point_list = []
            for contour in range(len(work_glyph.contours)):
                work_glyph_contour_point_list = []
                for points in work_glyph[contour].points:
                    # pega somente pontos dentro da curva
                    if str(points.type) is not "offCurve":
                        work_glyph_contour_point_list += [(points.x, points.y)]
                        # work_glyph_contour_point_list += [(points.x+randint(0,200), points.y+randint(0,200))]
                work_glyph_point_list += [work_glyph_contour_point_list]

            # cria o espaço para o novo glifo na fonte destino
            font_dest_glyph = font_dest.newGlyph(work_glyph.name)
            font_dest_glyph.width = font_source_glyph.width
Beispiel #6
0
    def _drawElements(self, glyph, color, distance, mode):
        assert mode == 'canvas' or mode == 'foreground'
        assert self.elementShape in SHAPE_OPTIONS

        if mode == 'foreground':
            phantomGlyph = RGlyph()

        for eachContour in glyph:
            for indexSegment, eachSegment in enumerate(eachContour):
                if indexSegment != len(eachContour) - 1:
                    nextSegment = eachContour[indexSegment + 1]
                else:
                    if eachContour.open is True:
                        continue
                    else:
                        nextSegment = eachContour[0]

                pt1 = eachSegment.onCurve.x, eachSegment.onCurve.y
                pt4 = nextSegment.onCurve.x, nextSegment.onCurve.y

                if nextSegment.offCurve:
                    pt2 = nextSegment.offCurve[0].x, nextSegment.offCurve[0].y
                    pt3 = nextSegment.offCurve[1].x, nextSegment.offCurve[1].y
                else:
                    pt2 = pt1
                    pt3 = pt4
                pt1 = eachSegment.onCurve.x, eachSegment.onCurve.y
                pt4 = nextSegment.onCurve.x, nextSegment.onCurve.y

                if eachSegment.onCurve.naked().uniqueID in glyph.lib[PLUGIN_KEY] and \
                   nextSegment.onCurve.naked().uniqueID in glyph.lib[PLUGIN_KEY]:
                    startLib = glyph.lib[PLUGIN_KEY][
                        eachSegment.onCurve.naked().uniqueID]
                    endLib = glyph.lib[PLUGIN_KEY][
                        nextSegment.onCurve.naked().uniqueID]

                    bezPoints = collectsPointsOnBezierCurveWithFixedDistance(
                        pt1, pt2, pt3, pt4, distance)
                    for indexBezPt, eachBezPt in enumerate(bezPoints):
                        factor = indexBezPt / float(len(bezPoints))
                        width = lerp(startLib['width'], endLib['width'],
                                     factor)
                        height = lerp(startLib['height'], endLib['height'],
                                      factor)
                        angle = lerp(startLib['angle'], endLib['angle'],
                                     factor)

                        if mode == 'canvas':
                            save()
                            fill(*color)
                            translate(eachBezPt[0][0], eachBezPt[0][1])
                            rotate(angle)

                            if self.elementShape == 'Oval':
                                oval(-width / 2., -height / 2., width, height)
                            else:
                                rect(-width / 2., -height / 2., width, height)
                            restore()

                        else:
                            matrix = Identity
                            matrix = matrix.translate(eachBezPt[0][0],
                                                      eachBezPt[0][1])
                            matrix = matrix.rotate(math.radians(angle))

                            if self.elementShape == 'Oval':
                                robofabOval(phantomGlyph, 0, 0, width, height)
                            else:
                                robofabRect(phantomGlyph, 0, 0, width, height)
                            phantomGlyph[len(phantomGlyph) -
                                         1].transform(matrix)

        if mode == 'foreground':
            phantomGlyph.removeOverlap()
            flattenGlyph(phantomGlyph, 20)
            thresholdGlyph(phantomGlyph, 5)
            if version[0] == '2':
                glyph.getLayer('public.default',
                               clear=True).appendGlyph(phantomGlyph, (0, 0))
            else:
                glyph.getLayer('foreground',
                               clear=True).appendGlyph(phantomGlyph, (0, 0))