def export(): # Find non-existing name for n in range(10000): filePath = EXPORT_PATH % n if not os.path.exists(filePath): context.saveImage(filePath) # Save the sample as png. break # Make sure to break, or else 10000 copies are created.
def drawAnimation(): positionFontIcons() varFontIcon = id2FontIcon['VarFont'] KeyFrame(fontIcons, {}, 15, drawBackground=drawBackground1).draw() KeyFrame(fontIcons, { 'Regular': (varFontIcon.x, varFontIcon.y) }, 10, drawBackground=drawBackground1).draw() id2FontIcon['Regular'].show = False varFontIcon.title = '0 axis' varFontIcon.label = FSIZE varFontIcon.c = 'F' KeyFrame(fontIcons, { 'Bold': (varFontIcon.x, varFontIcon.y) }, 10, drawBackground=drawBackground1).draw() id2FontIcon['Bold'].show = False varFontIcon.title = '1 axis [Weight]' varFontIcon.label = '100k' KeyFrame(fontIcons, {}, 10, drawBackground=drawBackground2).draw() KeyFrame(fontIcons, { 'UltraLight': (varFontIcon.x, varFontIcon.y), 'Light': (varFontIcon.x, varFontIcon.y), 'Thin': (varFontIcon.x, varFontIcon.y), 'Book': (varFontIcon.x, varFontIcon.y), 'Medium': (varFontIcon.x, varFontIcon.y), 'Semibold': (varFontIcon.x, varFontIcon.y), 'Bold': (varFontIcon.x, varFontIcon.y) }, 10, drawBackground=drawBackground2).draw() id2FontIcon['UltraLight'].show = False id2FontIcon['Light'].show = False id2FontIcon['Thin'].show = False id2FontIcon['Book'].show = False id2FontIcon['Medium'].show = False id2FontIcon['Semibold'].show = False varFontIcon.label = '100K' KeyFrame(fontIcons, {}, 40, drawBackground=drawBackground3).draw() c.saveImage('_export/VarFontManyWeights.gif')
def drawSample(name): for imageIndex, layers in enumerate(animation): context.newDrawing() for index in range(len(layers)): bss = [] for fontName, color in layers[:index+1]: fontName = 'BitcountPropSingle-%s' % fontName c = (int(color[:2], 16)/256.0,int(color[2:4], 16)/256.0,int(color[4:], 16)/256.0) # First half of frames, add bss.append(getFittingString(name, fontName, c)) drawLayers(bss) # Draw layers on several identical frames, using SIngle or Double. for index in range(len(layers)-2): bss = [] for fontName, color in layers[:-index-1]: fontName = 'BitcountPropSingle-%s' % fontName c = (int(color[:2], 16)/256.0,int(color[2:4], 16)/256.0,int(color[4:], 16)/256.0) # First half of frames, add bss.append(getFittingString(name, fontName, c)) drawLayers(bss) # Draw layers on several identical frames, using SIngle or Double. context.saveImage(EXPORT_PATH % imageIndex) # Save the sample as file or animated gif.
def drawFigures(): W, H = 860, 451 newPage(W, H) LEADING = 0.9 fs = c.newString('ABC0123456789\n', style=dict(textFill=0, rLeading=1, font='BitcountPropSingle-RegularCircle', fontSize=90)) fs += c.newString('abc0123456789\n', style=dict(textFill=0, font='BitcountPropSingle-RegularCircle', rLeading=LEADING, fontSize=90, openTypeFeatures=dict(smcp=True))) fs += c.newString('ABCabc0123456789\n', style=dict(textFill=0, font='BitcountPropSingle-RegularCircle', rLeading=LEADING, fontSize=90, openTypeFeatures=dict(onum=True, ss07=True))) fs += c.newString('ABCabc0123456789\n', style=dict(textFill=0, font='BitcountPropSingle-RegularCircle', rLeading=LEADING, fontSize=90, openTypeFeatures=dict(ss07=True))) fs += c.newString('Fraction 1/2 12345/67890\n', style=dict(textFill=0, font='BitcountPropSingle-RegularCircle', rLeading=LEADING, fontSize=90, openTypeFeatures=dict(frac=True))) M = 30 c.textBox(fs, (M+10, -10, W-2*M, H)) c.saveImage('_export/figures.png') # Save the sample as file or animated gif.
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)
IMAGE_PATHS = ( ('bitcountFlashes1.jpg', 4), ('bitcountFlashes2.jpg', 2), ('bitcountFlashes1.jpg', 1), ('bitcountFlashes2.jpg', 2), ('bitcountFlashes1.jpg', 1), ('bitcountFlashes2.jpg', 1), ('bitcountFlashes3.jpg', 1), ('bitcountFlashes2.jpg', 1), ('bitcountFlashes3.jpg', 1), ('bitcountFlashes2.jpg', 1), ('bitcountFlashes3.jpg', 1), ('bitcountFlashes2.jpg', 1), ('bitcountFlashes3.jpg', 8), ('bitcountFlashes1.jpg', 1), ('bitcountFlashes2.jpg', 2), ('bitcountFlashes3.jpg', 14), ('bitcountFlashes2.jpg', 1), ('bitcountFlashes3.jpg', 20), ) W, H = 1340 / 2, 560 / 2 M = 60 for imageName, duration in IMAGE_PATHS: for n in range(duration): context.newPage(W, H) context.frameDuration(0.1) context.image('docs/images/' + imageName, (-2 * M - 40, -M / 2), w=W + 2 * M) context.saveImage(PATH)
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('w=%d' % w, (PADDING + w + 5, H - PADDING - 5)) 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()) c.draw(Width) else: angle = 0 while angle < 360: dx = sin(radians(angle)) * 0.5 + 0.5 draw(160 + (W - 2 * PADDING - 160) * dx) angle += 360 / FRAMES c.saveImage('_export/fitVariableHeadlineStyleCompare.gif')
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)
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')
s = blurb.getBlurb('article_content', noTags=True) fs = context.newString(s, style=dict(font='BitpathGridDouble-RegularLineSquare', fontSize=F, textFill=(0, 1, 0), rLeading=0.5)) context.textBox(fs, (x, y, 1000, 900)) s = blurb.getBlurb('article_content', noTags=True) fs = context.newString(s, style=dict(font='BitpathGridDouble-RegularLineSquare', fontSize=F, textFill=(0, 1, 1), rLeading=0.5)) context.textBox(fs, (x, y, 1000, 900)) s = blurb.getBlurb('article_content', noTags=True) fs = context.newString(s, style=dict(font='BitpathGridDouble-RegularLineSquare', fontSize=F, textFill=(1, 1, 0), rLeading=0.5)) context.textBox(fs, (x, y, 1000, 900)) s = blurb.getBlurb('article_content', noTags=True) fs = context.newString(s, style=dict(font='BitpathGridDouble-RegularLineSquare', fontSize=F, textFill=(0, 0, 0), rLeading=0.5)) context.textBox(fs, (x, y, 1000, 900)) context.saveImage('_export/PatternPage2.pdf')
# ----------------------------------------------------------------------------- # # UseBabelStrings.py # # BabelString instances are wrappers around formatted strings, # hiding their context. For DrawBot BabelStrings (bs.s) contain # OSX/IOS FormattedStrings. # For FlexContext, equivalent text-formatted structures are implemented. # from pagebot.contexts import defaultContext as context W = H = 1000 M = 100 EXPORT_PATH = '_export/UseBabelStrings.pdf' # Create a page and set y on top margin. context.newPage(W, H) y = H - M # Create formatted string, with default settings of font, fontSize and textFill color bs = context.newString('This is a formatted BabelString') context.text(bs, (100, y)) # Add string with formatting style dict bs += context.newString('\nAdd an other string with format', style=dict(textFill=(1, 0, 0), fontSize=20, rLeading=1.4)) y -= 50 context.text(bs, (100, y)) context.saveImage(EXPORT_PATH)
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')
(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)) 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: angle = 0 while angle < 360: dx = sin(radians(angle)) * 0.5 + 0.5 draw(160 + (W-2*PADDING-160) * dx) angle += 360/FRAMES c.saveImage('_export/fitVariableHeadline.gif')
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) # Bitcount measures, pixels are 1/10 of Em for yy in range(-3,10): c.stroke(1, 0, 0) c.fill(None) y = (myTextBox.y + myTextBox.h + yy*fittingSize/10 - myTextBox.baseLines[-1][1]) c.line((myTextBox.x, y), (myTextBox.x + myTextBox.w, y)) c.saveImage('_export/testTextLineTextRun.pdf')
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, # ss03=True), tracking=40, #textFill=None, textFill=(random(), random(), random(), 0.1), textStroke=(random(), random(), random()), textStrokeWidth=0.5)) context.text(fs, (50, 100)) context.saveImage('_export/CompareBitpath2BitcountJP.pdf')
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)) if __name__ == '__main__': c.Variable( [ #dict(name='ElementOrigin', ui='CheckBox', # args=dict(value=False)), dict(name='FontSize', ui='Slider', args=dict(minValue=30, value=50, maxValue=120)), ], globals()) run() c.saveImage('_export/TestKanjiFormattedString.pdf')
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) print 'Done'
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")
speed) for flash in range(4): makeFlash(line1, w, h, 9 * PIX, 0) #for n in range(int(round(len(message)*6))): # makeRunningLeds(message, w, h, -(1+n)*PIX*speed, 3*PIX, speed) for flash in range(6): makeFlash(line2, w, h, 7 * PIX, 0, color1=(0.3, 0.9, 0), color2=(0.1, 0.3, 0)) context.openTypeFeatures( dict(liga=False, zero=False, onum=False, lnum=False, hwid=False, ss01=False, ss02=False, ss04=False, ss05=False, ss06=False, pcap=False, smcp=False, c2sc=False)) context.saveImage('_export/runningLedsPropExtendedTN.gif')
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)) if __name__ == '__main__': # If no Bitcount fonts could be found, open the browser on the TypeNetwork shop page and stop this script. if not fontNamePaths: os.system('open %s/fonts/%s' % (typetrStoreUrl, 'bitcount')) #familyName.lower()) else: tts = ('Prop', 'Mono', 'Grid') for frame in range(frames): if frame < frames / 3: tt = tts[0] elif frame < frames * 2 / 3: tt = tts[1] else: tt = tts[2] drawSample(t, tt) context.saveImage( EXPORT_PATH) # Save the sample as file or animated gif.
print 'unitsPerEm:', f.info.unitsPerEm # GPOS print '-- GPOS', '-' * L print 'gposFeatures:', f.info.gposFeatures # GSUB print '-- GSUB', '-' * L print 'gsubFeatures:', f.info.gsubFeatures # Glyph content of the font print '-- Glyhps', '-' * L print 'Char set:', f.info.charSet print 'Glyph set:', f.info.glyphSet W = H = 1000 GX = GY = 20 M = 50 # Scale em of 2048 back to page size. glyphIndex = 1 s = 0.04 for y in range(GY): for x in range(GX): # Offset of drawing origin c.save() c.translate(M + (W - 2 * M) / GX * x, H - M - (H - 2 * M) / GY * (y + 1)) g = f[f.info.glyphSet[glyphIndex]] c.drawPath(g.path, (0, 0), s) glyphIndex += 1 c.restore() c.saveImage(EXPORT_PATH)
fs = context.newString(scriptGlobals.s4, style=dict(font='BitpathGridDouble-RegularLineSquare', fontSize=F, textFill=(1, 1, 0), rLeading=rLeading)) context.textBox(fs, (x+7, y, 1000, 900)) fs = context.newString(scriptGlobals.s5, style=dict(font='BitpathGridDouble-BlackLineRound', fontSize=F, textFill=(0, 0, 0, 0.4), rLeading=rLeading)) context.textBox(fs, (x+(-dx+dy)/2, y+(-dx+dy)/2, 1000, 900)) fs = context.newString(scriptGlobals.s5, style=dict(font='BitpathGridDouble-Round', fontSize=F, textFill=0, rLeading=rLeading)) context.textBox(fs, (x+dx, y+dy, 1000, 900)) fs = context.newString(scriptGlobals.s5, style=dict(font='BitpathGridDouble-BookRound', fontSize=F, textFill=1, rLeading=rLeading)) context.textBox(fs, (x+dx-2, y+dy+2, 1000, 900)) context.saveImage('_export/PatternRotatingText.gif')
# 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')