def __init__(self, f, words=None, labelFontSize=None, **kwargs): """ >>> from pagebot.fonttoolbox.objects.font import findFont >>> from pagebot.document import Document >>> from pagebot.constants import Letter >>> from pagebot.contexts.drawbotcontext import DrawBotContext >>> from pagebot.conditions import * >>> from pagebot.toolbox.units import em >>> c = DrawBotContext() >>> w, h = Letter >>> doc = Document(w=w, h=h, padding=80, originTop=False, autoPages=2, context=c) >>> conditions = [Fit()] >>> page = doc[1] >>> font1 = findFont('AmstelvarAlpha-VF') >>> style = dict(gh=16, fill=0.95, leading=em(1.4)) >>> gs = Stacked(font1, parent=page, conditions=conditions, padding=40, style=style, context=c) >>> page = doc[2] >>> font2 = findFont('RobotoDelta-VF') >>> #font2 = findFont('Upgrade-Regular') >>> #font2 = findFont('Escrow-Bold') >>> style = dict(stroke=0, strokeWidth=0.25, gh=8, leading=em(1.4)) >>> gs = Stacked(font2, parent=page, conditions=conditions, style=style, padding=40, context=c) >>> score = doc.solve() >>> doc.export('_export/%sStacked.pdf' % font1.info.familyName) """ BaseFontShow.__init__(self, **kwargs) self.f = f # Font instance self.words = words or {} # Optional dictionary for headline words. Keys is frame index number. self.usedText = set() # Avoid double use of headline words. # Add semi-random generated content, styles of fitting. self.blurb = Blurb() # Random content creator, in case there is no content supplied. self.lineTag = 'design_headline' # Default label where to find random word choices. self.headlineTag = 'design_headline' # Default label where to find (or create) random headline text. self.textTag = 'da_text' # Default label where to find (or create) random body text.
def getAnkeiler(self, cnt=None): u"""Answer a blurb ankeiler. Make sure it does end with '.'""" ankeiler = Blurb().getBlurb('article_ankeiler', cnt=cnt) while ankeiler and ankeiler[-1] in ',:;-': ankeiler = ankeiler[:-1] if not ankeiler.endswith('.'): ankeiler += '.' return ankeiler
def test(context): print("creating doc") doc = Document(w=W, h=H, context=context) doc.name = 'TextBoxes-%s' % doc.context.name print('# Testing text boxes in %s' % doc) page = doc[1] #s = getString(page) blurb = Blurb() txt = blurb.getBlurb('stylewars_bluray') i = len(txt.split('. ')[0]) + 1 style = {'font': bungeeRegular, 'fontSize': 24, 'leading': 1.5} s = page.newString(txt[0:i], style=style) style = {'font': bungeeOutline, 'fontSize': 24, 'leading': 1.5} s += page.newString(txt[i:], style=style) w = W / 2 - 2 * M h = 460 #H - 2*M x = M y = H - M - h sc = color(0.3, 0.2, 0.1, 0.5) tb = newTextBox(s, x=x, y=y, w=w, h=h, parent=page, stroke=sc) y0 = H - M drawBaselines(x, y0, w, tb.baselines, s, page) # Get the rest of the text. txt = tb.getOverflow() style = {'font': pageBotBold, 'fontSize': 24, 'leading': 1.5} s = page.newString(txt, style=style) w = W / 2 - 2 * M 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()
def getBlurb(self, topic, cnt=None, addPeriod=True): """Answer a generated article text with the estimated cnt length.""" txt = Blurb().getBlurb(topic, cnt=cnt) while txt and txt[-1] in ',:;-': txt = txt[:-1] if addPeriod and not txt.endswith('.'): txt += '.' elif txt.endswith('.'): txt = txt[:-1] #txt = txt.capitalize() return txt
def DEPRECATED_typesetFilibuster(self, e, blurbNames=None): u"""The typesetFilibuster answers the parsed typeset nodes from a Filibuster blurb. If the blurb instances is not given, then create a default Filibuster article.""" if blurbNames is None: # Nothing supplied: at least create some standard content as article to parse. blurbNames = (('h3', 'article_ankeiler'), ('h1', 'article_summary'), ('p', 'article')) blurbArticle = [] from pagebot.contributions.filibuster.blurb import Blurb blurb = Blurb() for tag, blurbName in blurbNames: blurbArticle.append('<%s>%s</%s>\n' % (tag, blurb.getBlurb(blurbName), tag)) xml = u'<document>%s</document>' % '\n'.join(blurbArticle) root = ET.parseString(xml) # Get the root element of the parsed XML tree. self.typesetNode(root, e)
def getHeadline(self, s, style, cnt=None, w=None): u"""Answer a styled BabelString instance, with some checking on the content. Create a blurb headline if s is None. Make sure it does not end with '.,:;-'. If w is not None, then force the fontsize of the headline to fit the width.""" if s is None: s = Blurb().getBlurb('news_headline', cnt=cnt) while s and s[-1] in '.,:;-': s = s[:-1] formattedHeadline = self.view.newString(s, style=style, w=w) return formattedHeadline
def getExtendedBlurb(doc): blurb = Blurb() fs = newFS(blurb.getBlurb('news_headline', noTags=True) + '\n', style=doc.styles['h1']) for n in range(ARTICLE_CNT): fs += newFS(blurb.getBlurb('design_headline', noTags=True) + '\n', style=doc.styles['h2']) fs += newFS(blurb.getBlurb('design_headline', noTags=True) + '\n', style=doc.styles['h3']) fs += newFS(blurb.getBlurb('article', noTags=True) + '\n', style=doc.styles['p']) fs += newFS(blurb.getBlurb('design_headline', noTags=True) + '\n', style=doc.styles['h3']) fs += newFS(blurb.getBlurb('article', noTags=True) + '\n', style=doc.styles['p']) return fs
class Stacked(BaseFontShow): """Showing the specified (variable) font as full page with a matrix of all glyphs in the font. Usage of standard style parameters fill Fill color for the background of the element stroke Draw frame around the element textFill Color of the text. Default is black. padding Use in case of background color or frame. Default is 0 """ def __init__(self, f, words=None, labelFontSize=None, **kwargs): """ >>> from pagebot.fonttoolbox.objects.font import findFont >>> from pagebot.document import Document >>> from pagebot.constants import Letter >>> from pagebot.contexts.drawbotcontext import DrawBotContext >>> from pagebot.conditions import * >>> from pagebot.toolbox.units import em >>> c = DrawBotContext() >>> w, h = Letter >>> doc = Document(w=w, h=h, padding=80, originTop=False, autoPages=2, context=c) >>> conditions = [Fit()] >>> page = doc[1] >>> font1 = findFont('AmstelvarAlpha-VF') >>> style = dict(gh=16, fill=0.95, leading=em(1.4)) >>> gs = Stacked(font1, parent=page, conditions=conditions, padding=40, style=style, context=c) >>> page = doc[2] >>> font2 = findFont('RobotoDelta-VF') >>> #font2 = findFont('Upgrade-Regular') >>> #font2 = findFont('Escrow-Bold') >>> style = dict(stroke=0, strokeWidth=0.25, gh=8, leading=em(1.4)) >>> gs = Stacked(font2, parent=page, conditions=conditions, style=style, padding=40, context=c) >>> score = doc.solve() >>> doc.export('_export/%sStacked.pdf' % font1.info.familyName) """ BaseFontShow.__init__(self, **kwargs) self.f = f # Font instance self.words = words or {} # Optional dictionary for headline words. Keys is frame index number. self.usedText = set() # Avoid double use of headline words. # Add semi-random generated content, styles of fitting. self.blurb = Blurb() # Random content creator, in case there is no content supplied. self.lineTag = 'design_headline' # Default label where to find random word choices. self.headlineTag = 'design_headline' # Default label where to find (or create) random headline text. self.textTag = 'da_text' # Default label where to find (or create) random body text. def build(self, view, origin, drawElements=True): """Default drawing method just drawing the frame. Probably will be redefined by inheriting element classes.""" c = self.context p = pointOffset(self.origin, origin) p = self._applyScale(view, p) p = self._applyAlignment(p) # Ignore z-axis for now. self.buildFrame(view, p) # Draw optional background fill, frame or borders. # Let the view draw frame info for debugging, in case view.showFrame == True view.drawElementFrame(self, p) if self.drawBefore is not None: # Call if defined self.drawBefore(self, view, p) # Draw that actual content of the element by stacked specimen rectangles. self.drawStacked(view, p) if self.drawAfter is not None: # Call if defined self.drawAfter(self, view, p) self._restoreScale(view) view.drawElementInfo(self, origin) # Depends on flag 'view.showElementInfo' def getText(self, tag, cnt=None, charCnt=None): """If the tag type of text is in self.words, then take a random choice from there. Otherwise use the tag to create a blurb with the specified length.""" if tag in self.words: text = choice(self.words[tag]) if text in self.usedText: # Already used, try once more. text = choice(self.words[tag]) else: text = self.blurb.getBlurb(tag, cnt=cnt, charCnt=charCnt) self.usedText.add(text) return text def drawStacked(self, view, origin): """Draw the content of the element, responding to size, styles, font and content.""" c = self.context # Start on top left, with respect to optional padding value. x = self.pl y = self.h-self.pt # Top headline. (x,y) is top-left of the box, passed on for the position of the next box. s = self.getText(self.lineTag, charCnt=10).upper() x, y = self.buildStackedLine(s, origin, x, y, self.pw, wght=0.7, wdth=-0.4) # Second headline s = self.getText(self.lineTag, 4, 18) x, y = self.buildStackedLine(s, origin, x, y, self.pw, wght=-0.7) # Some large headline thing s = self.getText(self.lineTag, 5, 24) x, y = self.buildStackedLine(s, origin, x, y, self.pw, wght=0.3, wdth=-0.4) # Body text 16/24 s = self.getText(self.textTag, 20) x, y = self.buildTextBox(None, s, origin, x, y, self.pw, None, 16, JUSTIFIED) # Body text 12/18 s = self.getText(self.textTag, 30) x, y = self.buildTextBox(None, s, origin, x, y, self.pw, None, 12, JUSTIFIED) # Body text 10/15 s1 = self.getText(self.headlineTag) s2 = self.getText(self.textTag, cnt=20) x, y = self.buildTextBox(s1, s2, origin, x, y, self.pw, None, 10, JUSTIFIED, Bwght=0.7, Bwdth=-0.1) # Body text 9/13.5 # Don't update to the new y, next colomn needs to be on the right, starting at the same y. s1 = self.getText(self.headlineTag) s2 = self.getText(self.textTag) + ' ' + self.getText(self.textTag) x, _ = self.buildTextBox(s1, s2, origin, x, y, (self.pw-self.gw)/2, y-self.pb, 9, LEFT, labelSize=7, Bwght=0.6, Bwdth=-0.1) # Body text 8/12 s1 = self.getText(self.headlineTag) s2 = self.getText(self.textTag) + ' ' + self.getText(self.textTag) x, y = self.buildTextBox(s1, s2, origin, x+(self.pw+self.gw)/2, y, (self.pw-self.gw)/2, y-self.pb, 8, LEFT, labelSize=7, Bwght=0.6, Bwdth=-0.1)
# Take text of 3-4 paragraphs (headline, body text, caption) # Make 2 rect elements, with a color # Organize those 3-4 elements on a responsive page. from pagebot.document import Document from pagebot.elements import * from pagebot.conditions import * from pagebot.style import A5, TOP from pagebot.contributions.filibuster.blurb import Blurb blurb = Blurb() #print blurb.getBlurb('design_headline') #print blurb.getBlurb('news_headline') #print blurb.getBlurb('article') W, H = int(A5[0]), int(A5[1]) print W, H doc = Document(w=W, h=H, originTop=False, autoPages=1) view = doc.getView() view.showPagePadding = True view.showElementOrigin = True view.showFlowConnections = True page = doc[0] page.padding = int(page.h / 12), int(page.w / 12) newRect(parent=page, z=10, fill=(1, 0, 0),
mr=G, h=RH, w=CW1, conditions=(Right2Right(), Float2Top(), Float2Left())) newTextBox(parent=self, name='TopHeadDate', h=RH, w=CW1, conditions=(Right2Right(), Top2Top(), Float2Left())) # ============================================================================= # Random text generator # ............................................................................. blurb = Blurb() # ============================================================================= # Building switches # ............................................................................. SHOW_TOPHEAD = True # Headline on top of title SHOW_TITLE = True # Main title of the newspaper SHOW_ARTICLE1 = True SHOW_BACKGROUND = True # ============================================================================= # Measures # ............................................................................. #W, H = Broadsheet # Split paper size in document width and height W, H = pt(819, 1176) # Dutch Volksrant tabloid size.
def makeDocument(): u"""Create Document instance with a single page. Fill the page with elements and perform a conditional layout run, until all conditions are solved.""" foundryName, bookName = findFont((None, 'Book', 'Regular')) # Find these styles in order. _, mediumName = findFont(('Medium', 'Book', 'Regular')) mediumName = mediumName or bookName # In case medium weight does not exist. _, boldName = findFont(('Bold', 'Medium')) bookItalicName = italicName(bookName) mediumItalicName = italicName(mediumName) boldItalicName = italicName(boldName) # Get the fonts, so we can dig in the information. bookFont = getFontByName(bookName, install=False) mediumFont = getFontByName(mediumName, install=False) boldFont = getFontByName(boldName, install=False) bookItalicFont = getFontByName(bookItalicName, install=False) mediumItalicFont = getFontByName(mediumItalicName, install=False) boldItalicFont = getFontByName(boldItalicName, install=False) # Some parameters from the original book paperColor = int2Color(0xF4EbC9) # Approximation of paper color of original specimen. redColor = int2Color(0xAC1E2B) # Red color used in the original specimen RedBoxY = 118*MM # Vertical position of the Red Box, on Bodoni chapter. columnX = 80*MM # Original 80MM, by we don't adjust, so optically a bit more. columnW = 60*MM leftPadding = rightPadding = 52*MM # Exception page padding for columns blurb = Blurb() # BLurb generator doc = Document(w=PageWidth, h=PageHeight, originTop=False, startPage=1, autoPages=10) # Get default view from the document and set the viewing parameters. view = doc.view c = view.context view.style['fill'] = 1 # TODO: There is a bug that makes view page size grow, if there are multiple pages and padding > 0 # TODO: Add optional showing of mid-page line gradient, to suggest bended book pages. view.padding = 0 # 20*MM # To show cropmarks and such, make >=20*MM or INCH. view.showPageCropMarks = False # Won't show if there is not padding in the view. view.showPageRegistrationMarks = False view.showPageFrame = True view.showPageNameInfo = False view.showElementOrigin = False view.showElementDimensions = False #ShowDimensions view.showElementInfo = False view.showTextOverflowMarker = False # Don't show marker in case Filibuster blurb is too long. labelFont = boldFont padding = (3*MM, 3*MM, 3*MM, 3*MM) fontNameSize = 16 aboutSize = 10 glyphSetSize = 11 glyphSetLeading = 5*MM captionSize = 7 pageNumberSize = 12 glyphTracking = 0.2 # Tracking of glyphset samples rt = 0.02 # Relative tracking capHeight = labelFont.info.capHeight / labelFont.info.unitsPerEm * fontNameSize border = dict(line=INLINE, dash=None, stroke=redColor, strokeWidth=1) # ----------------------------------------------------------------------------------- # Cover from image scan. pn = 1 page = doc[pn] # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style. page.margin = 0 page.padding = pagePadding # Add image of cover scan. # TODO: Make other positions and scaling work on image element. newImage(path=COVER_IMAGE_PATH, parent=page, conditions=[Fit2Sides()]) page.solve() # ----------------------------------------------------------------------------------- # Empty left page. pn += 1 page = doc[pn] # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style. page.margin = 0 page.padding = pagePadding # Fill with paper color # TODO: Just background color could be part of page fill instead of extra element. newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor) # ----------------------------------------------------------------------------------- # Full red page with white chapter title. pn += 1 page = doc[pn] # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style. page.margin = 0 page.padding = pagePadding # Fill full page with red color # TODO: Just background color could be part of page fill instead of extra element. newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=redColor) fs = c.newString('BOEKLETTER', style=dict(font=boldName, xTextAlign=RIGHT, textFill=paperColor, fontSize=24, rTracking=0.1))#, xTextAlign=RIGHT)) newTextBox(fs, parent=page, y=page.h-176*MM, conditions=[Left2Left(), Fit2Right(), Fit2Bottom()]) page.solve() # ----------------------------------------------------------------------------------- # Empty left page. pn += 1 page = doc[pn] # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style. page.margin = 0 page.padding = pagePadding # Fill with paper color # TODO: Just background color could be part of page fill instead of extra element. newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor) # ----------------------------------------------------------------------------------- # Title page of family. pn += 1 page = doc[pn] # Get the single front page from the document. # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style. page.margin = 0 page.padding = pagePadding # Fill with paper color # TODO: Just background color could be part of page fill instead of extra element. newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor) fs = c.newString(labelFont.info.familyName.upper(), style=dict(font=boldName, textFill=paperColor, fontSize=fontNameSize, tracking=0, rTracking=0.3)) tw, th = fs.textSize() # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured. tbName = newTextBox(fs, parent=page, h=capHeight+3*padding[0], w=tw+2*padding[1], conditions=[Right2RightSide()], fill=redColor, padding=padding) tbName.top = page.h-RedBoxY tbName.solve() # Make it go to right side of page. fs = c.newString(foundryName.upper(), style=dict(font=boldName, textFill=0, fontSize=fontNameSize, tracking=0, rTracking=0.3)) tw, th = fs.textSize() # TODO: Something wrong with left padding or right padding. Should be symmetric. tbFoundry = newTextBox(fs, parent=page, h=capHeight+3*padding[0], w=tw+2*padding[1], fill=None, padding=padding, borders=border) tbFoundry.top = page.h-RedBoxY tbFoundry.right = tbName.left # Make blurb text about design and typography. aboutText = blurb.getBlurb('article_summary', noTags=True) fs = c.newString(aboutText, style=dict(font=bookName, textFill=0, fontSize=aboutSize, tracking=0, rTracking=rt, rLeading=1.3, hyphenation='en')) # TODO: Something wrong with left padding or right padding. Should be symmetric. tbAbout = newTextBox(fs, parent=page, x=columnX, w=columnW, conditions=[Fit2Bottom()]) tbAbout.top = tbFoundry.bottom - 8*MM # ----------------------------------------------------------------------------------- # Page 2 of a family chapter. Glyph overview and 3 columns. pn += 1 page = doc[pn] # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style. page.margin = 0 page.padding = pagePadding # Fill with paper color # TODO: Just background color could be part of page fill instead of extra element. newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor) # Glyph set caps = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ\n' lc = caps.lower() figures = u'1234567890\n' capAccents = u'ÁÀÄÂÉÈËÊÇÍÌÏÎÓÒÖÔØÚÙÜÛÑ\n' lcAccents = capAccents.lower() punctuations = u',.;:?![]()-–—“”‘’' fs = c.newString(caps, style=dict(font=bookName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) fs += c.newString(lc, style=dict(font=bookName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) if bookName != bookItalicName: fs += C.newString(caps, style=dict(font=bookItalicName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) fs += C.newString(lc, style=dict(font=bookItalicName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) fs += c.newString(figures, style=dict(font=bookName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) if bookName != bookItalicName: fs += C.newString(figures, style=dict(font=bookItalicName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) fs += c.newString(capAccents, style=dict(font=bookName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) fs += c.newString(lcAccents, style=dict(font=bookName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) if bookName != bookItalicName: fs += C.newString(capAccents, style=dict(font=bookItalicName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) fs += C.newString(lcAccents, style=dict(font=bookItalicName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) fs += c.newString(punctuations, style=dict(font=bookName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) if bookName != bookItalicName: fs += c.newString(punctuations + '\n', style=dict(font=bookItalicName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) else: fs += '\n' if bookName != boldName: fs += c.newString(caps+lc+figures+capAccents+lcAccents+punctuations, style=dict(font=boldName, textFill=0, fontSize=glyphSetSize, leading=glyphSetLeading, tracking=0, rTracking=glyphTracking)) tbGlyphSet = newTextBox(fs, parent=page, w=112*MM, x=leftPadding, conditions=[Top2Top()]) fs = c.newString(labelFont.info.familyName.upper(), style=dict(font=boldName, textFill=paperColor, fontSize=fontNameSize, tracking=0, rTracking=0.3)) tw, th = fs.textSize() # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured. tbName = newTextBox(fs, parent=page, h=capHeight+3*padding[0], w=tw+2*padding[1], conditions=[Left2LeftSide()], fill=redColor, padding=padding) tbName.top = page.h-RedBoxY tbName.solve() # Make it go to right side of page. fs = c.newString(foundryName.upper(), style=dict(font=boldName, textFill=0, fontSize=fontNameSize, tracking=0, rTracking=0.3)) tw, th = fs.textSize() # TODO: Something wrong with left padding or right padding. Should be symmetric. tbFoundry = newTextBox(fs, parent=page, h=capHeight+3*padding[0], w=tw+2*padding[1], fill=None, padding=padding, borders=border) tbFoundry.top = page.h-RedBoxY tbFoundry.left = tbName.right # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=6.5, tracking=0, rTracking=rt, leading=6.5, hyphenation='en')) # TODO: Last line of text blocks in original is bold. # TODO: Something wrong with left padding or right padding. Should be symmetric. tbSpec6 = newTextBox(fs, parent=page, x=leftPadding, w=50*MM, h=30*MM) tbSpec6.top = tbFoundry.bottom - 8*MM fs = c.newString('6 1/2 set\nop 6 pt gegoten (links)', style=dict(font=bookName, fontSize=captionSize, textFill=redColor, xTextAlign=RIGHT, rTracking=0.05, leading=8, openTypeFeatures=dict(frac=True))) # TODO: Something wrong with left padding or right padding. Should be symmetric. tbCaption6 = newTextBox(fs, parent=page, x=page.pl, w=leftPadding - page.pl - 3*MM, h=30*MM) tbCaption6.top = tbSpec6.top # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=6.5, tracking=0, rTracking=rt, leading=7, hyphenation='en')) # TODO: Something wrong with left padding or right padding. Should be symmetric. tbSpec7 = newTextBox(fs, parent=page, x=leftPadding, w=50*MM, h=35*MM) tbSpec7.top = tbSpec6.bottom - 5*MM fs = c.newString('op 7 pt gegoten (links)', style=dict(font=bookName, fontSize=captionSize, textFill=redColor, xTextAlign=RIGHT, rTracking=0.05, leading=8)) # TODO: Something wrong with left padding or right padding. Should be symmetric. tbCaption7 = newTextBox(fs, parent=page, x=page.pl, w=leftPadding - page.pl - 3*MM, h=30*MM) tbCaption7.top = tbSpec7.top # TODO: Align with first baseline, instead of box top. # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=6.5, tracking=0, rTracking=rt, leading=8, hyphenation='en')) # TODO: Something wrong with left padding or right padding. Should be symmetric. tbSpec8 = newTextBox(fs, parent=page, h=tbSpec6.top - tbSpec7.bottom) tbSpec8.top = tbSpec6.top tbSpec8.left = tbSpec6.right + 5*MM tbSpec8.w = page.w - page.pr - tbSpec8.left fs = c.newString('op 8 pt gegoten (rechts)', style=dict(font=bookName, fontSize=captionSize, textFill=redColor, xTextAlign=RIGHT, rTracking=0.05, leading=8)) # TODO: Something wrong with left padding or right padding. Should be symmetric. tbCaption8 = newTextBox(fs, parent=page, x=page.pl, w=leftPadding - page.pl - 3*MM) tbCaption8.bottom = tbSpec8.bottom # TODO: Align with the position of the lowest base line. # TODO: Calculate the right amount fs = c.newString('Corps 6 – per 100 aug.: romein 417, cursief 444, vet 426 letters', style=dict(font=bookName, fontSize=captionSize, textFill=redColor, xTextAlign=RIGHT, rTracking=rt, leading=8)) # TODO: Something wrong with left padding or right padding. Should be symmetric. tbCaptionTotal = newTextBox(fs, parent=page, x=page.pl, w=page.w - page.pl - page.pr) tbCaptionTotal.top = tbSpec8.bottom - MM # Page number fs = c.newString(`pn`, style=dict(font=bookName, fontSize=pageNumberSize, textFill=redColor, xTextAlign=LEFT, rTracking=rt, leading=8)) # TODO: Something wrong with left padding or right padding. Should be symmetric. tbPageNumber = newTextBox(fs, parent=page, x=leftPadding, w=10*MM) tbPageNumber.bottom = 20*MM # ----------------------------------------------------------------------------------- # Page 3, 3 columns. pn += 1 page = doc[pn] # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style. page.margin = 0 page.padding = pagePadding # Fill with paper color # TODO: Just background color could be part of page fill instead of extra element. newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor) # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=8.5, tracking=0, rTracking=rt, leading=8, hyphenation='en')) # TODO: Something wrong with left padding or right padding. Should be symmetric. tbText1 = newTextBox(fs, parent=page, h=110*MM, w=50*MM, conditions=[Top2Top(), Left2Left()]) page.solve() # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=8.5, tracking=0, rTracking=rt, leading=9, hyphenation='en')) # TODO: Something wrong with left padding or right padding. Should be symmetric. x = tbText1.right + 5*MM tbText2 = newTextBox(fs, parent=page, x=x, y=tbText1.y, h=tbText1.h, w=page.w - x - rightPadding) page.solve() # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=8.5, tracking=0, rTracking=rt, leading=10, hyphenation='en')) x = tbText1.left tbText3 = newTextBox(fs, parent=page, x=x, h=64*MM, w=page.w - x - rightPadding, mt=10*MM, conditions=[Float2TopLeft()]) # TODO: Add red captions here. # Red label on the left fs = c.newString(labelFont.info.styleName.upper(), style=dict(font=boldName, textFill=paperColor, fontSize=fontNameSize, tracking=0, rTracking=0.3)) tw, th = fs.textSize() # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured. tbName = newTextBox(fs, parent=page, h=capHeight+3*padding[0], w=tw+2*padding[1], conditions=[Right2RightSide()], fill=redColor, padding=padding) tbName.top = page.h-RedBoxY # Page number fs = c.newString(`pn`, style=dict(font=bookName, fontSize=pageNumberSize, textFill=redColor, xTextAlign=RIGHT, rTracking=rt, leading=8)) tbPageNumber = newTextBox(fs, parent=page, x=page.w - rightPadding - 10*MM, w=10*MM) tbPageNumber.bottom = 20*MM # ----------------------------------------------------------------------------------- # Page 4, 3 columns. pn += 1 page = doc[pn] # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style. page.margin = 0 page.padding = pagePadding # Fill with paper color # TODO: Just background color could be part of page fill instead of extra element. newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor) x = leftPadding # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=10.5, tracking=0, rTracking=rt, leading=10, hyphenation='en')) # TODO: Something wrong with left padding or right padding. Should be symmetric. tbText1 = newTextBox(fs, parent=page, x=x, h=55*MM, w=page.w - x - page.pl, conditions=[Top2Top()]) page.solve() # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=10.5, tracking=0, rTracking=rt, leading=11, hyphenation='en')) # TODO: Something wrong with left padding or right padding. Should be symmetric. newTextBox(fs, parent=page, mt=5*MM, x=x, h=60*MM, w=page.w - x - page.pl, conditions=[Float2Top()]) page.solve() # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=10.5, tracking=0, rTracking=rt, leading=12, hyphenation='en')) # TODO: Something wrong with left padding or right padding. Should be symmetric. newTextBox(fs, parent=page, mt=5*MM, x=x, h=65*MM, w=page.w - x - page.pl, conditions=[Float2Top()]) page.solve() # TODO: Add red captions here. # Red label on the right fs = c.newString('10.5pt', style=dict(font=boldName, textFill=paperColor, fontSize=fontNameSize, tracking=0, rTracking=0.3)) tw, th = fs.textSize() # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured. tbName = newTextBox(fs, parent=page, h=capHeight+3*padding[0], w=tw+2*padding[1], conditions=[Left2LeftSide()], fill=redColor, padding=padding) tbName.top = page.h-RedBoxY # Page number, even on left side. fs = c.newString(`pn`, style=dict(font=bookName, fontSize=pageNumberSize, textFill=redColor, xTextAlign=LEFT, rTracking=rt, leading=8)) tbPageNumber = newTextBox(fs, parent=page, x=leftPadding, w=10*MM) tbPageNumber.bottom = 20*MM # ----------------------------------------------------------------------------------- # Page 5, 2 columns. pn += 1 page = doc[pn] # Hard coded padding, just for simple demo, instead of filling padding an columns in the root style. page.margin = 0 page.padding = pagePadding # Fill with paper color # TODO: Just background color could be part of page fill instead of extra element. newRect(z=-1, parent=page, conditions=[Fit2Sides()], fill=paperColor) # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=12.5, tracking=0, rTracking=rt, leading=12, hyphenation='en')) newTextBox(fs, parent=page, x=x, h=64*MM, w=page.w - page.pl - rightPadding, mt=10*MM, conditions=[Top2Top(), Left2Left()]) # Make blurb text about design and typography. specText = blurb.getBlurb('article', noTags=True) + ' ' + blurb.getBlurb('article', noTags=True) fs = c.newString(specText, style=dict(font=bookName, textFill=0, fontSize=12.5, tracking=0, rTracking=rt, leading=13, hyphenation='en')) newTextBox(fs, parent=page, x=x, h=64*MM, w=page.w - page.pl - rightPadding, mt=10*MM, conditions=[Float2TopLeft()]) # TODO: Add red captions here. # Red label on the left fs = c.newString(labelFont.info.styleName.upper(), style=dict(font=boldName, textFill=paperColor, fontSize=fontNameSize, tracking=0, rTracking=0.3)) tw, th = fs.textSize() # TODO: h is still bit of a guess with padding and baseline position. Needs to be solved more structured. tbName = newTextBox(fs, parent=page, h=capHeight+3*padding[0], w=tw+2*padding[1], conditions=[Right2RightSide()], fill=redColor, padding=padding) tbName.top = page.h-RedBoxY # Page number fs = c.newString(`pn`, style=dict(font=bookName, fontSize=pageNumberSize, textFill=redColor, xTextAlign=RIGHT, rTracking=rt, leading=8)) tbPageNumber = newTextBox(fs, parent=page, x=page.w - rightPadding - 10*MM, w=10*MM) tbPageNumber.bottom = 20*MM # Solve remaining layout and size conditions. score = doc.solve() if score.fails: print 'Condition fails', score.fails return doc # Answer the doc for further doing.
from pagebot.constants import A5 from pagebot.toolbox.units import pt from pagebot.contributions.filibuster.blurb import Blurb from flat import * # rgb, font, shape, strike, document import random w, h = pt(A5) w = int(w) h = int(h) red = rgb(255, 0, 0) black = rgb(0, 0, 0) bungee = findFont('Bungee-Regular') bungeeFlat = font.open(bungee.path) blurb = Blurb() types = blurb.getBlurbTypes() txts = [] for i in range(5): i = random.randint(0, len(types)) t = types[i] print(t) txts.append(blurb.getBlurb(t, noTags=True)) txt = '. '.join(txts) #print(txt) headline = strike(bungeeFlat).color(red).size(20, 24) body = strike(bungeeFlat).color(black).size(10, 12)
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- if __name__ == '__main__': from pagebot.contributions.filibuster.blurb import Blurb # Show the list of all possible entries. SHOW_ALL_TYPES = False # see if we can generate all of them blurb = Blurb() # General aricle new headline print(blurb.getBlurb('name_german_male')) print(blurb.getBlurb('name_japanese')) # General book title and author name print(blurb.getBlurb('book_title')) # Scientific book title print(blurb.getBlurb('book_pseudoscientific')) # Philosphy book title print(blurb.getBlurb('book_phylosophy_title')) # Neutral airport new headline print(blurb.getBlurb('air_news_neutral')) # General aricle new headline print(blurb.getBlurb('_headline'))
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- import codecs import os from pagebot.contributions.filibuster.blurb import Blurb from pagebot.contributions.filibuster.content import index # see if we can generate all of them w = Blurb() names = w.getBlurbTypes() dst = os.path.join(os.getcwd(), "_export") # Make output not write to Git. if not os.path.exists(dst): os.makedirs(dst) maxTests = 20 count = 0 for name in names: count += 1 namePath = os.path.join(dst, "%s.txt" % name) nameTagPath = os.path.join(dst, "___%s_trying.txt" % name) t = codecs.open(nameTagPath, 'w', 'utf-8') t.write("a") success = False f = codecs.open(namePath, 'w', 'utf-8') f.write("Results for \"%s\"" % name) definedIn, usedIn = index(name) usedMods = {}
def initialize(self, padding=None, gutter=None, columns=None, **kwargs): u"""Initialize the generic book templates. """ blurb = Blurb() # TODO: Solve for left/right templates. if padding is None: padding = self.PADDING if gutter is None: gutter = self.GUTTER if columns is None: columns = self.COLUMNS fillColor1 = (0.2, 0.2, 0.9, 0.6) # Temp fill of markers. fillColor2 = (0.9, 0.2, 0.9, 0.6) # Temp fill of markers. fillColor3 = (0.9, 0.2, 0.3, 0.6) # Temp fill of markers. fillColor4 = (0.9, 0.9, 0.3, 0.6) # Temp fill of markers. fillColor1 = fillColor2 = fillColor3 = fillColor4 = None w, h = self.w, self.h cw = (w - 2 * padding - gutter * (columns - 1)) / columns cwg = cw + gutter lineW = 4 # Max amount of words return by the blurb generator. maxHeadline = 6 maxHeadlineShort = 4 maxAnkeiler = 30 fontPaths = getFontPaths() #for fontName, path in getFontPaths().items(): # if 'Escrow' in fontName: # print(fontName, path) #newspaperTitleFont = fontPaths['Escrow-Black'] #newspaperTitleFont = 'Proforma Book' newspaperTitleFont = 'Upgrade Semibold' h1Font = 'Upgrade Medium' bodyFont = 'Upgrade Book' titleStyle = dict(font=newspaperTitleFont, fontSize=140, w=(columns - 2) * cw, textFill=0) h1Style = dict(font=h1Font, fontSize=90, leading=90, textFill=0) h2Style = dict(font=h1Font, fontSize=60, leading=60, textFill=0) bodyStyle = dict(font=bodyFont, fontSize=14, hyphenation=True, leading=18, textFill=0, firstParagraphIndent=2 * gutter, firstLineIndent=gutter) h1IntroStyle = dict(font=bodyFont, fontSize=45, hyphenation=True, leading=52, textFill=0) h2IntroStyle = dict(font=bodyFont, fontSize=30, hyphenation=True, leading=36, textFill=0) titleLine = dict(strokeWidth=1, stroke=0) # grid-template-columns, grid-template-rows, grid-auto-rows, grid-column-gap, grid-row-gap, gridX = [] for n in range(columns): gridX.append([cw, gutter]) gridX[-1][-1] = 0 gridY = [(None, 0)] # Default is full height of columns # Template 'Front' t = Template(w=w, h=h, name='Front', padding=padding, gridX=gridX, gridY=gridY) # Newspaper name with border lines on top and bottom #self.title = 'NORTHAMPTON GLOBE' bs = self.view.newString(self.title.upper(), style=titleStyle) _, nameHeight = bs.size() title = Title(parent=t, mb=2 * gutter, h=nameHeight, conditions=[Top2Top(), Fit2Width()]) tb = newTextBox(bs, parent=title, h=nameHeight, xTextAlign=CENTER, pt=gutter, borderTop=titleLine, borderBottom=titleLine, conditions=[Fit2Width()]) # Place article 3 columns cc = 3 # Column width of this article. article = Article(parent=t, h=h / 3, w=cc * cwg - gutter, mr=gutter, mb=gutter, fill=fillColor1, conditions=[Left2Left(), Float2Top()]) s = None #'Happy birthday, Jill' headLine = self.getHeadline(s, h2Style, cnt=maxHeadline, w=cc * cwg - gutter) newTextBox(headLine, parent=article, w=cc * cwg - gutter, fill=fillColor2, conditions=[Left2Left(), Float2Top()]) intro = self.getAnkeiler(cnt=maxAnkeiler) bs = self.view.newString(intro, style=h2IntroStyle) newTextBox(bs, parent=article, w=cc * cwg - gutter, mt=gutter, mb=gutter, fill=fillColor3, conditions=[Left2Left(), Float2Top()]) for n in range(cc): dummyArticle = blurb.getBlurb('article', newLines=True) bs = self.view.newString(dummyArticle, style=bodyStyle) newTextBox(bs, parent=article, w=cw, mr=gutter, h=10, fill=fillColor4, conditions=[ Right2Right(), Float2Top(), Float2Left(), Fit2Bottom() ]) cc = 3 # Column width of this article. article = Article(parent=t, h=h / 4, w=cc * cwg - gutter, mr=gutter, mb=gutter, pt=gutter, borderTop=titleLine, conditions=[Left2Left(), Float2Top()]) s = None #'Explore Northampton in spring' headLine = self.getHeadline(s, h2Style, cnt=maxHeadline, w=cc * cwg - 2 * gutter) newTextBox(headLine, parent=article, pr=gutter, w=cc * cwg, conditions=[Left2Left(), Float2Top()]) intro = blurb.getBlurb('article_ankeiler', cnt=maxAnkeiler) bs = self.view.newString(intro, style=h2IntroStyle) newTextBox(bs, parent=article, pr=gutter, w=cc * cwg, mt=gutter, mb=gutter, conditions=[Left2Left(), Float2Top()]) for n in range(cc): dummyArticle = blurb.getBlurb('article', newLines=True) bs = self.view.newString(dummyArticle, style=bodyStyle) newTextBox(bs, parent=article, w=cw, mr=gutter, conditions=[ Left2RightSide(), Float2Top(), Float2Left(), Fit2Bottom() ]) cc = 3 # Column width of this article. article = Article(parent=t, h=h / 4, w=cc * cwg - gutter, mr=gutter, mb=gutter, pt=gutter, borderTop=titleLine, borderBottom=titleLine, conditions=[Left2Left(), Float2Top(), Fit2Bottom()]) s = None #'Mothersday for Sara & Jill' headLine = self.getHeadline(s, h2Style, cnt=maxHeadline, w=cc * cwg - 2 * gutter) newTextBox(headLine, parent=article, pr=gutter, w=cc * cwg, conditions=[Left2Left(), Float2Top()]) intro = self.getAnkeiler(cnt=maxAnkeiler) bs = self.view.newString(intro, style=h2IntroStyle) newTextBox(bs, parent=article, w=cc * cwg, mt=gutter, mb=gutter, conditions=[Left2Left(), Float2Top()]) for n in range(cc): dummyArticle = blurb.getBlurb('article', newLines=True) bs = self.view.newString(dummyArticle, style=bodyStyle) newTextBox(bs, parent=article, pr=gutter, w=cw, mr=gutter, conditions=[ Left2RightSide(), Float2Top(), Float2Left(), Fit2Bottom() ]) # Place article 4 columns with photo cc = 4 article = Article( parent=t, w=cc * cwg, h=h / 2, pr=gutter, conditions=[Right2RightSide(), Float2Top(), Float2Left()]) newRect(h=cc * cw * 2 / 3, mb=gutter, parent=article, fill=0.8, stroke=0, strokeWidth=0.5, conditions=[Left2Left(), Top2Top(), Fit2Width()]) s = None #'Petr & Claudia visiting soon' headLine = self.getHeadline(s, h1Style, cnt=5, w=cc * cwg - 2 * gutter) newTextBox(headLine, parent=article, pr=gutter, w=cc * cwg, pb=gutter, conditions=[Left2Left(), Float2Top(), Fit2Width()]) for n in range(cc): if n == 3: newRect(mb=gutter, parent=article, w=cw, fill=0.8, stroke=0, strokeWidth=0.5, conditions=[ Right2RightSide(), Float2Top(), Float2Left(), Fit2Bottom() ]) else: dummyArticle = blurb.getBlurb('article', newLines=True) bs = self.view.newString(dummyArticle, style=bodyStyle) newTextBox(bs, parent=article, pr=gutter, w=cw, mr=gutter, h=10, conditions=[ Right2Right(), Float2Top(), Float2Left(), Fit2Bottom() ]) cc = 2 # Column width of this article. article = Article(parent=t, w=cc * cwg, borderTop=titleLine, mb=gutter, borderBottom=titleLine, conditions=[ Right2Right(), Float2Top(), Float2Left(), Fit2Bottom() ]) s = None #'AirB&B stock up 450%' headLine = self.getHeadline(s, h2Style, cnt=maxHeadlineShort, w=cc * cwg - gutter) newTextBox(headLine, parent=article, pr=gutter, w=cc * cwg, pt=gutter, conditions=[Left2Left(), Float2Top()]) intro = self.getAnkeiler(cnt=maxAnkeiler) bs = self.view.newString(intro, style=h2IntroStyle) newTextBox(bs, parent=article, pr=gutter, w=cc * cwg, mt=gutter, mb=gutter, conditions=[Left2Left(), Float2Top()]) for n in range(cc): dummyArticle = blurb.getBlurb('article', newLines=True) bs = self.view.newString(dummyArticle, style=bodyStyle) newTextBox(bs, parent=article, pr=gutter, w=cwg, conditions=[ Left2RightSide(), Float2Top(), Float2Left(), Fit2Bottom() ]) cc = 2 # Column width of this article. article = Article(parent=t, w=cc * cwg, borderTop=titleLine, mb=gutter, borderBottom=titleLine, conditions=[ Right2RightSide(), Float2Top(), Float2Left(), Fit2Bottom() ]) s = None #u'Tay & Lan’s best moms' headLine = self.getHeadline(s, h2Style, cnt=maxHeadlineShort, w=cc * cwg - gutter) newTextBox(headLine, parent=article, pr=gutter, w=cc * cwg, pt=gutter, conditions=[Left2Left(), Float2Top()]) intro = self.getAnkeiler(cnt=maxAnkeiler) bs = self.view.newString(intro, style=h2IntroStyle) newTextBox(bs, parent=article, pr=gutter, w=cc * cwg - gutter, mr=gutter, mt=gutter, mb=gutter, conditions=[Left2Left(), Float2Top()]) newRect( mb=gutter, parent=article, h=200, maxH= MAX_HEIGHT, # TODO: Why need to set this, as r.maxH is 100 here. fill=0.8, stroke=0, strokeWidth=0.5, conditions=[Left2Left(), Float2Top(), Fit2Width()]) for n in range(cc): dummyArticle = blurb.getBlurb('article', newLines=True) bs = self.view.newString(dummyArticle, style=bodyStyle) newTextBox(bs, parent=article, pr=gutter, w=cwg, conditions=[ Left2RightSide(), Float2Top(), Float2Left(), Fit2Bottom() ]) self.addTemplate(t.name, t) # Template 'MainPage' t = Template(w=w, h=h, name='MainPage', padding=padding, gridX=gridX, gridY=gridY) for n in range(columns): if n == 0: cc = 3 headLine = self.getHeadline(None, h2Style, cnt=maxHeadline) newTextBox(headLine, parent=t, pr=gutter, w=cc * cwg, conditions=[Left2Left(), Float2Top()]) intro = self.getAnkeiler(cnt=maxAnkeiler) bs = self.view.newString(intro, style=h2IntroStyle) newTextBox(bs, parent=t, pr=gutter, w=cc * cwg, mt=gutter, mb=gutter, conditions=[Left2Left(), Float2Top()]) dummyArticle = blurb.getBlurb('article', newLines=True) bs = self.view.newString(dummyArticle, style=bodyStyle) newTextBox(bs, parent=t, pr=gutter, w=cw + gutter, z=0, conditions=[ Right2RightSide(), Float2Top(), Fit2Bottom(), Float2Left() ]) self.addTemplate(t.name, t)
from pagebot.contexts.strings.flatstring import FlatString from pagebot.toolbox.units import pt from pagebot.toolbox.color import noColor, color from pagebot.contributions.filibuster.blurb import Blurb from pagebot.constants import * W, H = A5 H = pt(H) W = pt(W) M = 100 s = 36 roboto = findFont('Roboto-Regular') robotoBold = findFont('Roboto-Bold') bungee = findFont('BungeeHairline-Regular') blurb = Blurb() txt = blurb.getBlurb('news_headline', noTags=True) testContexts = ( (DrawBotContext(), '_export/testDrawBotString.pdf'), #(FlatContext(), '_export/testFlatString.pdf'), #(InDesignContext(), '_export/testInDesignString.pdf'), #(HtmlContext(), '_export/testHtmlString.pdf'), #(InDesignContext(), '_export/testInDesignString.pdf'), #(IdmlContext(), '_export/testIdmlString.pdf') ) def testContext(context, path): doc = Document(w=W, h=H, context=context) page = doc[1]
# # Hyphenation. from pagebot.document import Document from pagebot import getContext from pagebot.elements import * from pagebot.contributions.filibuster.blurb import Blurb from pagebot.toolbox.color import color from pagebot.toolbox.units import pt from pagebot.fonttoolbox.objects.font import findFont #from pagebot.contexts.flat.flatcontext import FlatContext #context = FlatContext() context = getContext() bungee = findFont('Bungee-Regular') txt = Blurb().getBlurb('article_ankeiler', noTags=True) w = 400 # change width to see other hyphenations h = 400 W = 1200 H = 1500 doc = Document(w=W, h=H, autoPages=1) page = doc[1] # hyphenationHead=4, hyphenationTail=3 currently not supported style = dict(font=bungee, fontSize=pt(24), hyphenation=True) bs = context.newString(txt, style=style) newTextBox(bs, x=100, y=H - h - 100,
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()
# Fonts. f = findFont('Bungee-Regular') bungee = font.open(f.path) f = findFont('Bungee-OutlineRegular') bungeeOutline = font.open(f.path) f = findFont('PageBot-Book') pageBotBook = font.open(f.path) # Images. cotg3src = '../../../docs/stylewars/dondi-white-children-of-the-grave-pt3-martha-cooper.png' cotg3image = image.open(cotg3src) cotg2src = '../../../docs/stylewars/dondi-white-children-of-the-grave-pt2.jpg' cotg2image = image.open(cotg2src) line = 12 blurb = Blurb() h1Outline = strike(bungeeOutline).color(red).size(20, 24) h1 = strike(bungee).color(white).size(20, 24) intro = strike(bungee).color(white).size(10, 12) body = strike(pageBotBook).color(white).size(16, 18) title = blurb.getBlurb('stylewars_original') txt = blurb.getBlurb('stylewars_documentary') redStroke = shape().stroke(red).width(0.5) blackFill = shape().nostroke().fill(black) blackStroke = shape().stroke(black).width(0.2) whiteFill = shape().nostroke().fill(white) d = document(w, h, 'pt')
#!/usr/bin/env python # ----------------------------------------------------------------------------- # Copyright (c) 2016+ Buro Petr van Blokland + Claudia Mens & Font Bureau # www.pagebot.io # # P A G E B O T # # Licensed under MIT conditions # Example written by Frederik Berlaen # # Supporting usage of DrawBot, www.drawbot.com # ----------------------------------------------------------------------------- # # testFiliBusterArticle.py # from pagebot.contributions.filibuster.blurb import Blurb NO_TAGS = True # Flag to show/hide HTML tags in output w = Blurb() print w.getBlurb('news_headline', noTags=NO_TAGS) print print w.getBlurb('article_ankeiler', noTags=NO_TAGS) print print w.getBlurb('article_summary', noTags=NO_TAGS) print print w.getBlurb('article', noTags=NO_TAGS)
from pagebot.toolbox.units import * from pagebot.toolbox.color import * from pagebot.document import Document from pagebot.constants import * from pagebot.elements import * from pagebot.conditions import * from pagebot.fonttoolbox.objects.font import findFont from pagebot import getContext from pagebot.contributions.filibuster.blurb import Blurb context = getContext() b = Blurb() print(b.getBlurb('article')) H, W = A4 PADDING = p(6) H1_FONTSIZE = pt(36) H2_FONTSIZE = pt(14) P_FONTSIZE = pt(10) WATERFALL_TEXT = 'Hamburgefontstiv' COLS = 4 G = pt(12) CW = (W - 2 * PADDING - (COLS - 1) * G) / COLS GRID_X = [(CW, G)] * 4 # --------------------------------------- doc = Document(w=W, h=H, gridX=GRID_X, originTop=False,
from pagebot.contributions.filibuster.blurb import Blurb # Debugging switches SHOW_FRAMES = False # True shows page and padding frames. SHOW_TEMPLATE = False # True shows the ATF scan at the back of every page to show alignment. SHOW_GRID = False # Show page grid and elements backgrounds in opaque colors. if SHOW_GRID: # Some debugging colors, used when SHOW_GRID is on. DEBUG_COLOR0 = (0.7, 0.3, 0.7, 0.2) DEBUG_COLOR1 = (0.3, 0.3, 0.7, 0.2) DEBUG_COLOR2 = (0.7, 0.3, 0.3, 0.2) DEBUG_COLOR3 = (0.3, 0.7, 0.3, 0.2) else: # Otherwise ignore the background colors of the column elements. DEBUG_COLOR0 = DEBUG_COLOR1 = DEBUG_COLOR2 = DEBUG_COLOR3 = None blurb = Blurb() # Basic page metrics. U = 8 # Page layout units, to unite baseline grid and gutter. W = 7.3*INCH # Copy size from original (?) ATF specimen. H = 11*INCH # Hard coded padding sizes derived from the scan. PT, PR, PB, PL = PADDING = 36, 34, 75, 70 # Page padding top, right, bottom, left L = 2*U # Baseline leading G = 3*U # Default gutter = space between the columns # Hard coded column sizes derived from the scan. C1, C2, C3 = (150, 112, 112) # Construct the grid pattern. # Last value None means that there is no gutter running inside the right padding. GRID_X = ((C1, G), (C2, G), (C3, None))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # ----------------------------------------------------------------------------- # Copyright (c) 2016+ Buro Petr van Blokland + Claudia Mens # www.pagebot.io # # P A G E B O T # # Licensed under MIT conditions # Example written by Frederik Berlaen # # Supporting DrawBot, www.drawbot.com # ----------------------------------------------------------------------------- # # testFiliBusterArticle.py # from pagebot.contributions.filibuster.blurb import Blurb NO_TAGS = True # Flag to show/hide HTML tags in output blurb = Blurb() print(blurb.getBlurb('news_headline', noTags=NO_TAGS)+'\n') print(blurb.getBlurb('article_ankeiler', noTags=NO_TAGS)+'\n') print(blurb.getBlurb('article_summary', noTags=NO_TAGS)+'\n') print(blurb.getBlurb('article', noTags=NO_TAGS)+'\n')
class Paragraphs(BaseFontShow): """Showing the specified (variable) font as full page with a matrix of all glyphs in the font. Usage of standard style parameters fill Fill color for the background of the element stroke Draw frame around the element textFill Color of the text. Default is black. padding Use in case of background color or frame. Default is 0 """ def __init__(self, f, words=None, labelSize=None, **kwargs): """ >>> from pagebot.fonttoolbox.objects.font import findFont >>> from pagebot.document import Document >>> from pagebot.constants import Letter >>> from pagebot.contexts.drawbotcontext import DrawBotContext >>> from pagebot.conditions import * >>> from pagebot.toolbox.color import color >>> from pagebot.toolbox.units import em >>> c = DrawBotContext() >>> w, h = Letter >>> doc = Document(w=w, h=h, padding=80, originTop=False, autoPages=2, context=c) >>> style = dict(gh=16, fill=color(0.95), leading=em(1.4)) >>> conditions = [Fit()] >>> page = doc[1] >>> font1 = findFont('AmstelvarAlpha-VF') >>> gs = Paragraphs(font1, parent=page, conditions=conditions, padding=40, style=style, context=c) >>> style = dict(stroke=0, strokeWidth=0.25, gh=8, leading=em(1.4)) >>> page = doc[2] >>> font2 = findFont('RobotoDelta-VF') >>> #font2 = findFont('Upgrade-Regular') >>> #font2 = findFont('Escrow-Bold') >>> gs = Paragraphs(font2, parent=page, conditions=conditions, style=style, padding=40, context=c) >>> score = doc.solve() >>> doc.export('_export/%sParagraphs.pdf' % font1.info.familyName) """ BaseFontShow.__init__(self, **kwargs) self.f = f # Font instance self.words = words or { } # Optional dictionary for headline words. Keys is frame index number. self.usedText = set() # Avoid double use of headline words. # Add semi-random generated content, styles of fitting. self.blurb = Blurb( ) # Random content creator, in case there is no content supplied. self.lineTag = 'design_headline' # Default label where to find random word choices. self.headlineTag = 'design_headline' # Default label where to find (or create) random headline text. self.textTag = 'da_text' # Default label where to find (or create) random body text. self.labelSize = labelSize # If undefined, then don't draw labels. def build(self, view, origin, drawElements=True): """Default drawing method just drawing the frame. Probably will be redefined by inheriting element classes.""" c = self.context p = pointOffset(self.origin, origin) p = self._applyScale(view, p) p = self._applyAlignment(p) # Ignore z-axis for now. self.buildFrame(view, p) # Draw optional background fill, frame or borders. # Let the view draw frame info for debugging, in case view.showFrame == True view.drawElementFrame(self, p) if self.drawBefore is not None: # Call if defined self.drawBefore(self, view, p) # Draw that actual content of the element by stacked specimen rectangles. self.drawStacked(view, p) if self.drawAfter is not None: # Call if defined self.drawAfter(self, view, p) self._restoreScale(view) view.drawElementInfo(self, origin) # Depends on flag 'view.showElementInfo' def getText(self, tag, cnt=None, charCnt=None): """If the tag type of text is in self.words, then take a random choice from there. Otherwise use the tag to create a blurb with the specified length.""" if tag in self.words: text = choice(self.words[tag]) if text in self.usedText: # Already used, try once more. text = choice(self.words[tag]) else: text = self.blurb.getBlurb(tag, cnt=cnt, charCnt=charCnt) self.usedText.add(text) return text def drawStacked(self, view, origin): """Draw the content of the element, responding to size, styles, font and content. Create 2 columns for the self.fontSizes ranges that show the text with and without [opsz] if the axis exists. TODO: If the axis does not exist, do something else with the right column """ c = self.context # Start on top left, with respect to optional padding value. x = self.pl y = self.h - self.pt fontSizes = (7, 8, 9, 10, 11) for fontSize in fontSizes: # Don't update to the new y, next colomn needs to be on the right, starting at the same y. s1 = self.getText(self.headlineTag, cnt=6) if not s1[-1] in ',.!?': s1 += '.' s2 = self.getText(self.textTag) + ' ' + self.getText(self.textTag) x, _ = self.buildTextBox(s1, s2, origin, x, y, w=(self.pw - self.gw) / 2, h=self.ph / len(fontSizes) - self.gh, fontSize=fontSize, alignment=LEFT, labelSize=self.labelSize or self.DEFAULT_LABEL_SIZE, Bwght=0.4, Bwdth=-0.1) # Same text in same fontSize, without optical size axis used _, y = self.buildTextBox(s1, s2, origin, x + (self.pw + self.gw) / 2, y, w=(self.pw - self.gw) / 2, h=self.ph / len(fontSizes) - self.gh, fontSize=fontSize, alignment=LEFT, labelSize=self.labelSize or self.DEFAULT_LABEL_SIZE, label='No optical size axis used.\n\n', Bwght=0.6, Bwdth=-0.1, useOpsz=False)
from pagebot import getRootPath from pagebot import getContext from pagebot.fonttoolbox.variablefontbuilder import getVarFontInstance from pagebot.constants import CENTER from pagebot.toolbox.units import pt from pagebot.toolbox.color import color, Color from pagebot.contributions.filibuster.blurb import Blurb # TODO: merge with Strings NO_TAGS = True # Flag to show/hide HTML tags in output blurb = Blurb() txt = blurb.getBlurb('news_headline', noTags=NO_TAGS) + '\n' txt0 = txt[0:3] txt1 = txt[3:6] txt2 = txt[6:9] txt3 = txt[9:12] c = getContext() W = H = 500 def testBabelStrings(): c.newPage(pt(W), pt(H)) style = dict(font='Helvetica', fontSize=pt(100), textFill=color(1, 1, 0)) # Formattted string using append. print(' * Testing with append') bs = c.newString(txt0) # NOTE: style isn't initiated, bug later on.