def onBlack(self, p): """Answers is the single point (x, y) is on black.""" # TODO: We need to make a method to have the context available here. from pagebot import getContext context = getContext() glyphPath = context.getGlyphPath(self.glyph) return context.onBlack(p, glyphPath)
def __init__(self): """ Connects main window and output window for errors. """ super(CanvasApp, self).__init__() self.window = Window((800, 600), minSize=(1, 1), closable=True) self.context = getContext('Canvas') self.window.open() self.run()
def find(self, name=None, pattern=None, extension=None, **kwargs): """Answer the elements that hold the data of matching path extensions.""" elements = [] context = getContext() for path in self.findPaths(name=name, pattern=pattern, extension=extension): if os.path.exists(path): e = elementFromPath(path, context=context, name=name, **kwargs) if e is not None: elements.append(e) return elements
def testCoordinates(): context = getContext() context.fill((0, 1, 0)) context.stroke(None) for rects in rectSets: i = 0 for r in rects: i += 1 x = r.getFloatLeftSide() y = r.getFloatTopSide() #print('%d %d' % (x, y)) context.circle(x, y, 2) context.text('%d' % i, (x + 5, y - 5))
def showContexts(): print('Here are some examples of how to retrieve different kinds of contexts:') context = getContext() # Creates a DrawBot context on Mac, Flat on others print(context) context = getContext() # Still DrawBot, takes the buffered DEFAULT_CONTEXT. print(context) context = getContext('DrawBot') # Still DrawBot, takes the buffered DEFAULT_CONTEXT. print(context) context = getContext(contextType='Flat') # Force Flat. print(context) context = getContext(contextType='Flat') # Buffered in DEFAULT_CONTEXT this time. print(context) context = getContext(contextType='HTML') print(context) context = getContext(contextType='InDesign') # To be implemented. print(context) context = getContext(contextType='IDML') # To be implemented. print(context) context = getContext(contextType='SVG') # To be implemented. print(context)
def __init__(self): """Connects main window and output window for errors.""" for path in getFontPaths(): name = path.split('/')[-1] self.FONTS.append(name) self.font = findFont(self.FONTS[0]) self.context = getContext() self.window = Window((800, 600), minSize=(1, 1), closable=True) self.window.drawView = DrawView((0, 32, -0, -0)) self.outputWindow = Window((400, 300), minSize=(1, 1), closable=True) self.outputWindow.outputView = OutPutEditor((0, 0, -0, -0), readOnly=True) self.initialize() self.window.open() self.outputWindow.open()
def makeDocument(): # Creates the publication/document that holds the pages. doc = Document(w=W, h=H, originTop=False, autoPages=1) print(doc.view) print(doc.pages) doc.view.padding = 100 # Don't show cropmarks in this example. #doc.margin = doc.view.showPadding = True # Gets page by pageNumber, first in row (at this point there is only one in # this row). page = doc[1] page.padding = 1 page.showPadding = True conditions = [Right2Right(), Float2Top(), Float2Left()] #conditions = [Right2Right(), Float2Top()] #conditions = [Left2Left()] #conditions = [Right2Right()] numberOfSquares = 8 ratio = 1 / numberOfSquares rects = [] for n in range(numberOfSquares): r = newRect(w=40, h=42, mr=4, mt=4, parent=page, fill=color(1 - n * ratio, 0, 0.5), conditions=conditions, margin=0) rects.append(r) score = doc.solve() doc.build() from pagebot import getContext context = getContext() for r in rects: x = r.getFloatLeftSide() + doc.view.pr y = r.getFloatTopSide() + doc.view.pt context.fill((0, 1, 0)) context.circle(x, y, 2)
def test(): objs = {} testContexts = {} for contextName in ('DrawBot', 'Flat'): testContexts[contextName] = getContext(contextName) for contextName, context in testContexts.items(): print('* %s' % contextName) objs[contextName] = {} print(' - Units: %s' % context.units) doc = testDocument(context) objs[contextName]['doc'] = doc for contextName, context in testContexts.items(): doc = objs[contextName]['doc'] testPages(doc) for contextName, context in testContexts.items(): print(contextName) doc = objs[contextName]['doc'] # TODO: maybe make this work? #page = doc.pages[-1] page = doc.pages[1][0] print(' - %s' % page) print(' - %s' % type(page)) try: testElements(context, page) except: 'Error running testElements for context %s' % context print(traceback.format_exc()) for contextName, context in testContexts.items(): doc = objs[contextName]['doc'] try: build(doc) export(context) except: msg = '!!!Error buiding and exporting context %s' % context print(msg) print(traceback.format_exc()) break
def setClipPath(): context = getContext() context.fill((0, 1, 1)) context.rect(80, 80, 400, 400) path = context.newPath() path.moveTo((100, 100)) path.lineTo((100, 150)) path.lineTo((200, 200)) path.lineTo((200, 150)) path.lineTo((100, 150)) path.closePath() # This changes the clip path: context.save() context.clipPath(path) context.fill((1, 0, 0, 0.9)) context.rect(150, 150, 600, 600) context.restore() context.fill((1, 1, 0, 0.8)) context.rect(400, 20, 300, 400)
from pagebot import getContext from pagebot.contributions.filibuster.blurb import Blurb from pagebot.toolbox.units import pt from pagebot.toolbox.color import color, Color from pagebot.fonttoolbox.objects.font import findFont H = 850 W = 652 LINE = 29.2 PADDING = 6 f = Color(1, 0, 0) wbox = 300 hbox = 400 blurb = Blurb() context = getContext('DrawBot') context.newDrawing() context.newPage(W, H) x = 0 y = 0 context.text('(%s, %s)' % (x, y), (x, y)) x = W / 2 y = H - hbox context.text('(%s, %s)' % (x, y), (x, y)) b = blurb.getBlurb('stylewars_documentary')[:200] font = findFont('Bungee-Regular') style = dict(font=font, fontSize=pt(18), textFill=color(0.5, 1, 0)) bs = context.newString(b, style=style) lines = bs.getTextLines(w=wbox, h=hbox) attrString = bs.s.getNSObject() setter = CTFramesetterCreateWithAttributedString(attrString)
# Supporting Flat, xxyxyz.org/flat # ----------------------------------------------------------------------------- # # 11_PageCropMarks.py # # Show the baseline grid of the page (drawn by the PageView) # and the relation with the usable page padding area. # from pagebot.document import Document # Get the main Document class from pagebot.toolbox.units import pt, inch from pagebot import getContext from pagebot.constants import BASE_LINE_BG, BASE_Y_LEFT, BASE_INDEX_LEFT, B5 from pagebot.elements import * context = getContext( ) # Get the current context (e.g. DrawBotContext instance) # Example baseline position, showing that start can be different from page side # or top of text box. BASELINE = pt(15) BASELINE_START = 3.5 * BASELINE PADDING = 5 * BASELINE # Page padding related to baseline in this example. doc = Document( size=B5, padding=PADDING, originTop=True, autoPages=3, # Create multiple pages, to show the page number/total pages. baselineGrid=BASELINE, baselineGridStart=BASELINE_START)
from pagebot.document import Document from pagebot.elements import * # Import all types of page-child elements for convenience from pagebot.toolbox.color import color from pagebot.toolbox.units import em, p, pt from pagebot.conditions import * # Import all conditions for convenience. from pagebot.constants import GRID_COL_BG, GRID_ROW_BG, GRID_SQR_BG, LANGUAGE_EN from pagebot.mining.filibuster.samplecontent import SampleContent sampleContent = SampleContent() # Uncomment to show the attribute names of # available sample content. #print(sampleContent.info) # Dummy text text = ' '.join(sampleContent.articles[:]) context = getContext() # Get the context that we are running in (e.g. DrawBotContext = DrawBot) W, H = pt(1500, 1000) # Document size PADDING = pt(100) # Page padding on all sides G = p(2) # 2 Pica gutter PW = W - 2*PADDING # Usable padded page width PH = H - 2*PADDING # Usable padded page height CW = (PW - G)/3 # Column width CH = PH # Hard coded grid for 3 columns, will be automatic in later examples. GRIDX = ((CW, G), (CW, G), (CW, G)) GRIDY = ((CH, 0),) # No division in vertical grid. BASELINE = G # Get the font object, from te Roboto file that is included in PageBot resources for testing. font = findFont('Roboto-Regular')
def testFlatContext(): context = getContext('Flat') # PageBot implementation, to be used for strings and styles. pagebotFont = findFont(FONTNAME) pagebotFill = color((180.0 / 255, 0, 125.0 / 255)) pagebotStroke = color(100.0 / 255, 180.0 / 255, 0) # Native flat implementation of fonts and colors. flatFont = font.open(pagebotFont.path) flatFill = rgb(180, 0, 125) flatStroke = rgb(100, 180, 0) # Stroke width is the same. strokeWidth = 1 ''' Creates a document. ''' # Creating a Flat document. flatDoc = document(WIDTH, HEIGHT, 'pt') flatPage = flatDoc.addpage() # Pagebot equivalent. context.newDrawing(WIDTH, HEIGHT) pbPage = context.newPage() print(pbPage) ''' Draws a figure. ''' # Flat. #figure = shape().fill(flatFill).stroke(flatStroke).width(strokeWidth) #r = figure.rectangle(50, 50, 20, 20) #p.place(r) # Pagebot. #context.fill(pagebotFill) #context.stroke(pagebotStroke) #context.strokeWidth(strokeWidth) #context.rect(50, 50, 20, 20) #print(p.items[0].item.style.width) #print(context.pages[0].items[0].item.style.width) #s = context.pages[0].items[0] #print(s.item.style.fill) #print(s.item.style.stroke) #print(s.item.style.join) #print(s.item.style.limit) ''' Draws text. ''' msg = 'Hello world!' # Flat. header = strike(flatFont).color(flatStroke).size(FONTSIZE, LEADING, units='pt') t = header.text(msg) placedText = flatPage.place(t).frame(100, 100, 380, 80) # Pagebot. style = dict(font=pagebotFont, fontSize=FONTSIZE, textFill=pagebotStroke, leading=LEADING) bs = context.newString(msg, style=style) context.text('bla', (50, 100)) # TODO: also for native flat. context.text(bs, (100, 100)) #print(headline.style.size) #print(headline.style.leading) #print(headline.style.color.r) #print(headline.style.color.g) # Now for conditions and elements. c = (Left2Left(), Fit2Right(), Float2Top()) style = dict(fontSize=14, font=pagebotFont) msg = 'Testing textBox' print(msg) bs = context.newString(msg, style=style) print(type(bs)) newTextBox(bs, font=pagebotFont, parent=pbPage, conditions=c, fill=0.9, margin=4) #print(p.items) ''' Exports file. ''' im = flatPage.image(kind='rgb') # TODO: #imagePath = getResourcesPath() + '/images/peppertom_lowres_398x530.png' #size = context.imageSize(imagePath) #print(size) if not os.path.exists('_export'): os.mkdir('_export') #print('Exporting native') flatDoc.pdf('_export/native-flat.pdf') #im.png('_export/native-flat.png') #im.jpeg('_export/native-flat.jpg') #p.svg('_export/native-flat.svg') #print(context.doc) context.saveDrawing('_export/pagebot-flat.pdf')
def testFlat(): context = getContext('Flat') pagebotFont = findFont(FONTNAME) flatFont = font.open(pagebotFont.path) flatFill = rgb(180, 0, 125) pagebotFill = color((180.0 / 255, 0, 125.0 / 255)) flatStroke = rgb(100, 180, 0) pagebotStroke = color(100.0 / 255, 180.0 / 255, 0) strokeWidth = 1 ''' Creates a document. ''' # Flat. doc = document(WIDTH, HEIGHT, 'pt') p = doc.addpage() # Pagebot. context.newDocument(WIDTH, HEIGHT) context.newPage() ''' Draws a figure. ''' # Flat. figure = shape().fill(flatFill).stroke(flatStroke).width(strokeWidth) r = figure.rectangle(50, 50, 20, 20) p.place(r) # Pagebot. context.fill(pagebotFill) context.stroke(pagebotStroke) context.strokeWidth(strokeWidth) context.rect(50, 50, 20, 20) ''' print(p.items[0].item.style.width) print(context.pages[0].items[0].item.style.width) ''' s = context.pages[0].items[0] ''' print(s.item.style.fill) print(s.item.style.stroke) print(s.item.style.join) print(s.item.style.limit) ''' ''' Draws text. ''' msg = 'Hello world!' # Flat. headline = strike(flatFont).color(flatStroke).size(FONTSIZE, LEADING, units='pt') t = headline.text(msg) entity = p.place(t) entity.frame(100, 100, 380, 80) # Pagebot. style = dict(font=pagebotFont, fontSize=FONTSIZE, color=pagebotStroke, leading=LEADING) bs = context.newString(msg, style=style) context.text('bla', (50, 100)) # TODO: also for native flat. context.text(bs, (100, 100)) ''' print(headline.style.size) print(headline.style.leading) print(headline.style.color.r) print(headline.style.color.g) print(headline.style.color.b) ''' ''' Exports file. ''' im = p.image(kind='rgb') #print(p.items) # TODO: #imagePath = getResourcesPath() + '/images/peppertom_lowres_398x530.png' #size = context.imageSize(imagePath) #print(size) if not os.path.exists('_export'): os.mkdir('_export') #print('Exporting native') doc.pdf('_export/native-flat.pdf') ''' im.png('_export/native-flat.png') im.jpeg('_export/native-flat.jpg') p.svg('_export/native-flat.svg') ''' print(context.doc) context.saveDocument('_export/pagebot-flat.pdf')
h = 240 #H - 2*M x = M y = M tb = newTextBox(s, x=x, y=y, w=w, h=h, parent=page, stroke=sc) y0 = M + h drawBaselines(x, y0, w, tb.baselines, s, page) # Get the rest of the text. txt = tb.getOverflow() style = {'font': robotoRegular, 'fontSize': 24, 'leading': 1.5} s = page.newString(txt, style=style) h = 500 x = W / 2 y = M w = W / 2 - M tb = newTextBox(s, x=x, y=y, w=w, h=h, parent=page, stroke=sc) y0 = M + h drawBaselines(x, y0, w, tb.baselines, s, page) print('Starting doc build') doc.build() for contextName in ('DrawBot', 'Flat'): #for contextName in ('DrawBot',): #for contextName in ('Flat',): context = getContext(contextName) test(context)
def makeDocument(): #Parameters of the docuemnt context = getContext() W, H = pt(1920, 1080) padheight = pt(70) padside = pt(466) PADDING = padheight, padside, padheight, padside G = mm(4) PW = W - 2*padside PH = H - 2*padheight CW = (PW - (G*2))/3 CH = PH GRIDX = ((CW, G), (CW, 0)) GRIDY = ((CH, 0),) # Function for the first column in the main page layout def firstColumnWaterfall(b, fontStyle): s = c.newString('', style=dict(font=f)) CW2 = (PW - (G*2))/3 # Column width for n in range(4): s += c.newString( b + '\n', style=dict(font=fontStyle, fontSize=pt(12+n*1), leading=pt((12+n*1)+3) )) newTextBox(s ,parent=page, w=CW2, h=pt(700),font=f, pt=pt(160), nextElementName='e2',conditions=[Left2Left(),Top2Top(), Overflow2Next()]) doc.solve() # Function for the second column in the main page layout def secondColumnWaterfall(b, fontStyle): s = c.newString('', style=dict(font=f)) CW2 = (PW - (G*2))/3 # Column width for n in range(3): s += c.newString( b + '\n', style=dict(font=fontStyle, fontSize=pt(16+n*2), leading=pt((12+n*2)+6) )) newTextBox(s ,parent=page, w=CW2, h=pt(700),font=f, pt=pt(160), conditions=[Right2Right(),Top2Top()]) doc.solve() # Function for the Waterfall layout def typeWaterfall(x, fontStyle, PageDescription): newTextBox(PageDescription, style=subtitle, w=PW, h=PH, parent=page, columnAlignY = TOP, conditions=(Left2Left(), Top2Top())) st = c.newString('', style=dict(font=f)) for n in range(7): if n < 4: fontSize=144-n*24 leading=(144-n*24)+24 else: fontSize=108-n*12 leading=None st += c.newString( x + '\n', style=dict(font=fontStyle, fontSize=fontSize, leading=leading)) newTextBox(st ,parent=page, padding=pt(4), x=pt(60), y= pt(950), w=W, font=f, cconditions=[Left2Left(), Top2Top(), Overflow2Next()], yAlign=TOP, xAlign=LEFT,) return doc doc.solve() # Create a new document with 1 page. Set overall size and padding. doc = Document(w=W, h=H, padding=PADDING, gridX=GRIDX, gridY=GRIDY, context=context) view = doc.view page = doc[1] subtitle = dict(font=f, fontSize=pt(24), leading=pt(28)) pagePaddings = (50, 50, 50, 50) # Page1 # Function to make the main page layout def mainPage(fontStyle1, fontStyle2): # New text box for the Title maintitle = context.newString("Amstelvar", style=dict(font=fontStyle1, xTextAlign=CENTER, fontSize=pt(96), leading=pt(115))) newTextBox(maintitle, w=PW, h=PH, parent=page, columnAlignY = TOP, xTextAlign=CENTER, conditions=(Center2Center(), Top2Top())) subtitle = dict(font=fontStyle2, fontSize=pt(24), leading=pt(28)) newTextBox("Series by David Berlow", style=subtitle, pt = pt(100), w=PW, h=PH, parent=page, columnAlignY = BOTTOM, xTextAlign=CENTER, conditions=(Center2Center(), Bottom2Bottom())) # 3 columns heightCol = pt(700) textString = "ABCDEFG HIJKLMN OPQRSTU VWXYZ&! abcdefghij klmnopqrs tuvwxyzĸ¢ 1234567890" centertext = context.newString(textString, style=dict(font=fontStyle1, xTextAlign=CENTER, fontSize=pt(60), leading=pt(69))) CW2 = (PW - (G*2)) # Column width style3 = dict(font=f, fontSize=pt(60), leading=pt(69), hyphenation=None, prefix= None, postfix=None) newTextBox(centertext, style=style3, w=CW, h=heightCol, pt = pt(148), xTextAlign=CENTER, parent=page, conditions=[Center2Center(), Top2Top()]) text4 = "Betreed de wereld van de invloedrijke familie Plantin en Moretus. Christophe Plantin bracht zijn leven door in boeken. Samen met zijn vrouw en vijf dochters woonde hij in een imposant pand aan de Vrijdagmarkt. Plantin en Jan Moretus hebben een indrukwekkende drukkerij opgebouwd. Tegenwoordig is dit het enige museum ter wereld dat ..." style4 = dict(font=fontStyle2, fontSize=pt(29), leading=pt(35)) newTextBox(text4, style=style4, xTextAlign=JUSTIFIED, w=CW2, parent=page, conditions=[Left2Left(), Bottom2Bottom()]) b = ("Hyni në botën e familjes me ndikim Plantin dhe Moretus. Christophe Plantin e kaloi jetën mes librave. Së bashku me gruan dhe pesë bijat e tij, ai jetonte në një pronë imponuese në Vrijdagmarkt. Plantin dhe Jan Moretus krijuan një biznes shtypës mbresëlënës. Sot, ky është muze i vetëm në botë që do të ... \n ") firstColumnWaterfall(b, fontStyle2) secondColumnWaterfall(b, fontStyle2) doc.solve() # Parameters of the function fontStyle1 = H2OPTICAL.path fontStyle2 = f.path mainPage(fontStyle1, fontStyle2) # Page2 # Function to make the one column layout page = page.next def oneColumnPage(fontStyle, textString, PageDescription): astring = context.newString(textString, style=dict(font=fontStyle, xTextAlign=CENTER, fontSize=pt(144), leading=pt(163))) page.padding = pagePaddings padd= pt(100) PW2 = W - 2*padd newTextBox(astring, pt= pt(130), w=PW2, h=H, hyphenation=False, parent=page, conditions=(Center2Center(), Middle2Middle())) newTextBox(PageDescription, style=subtitle, w=PW, hyphenation=False, h=PH, parent=page, columnAlignY = TOP, conditions=(Left2Left(), Top2Top())) doc.solve() # Parameters of the function textString = "Aa Bb Cc Dd Ee Ff \nGg Hh Ii Jj Kk \nLl Mm Nn Oo Pp \nQq Rr Ss Tt Uu \nVv Ww Xx Yy Zz" PageDescription = "Opsz-max camelcase roman" fontStyle = MAXOPTICAL.path oneColumnPage(fontStyle, textString, PageDescription) # Page3 page = page.next PageDescription = "Opsz-default camelcase roman" fontStyle = f.path oneColumnPage(fontStyle, textString, PageDescription) #Page4 page = page.next PageDescription = "Opsz-min camelcase roman" fontStyle = MINOPTICAL.path oneColumnPage(fontStyle, textString, PageDescription) # Page 5 #Function to make the 3 column layout page = page.next def threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription): page.padding = pagePaddings CW3 = (W-120)/3 # Column width cstring = context.newString(textString, style=dict(font=fontStyle1, xTextAlign=CENTER, fontSize=pt(144), leading=pt(163))) dstring = context.newString(textString, style=dict(font=fontStyle2, xTextAlign=CENTER, fontSize=pt(144), leading=pt(163), hyphenation=None)) spreads= dict(font=fontStyle3, fontSize=pt(144), leading=pt(163)) newTextBox(cstring, w=(CW3+10), parent=page, conditions=[Left2Left(), Middle2Middle()]) newTextBox(textString, style=spreads, w=CW3, xTextAlign=CENTER, parent=page, conditions=[Center2Center(), Middle2Middle()]) newTextBox(dstring, w=CW3, parent=page, conditions=[Right2Right(), Middle2Middle()]) newTextBox(PageDescription, style=subtitle, w=PW, h=PH, parent=page, columnAlignY = TOP, conditions=(Left2Left(), Top2Top())) doc.solve() # Parameters of the function textString = "ABCDE\nFGHIJK\nLMNOP\nQRSTU\nVWXYZ" PageDescription = "Opsz-min opsz-default opsz-max uppercase roman" fontStyle1 = MINOPTICAL.path fontStyle2 = MAXOPTICAL.path fontStyle3 = f.path threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription) # Page 6 page = page.next textString = 'abcde\nfghijk\nlmnop\nqrstu\nvwxyz' PageDescription = "Opsz-min opsz-default opsz-max lowercase roman" fontStyle1 = MINOPTICAL.path fontStyle2 = MAXOPTICAL.path fontStyle3 = f.path threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription) # Page 7 page = page.next page.padding = pagePaddings x = 'ABCDEFGHIJKLMNOPQRST' fontStyle = MAXOPTICAL.path PageDescription = 'Waterfall uppercase roman' typeWaterfall(x, fontStyle, PageDescription) # Page 8 page = page.next page.padding = pagePaddings x = 'abcdefghijklmnopqrstuvwxyz' fontStyle = MAXOPTICAL.path PageDescription = 'Waterfall lowercase roman' typeWaterfall(x, fontStyle, PageDescription) # Page 9 page = page.next page.padding = pagePaddings x = '123456789!@#$%^&*()_+{}|:”<>?/.,’;\][' fontStyle = MAXOPTICAL.path PageDescription = 'Waterfall numerals and punctuation roman' typeWaterfall(x, fontStyle, PageDescription) # Page 10 page = page.next page.padding = pagePaddings x = '₡$€£₣₤₦₩₫₭₱₲₵₹₺₼₽' fontStyle = MAXOPTICAL.path PageDescription = 'Waterfall monetary' typeWaterfall(x, fontStyle, PageDescription) # Page 1 Italic page = page.next fontStyle1 = H2OPTICALIT.path fontStyle2 = f2.path mainPage(fontStyle1, fontStyle2) # Page 2 Italic page = page.next textString = "Aa Bb Cc Dd Ee Ff \nGg Hh Ii Jj Kk \nLl Mm Nn Oo Pp \nQq Rr Ss Tt Uu \nVv Ww Xx Yy Zz" PageDescription = "Opsz-max camelcase italic" fontStyle = MAXOPTICALIT.path oneColumnPage(fontStyle, textString, PageDescription) # Page 3 Italic page = page.next PageDescription = "Opsz-default camelcase italic" fontStyle = f2.path oneColumnPage(fontStyle, textString, PageDescription) # Page 4 Italic page = page.next PageDescription = "Opsz-min camelcase italic" fontStyle = MINOPTICALIT.path oneColumnPage(fontStyle, textString, PageDescription) # Page 5 Italic page = page.next textString = "ABCDE\nfFGHIJK\nfLMNOP\nfQRSTU\nfVWXYZ" PageDescription = "Opsz-min opsz-default opsz-max uppercase italic" fontStyle1 = MINOPTICALIT.path fontStyle2 = MAXOPTICALIT.path fontStyle3 = f2.path threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription) # Page 6 Italic page = page.next textString = 'abcde\nfghijk\nlmnop\nqrstu\nvwxyz' PageDescription = "Opsz-min opsz-default opsz-max lowercase italic" fontStyle1 = MINOPTICALIT.path fontStyle2 = MAXOPTICALIT.path fontStyle3 = f2.path threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription) doc.solve() # Page 7 Italic page = page.next page.padding = pagePaddings x = 'ABCDEFGHIJKLMNOPQRST' fontStyle = MAXOPTICALIT.path PageDescription = 'Waterfall uppercase italic' typeWaterfall(x, fontStyle, PageDescription) doc.solve() # Page 8 Italic page = page.next page.padding = pagePaddings x = 'abcdefghijklmnopqrstuvwxyz' fontStyle = MAXOPTICALIT.path PageDescription = 'Waterfall lowercase italic' typeWaterfall(x, fontStyle, PageDescription) doc.solve() # Page 9 Italic page = page.next page.padding = pagePaddings x = '123456789!@#$%^&*()_+{}|:”<>?/.,’;\][' fontStyle = MAXOPTICALIT.path PageDescription = 'Waterfall numerals and punctuation roman' typeWaterfall(x, fontStyle, PageDescription) doc.solve() # Page 10 Italic page = page.next page.padding = pagePaddings x = '₡$€£₣₤₦₩₫₭₱₲₵₹₺₼₽' fontStyle = MAXOPTICALIT.path PageDescription = 'Waterfall monetary' typeWaterfall(x, fontStyle, PageDescription) page.solve() return doc
def makeDocument(): #Parameters of the docuemnt context = getContext() W, H = pt(1920, 1080) padheight = pt(70) padside = pt(466) PADDING = padheight, padside, padheight, padside G = mm(4) PW = W - 2 * padside PH = H - 2 * padheight CW = (PW - (G * 2)) / 3 CH = PH GRIDX = ((CW, G), (CW, 0)) GRIDY = ((CH, 0), ) fontSizeH1 = 144 points = ' / ' + str(fontSizeH1) # Function for the first column in the main page layout def firstColumnWaterfall(b, fontStyle): s = c.newString('', style=dict(font=f)) s2 = c.newString('', style=dict(font=f)) CW2 = (PW - (G * 2)) / 3 # Column width for n in range(4): fontSize = pt(12 + n * 1) leading = pt((12 + n * 1) + 3) if n < 3: leading2 = pt(((12 + n * 1) * n) + 90 + n * 4) else: leading2 = ((12 + n * 1) * n) + 86 + n s += c.newString(b + '\n', style=dict(font=fontStyle, fontSize=fontSize, leading=leading)) s2 += c.newString(str(fontSize) + '/' + str(leading) + '\n', style=dict(font=fontStyle, fontSize=10, leading=leading2)) newTextBox(s, parent=page, w=CW2, h=pt(700), font=f, pt=pt(160), nextElementName='e2', conditions=[Left2Left(), Top2Top(), Overflow2Next()]) newTextBox(s2, parent=page, w=CW2, h=pt(700), font=f, pt=(pt(70)), nextElementName='e2', conditions=[Left2Left(), Top2Top(), Overflow2Next()]) doc.solve() # Function for the second column in the main page layout def secondColumnWaterfall(b, fontStyle): s = c.newString('', style=dict(font=f)) s2 = c.newString('', style=dict(font=f)) CW2 = (PW - (G * 2)) / 3 # Column width for n in range(3): fontSize = pt(16 + n * 2) leading = pt((12 + n * 2) + 6) if n < 1: leading2 = (((12 + n * 2) + 6) * n * 2) + 90 + n * 10 elif n < 2: leading2 = (((12 + n * 2) + 6) * n * 2) + 110 + n * 10 else: leading2 = ((((12 + n * 2) + 6) * n * 2) + 76 + n * 10) + n * 6 s += c.newString(b + '\n', style=dict(font=fontStyle, fontSize=fontSize, leading=leading)) s2 += c.newString(str(fontSize) + '/' + str(leading) + '\n', style=dict(font=fontStyle, fontSize=10, leading=leading2)) newTextBox(s, parent=page, w=CW2, h=pt(700), font=f, pt=pt(160), conditions=[Right2Right(), Top2Top()]) newTextBox(s2, parent=page, w=CW2, h=pt(700), font=f, pt=(pt(70)), conditions=[Right2Right(), Top2Top()]) doc.solve() # Function for the Waterfall layout def typeWaterfall(x, fontStyle, PageDescription, pageNumber): newTextBox(PageDescription, style=subtitle, w=PW, h=PH, parent=page, columnAlignY=TOP, conditions=(Left2Left(), Top2Top())) newTextBox(pageNumber, style=subtitle, xTextAlign=RIGHT, w=50, h=PH, parent=page, columnAlignY=TOP, conditions=(Right2Right(), Top2Top())) st = c.newString('', style=dict(font=f)) st2 = c.newString('', style=dict(font=f)) for n in range(7): if n < 4: fontSize = 144 - n * 24 leading = (144 - n * 24) + 24 leading2 = (144 - n * 24) + 24 else: fontSize = 108 - n * 12 leading = None leading2 = (108 - n * 12) + 24 st += c.newString(x + '\n', style=dict(font=fontStyle, fontSize=fontSize, leading=leading)) st2 += c.newString(str(fontSize) + 'pt' + '\n', style=dict(font=fontStyle, fontSize=12, leading=leading2)) newTextBox( st, parent=page, padding=pt(4), x=pt(60), y=pt(950), w=W, font=f, cconditions=[Left2Left(), Top2Top(), Overflow2Next()], yAlign=TOP, xAlign=LEFT, ) newTextBox( st2, parent=page, padding=pt(4), x=pt(60), y=pt(940), w=W, font=f, cconditions=[Left2Left(), Top2Top(), Overflow2Next()], yAlign=TOP, xAlign=LEFT, ) return doc doc.solve() # Function for the Waterfall layout def typeWaterfallTwolines(x, fontStyle, PageDescription, pageNumber): newTextBox(PageDescription, style=subtitle, w=PW, h=PH, parent=page, columnAlignY=TOP, conditions=(Left2Left(), Top2Top())) newTextBox(pageNumber, style=subtitle, xTextAlign=RIGHT, w=50, h=PH, parent=page, columnAlignY=TOP, conditions=(Right2Right(), Top2Top())) st = c.newString('', style=dict(font=f)) st2 = c.newString('', style=dict(font=f)) for n in range(7): if n < 4: fontSize = 144 - n * 24 leading = (144 - n * 24) + 24 leading2 = (144 - n * 24) + 24 else: fontSize = 108 - n * 12 leading = None leading2 = (108 - n * 12) + 24 st += c.newString(x + '\n', style=dict(font=fontStyle, hyphenation=False, fontSize=fontSize, leading=leading)) st2 += c.newString(str(fontSize) + 'pt' + '\n', style=dict(font=fontStyle, fontSize=12, leading=leading2)) newTextBox( st, parent=page, hyphenation=False, padding=pt(4), x=pt(60), y=pt(950), w=W - 50, font=f, cconditions=[Left2Left(), Top2Top(), Overflow2Next()], yAlign=TOP, xAlign=LEFT, ) newTextBox( st2, parent=page, padding=pt(4), x=pt(60), y=pt(780), w=W, font=f, cconditions=[Left2Left(), Top2Top(), Overflow2Next()], yAlign=TOP, xAlign=LEFT, ) return doc doc.solve() # Create a new document with 1 page. Set overall size and padding. doc = Document(w=W, h=H, padding=PADDING, gridX=GRIDX, gridY=GRIDY, context=context) view = doc.view page = doc[1] subtitle = dict(font=f, fontSize=pt(18), leading=pt(28)) pagePaddings = (50, 50, 50, 50) # Page1 # Function to make the main page layout def mainPage(fontStyle1, fontStyle2, pageNumber, defaultfont): # New text box for the Title maintitle = context.newString("Amstelvar", style=dict(font=fontStyle1, xTextAlign=CENTER, fontSize=pt(96), leading=pt(115))) newTextBox(maintitle, w=PW, h=PH, parent=page, columnAlignY=TOP, xTextAlign=CENTER, conditions=(Center2Center(), Top2Top())) subtitle = dict(font=fontStyle2, fontSize=pt(18), leading=pt(28)) subtitle2 = dict(font=defaultfont, fontSize=pt(18), leading=pt(28)) newTextBox(pageNumber, w=W - 100, pt=-20, h=PH + 100, parent=page, xAlign=RIGHT, xTextAlign=RIGHT, style=subtitle2, conditions=(Center2Center(), Top2Top())) newTextBox("Series by David Berlow", style=subtitle, pt=pt(100), w=PW, h=PH, parent=page, columnAlignY=BOTTOM, xTextAlign=CENTER, conditions=(Center2Center(), Bottom2Bottom())) # 3 columns heightCol = pt(700) textString = "ABCDEFG HIJKLMN OPQRSTU VWXYZ&! abcdefghij klmnopqrs tuvwxyzĸ¢ 1234567890" centertext = context.newString(textString, style=dict(font=fontStyle1, xTextAlign=CENTER, fontSize=pt(60), leading=pt(69))) CW2 = (PW - (G * 2)) # Column width style3 = dict(font=f, fontSize=pt(60), leading=pt(69), hyphenation=None, prefix=None, postfix=None) newTextBox(centertext, style=style3, w=CW, h=heightCol, pt=pt(158), xTextAlign=CENTER, parent=page, conditions=[Center2Center(), Top2Top()]) text4 = "Betreed de wereld van de invloedrijke familie Plantin en Moretus. Christophe Plantin bracht zijn leven door in boeken. Samen met zijn vrouw en vijf dochters woonde hij in een imposant pand aan de Vrijdagmarkt. Plantin en Jan Moretus hebben een indrukwekkende drukkerij opgebouwd. Tegenwoordig is dit het enige museum ter wereld dat ..." style4 = dict(font=fontStyle2, fontSize=pt(28), leading=pt(34)) newTextBox(text4, style=style4, xTextAlign=JUSTIFIED, w=CW2 + 26, h=pt(380), parent=page, pt=pt(174), conditions=[Right2Right(), Bottom2Bottom()]) style5 = dict(font=defaultfont, fontSize=pt(10)) b = ( "Hyni në botën e familjes me ndikim Plantin dhe Moretus. Christophe Plantin e kaloi jetën mes librave. Së bashku me gruan dhe pesë bijat e tij, ai jetonte në një pronë imponuese në Vrijdagmarkt. Plantin dhe Jan Moretus krijuan një biznes shtypës mbresëlënës. Sot, ky është muze i vetëm në botë që mbresëlënës do gruan ... \n " ) c = ( "Hyni në botën e familjes me ndikim Plantin dhe Moretus. Christophe Plantin e kaloi jetën mes librave. Së bashku me gruan dhe pesë bijat e tij, ai jetonte në një pronë imponuese në Vrijdagmarkt. Plantin dhe Jan Moretus krijuan një biznes shtypës mbresëlënës. Sot, ky është muze i vetëm në botë që mbresëlënës do ... \n " ) newTextBox('60pt/72pt', fontSize=pt(10), parent=page, w=CW - 60, h=heightCol, font=f, pt=pt(146), conditions=[Center2Center(), Top2Top()]) newTextBox('28pt/34pt', fontSize=pt(10), parent=page, w=CW2, h=pt(380), font=f, pt=pt(160), conditions=[Left2Left(), Bottom2Bottom()]) firstColumnWaterfall(b, fontStyle2) secondColumnWaterfall(c, fontStyle2) doc.solve() # Parameters of the function fontStyle1 = H2OPTICAL.path fontStyle2 = f.path defaultfont = f.path pageNumber = '1' mainPage(fontStyle1, fontStyle2, pageNumber, defaultfont) # Page2 # Function to make the one column layout page = page.next def oneColumnPage(fontStyle, textString, PageDescription, pageNumber): astring = context.newString(textString, style=dict(font=fontStyle, xTextAlign=CENTER, fontSize=fontSizeH1, leading=pt(163))) page.padding = pagePaddings padd = pt(100) PW2 = W - 2 * padd newTextBox(astring, pt=pt(130), w=PW2, h=H, hyphenation=False, parent=page, conditions=(Center2Center(), Middle2Middle())) newTextBox(PageDescription, style=subtitle, w=PW, hyphenation=False, h=PH, parent=page, columnAlignY=TOP, conditions=(Left2Left(), Top2Top())) newTextBox(pageNumber, style=subtitle, xTextAlign=RIGHT, w=50, h=PH, parent=page, columnAlignY=TOP, conditions=(Right2Right(), Top2Top())) #newTextBox('144pt', style=subtitle, xTextAlign=CENTER, w=200, h=50, parent=page, columnAlignY = TOP, conditions=(Center2Center(), Top2Top())) doc.solve() # Parameters of the function textString = "Aa Bb Cc Dd Ee Ff \nGg Hh Ii Jj Kk \nLl Mm Nn Oo Pp \nQq Rr Ss Tt Uu \nVv Ww Xx Yy Zz" PageDescription = "Opsz-max camelcase roman" + points fontStyle = MAXOPTICAL.path pageNumber = '2' oneColumnPage(fontStyle, textString, PageDescription, pageNumber) # Page3 page = page.next PageDescription = "Opsz-default camelcase roman" + points fontStyle = f.path pageNumber = '3' oneColumnPage(fontStyle, textString, PageDescription, pageNumber) #Page4 page = page.next PageDescription = "Opsz-min camelcase roman" + points fontStyle = MINOPTICAL.path pageNumber = '4' oneColumnPage(fontStyle, textString, PageDescription, pageNumber) # Page 5 #Function to make the 3 column layout page = page.next def threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription, pageNumber): page.padding = pagePaddings CW3 = (W - 120) / 3 # Column width cstring = context.newString(textString, style=dict(font=fontStyle1, xTextAlign=CENTER, fontSize=fontSizeH1, leading=pt(163))) dstring = context.newString(textString, style=dict(font=fontStyle2, xTextAlign=CENTER, fontSize=fontSizeH1, leading=pt(163), hyphenation=None)) spreads = dict(font=fontStyle3, fontSize=fontSizeH1, leading=pt(163)) newTextBox(cstring, w=(CW3 + 10), parent=page, conditions=[Left2Left(), Middle2Middle()]) newTextBox(textString, style=spreads, w=CW3, xTextAlign=CENTER, parent=page, conditions=[Center2Center(), Middle2Middle()]) newTextBox(dstring, w=CW3, parent=page, conditions=[Right2Right(), Middle2Middle()]) newTextBox(PageDescription, style=subtitle, w=PW, h=PH, parent=page, columnAlignY=TOP, conditions=(Left2Left(), Top2Top())) newTextBox(pageNumber, style=subtitle, xTextAlign=RIGHT, w=50, h=PH, parent=page, columnAlignY=TOP, conditions=(Right2Right(), Top2Top())) #newTextBox('144pt', style=subtitle, xTextAlign=CENTER, w=200, h=50, parent=page, columnAlignY = TOP, conditions=(Center2Center(), Top2Top())) doc.solve() # Parameters of the function textString = "ABCDE\nFGHIJK\nLMNOP\nQRSTU\nVWXYZ" PageDescription = "Opsz-min opsz-default opsz-max uppercase roman" + points fontStyle1 = MINOPTICAL.path fontStyle2 = MAXOPTICAL.path fontStyle3 = f.path pageNumber = '5' threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription, pageNumber) # Page 6 page = page.next textString = 'adhesion' PageDescription = "Opsz-min opsz-default opsz-max lowercase roman" + points fontStyle1 = MINOPTICAL.path fontStyle2 = MAXOPTICAL.path fontStyle3 = f.path pageNumber = '6' threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription, pageNumber) # Page 7 page = page.next page.padding = pagePaddings x = 'ADHESION' fontStyle = MAXOPTICAL.path PageDescription = 'Waterfall uppercase roman' pageNumber = '7' typeWaterfallTwolines(x, fontStyle, PageDescription, pageNumber) # Page 8 page = page.next page.padding = pagePaddings x = 'adhesion' fontStyle = MAXOPTICAL.path PageDescription = 'Waterfall lowercase roman' pageNumber = '8' typeWaterfall(x, fontStyle, PageDescription, pageNumber) # Page 9 page = page.next page.padding = pagePaddings x = '1234567890‘?“!(%)[#]{@}/&\$:;,._^*' fontStyle = MAXOPTICAL.path PageDescription = 'Waterfall numerals and punctuation roman' pageNumber = '9' typeWaterfallTwolines(x, fontStyle, PageDescription, pageNumber) # Page 10 page = page.next page.padding = pagePaddings x = '₡$€£₣₤₦₩₫₭₱₲₵₹₺₼₽' fontStyle = MAXOPTICAL.path PageDescription = 'Waterfall monetary' pageNumber = '10' typeWaterfall(x, fontStyle, PageDescription, pageNumber) # Page 1 Italic page = page.next fontStyle1 = H2OPTICALIT.path fontStyle2 = f2.path defaultfont = f.path pageNumber = '11' mainPage(fontStyle1, fontStyle2, pageNumber, defaultfont) # Page 2 Italic page = page.next textString = "Aa Bb Cc Dd Ee Ff \nGg Hh Ii Jj Kk \nLl Mm Nn Oo Pp \nQq Rr Ss Tt Uu \nVv Ww Xx Yy Zz" PageDescription = "Opsz-max camelcase italic" + points fontStyle = MAXOPTICALIT.path pageNumber = '12' oneColumnPage(fontStyle, textString, PageDescription, pageNumber) # Page 3 Italic page = page.next PageDescription = "Opsz-default camelcase italic" + points fontStyle = f2.path pageNumber = '13' oneColumnPage(fontStyle, textString, PageDescription, pageNumber) # Page 4 Italic page = page.next PageDescription = "Opsz-min camelcase italic" + points fontStyle = MINOPTICALIT.path pageNumber = '14' oneColumnPage(fontStyle, textString, PageDescription, pageNumber) # Page 5 Italic page = page.next textString = "ABCDE\nFGHIJK\nLMNOP\nQRSTU\nVWXYZ" PageDescription = "Opsz-min opsz-default opsz-max uppercase italic" + points fontStyle1 = MINOPTICALIT.path fontStyle2 = MAXOPTICALIT.path fontStyle3 = f2.path pageNumber = '15' threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription, pageNumber) # Page 6 Italic page = page.next textString = 'abcde\nfghijk\nlmnop\nqrstu\nvwxyz' PageDescription = "Opsz-min opsz-default opsz-max lowercase italic" + points fontStyle1 = MINOPTICALIT.path fontStyle2 = MAXOPTICALIT.path fontStyle3 = f2.path pageNumber = '16' threeColumnPage(fontStyle1, fontStyle2, fontStyle3, textString, PageDescription, pageNumber) doc.solve() # Page 7 Italic page = page.next page.padding = pagePaddings x = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' fontStyle = MAXOPTICALIT.path PageDescription = 'Waterfall uppercase italic' pageNumber = '17' typeWaterfallTwolines(x, fontStyle, PageDescription, pageNumber) doc.solve() # Page 8 Italic page = page.next page.padding = pagePaddings x = 'abcdefghijklmnopqrstuvwxyz' fontStyle = MAXOPTICALIT.path PageDescription = 'Waterfall lowercase italic' pageNumber = '18' typeWaterfall(x, fontStyle, PageDescription, pageNumber) doc.solve() # Page 9 Italic page = page.next page.padding = pagePaddings x = '1234567890‘?“!(%)[#]{@}/&\$:;,._^*' fontStyle = MAXOPTICALIT.path PageDescription = 'Waterfall numerals and punctuation roman' pageNumber = '19' typeWaterfallTwolines(x, fontStyle, PageDescription, pageNumber) doc.solve() # Page 10 Italic page = page.next page.padding = pagePaddings x = '₡$€£₣₤₦₩₫₭₱₲₵₹₺₼₽' fontStyle = MAXOPTICALIT.path PageDescription = 'Waterfall monetary' pageNumber = '20' typeWaterfall(x, fontStyle, PageDescription, pageNumber) page.solve() return doc
from pagebot.fonttoolbox.objects.font import findFont from pagebot.elements import newTextBox, newImage W = 652 H = 850 W = pt(W) H = pt(H) PADDING = pt(83, 42, 19, 33) ACC_GUTTER = pt(32) # Distance between accommodations IMG_GUTTER = pt(3) # Vertical distance between images COL_GUTTER = pt(12) # Distance between columns #f = Color(0, 0, 0) s = Color(1, 0, 0) drawBotContext = getContext('DrawBot') flatContext = getContext('Flat') boldFontName = 'PageBot-Bold' boldFont = findFont(boldFontName) regularFontName = 'Roboto-Regular' regularFont = findFont(regularFontName) LINE = 12 TEXTSIZE = 12 HEADSIZE = 14 def loadJSON(context): doc = Document(w=W, h=H, originTop=False, context=context) #doc = Document(w=W, h=H, originTop=True, context=context) view = doc.getView() view.showPadding = True view.showDimensions = True
def produce(self, srcPaths, viewId=None, cssPy=None, resourcePaths=None, cssUrls=None, defaultImageWidth=None, name=None, title=None, theme=None, verbose=False, spellCheck=False, doOpen=True, **kwargs): """Create a Document with the current settings of self. Then build the document using the defined view (detault is MampView.viewId) to make the Mamp site. Finally answer the created Document instance.""" if defaultImageWidth is None: defaultImageWidth = MAX_IMAGE_WIDTH if theme is None: theme = self.theme if not isinstance(srcPaths, (list, tuple)): srcPaths = [srcPaths] context = getContext('Html') doc = self.newDocument(viewId=viewId or self.DEFAULT_VIEW_ID, autoPages=1, defaultImageWidth=defaultImageWidth, name=name or self.name, title=title or self.title, theme=theme, context=context, **kwargs) # Write the CSS, set the view css paths and translate cssPy into css # source file. view = doc.view view.resourcePaths = resourcePaths or ['css'] view.cssUrls = cssUrls or ['css/normalized.css'] if cssPy is not None: p = os.path.abspath(__file__) base = '/'.join(p.split('/')[:-1]) # Generate css by mapping theme.mood on cssPy. cssPath = '%s/css/nanostyle_py.css' % base view.cssUrls.append(cssPath) try: doc.context.b.writeCss(cssPath, cssPy % doc.theme.mood) except: # Travis crashes on relative path. print(traceback.format_exc()) # Make the all pages and elements of the site as empty containers, that # then can be selected and filled by the composer, using the galley # content. Of the MarkDown text can decide to create new elements # inside selected elements. template = self.makeTemplate(doc) page = doc[1] # Copy element tree to page. page.applyTemplate(template) # By default, the typesetter produces a single Galley with content and # code blocks. t = Typesetter(doc.context) for srcPath in srcPaths: galley = t.typesetFile(srcPath) # Creates a Composer for this document, then create pages and fill # content. composer = Composer(doc) # The composer executes the embedded Python code blocks that indicate # where content should go. by the HtmlContext. Feedback by the code # blocks is added to verbose and errors list targets = dict(doc=doc, page=page, template=template) composer.compose(galley, targets=targets) if verbose: if targets['verbose']: print('Verbose\n', '\n'.join(targets['verbose'])) # In case there are any errors, show them. if targets['errors']: print('Errors\n', '\n'.join(targets['errors'])) # Find the navigation elements and fill them, now we know all the # pages. self.makeNavigation(doc) if spellCheck: # https://www.hyphenator.net/en/word/... unknownWords = doc.spellCheck(LANGUAGE_EN) if unknownWords: print(unknownWords) view = doc.view mampPath = getMampPath() siteName = doc.name.replace(' ', '_') filePath = mampPath + siteName if verbose: print('Site path: %s' % filePatah) if os.path.exists(filePath): # Comment this line, if more safety is required. In that case # manually delete. shutil.rmtree(filePath) doc.export(filePath) if doOpen: url = view.getUrl(siteName) os.system(u'/usr/bin/open "%s"' % url) return doc
H, W = A3 W = pt(W) H = pt(H) M = 36 roboto = findFont('Roboto-Regular') robotoBold = findFont('Roboto-Bold') bungee = findFont('Bungee-HairlineRegular') bungeeSize = 48 blurb = Blurb() txt = blurb.getBlurb('news_headline', noTags=True) testContexts = ( (getContext('DrawBot'), '_export/testDrawBotString.pdf'), (getContext('Flat'), '_export/testFlatString.pdf'), ) def drawLines(page): page.context.fill(noColor) page.context.stroke((0.2, 0.7, 0.5, 0.3)) page.context.strokeWidth(1) page.context.line((M, 0), (M, H)) # Number of lines. r = H / M for i in range(int(r)):
# # SimpleDocument.py # # This is a simple page document to show the working of layouts # using conditions. # from pagebot.constants import A4 from pagebot.document import Document from pagebot.elements import newRect, newTextBox from pagebot.conditions import * from pagebot.toolbox.color import color from pagebot.toolbox.units import pt, p if 1: from pagebot import getContext context = getContext() # DrawBotContext or FlatContext if available. else: from pagebot.contexts.svgcontext import SvgContext context = SvgContext() SIZE = 498, 770 #A4 # Standard page size # To see how the "responsive" layout works in landscape, swap W and H #H, W = A4 PAD = pt(50) # Page padding # Create a Document instance of the defined size and one automatic page. doc = Document(size=SIZE, title="Demo pages", originTop=False, context=context) # Get the view of the document. By default this is a PageView, writing # on a DrawBotContext or FlatContext, whatever is avaialbe as default. view = doc.view view.padding = pt(
from pagebot import getContext from pagebot.contributions.filibuster.blurb import Blurb from pagebot.toolbox.units import pt from pagebot.toolbox.color import color, Color from pagebot.fonttoolbox.objects.font import findFont H = 850 W = 652 LINE = 29.2 PADDING = 6 f = Color(1, 0, 0) wbox = 300 hbox = 400 blurb = Blurb() context = getContext('Flat') context.newDrawing() context.newPage(W, H) x = 0 y = 0 context.text('(%s, %s)' % (x, y), (x, y)) b = blurb.getBlurb('stylewars_documentary')[:200] font = findFont('Bungee-Regular') style = dict(font=font, fontSize=pt(18), textFill=color(0.5, 1, 0)) bs = context.newString(b, style=style) lines = bs.getTextLines(w=wbox, h=hbox) print(lines) context.fill(None)
# Licensed under MIT conditions # # Supporting DrawBot, www.drawbot.com # Supporting Flat, xxyxyz.org/flat # ----------------------------------------------------------------------------- # # UseGlyphBeamIntersection.py # # Implements a PageBot font classes to get info from a TTFont. # Show drawing of outline points and intersection beam with flattened path # from pagebot.fonttoolbox.objects.font import findFont from pagebot import getContext from pagebot.toolbox.color import color, noColor, blackColor c = getContext() c.newPage(2000, 550) c.scale(0.5) font = findFont('PageBot-Bold') print(font.analyzer) print(font.analyzer.name) def drawGlyph(px, py, glyph): ga = glyph.analyzer # Three ways to access the glyph metrics #print('Glyph width:', ga.width, ga.glyph.width, glyph.width) #print('Glyph bounding box:', ga.boundingBox) # X position of vertical lines also includes sides of serifs.
def _getContext(self): """Answers the best/default context for this type of view.""" return getContext( ) # Default is DrawBotContext or FlatContext instance.
# # P A G E B O T # # Licensed under MIT conditions # # Supporting DrawBot, www.drawbot.com # Supporting Flat, xxyxyz.org/flat # ----------------------------------------------------------------------------- # # TODO: Floating on second line does not seem to work currently from pagebot.conditions import * from pagebot import getContext from pagebot.elements.element import Element context = getContext() #context = getContext('Flat') context.newDrawing() context.newPage() e = Element(w=500, h=500, context=context) print(' * Testing in %s' % context.name) print(e) print(e.childClipPath) e1 = Element(parent=e, x=0, y=0, w=50, h=80) # Flat not getting correct results due to missing boolean operators. print(len(e.childClipPath)) # 7 print(len(e1.childClipPath)) # 7 print(e.childClipPath.points) print(e1.childClipPath.points) #[(50.0, 0.0), (500.0, 0.0), (500.0, 500.0), (0.0, 500.0), (0.0, 80.0), (50.0, 80.0), (50.0, 0.0)]
# # Draw a two columns with a single text, showing overflow from one column # into the other. Use some view.showGrid options to show the grid. # Use view.showBaselineGrid = True to show the default baselines of the text. from pagebot import getContext from pagebot.fonttoolbox.objects.font import findFont from pagebot.document import Document from pagebot.elements import * # Import all types of page-child elements for convenience from pagebot.toolbox.color import color from pagebot.toolbox.units import em, p, pt from pagebot.conditions import * # Import all conditions for convenience. from pagebot.constants import * context = getContext() # Probably DrawBotContext, when running in DrawBot. W = H = pt(1000) # Document size for square pages. PADDING = pt(100) # Page padding on all sides G = p(2) # 2 Pica gutter PW = W - 2*PADDING # Usable padded page width PH = H - 2*PADDING # Usable padded page height CW = (PW - 3*G)/4 # Column width CH = (PH - 3*G)/4 # Column height, same as with in this example, because page is square. # Hard coded grid, will be automatic in later examples. GRIDX = ((CW, G), (CW, G), (CW, G), (CW, G)) GRIDY = ((CH, G), (CH, G), (CH, G), (CH, G)) 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. """ font = findFont('Roboto-Regular')