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))
def drawLayers(bss): # Draw this layer in a couple of frame context.newPage(W, H) context.frameDuration(fd) #fill(backgroundColor[0],backgroundColor[1],backgroundColor[2]) #rect(0, 0, W, H) y = 3*padding for bs in bss: context.text(bs, (2*padding, y+100))
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))
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(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))
def drawLayers(fss, frame): # Draw this layer in a couple of frame context.newPage(W, H) context.frameDuration(fd) #fill(backgroundColor[0],backgroundColor[1],backgroundColor[2]) #rect(0, 0, W, H) y = 3 * padding for fsSingle, fsDouble in fss: if frame < frames / 2: fs = fsSingle else: fs = fsDouble context.text(fs, (2 * padding, y + 100))
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(fss, frame, dx, dy, doNewPage): # Draw this layer in a couple of frame if doNewPage: context.newPage(W, H) context.frameDuration(fd) #context.fill(backgroundColor[0],backgroundColor[1],backgroundColor[2]) #context.rect(0, 0, W, H) for fsSingle, fsDouble in fss: if frame < frames/2: fs = fsSingle else: fs = fsDouble context.text(fs, (dx*2*padding, dy))
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']
def run(): s = u"""글자가 일상이 된다 산돌커뮤니케이션 ABCD123 Latin すべての文化集団は,独自の言語,文字,書記システムを持つ.それゆえ,個々の書記システムをサイバースペースに移転することは. ABCD123 Latin included""" c.newPage(W, H) fsr = c.newString(s, style=dict(font='Generic-Regular', fontSize=FontSize)) fsb = c.newString(s, style=dict(font='Generic-Regular_Bold', fontSize=FontSize)) fsbRed = c.newString(s, style=dict(font='Generic-Regular_Bold', fill=(1, 0, 0), fontSize=FontSize)) c.textBox(fsr, (100, 600, 820, 350)) c.textBox(fsb, (100, 300, 820, 350)) c.textBox(fsbRed, (100, 0, 820, 350)) c.textBox(fsr, (100, 0, 820, 350))
def draw(self): for n in range(self.steps): c.newPage(W, H) self.drawBackground() if self.drawBackgroundHook is not None: self.drawBackgroundHook(self, n) for o in self.objects: offsetX = 0 offsetY = 0 if o.eId in self.positions: # Changed target, then calculate new offset tx, ty = self.positions[o.eId] offsetX = (tx - o.x) * 1.0 * n / self.steps offsetY = (ty - o.y) * 1.0 * n / self.steps o.draw(offsetX, offsetY) # Set the new target positions for o in self.objects: if o.eId in self.positions: tx, ty = self.positions[o.eId] o.x = tx o.y = ty
def run(): W, H = 1000, 400 c.newPage(W, H) txt = "Hello World" x, y = 10, 100 fs = c.newString(txt, style=dict(fontSize=300, font="Verdana")) # draw the text c.text(fs, (x, y)) # calculate the size of the text textWidth, textHeight = c.textSize(txt) # set a red stroke color c.stroke(1, 0, 0) # loop over all font metrics for metric in (0, fs.fontDescender(), fs.fontAscender(), fs.fontXHeight(), fs.fontCapHeight()): # draw a red line with the size of the drawn text c.line((x, y + metric), (W - 2 * x, y + metric))
def buildBusinessCard1(w, h): M = 4 # Margin # Page 66 context.newPage(w, h) y = h context.image('docs/images/IMG_2381-50.jpg', (0, 0), w=w) # Title of cover, make it fit in with and add shadow style = dict(font='Upgrade-Regular', fontSize=14, textFill=1, xTextAlign=CENTER) styleTitle = dict(font='Upgrade-Italic', fontSize=10, textFill=1, xTextAlign=CENTER) styleEmail = dict(font='Upgrade-Light', fontSize=8, textFill=1, xTextAlign=CENTER, leading=10, rTracking=0.02) bs = context.newString('Petr van Blokland\n', style=style) bs += context.newString('Designer | Educator | Founder\n', style=styleTitle) bs += context.newString('[email protected] | @petrvanblokland', style=styleEmail) tw, th = bs.size() context.text(bs, (w / 2 - tw / 2, h * 0.55)) logoStyle = dict(font='Upgrade-Black', fontSize=22, textFill=1, rTracking=1.4) bs = context.newString(u'.TYPETR', style=logoStyle) tw, th = bs.size() context.text(bs, (w / 2 - tw / 2 - 3, 2 * M))
def buildBusinessCard(w, h): for imageIndex in range(1, 5): context.newPage(w, h) y = h # Start vertical position on top of the page. # Draw one of the 4 Bitcount background images, filename indexed by imageIndex # The TYPETR Bitcount license can be purchased at: # https://store.typenetwork.com/foundry/typetr/fonts/bitcount imagePath = ROOT_PATH + '/Examples/Portfolios/images/BitcountRender%d.png' % imageIndex context.image(imagePath, (0, 0), w=w) # Set to full page width at origin # Define some style. Note thate TYPETR Upgrade is the identity typeface, which may not be installed. # Another font is selected in case TYPETR Upgrade is not available. # View more here: https://upgrade.typenetwork.com # A license can be purchased at: # https://store.typenetwork.com/foundry/typetr/fonts/upgrade style = dict(font='Upgrade-Regular', fontSize=14, textFill=1, xTextAlign=CENTER) styleTitle = dict(font='Upgrade-Italic', fontSize=10, textFill=1, xTextAlign=CENTER) styleEmail = dict(font='Upgrade-Light', fontSize=8, textFill=1, xTextAlign=CENTER, leading=10, rTracking=0.02) # Create styled BabelString for the name lines bs = context.newString('Petr van Blokland\n', style=style) bs += context.newString('Designer | Educator | Founder\n', style=styleTitle) bs += context.newString('[email protected] | @petrvanblokland', style=styleEmail) # Get the size of the text block, to position it centered tw, th = context.textSize(bs) # Draw a textbox in the contextf canvas. context.text(bs, (w/2-tw/2, h*0.55)) # Create a style for the logo. The size and tracking is hardcoded to fit the business card width. logoStyle = dict(font='Upgrade-Black', fontSize=22, textFill=1, rTracking=1.4) # Create the BabelString, containing the fitting logo with tracking. bs = context.newString(u'.TYPETR', style=logoStyle) # Get the size of the text block, to position it centered tw, th = bs.size() # Draw a textbox in the contextf canvas. context.text(bs, (w/2-tw/2-3, 2*M))
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))
def buildDesignPages(w, h): cw = w - ML - MR # Page 66 context.newPage(w, h) bs = context.newText(t) R = (ML, MB, w - ML - MR, h - MB - MT) overFill = context.textOverflow(bs, R) context.textBox(bs, R) pn = context.newString(66, style=pageNumberStyle) context.text(pn, (w / 2 - pn.w / 2, M / 2)) pt = context.newString(bookTitle, style=pageTitleStyle) context.textBox(pt, (ML, h - MT * 0.75, cw, pt.h)) # Page 67 context.newPage(w, h) # Assume that we have a footnote on this page, calc it's space. fnMark = context.newString(footNoteRef, style=footNoteRefStyle) fn = fnMark + ' ' + context.newString(footNoteText, style=footNoteStyle) fnw, fnh = fn.textSize(cw) cfnh = fnh + bodyStyle['fontSize'] * bodyStyle['rLeading'] ch = h - MB - MT - cfnh R = (ML, MB + cfnh, cw, ch) context.textBox(overFill, R) context.textBox(fn, (ML, MB, cw, fnh)) pt = context.newString(chapterTitle, style=pageChapterStyle) context.textBox(pt, (ML, h - MT * 0.75, cw, pt.h)) pn = context.newString(67, style=pageNumberStyle) context.text(pn, (w / 2 - pn.w / 2, M / 2))
def buildBusinessCard2(w, h): M = 4 # Margin # Page 66 context.newPage(w, h) y = h context.image('docs/images/IMG_2379-50.jpg', (0, 0), w=w * 1.3) # Title of cover, make it fit in with and add shadow style = dict(font='Upgrade-Regular', fontSize=14, textFill=1, xTextAlign=CENTER) styleTitle = dict(font='Upgrade-Italic', fontSize=10, textFill=(0xEC / 255, 0x3E / 255, 0x2B / 255), xTextAlign=CENTER) styleEmail = dict(font='Upgrade-Light', fontSize=8, textFill=1, xTextAlign=CENTER, leading=10, rTracking=0.02) bs = context.newString('Claudia Mens\n', style=style) bs += context.newString('Designer | Educator | Founder\n', style=styleTitle) bs += context.newString('[email protected] ', style=styleEmail) tw, th = bs.size() context.textBox(bs, (w / 2 - tw / 2, h / 2 - th / 2, tw, th)) styleLogo = dict(font='Upgrade-Thin', fontSize=14, textFill=1, openTypeFeatures=dict(case=True))
## 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)
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)
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))
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))
runs = False c.newPath() c.moveTo((mx, my)) for n in range(0, int(N), 4): dx1 = n*Sx*D dy1 = n*Sy*D dx2 = (n+1)*Sx*D dy2 = (n+1)*Sy*D dx3 = (n+2)*Sx*D dy3 = (n+2)*Sy*D dx4 = (n+3)*Sx*D dy4 = (n+3)*Sy*D #dx5 = (n+4)*Sx*D #dy5 = (n+4)*Sy*D if not runs: c.moveTo((mx, my)) else: c.curveTo((mx-dx1*Exy, my-dy1), (mx-dx1, my-dy1*Exy), (mx-dx1, my)) c.curveTo((mx-dx2, my+dy2*Exy), (mx-dx2*Exy, my+dy2), (mx, my+dy2)) c.curveTo((mx+dx3*Exy, my+dy3), (mx+dx3, my+dy3*Exy), (mx+dx3, my)) c.curveTo((mx+dx4, my-dy4*Exy), (mx+dx4*Exy, my-dy4), (mx, my-dy4)) runs = True c.fill(None) c.stroke(0) c.drawPath() c.newPage(W, H) drawSpiral() c.saveImage("spiral.pdf")
fs += fittingWord fittingWord = c.newString('ABC\n', style=dict(font='BitcountMonoDouble-RegularCircle', align='left', fontSize=500)) w, _ = c.textSize(fittingWord) fittingSize = W/w*500 fittingWord = c.newString('ABC\n', style=dict(font='BitcountMonoDouble-RegularCircle', align='left', fontSize=fittingSize, lineHeight=fittingSize)) fs += fittingWord c.newPage(W+G*2, H + G*2) myTextBox = c.TextBox(fs, G, G, W, H) myTextBox.draw() myTextBox._drawFrame() myTextBox._drawBaselines(showIndex=True, showY=True, showLeading=True) for pattern in myTextBox.findPattern('Find'): #print pattern px = pattern.x py = pattern.y print pattern print px, py[1] c.stroke(1, 0, 0) c.fill(None) c.oval(px-10, py[1]-10, 20, 20)
def buildCoverPages1(w, h, imagePath, page): magazineTitle = 'Bier!' M = 10 # Margin ML, MR, MT, MB = M, M, M, 1.5 * M cw = w - ML - MR LM = 2 * M # Page 66 context.newPage(w, h) biw, bih = ((None, h), (w, None), (None, h), (None, h))[page] # Draw image, covering all page, scaled. context.image('docs/images/' + imagePath, (0, 0), w=biw, h=bih) t = ( u'Voorjaar 2018 | No. 36 | €5', u'Zomer 2018 | No. 37 | €5', u'Najaar 2018 | No. 38 | €5', u'Winter 2018 | No. 39 | €5', ) priceStyle1 = dict(font='Upgrade-Book', fontSize=15, textFill=1, rTracking=0.02) priceStyle2 = dict(font='Upgrade-Book', textFill=1, fontSize=15, openTypeFeatures=dict(sups=True)) bs = context.newString(t[page], style=priceStyle1) bs += context.newString('95', style=priceStyle2) bx, by, bw, bh = bs.bounds() context.text(bs, (w - M - (bx + bw), MB)) y = h - M print listOpenTypeFeatures('Upgrade-Light') c = ( # Title colors per page 0, 1, 0, 1) # Title of cover, make it fit in with and add shadow style = dict(font='Upgrade-Light', fontSize=15.5, textFill=c[page], openTypeFeatures=dict(smcp=True, c2sc=True, ss08=True), rLeading=0.9, rTracking=0.02) #bs = context.newString('onafhankelijk smaakmakend\rmagazine over speciaal bier', style=style) bs = context.newString('onafhankelijk smaakmakend\r'.upper(), style=style) style['rTracking'] = 0.042 bs += context.newString('magazine over speciaal bier'.upper(), style=style) bx, by, bw, bh = bs.bounds() context.text(bs, (w / 2.3, y - bh - M / 2)) # Title of cover, make it fit in with and add shadow coverTitleStyle = dict(font='Upgrade-Black', fontSize=100, textFill=1, rTracking=-0.025) bs = context.newString(magazineTitle, style=coverTitleStyle, w=w) bx, by, bw, bh = bs.bounds() context.setShadow(shadow) context.text(bs, (w / 2 - (bw + bx) / 2, y - bh)) context.resetShadow() y -= (bh - by) + 2 * LM t = ((u'Leven in de brouwerij', w * 2 / 3.2), (u'De Koninck Late Night', w * 2 / 3.2), (u'Brouwerijtour', w / 2), (u'Bierreis grensstreek', w * 2 / 3.2)) style = dict(font='Upgrade-Italic', fontSize=64, textFill=(1, 1, 1, 0.8), rLeading=1) bs = context.newString(t[page][0], style=style, w=t[page][1]) bx, by, bw, bh = bs.bounds() context.text(bs, (M, y - bh)) y -= (bh - by) + LM - 8 t = ( (u'Hommels', w / 2), (u'Geproefde bieren', w / 2 - 2 * M), (u'Beer Battle', w / 2 - 2 * M), (u'Droomweekend bier', w / 2), ) style = dict(font='Upgrade-Semibold', fontSize=50, textFill=(0xd4 / 255, 0x89 / 255, 0x5a / 255, 0.8), rTracking=0.02, rLeading=0.7) bs = context.newString(t[page][0], style=style, w=t[page][1]) bx, by, bw, bh = bs.bounds() context.setShadow(shadow) context.text(bs, (M, y - bh)) context.resetShadow() y -= (bh - by) + 3.5 * LM t = ( (u'De Baronie\nWestmalle\nCafé Trappisten', w - 2 * M, (0x3e / 255, 0x1a / 255, 0x09 / 255, 0.2)), (u'Vlaamse\nBiergaai', w / 2 - 3 * M, (0xd4 / 255, 0x89 / 255, 0x5a / 255, 0.1)), (u'.\n\n\nHollandse\nHopvogel', w / 2 - 2 * M, (0xd4 / 255, 0x89 / 255, 0x5a / 255, 0.1)), (u'Italiaans abdijbier', w - 2 * M, (0xd4 / 255, 0x89 / 255, 0x5a / 255, 0.1)), ) style = dict(font='Upgrade-Black', fontSize=60, textFill=t[page][2], textStroke=(1, 1, 1, 0.5), textStrokeWidth=3, rTracking=0.03, rLeading=0.9) bs = context.newString(t[page][0], style=style, w=t[page][1]) bx, by, bw, bh = bs.bounds() context.text(bs, (M, y - bh)) y -= (bh - by) - LM t = ( u'Kompaan brouwt het beste bier van Nederland', u'Wederopbouw: Help de monniken met “Deep Roots”', u'Two Chefs Brewing opent microbrouwerij Amsterdam', u'Brouwerij in distilleerderij in Weesper kerk', ) style = dict(font='Upgrade-Regular', fontSize=100, textFill=(1, 1, 1, 0.95), rTracking=0.02) bs = context.newString(t[page], style=style, w=w - 3 * M) bx, by, bw, bh = bs.bounds() context.setShadow(shadow) context.text(bs, (1.5 * M, 6 * M)) context.resetShadow()
# -*- coding: UTF-8 -*- # ----------------------------------------------------------------------------- # # 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 fontName in context.installedFonts(): if 'Bitcount' in fontName: if 'Italic' in fontName: continue bitcounts.append(fontName) if 'Bitpath' in fontName: if 'Italic' in fontName: continue bitpaths.append(fontName) #print len(bitpaths) #print len(bitcounts) for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz': context.newPage(2400, 300) fonts = bitpaths + bitcounts #print len(fonts) shuffle(fonts) for name in fonts: #if not 'Double' in name: # continue if not 'Single' in name: continue if not 'Mono' in name: continue fs = context.newString( 'Claire Lindsey', style=dict( font=name, fontSize=200,
# This script shows the behavior of FormattedStrings in DrawBot Context. # Tracking is added after the glyphs, so the measured width of a tracked # string is wider that it looks. # To safely measure the real width of the string, the width of one "track" # needs to be subtracted. from pagebot.contexts import defaultContext as context # Create a new page w, h = 400, 100 context.newPage(w, h) # 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()
for fontName in context.installedFonts(): if 'Bitcount' in fontName: if not 'Italic' in fontName: continue bitcounts.append(fontName) if 'Bitpath' in fontName: if not 'Italic' in fontName: continue bitpaths.append(fontName) print len(bitpaths) print len(bitcounts) for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz': context.newPage(2200, 300) fonts = bitpaths + bitcounts print len(fonts) shuffle(fonts) for name in fonts: #if not 'Double' in name: # continue if not 'Single' in name: continue if not 'Mono' in name: continue fs = context.newString('Jill Pichotta', style=dict(font=name, fontSize=200, #openTypeFeatures=dict(ss01=True, # ss02=True,
if not hasattr(scriptGlobals, 'initialized'): scriptGlobals.initialized = True scriptGlobals.s1 = blurb.getBlurb('article_content', noTags=True) scriptGlobals.s2 = blurb.getBlurb('article_content', noTags=True) scriptGlobals.s3 = blurb.getBlurb('article_content', noTags=True) scriptGlobals.s4 = blurb.getBlurb('article_content', noTags=True) scriptGlobals.s5 = blurb.getBlurb('article_content', noTags=True) F = 50 R = 10 x = y = 20 rLeading = 0.6 for angle in range(0, 360, 10): context.newPage(1000, 1000) dx = sin(angle/360*2*pi) * R dy = cos(angle/360*2*pi) * R fs = context.newString(scriptGlobals.s1, style=dict(font='BitpathGridDouble-RegularLineSquare', fontSize=F, textFill=(1, 0, 0), rLeading=rLeading)) context.textBox(fs, (x, y, 1000, 900)) fs = context.newString(scriptGlobals.s2, style=dict(font='BitpathGridDouble-RegularLineSquare', fontSize=F, textFill=(0, 1, 0), rLeading=rLeading)) context.textBox(fs, (x+7, y+7, 1000, 900))
if __name__ == '__main__': # Let's say we want to scale it to 50%. The 0.5 is the multiplication factor. newScale = 0.5 # Define the path where to find the example image. path = 'docs/sources/' dstPath = 'docs/images/' for fileName in os.listdir(path): if fileName.startswith('.'): continue imagePath = path + fileName # Use the standard DrawBot function to get the width/height of the image from the file. w, h = context.imageSize(imagePath) # Make a page with the size of the scaled image, rounded to whole pixels. context.newDrawing() context.newPage(int(w * newScale), int(h * newScale)) # Save the “graphics state“, just in case the script is extended later, where other # operation need to work in 100%. context.save() context.scale(newScale) # Make all drawing scale to 50% context.image( imagePath, (0, 0) ) # Draw the scaled image at the bottom-left corner. It fills the whole page. # Restore the graphics state, so DrawBot scaling is back to 100% after this. context.restore() # Note that resulting images may look sharper, by has 4.5x the size of the .jpg. dstImagePath = dstPath + fileName.replace('.', '-%d.' % (newScale * 100)) print fileName, '-->', dstImagePath context.saveImage(dstImagePath)