def __init__(self, *args, **kwargs): # the initialization is taken from rst2pdf.flowables.Heading hstyle = kwargs.pop('hstyle') level = kwargs.pop('level') text = kwargs.pop('text') self.snum = kwargs.pop('snum') self.parent_id = kwargs.pop('parent_id') Heading.__init__(self, text, hstyle, level=level, parent_id=self.parent_id) # Stuff needed for the outline entry MyImage.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): # The inicialization is taken from rst2pdf.flowables.Heading hstyle = kwargs.pop('hstyle') level = 0 text = kwargs.pop('text') self.snum = kwargs.pop('snum') self.parent_id = kwargs.pop('parent_id') # self.stext = Heading.__init__(self, text, hstyle, level=level, parent_id=self.parent_id) # Cleanup title text # self.stext = re.sub(r'<[^>]*?>', '', unescape(self.stext)) # self.stext = self.stext.strip() # Stuff needed for the outline entry MyImage.__init__(self, *args, **kwargs)
def gather_elements(self, client, node, style): # FIXME: handle alt target = None if isinstance(node.parent, docutils.nodes.reference): target = node.parent.get('refuri', None) st_name = 'image' if node.get('classes'): st_name = node.get('classes')[0] style = client.styles[st_name] uri = str(node.get("uri")) if uri.split("://")[0].lower() not in ('http', 'ftp', 'https'): imgname = os.path.join(client.basedir, uri) else: imgname = uri try: w, h, kind = MyImage.size_for_node(node, client=client) except ValueError: # Broken image, return arbitrary stuff imgname = missing w, h, kind = 100, 100, 'direct' node.elements = [ MyImage(filename=imgname, height=h, width=w, kind=kind, client=client, target=target) ] alignment = node.get('align', '').upper() if not alignment: # There is no JUSTIFY for flowables, of course, so 4:LEFT alignment = { 0: 'LEFT', 1: 'CENTER', 2: 'RIGHT', 4: 'LEFT' }[style.alignment] if not alignment: alignment = 'CENTER' node.elements[0].image.hAlign = alignment node.elements[0].spaceBefore = style.spaceBefore node.elements[0].spaceAfter = style.spaceAfter # Image flowables don't support valign (makes no sense for them?) # elif alignment in ('TOP','MIDDLE','BOTTOM'): # i.vAlign = alignment return node.elements
def gather_elements(self, client, node, style): # Create image calling plantuml tfile = tempfile.NamedTemporaryFile(dir='.', delete=False, suffix='.' + node['format']) args = 'plantuml -pipe -charset utf-8' if node['format'].lower() == 'svg': args += ' -tsvg' client.to_unlink.append(tfile.name) try: p = subprocess.Popen(args.split(), stdout=tfile, stdin=subprocess.PIPE, stderr=subprocess.PIPE) except OSError as err: if err.errno != errno.ENOENT: raise raise PlantUmlError('plantuml command %r cannot be run' % self.builder.config.plantuml) serr = p.communicate(node['uml'].encode('utf-8'))[1] if p.returncode != 0: raise PlantUmlError('error while running plantuml\n\n' + serr) # Add Image node with the right image return [MyImage(tfile.name, client=client)]
def drawOn(self, canv, x, y, _sW): # Add outline entry. This is copied from rst2pdf.flowables.heading canv.bookmarkHorizontal(self.parent_id, 0, y + self.image.height) if canv.firstSect: canv.sectName = self.stext canv.firstSect = False if self.snum is not None: canv.sectNum = self.snum else: canv.sectNum = "" canv.addOutlineEntry(self.stext, self.parent_id, int(self.level), False) # And let MyImage do all the drawing MyImage.drawOn(self, canv, x, y, _sW)
def gather_elements(self, client, node, style): # Based on the graphviz extension global graphviz_warn try: # Is vectorpdf enabled? if hasattr(VectorPdf, 'load_xobj'): # Yes, we have vectorpdf fname, outfn = sphinx.ext.graphviz.render_dot( node['builder'], node['code'], node['options'], 'pdf') else: # Use bitmap if not graphviz_warn: log.warning( 'Using graphviz with PNG output. You get much better results if you enable the vectorpdf extension.' ) graphviz_warn = True fname, outfn = sphinx.ext.graphviz.render_dot( node['builder'], node['code'], node['options'], 'png') if outfn: client.to_unlink.append(outfn) client.to_unlink.append(outfn + '.map') else: # Something went very wrong with graphviz, and # sphinx should have given an error already return [] except sphinx.ext.graphviz.GraphvizError as exc: log.error('dot code %r: ' % node['code'] + str(exc)) return [Paragraph(node['code'], client.styles['code'])] return [MyImage(filename=outfn, client=client)]
def __init__(self, *args, **kwargs): # The inicialization is taken from rst2pdf.flowables.Heading hstyle = kwargs.pop('hstyle') level = 0 text = kwargs.pop('text') self.snum = kwargs.pop('snum') self.parent_id= kwargs.pop('parent_id') #self.stext = Heading.__init__(self,text,hstyle,level=level, parent_id=self.parent_id) # Cleanup title text #self.stext = re.sub(r'<[^>]*?>', '', unescape(self.stext)) #self.stext = self.stext.strip() # Stuff needed for the outline entry MyImage.__init__(self, *args, **kwargs)
def drawOn(self, canv, x, y, _sW): ## These two lines are magic. #if isinstance(self.parent_id, tuple): #self.parent_id=self.parent_id[0] # Add outline entry. This is copied from rst2pdf.flowables.heading canv.bookmarkHorizontal(self.parent_id, 0, y + self.image.height) if canv.firstSect: canv.sectName = self.stext canv.firstSect = False if self.snum is not None: canv.sectNum = self.snum else: canv.sectNum = "" canv.addOutlineEntry(self.stext.encode('utf-8', 'replace'), self.parent_id.encode('utf-8', 'replace'), int(self.level), False) # And let MyImage do all the drawing MyImage.drawOn(self, canv, x, y, _sW)
def drawOn(self,canv,x,y,_sW): ## These two lines are magic. #if isinstance(self.parent_id, tuple): #self.parent_id=self.parent_id[0] # Add outline entry. This is copied from rst2pdf.flowables.heading canv.bookmarkHorizontal(self.parent_id,0,y+self.image.height) if canv.firstSect: canv.sectName = self.stext canv.firstSect=False if self.snum is not None: canv.sectNum = self.snum else: canv.sectNum = "" canv.addOutlineEntry(self.stext.encode('utf-8','replace'), self.parent_id.encode('utf-8','replace'), int(self.level), False) # And let MyImage do all the drawing MyImage.drawOn(self,canv,x,y,_sW)
def get_text(self, client, node, replaceEnt): # First see if the image file exists, or else, # use image-missing.png imgname = os.path.join(client.basedir, str(node.get("uri"))) try: w, h, kind = MyImage.size_for_node(node, client=client) except ValueError: # Broken image, return arbitrary stuff imgname = missing w, h, kind = 100, 100, 'direct' alignment = node.get('align', 'CENTER').lower() if alignment in ('top', 'middle', 'bottom'): align = 'valign="%s"' % alignment else: align = '' # TODO: inline images don't support SVG, vectors and PDF, # which may be surprising. So, work on converting them # previous to passing to reportlab. # Try to rasterize using the backend w, h, kind = MyImage.size_for_node(node, client=client) uri = MyImage.raster(imgname, client) return '<img src="%s" width="%f" height="%f" %s/>' % \ (uri, w, h, align)
def gather_elements(self, client, node, style): # FIXME: handle alt target = None if isinstance(node.parent, docutils.nodes.reference): target = node.parent.get('refuri', None) st_name = 'image' if node.get('classes'): st_name = node.get('classes')[0] style = client.styles[st_name] uri = str(node.get("uri")) if uri.split("://")[0].lower() not in ('http', 'ftp', 'https'): imgname = os.path.join(client.basedir, uri) else: imgname = uri try: w, h, kind = MyImage.size_for_node(node, client=client) except ValueError: # Broken image, return arbitrary stuff imgname = missing w, h, kind = 100, 100, 'direct' node.elements = [ MyImage(filename=imgname, height=h, width=w, kind=kind, client=client, target=target)] alignment = node.get('align', '').upper() if not alignment: # There is no JUSTIFY for flowables, of course, so 4:LEFT alignment = { 0: 'LEFT', 1: 'CENTER', 2: 'RIGHT', 4:'LEFT' }[style.alignment] if not alignment: alignment = 'CENTER' node.elements[0].image.hAlign = alignment node.elements[0].spaceBefore = style.spaceBefore node.elements[0].spaceAfter = style.spaceAfter # Image flowables don't support valign (makes no sense for them?) # elif alignment in ('TOP','MIDDLE','BOTTOM'): # i.vAlign = alignment return node.elements