def setStrokeColor(c, w=1, fs=None, cmyk=False): u"""Set global stroke color or the color of the formatted string.""" if c is NO_COLOR: pass # Color is undefined, do nothing. elif c is None or isinstance( c, (float, long, int)): # Because None is a valid value. if cmyk: if fs is None: cmykStroke(c) else: fs.cmykStroke(c) else: if fs is None: stroke(c) else: fs.stroke(c) elif isinstance(c, (list, tuple)) and len(c) in (3, 4): if cmyk: if fs is None: cmykStroke(*c) else: fs.cmykStroke(*c) else: if fs is None: stroke(*c) else: fs.stroke(*c) else: raise ValueError('Error in color format "%s"' % c) if w is not None: strokeWidth(w)
def drawPageCropMarks(self, e, origin): u"""If the show flag is set, then draw the cropmarks or page frame.""" if self.showPageCropMarks: x, y, _ = point3D(origin) # Ignore z-axus for now. w, h = e.w, e.h folds = self.css('folds') bleed = self.css('bleed') / 2 # 1/2 overlap with image bleed cmSize = min(self.css('viewCropMarkSize', 32), self.pl) cmStrokeWidth = self.css('viewCropMarkStrokeWidth') fill(None) cmykStroke(1, 1, 1, 1) strokeWidth(cmStrokeWidth) newPath() # Bottom left moveTo((x - bleed, y)) lineTo((x - cmSize, y)) moveTo((x, y - bleed)) lineTo((x, y - cmSize)) # Bottom right moveTo((x + w + bleed, y)) lineTo((x + w + cmSize, y)) moveTo((x + w, y - bleed)) lineTo((x + w, y - cmSize)) # Top left moveTo((x - bleed, y + h)) lineTo((x - cmSize, y + h)) moveTo((x, y + h + bleed)) lineTo((x, y + h + cmSize)) # Top right moveTo((x + w + bleed, y + h)) lineTo((x + w + cmSize, y + h)) moveTo((x + w, y + h + bleed)) 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: moveTo((x + fx, y - bleed)) lineTo((x + fx, y - cmSize)) moveTo((x + fx, y + h + bleed)) lineTo((x + fx, y + h + cmSize)) if fy is not None: moveTo((x - bleed, y + fy)) lineTo((x - cmSize, y + fy)) moveTo((x + w + bleed, y + fy)) lineTo((x + w + cmSize, y + fy)) drawPath()
def drawCropMarks(origin, w, h, bleed, cmSize, cmStrokeWidth, folds=None): u"""If the show flag is set, then draw the cropmarks or page frame.""" x, y, _ = point3D(origin) # Ignore z-axus for now. fill(None) cmykStroke(1, 1, 1, 1) strokeWidth(cmStrokeWidth) newPath() # Bottom left moveTo((x - bleed, y)) lineTo((x - cmSize, y)) moveTo((x, y - bleed)) lineTo((x, y - cmSize)) # Bottom right moveTo((x + w + bleed, y)) lineTo((x + w + cmSize, y)) moveTo((x + w, y - bleed)) lineTo((x + w, y - cmSize)) # Top left moveTo((x - bleed, y + h)) lineTo((x - cmSize, y + h)) moveTo((x, y + h + bleed)) lineTo((x, y + h + cmSize)) # Top right moveTo((x + w + bleed, y + h)) lineTo((x + w + cmSize, y + h)) moveTo((x + w, y + h + bleed)) 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: moveTo((x + fx, y - bleed)) lineTo((x + fx, y - cmSize)) moveTo((x + fx, y + h + bleed)) lineTo((x + fx, y + h + cmSize)) if fy is not None: moveTo((x - bleed, y + fy)) lineTo((x - cmSize, y + fy)) moveTo((x + w + bleed, y + fy)) lineTo((x + w + cmSize, y + fy)) drawPath()
def drawRegistrationMark(origin, cmSize, cmStrokeWidth, vertical): u"""Draw registration mark as position x, y.""" x, y = origin if vertical: dx = cmSize / 2 dy = cmSize else: dx = cmSize dy = cmSize / 2 fill(None) cmykStroke(1, 1, 1, 1) strokeWidth(cmStrokeWidth) newPath() # Registration circle oval(x - cmSize / 4, y - cmSize / 4, cmSize / 2, cmSize / 2) # Registration cross, in length of direction. moveTo((x - dx, y)) # Horizontal line. lineTo((x + dx, y)) moveTo((x, y + dy)) # Vertical line. lineTo((x, y - dy)) drawPath()