# HG changeset patch # User Paul Boddie # Date 1316469768 -7200 # Node ID f3511ba829c379d64487b71671ec9aa52775b492 # Parent bb3f785cfacd8f588bdb259bb74440fc77bb8407 Distinguish between image and object formats, supporting the latter with the transclusion formatter method so that SVG images can be embedded. Currently, SVG images are not initially sized correctly (at least in Firefox 3.x) and usually occupy an appropriately sized region only after the page zoom has been adjusted or when a page is viewed on subsequent occasions. diff -r bb3f785cfacd -r f3511ba829c3 graphviz.py --- a/graphviz.py Mon Sep 19 01:16:32 2011 +0200 +++ b/graphviz.py Tue Sep 20 00:02:48 2011 +0200 @@ -104,8 +104,10 @@ FILTERS = ['dot', 'neato', 'twopi', 'circo', 'fdp'] IMAGE_FORMATS = ['png', 'gif'] - FORMATS = IMAGE_FORMATS + ['ps', 'svg', 'svgz', 'fig', 'mif', \ - 'hpgl', 'pcl', 'dia', 'imap', 'cmapx'] + OBJECT_FORMATS = ['svg', 'svgz'] + OUTPUT_FORMATS = IMAGE_FORMATS + OBJECT_FORMATS + FORMATS = OUTPUT_FORMATS + \ + ['ps', 'fig', 'mif', 'hpgl', 'pcl', 'dia', 'imap', 'cmapx'] extensions = [] Dependencies = Dependencies @@ -115,7 +117,12 @@ def format(self, formatter): """ Send the text. """ - self.request.flush() # to identify error text + + request = self.request + page = request.page + _ = request.getText + + request.flush() # to identify error text self.filter = Parser.FILTERS[0] self.format = 'png' @@ -138,8 +145,9 @@ elif l.lower().startswith('//cmapx='): self.cmapx = wikiutil.escape(l.split('=', 1)[1]) - if not self.format in Parser.IMAGE_FORMATS: - raise NotImplementedError, "only formats %s are currently supported" % Parser.IMAGE_FORMATS + if not self.format in Parser.OUTPUT_FORMATS: + raise NotImplementedError, "only formats %s are currently supported" % \ + Parser.OUTPUT_FORMATS if self.cmapx: if not self.format in Parser.IMAGE_FORMATS: @@ -149,8 +157,8 @@ img_name = 'graphviz_%s.%s' % (sha.new(self.raw).hexdigest(), self.format) self.pagename = formatter.page.page_name - url = AttachFile.getAttachUrl(self.pagename, img_name, self.request) - self.attach_dir=AttachFile.getAttachDir(self.request,self.pagename,create=1) + url = AttachFile.getAttachUrl(self.pagename, img_name, request) + self.attach_dir=AttachFile.getAttachDir(request,self.pagename,create=1) self.delete_old_graphs(formatter) @@ -159,13 +167,14 @@ if self.format in Parser.IMAGE_FORMATS: if self.cmapx: - self.request.write('\n' + self.graphviz(self.raw, format='cmapx') + '\n') - self.request.write(formatter.image(src="%s" % url, usemap="#%s" % self.cmapx)) + request.write('\n' + self.graphviz(self.raw, format='cmapx') + '\n') + request.write(formatter.image(src="%s" % url, usemap="#%s" % self.cmapx)) else: - self.request.write(formatter.image(src="%s" % url, alt="graphviz image")) + request.write(formatter.image(src="%s" % url, alt="graphviz image")) else: - # TODO: read the docs and figure out how to do this correctly - self.request.write(formatter.attachment_link(True, url=url)) + request.write(formatter.transclusion(1, data=url)) + request.write(formatter.text(_("graphviz image"))) + request.write(formatter.transclusion(0)) def delete_old_graphs(self, formatter): page_info = formatter.page.lastEditInfo()