Пример #1
0
def makeFlash(s, w, h, px, py, color1=None, color2=None, flashSpeed=4):
    if color1 is None:
        r1, g1, b1 = 1, 0, 0
    else:
        r1, g1, b1 = color1
    if color2 is None:
        r2, g2, b2 = 0.2, 0, 0
    else:
        r2, g2, b2 = color2
    for n in range(flashSpeed):
        context.newPage(w, h)
        context.fill(0)
        context.rect(0, 0, w, h)
        drawString(s, px, py, 'PropSingleBold', (r1, g1, b1, 0.2))
        drawString(s, px, py, 'PropSingleMedium', (r1, g1, b1, 0.5))
        if HIGHLIGHT:
            drawString(s, px, py, 'PropSingle',
                       (r1 * 0.9, g1 * 0.9, b1 * 0.9, 1))
            drawString(s, px - 1, py + 1, 'PropSingleLight', (r1, g1, b1, 1))
        else:
            drawString(s, px, py, 'PropSingle', (r1, g1, b1, 1))

    for n in range(flashSpeed):
        context.newPage(w, h)
        context.fill(0)
        context.rect(0, 0, w, h)
        drawString(s, px, py, 'PropSingleBold', (r2, g2, b2, 0.2))
        drawString(s, px, py, 'PropSingleMedium', (r2, g2, b2, 0.5))
        if HIGHLIGHT:
            drawString(s, px, py, 'PropSingle',
                       (r2 * 0.9, g2 * 0.9, b2 * 0.9, 1))
            drawString(s, px - 1, py + 1, 'PropSingleLight', (r2, g2, b2, 1))
        else:
            drawString(s, px, py, 'PropSingle', (r2, g2, b2, 1))
Пример #2
0
def drawSierpinskiSquare(px, py, w, maxW):
    if w < 1:
        return
    for x in range(3):
        for y in range(3):
            if x == 1 and y == 1:
                context.fill(max(0, 0.75 - w/100))
                context.rect(px+w, py+w, w, w)
            elif px <= maxW and py <= maxW:
                drawSierpinskiSquare(px+x*w, py+y*w, w/3, maxW)
Пример #3
0
def makeRunningLeds(s, w, h, px, py, speed=1):
    context.newPage(w, h)
    context.fill(0)
    context.rect(0, 0, w, h)
    drawString(s, px, py, 'PropSingleBoldItalic', (0.3, 0, 0, 1))
    drawString(s, px, py, 'PropSingleMediumItalic', (0.6, 0.0, 0, 1))
    if HIGHLIGHT:
        drawString(s, px, py, 'PropSingleItalic', (0.8, 0, 0, 1))
        drawString(s, px - 1, py + 1, 'PropSingleLightItalic', (1, 0, 0, 1))
    else:
        drawString(s, px, py, 'PropSingleItalic', (1, 0, 0, 1))
def drawLayers(fss):
    # Draw this layer in a couple of frame
    _, h = fss[0].size()
    h += padding
    for n in range(frameLength):
        context.newPage(W, h)
        context.fill(
            (backgroundColor[0], backgroundColor[1], backgroundColor[2]))
        context.rect(0, 0, W, h)
        for fs in fss:
            context.text(fs, (2 * padding, -padding))
Пример #5
0
def drawLayers(fss1, fss2):
    # Draw this layer in a couple of frame
    context.newPage(W, H)
    context.frameDuration(fd)
    context.fill((backgroundColor[0], backgroundColor[1], backgroundColor[2]))
    context.rect(0, 0, W, H)
    y = 3 * padding
    offsetY = -100
    for fs in fss1:
        context.text(fs, (2 * padding, y + offsetY + 310))
    for fs in fss2:
        context.text(fs, (2.35 * padding, y + offsetY + 5))
Пример #6
0
def pathFilter(e, path, view):
    r = 24
    for x in range(0, e.w * 4, 30):
        for y in range(0, e.h * 2, 30):
            # Use the glyph to query for color at this position.
            if e.glyph.onBlack((x, y)):
                context.fill((random(), random(),
                              random()))  # Color as one tuple, in context API
                context.oval(x - r / 2, y - r / 2, r, r)
            else:
                context.fill((0, 1, 0))  # Color as one tuple, in context API
                context.rect(x - r / 4, y - r / 4, r / 2, r / 2)
Пример #7
0
def drawSierpinskiSquare(px, py, w, maxW):
    if w < 1:
        return
    for x in range(3):
        for y in range(3):
            if x == 1 and y == 1:
                c = max(0, 0.5 - 0.5 * w / W)
                context.fill((random(), c, c))
                #print x, y, w, 0.5*w/W
                context.rect(px + w, py + w, w, w)
            elif px <= maxW and py <= maxW:
                drawSierpinskiSquare(px + x * w, py + y * w, w / 3.0, maxW)
Пример #8
0
def drawLayers(fss, fontSize):
    # Draw this layer in a couple of frame
    offsetX = 0
    offsetY = -20
    _, h = fss[0].size()
    h += M
    context.newPage(W, h)
    context.fill(Background_Color)
    context.rect(0, 0, W, h)
    for fs in fss:
        context.text(fs, (M + offsetX, M + offsetY))
        offsetX += Layer_Offset_X
        offsetY += Layer_Offset_Y
def drawLayers(layers):
    # Draw this layer in a couple of frame
    # Calculate the pixel size. 100 units on 1000 Em.
    #pixelSize =
    x = M
    y = 0
    _, h = layers[0]['text'].size()
    h += M / 2
    context.newPage(W, h)
    context.fill(Background_Color)
    context.rect(0, 0, W, h)
    for layerIndex, layer in sorted(layers.items()):
        context.text(layer['text'], (x, y))
        x += layer['offsetX']
        y += layer['offsetY']
Пример #10
0
def drawLayers(fss, frame, dx, dy, doNewPage):
    # Draw this layer in a couple of frame
    if doNewPage:
        context.newPage(W, H)
        context.fill(0)
        context.rect(0, 0, W, H)
        context.frameDuration(fd)
    #context.fill(backgroundColor[0],backgroundColor[1],backgroundColor[2])
    #context.rect(0, 0, W, H)
    y = 2*padding + dy
    for fsSingle, fsDouble in fss:
        if frame < frames/2:
            fs = fsSingle
        else:
            fs = fsDouble
        context.text(fs, (dx*2*padding, y))
Пример #11
0
def makeAnimation():
    axes = vMasterFont.axes

    print 'Variable A X E S'
    for axisName, (minValue, defaultValue,
                   maxValue) in vMasterFont.axes.items():
        print axisName, 'minValue', minValue, 'defaultValue', defaultValue, 'maxValue', maxValue

    location = getDefaultLocation(axes)

    if TERMINAL_VALUES_S[TerminalValue] != 'None':
        location[TERMINALS[TerminalShape]] = TERMINAL_VALUES[TerminalValue]
    if SKELETON_VALUES[SkeletonValue] != 'None':
        location[SKELETONS[SkeletonShape]] = SKELETON_VALUES[SkeletonValue]
    if BLEND_VALUES[BlendValue] != 'None':
        location[BLENDS[BlendShape]] = BLEND_VALUES[BlendValue]
    location['wmx2'] = WEIGHT_VALUES[WeightValue - 2]

    #for sequence in getProofSequences():
    #    for location in getLocations(axes, sequence): # Expand into a sequence of locations.
    #        newPage(W, H)
    context.fill(1)
    context.rect(0, 0, W, H)
    context.save()
    textColor = 0
    for gIndex, glyph in enumerate(TEXT):
        # Only works by glyph name.
        drawGlyphPath(vMasterFont.ttFont,
                      glyph,
                      S * 40 + S * gIndex * 6 * 9,
                      S * 22,
                      location=location,
                      s=S * 0.04,
                      fillColor=textColor)
        drawGlyphPath(vMasterFont.ttFont,
                      glyph,
                      S * 40 + S * gIndex * 6 * 9,
                      S * 22,
                      location=location,
                      s=S * 0.04,
                      fillColor=textColor)
    # TODO To be extended PageBot
    #drawGlyphPaths(vMasterFont, TEXT, x=S*40 + S*gIndex*6*9, y=S*22, location=location, fontSize=S*0.04, fillColor=textColor)
    context.restore()
    context.fill(0)
    context.fontSize(24)
Пример #12
0
def draw(w):
    u"""
      Draw 3 lines of text: the boundaries of with the width axis
       and the interpolated width from the slider value.
      If the slider goes of the extremes, then the middle line stops
       at the boundary width.
    """
    d = fitVariableWidth(f, HEADLINE, w, HEADLINE_SIZE,
                         condensedLocation, wideLocation)

    c.newPage(W, H)
    c.fill(1)
    c.rect(0, 0, W, H)
    c.text(d['condensedFs'], (PADDING, 50))
    c.text(d['fs'], (PADDING, 100))
    c.text(d['wideFs'], (PADDING, 150))
    c.fill(None)
    c.stroke(0)
    c.line((PADDING, PADDING), (PADDING, H-PADDING))
    c.line((PADDING+d['condensedWidth'], PADDING),
         (PADDING+d['condensedWidth'], H-PADDING))
    c.line((PADDING+d['width'], PADDING),
         (PADDING+d['width'], H-PADDING))
    c.line((PADDING+d['wideWidth'], PADDING),
         (PADDING+d['wideWidth'], H-PADDING))
    c.stroke(None)
    c.fill(0)
    c.text('%d %0.2f' % (round(d['condensedWidth']),
                         d['condensedLocation']['wdth']),
           (PADDING + d['condensedWidth'] + 5, PADDING))
    c.text('%d %0.2f' % (round(d['width']), d['location']['wdth']),
           (PADDING + d['width'] + 5, PADDING))
    c.text('%d %0.2f' % (round(d['wideWidth']), d['wideLocation']['wdth']),
           (PADDING + d['wideWidth'] + 5, PADDING))
    c.stroke(1, 0, 0)
    c.line((PADDING+w, PADDING), (PADDING+w, H-PADDING))
    c.stroke(None)
    c.fill(1, 0, 0)
    c.text('Column %d' % w, (PADDING+w+5, H-PADDING-5))
Пример #13
0
            context.text(dFixed['fs'], (PADDING + M, y - PADDING - M))
        else:
            context.text(d['wideFs'], (PADDING + M, y - PADDING - M))


if INTERACTIVE:
    Variable(
        [
            #dict(name='ElementOrigin', ui='CheckBox', args=dict(value=False)),
            dict(name='Width',
                 ui='Slider',
                 args=dict(
                     minValue=PADDING, value=200, maxValue=W - 2 * PADDING))
        ],
        globals())

    draw(Width)
else:
    pageFrame = None
    angle = 0
    while angle < 360:
        context.newPage(W, H)
        context.fill(0.8)
        context.rect(0, 0, W, H)
        dx = sin(radians(angle)) * 0.5 + 0.5
        w = W / 2 + (W - 2 * PADDING - W / 2) * dx
        draw(w, H - PADDING, True)
        draw(w, (H - PADDING) / 2, False)
        angle += 360 / FRAMES
    context.saveImage('_export/fitVariableColumns.gif')
Пример #14
0
def buildCoverPages1(w, h, v):

    M = 10

    # Page 66
    context.newPage(w, h)

    context.fill(0.1)
    context.rect(0, 0, w, h)

    c1 = (0.2, 0.7, 1)
    c2 = 0.8

    y = h - M

    # Title of cover, make it fit in with and add shadow
    coverTitleStyle = dict(font='Upgrade-Hairline', fontSize=100, textFill=c1)
    bs = context.newString('THE', style=coverTitleStyle, w=w - M)
    bx, by, bw, bh = bs.bounds()
    context.text(bs, (w / 2 - (bw + bx) / 2, y - bh + by))

    y -= bh - by + M / 2

    coverTitleStyle = dict(font='Upgrade-Thin', fontSize=100, textFill=c1)
    bs = context.newString('LONGEST', style=coverTitleStyle, w=w - 1.5 * M)
    bx, by, bw, bh = bs.bounds()
    context.text(bs, (w / 2 - (bw + bx) / 2, y - bh + by))

    y -= bh - by + M / 2

    # Title of cover, make it fit in with and add shadow
    coverTitleStyle = dict(font='Upgrade-ExtraLight',
                           fontSize=100,
                           textFill=c1,
                           rTracking=0.05)
    bs = context.newString('MELLIFLUOUSLY',
                           style=coverTitleStyle,
                           w=w - 1.5 * M)
    bx, by, bw, bh = bs.bounds()
    context.text(bs, (w / 2 - (bw + bx) / 2, y - bh + by))

    y -= bh - by + M / 2

    coverTitleStyle = dict(font='Upgrade-Light',
                           fontSize=100,
                           textFill=c1,
                           rTracking=0.07)
    bs = context.newString('supercalifragilisticexpialidociously'.upper(),
                           style=coverTitleStyle,
                           w=w - 2 * M)
    bx, by, bw, bh = bs.bounds()
    context.text(bs, (w / 2 - (bw + bx) / 2, y - bh + by))

    y -= bh - by + M / 2

    coverTitleStyle = dict(font='Upgrade-Book',
                           fontSize=100,
                           textFill=c1,
                           rTracking=0.07)
    bs = context.newString(
        'pneumonoultramicroscopicsilicovolcanoconiosis'.upper(),
        style=coverTitleStyle,
        w=w - 2 * M)
    bx, by, bw, bh = bs.bounds()
    context.text(bs, (w / 2 - (bw + bx) / 2, y - bh + by))

    y -= bh - by + M / 2

    coverTitleStyle = dict(font='Upgrade-Light', fontSize=100, textFill=c1)
    bs = context.newString('INTERMIXED', style=coverTitleStyle, w=w - 1.5 * M)
    bx, by, bw, bh = bs.bounds()
    context.text(bs, (w / 2 - (bw + bx) / 2, y - bh + by))

    y -= bh - by + 2 * M

    # Title of cover, make it fit in with and add shadow
    coverTitleStyle = dict(font='Upgrade-Light', fontSize=100, textFill=c2)
    bs = context.newString('MATTHEW', style=coverTitleStyle, w=w - 1.5 * M)
    bx, by, bw, bh = bs.bounds()
    context.text(bs, (w / 2 - (bw + bx) / 2, y - bh + by))

    y -= bh - by + M / 2

    # Title of cover, make it fit in with and add shadow
    coverTitleStyle = dict(font='Upgrade-Light', fontSize=100, textFill=c2)
    bs = context.newString('DOW', style=coverTitleStyle, w=w - M)
    bx, by, bw, bh = bs.bounds()
    context.text(bs, (w / 2 - (bw + bx) / 2, y - bh + by))
Пример #15
0
    def draw(self):

        # Try to use TYPETR-Bitcount. Only is instsalled in the system.
        # See samples at https://bitcount.typenetwork.com
        # Order a license at: https://store.typenetwork.com/foundry/typetr/fonts/bitcount
        USE_BITCOUNT = True

        LETTERS = 'ABCEFGHIJKLMNOPQRSTUVWXYZ'

        Frames = 80
        W = H = 500

        IMAGE_PATH = '_export/HorizonWorld.gif'
        if not USE_BITCOUNT or not 'BitcountMonoDouble-RegularCircle' in context.installedFonts(
        ):
            fontNames = ['Georgia-Bold', 'Georgia']
        else:
            fontNames = []
            for fontName in installedFonts():
                if 'BitcountMono' in fontName and not 'Italic' in fontName:
                    fontNames.append(fontName)

        letters = []
        for n in range(10):
            c = choice(LETTERS)
            x = 0
            y = 15
            z = 20 + int(random() * 500)

            x = 1 / z + random() * 100 - 100
            cc = random() * 0.8 + 0.1, random() * 0.1, random() * 0.8 * 0.1
            f = choice(fontNames)
            letters.append((c, f, x, y, z, cc))

        for n in range(Frames):
            context.newPage(W, H)
            context.fill(0.8)
            context.rect(0, 0, W, H)
            for c, f, x, y, z, (r, g, b) in letters:
                #y = y/z
                context.fill(
                    (r, g, b)
                )  # Needs tuple, instead of separate r, g, b as in DrawBot
                context.font(f)
                context.stroke(None)
                fSize = min(200, 40000 / z)
                context.fontSize(fSize)
                context.text(c, (x + 250, y + 250 - fSize / 2))

                context.fill(None)
                context.strokeWidth(0.5)
                context.stroke(0.5)
                context.line((0, 250), (500, 250))

                context.fill(
                    (1, 1, 1, 0.4)
                )  # Needs tuple, instead of separate r, g, b as in DrawBot
                context.rect(0, 0, W, H / 2 - 1)

                for n in range(0, 500, 10):
                    context.fill(None)
                    context.stroke(1)
                    y = W / 2 - 2 - n * 0.4
                    lineThickness = (random() * 3 + 0.5) * (H / 2 - y) / 10
                    context.strokeWidth(lineThickness)
                    context.line((0, y - lineThickness / 2),
                                 (W, y - lineThickness / 2))

        context.saveImage(IMAGE_PATH)
Пример #16
0
        if w < fixedWidth:
            c.text(d['condensedFs'], (PADDING + M, y - PADDING - M))
        elif w < maxWidth:
            c.text(dFixed['fs'], (PADDING + M, y - PADDING - M))
        else:
            c.text(d['wideFs'], (PADDING + M, y - PADDING - M))


if INTERACTIVE:
    #dict(name='ElementOrigin', ui='CheckBox', args=dict(value=False)),
    c.Variable([
        dict(name='Width',
             ui='Slider',
             args=dict(minValue=PADDING, value=200, maxValue=W - 2 * PADDING))
    ], globals())

    draw(Width)
else:
    pageFrame = None
    angle = 0
    while angle < 360:
        c.newPage(W, H)
        c.fill(0.8)
        c.rect(0, 0, W, H)
        dx = sin(radians(angle)) * 0.5 + 0.5
        w = W / 2 + (W - 2 * PADDING - W / 2) * dx
        draw(w, H - PADDING, True)
        draw(w, (H - PADDING) / 2, False)
        angle += 360 / FRAMES
    c.saveImage('_export/fitVariableColumns.gif')
Пример #17
0
def buildCoverPages2(w, h, v):

    M = 30
    for pn in range(v):
        # Page 66
        context.newPage(w, h)

        context.fill(0.1)
        context.rect(0, 0, w, h)

        c1 = (0.2, 0.7, 1)
        c2 = 0.8

        y = h - M

        # Title of cover, make it fit in with and add shadow
        coverTitleStyle = dict(font='Upgrade-Book',
                               fontSize=100,
                               textFill=1,
                               rTracking=0.2,
                               openTypeFeatures=dict(smcp=True))
        bs = context.newString('One Lightyear Equals',
                               style=coverTitleStyle,
                               w=w - 2 * M)
        bx, by, bw, bh = bs.bounds()
        context.text(bs, (w / 2 - (bw + bx) / 2, y - bh + by))

        y -= 100

        styleColors = ('Upgrade-UltraBlack', 'Upgrade-ExtraBlack',
                       'Upgrade-Black', 'Upgrade-Semibold', 'Upgrade-Medium',
                       'Upgrade-Regular', 'Upgrade-Book', 'Upgrade-Light',
                       'Upgrade-ExtraLight', 'Upgrade-Thin',
                       'Upgrade-Hairline')
        if v == 1:
            R = 22
        else:
            R = math.sin(math.radians(pn * 360 / v)) * 16
        for index, name in enumerate(styleColors):
            coverTitleStyle = dict(font=name,
                                   fontSize=100,
                                   textFill=list(c1) +
                                   [index / len(styleColors)],
                                   rTracking=0.2,
                                   rLeading=0.9,
                                   openTypeFeatures=dict(tnum=True))
            bs = context.newString('9460\n7304\n7258\n0800\n512',
                                   style=coverTitleStyle,
                                   w=w - M / 2)
            bx, by, bw, bh = bs.bounds()
            context.text(bs, (w / 2 - (bw + bx) / 2 + (random() * R - R / 2),
                              -by + 1.5 * M + (random() * R - R / 2)))

        coverTitleStyle = dict(font='Upgrade-ExtraLight',
                               fontSize=100,
                               textFill=c1,
                               rTracking=0.05,
                               rLeading=0.9)
        bs = context.newString('mm', style=coverTitleStyle, w=w / 5)
        bx, by, bw, bh = bs.bounds()
        context.text(bs, (w * 4 / 6 + M, -by + 3.2 * M))

        coverTitleStyle = dict(font='Upgrade-Regular',
                               fontSize=100,
                               textFill=c2,
                               rTracking=0.2,
                               rLeading=1.2,
                               openTypeFeatures=dict(smcp=True))
        bs = context.newString('Design\nDesign\nSpace',
                               style=coverTitleStyle,
                               w=w / 5)
        bx, by, bw, bh = bs.bounds()
        context.text(bs, (w * 4 / 6 + M, -by + 0.75 * M))
Пример #18
0
## https://github.com/thomgb/drawbot
## download my DrawBot: https://www.dropbox.com/s/xsu1mz89ipo5x3y/DrawBot.dmg?dl=0
from pagebot.contexts import defaultContext as context
from pagebot.contributions.filibuster.blurb import Blurb

#text = Blurb().getBlurb('article_ankeiler', noTags=True)
text = """Considering the fact that the application allows individuals to call a phone number and leave a voice mail, which is automatically translated into a tweet with a hashtag from the country of origin."""

t = context.newString(text,
                      style=dict(fontSize=30,
                                 hyphenationHead=4,
                                 hyphenationTail=3))

w = 554  # change width to see other hyphenations

W = 1000
H = 2000
context.newPage(W, H)

context.hyphenation(True)
context.textBox(t, (100, 600, w, 400))
context.fill(None)
context.stroke(0)
context.rect(100, 600, w, 600)

context.hyphenation(False)
context.textBox(t, (100, 100, w, 400))
context.fill(None)
context.stroke(0)
context.rect(100, 100, w, 600)
Пример #19
0
    def draw(self, page, x, y):
        u"""Draw the circle info-graphic, showing most info about the variation font as can be interpreted from the file."""
        c.fill(0.9)
        c.stroke(None)
        mx = x + self.w / 2
        my = y + self.h / 2

        # Gray circle that defines the area of
        c.oval(x, y, self.w, self.h)

        # Draw axis spikes first, so we can cover them by the circle markers.
        axes = self.font.axes
        fontSize = self.style.get('fontSize', self.DEFAULT_FONT_SIZE)

        # Calculate sorted relative angle pairs.
        xAngles = {}  # X-ref, key is angle, value is list of axisName
        for axisName in axes:
            angle = globals()[axisName]
            if not angle in xAngles:  # Ignore overlapping
                xAngles[angle] = axisName
        #print xAngles
        sortedAngles = sorted(xAngles)
        anglePairs = []
        a1 = None
        for a2 in sortedAngles:
            if a1 is not None:
                if abs(a2 - a1) < 35:
                    anglePairs.append((a1, a2))
            a1 = a2

        # Draw name of the font
        c.fill(0)
        c.text(
            c.newString(self.font.info.familyName,
                        style=dict(font=self.style['labelFont'],
                                   fontSize=self.style['titleFontSize'])),
            (x - fontSize / 2, y + self.h + fontSize / 4))

        # Draw spokes
        c.fill(None)
        c.stroke(0.7)
        c.strokeWidth(1)
        # Gray on full circle
        c.newPath()
        for axisName, angle in self.angles.items():
            markerX, markerY = self._angle2XY(angle, self.w / 2)
            c.moveTo((mx - markerX, my - markerY))
            c.lineTo((mx + markerX, my + markerY))
        c.drawPath()

        # Black on range of axis.
        c.stroke(0)
        c.newPath()
        for axisName, angle in self.angles.items():
            markerX, markerY = self._angle2XY(angle, self.w / 2)
            c.moveTo((mx, my))
            c.lineTo((mx + markerX, my + markerY))
        c.drawPath()

        # Pair combinations
        if anglePairs:
            c.newPath()
            for a1, a2 in anglePairs:
                markerX1, markerY1 = self._angle2XY(a1, self.w / 2)
                markerX2, markerY2 = self._angle2XY(a2, self.w / 2)
                c.moveTo((mx + markerX1, my + markerY1))
                c.lineTo((mx + markerX2, my + markerY2))
                c.moveTo((mx + markerX1 * INTERPOLATION,
                          my + markerY1 * INTERPOLATION))
                c.lineTo((mx + markerX2 * INTERPOLATION,
                          my + markerY2 * INTERPOLATION))
            c.stroke(0, 0, 1)
            c.fill(None)
            c.drawPath()

        # Draw default glyph marker in middle.
        glyphName = self.glyphNames[0]
        defaultLocation = {}
        self._drawGlyphMarker(mx,
                              my,
                              glyphName,
                              fontSize,
                              defaultLocation,
                              strokeW=3)

        # Draw DeltaLocation circles.
        for axisName, (minValue, defaultValue, maxValue) in axes.items():
            angle = self.angles[axisName]
            # Outside maxValue
            location = {axisName: maxValue}
            markerX, markerY = self._angle2XY(angle, self.w / 2)
            self._drawGlyphMarker(mx + markerX, my + markerY, glyphName,
                                  fontSize / 2, location)

            # Interpolated DeltaLocation circles.
            location = {
                axisName: minValue + (maxValue - minValue) * INTERPOLATION
            }
            markerX, markerY = self._angle2XY(angle, self.w / 4)
            self._drawGlyphMarker(mx + markerX * INTERPOLATION * 2,
                                  my + markerY * INTERPOLATION * 2, glyphName,
                                  fontSize / 2, location)

            # If there are any pairs, draw the interpolation between them
            #if anglePairs:
            #    for a1, a2 in anglePairs:
            #        axis1 =

        # helper function:
        def makeAxisName(axisName):
            if not axisName in ('wght', 'wdth', 'opsz'):
                return axisName.upper()
            return axisName

        # Draw axis names and DeltaLocation values
        if self.showAxisNames:
            for axisName, (minValue, defaultValue, maxValue) in axes.items():
                angle = self.angles[axisName]
                location = {axisName: maxValue}
                valueFontSize = self.style.get('valueFontSize', 12)
                axisNameFontSize = self.style.get('axisNameFontSize', 12)
                markerX, markerY = self._angle2XY(angle, self.w / 2)
                fs = c.newString(
                    makeAxisName(axisName),
                    style=dict(font=self.style.get('labelFont', 'Verdana'),
                               fontSize=axisNameFontSize,
                               fill=self.style.get('axisNameColor', 0)))
                tw, th = c.textSize(fs)
                c.fill(0.7, 0.7, 0.7, 0.6)
                c.stroke(None)
                c.rect(mx + markerX - tw / 2 - 4,
                       my + markerY - axisNameFontSize / 2 - th * 1.5 - 4,
                       tw + 8, th)
                c.text(fs, (mx + markerX - tw / 2,
                            my + markerY - axisNameFontSize / 2 - th * 1.5))

                # DeltaLocation master value
                if maxValue < 10:
                    sMaxValue = '%0.2f' % maxValue
                else:
                    sMaxValue = ` int(round(maxValue)) `
                fs = c.newString(
                    sMaxValue,
                    style=dict(font=self.style.get('labelFont', 'Verdana'),
                               fontSize=valueFontSize,
                               fill=self.style.get('axisValueColor', 0)))
                tw, th = c.textSize(fs)
                c.fill(0.7, 0.7, 0.7, 0.6)
                c.stroke(None)
                c.rect(mx + markerX - tw / 2 - 4,
                       my + markerY + valueFontSize / 2 + th * 1.5 - 4, tw + 8,
                       th)
                c.text(fs, (mx + markerX - tw / 2,
                            my + markerY + valueFontSize / 2 + th * 1.5))

                # DeltaLocation value
                interpolationValue = minValue + (maxValue -
                                                 minValue) * INTERPOLATION
                if interpolationValue < 10:
                    sValue = '%0.2f' % interpolationValue
                else:
                    sValue = ` int(round(interpolationValue)) `
                fs = c.newString(
                    sValue,
                    style=dict(font=self.style.get('labelFont', 'Verdana'),
                               fontSize=valueFontSize,
                               fill=self.style.get('axisValueColor', 0)))
                tw, th = c.textSize(fs)
                c.fill(0.7, 0.7, 0.7, 0.6)
                c.stroke(None)
                c.rect(
                    mx + markerX * INTERPOLATION - tw / 2 - 4, my +
                    markerY * INTERPOLATION + valueFontSize / 2 + th * 1.5 - 4,
                    tw + 8, th)
                c.text(
                    fs,
                    (mx + markerX * INTERPOLATION - tw / 2, my +
                     markerY * INTERPOLATION + valueFontSize / 2 + th * 1.5))

                # DeltaLocation value
                if minValue < 10:
                    sValue = '%0.2f' % minValue
                else:
                    sValue = ` int(round(minValue)) `
                fs = c.newString(
                    sValue,
                    style=dict(font=self.style.get('labelFont', 'Verdana'),
                               fontSize=valueFontSize,
                               fill=self.style.get('axisValueColor', 0)))
                tw, th = c.textSize(fs)
                c.fill(0.7, 0.7, 0.7, 0.6)
                c.stroke(None)
                minM = 0.2
                c.rect(mx + markerX * minM - tw / 2 - 4,
                       my + markerY * minM - 8, tw + 8, th)
                c.text(fs,
                       (mx + markerX * minM - tw / 2, my + markerY * minM - 4))
Пример #20
0
    leading = 24
    for n in range(0, 1000, leading):
        context.stroke(1, 0, 0)
        context.fill(None)
        context.line((0, n),(1000,n))
   
    fs1 = context.newString('')   
    fs2 = context.newString('aaa vvv bbbbbb\nss' * 5,
                      style=dict(fontSize=14,
                                 lineHeight=24))
    appendS(fs1, fs2, 300, 24)

    bx, by, bw, bh = 50, 50, leading*3, 200#, leading*20
    context.stroke(0)
    context.fill(None)
    context.rect(bx, by, bw, bh)

    Y = 100
    bx, by, bw, bh = box = (100, Y, 400, 500)
    baselines = context.textBoxBaseLines(fs, box)
    for x, y in baselines:
        context.stroke(0, 1, 0)
        context.fill(None)
        context.line((x-10, y), (400+10, y))
    dy = round(baselines[0][1]/leading)*leading - baselines[0][1]
    print dy
    box2 = (bx,by+dy, 400, 500)
    context.textBox(fs, box2)
    context.rect(bx, by+dy, bw, bh)
    context.saveImage(path)
Пример #21
0
print 'x-position of verticals:', sorted(gaH.verticals.keys())
# Y position of horizontal lines
print 'y-position of horizontals:', sorted(gaH.horizontals.keys())

c.stroke(0)
c.fill(None)
print gaH.glyph.leftMargin
x = y = 100
s = 0.25
c.drawPath(glyphH.path, (x, y), s)
# Draw markers on the glyph points
c.fill((1, 0, 0))
c.stroke(None)
for p in glyphH.points:
    r = {True:5, False:3}[p.onCurve]
    c.rect(x+p.x*s-r/2, x+p.y*s-r/2, r, r)
    
#c.rect(x, y, 100, 100)
# Draw flattened path next to it on H-width distance.
c.fill(None)
c.stroke(0)
x += glyphH.width*s # Get scaled glyph width
flattenedPath = glyphH.flattenedPath
c.drawPath(flattenedPath, (x, y), s)
# Draw the flattened contours/points
r = 3
c.fill((0, 0.5, 0))
c.stroke(None)
for contour in glyphH.flattenedContours:
    for p in contour:
        c.rect(x+p[0]*s-r/2, y+p[1]*s-r/2, r, r)
Пример #22
0
from pagebot.contexts import defaultContext as c

for p in range(10):
    c.newPage(1000, 1000)
    for n in range(50):
        c.fill((random(), 0, random(), 0.5 + random() * 0.2))
        ch = random()
        x = 20 + random() * 800
        y = 20 + random() * 800
        if ch < 0.2:
            c.oval(x, y, 80, 80)
        elif ch < 0.4:
            c.rect(x, y, 80, 80)
        else:
            c.fontSize(24)
            c.text('Hello world on %d,%d' % (x, y), (x, y))

c.saveImage('_export/HelloCircleSquare.gif')
Пример #23
0
 def _drawFrame(self):
     c.stroke(0, 0, 1)
     c.fill(None)
     c.rect(self.x, self.y, self.w, self.h)
Пример #24
0
#     P A G E B O T
#
#     Copyright (c) 2016+ Buro Petr van Blokland + Claudia Mens & Font Bureau
#     www.pagebot.io
#     Licensed under MIT conditions
#
#     Supporting usage of DrawBot, www.drawbot.com
#     Supporting usage of Flat, https://github.com/xxyxyz/flat
# -----------------------------------------------------------------------------
#
from pagebot.contexts import defaultContext as c

c.newPage(1000, 1000)
fs = c.newString("b", style=dict(lineHeight=74, font="Times", fontSize=38))
fs += c.newString("hello world ",
                  style=dict(font="Helvetica", fontSize=10, lineHeight=12))
fs += c.newString("hi agian " * 10)

r = (10, 10, 200, 200)
c.textBox(fs, r)

c.fill(None)
c.stroke(1, 0, 0)
c.rect(*r)

positions = c.textBoxBaseLines(fs, r)

s = 2
for x, y in positions:
    c.oval(x - s, y - s, s * 2, s * 2)
 def drawBackground(self):
     c.fill(1)
     c.rect(0, 0, W, H)
Пример #26
0
spacer = context.newString('-----\n ',
                           style=dict(lineHeight=1,
                                      font=f.installedName,
                                      fontSize=12))

# Create DrawBotString, inheriting from BabelString, based on view type.
bs = context.newString('Hlxg',
                       style=dict(font=f.installedName,
                                  textFill=(1, 0, 0),
                                  fontSize=300,
                                  leading=320,
                                  baselineShift=200))

M = 20
context.fill(0.9)
context.rect(M, M, 1000 - 2 * M, 800 - 2 * M)

Y = 1000 - M
BASE = (f.info.ascender + f.info.descender + f.info.lineGap) / 2
print('%s %s %s %s' % (f.info.familyName, f.info.styleName,
                       'Ascender + Descender + lineGap =', BASE))
YS = (BASE, )
print YS
for y in YS:
    context.stroke(0)
    context.strokeWidth(0.5)
    context.line((0, y), (1000, y))

context.fill(0)
context.stroke(None)
context.textBox(bs, (M, M, 1000 - 2 * M, 400 - 2 * M))
Пример #27
0
# Draw vertical line in the middle of the page as reference.
context.fill(None)
context.strokeWeight = 0.5
context.stroke((0, 0, 0.4))
context.line((w / 2, 0), (w / 2, h))

TRACKING = 1
FONT_SIZE = 14
TRACKED_SPACE = FONT_SIZE * TRACKING

# New Babel string, probably DrawBot FormattedString flavor.
bs = context.newString('TRACKEDSTRING',
                       style=dict(font='Verdana',
                                  fontSize=FONT_SIZE,
                                  rTracking=TRACKING))
# Call DrawBot textSize to determine the size of the string
# including the tracking
tw, th = bs.size()

context.text(bs, (w / 2 - tw / 2, 70))
context.stroke((1, 0, 0))
context.rect(w / 2 - tw / 2, 60, tw, th)

print TRACKED_SPACE

tw -= TRACKED_SPACE

context.text(bs, (w / 2 - tw / 2, 20))
context.stroke((1, 0, 0))
context.rect(w / 2 - tw / 2, 10, tw, th)
Пример #28
0
context.newDocument(w=W, h=H)
for p in range(PAGES):
    context.newPage(W, H)
    for n in range(RECTS):
        # Compatible to DrawBot: color values between (0, 1)
        red, green, blue = random(), random(), random()
        #a = 0.5 + random()*0.5
        #context.fill((red, green, blue, a))
        context.fill((red, green, blue))
        ch = random()
        x = M + random() * (W - 2 * M - R)  # Only in available space
        y = M + random() * (H - 2 * M - R)
        if ch < 0.2:
            context.oval(x, y, R, R)
        elif ch < 0.4:
            context.rect(x, y, R, R)
        else:
            # Make formatted Flat flavor BabelString instance.
            bs = context.newString('Hello world on %d,%d' % (x, y),
                                   style=dict(font=FONTNAME, fontSize=10))
            context.text(bs, (x, y))

#context.saveImage('_export/HelloCircleSquare.gif')
# PDF does not support alpha colors.
#context.saveDocument('_export/HelloCircleSquare.pdf')
# Does not support alpha colors
#context.saveDocument('_export/HelloCircleSquare.jpg')
context.saveDocument(EXPORT_PATH)

os.system(u'open "%s"' % EXPORT_PATH)
print('Done')
    def draw(self, page, x, y):
        u"""Draw the circle info-graphic, showing most info about the variation font as can be interpreted from the file."""
        c.fill(0.9)
        c.stroke(None)
        mx = x + self.w / 2
        my = y + self.h / 2

        # Gray circle that defines the area of
        c.oval(x, y, self.w, self.h)

        # Draw axis spikes first, so we can cover them by the circle markers.
        axes = self.font.axes
        fontSize = self.style.get('fontSize', self.DEFAULT_FONT_SIZE)

        # Draw name of the font
        c.fill(0)
        c.text(
            c.newString(self.font.info.familyName,
                        style=dict(font=self.style['labelFont'],
                                   fontSize=self.style['axisNameFontSize'])),
            (x - fontSize / 2, y + self.h + fontSize / 2))

        # Draw spokes
        c.fill(None)
        c.stroke(0)
        c.strokeWidth(1)
        c.newPath()
        for axisName, angle in self.angles.items():
            markerX, markerY = self._angle2XY(angle, self.w / 2)
            c.moveTo((mx, my))
            c.lineTo((mx + markerX, my + markerY))
        c.drawPath()

        # Draw default glyph marker in middle.
        glyphName = self.glyphNames[0]
        defaultLocation = {}
        self._drawGlyphMarker(mx,
                              my,
                              glyphName,
                              fontSize,
                              defaultLocation,
                              strokeW=3)

        # Draw DeltaLocation circles.
        for axisName, (minValue, defaultValue, maxValue) in axes.items():
            angle = self.angles[axisName]
            # Outside maxValue
            location = {axisName: maxValue}
            markerX, markerY = self._angle2XY(angle, self.w / 2)
            self._drawGlyphMarker(mx + markerX, my + markerY, glyphName,
                                  fontSize / 2, location)

            # Interpolated DeltaLocation circles.
            location = {
                axisName: minValue + (maxValue - minValue) * INTERPOLATION
            }
            markerX, markerY = self._angle2XY(angle, self.w / 4)
            self._drawGlyphMarker(mx + markerX * INTERPOLATION * 2,
                                  my + markerY * INTERPOLATION * 2, glyphName,
                                  fontSize / 2, location)

        # Draw axis names and DeltaLocation values
        if self.showAxisNames:
            for axisName, (minValue, defaultValue, maxValue) in axes.items():
                angle = self.angles[axisName]
                location = {axisName: maxValue}
                valueFontSize = self.style.get('valueFontSize', 12)
                axisNameFontSize = self.style.get('axisNameFontSize', 12)
                markerX, markerY = self._angle2XY(angle, self.w / 2)
                fs = c.newString(
                    makeAxisName(axisName),
                    style=dict(font=self.style.get('labelFont', 'Verdana'),
                               fontSize=axisNameFontSize,
                               fill=self.style.get('axisNameColor', 0)))
                tw, th = c.textSize(fs)
                c.fill(0.7, 0.7, 0.7, 0.6)
                c.stroke(None)
                c.rect(mx + markerX - tw / 2 - 4,
                       my + markerY - axisNameFontSize / 2 - th * 1.5 - 4,
                       tw + 8, th)
                c.text(fs, (mx + markerX - tw / 2,
                            my + markerY - axisNameFontSize / 2 - th * 1.5))

                # DeltaLocation master value
                if maxValue < 10:
                    sMaxValue = '%0.2f' % maxValue
                else:
                    sMaxValue = ` int(round(maxValue)) `
                fs = c.newString(
                    sMaxValue,
                    style=dict(font=self.style.get('labelFont', 'Verdana'),
                               fontSize=valueFontSize,
                               fill=self.style.get('axisValueColor', 0)))
                tw, th = c.textSize(fs)
                c.fill(0.7, 0.7, 0.7, 0.6)
                c.stroke(None)
                c.rect(mx + markerX - tw / 2 - 4,
                       my + markerY + valueFontSize / 2 + th * 1.5 - 4, tw + 8,
                       th)
                c.text(fs, (mx + markerX - tw / 2,
                            my + markerY + valueFontSize / 2 + th * 1.5))

                # DeltaLocation value
                interpolationValue = minValue + (maxValue -
                                                 minValue) * INTERPOLATION
                if interpolationValue < 10:
                    sValue = '%0.2f' % interpolationValue
                else:
                    sValue = ` int(round(interpolationValue)) `
                fs = c.newString(
                    sValue,
                    style=dict(font=self.style.get('labelFont', 'Verdana'),
                               fontSize=valueFontSize,
                               fill=self.style.get('axisValueColor', 0)))
                tw, th = c.textSize(fs)
                c.fill(0.7, 0.7, 0.7, 0.6)
                c.stroke(None)
                c.rect(
                    mx + markerX * INTERPOLATION - tw / 2 - 4, my +
                    markerY * INTERPOLATION + valueFontSize / 2 + th * 1.5 - 4,
                    tw + 8, th)
                c.text(
                    fs,
                    (mx + markerX * INTERPOLATION - tw / 2, my +
                     markerY * INTERPOLATION + valueFontSize / 2 + th * 1.5))

                # DeltaLocation value
                if minValue < 10:
                    sValue = '%0.2f' % minValue
                else:
                    sValue = ` int(round(minValue)) `
                fs = c.newString(
                    sValue,
                    style=dict(font=self.style.get('labelFont', 'Verdana'),
                               fontSize=valueFontSize,
                               fill=self.style.get('axisValueColor', 0)))
                tw, th = c.textSize(fs)
                c.fill(0.7, 0.7, 0.7, 0.6)
                c.stroke(None)
                minM = 0.2
                c.rect(mx + markerX * minM - tw / 2 - 4,
                       my + markerY * minM + th * 0.5 - 4, tw + 8, th)
                c.text(fs, (mx + markerX * minM - tw / 2,
                            my + markerY * minM + th * 0.5))
Пример #30
0
#     P A G E B O T
#
#     Copyright (c) 2016+ Buro Petr van Blokland + Claudia Mens & Font Bureau
#     www.pagebot.io
#     Licensed under MIT conditions
#
#     Supporting usage of DrawBot, www.drawbot.com
#     Supporting usage of Flat, https://github.com/xxyxyz/flat
# -----------------------------------------------------------------------------
#
from random import random
from pagebot.contexts import defaultContext as context

for p in range(20):
    context.newPage(1000, 1000)
    for n in range(50):
        context.fill((random(), 0, random(), 0.5 + random() * 0.2))
        ch = random()
        x = 20 + random() * 800
        y = 20 + random() * 800
        if ch < 0.2:
            context.oval(x, y, 80, 80)
        elif ch < 0.4:
            context.rect(x, y, 80, 80)
        else:
            bs = context.newString('Hello world on %d,%d' % (x, y),
                                   style=dict(fontSize=24))
            context.text(bs, (x, y))

context.saveImage('_export/OurNiceDrawing.pdf')