def drawCropMarks(context, origin, w, h, bleed, cmSize, cmStrokeWidth, folds=None): """If the show flag is set, then draw the cropmarks or page frame. >>> from pagebot.toolbox.units import pt >>> from pagebot import getContext >>> context = getContext('Flat') >>> context.newPage(pt(100), pt(100)) >>> drawCropMarks(context, pt(0,0), pt(100), pt(100), False, pt(20), pt(1)) """ x, y, _ = point3D(origin) # Ignore z-axus for now. context.fill(noColor) context.stroke(color(cmyk=(1, 1, 1, 1)), w=cmStrokeWidth) context.newPath() # Bottom left context.moveTo((x - bleed, y)) context.lineTo((x - cmSize, y)) context.moveTo((x, y - bleed)) context.lineTo((x, y - cmSize)) # Bottom right context.moveTo((x + w + bleed, y)) context.lineTo((x + w + cmSize, y)) context.moveTo((x + w, y - bleed)) context.lineTo((x + w, y - cmSize)) # Top left context.moveTo((x - bleed, y + h)) context.lineTo((x - cmSize, y + h)) context.moveTo((x, y + h + bleed)) context.lineTo((x, y + h + cmSize)) # Top right context.moveTo((x + w + bleed, y + h)) context.lineTo((x + w + cmSize, y + h)) context.moveTo((x + w, y + h + bleed)) context.lineTo((x + w, y + h + cmSize)) # Any fold lines to draw? if folds is not None: for fx, fy in folds: if fx is not None: context.moveTo((x + fx, y - bleed)) context.lineTo((x + fx, y - cmSize)) context.moveTo((x + fx, y + h + bleed)) context.lineTo((x + fx, y + h + cmSize)) if fy is not None: context.moveTo((x - bleed, y + fy)) context.lineTo((x - cmSize, y + fy)) context.moveTo((x + w + bleed, y + fy)) context.lineTo((x + w + cmSize, y + fy)) context.drawPath()
def drawRegistrationMarks(context, origin, w, h, cmSize, cmStrokeWidth): """Draw standard registration mark, to show registration of CMYK colors. https://en.wikipedia.org/wiki/Printing_registration. >>> from pagebot.toolbox.units import pt >>> from pagebot import getContext >>> context = getContext('Flat') >>> context.newPage(pt(100), pt(100)) >>> drawRegistrationMarks(context, pt(0,0), pt(100), pt(100), pt(20), pt(1)) """ x, y, _ = point3D(origin) drawRegistrationMark(context, (x + w / 2, y - cmSize), cmSize, cmStrokeWidth, False) # Bottom registration mark drawRegistrationMark(context, (x - cmSize, y + h / 2), cmSize, cmStrokeWidth, True) # Left registration mark drawRegistrationMark(context, (x + w + cmSize, y + h / 2), cmSize, cmStrokeWidth, True) # Right registration mark drawRegistrationMark(context, (x + w / 2, y + h + cmSize), cmSize, cmStrokeWidth, False) # Top registration mark
def __init__(self, styles=None, theme=None, viewId=None, name=None, title=None, pages=None, autoPages=1, template=None, templates=None, originTop=True, startPage=None, w=None, h=None, d=None, size=None, padding=None, lib=None, context=None, exportPaths=None, **kwargs): """Contains a set of Page elements and other elements used for display in thumbnail mode. Used to compose the pages without the need to send them directly to the output for asynchronous page filling.""" if size is not None: # For convenience of the caller, also accept size tuples. w, h, d = point3D(size) # Apply the theme if defined or create default styles, to make sure they are there. self.rootStyle = rs = self.makeRootStyle(**kwargs) self.initializeStyles( theme, styles) # May or may not overwrite the root style. self.name = name or title or 'Untitled' self.title = title or self.name self.originTop = originTop # Set as property in rootStyle and also change default rootStyle['yAlign'] to right side. self.w = w or DEFAULT_DOC_WIDTH # Always needs a value. Take 1000 if 0 or None defined. self.h = h or DEFAULT_DOC_HEIGHT # These values overwrite the self.rootStyle['w'] and self.rootStyle['h'] self.d = d # In case depth is 0, keep is as value if padding is not None: self.padding = padding # Initialize the dictionary of pages. self.pages = { } # Key is pageNumber, Value is row list of pages: self.pages[pn][index] = page for page in pages or []: # In case there are pages defined on init, add them. self.appendPage(page, startPage) # Initialize the current view of this document. All conditional # checking and building is done through this view. The defaultViewClass # is set either to an in stance of PageView. self.views = {} # Key is the viewId. Value is a view instance. # Set the self.view to an instance of viewId or defaultViewClass.viewId # and store in self.views. Add the optional context, if defined. # Otherwise use the result of default getContext. A context is an # instance of e.g. one of DrawBotContext, FlatContext or HtmlContext, # which then hold the instance of a builder (respectively DrawBot, Flat # and one of the HtmlBuilders, such as GitBuilder or MampBuilder) self.newView(viewId or self.DEFAULT_VIEWID, context=context) # Template is name or instance default template. self.initializeTemplates(templates, template) # Property self.lib for storage of collected content while typesetting # and composing, referring to the pages they where placed on during # composition. The lib can optionally be defined when constructing # self. if lib is None: lib = {} self._lib = lib # Document (w, h) size is default from page, but will modified by the type of display mode. if autoPages: self.makePages(pageCnt=autoPages, pn=startPage, w=self.w, h=self.h, d=self.d, **kwargs) # Call generic initialize method, allowing inheriting publication # classes to initialize their stuff. This can be the creation of # templates, pages, adding/altering styles and view settings. Default # is to do nothing. self.initialize(**kwargs)
def _set_size(self, size): if size is None: # Reset to original size by single None value. size = None, None, None self._w, self._h, self.d = point3D(size)