def __init__(self, fontpath, point=None, parent=None, style=None, name=None, eId=None, captionStyle=None, caption=None, clipRect=None, mask=None, imo=None, **kwargs): Element.__init__(self, point=point, parent=parent, style=style, name=name, eId=eId, **kwargs) self.font = fontpath self.eId = eId self.style = makeStyle(style, **kwargs) # Combine self.style from # Try to figure out the requested dimensions if the element display per axes. if dimensions is None: dimensions = dict(wght=5, wdth=5, opsz=5) self.dimensions = dimensions # Each element should check at this point if the minimum set of style values # are set and if their values are valid. assert self.w is not None and self.h is not None # Make sure that these are defined. # Make sure that this is a formatted string. Otherwise create it with the current style. # Note that in case there is potential clash in the double usage of fill and stroke. # FIXME: Review this: the 's' variable below is undefined. #self.glyphNames = s or 'e' self.glyphNames = 'e' # Store the external location, to allow other axis values to be set. if location is None: location = {} self.location = copy(location)
def __init__(self, leftPage=None, rightPage=None, **kwargs): u"""Add specific parameters for a page, besides the parameters for standard Elements. """ Element.__init__(self, **kwargs) self.leftPage = leftPage # Force left/right side of a page, independen of document odd/even. self.rightPage = rightPage self.class_ = self.class_ or 'page' # Defined default CSS class for pages.
def __init__(self, w=None, h=None, contect=None, parent=None, context=None, verbose=False, **kwargs): Element.__init__(self, parent=parent, **kwargs) if not w and self.parent: w = self.parent.w if not h and self.parent: h = self.parent.h self.w = w self.h = h self.verbose = verbose # If set to Trye, views may decide to add more information while building. if context is None: context = self._getContext( ) # Use the default context for this view, if not defined. self.context = context self._initializeControls() self.setControls() # List of collected elements that need to draw their info on top of the main drawing, self.elementsNeedingInfo = {} self._isDrawn = False # Automatic call self.drawPages if build is called without drawing.
def __init__(self, bs=None, minW=None, w=None, h=None, size=None, **kwargs): Element.__init__(self, **kwargs) """Creates a TextBox element. Default is the storage of `self.s`. (DrawBot FormattedString or Flat equivalent), but optional it can also be ts (tagged str) if output is mainly through build and HTML/CSS. Since both strings cannot be converted lossless one into the other, it is safer to keep them both if they are available.""" # Make sure that this is a formatted string. Otherwise create it with # the current style. Note that in case there is potential clash in the # double usage of fill and stroke. self._textLines = self._baselines = None # Force initiaize upon first usage. if size is not None: self.size = size else: self.size = w or DEFAULT_WIDTH, h # If h is None, height is elastic size if bs is None: # If not defined, initialize as empty string (to avoid display of "None") bs = '' self.bs = self.newString( bs, style=self.style ) # Source can be any type: BabelString instance or plain unicode string.
def __init__(self, w=None, h=None, contect=None, parent=None, context=None, verbose=False, **kwargs): Element.__init__(self, parent=parent, **kwargs) if not w and self.parent: w = self.parent.w if not h and self.parent: h = self.parent.h self.w = w self.h = h # If set to True, views may decide to add more information while # building. self.verbose = verbose if context is None: raise ValueError('Missing context for view "%s"' % self) self.context = context # Set the self._context property. #if context is not None: # self.context.setSize(self.w, self.h) # Optionally implemented by inheriting view classes to preset parameters. self.setControls() # List of collected elements that need to draw their info on top of the # main drawing. self.elementsNeedingInfo = {} # Automatically call self.drawPages if build is called without drawing. self._isDrawn = False
def __init__(self, font, s=None, draw3D=True, location=None, showAxisNames=True, markerRadius=None, labelFont=None, labelFontSize=None, axisNameFontSize=None, **kwargs): Element.__init__(self, **kwargs) # Initialize the default Element behavior tags. self.vfFont = font if labelFont is None: labelFont = font self.labelFont = labelFont if axisNameFontSize is None: axisNameFontSize = self.fontSize self.axisNameFontSize = axisNameFontSize self.labelFontSize = labelFontSize or pt(12) self.glyphNames = s or 'e' self.draw3D = draw3D # TODO: Draw as 3D structure of spheres and needles/spikes. self.location = location # Use to visualize a specific location, otherwise all needles are at min value. self.showAxisNames = showAxisNames self.markerRadius = markerRadius or self.MARKER_RADIUS self.angles = {} if self.vfFont.axes: aIndex = 0 da = 180/len(self.vfFont.axes) for axis, (minValue, defaultValue, maxValue) in sorted(self.vfFont.axes.items()): minAngle = maxAngle = None if minValue != defaultValue: minAngle = aIndex * da if maxValue != defaultValue: maxAngle = aIndex * (da+180) self.angles[axis] = minAngle, maxAngle aIndex += 1 print(self.angles)
def __init__(self, date=None, **kwargs): if date is None: date = now() self.date = date self.calendarMonth = date.calendarMonth Element.__init__(self, **kwargs)
def __init__(self, points=None, closed=True, **kwargs): if points is None: points = [] # Force copy, so calling function can't change size cache. self.points = points[:] self.closed = closed Element.__init__(self, **kwargs)
def __init__(self, path, name=None, w=None, h=None, size=None, z=0, clipRect=None, clipPath=None, mask=None, imo=None, index=1, **kwargs): Element.__init__(self, **kwargs) # Initialize the self.im and self.ih sizes of the image file, defined by path. # If the path does not exist, then self.im = self.ih = pt(0) self.setPath(path) # If path is omitted or file does not exist, a gray/crossed rectangle will be drawn. self.initImageSize() # One of the two needs to be defined, the other can be None. # If both are set, then the image scales disproportional. if size is None and w is None and h is None: # Set size to original proportions in the file self.size = None elif size is not None: # Disproportional scaling if both are not None or reset to 100% with (None, None) self.size = size elif w is not None and h is not None: # Disproportional scaling self.size = w, h elif w is not None: # Separate settings, to keep proportions if only one it set. self.w = w # Sets self._h to None to indicate that width is the lead. elif h is not None: self.h = h # Sets self._w to None to indicate that height is the lead. self.z = z # Make conditions work with captions inside an image frame element. self.name = name self.mask = mask # Optional mask element. self.clipRect = clipRect # Optional clip rectangle in local coordinate and size. self.clipPath = clipPath # Optional clip path. self.imo = imo # Optional ImageObject with filters defined. See http://www.drawbot.com/content/image/imageObject.html self.index = index # In case there are multiple images in the file (e.g. PDF), use this index. Default is first = 1
def __init__(self, path=None, name=None, w=None, h=None, size=None, z=0, mask=None, imo=None, index=1, saveScaled=True, **kwargs): Element.__init__(self, **kwargs) # Initialize the self.im and self.ih sizes of the image file, defined by path. # If the path does not exist, then self.im = self.ih = pt(0) self.path = path # If path is omitted or file does not exist, a gray/crossed rectangle will be drawn. self.initImageSize() # One of the two needs to be defined, the other can be None. # If both are set, then the image scales disproportional. if size is None and w is None and h is None: # Set size to original proportions in the file self.size = None elif size is not None: # Disproportional scaling if both are not None or reset to 100% with (None, None) self.size = size elif w is not None and h is not None: # Disproportional scaling self.size = w, h elif w is not None: # Separate settings, to keep proportions if only one it set. self.w = w # Sets self._h to None to indicate that width is the lead. elif h is not None: self.h = h # Sets self._w to None to indicate that height is the lead. self.z = z # Make conditions work with captions inside an image frame element. self.name = name self.mask = mask # Optional mask element. self.imo = imo # Optional ImageObject with filters defined. See http://www.drawbot.com/content/image/imageObject.html self.index = index # In case there are multiple images in the file (e.g. PDF), use this index. Default is first = 1 # If True (default), then save the image to a scaled version in _scaled/<fileName> and alter self.path name to scaled image. # Do not scale the image, if the cache file already exists. If False, then not scaled cache is created. self.saveScaled = saveScaled
def __init__(self, path, name=None, w=None, h=None, z=0, clipRect=None, clipPath=None, mask=None, imo=None, **kwargs): Element.__init__(self, **kwargs) # One of the two needs to be defined, the other can be None. # If both are set, then the image scales disproportional. self.w = w self.h = h self.z = z # Make conditions work with captions inside the image frame element. self.name = name self.mask = mask # Optional mask element. self.clipRect = clipRect # Optional clip rectangle self.clipPath = clipPath # Optional clip path. self.imo = imo # Optional ImageObject with filters defined. See http://www.drawbot.com/content/image/imageObject.html self.setPath( path ) # If path is omitted, a gray/crossed rectangle will be drawn.
def __init__(self, path=None, style=None, pixelMap=None, name=None, title=None, caption=None, clipRect=None, mask=None, imo=None, w=None, h=None, imageConditions=None, titleConditions=None, captionConditions=None, conditions=None, **kwargs): self.image = None # Aviud setting of self.omage.w and self.omage.h while not initialized. Element.__init__(self, w=w, h=h, name=name, conditions=conditions, **kwargs) assert path is None or pixelMap is None # One or the other or both None. if title is not None: # Only make title element if defined content. if titleConditions is None: titleConditions = (Top2TopSide(), Fit2Width()) title = TextBox(title, style=style, conditions=titleConditions) # If defined, title can be any type of element, but most likely a text box. Other wise None self.title = title # Property to add to self.elements and set caption.parent to self. if imageConditions is None: imageConditions = (Float2TopSide(), Fit2Width()) if pixelMap is None: # Path can be None or non-existing, making PixelMap show gray rectangle of missing image. pixelMap = PixelMap(path, name='PixelMap', clipRect=clipRect, mask=mask, imo=imo, w=w, h=h, conditions=imageConditions, **kwargs) # Default width is leading. self.image = pixelMap # Property to add to self.elements and set pixelMap.parent to self. if caption is not None: # Only make caption element if defined content if captionConditions is None: captionConditions = (Float2TopSide(), Fit2Width()) caption = TextBox(caption, style=style, conditions=captionConditions) # Caption can be any type of element, but most likely a text box. self.caption = caption # Property to add to self.elements and set caption.parent to self. # Solve the optional conditions defined in title, pixelMap and caption. self.solve()
def __init__(self, points, **kwargs): #print(points) #print(kwargs) if points is None: points = [] self.points = points[:] # Force copy, so caller cannot change and not change size cache. Element.__init__(self, **kwargs)
def __init__(self, **kwargs): Element.__init__(self, **kwargs) # Make sure that this is a formatted string. Otherwise create it with # the current style. # Note that in case there is potential clash in the # double usage of fill and stroke (?) self.lastTextBox = None
def __init__(self, paths, **kwargs): if paths is None: paths = [] elif not isinstance(paths, (tuple, list)): paths = [paths] # Create an ordered list of PageBotPath instances self.paths = paths for path in paths: assert isinstance(path, self.PATH_CLASS) Element.__init__(self, **kwargs)
def __init__(self, colNames=None, cols=1, rows=1, fillHeader=0.8, **kwargs): Element.__init__(self, **kwargs) # Make the column/row/cell dictionary self.initCells(colNames, cols, rows, fillHeader)
def __init__(self, callback=None, minW=None, maxW=None, minH=None, maxH=None, closable=None, **kwargs): Element.__init__(self, closable=None, **kwargs) self.callback = callback self.minW = minW or 1 self.maxW = maxW or XXXL self.minH = minH or 1 self.maxH = maxH or XXXL if closable is None: closable = True self.closable = closable
def __init__(self, path, clipPath=None, pathFill=None, mask=None, imo=None, **kwargs): Element.__init__(self, **kwargs) """The Image element is the container for a single ImageData instance. Since the it is implemented as a normal child element, all operations (such as layout conditions) can be performed on the combination. There also is a property self.imageData to find the image data element directly. """ self.imageData = ImageData(path, parent=self, imo=imo) self.clipPath = clipPath self.pathFill = pathFill or noColor self.mask = mask
def __init__(self, path, name=None, x=0, y=0, w=None, h=None, imo=None, **kwargs): Element.__init__(self, **kwargs) self.path = path self.name = name self.imo = imo # Optional ImageObject (or other context equivalent) as used by DrawBot. self.x = x self.y = y self._iw = self._ih = None # Size from image file initialized by property upon request. self._w = w # Unless defined, the properties will copy from self._iw or parent.w self._h = h self.pn = 1
def __init__(self, w=None, h=None, parent=None, **kwargs): Element.__init__(self, parent=parent, **kwargs) if not w and self.parent: w = self.parent.w if not h and self.parent: h = self.parent.h self.w = w self.h = h self._initializeControls() self.setControls() # List of collected elements that need to draw their info on top of the main drawing, self.elementsNeedingInfo = {} self._isDrawn = False # Automatic call self.drawPages if export is called without drawing.
def __init__(self, fill=None, name=None, drawAfter=None, **kwargs): if fill is None: fill = self.DEFAULT_FILL if name is None: name = 'Unnamed Placer' if drawAfter is None: drawAfter = self._drawNameLabel Element.__init__(self, fill=fill, name=name, drawAfter=drawAfter, **kwargs)
def __init__(self, font, s=None, draw3D=True, location=None, showAxisNames=True, **kwargs): Element.__init__(self, **kwargs) # Initialize the default Element behavior tags. self.font = font self.glyphNames = s or 'e' self.draw3D = draw3D # TODO: Draw as 3D structure of spheres and needles/spikes. self.location = location # Use to visualize a specific location, otherwise all needles are at min value. self.showAxisNames = showAxisNames
def __init__(self, bs=None, minW=None, w=DEFAULT_WIDTH, h=None, showBaselines=False, **kwargs): Element.__init__(self, **kwargs) u"""Creates a TextBox element. Default is the storage of self.s (DrawBot FormattedString or Flat equivalent), but optional it can also be ts (tagged basestring) if output is mainly through build and HTML/CSS. Since both strings cannot be conversted lossless one into the other, it is safer to keep them both if they are available. """ # Make sure that this is a formatted string. Otherwise create it with the current style. # Note that in case there is potential clash in the double usage of fill and stroke. self.minW = max(minW or 0, MIN_WIDTH, self.TEXT_MIN_WIDTH) self._textLines = self._baseLines = None # Force initiaize upon first usage. self.size = w, h self.bs = self.newString(bs) # Source can be any type: BabelString instance or plain unicode string. self.showBaselines = showBaselines # Force showing of baseline if view.showBaselines is False.
def __init__(self, fill=None, conditions=None, **kwargs): Element.__init__(self, **kwargs) # Make sure that this is a formatted string. Otherwise create it with # the current style. #if fill is None: # Set default Galley color if not defined. # fill = self.OLD_PAPER_COLOR self.fill = fill or noColor if conditions is None: conditions = [Fit(), Overflow2Next()] self.conditions = conditions e = self.TEXTBOX_CLASS(conditions=[Fit()], parent=self) # First textbox on the Galley self.appendElement(e) # Attach it to the galley self.
def __init__(self, leftPage=None, rightPage=None, htmlCode=None, htmlPath=None, headCode=None, headPath=None, bodyCode=None, bodyPath=None, cssCode=None, cssPath=None, cssUrls=None, jsCode=None, jsPath=None, jsUrls=None, viewPort=None, favIconUrl=None, fileName=None, url=None, webFontUrls=None, **kwargs): u"""Add specific parameters for a page, besides the parameters for standard Elements. >>> page = Page() >>> page.w, page.h (100, 100) >>> page.w = 1111 >>> page.w, page.h (1111, 100) """ Element.__init__(self, **kwargs) self.cssClass = self.cssClass or 'page' # Defined default CSS class for pages. self._isLeft = leftPage # Undefined if None, let self.doc decide instead self._isRight = rightPage # Site stuff self.viewPort = viewPort or self.VIEW_PORT self.appleTouchIconUrl = None self.favIconUrl = favIconUrl or self.FAVICON_PATH self.fileName = fileName or self.INDEX_HTML self.url = url or self.INDEX_HTML_URL # Used for links to home or current page url # Optional resources to be included # Define string or file paths where to read content, instead of constructing by the builder. self.htmlCode = htmlCode # Set to string in case the full HTML is defined in a single file. self.htmlPath = htmlPath # Set to string in case the full HTML is defined in a single file. self.headCode = headCode # Optional set to string that contains the page <head>...</head>, excluding the tags. self.headPath = headPath # Set to path, if head is available in a single file, excluding the tags. self.cssCode = cssCode # Set to string, if CSS is available as single source. Exported as css file once. self.cssPath = cssPath # Set to path, if CSS is available in a single file to be included in the page. self.cssUrls = cssUrls # Optional CSS, if different from what is defined by the view. self.bodyCode = bodyCode # Optional set to string that contains the page <body>...</body>, excluding the tags. self.bodyPath = bodyPath # Set to path, if body is available in a single file, excluding the tags. self.jsCode = jsCode # Set to path, if JS is available in a single file, excluding the tags. self.jsPath = jsPath # Optional javascript, to be added at the end of the page, inside <body>...</body> tag. self.jsUrls = jsUrls # Optional Javascript Urls, if different from what is defined by the view. self.webFontUrls = webFontUrls # Optional set of webfont urls if different from what is in the view.
def __init__(self, path=None, style=None, pixelMap=None, title=None, caption=None, clipRect=None, mask=None, imo=None, w=None, h=None, imageConditions=None, conditions=None, **kwargs): self.image = None # Aviud setting of self.omage.w and self.omage.h while not initialized. Element.__init__(self, w=w, h=h, conditions=conditions, **kwargs) assert path is None or pixelMap is None # One or the other or both None. if imageConditions is None: imageConditions = (Top2TopSide(), Fit2Width()) if pixelMap is None: # Path can also be None, making PixelMap show gray rectangle of missing image. pixelMap = PixelMap(path, name='PixelMap', clipRect=clipRect, mask=mask, imo=imo, w=w, h=h, conditions=imageConditions, **kwargs) # Default width is leading. self.image = pixelMap # Property to add to self.elements and set pixelMap.parent to self. # Title can be any type of element, but most likely a text box. self.title = title # Property to add to self.elements and set caption.parent to self. # Caption can be any type of element, but most likely a text box. self.caption = caption # Property to add to self.elements and set caption.parent to self. self.solve() # Solve the optional conditions defined in pixelMap and caption.
def __init__(self, folds=None, startPage=None, **kwargs): Element.__init__(self, **kwargs) if folds is None: # Default is single page. E.g. (2, 1) would be a spread, etc. # Types of Quire formats, how to compose pages # QUIRE_SINGLE = (1, 1) # QUIRE_SPREAD = (-2, 1) # Spread of 2 connected pages, without gutter for crop-marks or bleed # QUIRE_2x2 = (2, 2) # is a Quire of 4 pages, e.g. to be cut as separate sheets # QUIRE_8x4 = (8, 4) # is a Quire of 32 separate pages, e.g. to be cut as 32 business cards. # QUIRE_LEPARELLO3 = (-3, 1) # is a leparello of 3 connected pages. # QUIRE_LEPARELLO4 = (-4, 1) # is a leparello of 4 connected pages. # QUIRE_FOLIO = (QUIRE_SPREAD, 2) # 2o, a Quire of 2 spreads # QUIRE_QUARTO = (2, QUIRE_FOLIO) # 4o # QUIRE_OCTAVO = (QUIRE_QUARTO, 2) # 8o, folding into 16 pages folds = QUIRE_SINGLE # 1, 1 self.folds = folds self.startPage = startPage or 1
def __init__(self, folds=None, **kwargs): Element.__init__(self, **kwargs) if folds is None: # Default is single page. E.g. (2, 1) would be a spread, etc. # Types of Quire formats, how to compose pages # The gap between the pages is defined by page.margin values # QUIRE_SINGLE = (1, 1) # QUIRE_SPREAD = (2, 1) # Spread of 2 connected pages, without gutter for crop-marks or bleed # QUIRE_2x2 = (2, 2) # is a Quire of 4 pages, e.g. to be cut as separate sheets # QUIRE_8x4 = (8, 4) # is a Quire of 32 separate pages, e.g. to be cut as 32 business cards. # QUIRE_LEPARELLO3 = (3, 1) # is a leparello of 3 connected pages. # QUIRE_LEPARELLO4 = (4, 1) # is a leparello of 4 connected pages. # QUIRE_FOLIO = (QUIRE_SPREAD, 2) # 2°, a Quire of 2 spreads # QUIRE_QUARTO = (2, QUIRE_FOLIO) # 4° # QUIRE_OCTAVO = (QUIRE_QUARTO, 2) # 8°, folding into 16 pages folds = QUIRE_SINGLE # 1, 1 self.piw, self.pih = self.folds = folds # Split value of page-index-width and page-index-height self.pages = {}
def __init__(self, s=None, style=None, sizeX=5, sizeY=5, recipeAxes=None, designSpace=None, locations=None, **kwargs): Element.__init__(self, **kwargs) self.style = makeStyle(style, **kwargs) # Combine self.style from self.sizeX = sizeX self.sizeY = sizeY # Ordered name list of axes to show in legenda. Ignore if None. self.recipeAxes = recipeAxes self.designSpace = designSpace or {} self.locations = locations # Each element should check if the minimum set of style values are set # and if their values are valid at this point. assert self.w is not None and self.h is not None # Make sure that these are defined. # Makes sure that this is a formatted string. Otherwise creates it with # the current style. Note that in case there is potential clash in the # duplicate usage of fill and stroke. self.glyphNames = s or 'e'
def __init__(self, document, docCacheType=None, pn=None, **kwargs): """Store document, to by used as background drawing for self. Note that as with any Element, child elements can be added for display. >>> from pagebot.document import Document >>> from pagebot.elements import * >>> from pagebot.contexts import getContext >>> context = getContext() >>> doc1 = Document(name='Placed Document', w=300, h=400, context=context) >>> page = doc1[1] >>> e = Rect(parent=page, fill='red') >>> doc2 = Document(name='Canvas Document', context=context) >>> page = doc2[1] >>> e = DocWrap(doc1, parent=page, x=100, y=200, fill=0.5) >>> doc2.export('_export/ExampleDocWrap.pdf') """ Element.__init__(self, **kwargs) assert document is not self.doc # Make sure there is not circular reference. self.wrappedDocument = document self.docCacheType = docCacheType # TODO: Currently not used. self.pn = pn or 1 # In case a specific page is selected.