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;
31 public class PSExport extends SecStrDrawingProducer {
39 private String PSMacros() {
41 // Params [fontsize|...]
42 "/setbasefont \n" + "{ /Helvetica-Bold findfont\n" + // =>
44 " exch scalefont\n" + // => [scaled_font|...]
45 " setfont \n" + // => [...]
48 String writeTextCentered =
49 // Params [txt|size|...]
50 "/txtcenter \n" + "{ dup \n" + // => [txt|txt|size|...]
51 " stringwidth pop\n" + // => [wtxt|txt|size|...]
52 " 2 div neg \n" + // => [-wtxt/2|txt|size|...]
53 " 3 -1 roll \n" + // => [size|-wtxt/2|txt...]
54 " 2 div neg\n" + // => [-size/2|-wtxt/2|txt|...]
55 " rmoveto\n" + // => [txt|...]
56 " show\n" + // => [...]
59 String drawEllipse = "/ellipse {\n" + " /endangle exch def\n"
60 + " /startangle exch def\n" + " /yrad exch def\n"
61 + " /xrad exch def\n" + " /y exch def\n" + " /x exch def\n"
62 + " /savematrix matrix currentmatrix def\n"
63 + " x y translate\n" + " xrad yrad scale\n"
64 + " 0 0 1 startangle endangle arc\n"
65 + " savematrix setmatrix\n" + " } def\n\n";
66 return setFontSize + writeTextCentered + drawEllipse;
69 private String EPSHeader(double minX, double maxX, double minY, double maxY) {
70 String bbox = PSBBox(minX, minY, maxX, maxY);
71 String init = "%!PS-Adobe-3.0\n" + "%%Pages: 1\n" + bbox
72 + "%%EndComments\n" + "%%Page: 1 1\n";
73 String macros = PSMacros();
77 private String EPSFooter() {
78 return "showpage\n" + "%%EndPage: 1\n" + "%%EOF";
81 private String PSNewPath() {
85 private String PSMoveTo(double x, double y) {
86 return ("" + x + " " + y + " moveto\n");
89 private String PSLineTo(double dx, double dy) {
90 return ("" + dx + " " + dy + " lineto\n");
93 private String PSRLineTo(double dx, double dy) {
94 return ("" + dx + " " + dy + " rlineto\n");
97 private String PSSetLineWidth(double thickness) {
99 return ("" + thickness + " setlinewidth\n");
102 private String PSStroke() {
106 private String PSArc(double x, double y, double radiusX, double radiusY,
107 double angleFrom, double angleTo) {
112 // return (centerX + " " + centerY + " "+ radiusX/2.0+" " + angleFrom +
113 // " " + angleTo + " arc\n");
115 return (centerX + " " + centerY + " " + radiusX / 2.0 + " " + radiusY
116 / 2.0 + " " + angleTo + " " + angleFrom + " ellipse\n");
120 private String PSArc(double x, double y, double radius, double angleFrom,
123 return ("" + x + " " + y + " " + radius + " " + angleFrom + " "
124 + angleTo + " arc\n");
127 private String PSBBox(double minX, double maxX, double minY, double maxY) {
128 String norm = ("%%BoundingBox: " + (long) Math.floor(minX) + " "
129 + (long) Math.floor(minY) + " " + (long) Math.ceil(maxX) + " "
130 + (long) Math.ceil(maxY) + "\n");
131 String high = ("%%HighResBoundingBox: " + (long) Math.floor(minX) + " "
132 + (long) Math.floor(minY) + " " + (long) Math.ceil(maxX) + " "
133 + (long) Math.ceil(maxY) + "\n");
137 private String PSText(String txt) {
138 return ("(" + txt + ") ");
141 @SuppressWarnings("unused")
142 private String PSShow() {
146 private String PSClosePath() {
147 return ("closepath\n");
150 private String PSFill() {
154 private String PSSetColor(Color col) {
155 return ("" + (((double) col.getRed()) / 255.0) + " "
156 + (((double) col.getGreen()) / 255.0) + " "
157 + (((double) col.getBlue()) / 255.0) + " setrgbcolor\n");
160 private String fontName(int font) {
162 case (FONT_TIMES_ROMAN):
163 return "/Times-Roman";
164 case (FONT_TIMES_BOLD):
165 return "/Times-Bold";
166 case (FONT_TIMES_ITALIC):
167 return "/Times-Italic";
168 case (FONT_TIMES_BOLD_ITALIC):
169 return "/Times-BoldItalic";
170 case (FONT_HELVETICA):
172 case (FONT_HELVETICA_BOLD):
173 return "/Helvetica-Bold";
174 case (FONT_HELVETICA_OBLIQUE):
175 return "/Helvetica-Oblique";
176 case (FONT_HELVETICA_BOLD_OBLIQUE):
177 return "/Helvetica-BoldOblique";
180 case (FONT_COURIER_BOLD):
181 return "/Courier-Bold";
182 case (FONT_COURIER_OBLIQUE):
183 return "/Courier-Oblique";
184 case (FONT_COURIER_BOLD_OBLIQUE):
185 return "/Courier-BoldOblique";
190 private String PSSetFont(int font, double size) {
191 return (fontName(font) + " findfont " + size + " scalefont setfont\n");
194 public String setFontS(int font, double size) {
195 _fontsize = (long) (0.4 * size);
196 return PSSetFont(font, _fontsize);
199 public String setColorS(Color col) {
200 super.setColorS(col);
201 String result = PSSetColor(col);
205 public String drawLineS(Point2D.Double p0, Point2D.Double p1,
208 tmp += PSMoveTo(p0.x, p0.y);
209 tmp += PSLineTo(p1.x, p1.y);
210 tmp += PSSetLineWidth(thickness);
215 public String drawTextS(Point2D.Double p, String txt) {
217 tmp += PSMoveTo(p.x, p.y);
218 tmp += ("" + (_fontsize / 2.0 + 1) + " \n");
220 tmp += (" txtcenter\n");
224 public String drawRectangleS(Point2D.Double orig, Point2D.Double dims,
226 String tmp = PSNewPath();
227 tmp += PSMoveTo(orig.x, orig.y);
228 tmp += PSRLineTo(0, dims.y);
229 tmp += PSRLineTo(dims.x, 0);
230 tmp += PSRLineTo(0, -dims.y);
231 tmp += PSClosePath();
232 tmp += PSSetLineWidth(thickness);
237 public String drawCircleS(Point2D.Double p, double radius, double thickness) {
238 String tmp = PSNewPath();
239 tmp += PSArc(p.x, p.y, radius, 0, 360);
240 tmp += PSSetLineWidth(thickness);
245 public String fillCircleS(Point2D.Double p, double radius,
246 double thickness, Color color) {
247 String tmp = PSNewPath();
248 tmp += PSArc(p.x, p.y, radius, 0, 360);
249 tmp += PSSetLineWidth(thickness);
250 tmp += PSSetColor(color);
255 public String footerS() {
259 public String headerS(Rectangle2D.Double bb) {
260 return EPSHeader(bb.x, bb.y, bb.x + bb.width, bb.y + bb.height);
264 public String drawArcS(Point2D.Double origine, double width, double height,
265 double startAngle, double endAngle) {
266 return PSArc(origine.x, origine.y, width, height, startAngle, endAngle)
271 public String drawPolygonS(Double[] points, double thickness) {
272 String tmp = PSNewPath();
273 tmp += PSSetLineWidth(thickness);
274 for (int i = 0; i < points.length; i++) {
276 tmp += PSMoveTo(points[i].x, points[i].y);
278 tmp += PSLineTo(points[i].x, points[i].y);
281 tmp += PSClosePath();
287 public String fillPolygonS(Double[] points, Color color) {
288 Color bck = _curColor;
289 String tmp = PSNewPath();
290 for (int i = 0; i < points.length; i++) {
292 tmp += PSMoveTo(points[i].x, points[i].y);
294 tmp += PSLineTo(points[i].x, points[i].y);
297 tmp += PSClosePath();
298 tmp += PSSetColor(color);
300 tmp += PSSetColor(bck);
305 public String drawBaseStartS(int index) {
310 public String drawBaseEndS(int index) {
315 public String drawBasePairStartS(int i, int j, ModeleBP bps) {
320 public String drawBasePairEndS(int index) {
325 public String drawBackboneStartS(int i, int j) {
330 public String drawBackboneEndS(int index) {