def pdf2svg(): tlist = get_treelist() try: i = int(request.vars.i) t = tlist.trees[i] if request.vars.ladderize: t.root.order_subtrees_by_size(recurse=True, reverse=bool(request.vars.rev)) except: session.flash = "no tree '%s'" % i redirect("index") fname = "tred-" + response.session_id opts = t.printopts v = request.vars if v.parsevars: t.labelfilter = v.labelfilter or "" t.labeltype = v.labeltype or t.labeltype t.labelsort = v.labelsort or t.labelsort opts.title = v.title or opts.title or "%s-%s" % (t.source, t.name) opts.pagesize = v.pagesize or opts.pagesize or "letter" #print opts.pagesize opts.draw_phylogram = v.draw_phylogram and t.phylogram opts.baseheight = float(v.baseheight or 0) or opts.baseheight opts.unitwidth = float(v.unitwidth or 0) or opts.unitwidth opts.border = float(v.border or 0) or opts.border opts.vpad = float(v.vpad or 1.1) if v.draw_intlabels and "intlabel" not in opts.visible: opts.visible.append("intlabel") if (not v.draw_intlabels) and "intlabel" in opts.visible: opts.visible.remove("intlabel") node, mapping = drawtree.traverse(t.root, opts) thicken_branches(node) node.set_attr("vpad", opts.vpad, 1) d = drawtree.draw(node, opts) t.drawing = d buf = drawtree.render_pdf(d, opts) proc = subprocess.Popen(("/usr/bin/pstoedit", "-f", "plot-svg"), stdin=subprocess.PIPE, stdout=subprocess.PIPE) out, err = proc.communicate(buf.getvalue()) out = out.split("\n") out[2] = '<svg version="1.1" baseProfile="full" id="body" '\ 'width="%s" height="%s" viewBox="0 0 1 1" '\ 'preserveAspectRatio="none" '\ 'xmlns="http://www.w3.org/2000/svg" '\ 'xmlns:xlink="http://www.w3.org/1999/xlink" '\ 'xmlns:ev="http://www.w3.org/2001/xml-events">' \ % (d.width, d.height) out[5] = "" response.headers["Content-Type"] = "image/svg" f = t.printopts.title + ".svg" s = "attachment; filename=%s" % f response.headers["Content-Disposition"] = s return "\n".join(out)
def pdf2svg(): tlist = get_treelist() try: i = int(request.vars.i) t = tlist.trees[i] if request.vars.ladderize: t.root.order_subtrees_by_size(recurse=True, reverse=bool(request.vars.rev)) except: session.flash = "no tree '%s'" % i redirect("index") fname = "tred-" + response.session_id opts = t.printopts v = request.vars if v.parsevars: t.labelfilter = v.labelfilter or "" t.labeltype = v.labeltype or t.labeltype t.labelsort = v.labelsort or t.labelsort opts.title = v.title or opts.title or "%s-%s" % (t.source, t.name) opts.pagesize = v.pagesize or opts.pagesize or "letter" # print opts.pagesize opts.draw_phylogram = v.draw_phylogram and t.phylogram opts.baseheight = float(v.baseheight or 0) or opts.baseheight opts.unitwidth = float(v.unitwidth or 0) or opts.unitwidth opts.border = float(v.border or 0) or opts.border opts.vpad = float(v.vpad or 1.1) if v.draw_intlabels and "intlabel" not in opts.visible: opts.visible.append("intlabel") if (not v.draw_intlabels) and "intlabel" in opts.visible: opts.visible.remove("intlabel") node, mapping = drawtree.traverse(t.root, opts) thicken_branches(node) node.set_attr("vpad", opts.vpad, 1) d = drawtree.draw(node, opts) t.drawing = d buf = drawtree.render_pdf(d, opts) proc = subprocess.Popen(("/usr/bin/pstoedit", "-f", "plot-svg"), stdin=subprocess.PIPE, stdout=subprocess.PIPE) out, err = proc.communicate(buf.getvalue()) out = out.split("\n") out[2] = ( '<svg version="1.1" baseProfile="full" id="body" ' 'width="%s" height="%s" viewBox="0 0 1 1" ' 'preserveAspectRatio="none" ' 'xmlns="http://www.w3.org/2000/svg" ' 'xmlns:xlink="http://www.w3.org/1999/xlink" ' 'xmlns:ev="http://www.w3.org/2001/xml-events">' % (d.width, d.height) ) out[5] = "" response.headers["Content-Type"] = "image/svg" f = t.printopts.title + ".svg" s = "attachment; filename=%s" % f response.headers["Content-Disposition"] = s return "\n".join(out)
def pdfsingle(): tlist = get_treelist() try: i = int(request.vars.i) t = tlist.trees[i] if request.vars.ladderize: t.root.order_subtrees_by_size(recurse=True, reverse=bool(request.vars.rev)) except: session.flash = "no tree '%s'" % i redirect("index") fname = "tred-" + response.session_id opts = t.printopts v = request.vars if v.parsevars: t.labelfilter = v.labelfilter or "" t.labeltype = v.labeltype or t.labeltype t.labelsort = v.labelsort or t.labelsort opts.title = v.title or opts.title or "%s-%s" % (t.source, t.name) opts.pagesize = v.pagesize or opts.pagesize or "letter" #print opts.pagesize opts.draw_phylogram = v.draw_phylogram and t.phylogram opts.baseheight = float(v.baseheight or 0) or opts.baseheight opts.unitwidth = float(v.unitwidth or 0) or opts.unitwidth opts.border = float(v.border or 0) or opts.border opts.vpad = float(v.vpad or 1.1) if v.draw_intlabels and "intlabel" not in opts.visible: opts.visible.append("intlabel") if (not v.draw_intlabels) and "intlabel" in opts.visible: opts.visible.remove("intlabel") node, mapping = drawtree.traverse(t.root, opts) thicken_branches(node) node.set_attr("vpad", opts.vpad, 1) d = drawtree.draw(node, opts) t.drawing = d buf = drawtree.render_pdf(d, opts) response.headers["Content-Type"] = "application/x-pdf" f = t.printopts.title + ".pdf" s = "attachment; filename=%s" % f response.headers["Content-Disposition"] = s return buf.getvalue()
def pdfsingle(): tlist = get_treelist() try: i = int(request.vars.i) t = tlist.trees[i] if request.vars.ladderize: t.root.order_subtrees_by_size(recurse=True, reverse=bool(request.vars.rev)) except: session.flash = "no tree '%s'" % i redirect("index") fname = "tred-" + response.session_id opts = t.printopts v = request.vars if v.parsevars: t.labelfilter = v.labelfilter or "" t.labeltype = v.labeltype or t.labeltype t.labelsort = v.labelsort or t.labelsort opts.title = v.title or opts.title or "%s-%s" % (t.source, t.name) opts.pagesize = v.pagesize or opts.pagesize or "letter" # print opts.pagesize opts.draw_phylogram = v.draw_phylogram and t.phylogram opts.baseheight = float(v.baseheight or 0) or opts.baseheight opts.unitwidth = float(v.unitwidth or 0) or opts.unitwidth opts.border = float(v.border or 0) or opts.border opts.vpad = float(v.vpad or 1.1) if v.draw_intlabels and "intlabel" not in opts.visible: opts.visible.append("intlabel") if (not v.draw_intlabels) and "intlabel" in opts.visible: opts.visible.remove("intlabel") node, mapping = drawtree.traverse(t.root, opts) thicken_branches(node) node.set_attr("vpad", opts.vpad, 1) d = drawtree.draw(node, opts) t.drawing = d buf = drawtree.render_pdf(d, opts) response.headers["Content-Type"] = "application/x-pdf" f = t.printopts.title + ".pdf" s = "attachment; filename=%s" % f response.headers["Content-Disposition"] = s return buf.getvalue()