def process(self): kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) preserve = kwargs.pop('preserveAspectRatio') show = kwargs.pop('showBoundary') if preserve: imgX, imgY = kwargs['image'].getSize() # Scale image correctly, if width and/or height were specified if 'width' in kwargs and 'height' not in kwargs: kwargs['height'] = imgY * kwargs['width'] / imgX elif 'height' in kwargs and 'width' not in kwargs: kwargs['width'] = imgX * kwargs['height'] / imgY elif 'width' in kwargs and 'height' in kwargs: if float(kwargs['width']) / kwargs['height'] > float( imgX) / imgY: kwargs['width'] = imgX * kwargs['height'] / imgY else: kwargs['height'] = imgY * kwargs['width'] / imgX canvas = attr.getManager(self, interfaces.ICanvasManager).canvas getattr(canvas, self.callable)(**kwargs) if show: width = kwargs.get('width', kwargs['image'].getSize()[0]) height = kwargs.get('height', kwargs['image'].getSize()[1]) canvas.rect(kwargs['x'], kwargs['y'], width, height)
def process(self): self.options = [] self.processSubDirectives() kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) kwargs['options'] = self.options canvas = attr.getManager(self, interfaces.ICanvasManager).canvas getattr(reportlab.pdfbase.pdfform, self.callable)(canvas, **kwargs)
def process(self): modulePath, functionName, params = self.getAttributeValues( valuesOnly=True) module = __import__(modulePath, {}, {}, [modulePath]) function = getattr(module, functionName) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas function(canvas, params)
def process(self): kwargs = dict(self.getAttributeValues(ignore=('points',))) # Start the path and set the cursor to the start location. canvas = attr.getManager(self, interfaces.ICanvasManager).canvas self.path = canvas.beginPath() self.path.moveTo(kwargs.pop('x'), kwargs.pop('y')) # Process the text before the first sub-directive. if self.element.text is not None: self.processPoints(self.element.text) # Handle each sub-directive. for directive in self.element.getchildren(): if directive.tag in self.factories: self.factories[directive.tag](directive, self).process() # If there is more text after sub-directive, process it. if directive.tail is not None: self.processPoints(directive.tail) if kwargs.pop('close', False): self.path.close() if kwargs.pop('clip', False): canvas.clipPath(self.path, **kwargs) else: canvas.drawPath(self.path, **kwargs)
def process(self): kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) preserve = kwargs.pop('preserveAspectRatio') show = kwargs.pop('showBoundary') if preserve: imgX, imgY = kwargs['image'].getSize() # Scale image correctly, if width and/or height were specified if 'width' in kwargs and 'height' not in kwargs: kwargs['height'] = imgY * kwargs['width'] / imgX elif 'height' in kwargs and 'width' not in kwargs: kwargs['width'] = imgX * kwargs['height'] / imgY elif 'width' in kwargs and 'height' in kwargs: if float(kwargs['width'])/kwargs['height'] > float(imgX)/imgY: kwargs['width'] = imgX * kwargs['height'] / imgY else: kwargs['height'] = imgY * kwargs['width'] / imgX canvas = attr.getManager(self, interfaces.ICanvasManager).canvas getattr(canvas, self.callable)(**kwargs) if show: width = kwargs.get('width', kwargs['image'].getSize()[0]) height = kwargs.get('height', kwargs['image'].getSize()[1]) canvas.rect(kwargs['x'], kwargs['y'], width, height)
def process(self): kwargs = dict(self.getAttributeValues(ignore=('points', ))) # Start the path and set the cursor to the start location. canvas = attr.getManager(self, interfaces.ICanvasManager).canvas self.path = canvas.beginPath() self.path.moveTo(kwargs.pop('x'), kwargs.pop('y')) # Process the text before the first sub-directive. if self.element.text is not None: self.processPoints(self.element.text) # Handle each sub-directive. for directive in self.element.getchildren(): if directive.tag in self.factories: self.factories[directive.tag](directive, self).process() # If there is more text after sub-directive, process it. if directive.tail is not None: self.processPoints(directive.tail) if kwargs.pop('close', False): self.path.close() if kwargs.pop('clip', False): canvas.clipPath(self.path, **kwargs) else: canvas.drawPath(self.path, **kwargs)
def getProcessor(self): manager = attr.getManager(self, interfaces.IPostProcessorManager) procs = dict(manager.postProcessors) if 'CONCAT' not in procs: proc = ConcatenationPostProcessor() manager.postProcessors.append(('CONCAT', proc)) return proc return procs['CONCAT']
def process(self): args = dict(self.getAttributeValues()) manager = attr.getManager(self) index = manager.indexes[args['name']] args['format'] = index.formatFunc.__name__[8:] args['offset'] = index.offset index.setup(**args) self.parent.flow.append(index)
def getProcessor(self): manager = attr.getManager(self, interfaces.IPostProcessorManager) procs = dict(manager.postProcessors) if 'MERGE' not in procs: proc = MergePostProcessor() manager.postProcessors.append(('MERGE', proc)) return proc return procs['MERGE']
def process(self): args = dict(self.getAttributeValues()) manager = attr.getManager(self) index = manager.indexes[args["name"]] args["format"] = index.formatFunc.__name__[8:] args["offset"] = index.offset index.setup(**args) self.parent.flow.append(index)
def getProcessor(self): manager = attr.getManager(self, interfaces.IPostProcessorManager) procs = dict(manager.postProcessors) if "MERGE" not in procs: proc = page.MergePostProcessor() manager.postProcessors.append(("MERGE", proc)) return proc return procs["MERGE"]
def process(self): kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas # Convert width and height to end locations kwargs['text'] = kwargs['text'] % { 'page_number': canvas.getPageNumber(), } getattr(canvas, self.callable)(**kwargs)
def process(self): kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas # Convert width and height to end locations kwargs['x2'] = kwargs['x1'] + kwargs['width'] del kwargs['width'] kwargs['y2'] = kwargs['y1'] + kwargs['height'] del kwargs['height'] getattr(canvas, self.callable)(**kwargs)
def process(self): kw = dict(self.getAttributeValues()) name = kw.pop('code') kw['value'] = str(kw['value']) x = kw.pop('x', 0) y = kw.pop('y', 0) code = reportlab.graphics.barcode.createBarcodeDrawing(name, **kw) manager = attr.getManager(self, interfaces.ICanvasManager) code.drawOn(manager.canvas, x, y)
def getProcessor(self): manager = attr.getManager(self, interfaces.IPostProcessorManager) procs = dict(manager.postProcessors) if 'CONCAT' not in procs: log.debug('Using concetation post-processor: %s', self.ConcatenationPostProcessorFactory) proc = self.ConcatenationPostProcessorFactory() manager.postProcessors.append(('CONCAT', proc)) return proc return procs['CONCAT']
def process(self): contents = self.getAttributeValues(valuesOnly=True)[0] self.params = {} self.processSubDirectives() for name, type in self.paramTypes.items(): if name in self.params: bound = type.bind(self) self.params[name] = bound.fromUnicode(self.params[name]) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas canvas.textAnnotation(contents, **self.params)
def process(self): if PyPDF2 is None: raise Exception( 'pyPdf is not installed, so this feature is not available.') inputFile, inPage = self.getAttributeValues(valuesOnly=True) manager = attr.getManager(self, interfaces.ICanvasManager) outPage = manager.canvas.getPageNumber()-1 proc = self.getProcessor() pageOperations = proc.operations.setdefault(outPage, []) pageOperations.append((inputFile, inPage))
def process(self): id = dict(self.getAttributeValues()).pop('id') manager = attr.getManager(self) text = manager.names[id] + (self.element.tail or u'') # Now replace the element with the text parent = self.element.getparent() if parent.text is None: parent.text = text else: parent.text += text parent.remove(self.element)
def process(self): if PyPDF2 is None: raise Exception( 'pyPdf is not installed, so this feature is not available.') inputFile, inPage = self.getAttributeValues(valuesOnly=True) manager = attr.getManager(self, interfaces.ICanvasManager) outPage = manager.canvas.getPageNumber() - 1 proc = self.getProcessor() pageOperations = proc.operations.setdefault(outPage, []) pageOperations.append((inputFile, inPage))
def process(self): kwargs = dict(self.getAttributeValues()) parent = kwargs.pop('parent', paraparser.SpanStyle('DefaultSpan')) name = kwargs.pop('name') style = copy.deepcopy(parent) style.name = name[6:] if name.startswith('style.') else name for name, value in kwargs.items(): setattr(style, name, value) manager = attr.getManager(self) manager.styles[style.name] = style
def process(self): kw = dict(self.getAttributeValues()) id = kw.pop('id') # Create Style self.style = reportlab.platypus.tables.TableStyle() for name, value in kw.items(): setattr(self.style, name, value) # Fill style self.processSubDirectives() # Add style to the manager manager = attr.getManager(self) manager.styles[id] = self.style
def process(self): kwargs = dict(self.getAttributeValues()) parent = kwargs.pop('parent', SampleStyleSheet['Normal']) name = kwargs.pop('name') style = copy.deepcopy(parent) style.name = name[6:] if name.startswith('style.') else name for name, value in kwargs.items(): setattr(style, name, value) manager = attr.getManager(self) manager.styles[style.name] = style
def process(self): kwargs = dict(self.getAttributeValues()) parent = kwargs.pop( 'parent', reportlab.lib.styles.getSampleStyleSheet()['Normal']) style = copy.deepcopy(parent) for name, value in kwargs.items(): setattr(style, name, value) manager = attr.getManager(self) manager.styles[style.name] = style
def getAttributeValues(self, ignore=None, select=None, attrMapping=None, includeMissing=False, valuesOnly=False): """See interfaces.IRMLDirective""" manager = getManager(self) cache = '{}.{}'.format(self.signature.__module__, self.signature.__name__) if cache in manager.attributesCache: fields = manager.attributesCache[cache] else: fields = [] for name, attr in zope.schema.getFieldsInOrder(self.signature): fields.append((name, attr)) manager.attributesCache[cache] = fields items = [] for name, attr in fields: # Only add the attribute to the list, if it is supposed there if ((ignore is None or name not in ignore) and (select is None or name in select)): # Get the value. value = attr.bind(self).get() # If no value was found for a required field, raise a value # error if attr.required and value is attr.missing_value: raise ValueError( 'No value for required attribute "%s" ' 'in directive "%s" %s.' % (name, self.element.tag, getFileInfo(self))) # Only add the entry if the value is not the missing value or # missing values are requested to be included. if value is not attr.missing_value or includeMissing: items.append((name, value)) # Sort the items based on the section if select is not None: select = list(select) items = sorted(items, key=lambda n: select.index(n[0])) # If the attribute name does not match the internal API # name, then convert the name to the internal one if attrMapping: items = [(attrMapping.get(name, name), value) for name, value in items] # Sometimes we only want the values without the names if valuesOnly: return [value for name, value in items] return items
def process(self): kw = dict(self.getAttributeValues()) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas if 'width' in kw: canvas.setLineWidth(kw['width']) if 'join' in kw: canvas.setLineJoin(kw['join']) if 'cap' in kw: canvas.setLineCap(kw['cap']) if 'miterLimit' in kw: canvas.setMiterLimit(kw['miterLimit']) if 'dash' in kw: canvas.setDash(kw['dash'])
def process(self): kwargs = dict(self.getAttributeValues()) parent = kwargs.pop( 'parent', reportlab.lib.styles.ListStyle(name='List')) name = kwargs.pop('name') style = copy.deepcopy(parent) style.name = name[6:] if name.startswith('style.') else name for name, value in kwargs.items(): setattr(style, name, value) manager = attr.getManager(self) manager.styles[style.name] = style
def process(self): kwargs = dict(self.getAttributeValues()) id = kwargs.pop('id') for attrName in ('RGB', 'CMYK', 'value'): color = kwargs.pop(attrName, None) if color is not None: # CMYK has additional attributes. for name, value in kwargs.items(): setattr(color, name, value) manager = attr.getManager(self) manager.colors[id] = color return raise ValueError('At least one color definition must be specified.')
def process(self): kwargs = dict(self.getAttributeValues()) parent = kwargs.pop( 'parent', SampleStyleSheet['Normal']) name = kwargs.pop('name') style = copy.deepcopy(parent) style.name = name[6:] if name.startswith('style.') else name for name, value in kwargs.items(): setattr(style, name, value) manager = attr.getManager(self) manager.styles[style.name] = style
def process(self): kwargs = dict(self.getAttributeValues()) parent = kwargs.pop('parent', reportlab.lib.styles.ListStyle(name='List')) name = kwargs.pop('name') style = copy.deepcopy(parent) style.name = name[6:] if name.startswith('style.') else name for name, value in kwargs.items(): setattr(style, name, value) manager = attr.getManager(self) manager.styles[style.name] = style
def process(self): attrs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) angle = attrs.pop('angle', 0) x, y = attrs.pop('dx'), attrs.pop('dy') self.drawing = shapes.Drawing(attrs.pop('dwidth'), attrs.pop('dheight')) self.context = chart = self.createChart(attrs) self.processSubDirectives() group = shapes.Group(chart) group.translate(0,0) group.rotate(angle) self.drawing.add(group) manager = attr.getManager(self, interfaces.ICanvasManager) self.drawing.drawOn(manager.canvas, x, y)
def process(self): attrs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) angle = attrs.pop('angle', 0) x, y = attrs.pop('dx'), attrs.pop('dy') self.drawing = shapes.Drawing(attrs.pop('dwidth'), attrs.pop('dheight')) self.context = chart = self.createChart(attrs) self.processSubDirectives() group = shapes.Group(chart) group.translate(0, 0) group.rotate(angle) self.drawing.add(group) manager = attr.getManager(self, interfaces.ICanvasManager) self.drawing.drawOn(manager.canvas, x, y)
def getAttributeValues(self, ignore=None, select=None, attrMapping=None, includeMissing=False, valuesOnly=False): """See interfaces.IRMLDirective""" manager = getManager(self) cache = '%s.%s' % (self.signature.__module__, self.signature.__name__) if cache in manager.attributesCache: fields = manager.attributesCache[cache] else: fields = [] for name, attr in zope.schema.getFieldsInOrder(self.signature): fields.append((name, attr)) manager.attributesCache[cache] = fields items = [] for name, attr in fields: # Only add the attribute to the list, if it is supposed there if ((ignore is None or name not in ignore) and (select is None or name in select)): # Get the value. value = attr.bind(self).get() # If no value was found for a required field, raise a value # error if attr.required and value is attr.missing_value: raise ValueError( 'No value for required attribute "%s" ' 'in directive "%s" %s.' % ( name, self.element.tag, getFileInfo(self))) # Only add the entry if the value is not the missing value or # missing values are requested to be included. if value is not attr.missing_value or includeMissing: items.append((name, value)) # Sort the items based on the section if select is not None: select = list(select) items = sorted(items, key=lambda n: select.index(n[0])) # If the attribute name does not match the internal API # name, then convert the name to the internal one if attrMapping: items = [(attrMapping.get(name, name), value) for name, value in items] # Sometimes we only want the values without the names if valuesOnly: return [value for name, value in items] return items
def process(self): x, y, width, height = self.getAttributeValues( select=('x', 'y', 'width', 'height'), valuesOnly=True) y += height flows = flowable.Flow(self.element, self.parent) flows.process() canvas = attr.getManager(self, interfaces.ICanvasManager).canvas for flow in flows.flow: flowWidth, flowHeight = flow.wrap(width, height) if flowWidth <= width and flowHeight <= height: y -= flowHeight flow.drawOn(canvas, x, y) height -= flowHeight else: raise ValueError("Not enough space")
def process(self): x, y, width, height = self.getAttributeValues(select=('x', 'y', 'width', 'height'), valuesOnly=True) y += height flows = flowable.Flow(self.element, self.parent) flows.process() canvas = attr.getManager(self, interfaces.ICanvasManager).canvas for flow in flows.flow: flowWidth, flowHeight = flow.wrap(width, height) if flowWidth <= width and flowHeight <= height: y -= flowHeight flow.drawOn(canvas, x, y) height -= flowHeight else: raise ValueError("Not enough space")
def process(self): if 'round' in self.element.keys(): self.callable = 'roundRect' kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas # Create a link url = kwargs.pop('href', None) if url: canvas.linkURL(url, (kwargs['x'], kwargs['y'], kwargs['x'] + kwargs['width'], kwargs['y'] + kwargs['height'])) dest = kwargs.pop('destination', None) if dest: canvas.linkRect('', dest, (kwargs['x'], kwargs['y'], kwargs['x'] + kwargs['width'], kwargs['y'] + kwargs['height'])) # Render the rectangle getattr(canvas, self.callable)(**kwargs)
def process(self): if 'round' in self.element.keys(): self.callable = 'roundRect' kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas # Create a link url = kwargs.pop('href', None) if url: canvas.linkURL( url, (kwargs['x'], kwargs['y'], kwargs['x']+kwargs['width'], kwargs['y']+kwargs['height'])) dest = kwargs.pop('destination', None) if dest: canvas.linkRect( '', dest, (kwargs['x'], kwargs['y'], kwargs['x']+kwargs['width'], kwargs['y']+kwargs['height'])) # Render the rectangle getattr(canvas, self.callable)(**kwargs)
def process(self): super(Drawing, self).process() canvas = attr.getManager(self, interfaces.ICanvasManager).canvas canvas.showPage()
def process(self): args = dict(self.getAttributeValues()) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas args['left'], args['top'] = canvas.absolutePosition( args['x'], args['y']) canvas.bookmarkPage(**args)
def process(self): argset = self.getAttributeValues(valuesOnly=True)[0] canvas = attr.getManager(self, interfaces.ICanvasManager).canvas for args in argset: getattr(canvas, self.callable)(*args)
def process(self): args = self.getAttributeValues(valuesOnly=True) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas canvas.transform(*args[0])
def process(self): kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas getattr(canvas, self.callable)(**kwargs)
def process(self): args = dict(self.getAttributeValues()) canvas = attr.getManager(self, interfaces.ICanvasManager).canvas args['left'], args['top'] = canvas.absolutePosition(args['x'], args['y']) canvas.bookmarkPage(**args)
def process(self): canvas = attr.getManager(self, interfaces.ICanvasManager).canvas kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping)) kwargs['text'] = self._getText(self.element, canvas).strip() getattr(canvas, self.callable)(**kwargs)