Beispiel #1
0
def makeSpecimen(rs):
        
    # Template 1
    template1 = Template(rs) # Create template of main size. Front page only.
    # Show grid columns and margins if rootStyle.showGrid or rootStyle.showGridColumns are True
    template1.grid(rs) 
    # Show baseline grid if rs.showBaselineGrid is True
    template1.baselineGrid(rs)
   
    # Create new document with (w,h) and fixed amount of pages.
    # Make number of pages with default document size.
    # Initially make all pages default with template2
    doc = Document(rs, autoPages=1, template=template1) 
    page = doc[1]
    """
    for (axis1, axis2), location in AXES_LOCATIONS:
        vCube = VariationCube(FONT_PATH, w=500, h=500, s='a', fontSize=86, dimensions={axis1:8, axis2:8}, location=location)
        page.place(vCube, 50, 160)
        page = doc.newPage()
    """
    vMasterFont = TTFont(FONT_PATH)
    for c in ((0.2, 0, 0.5), (1, 0, 0), (0, 0.1, 0)):
        for ix in range(15):
            for iy in range(15):
                location = {'line': int(random()*1000), 'open': int(random()*1000), 'rndi': int(random()*1000), 'rndo': int(random()*1000), 'sqri': int(random()*1000), 'sqro': int(random()*1000), 'wght': int(random()*1000)}
                drawGlyphPath(vMasterFont, 'a', 50 + ix * 500/8, 50 + iy * 500/8, location=location, s=0.09, fillColor=c)
        #page = doc.newPage()

    return doc
Beispiel #2
0
def makeAnimatiom():
    lineV, lineS = rnd()
    openV, openS = rnd()
    rndiV, rndiS = rnd()
    rndoV, rndoS = rnd()
    sqriV, sqriS = rnd()
    sqroV, sqroS = rnd()
    wghtV, wghtS = rnd()
    
    c1 = (random(), random(), random())
    c2 = (random(), random(), random())
    c3 = (random(), random(), random())

    vMasterFont = TTFont(FONT_PATH)
    for n in range(20):
        newPage(W, H)
        for cIndex, c in enumerate((c1, c2, c3)):
            location = {'line': lineV[cIndex], 'open': openV[cIndex], 'rndi': rndiV[cIndex], 'rndo': rndoS[cIndex], 'sqri': sqriV[cIndex], 'sqro': sqroV[cIndex], 'wght': wghtV[cIndex]}
            drawGlyphPath(vMasterFont, 'a', S*45, S*25, location=location, s=S*0.09, fillColor=c)
            setValue(lineV, lineS, cIndex)
            setValue(openV, openS, cIndex)
            setValue(rndiV, rndiS, cIndex)
            setValue(rndoV, rndoS, cIndex)
            setValue(sqriV, sqriS, cIndex)
            setValue(sqroV, sqroS, cIndex)
            setValue(wghtV, wghtS, cIndex)
Beispiel #3
0
    def _drawGlyphMarker(self, mx, my, glyphName, markerSize, location, strokeW=2):
        # Middle circle 
        fill(1)
        stroke(0)
        strokeWidth(strokeW)
        oval(mx-markerSize/2, my-markerSize/2, markerSize, markerSize)

        glyphPathScale = markerSize/self.font.info.unitsPerEm*3/4
        drawGlyphPath(self.font.ttFont, glyphName, mx, my-markerSize/4, location, s=glyphPathScale, fillColor=0)
Beispiel #4
0
def makeAnimatiom():
    lineV = rnd()  # ((angle, speed), (angle, speed), (angle, speed))
    openV = rnd()
    rndiV = rnd()
    rndoV = rnd()
    sqriV = rnd()
    sqroV = rnd()
    wghtV = rnd()

    c1, c2, c3 = [1, 0.1, 0, 0.7], [0, 1, 0, 0.7], [0, 0, 1, 0.7]

    vMasterFont = TTFont(FONT_PATH)
    for n in range(0, FRAMES, STEP):
        newPage(W, H)
        #fill(0)
        #rect(0, 0, W, H)
        for cIndex, c in enumerate((c1, c2, c3)):
            if cIndex == 0:
                c[0] = (1.5 + openV[cIndex][0] / 2) / 2
                #c[1] = (1+lineV[cIndex][0]/16)/2
                #c[2] = (1+wghtV[cIndex][0]/16)/2
            elif cIndex == 1:
                #c[0] = (1+rndoV[cIndex][0]/8)/2
                c[1] = (1.2 + rndiV[cIndex][0] / 2) / 2
                #c[2] = (1+sqroV[cIndex][0]/8)/2
            else:
                #c[0] = (1+rndoV[cIndex][0]/16)/2
                #c[1] = (1+wghtV[cIndex][0]/16)/2
                c[2] = (1.5 + wghtV[cIndex][0] / 2) / 2
            location = {
                'line': aValue(cIndex, lineV),
                'open': aValue(cIndex, openV),
                'rndi': aValue(cIndex, rndiV),
                'rndo': aValue(cIndex, rndoV),
                'sqri': aValue(cIndex, sqriV),
                'sqro': aValue(cIndex, sqroV),
                'wght': aValue(cIndex, wghtV)
            }
            for gIndex, glyph in enumerate(TEXT):
                # Only works by glyph name.
                drawGlyphPath(vMasterFont,
                              glyph,
                              S * 40 + S * gIndex * 6 * 9,
                              S * 22,
                              location=location,
                              s=S * 0.09,
                              fillColor=c)
Beispiel #5
0
    def draw(self, view, origin):
        c = self.doc.context

        p = pointOffset(self.oPoint, origin)
        p = self._applyScale(view, p)    
        px, py, _ = self._applyAlignment(p) # Ignore z-axis for now.

        if self.drawBefore is not None: # Call if defined
            self.drawBefore(self, view, p)

        fillColor = self.style.get('fill')
        if fillColor is not None:
            c.fill(fillColor)
        c.stroke(None)

        stepX = self.w / (self.sizeX+1)
        stepY = self.h / (self.sizeY+1)
        """Add more parametric layout behavior here."""
        for indexX in range(self.sizeX+1):
            for indexY in range(self.sizeY+1):
                ox = 30
                oy = 25
                ppx = ox + px + indexX * stepX
                ppy = oy + py + indexY * stepY
                if self.locations is not None:
                    location = choice(self.locations)
                else:
                    location = self.getRandomLocation()
                glyphPathScale = self.fontSize/self.font.info.unitsPerEm
                fillColor = self.style.get('textFill') or (0, 0, 0)
                drawGlyphPath(self.font.ttFont, self.glyphNames[0],
                              px, py, location, s=glyphPathScale,
                              fillColor=fillColor)
                if self.recipeAxes:
                    recipe = self.location2Recipe(location)
                    bs = c.newString(recipe, fontSize=4, fill=0)
                    w, h = bs.size()
                    c.text(bs, ppx - stepX/4, ppy - 24) # Bit of hack, we need the width of the glyph here.
                    if len(self.recipeAxes) > 3:
                        recipe = self.location2Recipe(location, 3, 6)
                        bs = c.newString(recipe, fontSize=4, fill=0)
                        w, h = bs.size()
                        c.text(bs, point=(ppx - stepX/4 + 30, ppy - 24)) # Bit of hack, we need the width of the glyph here.

        if self.drawAfter is not None: # Call if defined
            self.drawAfter(self, view, p)
Beispiel #6
0
def makeAnimatiom():
    lineV = rnd()  # ((angle, speed), (angle, speed), (angle, speed))
    openV = rnd()
    rndiV = rnd()
    rndoV = rnd()
    sqriV = rnd()
    sqroV = rnd()
    wghtV = rnd()

    c1, c2, c3 = [1, 0, 0], [1, 0, 0.5], [0.5, 0.1, 0.5]

    vMasterFont = TTFont(FONT_PATH)
    for n in range(0, FRAMES, STEP):
        newPage(W, H)
        fill(0)
        rect(0, 0, W, H)
        for cIndex, c in enumerate((c1, c2, c3)):
            if cIndex == 0:
                c[0] = (1 + lineV[cIndex][0]) / 2
                c[1] = (1 + openV[cIndex][0]) / 2
                c[2] = (1 + wghtV[cIndex][0]) / 2
            elif cIndex == 1:
                c[0] = (1 + rndoV[cIndex][0]) / 2
                c[1] = (1 + wghtV[cIndex][0]) / 2
                c[2] = (1 + sqriV[cIndex][0]) / 2
            else:
                c[0] = (1 + wghtV[cIndex][0]) / 2
                c[1] = (1 + sqroV[cIndex][0]) / 2
                c[2] = (1 + rndiV[cIndex][0]) / 2
            location = {
                'line': aValue(cIndex, lineV),
                'open': aValue(cIndex, openV),
                'rndi': aValue(cIndex, rndiV),
                'rndo': aValue(cIndex, rndoV),
                'sqri': aValue(cIndex, sqriV),
                'sqro': aValue(cIndex, sqroV),
                'wght': aValue(cIndex, wghtV)
            }
            drawGlyphPath(vMasterFont,
                          'a',
                          S * 45,
                          S * 25,
                          location=location,
                          s=S * 0.09,
                          fillColor=c)
Beispiel #7
0
def makeAnimatiom():
    lineV = [0, 100, 200]
    lineS = [100, -30, 60]
    openV = [500, 600, 700]
    openS = [50, -30, 140]
    rndiV = [200, 300, 100]
    rndiS = [120, -30, 120]
    rndoV = [700, 300, 400]
    rndoS = [-130, -40, -60]
    sqriV = [400, 300, 400]
    sqriS = [80, -30, -50]
    sqroV = [300, 500, 600]
    sqroS = [-40, -80, 60]
    wghtV = [500, 600, 400]
    wghtS = [-30, 50, 80]
    vMasterFont = TTFont(FONT_PATH)
    for n in range(100):
        newPage(W, H)
        for cIndex, c in enumerate(((0.2, 0, 0.5), (1, 0, 0), (0, 0.1, 0))):
            location = {
                'line': lineV[cIndex],
                'open': openV[cIndex],
                'rndi': rndiV[cIndex],
                'rndo': rndoS[cIndex],
                'sqri': sqriV[cIndex],
                'sqro': sqroV[cIndex],
                'wght': wghtV[cIndex]
            }
            drawGlyphPath(vMasterFont,
                          'a',
                          S * 45,
                          S * 25,
                          location=location,
                          s=S * 0.09,
                          fillColor=c)
            setValue(lineV, lineS, cIndex)
            setValue(openV, openS, cIndex)
            setValue(rndiV, rndiS, cIndex)
            setValue(rndoV, rndoS, cIndex)
            setValue(sqriV, sqriS, cIndex)
            setValue(sqroV, sqroS, cIndex)
            setValue(wghtV, wghtS, cIndex)
Beispiel #8
0
    def _drawGlyphMarker(self,
                         mx,
                         my,
                         glyphName,
                         fontSize,
                         location,
                         strokeW=2):
        # Middle circle
        fill(1)
        stroke(0)
        strokeWidth(strokeW)
        oval(mx - fontSize * self.R, my - fontSize * self.R,
             fontSize * 2 * self.R, fontSize * 2 * self.R)

        glyphPathScale = fontSize / self.font.info.unitsPerEm
        drawGlyphPath(self.font.ttFont,
                      glyphName,
                      mx,
                      my - fontSize / 4,
                      location,
                      s=glyphPathScale,
                      fillColor=0)