def makeDocument(): u"""Make a new document.""" doc = Document(w=W, h=H, originTop=False, autoPages=1) print('One page in the document', doc.pages) view = doc.getView() view.showPagePadding = True view.showElementDimensions = True view.showElementOrigin = True page = doc[0] # Get the single page from te document. page.name = 'First page' page.padding = 20 conditions = (Center2Center(), Middle2Middle()) # Try other positions #conditions= (Left2Left(), Top2TopSide()) #conditions= (Right2Right(), Top2TopSide()) # Position square in the center of the page area. # Notice that their alignment (left) does not matter for the conditions. newTextBox(page.name, w=30, h=30, parent=page, pl=3, pt=3, conditions=conditions, fill=0.7) page.solve() view = doc.getView() view.w, view.h = W, H view.padding = 0 # Don't show cropmarks and such. return doc # Answer the doc for further doing.
def showPaths(): context = getContext() doc = Document(w=W, h=H, originTop=False, autoPages=1, context=context) page = doc[1] c = (Fit2Right(), Left2Left(), Float2Top()) f = findFont('PageBot-Regular') # FIXME: text disappears with padding. #t = newText('bla', font='Helvetica', parent=page, conditions=c, fontSize=200, padding=1) # FIXME: causes scaling unit error. #path = newPageBotPath(context=context) #path.text('ABCD', style=dict(font=f, fontSize=30, fill=(0, 1, 0))) #newPaths(path, parent=page, fill=(0, 1, 1), conditions=c, stroke=None) rootPath = getRootPath() s = dict(fontSize=24, font=f) msg = 'Root path is %s' % rootPath bs = page.newString(msg, style=s) makeText(bs, page, c) resourcesPath = getResourcesPath() msg = 'Resources path is %s' % resourcesPath bs = page.newString(msg, style=s) makeText(bs, page, c) print(glob.glob('%s/*' % resourcesPath)) defaultFontPath = getDefaultFontPath() msg = 'Default font path is %s' % defaultFontPath bs = page.newString(msg, style=s) makeText(bs, page, c) page.solve() doc.build()
def makeDocument(): doc = Document(w=W, h=H, originTop=False) view = doc.getView() view.padding = INCH/2 view.showPageNameInfo = True view.showPageCropMarks = True view.showPagePadding = True view.showPageFrame = True view.showPageRegistrationMarks = True view.showGrid = False view.showGridColumns = True view.showElementOrigin = True view.showElementInfo = False page = doc[0] page.padding = INCH #rr = newRect(parent=page, x=100, y=200, w=50, h=50, fill=(1, 0, 0)) cc = [Left2Left(), Float2Top()] rr = newRect(parent=page, h=300, conditions=cc, fill=(1, 0, 0)) print page.elements conditions = [Left2LeftSide(), Top2TopSide(), Fit2Width()] conditions = [Left2Left(), Float2Top()] pr = newRect(parent=page, conditions=conditions, w=page.pw*2/3, fill=(1, 0, 1)) doc.solve() #rr.left = pr.right #rr.top = pr.bottom return doc
def makeDocument(): # Creates the publication/document that holds the pages. doc = Document(w=W, h=H, originTop=False, autoPages=1) # Gets page by pageNumber, first in row (at this point there is only one in # this row). page = doc[1] page.padding = 28 page.showPadding = True conditions = [Right2Right(), Float2Top(), Float2Left()] #, Float2Top()]#, Float2Left()] # TODO: Solve this bug, does not mirror. #conditions = [Left2Left(), Float2Top(), Float2Right()] numberOfSquares = 88 ratio = 1 / numberOfSquares for n in range(numberOfSquares): newRect(w=40, h=40, parent=page, fill=color(1 - n * ratio, 0, 0.5), conditions=conditions, margin=0) # Recursively solve the conditions in all pages. # If there are failing conditions, then the status # is returned in the Score instance. score = doc.solve() doc.build()
def fit(): varFont = findFont('RobotoDelta-VF') print(varFont.axes) condensedFont = getVarFontInstance(varFont, dict(wdth=75, YTUC=528)) wideFont = getVarFontInstance(varFont, dict(wdth=125, YTUC=528)) boldFont = getVarFontInstance(varFont, dict(wght=900, GRAD=1)) W, H = 500, 500 PADDING = 56 COL = 40 doc = Document(w=W, h=H, originTop=False) view = doc.view context = view.context page = doc[1] # Get page on pageNumber, first in row (this is only one now). page.padding = PADDING s = 'a' fontSize = 32 for ix in range(10): for iy in range(10): instance = getVarFontInstance(varFont, dict(wdth=75, YTUC=528)) style = dict(font=instance, fontSize=fontSize, leading=fontSize) bs = context.newString(s, style=style) tw, th = bs.size newText(bs, x=page.pl+ix*COL, y=page.pb+iy*COL, w=COL, h=COL, parent=page) doc.export(EXPORT_PATH)
def testContext(context, path): doc = Document(w=W, h=H, context=context) page = doc[1] #print('Current page: %s' % page) nextPage = page.next #print('Next page: %s' % nextPage) #print(type(page)) #print('Units: %s' % context.units) #print('# Testing document in %s' % context) conditions = [Right2Right(), Float2Top(), Float2Left()] for n in range(10): newLine(x=100, y=n * 100, parent=page, stroke=0) for n in range(10): newRect(w=40, h=42, mr=4, mt=4, parent=nextPage, fill=color(random() * 0.5 + 0.5, 0, 0.5), conditions=conditions) score = nextPage.solve() #print(score) doc.build() # Export?
def makeDocument(): # Creates the publication/document that holds the pages. doc = Document(w=W, h=H, originTop=False, autoPages=1) # Gets page by pageNumber, first in row (at this point there is only one in # this row). page = doc[1] page.padding = PADDING page.showPadding = True conditions = [Right2Right(), Float2Top(), Float2Left()] # TODO: Solve this bug, does not mirror. conditions = (Left2Left(), Float2Top(), Float2Right()) numberOfSquares = 88 ratio = 1 / numberOfSquares for n in range(numberOfSquares): newRect(w=RW, h=RH, parent=page, fill=color(1 - n * ratio, 0, 0.5), conditions=conditions, margin=0) # Recursively solve the conditions in all page child elements.. # If there are failing conditions, then the status # is returned in the Score instance. score = doc.solve() # Export to various export formats for exportPath in EXPORT_PATHS: doc.export(exportPath)
def makeDocument(): u"""Create the main document in the defined size with a couple of automatic empty pages.""" doc = Document(w=W, h=H, title='Variable Font Sample Page', originTop=False, startPage=1, autoPages=10, context=context) # Get default view from the document and set the viewing parameters. view = doc.view view.padding = INCH / 2 # To show cropmarks and such, make >=20*MM or INCH. view.showPageCropMarks = True # Won't show if there is not padding in the view. view.showPageFrame = False # No frame in case PAPER_COLOR exists to be shown. view.showPageRegistrationMarks = True view.showPageNameInfo = True view.showTextOverflowMarker = False # Don't show marker in case Filibuster blurb is too long. # Build the pages for all fonts that include one of these patterns. fontNames = findInstalledFonts(fontNamePatterns=FONT_NAME_PATTERNS, context=context) buildSpecimenPages(doc, fontNames) # Solve remaining layout and size conditions. score = doc.solve() if score.fails: print 'Conditiond failed', score.fails return doc
def makeDocument(): u"""Make a new document.""" W = H = PageSize # Create a new document, default to the defined page size. doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=2) view = doc.getView() view.padding = 0 # Aboid showing of crop marks, etc. view.showPageCropMarks = True view.showPageRegistrationMarks = True view.showPageFrame = True view.showPagePadding = True view.showElementOrigin = True view.showElementDimensions = False # Get list of pages with equal y, then equal x. #page = doc[0][0] # Get the single page from te document. page0 = doc.getPage(0) # Get page on pageNumber, # first in row (this is only one now). page0.name = 'Page 1' page0.padding = PagePadding s = '' for n in range(10): s += ('(Line %d) Volume of text defines the box height.' ' Volume of text defines the box height.\n') % (n+1) h1 = None newTextBox(s, name='CSSTextBox1', parent=page0, padding=4, x=100, font='Verdana', h=h1, maxW=W-2*PagePadding, minW=100, mb=20, mr=10, # 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=[Left2Left(), Fit2Width(), Float2Top()], # Position of the origin of the element. # Just to show where it is. # Has no effect on the position conditions. yAlign=BOTTOM, xAlign=LEFT, leading=5, fontSize=9, textFill=0, strokeWidth=0.5, fill=0.9, stroke=None) newTextBox('', # Empty box, will get the # overflow from e1, if there is any. name='CSSTextBox2', # Flow reference by element.name parent=page0, padding=4, x=100, h=200, maxW=W-2*PagePadding, minW=100, conditions=[Left2Left(), Fit2Width(), Float2Top()], yAlign=TOP, fill=1, stroke=None) score = doc.solve() # Try to solve all pages. if score.fails: print score.fails return doc # Answer the doc for further doing.
def makeDocument(): u"""Make a new document.""" # Create a new document, default to the defined page size. doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=2) view = doc.getView() view.padding = ViewPadding # Aboid showing of crop marks, etc. view.showPageCropMarks = True view.showPageRegistrationMarks = True view.showPageFrame = True view.showPagePadding = True view.showElementOrigin = True view.showElementDimensions = False view.showTextOverflowMarker = False padding = 12 # Get list of pages with equal y, then equal x. #page = doc[0][0] # Get the single page from te document. page = doc.getPage( 0) # Get page on pageNumber, first in row (this is only one now). page.name = 'Page 1' page.padding = padding BODY_FONT = 'BitcountMonoDouble-RegularCircle' fs = newFS('TYPETR', w=W - padding * 2, style=dict(font=BODY_FONT, fontSize=56, leading=0, textFill=0)) fs += newFS("""\nPetr van Blokland Designer|Lecturer|Developer Rietveld 56 | 2611 LM Delft The Netherlands Email [email protected] typetr.typenetwork.com Twitter @petrvanblokland Mobile +31 6 2421 9502""", style=dict(font=BODY_FONT, fontSize=9, leading=0, textFill=0)) e1 = newTextBox( fs, name='ElasticTextBox1', parent=page, font=BODY_FONT, pt=6, # And the condition that there should be no overflow, otherwise the text box # will try to solve it. conditions=[Left2Left(), Fit2Width(), Float2TopSide()], # Position of the origin of the element. Just to show where it is. # Has no effect on the position conditions. ) score = doc.solve() # Try to solve all pages. if score.fails: print score.fails return doc # Answer the doc for further doing.
def makeDocument(): u"""Make a new document.""" #W = H = 120 # Get the standard a4 width and height in points. W = PageSize H = PageSize # Hard coded SQUARE and GUTTE, just for simple demo, instead of filling padding an columns in the root style. # Page size decides on the amount squares that is visible. # Page padding is centered then. sqx = int(W/(SQUARE + GUTTER)) # Whole amount of squares that fit on the page. sqy = int(H/(SQUARE + GUTTER)) # Calculate centered paddings for the amount of fitting squares. # Set values in the rootStyle, so we can compare with column calculated square position and sizes. #rs['colH'] = rs['colW'] = SQUARE # Make default colW and colH square. #padX = (W - sqx*(SQUARE + GUTTER) + GUTTER)/2 my = (H - sqy*(SQUARE + GUTTER) + GUTTER)/2 doc = Document(w=W, h=H, originTop=False, title='Color Squares', autoPages=1) view = doc.getView() view.padding = 0 # Aboid showing of crop marks, etc. view.showElementOrigin = True # Get list of pages with equal y, then equal x. #page = doc[0][0] # Get the single page from te document. page = doc.getPage(0) # Get page on pageNumber, first in row (this is only one now). page.name = 'This is a demo page for floating child elements' page.padding = PagePadding page.gutter3D = GUTTER # Set all 3 gutters to same value im = newImage('images/cookbot10.jpg', (50, 50, 10), padding=0, parent=page, w=200, h=300, conditions=(Top2Top(), Fit2Width(), SolveBlock(), Shrink2BlockBottom()), yAlign=BOTTOM, fill=(0, 1, 0, 0.3), stroke=(1, 0, 0) ) # Give parent on creation, to have the css chain working. # Caption falls through the yr2 (with differnt z) and lands on yr1 by Float2BottomSide() fs = doc.context.newString('Captions float below the image', style=dict(font='Verdana', fontSize=20, textFill=1)) cap = newTextBox(fs, name='Caption', parent=im, z=0, conditions=[ Fit2Width(), Float2Top()], padding=4, font='Verdana', yAlign=TOP, fontSize=9, textFill=1, strokeWidth=0.5, fill=(0, 0, 1, 0.3), stroke=(0, 0, 1), ) score = page.solve() if score.fails: print score.fails print im.h for e in im.elements: print e.h return doc # Answer the doc for further doing.
def fit(): varFont = findFont('RobotoDelta-VF') print(varFont.axes) condensedFont = getVarFontInstance(varFont, dict(wdth=75, YTUC=528)) wideFont = getVarFontInstance(varFont, dict(wdth=125, YTUC=528)) boldFont = getVarFontInstance(varFont, dict(wght=900, GRAD=1)) W, H = 500, 400 PADDING = 8 doc = Document(w=W, h=H, originTop=False) view = doc.view context = view.context page = doc[1] # Get page on pageNumber, first in row (this is only one now). page.padding = PADDING s = 'Variable' labelStyle = dict(font=varFont.path, fontSize=8, textFill=(1, 0, 0), leading=8) conditions1 = [Left2Left(), Top2Top()] conditions2 = [Left2Left(), Float2Top()] fontSize = 80 style = dict(font=varFont.path, fontSize=fontSize, leading=fontSize) bs = context.newString(s, style=style) tw, th = bs.size newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, conditions=conditions1) labelS = context.newString('Original var-font %0.2fpt' % (bs.fontSize), style=labelStyle) newText(labelS, parent=page, conditions=conditions2) style = dict(font=condensedFont.path, fontSize=fontSize, leading=fontSize) bs = context.newString(s, style=style) tw, th = bs.size newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, conditions=conditions2) labelS = context.newString('Wide %0.2fpt %s' % (bs.fontSize, wideFont.info.location), style=labelStyle) newText(labelS, parent=page, conditions=conditions2) style = dict(font=wideFont.path, fontSize=fontSize, leading=fontSize) bs = context.newString(s, style=style) tw, th = bs.size newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, conditions=conditions2) labelS = context.newString('Wide %0.2fpt %s' % (bs.fontSize, wideFont.info.location), style=labelStyle) newText(labelS, parent=page, conditions=conditions2) style = dict(font=boldFont.path, fontSize=fontSize, leading=fontSize) bs = context.newString(s, style=style) tw, th = bs.size newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, conditions=conditions2) labelS = context.newString('Bold %0.2fpt %s' % (bs.fontSize, boldFont.info.location), style=labelStyle) newText(labelS, parent=page, conditions=conditions2) page.solve() doc.export(EXPORT_PATH)
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 makeLogo(): doc = Document(w=W, h=W, autoPages=1) for frame in range(FRAMES): page = doc.newPage() x = int(round(random()*(W-4*LINE))) y = int(round(random()*(H-4*LINE))) w = h = 4*LINE newRect(x=x, y=y, w=w, h=h, parent=page, style=dict(strokeWidth=LINE, stroke=0, fill=None)) return doc
def makeDocument(fontPath): u"""Make a new document.""" f = Font(fontPath) # Get PageBot Font instance of Variable font. W = H = PageSize # Create a new document, default to the defined page size. doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=1) view = doc.getView() view.padding = 0 # Aboid showing of crop marks, etc. view.showPageCropMarks = True view.showPageRegistrationMarks = True view.showPageFrame = True view.showPagePadding = True view.showElementOrigin = False view.showElementDimensions = False # Get list of pages with equal y, then equal x. #page = doc[0][0] # Get the single page from te document. page = doc.getPage(0) # Get page on pageNumber, first in row (this is only one now). page.name = 'Page 1' page.padding = PagePadding fs = doc.context.newString(f.info.familyName + ' ' + f.info.styleName, style=dict(font=f.name, fontSize=18, textFill=0)) _, th = textSize(fs) title = newTextBox(fs, conditions=[Top2Top(), Fit2Width()], parent=page, h=th*1.2) circle = VariableCircle(f, s=GLYPH_NAME, name='VariableCircleSpeciment', parent=page, padding=4, x=100, fontSize=64, maxW=W-2*PagePadding, 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=[Float2Top(), Fit2Bottom(), Center2Center()], # 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=0, ) score = doc.solve() # Try to solve all pages. if score.fails: print score.fails # To avoid circular dependent conditions, we correct the position of the title # on left to that the position of the circle has become. title.pl = circle.x - page.pl return doc # Answer the doc for further doing.
def makeDocument(): if mode == 'Anim': template = makeAnimation(0,0,0,0) elif mode == 'Iter': template = makeIteration(0,0,0,0,0,0,0,0) elif mode == 'Words': template = makeWords(0,0,0,0,0,0,0,0) pages = [] for i in range(frames): pages.append(i+1) doc = Document(title='V-F AnimIterator', w=W, h=H, originTop=False, autoPages=frames, defaultTemplate=template) for i in pages: def easeInOutQuad(n): if n< 0.5: return 2 * n**2 else: n=n * 2 -1 return -0.5 * (n*(n-2) - 1) def Method(start, end): ee = easeInOutQuad(i/frames) result = start+(((end-start) * ee)) return result sWGTH = Method(WG[0],WG[1]) eWGTH = Method(WG[2],WG[3]) sWDTH = Method(WD[0],WD[1]) eWDTH = Method(WD[2],WD[3]) sSLNT = Method(SL[0],SL[1]) eSLNT = Method(SL[2],SL[3]) sCNTR = Method(CT[0],CT[1]) eCNTR = Method(CT[2],CT[3]) pageid = i + 1 # print(pageid, sWGTH,eWGTH,sWGTH,eWDTH) page = doc.getPage(i) if mode == 'Anim': page.applyTemplate(makeAnimation(sWGTH,sWDTH,sSLNT,sCNTR)) elif mode == 'Iter': page.applyTemplate(makeIteration(sWGTH,eWGTH,sWDTH,eWDTH, sSLNT, eSLNT, sCNTR, eCNTR)) elif mode == 'Words': page.applyTemplate(makeWords(sWGTH,eWGTH,sWDTH,eWDTH, sSLNT, eSLNT, sCNTR, eCNTR)) else: print ('Incorrect mode') doc.solve() 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)) 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(): """Make a new document.""" W = H = PageSize doc = Document(w=W, h=H, originTop=False, title='Color Squares', autoPages=1) view = doc.getView() view.padding = pt(0) # Aboid showing of crop marks, etc. view.showOrigin = False view.showTextOverflowMarker = False # Get list of pages with equal y, then equal x. #page = doc[1][0] # Get the single page from te document. page = doc.getPage(1) # Get page on pageNumber, first in row (this is only one now). page.name = 'This is a demo page for floating child elements' page.padding = PagePadding # Show margin of page, can also be done by # view.showPadding = True newRect(fill=color(0.9), parent=page, margin=0, conditions=(Left2Left(), Fit2Right(), Bottom2Bottom(), Fit2Height())) redContainer = newRect(fill=color(1, 0, 0), pb=pt(10), w=RedSize, h=RedSize, padding=pt(10), conditions=(Left2Left(), Bottom2Bottom()), parent=page) # Yellow square yellowSquare = newRect(fill=color(1, 1, 0), z=pt(8), w=YellowSize, h=YellowSize, parent=redContainer, xAlign=CENTER, yAlign=TOP, conditions=(Center2Center(), Bottom2Bottom())) # Blue square in different z=layer. No interaction with Floating on other z-layers. blueSquare = newRect(fill=color(0, 1, 1), z=10, w=50, h=50, parent=redContainer, xAlign=CENTER, conditions=(Top2Top(), Center2Center())) # Centered string fs = doc.context.newString('Float on top of yellow', style=dict(font='Verdana', fontSize=7, xTextAlign=CENTER, textFill=blackColor)) # Text falls through the yr2 (with differnt z) and lands on yellowSquare by Float2SideBottom() newTextBox(fs, name='Caption', parent=redContainer, z=8, fill=color(0, 1, 0), strokeWidth=0.5, stroke=color(1, 1, 0), conditions=[Fit2Width(), Float2SideBottom()], padding=3) score = page.solve() if score.fails: print(score.fails) return doc # Answer the doc for further doing.
def makeSite(viewId): doc = Document(viewId=viewId, autoPages=1) view = doc.view view.resourcePaths = ['js'] view.jsUrls = (URL_JQUERY, URL_MEDIA, 'js/d3.js') # SiteView will automatically generate css/style.scss.css from assumed css/style.scss view.cssUrls = None#('css/normalize.css', 'css/style.scss.css') # Make the single page and elements of the site as empty containers makePage(doc) doc.solve() # Solve all layout and float conditions for pages and elements. return doc
def showFilePaths(): # Get the context that this script runs in, e.g. DrawBotApp. context = getContext('Flat') # Make a Document instance for this size and context, intializing one page. doc = Document(w=W, h=H, originTop=False, autoPages=1, context=context) # Get the page. page = doc[1] # Make a set of conditions for the element positions of this page. c = (Left2Left(), Fit2Right(), Float2Top()) # Find the demo font, as supplied with the PageBot library installation. # This is a subset of TYPETR Upgrade Regular. f = findFont('PageBot-Regular') rootPath = getRootPath() # Location of this PageBot library style = dict(fontSize=14, font=f) msg = 'Root path is %s' % rootPath bs = page.newString(msg, style=style) makeText(bs, page, f, c) resourcesPath = getResourcesPath() msg = 'Resources path is %s' % resourcesPath bs = page.newString(msg, style=style) makeText(bs, page, f, c) #print(glob.glob('%s/*' % resourcesPath)) defaultFontPath = getDefaultFontPath() msg = 'Default font path is %s' % defaultFontPath msg = '\n\t'.join(msg.split('/')) bs = page.newString(msg, style=style) c = (Right2Right(), Float2Top()) e = makeText(bs, page, f, c) e.w = page.pw / 2 - 2 * GUTTER e.mr = 0 msg = 'PageBot font path is %s' % f.path msg = '\n\t'.join(msg.split('/')) bs = page.newString(msg, style=style) c = (Left2Left(), Float2Top()) e = makeText(bs, page, f, c) e.w = page.pw / 2 - 2 * GUTTER # Let the page solve all of its child element layout conditions. page.solve() doc.build()
def makeSpecimen(rs): # 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 template2 doc = Document(rs, autoPages=2) page1 = doc[1] vCube = VariableCube(FONT_PATH, w=500, h=500, s='a', fontSize=86, dimensions=dict(wght=4, rnds=4)) page1.place(vCube, 50, 160) font = getVariableFont(FONT_PATH, location=dict(wght=-0.5, rnds=2, diam=0.5)) page2 = doc[2] for n in range(600): page2.text( FormattedString('@', font=font, fontSize=800, fill=(random(), random(), random(), 0.8)), 50 + random() * 100, 200 + random() * 100) return doc
def testContext(context): doc = Document(w=W, h=H, context=context, autoPages=1) sq = 100 x = 0 y = 0 context.frameDuration(1) context.newDrawing() context.newPage(w=W, h=H) context.fill(f) context.stroke(s) context.translate(3*sq, 2*sq) context.scale(0.1) #context.rect(x, y, pt(sq), pt(sq)) context.circle(x, y, sq) #context.oval(x, y, sq, sq) #context.oval(x, y, sq, 2*sq) #context.oval(x, y, 2*sq, sq) #p0 = (x, y) #p1 = (x + 2*sq, y + sq) #context.line(p0, p1) font = findFont('Roboto-Black') glyphName = 'Q' glyph = font[glyphName] context.drawGlyphPath(glyph) context.translate(-3*sq, -sq) context.scale(3) context.rotate(10) context.rect(x, y, pt(sq), pt(sq)) path = '_export/Transformations-%s.pdf' % context.name context.saveImage(path)
def makeSpecimen(rs): # Template 1 template1 = Template(rs) # Create template of main size. Front page only. # Show grid columns and margins if rootStyle.showGrid or rootStyle.showGridColumns are True template1.grid(rs) # Show baseline grid if rs.showBaselineGrid is True template1.baselineGrid(rs) # 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 template2 doc = Document(rs, autoPages=1, template=template1) page = doc[1] """ for (axis1, axis2), location in AXES_LOCATIONS: vCube = VariationCube(FONT_PATH, w=500, h=500, s='a', fontSize=86, dimensions={axis1:8, axis2:8}, location=location) page.place(vCube, 50, 160) page = doc.newPage() """ vMasterFont = TTFont(FONT_PATH) for c in ((0.2, 0, 0.5), (1, 0, 0), (0, 0.1, 0)): for ix in range(15): for iy in range(15): location = {'line': int(random()*1000), 'open': int(random()*1000), 'rndi': int(random()*1000), 'rndo': int(random()*1000), 'sqri': int(random()*1000), 'sqro': int(random()*1000), 'wght': int(random()*1000)} drawGlyphPath(vMasterFont, 'a', 50 + ix * 500/8, 50 + iy * 500/8, location=location, s=0.09, fillColor=c) #page = doc.newPage() return doc
def makeSpecimen(rs): # Template 1 template1 = Template(rs) # Create template of main size. Front page only. # Show grid columns and margins if rootStyle.showGrid or rootStyle.showGridColumns are True template1.grid(rs) # Show baseline grid if rs.showBaselineGrid is True template1.baselineGrid(rs) # 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 template2 doc = Document(rs, autoPages=2, template=template1) page1 = doc[1] vCube = VariationCube(FONT_PATH, w=500, h=500, s='a', fontSize=86, dimensions=dict(wght=4, rnds=4)) page1.place(vCube, 50, 160) font = getVariationFont(FONT_PATH, location=dict(wght=-0.5, rnds=2, diam=0.5)) page2 = doc[2] for n in range(600): page2.text( FormattedString('@', font=font, fontSize=800, fill=(random(), random(), random(), 0.8)), 50 + random() * 100, 200 + random() * 100) return doc
def makeDocument(rs): # 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(rs, autoPages=1) # Change template of page 1 page = doc[0] glyphName = 'A' angles = {} style = dict(fontSize=FONT_SIZE, labelFont='Verdana', axisNameFontSize=14, valueFontSize=10, axisNameColor=(1, 0, 0)) for axisName in axes: angles[axisName] = globals()[axisName] vc = VariationCircle(varFont, x=M, y=M, w=W - M * 2, h=H - M * 2, s=glyphName, angles=angles, parent=page, style=style, showAxisNames=True) print vc.x, vc.y, vc.h, vc.w return doc
def makeDocument(): # Creates the publication/document that holds the pages. doc = Document(w=W, h=H, originTop=False, autoPages=1) print(doc.view) print(doc.pages) doc.view.padding = 0 # Don't show cropmarks in this example. #doc.margin = doc.view.showPadding = True c1 = [Right2Right(), Float2Top(), Float2Left()] c2 = [Right2Right(), Float2Top()] c3 = [Left2Left()] c4 = [Left2Left(), Float2TopLeft()] c5 = [Right2Right(), Float2TopLeft()] c6 = [Left2Left(), Float2TopRight()] conditions = [c1] #, c2]#, c3, c4, c5, c6] page = doc[1] for c in conditions: makePage(doc, page, c) #page = page.next testCoordinates()
def getDocument(self): """Answer the document that fits the current UI settings.""" w, h = self.getPaperSize() name = self.getDocumentName() padding = self.getPadding() gridX, gridY = self.getGrid(w, h, padding) # Make a new Document instance for export doc = Document(w=w, h=h, autoPages=1, padding=padding, originTop=False, gridX=gridX, gridY=gridY, context=context) view = doc.view view.showCropMarks = showMarks = bool( self.uiDesign.showCropMarks.get()) view.showRegistrationMarks = showMarks view.showNameInfo = showMarks view.showColorBars = bool(self.uiDesign.showColorBars.get()) #view.showBaselineGrid = bool(self.window.group.showBaselineGrid.get()) if bool(self.uiDesign.showGrid.get()): view.showGrid = GRID_COL else: view.showGrid = False view.showPadding = bool(self.uiDesign.showPagePadding.get()) view.showFrame = bool(self.uiDesign.showPageFrame.get()) if showMarks: # Needs padding outside the page? view.padding = pt(48) else: view.padding = 0 return doc
def makeDocument(): # Create new document with (w,h) size and fixed amount of pages. # Note that most of the rootStyle is cascading through the e.css('name') call, # except that values of x, y, z, w, h, d # Just to show here how to get the root style. If not altered, it can be omitted. # as Document( ) will create a RootStyle by default. rootStyle = getRootStyle() doc = Document(rootStyle, originTop=False, w=W, h=H, autoPages=1) page = doc[1] # 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. if RedRect: c = Color(1, 0, 0) else: c = Color(0.5) conditions = (Center2Center(), Middle2Middle()) newRect(fill=c, parent=page, w=RectSize, h=RectSize, 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) # Set the view parameters for the required output. view = doc.getView() view.w = view.h = W, H view.padding = 40 # Make view padding to show crop marks and frame view.showFrame = True # Show frame of the page in blue view.showPadding = False view.showCropMarks = True # Show crop marks view.showOrigin = ShowOrigins # Show origin alignment markers on each element. view.showDimensions = ShowOrigins view.showElementInfo = ShowElementInfo # Show baxes with element info element. return doc
def makeDocument(): # Creates the publication/document that holds the pages. doc = Document(w=W, h=H, originTop=False, autoPages=1) print(doc.view) print(doc.pages) doc.view.padding = 100 # Don't show cropmarks in this example. #doc.margin = doc.view.showPadding = True # Gets page by pageNumber, first in row (at this point there is only one in # this row). page = doc[1] page.padding = 1 page.showPadding = True conditions = [Right2Right(), Float2Top(), Float2Left()] #conditions = [Right2Right(), Float2Top()] #conditions = [Left2Left()] #conditions = [Right2Right()] numberOfSquares = 8 ratio = 1 / numberOfSquares rects = [] for n in range(numberOfSquares): r = newRect(w=40, h=42, mr=4, mt=4, parent=page, fill=color(1 - n * ratio, 0, 0.5), conditions=conditions, margin=0) rects.append(r) score = doc.solve() doc.build() from pagebot import getContext context = getContext() for r in rects: x = r.getFloatLeftSide() + doc.view.pr y = r.getFloatTopSide() + doc.view.pt context.fill((0, 1, 0)) context.circle(x, y, 2)
def makeDocument(families): u"""Create the main document in the defined size with a couple of automatic empty pages.""" # Calculate the amount of pages to create numPages = 1 # Add one page for the original page scan. for family in families: numPages += len(family) # Length of the family is the amount of fonts. numPages = min(numPages, MAX_PAGES - 1) doc = Document(w=W, h=H, title='Variable Font Sample Page', originTop=False, autoPages=numPages, context=context, gridX=GRID_X, gridY=GRID_Y) pn = 1 page = doc[pn] page.ch = 0 # No vertical grid page.padding = PADDING page.gridX = GRID_X newImage(ATF_PATH, x=0, y=0, w=W, parent=page) # Get default view from the document and set the viewing parameters. view = doc.view view.padding = inch( 0.5) # For showing cropmarks and such, make > mm(20) or inch(1). view.showPageCropMarks = True # Won't show if there is not padding in the view. view.showPageFrame = SHOW_FRAMES # No frame in case PAPER_COLOR exists to be shown. view.showPagePadding = SHOW_FRAMES # No frame in case PAPER_COLOR exists to be shown. view.showPageRegistrationMarks = True view.showGrid = SHOW_GRID # Show GRID_X lines view.showPageNameInfo = True # Show file name and date of the document view.showTextOverflowMarker = False # Don't show marker in case Filibuster blurb is too long. # Build the pages for all fonts that include one of these patterns. pn += 1 for family in families[:1]: pn = buildSpecimenPages(doc, family, pn) if pn > MAX_PAGES: break doc.solve() return doc