def onBlack(self, p): """Answers the boolean flag is the single point (x, y) is on black.""" # TODO: We need to make a method to have the context available here. from pagebot.contexts.platform 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.""" 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 __init__(self, font, name): from pagebot.contexts.platform import getContext self.context = getContext() self.name = name self.font = font # Stored as weakref self.dirty = True # Mark that we need initialization or something changed in the points. self._analyzer = None # Installed upon request self._points = None # Same as self.points property with added 4 spacing points in TTF style. self._points4 = None self._pointContexts = None self._contours = None self._segments = None self._components = None self._path = None # "Expensive", create self.path property value on initialize. self._flattenedPath = None # "More expensive", create property value upon request. self._flattenedContours = None # "More expensive", create property value upon request. self._analyzer = None # Initialized upon property self.analyzer usage. self._axisDeltas = None # Caching for AxisDeltas instances. self._boundingBox = None # Initialized on property call.
def draw(w): """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 = getContext() 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['condWidth'], PADDING), (PADDING + d['condWidth'], 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['condWidth']), d['condensedLocation']['wdth']), (PADDING + d['condWidth'] + 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))
# Supporting DrawBot, www.drawbot.com # Supporting Flat, xxyxyz.org/flat # ----------------------------------------------------------------------------- # # 100_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.contexts.platform 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) view = doc.view # Get the current view of this document. Defaulse it PageView. view.padding = inch(0.5) # Define padding of the view, so there is space for crop marks view.showBaselines = [BASE_LINE_BG, BASE_INDEX_LEFT] # Set to True to show baseline index #view.showBaselines = [BASE_LINE_BG, BASE_Y_LEFT] # Use this line to show vertical positions
# 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.contexts.platform import getContext from pagebot.toolbox.color import color, noColor, blackColor GLYPH_NAME = 'B' # 'ampersand' c = getContext() c.newPage(1000, 1000) c.scale(0.5) font = findFont('Roboto-Regular') print(font.analyzer) print(font.analyzer.name) glyph = font[GLYPH_NAME] 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. verticals = sorted(ga.verticals.keys()) print('x-position of detected verticals:', verticals)
def makeBanner(bd): u"""Demo random book cover generator.""" w, h = bd['w'], bd['h'] imagePaths = bd['imagePaths'] labelSize = bd['labelSize'] title1 = bd['title1'] title2 = bd['title2'] titleSize = bd['titleSize'] context = getContext() context.newDrawing() # 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 doc = Document(w=w, h=h, title=title1, autoPages=FRAMES, context=context, originTop=False) # One page, just the cover. A = (1, 1, 1, 0.5) B = (1, 0, 1, 0.8) C = (1, 1, 1, 0.8) COLORS = ( (B, B, B), (A, B, B), (B, A, B), (B, B, A), (A, B, B), (B, B, A), (B, A, B), ) for pn in range(1, FRAMES + 1): page = doc[pn] # Get the first/single page of the document. page.frameDuration = 1.5 imagePath, imageConditions = imagePaths[pn - 1] # Background image of the slide newImage(PATH + imagePath, conditions=imageConditions, parent=page) ww75 = w * 0.75 newRect(fill=(0.05, 0.05, 0.4, 0.8), w=ww75, conditions=(Fit2HeightSides(), Right2RightSide()), parent=page) ww25 = w * 0.25 #bs = context.newString('Type@Cooper\nTypographics', style=dict(font=fontRegular.path, fontSize=w/28, xTextAlign=CENTER, textFill=1, rLeading=1.05)) #tw, th = bs.textSize() #newTextBox(bs, parent=page, h=th+P/2, w=ww25, padding=(P/4,P/3,0,P/3), fill=(1,0,0,0.8), conditions=(Left2LeftSide(), Top2TopSide())) bs = context.newString('Typographics', style=dict(font=fontRegular.path, fontSize=w / 24, xTextAlign=CENTER, textFill=1, rLeading=1.05)) tw, th = bs.textSize() newTextBox(bs, parent=page, h=th + P / 2, w=ww25, padding=(P / 4, P / 3, 0, P / 3), fill=(1, 0, 0, 0.8), conditions=(Left2LeftSide(), Top2TopSide())) bs = context.newString(title1 + '\n', style=dict(font=fontMedium.path, textFill=C, fontSize=w / 11, rTracking=0.015, rLeading=1.4)) bs += context.newString(title2 + '\n', style=dict(font=fontBook.path, textFill=C, fontSize=w / 12, rLeading=1)) bs += context.newString('SKETCHING', style=dict(font=fontRegular.path, textFill=COLORS[pn - 1][0], fontSize=w / 15, rTracking=0.648, rLeading=1.5)) bs += context.newString('\nCODING', style=dict(font=fontRegular.path, textFill=COLORS[pn - 1][1], fontSize=w / 16, rTracking=0.185, rLeading=1.05)) bs += context.newString(' & ', style=dict(font=fontRegular.path, textFill=A, fontSize=w / 16, rTracking=0.185, rLeading=1.05)) bs += context.newString('MAKING\n', style=dict(font=fontRegular.path, textFill=COLORS[pn - 1][2], fontSize=w / 16, rTracking=0.185, rLeading=1.05)) bs += context.newString('Petr van Blokland April 11-13', style=dict(font=fontRegular.path, textFill=C, fontSize=w / 17.5, rTracking=0.032, rLeading=1.6)) newTextBox(bs, parent=page, x=ww25, y=0, padding=(0, 0, 0, w / 30), w=ww75 + w / 100, conditions=[Fit2HeightSides()]) score = page.evaluate() if score.fails: page.solve() # Evaluate again, result should now be >= 0 return doc
def makeBanner(bd): w, h = bd['w'], bd['h'] imagePaths = bd['imagePaths'] labelSize = bd['labelSize'] title1 = bd['title1'] title2 = bd['title2'] title3 = bd['title3'] sideImage = bd['sideImage'] titleSize = bd['titleSize'] L1 = bd['l1'] L2 = bd['l2'] padding = bd['padding'] type = bd['type'] context = getContext() context.newDrawing() # 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 doc = Document(w=w, h=h, title=title1, autoPages=FRAMES, context=context, originTop=False) # One page, just the cover. for pn in range(1, FRAMES + 1): page = doc[pn] # Get the first/single page of the document. page.frameDuration = 0.75 imagePath, imageConditions = imagePaths[0] # Background image of the slide im = newImage(PATH + imagePath, y=h / FRAMES * (pn - 1), conditions=imageConditions, parent=page) newImage(PATH + imagePath, y=h / FRAMES * (pn - 1) - 2 * im.h, conditions=imageConditions, parent=page) newImage(PATH + imagePath, y=h / FRAMES * (pn - 1) - im.h, conditions=imageConditions, parent=page) newImage(PATH + imagePath, y=h / FRAMES * (pn - 1) + im.h, conditions=imageConditions, parent=page) newImage(PATH + imagePath, y=h / FRAMES * (pn - 1) + 2 * im.h, conditions=imageConditions, parent=page) ww75 = w * 0.75 ww25 = w * 0.25 bs = context.newString('Type@Cooper\nTypographics', style=dict(font=fontRegular.path, fontSize=w / 30, xTextAlign=CENTER, textFill=1, rLeading=1.05, rTracking=0.02)) tw, th = bs.textSize() newRect(fill=(0.15, 0.17, 0.15, 0.7), w=ww75, conditions=(Fit2HeightSides(), Right2RightSide()), parent=page) newTextBox(bs, parent=page, h=th + P, w=ww25, padding=(P / 2, P, 0, P), fill=(1, 0, 0), conditions=(Left2LeftSide(), Top2TopSide())) # Show design measures m = padding * 2 m2 = m / 2 m4 = m / 4 designProcess = newGroup(x=0, y=0, fill=(0.3, 0.32, 0.3, 0.7), w=ww25, h=h - th - P, padding=padding, parent=page) design = newImage(PATH + sideImage, y=padding, h=h - th - P - 2 * padding, fill=None, conditions=[Center2Center()], parent=designProcess) designProcess.solve() if pn > 1: # Horizontal frame newLine(x=design.x - m4, y=design.y, w=design.w + m2, h=0, fill=None, stroke=1, strokeWidth=L1, parent=designProcess) newLine(x=design.x - m4, y=design.y + design.h, w=design.w + m2, h=0, fill=None, stroke=1, strokeWidth=L1, parent=designProcess) if pn > 2: # Vertical frame newLine(x=design.x, y=design.y - m4, w=0, h=design.h + m2, fill=None, stroke=1, strokeWidth=L1, parent=designProcess) newLine(x=design.x + design.w, y=design.y - m4, w=0, h=design.h + m2, fill=None, stroke=1, strokeWidth=L1, parent=designProcess) if pn == 4: # Diagonal newLine(x=design.x, y=design.y, w=design.w, h=design.h, fill=None, stroke=(1, 0, 0), strokeWidth=L2, parent=designProcess) newLine(x=design.x + design.w, y=design.y, w=-design.w, h=design.h, fill=None, stroke=(1, 0, 0), strokeWidth=L2, parent=designProcess) if pn > 5: # V-lines newLine(x=design.x + design.w / 2, y=design.y - m4, w=0, h=design.h + m2, stroke=1, strokeWidth=L1, parent=designProcess) if pn > 6: # V-lines newLine(x=design.x + design.w * 0.35, y=design.y - m4, w=0, h=design.h + m2, stroke=1, strokeWidth=L1, parent=designProcess) if pn > 7: # V-lines newLine(x=design.x + design.w * 0.92, y=design.y - m4, w=0, h=design.h + m2, stroke=1, strokeWidth=L1, parent=designProcess) if pn == 9: # H-lines 1/2 newLine(x=design.x - m2, y=design.y + design.h * 0.5, w=design.w + 2 * m2, h=0, stroke=1, strokeWidth=L1, parent=designProcess) if pn > 9: # H=lines newLine(x=design.x - m2, y=design.y + design.h * 0.53, w=design.w + 2 * m2, h=0, stroke=1, strokeWidth=L1, parent=designProcess) newLine(x=design.x - m2, y=design.y + design.h * 0.59, w=design.w + 2 * m2, h=0, stroke=1, strokeWidth=L1, parent=designProcess) if pn > 10: # H=lines newLine(x=design.x - m2, y=design.y + design.h * 0.24, w=design.w + 2 * m2, h=0, stroke=1, strokeWidth=L1, parent=designProcess) if pn > 11: # H=lines newLine(x=design.x - m2, y=design.y + design.h * 0.655, w=design.w + 2 * m2, h=0, stroke=1, strokeWidth=L1, parent=designProcess) if pn > 12: # Diagonal newLine(x=design.x, y=design.y, w=design.w, h=design.h * 0.53, fill=None, stroke=(1, 0, 0), strokeWidth=L2, parent=designProcess) newLine(x=design.x + design.w, y=design.y, w=-design.w, h=design.h * 0.53, fill=None, stroke=(1, 0, 0), strokeWidth=L2, parent=designProcess) if pn > 13: # Diagonal newLine(x=design.x, y=design.y + design.h * 0.59, w=design.w, h=design.h - design.h * 0.59, fill=None, stroke=(1, 0, 0), strokeWidth=L2, parent=designProcess) newLine(x=design.x + design.w, y=design.y + +design.h * 0.59, w=-design.w, h=design.h - design.h * 0.59, fill=None, stroke=(1, 0, 0), strokeWidth=L2, parent=designProcess) C0 = 1 C1 = C2 = (0, 1, 0.1, 0.95) if pn > 10: C2 = C0 if type == 'Small': bs = context.newString(title1 + '\n', style=dict(font=fontMedium.path, textFill=C0, fontSize=w / 20, rTracking=0.015, rLeading=1.25)) bs += context.newString(title2 + '\n', style=dict(font=fontBook.path, textFill=C1, fontSize=w / 20, rLeading=1.2, rTracking=0.03)) if title3 is not None: bs += context.newString(title3 + '\n', style=dict(font=fontRegular.path, textFill=1, fontSize=w / 30, rLeading=1.2, rTracking=0.03)) bs += context.newString( 'By DrawBot + PageBot + Petr van Blokland, June 17th', style=dict(font=fontRegular.path, textFill=C2, fontSize=w / 33, rTracking=0.030, rLeading=1.8)) newTextBox(bs, parent=page, x=ww25, y=0, padding=(w / 30, 0, 0, w / 30), w=ww75 + w / 100, conditions=[Fit2HeightSides()]) else: bs = context.newString(title1 + '\n', style=dict(font=fontMedium.path, textFill=C0, fontSize=w / 20, rTracking=0.015, rLeading=1.25)) bs += context.newString(title2 + '\n', style=dict(font=fontBook.path, textFill=C1, fontSize=w / 20, rLeading=1.2, rTracking=0.03)) if title3 is not None: bs += context.newString(title3 + '\n', style=dict(font=fontRegular.path, textFill=1, fontSize=w / 27, rLeading=1.2, rTracking=0.03)) bs += context.newString( 'By DrawBot + PageBot + Petr van Blokland, June 17th', style=dict(font=fontRegular.path, textFill=C2, fontSize=w / 33, rTracking=0.030, rLeading=1.8)) newTextBox(bs, parent=page, x=ww25, y=0, padding=(w / 30, 0, 0, w / 30), w=ww75 + w / 100, conditions=[Fit2HeightSides()]) score = page.evaluate() if score.fails: page.solve() # Evaluate again, result should now be >= 0 return doc
def _getContext(self): u"""Answer the best/default context for this type of view.""" return getContext( ) # Default is DrawBotContext or FlatContext instance.
# into the other. Use some view.showGrid options to show the grid. # Use view.showBaselines = True to show the baselines of the text. #from pagebot.contexts.flatcontext import FlatContext from pagebot.contexts.platform 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 GRID_COL_BG, GRID_ROW_BG, GRID_SQR_BG, LANGUAGE_EN #context = FlatContext() 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 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. """
def fitVariableWidth(varFont, s, w, fontSize, condensedLocation, wideLocation, fixedSize=False, tracking=None, rTracking=None): """Answer the font instance that makes string s width on the given width *w* for the given *fontSize*. The *condensedLocation* dictionary defines the most condensed font instance (optionally including the opsz) and the *wideLocation* dictionary defines the most wide font instance (optionally including the opsz). The string width for s is calculated with both locations and then the [wdth] value is interpolated and iterated until the location is found where the string *s* fits width *w). Note that interpolation may not be enough, as the width axis may contain non-linear masters. If the requested w outside of what is possible with two locations, then interations are performed to change the size. Again this cannot be done by simple interpolation, as the [opsz] also changes the width. It one of the axes does not exist in the font, then use the default setting of the font.""" c = getContext() condFont = getVarFontInstance(varFont, condensedLocation) condensedFs = c.newString(s, style=dict(font=condFont.path, fontSize=fontSize, tracking=tracking, rTracking=rTracking, textFill=0)) condWidth, _ = c.textSize(condensedFs) wideFont = getVarFontInstance(varFont, wideLocation) wideFs = c.newString(s, style=dict(font=wideFont.path, fontSize=fontSize, tracking=tracking, rTracking=rTracking, textFill=0)) wideWidth, _ = c.textSize(wideFs) # Check if the requested with is inside the boundaries of the font width # axis. if w < condWidth: font = condFont fs = condensedFs location = condensedLocation elif w > wideWidth: font = wideFont fs = wideFs location = wideLocation else: # Now interpolation the fitting location widthRange = wideLocation['wdth'] - condensedLocation['wdth'] location = copy.copy(condensedLocation) location['wdth'] += widthRange * (w - condWidth) / (wideWidth - condWidth) font = getVarFontInstance(varFont, location) fs = c.newString(s, style=dict(font=font.path, fontSize=fontSize, tracking=tracking, rTracking=rTracking, textFill=0)) return dict(condensendFont=condFont, condensedFs=condensedFs, condWidth=condWidth, condensedLocation=condensedLocation, wideFont=wideFont, wideFs=wideFs, wideWidth=wideWidth, wideLocation=wideLocation, font=font, fs=fs, width=c.textSize(fs)[0], location=location)
def __init__(self, doc=None, context=None, galley=None, globalDocName=None, globalPageName=None, globalBoxName=None, tryExcept=True, verbose=False, writeTags=True): u""" The Typesetter instance interprets an XML or Markdown file (.md) and converts it into a Galley instance, with formatted string depending on the current context. >>> from pagebot.contexts.platform import getContext >>> from pagebot import getResourcesPath >>> from pagebot.document import Document >>> from pagebot.elements.element import Element >>> path = getResourcesPath() + '/texts/TEST.md' >>> doc = Document(autoPages=1, context=getContext()) >>> t = Typesetter(doc=doc) # Create a new typesetter for this document >>> nodeTree = t.typesetFile(path) # Parse the Markdown file into HTML-->nodeTree >>> nodeTree.__class__.__name__ # This is an etree root, also called "Element", different class. 'Element' >>> e = Element() >>> t.typesetNode(nodeTree, e) """ # Set the doc context of the typesetter. doc be None, in which case it is expected that one of the code blocks # will define it in ~~~Python or it is set later by the calling application. self.doc = doc # Keep track of current page, as may have been defined in code blocks. self.page = None # The galley can be a Galley or a TextBox instance, if typsetting must go directly into a page element. # In that case image elements are added as child, loosing contact with their position in the text. # A Galley element keeps that relation, by adding multiple TextBox elements between the images. # If galley is None, then create an empty Galley instance, without parent. # Note that the single Galley will use the pagebot.contexts.Context as reference. # Also note that self.box and self.galley refer to the same object. self.box is used # in MarkDown files as reference where text should go. # Find the context, in case no doc has be defined yet. if context is None and doc is not None: context = doc.context if context is None: context = getContext() self.context = context if galley is None: galley = self.GALLEY_CLASS(context=context) self.galley = galley # Stack of graphic state as cascading styles. Last is template for the next. self.gState = [] self.tagHistory = [] # Code block results if any ~~~Python blocks defined in the Markdown file. self.globalDocName = globalDocName or 'doc' # Name of global doc to find in code blocks, to be stored in self.doc self.globalPageName = globalPageName or 'page' self.globalBoxName = globalBoxName = 'box' self.codeBlocks = { } # No results for now. Find codeblock result by codeId after typesetting. # Save some flags in case the typesetter is running in Python try-except mode. self.tryExcept = tryExcept self.verbose = verbose self.writeTags = writeTags
CLEAN = False try: import flat print('Flat found at %s' % flat.__path__[0]) except Exception as e: print(traceback.format_exc()) print('\nx Flat not found') CLEAN = False if not CLEAN: print('Not all dependencies are installed, please install missing ones.') else: # Testing PageBot. from pagebot.contexts.platform import getContext context = getContext() print(context) print(context.b) context = getContext(contextType='Flat') print(context) print(context.b) # Testing Sass. css = sass.compile(string='a { b { color: blue; } }') print(css) css = sass.compile(filename='sass/test.scss') print(css) test_scss = open('test.scss', 'w') import os, os.path if not os.path.exists('css'):
def testFlat(): context = getContext('Flat') f = findFont(FONTNAME) ff = font.open(f.path) c1 = rgb(180, 0, 125) c2 = rgb(100, 180, 0) style = dict(font=f, fontSize=FONTSIZE, color=c2, leading=LEADING) # Creates the document. d = document(WIDTH, HEIGHT, 'mm') #print(d.width) #print(d.height) p = d.addpage() #print(p.width) context.newDocument(WIDTH, HEIGHT) #print(context.doc.width) #print(context.doc.height) context.newPage() print(context.pages[0].width) print(context.pages[0].height) figure = shape().fill(c1).stroke(c2).width(2.5) r = figure.rectangle(50, 50, 20, 20) print(r) p.place(r) context.fill((180, 0, 125)) context.stroke((100, 180, 0)) context.strokeWidth(2.5) 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) headline = strike(ff).color(c2).size(FONTSIZE, LEADING) t = headline.text('Hello world!') entity = p.place(t) entity.frame(10, 10, 380, 80) bs = context.newString('Hello world!', style=style) #print(bs.__class__.__name__) context.text(bs, (10, 10)) ''' print(headline.style.size) print(headline.style.leading) print(headline.style.color.r) print(headline.style.color.g) print(headline.style.color.b) ''' 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') d.pdf('_export/native-flat.pdf') im.png('_export/native-flat.png') im.jpeg('_export/native-flat.jpg') p.svg('_export/native-flat.svg') print('Exporting pagebot') context.saveDocument('_export/pagebot-flat.pdf') context.saveDocument('_export/pagebot-flat.png') context.saveDocument('_export/pagebot-flat.jpg') context.saveDocument('_export/pagebot-flat.svg')
# # SimpleDocument.py # # This is a simple page document to show the working of layouts # using conditions. # from pagebot.style 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.contexts.platform 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(
# Copyright (c) 2016+ Buro Petr van Blokland + Claudia Mens # www.pagebot.io # # P A G E B O T # # Licensed under MIT conditions # # Supporting DrawBot, www.drawbot.com # Supporting Flat, xxyxyz.org/flat # ----------------------------------------------------------------------------- # # testDrawVariables.py # import sys from pagebot.contexts.platform import getContext context = getContext() if not context.isDrawBot: print('Example only runs on DrawBot.') sys.exit() # create small ui element for variables in the script if __name__ == '__main__': w = 100 h = 100 x = 0 y = 0 useColor = True c = [1, 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.showBaselines = True to show the default baselines of the text. from pagebot.contexts.platform 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')