def initialize(self): u"""Theme styles are created here by inheriting them classes. If srcTheme is not None, start initialize with a copy of that one.""" self.name = self.NAME self[self.ROOT] = getRootStyle() for headName in self.HEADS: self[headName] = getRootStyle() # Make sure there is something there for now.
def init(): DEBUG = False # Make True to see grid and element frames. FONT_PATH = pagebot.getFontPath() #fontPath = FONT_PATH + 'fontbureau/Decovar-VF-chained3.ttf' #fontPath = FONT_PATH + 'fontbureau/Decovar-VF-2axes.subset.ttf' #fontPath = FONT_PATH + 'fontbureau/Decovar-VF-2axes.ttf' fontPath = FONT_PATH + 'fontbureau/Decovar-VF-chained3.ttf' #fontPath = FONT_PATH + 'fontbureau/AmstelvarAlpha-Variations.ttf' fontPath = FONT_PATH + 'PromiseVar.ttf' #fontPath = FONT_PATH + 'BitcountGridVar.ttf' EXPORT_PATH = '_export/'+ fontPath.split('/')[-1].replace('ttf', 'pdf') varFont = Font(fontPath) varFontName = varFont.install() # Do DrawBot font install. axes = varFont.axes print axes RS = getRootStyle() RS['w'] = W = 600 RS['h'] = H = 600 M = 50
def makeRootStyle(self, **kwargs): u"""Create a rootStyle, then set the arguments from **kwargs, if their entry name already exists. This is similar (but not identical) to the makeStyle in Elements. There any value entry is copied, even if that is not defined in the root style.""" rootStyle = getRootStyle() for name, v in kwargs.items(): if name in rootStyle: # Only overwrite existing values. rootStyle[name] = v return rootStyle
def build(self): # Get the PageBot root style, including all default parameters. # Then onlt change the values that are not default. rs = getRootStyle(showGrid=self.showGrid, showGridColumns=self.showGridColumns) rs['language'] = 'en' # Make English hyphenation default. # Create a template for the main page. template = Template( rs) # Create second template. This is for the main pages. # Show grid columns and margins if rootStyle.showGrid or rootStyle.showGridColumns are True. # The grid is just a regular element, like all others on the page. Same parameters apply. template.grid(rs) # Add named text box to template for main specimen text. newTextBox('', 0, 0, 6, 1, parent=template, eId=self.titleBoxId, style=rs) newTextBox('', 2, 1, 4, 6, parent=template, eId=self.specimenBoxId, style=rs) newTextBox('', 0, 1, 2, 6, parent=template, eId=self.infoBoxId, style=rs) # Some lines template.cLine(0, 1, 6, 1, style=rs, stroke=0, strokeWidth=0.25) template.cLine(0, 7, 6, 7, style=rs, stroke=0, strokeWidth=0.25) # Create new document with (w,h) and start with a single page. self.documents['OnePage'] = doc = Document(rs, title=self.title, autoPages=1, template=template) # Make number of pages with default document size. # When building, make all pages default with template. # Call with separate method, so inheriting specimen publications classes can redefine.\ self.buildPage(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(): # 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 rootStyle = getRootStyle() doc = Document(rootStyle, originTop=OriginTop, w=W, h=H, autoPages=1) page = doc[0] # Get the first/single page of the document. page.size = W, H print page.originTop if OriginTop: s = 'Origin on top' conditions = (Center2Center(), Top2Top()) else: s = 'Origin on bottom' conditions = (Center2Center(), Bottom2Bottom()) fs = doc.context.newString(s, style=dict(fontSize=30, textFill=(1, 0, 0), xTextAlign=CENTER)) nt = newText(fs, y=100, xxconditions=conditions, parent=page, fill=(1, 1, 0)) print nt.x, nt.y, nt.w, nt.h score = page.solve() if score.fails: print score.fails print nt.x, nt.y, nt.w, nt.h # Set the view parameters for the required output. view = doc.getView() view.w = view.h = W, H view.padding = 100 # Make view padding to show crop marks and frame view.showPageFrame = True view.showPageCropMarks = True view.showElementOrigin = False view.showElementDimensions = True return doc
FONT_PATH = pagebot.getFontPath() #fontPath = FONT_PATH + 'fontbureau/Decovar-VF-chained3.ttf' #fontPath = FONT_PATH + 'fontbureau/Decovar-VF-2axes.subset.ttf' #fontPath = FONT_PATH + 'fontbureau/Decovar-VF-2axes.ttf' fontPath = FONT_PATH + 'fontbureau/Decovar-VF-chained3.ttf' #fontPath = FONT_PATH + 'fontbureau/AmstelvarAlpha-Variations.ttf' #fontPath = FONT_PATH + 'PromiseVar.ttf' #fontPath = FONT_PATH + 'BitcountGridVar.ttf' EXPORT_PATH = '_export/' + fontPath.split('/')[-1].replace('ttf', 'pdf') varFont = Font(fontPath) varFontName = varFont.install() # Do DrawBot font install. axes = varFont.axes print axes RS = getRootStyle() RS['w'] = W = 600 RS['h'] = H = 600 M = 50 #==================== def makeAxisName(axisName): if not axisName in ('wght', 'wdth', 'opsz'): return axisName.upper() return axisName class VariationCircle(Element): u"""Interpret the content of the self.font variation font and draw a circle info graphic on that info."""
baselineGrid = 2 * U listIndent = 2 * U RS = getRootStyle( u=U, # Page base unit # Basic layout measures altering the default rooT STYLE. w=595, # Om root level the "w" is the page width 210mm, international generic fit. h=11 * 72, # Page height 11", international generic fit. ml=7 * U, # Margin left rs.mt = 7*U # Margin top baselineGrid=14, #baselineGrid, gw=2 * U, # Generic gutter, equal for width and height gd=2 * U, # Column width. Uneven means possible split in 5+1+5 or even 2+1+2 +1+ 2+1+2 # 11 is a the best in that respect for column calculation. cw=11 * U, ch=6 * baselineGrid - U, # Approx. square and fitting with baseline. listIndent=listIndent, # Indent for bullet lists listTabs=[(listIndent, LEFT)], # Match bullet+tab with left indent. # Display option during design and testing showGrid=SHOW_GRID, showGridColumns=SHOW_GRID_COLUMNS, showBaselineGrid=SHOW_BASELINE_GRID, showFlowConnections=SHOW_FLOW_CONNECTIONS, BOX_COLOR=BOX_COLOR, # Text measures leading=14, rLeading=0, fontSize=9) RS['language'] = 'nl-be' # Make Dutch hyphenation. MD_PATH = 'testPaginaCompositie_nl.md' EXPORT_PATH = 'export/TestPaginaOpmaak.pdf'
# The standard PageBot function getRootStyle() answers a standard Python # dictionary, where all PageBot values are filled by their default values. # The root style is kept in RS as reference to for all ininitialzaiton # of elements. # # Each element uses the root style as copy and then modifies the values # it needs. Note that the use of style dictionaries is fully recursive # in PageBot, implementing a cascading structure that is very similar # to what happens in CSS. RS = getRootStyle(w=W, h=H, pl=64, pt=64, pr=64, pb=80, docW=docW, docH=docH, showElementInfo=False, showElementOrigin=True, originTop=True) # Export in folder that does not commit to Git. Force to export PDF. EXPORT_PATH = '_export/ABookCover.pdf' def makeDocument(rootStyle): u"""Demo random book cover generator.""" # Create new document with (w,h) and fixed amount of pages. # Make number of pages with default document size.
from pagebot.style import getRootStyle from pagebot.contexts import defaultContext as context rs = getRootStyle() rs['leading'] = 10 rs['fontSize'] = 9 rs['font'] = 'Verdana' fs = context.newString('aaa', None, rs) a = context.newString('', style=dict(lineHeight=rs['leading'], fontSize=rs['fontSize'], font='Verdana')) for n in range(100): a += 'AAA%s\n' % n fs += 'RS%s\n' % n fs += context.newString('SSSS', style=dict(fontSize=18, lineHeight=20)) fs += context.newString('DDDD\n', style=dict(fontSize=9, lineHeight=10)) stroke(0) strokeWidth(0.5) line((10, n * rs['leading']), (500, n * rs['leading'])) print textBox(a, (10, 10, 300, 800)) print textBox(fs, (320, 10, 300, 800))
PageNameInfo = True ViewPadding = 64 PageSize = 500 GUTTER = 8 # Distance between the squares. SQUARE = 10 * GUTTER # Size of the squares # The standard PageBot function getRootStyle() answers a standard Python dictionary, # where all PageBot style entries are filled by their default values. The root style is kept in RS # as reference for the ininitialization of all elements. # Each element uses the root style as copy and then modifies the values it needs. # Note that the use of style dictionaries is fully recursive in PageBot, implementing a cascading structure # that is very similar to what happens in CSS. RS = getRootStyle(w=PageSize, h=PageSize) # Setting value for demo purpose, it is style default, using the elements origin as top-left. # Change to False will show origin of elements in their bottom-left corner. if 0: # TOP RS['originTop'] = True RS['yAlign'] = TOP else: RS['originTop'] = False RS['yAlign'] = BOTTOM #for key, value in RS.items(): # print key, value EXPORT_PATH = '_export/ColorSquares.pdf' # Export in _export folder that does not commit in Git. Force to export PDF. def makeDocument(rs):
PB = 100 # The standard PageBot function getRootStyle() answers a standard Python dictionary, # where all PageBot values are filled by their default values. The root style is kept in RS # as reference to for all ininitialzaiton of elements. # Each element uses the root style as copy and then modifies the values it needs. # Note that the use of style dictionaries is fully recursive in PageBot, implementing a cascading structure # that is very similar to what happens in CSS. RS = getRootStyle( w=W, h=H, pl=PL, # Padding of page. pt=PT, pr=PR, pb=PB, conditions=[], fontSize=10, rLeading=0, showElementInfo=False, originTop=True, hyphenation=False, ) EXPORT_PATH = '_export/ConditionalElements.pdf' # Export in folder that does not commit un Git. Force to export PDF. def makeDocument(rootStyle): u"""Demo page composer.""" # Create new document with (w,h) and fixed amount of pages. # Make number of pages with default document size.
# on initialization, so we don't that to replace them later for our version of the # root style. RS = getRootStyle( u=U, # Page base unit # Basic layout measures altering the default rooT STYLE. w=595, # Om root level the "w" is the page width 210mm, international generic fit. h=11 * 72, # Page height 11", international generic fit. ml=7 * U, # Margin left rs.mt = 7*U # Margin top baselineGrid= baselineGrid, # Set the baseline grid, as shown when SHOW_BASELINE_GRID is True. gw=2 * U, # Generic gutter, equal for width and height gh=2 * U, # Column width. Uneven means possible split in 5+1+5 or even 2+1+2 +1+ 2+1+2 # 11 is a the best in that respect for column calculation. cw=11 * U, ch=6 * baselineGrid - U, # Approx. square and fitting with baseline. listIndent=listIndent, # Indent for bullet lists listTabs=[(listIndent, LEFT)], # Match bullet+tab with left indent. # Display option during design and testing. Pass the debug paramers into the root style. showGrid=SHOW_GRID, showGridColumns=SHOW_GRID_COLUMNS, showBaselineGrid=SHOW_BASELINE_GRID, showFlowConnections=SHOW_FLOW_CONNECTIONS, BOX_COLOR=BOX_COLOR, # Text measures leading= baselineGrid, # Basic leading of body text as fixed value (indepdent of font size) to 2 x U = 14. rLeading=0, # Set relative leading (dependent on font size) to 0. fontSize=U + 2 # Set default font size of body text to U + 2 = 9 pt. ) if 0: # In case an English MarkDown text of this example article is ready.