2 VARNA is a tool for the automated drawing, visualization and annotation of the secondary structure of RNA, designed as a companion software for web servers and databases.
3 Copyright (C) 2008 Kevin Darty, Alain Denise and Yann Ponty.
4 electronic mail : Yann.Ponty@lri.fr
5 paper mail : LRI, bat 490 Université Paris-Sud 91405 Orsay Cedex France
7 This file is part of VARNA version 3.1.
8 VARNA version 3.1 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 VARNA version 3.1 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with VARNA version 3.1.
16 If not, see http://www.gnu.org/licenses.
18 package fr.orsay.lri.varna.models.export;
20 import java.awt.Color;
21 import java.awt.geom.Point2D;
22 import java.awt.geom.Rectangle2D;
23 import java.awt.geom.Point2D.Double;
25 import fr.orsay.lri.varna.models.rna.ModeleBP;
27 public class SVGExport extends SecStrDrawingProducer {
29 private double _fontsize = 10.0;
30 private Rectangle2D.Double _bb = new Rectangle2D.Double(0, 0, 10, 10);
31 double _thickness = 2.0;
40 private String getRGBString(Color col) {
41 int rpc = (int) ((((double) col.getRed()) / 255.0) * 100);
42 int gpc = (int) ((((double) col.getGreen()) / 255.0) * 100);
43 int bpc = (int) ((((double) col.getBlue()) / 255.0) * 100);
44 return "rgb(" + rpc + "%, " + gpc + "%, " + bpc + "%)";
47 public String drawCircleS(Point2D.Double base, double radius,
49 _thickness = thickness;
50 return "<circle cx=\"" + base.x + "\" cy=\"" + (_bb.height - base.y)
51 + "\" r=\"" + radius + "\" stroke=\"" + getRGBString(_curColor)
52 + "\" stroke-width=\"" + thickness + "\" fill=\"none\"/>\n";
55 public String drawLineS(Point2D.Double orig, Point2D.Double dest,
57 _thickness = thickness;
58 return "<line x1=\"" + orig.x + "\" y1=\"" + (_bb.height - orig.y)
59 + "\" x2=\"" + dest.x + "\" y2=\"" + (_bb.height - dest.y)
60 + "\" stroke=\"" + getRGBString(_curColor)
61 + "\" stroke-width=\"" + thickness + "\" />\n";
64 public String drawRectangleS(Point2D.Double orig, Point2D.Double dims,
66 _thickness = thickness;
67 return "<rect x=\""+ orig.x+"\" y=\""+(_bb.height - orig.y - dims.y)+"\" width=\""+dims.x
68 +"\" height=\""+dims.y+
69 "\" fill=\"none\" style=\"stroke-width:"+thickness+";stroke:"+getRGBString(_curColor)+"\"/>";
72 public String drawTextS(Point2D.Double base, String txt) {
73 //System.out.println(txt);
77 + (_bb.height - base.y + 0.4 * _fontsize)
78 + "\" text-anchor=\"middle\" font-family=\"Verdana\" font-size=\""
79 + _fontsize + "\" fill=\"" + getRGBString(_curColor) + "\" >"
83 public String fillCircleS(Point2D.Double base, double radius,
84 double thickness, Color col) {
85 _thickness = thickness;
87 return "<circle cx=\"" + base.x + "\" cy=\"" + (_bb.height - base.y)
88 + "\" r=\"" + radius + "\" stroke=\"none\" stroke-width=\""
89 + thickness + "\" fill=\"" + getRGBString(col) + "\"/>\n";
92 public String footerS() {
96 public String headerS(Rectangle2D.Double bb) {
98 return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
99 + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n"
100 + "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
102 + "<svg width=\"100%\" height=\"100%\" version=\"1.1\"\n"
103 + "xmlns=\"http://www.w3.org/2000/svg\">\n";
106 public String setFontS(int font, double size) {
107 _fontsize = 0.5 * size;
112 private Point2D.Double polarToCartesian(Point2D.Double center, double radiusX, double radiusY, double angleInDegrees) {
113 double angleInRadians = (angleInDegrees) * Math.PI / 180.0;
115 return new Point2D.Double(center.x + (radiusX * Math.cos(angleInRadians)),
116 _bb.height - (center.y + (radiusY * Math.sin(angleInRadians))));
120 public String drawArcS(Point2D.Double o, double width, double height,
121 double startAngle, double endAngle) {
122 double rx = width / 2.0;
123 double ry = height / 2.0;
125 Point2D.Double ps = polarToCartesian(o,rx,ry,startAngle);
126 Point2D.Double pe = polarToCartesian(o,rx,ry,endAngle);
128 String d = "<path d=\"M " + ps.x + "," + ps.y + " A " + rx + "," + ry
129 + " 0 1,1 " + pe.x + "," + pe.y + "\" style=\"fill:none; stroke:"
130 + getRGBString(_curColor) + "; stroke-width:" + _thickness
135 public String drawPolygonS(Double[] points, double thickness) {
136 String result = "<path d=\"";
137 for (int i = 0; i < points.length; i++) {
139 result += "M " + points[i].x + " " + (_bb.height - points[i].y)
142 result += "L " + points[i].x + " " + (_bb.height - points[i].y)
146 result += "z\" style=\"fill:none; stroke:" + getRGBString(_curColor)
147 + "; stroke-width:" + thickness + ";\"/>\n";
152 public String fillPolygonS(Double[] points, Color col) {
153 String result = "<path d=\"";
154 for (int i = 0; i < points.length; i++) {
156 result += "M " + points[i].x + " " + (_bb.height - points[i].y)
159 result += "L " + points[i].x + " " + (_bb.height - points[i].y)
163 result += "z\" fill=\""+getRGBString(col)+"\" style=\"stroke:none;\"/>\n";
168 public String drawBaseStartS(int index) {
173 public String drawBaseEndS(int index) {
178 public String drawBasePairStartS(int i, int j, ModeleBP bps) {
183 public String drawBasePairEndS(int index) {
188 public String drawBackboneStartS(int i, int j) {
193 public String drawBackboneEndS(int index) {