示例#1
0
def lettersToNames(txt):
    txt = txt.decode("utf-8")

    output = ""
    for char in txt:
        uni = ord(char)
        if UV2AGL.get(uni) == "space":
            pass
        elif UV2AGL.get(uni) == "None":
            print("None!!!", char)
        else:
            output += UV2AGL.get(uni) + " "
    return output
示例#2
0
    def drawContour(self):

        color = self.colorScheme.colorsRGB['contour']

        drawBot.save()
        drawBot.fontSize(self.captionSize)
        drawBot.font(self.captionFont)

        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            # interpolate
            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')
            glyph = RGlyph()
            glyph.name = g1.name
            glyph.unicode = g1.unicode
            glyph.interpolate(self.interpolationFactor, g1, g2)

            # draw contours
            drawBot.stroke(*color)
            drawBot.strokeWidth(self.contourStrokeWidth)
            drawBot.fill(None)
            B = drawBot.BezierPath()
            for contour in glyph.contours:
                contour.draw(B)
            drawBot.drawPath(B)

            # done glyph
            drawBot.translate(glyph.width, 0)

        drawBot.restore()
示例#3
0
    def drawGlyph(self):
        color = self.colorScheme.colorsRGB['glyph']
        drawBot.save()
        drawBot.fontSize(self.captionSize)
        drawBot.font(self.captionFont)
        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            # interpolate
            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')
            glyph = RGlyph()
            glyph.name = g1.name
            glyph.unicode = g1.unicode
            glyph.interpolate(self.interpolationFactor, g1, g2)

            # contours
            drawBot.fill(*color)
            B = drawBot.BezierPath()
            for contour in glyph.contours:
                contour.draw(B)
            drawBot.drawPath(B)

            # advance width
            if self.glyphWidthDraw:
                drawBot.save()
                drawBot.strokeWidth(self.glyphWidthStrokeWidth)
                drawBot.stroke(*color)
                drawBot.line((0, self.yBottom), (0, self.yTop))
                drawBot.restore()

            # glyph data
            if self.glyphDataDraw:
                h = self.captionSize * 1.5
                m = 40
                w = glyph.width - m * 2
                drawBot.save()
                drawBot.stroke(None)
                drawBot.fill(*color)
                y = self.yTop - h
                drawBot.textBox(glyph.name, (m, y, w, h))
                drawBot.textBox(str(glyph.unicode), (m, y, w, h), align='right')
                y = self.yBottom
                drawBot.textBox(str(int(glyph.width)), (m, y, w, h), align='center')
                drawBot.restore()

            # done glyph
            drawBot.translate(glyph.width, 0)

        # last margin
        if self.glyphWidthDraw:
            drawBot.strokeWidth(self.glyphWidthStrokeWidth)
            drawBot.stroke(*color)
            drawBot.line((0, self.yBottom), (0, self.yTop))

        # done
        drawBot.restore()
def getGlyphNamesFromString(my_string):
    #my_string = my_string.decode("utf-8")
    glyphNames = []
    for char in my_string:
        if char == "\n":
            glyphNames.append(r"\n")
        else:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)
            if glyphName:
                glyphNames.append(glyphName)
    return glyphNames
示例#5
0
    def textLength(self):
        w = 0
        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            # interpolate
            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')
            glyph = RGlyph()
            glyph.name = g1.name
            glyph.unicode = g1.unicode
            glyph.interpolate(self.interpolationFactor, g1, g2)

            w += glyph.width

        return w
示例#6
0
 def drawComponent(self):
     color = self.colorScheme.colorsRGB['component']
     tempName = '_tmp_'
     drawBot.save()
     for char in self.txt:
         uni = ord(char)
         glyphName = UV2AGL.get(uni)
         glyph = self.font[glyphName]
         drawBot.fill(*color + (0.5,))
         drawBot.stroke(*color)
         if len(glyph.components):
             B = drawBot.BezierPath()
             for component in glyph.components:
                 component.draw(B)
             drawBot.drawPath(B)
         # done glyph
         drawBot.translate(glyph.width, 0)
     drawBot.restore()
示例#7
0
 def drawAnchor(self):
     r = self.anchorSize * 0.5
     color = self.colorScheme.colorsRGB['anchor']
     drawBot.save()
     drawBot.strokeWidth(self.anchorStrokeWidth)
     drawBot.stroke(*color)
     drawBot.fill(None)
     for char in self.txt:
         uni = ord(char)
         glyphName = UV2AGL.get(uni)
         glyph = self.font[glyphName]
         if len(glyph.anchors):
             for anchor in glyph.anchors:
                 x, y = anchor.x, anchor.y
                 drawBot.oval(x-r, y-r, r*2, r*2)
                 drawBot.line((x-r, anchor.y), (x+r, anchor.y))
                 drawBot.line((anchor.x, y-r), (anchor.x, y+r))
         drawBot.translate(glyph.width, 0)
     drawBot.restore()
示例#8
0
    def drawLayer(self):

        steps = 3
        alpha = 0.2 + 0.8 / (steps + 1)
        color = self.colorScheme.colorsRGB['layer']

        drawBot.save()

        # drawBot.fill(None)
        # drawBot.stroke(*color)
        # drawBot.strokeWidth(self.layerStrokeWidth)

        color += (alpha,)
        drawBot.fill(*color)
        drawBot.stroke(None)

        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')

            layerGlyphs = []
            for i in range(steps):
                factor = i * 1.0 / (steps - 1)
                g3 = RGlyph()
                g3.name = g1.name
                g3.unicode = g1.unicode
                g3.interpolate(factor, g1, g2)
                layerGlyphs.append(g3)

            for g in layerGlyphs:
                B = drawBot.BezierPath()
                g.draw(B)
                drawBot.drawPath(B)

            drawBot.translate(g2.width, 0)

        drawBot.restore()
示例#9
0
    def drawBPoint(self):

        r1 = self.bPointSize * 0.5
        r2 = self.pointSize * 0.5

        color = self.colorScheme.colorsRGB['bPoint']
        drawBot.save()
        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            # interpolate
            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')
            glyph = RGlyph()
            glyph.name = g1.name
            glyph.unicode = g1.unicode
            glyph.interpolate(self.interpolationFactor, g1, g2)

            for c in glyph.contours:
                for pt in c.bPoints:
                    x, y = pt.anchor
                    xIn,  yIn  = pt.bcpIn
                    xOut, yOut = pt.bcpOut

                    drawBot.fill(*color)
                    drawBot.stroke(None)
                    drawBot.oval(x - r1, y - r1, r1 * 2, r1 * 2)
                    if not self.layers['point']:
                        drawBot.oval(x + xIn - r2, y + yIn - r2, r2 * 2, r2 * 2)
                        drawBot.oval(x + xOut - r2, y + yOut - r2, r2 * 2, r2 * 2)

                    drawBot.fill(None)
                    drawBot.stroke(*color)
                    drawBot.strokeWidth(5)
                    drawBot.line((x, y), (x + xIn, y + yIn))
                    drawBot.line((x, y), (x + xOut, y + yOut))

            drawBot.translate(glyph.width, 0)
        drawBot.restore()
示例#10
0
    def drawSegment(self):

        color = self.colorScheme.colorsRGB['segment']
        r = self.bPointSize * 0.5        

        drawBot.save()
        drawBot.fontSize(self.captionSize)
        drawBot.font(self.captionFont)
        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            # interpolate
            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')
            glyph = RGlyph()
            glyph.name = g1.name
            glyph.unicode = g1.unicode
            glyph.interpolate(self.interpolationFactor, g1, g2)

            # draw segment contours
            drawBot.stroke(*color)
            drawBot.strokeWidth(self.segmentStrokeWidth)
            drawBot.fill(None)

            B = drawBot.BezierPath()
            glyph.draw(B)
            drawBot.drawPath(B)

            # draw segment points
            drawBot.stroke(None)
            drawBot.fill(*color)
            for x, y in B.onCurvePoints:
                drawBot.oval(x - r, y - r, r * 2, r * 2)

            drawBot.translate(glyph.width, 0)

        drawBot.restore()
示例#11
0
    def drawPoint(self):
        r = self.pointSize * 0.5
        color = self.colorScheme.colorsRGB['point']
        drawBot.save()
        drawBot.fill(*color)
        for char in self.txt:
            uni = ord(char)
            glyphName = UV2AGL.get(uni)

            # interpolate
            g1 = self.font[glyphName].getLayer('regular')
            g2 = self.font[glyphName].getLayer('bold')
            glyph = RGlyph()
            glyph.name = g1.name
            glyph.unicode = g1.unicode
            glyph.interpolate(self.interpolationFactor, g1, g2)

            for c in glyph.contours:
                for pt in c.points:
                    x, y = pt.x, pt.y
                    drawBot.oval(x-r, y-r, r*2, r*2)
            drawBot.translate(glyph.width, 0)
        drawBot.restore()
示例#12
0
def char2glyphName(char):
    uni = ord(char)
    glyphName = UV2AGL.get(uni)        
    return glyphName
示例#13
0
def char2glyphName(char):
    # char = char.decode("utf-8")
    uni = ord(char)
    glyphName = UV2AGL.get(uni)        
    return glyphName
示例#14
0
size(1024, 768)
translate(30, 680)
stroke(1, 0, 0)
strokeWidth(30)
fill(None)

# txt = 'uma frase \ncom 3 \nlinhas'
txt = u'Esta é uma \nfrase de \ntrês linhas \n?!'
txt2 = u"the design is final visual form maybe \n       as  much to do with working against \n rules and logic as with working with them"

entreLinha = -50
larguraLinha = 0
linha = 0

for char in txt2:
    if char == "\n":
        translate(-larguraLinha, entreLinha)
        larguraLinha = 0
    else:
        uni = ord(char)
        glyphName = UV2AGL.get(uni)
        if glyphName:
            save()
            scale(s)
            drawGlyph(f[glyphName])
            w = f[glyphName].width * s
            larguraLinha += w
            restore()
            translate(w, 0)
saveImage(["firstImage.svg"])