def useBabelStrings(): for contextId, context in ( ('DrawBot', DrawBotContext()), ('Flat', FlatContext())): W, H = pt(1000, 300) M = pt(100) EXPORT_PATH = '_export/UseBabelStrings-%s.pdf' % contextId # Create a page and set y on top margin. context.newPage(W, H) y = H - M cs = context.newString('Context: %s' % contextId, style={'textFill': color(0, 0, 1), 'fontSize': 36}) context.text(cs, (100, y)) y -= 20 # Create formatted string, with default settings of font, fontSize and textFill color bs = context.newString('This is a formatted BabelString') print(bs.__class__.__name__) context.text(bs, (100, y)) # FIXME: solve for Flat. # Add string with formatting style dict bs += context.newString('\nAdd an other string with color/size format', style=dict(textFill=color(1, 0, 0), fontSize=20, leading=em(1.4))) print(bs) y -= 50 context.text(bs, (100, y)) context.saveImage(EXPORT_PATH)
def getContext(): global DEFAULT_CONTEXT, MAMP_PATH if DEFAULT_CONTEXT is None: try: #import ForceImportError # Uncomment for simulate testing of other contexts/platforms import AppKit # Force exception on non-OSX platforms from pagebot.contexts.drawbotcontext import DrawBotContext DEFAULT_CONTEXT = DrawBotContext( ) # Test if platform is supporing DrawBot: # MampView.build exports in MAMP folder that does not commit in Git. MAMP_PATH = '/Applications/MAMP/htdocs/' #except (ImportError, AttributeError, ModuleNotFoundError): # Python3 except (ImportError, AttributeError): #import ForceOtherError # Uncomment for simulate testing of other contexts/platforms from pagebot.contexts.flatcontext import FlatContext DEFAULT_CONTEXT = FlatContext() # MampView.build exports in MAMP folder that does not commit in Git. MAMP_PATH = '/tmp/MAMP_PATH/' # TODO: Where is it located for Linux? except: raise NotImplementedError('Cannot decide on the platform context.') return DEFAULT_CONTEXT
style = self.style.copy() instance = self.f.getInstance(style['location']) style['font'] = instance bs = c.newString(self.sampleText, style=style) tw, th = bs.size c.text(bs, (self.w / 2 - tw / 2, self.h / 2 - th / 8)) # /8 vert style['fontSize'] = style['location']['opsz'] * 4 style['font'] = instance bs = c.newString('%s %dpt' % (self.sampleText, style['fontSize']), style=style) tw, th = bs.size c.text(bs, (self.w / 2 - tw / 2, self.h / 4 - th / 8)) c = DrawBotContext() W, H = 1360, 1020 # Type Network banners # Claire: for now, add your Fit-Variable_1.ttf to your /Library/Fonts and it can be found. #Gimlet_Italics-VF.ttf #Gimlet_Romans-VF.ttf font = findFont('AlliumMediumVARGX_hyphen') print(font) # Fit axes to select from: here we are showing the optical size. # Define tag list for axes to be part of the animation as sequence sequenceAxes = ['opsz'] sequenceLength = 3 # Seconds per sequence sequences = len(sequenceAxes) # Amount of sequences, one per axis duration = sequenceLength * len( sequenceAxes) # Total duration of the animation in seconds framesPerSecond = 8
# # P A G E B O T # # Licensed under MIT conditions # # Supporting usage of DrawBot, www.drawbot.com # ----------------------------------------------------------------------------- # # testBabelStrings.py # # Test BabelString both under DrawBotContext and FlatContext from pagebot.contexts.drawbotcontext import DrawBotContext from pagebot.contexts.flatcontext import FlatContext testContexts = ( (DrawBotContext(), '_export/testFlatString.pdf'), # TODO: Get this to work with Flat #(FlatContext(), '_export/testDrawBotString.pdf'), ) for context, path in testContexts: # Create a new BabelString with the DrawBot FormttedString inside. style = dict(font='Verdana', fontSize=50, textFill=(1, 0, 0)) bs = context.newString('This is a string', style=style) # It prints it content. print bs # Adding or appending strings are added to the internal formatted string. bs += ' and more' print bs # Usage in DrawBot by addressing the embedded FS for drawing. context.text(bs, (100, 100)) context.saveImage(path)
view.showFrame = True view.showPadding = True view.showNameInfo = True # These values can be changed in the Variable window, # when in DrawBot context. view.showOrigin = ShowOrigins # Show origin alignment # markers on each element. view.showDimensions = ShowDimensions view.showElementInfo = ShowElementInfo # Show boxes with element info return doc # Answer the doc. if __name__ == '__main__': context = DrawBotContext() # May contain NoneDrawBotBuilder if not running on a DrawBot platform d = makeDocument(context) # Make interactive global controls. Only works in DrawBot context. Otherwise ignored. d.context.Variable([ dict(name='ShowMeasures', ui='CheckBox', args=dict(value=True)), dict(name='ShowDimensions', ui='CheckBox', args=dict(value=False)), dict(name='ShowElementInfo', ui='CheckBox', args=dict(value=False)), dict(name='PageSize', ui='Slider', args=dict(minValue=100, value=400, maxValue=800)), ], globals()) # Export in _export folder that does not commit in Git. Force to export PDF. EXPORT_PATH = '_export/AlignElements.png' d.export(EXPORT_PATH) # FIX: F L A T #context = FlatContext()
def getDrawBotContext(): from pagebot.contexts.drawbotcontext import DrawBotContext return DrawBotContext()
def makeDocument(): """Re-generate the original Type3-PeopleInType chapter as PDF output.""" context = DrawBotContext() # Create new document with (w,h) and fixed amount of pages. # Make number of pages with default document size. # Initially make all pages default with template # One page, just the cover. doc = Document(w=W, h=H, title='Type Magazine #3', autoPages=endPage - startPage + 1, baselineGrid=BASELINE, baselineStart=BASELINE_START, style=styles, templates=getTemplates(), startPage=startPage, originTop=False, context=context) # Get the current view of the document. This allows setting of # parameters how the document is represented on output. view = doc.view view.w, view.h = W, H # Set view options. Full list is in elements/views/baseviews.py view.padding = 40 # Showing cropmarks and registration marks # need >= 20 padding of the view. view.showRegistrationMarks = True view.showCropMarks = True view.showFrame = True view.showPadding = True view.showNameInfo = True view.showMetaInfo = False view.showTextOverflowMarker = True view.showOrigin = False # Show origin marker view.showElementOrigin = False # Don't show the origin of other elements. view.showGrid = [GRID_COL, GRID_ROW] view.showBaselines = True view.showSpreadPages = True view.showSpreadMiddleAsGap = False # PageBot article _, backgroundHeight = context.imageSize(BACKGROUND_PDF) backgroundIndex = 0 for pn in range(startPage, endPage + 1): page = doc[pn] setPageStyle(page, backgroundIndex) backgroundIndex += 1 if 1: page = doc[startPage + 2] print(page) t = Typesetter(context, styles=styles, imageAsElement=True) galley = t.typesetFile(CONTENT_PATH, e=page) composer = Composer(doc) targets = dict(composer=composer, doc=doc, page=page, style=doc.styles, box=page.select('people'), newTextBox=newTextBox) composer.compose(galley, targets=targets, page=page) date = now() if EXPORT_PDF: # Export as PDF exportPath = EXPORT_PATH_PDF % (date.year, date.month, date.day, date.hour, startPage, endPage) doc.export(exportPath) if EXPORT_PNG: # Export as PNG without cropmarks for mapping purpose doc.view.padding = 0 exportPath = EXPORT_PATH_PNG % (startPage, endPage) doc.export(exportPath)
# # Licensed under MIT conditions # # Supporting DrawBot, www.drawbot.com # Supporting Flat, xxyxyz.org/flat # ----------------------------------------------------------------------------- # # 74-91-Type3-PeopleInType.py # # Proof of concept to re-generate the existing InDesign layouts as PDF. # import os from random import random # Used for random color palet. from pagebot.contexts.drawbotcontext import DrawBotContext context = DrawBotContext() # Create random title and names from pagebot.contributions.filibuster.blurb import blurb from pagebot.toolbox.color import color, blackColor from pagebot.toolbox.dating import now # Get function to find the Roboto family (in this case installed in the # PageBot repository). from pagebot.fonttoolbox.objects.family import getFamily from pagebot.fonttoolbox.objects.font import findFont from pagebot.toolbox.color import noColor, blackColor # Creation of the RootStyle (dictionary) with all # available default style parameters filled. from pagebot.style import getRootStyle
# # testBabelStrings.py # # Test BabelString in both DrawBotContext and FlatContext from pagebot.contexts.drawbotcontext import DrawBotContext #from pagebot.contexts.flatcontext import FlatContext from pagebot.fonttoolbox.objects.font import findFont W, H = 800, 220 M = 100 font = findFont('Roboto-Regular') bold = findFont('Roboto-Bold') testContexts = ((DrawBotContext(), '_export/testDrawBotString.pdf'), #(FlatContext(), '_export/testFlatString.pdf'), ) for context, path in testContexts: context.newPage(W, H) # Create a new BabelString with the DrawBot FormttedString inside. style = dict(font=font.path, fontSize=40, textFill=(1, 0, 0)) bs = context.newString('This is a string', style=style) # It prints its content. print(bs) # Adding or appending strings are added to the internal formatted string. # Adding plain strings take over the existing style. bs += ' and more' print(bs) # Reusing the same style with adjustments