-/* \r
+/*\r
Copyright Paul James Mutton, 2001-2004, http://www.jibble.org/\r
\r
This file is part of EpsGraphics2D.\r
* <p>\r
* Copyright Paul Mutton,\r
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>\r
- * \r
+ *\r
*/\r
public class EpsDocument {\r
- \r
- \r
+\r
+\r
/**\r
* Constructs an empty EpsDevice.\r
*/\r
_stringWriter = new StringWriter();\r
_bufferedWriter = new BufferedWriter(_stringWriter);\r
}\r
- \r
+\r
/**\r
* Constructs an empty EpsDevice that writes directly to a file.\r
* Bounds must be set before use.\r
_bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));\r
write(_bufferedWriter);\r
}\r
- \r
- \r
+\r
+\r
/**\r
* Returns the title of the EPS document.\r
*/\r
public synchronized String getTitle() {\r
return _title;\r
}\r
- \r
- \r
+\r
+\r
/**\r
* Updates the bounds of the current EPS document.\r
*/\r
minY = (float) y;\r
}\r
}\r
- \r
- \r
+\r
+\r
/**\r
* Appends a line to the EpsDocument. A new line character is added\r
* to the end of the line when it is added.\r
}\r
}\r
_lastG = g;\r
- \r
+\r
try {\r
_bufferedWriter.write(line + "\n");\r
}\r
throw new EpsException("Could not write to the output file: " + e);\r
}\r
}\r
- \r
- \r
+\r
+\r
/**\r
* Outputs the contents of the EPS document to the specified\r
* Writer, complete with headers and bounding box.\r
public synchronized void write(Writer writer) throws IOException {\r
float offsetX = -minX;\r
float offsetY = -minY;\r
- \r
+\r
writer.write("%!PS-Adobe-3.0 EPSF-3.0\n");\r
- writer.write("%%Creator: EpsGraphics2D " + EpsGraphics2D.VERSION + " by Paul Mutton, http://www.jibble.org/\n");\r
+ writer.write("%%Creator: Jalview " + jalview.bin.Cache.VERSION + " \n");\r
writer.write("%%Title: " + _title + "\n");\r
writer.write("%%CreationDate: " + new Date() + "\n");\r
writer.write("%%BoundingBox: 0 0 " + ((int) Math.ceil(maxX + offsetX)) + " " + ((int) Math.ceil(maxY + offsetY)) + "\n");\r
writer.write("%%Pages: 1\n");\r
writer.write("%%Page: 1 1\n");\r
writer.write("%%EndComments\n\n");\r
- \r
+\r
writer.write("gsave\n");\r
- \r
+\r
if (_stringWriter != null) {\r
writer.write(offsetX + " " + (offsetY) + " translate\n");\r
- \r
+\r
_bufferedWriter.flush();\r
StringBuffer buffer = _stringWriter.getBuffer();\r
for (int i = 0; i < buffer.length(); i++) {\r
writer.write(buffer.charAt(i));\r
}\r
- \r
+\r
writeFooter(writer);\r
}\r
else {\r
writer.write(offsetX + " " + ((maxY - minY) - offsetY) + " translate\n");\r
}\r
- \r
+\r
writer.flush();\r
}\r
- \r
- \r
+\r
+\r
private void writeFooter(Writer writer) throws IOException {\r
writer.write("grestore\n");\r
if (isClipSet()) {\r
writer.write("%%EOF");\r
writer.flush();\r
}\r
- \r
- \r
+\r
+\r
public synchronized void flush() throws IOException {\r
_bufferedWriter.flush();\r
}\r
- \r
+\r
public synchronized void close() throws IOException {\r
if (_stringWriter == null) {\r
writeFooter(_bufferedWriter);\r
_bufferedWriter.close();\r
}\r
}\r
- \r
- \r
+\r
+\r
public boolean isClipSet() {\r
return _isClipSet;\r
}\r
- \r
+\r
public void setClipSet(boolean isClipSet) {\r
_isClipSet = isClipSet;\r
}\r
- \r
- \r
+\r
+\r
private float minX;\r
private float minY;\r
private float maxX;\r
private float maxY;\r
- \r
+\r
private boolean _isClipSet = false;\r
\r
private String _title;\r
private StringWriter _stringWriter;\r
private BufferedWriter _bufferedWriter = null;\r
- \r
+\r
// We need to remember which was the last EpsGraphics2D object to use\r
// us, as we need to replace the clipping region if another EpsGraphics2D\r
// object tries to use us.\r
private EpsGraphics2D _lastG = null;\r
- \r
-}
\ No newline at end of file
+\r
+}\r