def makeDocument(): doc = Document(originTop=False, w=W, h=H, autoPages=1) # Set the view parameters for the required output. view = doc.view c = view.context view.padding = 0 # Make view padding to show crop marks and frame view.showPageFrame = True # Show frame of the page in blue #view.showPagePadding = True view.showPageCropMarks = True # Show crop marks page = doc[0] # Get the first/single page of the document. page.padding = 40 # TODO: order if 4 values? # Make rect as page element centered with centered origin. conditions = (Center2Center(), Middle2Middle()) shadow = Shadow(offset=(ShadowOffset, -ShadowOffset), blur=ShadowBlur, color=(0.2, 0.2, 0.2, 0.5)) textShadow = Shadow(offset=(ShadowTextOffset, -ShadowTextOffset), blur=ShadowTextBlur, color=(0.2, 0.2, 0.2, 0.5)) fs = c.newString('This is text with a shadow', style=dict(font='Verdana', fontSize=30, textFill=0, rLeading=1.2)) newTextBox(fs, fill=0.8, parent=page, w=RectSize, h=RectSize, shadow=shadow, textShadow=textShadow, conditions=conditions, xAlign=CENTER, yAlign=MIDDLE) # Solve the layout conditions of the red rectangle. # Show if one of the conditions failed to solve. score = page.solve() if score.fails: print 'Failed conditions', score.fails return doc
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.""" doc = Document(w=PageWidth, h=PageHeight, originTop=False, autoPages=1) # Get default view from the document and set the viewing parameters. view = doc.getView() view.style['fill'] = 1 view.padding = 40 # To show cropmarks and such, make >40 or so. view.showPageCropMarks = True # Won't show if there is not padding in the view. view.showPageRegistrationMarks = True view.showPageFrame = True view.showPageNameInfo = True view.showElementOrigin = False view.showElementDimensions = False #ShowDimensions view.showElementInfo = False view.showGridColumns = True view.showGrid = True #view.style['showGridCo page = doc[0] # Get the single frint 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 pageAreaW = PageWidth-pl-pr pageAreaH = PageHeight-pt-pb # Resources blockFill = None #(1, 1, 0) # Use color to debug page area gradient = Gradient(locations=[1,0], colors=((0, 0, 0), (0.8, 0.8, 0.8))) shadow = Shadow(offset=(6, -6), blur=10, color=(0.2, 0.2, 0.2, 0.5)) bookBorders = dict(stroke=(1, 1, 1, 0.5),strokeWidth=0.1,line=OUTLINE) bookPadding = (25, 30, 40, 30) # Styles titleStyle =dict(font='Georgia', fontSize=26, rLeading=1.4, xTextAlign=CENTER, textFill=1) authorStyle = dict(font='Georgia-Italic', textFill=1, fontSize=18, xTextAlign=CENTER) headStyle = dict(font='Verdana-Bold', textFill=0, fontSize=14, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=30, paragraphBottomSpacing=0) bodyStyle = dict(font='Verdana', textFill=0, fontSize=12, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=10, hyphenation=True) italicBodyStyle = copy.copy(bodyStyle) italicBodyStyle['font'] = 'Verdana-Italic' italicBodyStyle['paragraphTopSpacing'] = 0 score = page.solve() if score.fails: print 'Condition fails', score.fails return doc # Answer the doc for further doing.
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.""" doc = Document(w=PageWidth, h=PageHeight, originTop=False, autoPages=1) # Get default view from the document and set the viewing parameters. view = doc.view view.style['fill'] = 1 view.padding = 40 # To show cropmarks and such, make >40 or so. view.showPageCropMarks = True # Won't show if there is not padding in the view. view.showPageRegistrationMarks = True view.showPageFrame = True view.showPageNameInfo = True view.showElementOrigin = False view.showElementDimensions = False #ShowDimensions view.showElementInfo = False page = doc[0] # Get the single frint 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 pageAreaW = PageWidth-pl-pr pageAreaH = PageHeight-pt-pb # Resources blockFill = None #(1, 1, 0) # Use color to debug page area gradient = Gradient(locations=[1,0], colors=((0, 0, 0), (0.8, 0.8, 0.8))) shadow = Shadow(offset=(6, -6), blur=10, color=(0.2, 0.2, 0.2, 0.5)) bookBorders = dict(stroke=(1, 1, 1, 0.5),strokeWidth=0.1,line=OUTLINE) bookPadding = (25, 30, 40, 30) # Styles titleStyle =dict(font='Georgia', fontSize=26, rLeading=1.4, xTextAlign=CENTER, textFill=1) authorStyle = dict(font='Georgia-Italic', textFill=1, fontSize=18, xTextAlign=CENTER) headStyle = dict(font='Verdana-Bold', textFill=0, fontSize=14, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=30, paragraphBottomSpacing=0) bodyStyle = dict(font='Verdana', textFill=0, fontSize=12, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=10, hyphenation=True) sideBarStyle = dict(font='Verdana', textFill=0, fontSize=10, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=10, hyphenation=True) italicBodyStyle = copy.copy(bodyStyle) italicBodyStyle['font'] = 'Verdana-Italic' italicBodyStyle['paragraphTopSpacing'] = 0 # Make new container for adding elements inside with alignment. newRect(z=10, w=pageAreaW, h=pageAreaH, fill=blockFill, parent=page, margin=0, padding=0, yAlign=MIDDLE, maxW=pageAreaW, maxH=pageAreaH, xAlign=CENTER, conditions=(Center2Center(), Middle2Middle())) t1 = newTextBox('The PageBot Times', z=0, font='BlackmoorLetPlain', fontSize=40, w=pageAreaW/2, parent=page, conditions=(Left2Left(), Top2Top())) w = pageAreaW*0.75 # Used as element width and relative font size. padding = PageHeight/24 t2 = newTextBox('Book Review', z=0, font='NewOdanaLarge-Black', fontSize=w/7, w=PageWidth*0.75, parent=page, conditions=(Left2Left(), Float2Top())) i1 = newRect(z=0, h=PageHeight/2, padding=padding, gradient=gradient, borders=None, parent=page, conditions=(Fit2Width(), Float2Top())) i1.solve() m = i1.h/10 # Book 1 cover book1 = newRect(z=0, margin=m, w=(i1.w-3*m)/2, fill=(0.05, 0.05, 0.25), gradient=None, parent=i1, shadow=shadow, padding=bookPadding, conditions=(Fit2Height(), Top2Top(), Left2Left()), borders=bookBorders) fs = newFsString('Educational series', style=authorStyle) fs += newFsString('\n\nThrilling title\nfor my first book\nabout Design', style=titleStyle) fs += newFsString('\n'*3 + 'John Smith', style=authorStyle) frame = newRect(margin=6, conditions=(Fit(),), title1 = newTextBox(fs, parent=book1, shadow=None, conditions=(Fit2Width(), Center2Center(), Top2Top()))) fs = newFsString(u'¶', style=authorStyle) publisher1 = newTextBox(fs, parent=book1, shadow=None, conditions=(Fit2Width(), Bottom2Bottom())) # Book 2 cover book2 = newRect(z=0, margin=m, w=(i1.w-3*m)/2, fill=(0.1, 0.2, 0.45), gradient=None, parent=i1, shadow=shadow, padding=bookPadding, conditions=(Fit2Height(), Top2Top(), Right2Right()), borders=bookBorders) fs = newFsString('Educational series', style=authorStyle) fs += newFsString('\n\nPredictable title of my second book about Typography', style=titleStyle) fs += newFsString('\n'*3 + 'John Smith', style=authorStyle) title2 = newTextBox(fs, parent=book2, marginTop=120, shadow=None, conditions=(Fit2Width(), Center2Center(), Top2Top())) fs = newFsString(u'¶', style=authorStyle) publisher2 = newTextBox(fs, parent=book2, shadow=None, conditions=(Fit2Width(), Bottom2Bottom())) bottomContainer = newRect(parent=page, w=w, borderBottom=dict(strokeWidth=1), padding=0, conditions=(Left2Left(), Float2Top(), Fit2Bottom())) t3 = newTextBox('Reviewing 2017 score', z=0, font='BodoniSvtyTwoOSITCTT-Book', fontSize=w/8.5+3, w=w, stroke=NO_COLOR, pb=16, borderBottom=dict(strokeWidth=1), parent=bottomContainer, conditions=(Fit2Width(), Float2Top()), mt=20) # Review content fs = newFsString('About the thrilling title\n', style=headStyle) fs += newFsString(t, style=bodyStyle) t4 = newTextBox(fs, w=w/2-G, mt=10, parent=bottomContainer, conditions=(Left2Left(), Float2Top())) fs = newFsString('Second column\n', style=headStyle) fs += newFsString(t, style=bodyStyle) t5 = newTextBox(fs, w=w/2-G, mt=10, parent=bottomContainer, conditions=(Float2Right(), Float2Top())) # Text box on bottom right fs = newFsString('This is a funny head.\n', style=headStyle) fs += newFsString(t+t, style=sideBarStyle) t6 = newTextBox(fs, w=w/3-16, pt=34, parent=page, conditions=(Float2Right(), Float2Top(), Fit2Bottom())) fs = newFsString(topT, style=bodyStyle) fs += newFsString('\nAn addition italic line', style=italicBodyStyle) topText = newTextBox(fs, w=w/3-16, parent=page, conditions=(Top2Top(), Right2Right())) score = page.solve() if score.fails: print 'Condition fails', score.fails return doc # Answer the doc for further doing.
def makeDocument(fontPath): u"""Create Document instance with a single page. Fill the page with elements and perform a conditional layout run, until all conditions are solved.""" f = Font(fontPath) # Get PageBot Font instance of Variable font. fHeader = getVariableFont(f, dict(wght=0.5)) fHeaderCondensed = getVariableFont(f, dict(wght=0.5, wdth=0.4)) doc = Document(w=PageWidth, h=PageHeight, originTop=False, autoPages=1) # Get default view from the document and set the viewing parameters. view = doc.getView() view.style['fill'] = 1 view.padding = 0 # To show cropmarks and such, make >40 or so. view.showPageCropMarks = True # Won't show if there is not padding in the view. view.showPageRegistrationMarks = True view.showPageFrame = True view.showPagePadding = True view.showPageNameInfo = True view.showElementOrigin = False view.showElementDimensions = False #ShowDimensions view.showElementInfo = False page = doc[0] # Get the single frint 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 pageAreaW = PageWidth-pl-pr pageAreaH = PageHeight-pt-pb # Resources blockFill = None #(1, 1, 0) # Use color to debug page area gradient = Gradient(locations=[1,0], colors=((0, 0, 0), (0.8, 0.8, 0.8))) shadow = Shadow(offset=(6, -6), blur=10, color=(0.2, 0.2, 0.2, 0.5)) bookBorders = dict(stroke=(1, 1, 1, 0.5),strokeWidth=0.1,line=OUTLINE) bookPadding = (25, 30, 40, 30) # Styles titleStyle =dict(font=fHeader.installedName, fontSize=26, rLeading=1.4, xTextAlign=CENTER, textFill=1) authorStyle = dict(font='Georgia-Italic', textFill=1, fontSize=18, xTextAlign=CENTER) headStyle = dict(font=fHeader.installedName, textFill=0, fontSize=14, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=30, paragraphBottomSpacing=0) bodyStyle = dict(font='Verdana', textFill=0, fontSize=12, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=10, hyphenation=True) italicBodyStyle = copy.copy(bodyStyle) italicBodyStyle['font'] = 'Verdana-Italic' italicBodyStyle['paragraphTopSpacing'] = 0 fs = newFS(f.info.familyName + ' ' + f.info.styleName, style=titleStyle) _, th = textSize(fs) title = newTextBox(fs, conditions=[Top2Top(), Fit2Width()], parent=page, h=th*1.2) # Make new container for adding elements inside with alignment. newRect(z=10, w=pageAreaW, h=pageAreaH, fill=blockFill, parent=page, margin=0, padding=0, yAlign=MIDDLE, maxW=pageAreaW, maxH=pageAreaH, xAlign=CENTER, conditions=(Center2Center(), Middle2Middle())) t1 = newTextBox('Inside the Amstelvar', z=0, font=fHeader.installedName, fontSize=40, w=pageAreaW/2, parent=page, conditions=(Left2Left(), Top2Top())) w = pageAreaW*0.75 # Used as element width and relative font size. padding = PageHeight/24 fs = newFS('Variable Fonts ', style=dict(font=fHeader.installedName, textFill=0, fontSize=90)) fs += newFS('Explained', style=dict(font=fHeaderCondensed.installedName, textFill=0, fontSize=90)) t2 = newTextBox(fs, z=0, w=PageWidth*0.75, parent=page, conditions=(Left2Left(), Fit2Width(), Float2Top())) circle = VariableCircle(f, s=GLYPH_NAME, name='VariableCircleSpeciment', parent=page, padding=4, x=100, fontSize=150, maxW=PageWidth-2*PADDING, minW=100, showAxisName=True, # Conditions make the element move to top-left of the page. # And the condition that there should be no overflow, otherwise the text box # will try to solve it. #conditions=[Right2Right(), Float2Top()], conditions=[Left2Left(), Fit2Width(), Bottom2Bottom()], # Position of the origin of the element. Just to show where it is. # Has no effect on the position conditions. yAlign=BOTTOM, xAlign=LEFT, fill=CIRCLE_ELEMENT_FILL, borders=1, ) score = page.solve() if score.fails: print 'Condition fails', score.fails return doc # Answer the doc for further doing.
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.""" bookName = findFont(('Book', 'Regular')) # Find these styles in order. mediumName = findFont(('Medium', 'Book', 'Regular')) boldName = findFont(('Bold', 'Medium')) doc = Document(w=PageWidth, h=PageHeight, originTop=False, autoPages=1) # Get default view from the document and set the viewing parameters. view = doc.getView() view.style['fill'] = 1 view.padding = 0 # To show cropmarks and such, make >40 or so. view.showPageCropMarks = True # Won't show if there is not padding in the view. view.showPageRegistrationMarks = True view.showPageFrame = True view.showPageNameInfo = True view.showElementOrigin = False view.showElementDimensions = False #ShowDimensions view.showElementInfo = False page = doc[0] # Get the single frint 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 pageAreaW = PageWidth - pl - pr pageAreaH = PageHeight - pt - pb # Resources blockFill = None #(1, 1, 0) # Use color to debug page area gradient = Gradient(locations=[1, 0], colors=((0.3, 0.3, 0.3), (0.6, 0.6, 0.6))) shadow = Shadow(offset=(6, -6), blur=10, color=(0.2, 0.2, 0.2, 0.5)) bookBorders = dict(stroke=(1, 1, 1, 0.5), strokeWidth=0.1, line=OUTLINE) bookPadding = (25, 30, 40, 30) # Styles titleStyle = dict(font=bookName, fontSize=26, rLeading=1.4, xTextAlign=CENTER, textFill=1) authorStyle = dict(font=bookName, textFill=1, fontSize=18, xTextAlign=CENTER) headStyle = dict(font=boldName, textFill=0, fontSize=62, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=30, openTypeFeatures=dict(liga=True), paragraphBottomSpacing=0) bodyStyle = dict(font=bookName, textFill=0, fontSize=12, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=10, hyphenation=True) # Make new container for adding elements inside with alignment. newRect(z=10, w=pageAreaW, h=pageAreaH, fill=blockFill, parent=page, margin=0, padding=0, yAlign=MIDDLE, maxW=pageAreaW, maxH=pageAreaH, xAlign=CENTER, conditions=(Center2Center(), Middle2Middle())) t1 = newTextBox('PageBot Educational Series', z=0, font=bookName, fontSize=42, w=pageAreaW * 0.75, parent=page, conditions=(Left2Left(), Top2Top())) w = pageAreaW * 0.75 # Used as element width and relative font size. padding = 24 t2 = newTextBox('Hot metal typesetting', z=0, font=mediumName, fontSize=w / 8, w=pageAreaW, parent=page, mt=14, conditions=(Left2Left(), Float2Top())) i1 = newRect(z=0, h=PageHeight / 2, pl=padding, pr=padding, gradient=gradient, borders=None, parent=page, conditions=(Fit2Width(), Float2Top(), Fit2Bottom())) i1.solve() fs = newFS(topT, style=bodyStyle) fs += newFS('\nPrepare for what comes next.', style=bookName) topText = newTextBox(fs, w=w / 3 - 16, parent=page, conditions=(Top2Top(), Right2Right())) # Review content. Hard coded ligatures. t = u'This is an example of hot metal typesetting, where every letter had a fixed shape and its own width as rectangular box.\nVariable Fonts could adjust, fit and decorate letters where it is most needed in a column of text. Not in this example.' fs = newFS(t, style=headStyle) t4 = newTextBox(fs, w=w / 2 - G, mt=10, parent=i1, gradient=None, drawBefore=drawBefore, conditions=(Fit2Width(), Float2Top())) # Font names if 'Proforma' in bookName or 'Productus' in bookName: fontNamesFeatures = 'Example featuring typefaces TypeNetwork TYPETR Productus and Proforma' else: fontNamesFeatures = 'Example featuring OSX system fonts %s' % ', '.join( sorted(set((bookName, mediumName, boldName)))) fs = newFS(fontNamesFeatures, style=dict(font=bookName, fontSize=14, textFill=0)) t5 = newTextBox(fs, w=w / 2 - G, mt=10, parent=page, gradient=None, conditions=(Fit2Width(), Float2Top())) score = page.solve() if score.fails: print 'Condition fails', score.fails return doc # Answer the doc for further doing.
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.""" doc = Document(w=PageWidth, h=PageHeight, originTop=False, autoPages=1) # Get default view from the document and set the viewing parameters. view = doc.getView() view.style['fill'] = 1 view.padding = 40 # To show cropmarks and such, make >40 or so. view.showPageCropMarks = True # Won't show if there is not padding in the view. view.showPageRegistrationMarks = True view.showPageFrame = True view.showPageNameInfo = True view.showElementOrigin = False view.showElementDimensions = False #ShowDimensions view.showElementInfo = False view.showGridColumns = True view.showGrid = True #view.style['showGridCo page = doc[0] # Get the single frint 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 pageAreaW = PageWidth - pl - pr pageAreaH = PageHeight - pt - pb # Resources blockFill = None #(1, 1, 0) # Use color to debug page area gradient = Gradient(locations=[1, 0], colors=((0, 0, 0), (0.8, 0.8, 0.8))) shadow = Shadow(offset=(6, -6), blur=10, color=(0.2, 0.2, 0.2, 0.5)) # Styles coverTitleStyle = dict(font='Georgia', fontSize=80, rLeading=1.4, xTextAlign=CENTER, textFill=(1, 0, 0)) titleStyle = dict(font='Georgia', fontSize=26, rLeading=1.4, xTextAlign=CENTER, textFill=1) authorStyle = dict(font='Georgia-Italic', textFill=1, fontSize=18, xTextAlign=CENTER) headStyle = dict(font='Verdana-Bold', textFill=0, fontSize=14, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=30, paragraphBottomSpacing=0) bodyStyle = dict(font='Verdana', textFill=0, fontSize=12, rLeading=1.4, xTextAlign=LEFT, paragraphTopSpacing=10, hyphenation=True) italicBodyStyle = copy.copy(bodyStyle) italicBodyStyle['font'] = 'Verdana-Italic' italicBodyStyle['paragraphTopSpacing'] = 0 # Adding width to formatted string request will scale fontSize of # style to force fit width. fs = newFS('Magazine', w=page.pw, style=coverTitleStyle) # Keep h=None, to make vertical elastic box, depending on content. tb = newTextBox(fs, parent=page, showBaselines=True, conditions=[Fit2Width(), Top2TopSide()]) score = page.solve() if score.fails: print 'Condition fails', score.fails return doc # Answer the doc for further doing.
# # Free to use. Licensed under MIT conditions # # Supporting usage of DrawBot, www.drawbot.com # Supporting usage of Flat, https://github.com/xxyxyz/flat # ----------------------------------------------------------------------------- # # publications.py # from pagebot.contexts import defaultContext as context from pagebot.fonttoolbox.objects.font import getFontByName from pagebot.style import A4, CENTER, DISPLAY_BLOCK, RIGHT, LEFT from pagebot import Gradient, Shadow from pagebot.toolbox.dating import now shadow = Shadow(offset=(6, -6), blur=10, color=(0.2, 0.2, 0.2, 0.5)) W, H = A4[0] * 3 / 4, A4[1] * 3 / 4 TYPETR_COLOR = [0x1D / 255, 0x42 / 255, 0x9A / 255] def buildCoverPages1(w, h, imagePath, page): magazineTitle = 'Bier!' M = 10 # Margin ML, MR, MT, MB = M, M, M, 1.5 * M cw = w - ML - MR LM = 2 * M