Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / src / javajs / img / PdfEncoder.java
index 34aa41c..c75b032 100644 (file)
-/* $RCSfile$\r
- * $Author: hansonr $\r
- * $Date: 2009-06-30 18:58:33 -0500 (Tue, 30 Jun 2009) $\r
- * $Revision: 11158 $\r
- *\r
- * Copyright (C) 2002-2005  The Jmol Development Team\r
- *\r
- * Contact: jmol-developers@lists.sf.net\r
- *\r
- *  This library is free software; you can redistribute it and/or\r
- *  modify it under the terms of the GNU Lesser General Public\r
- *  License as published by the Free Software Foundation; either\r
- *  version 2.1 of the License, or (at your option) any later version.\r
- *\r
- *  This library is distributed in the hope that it will be useful,\r
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
- *  Lesser General Public License for more details.\r
- *\r
- *  You should have received a copy of the GNU Lesser General Public\r
- *  License along with this library; if not, write to the Free Software\r
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
- */\r
-package javajs.img;\r
-\r
-import java.util.Hashtable;\r
-import java.util.Map;\r
-\r
-import javajs.export.PDFCreator;\r
-\r
-/**\r
- * A relatively primitive PDF generator that just makes a document with an image\r
- * in it.\r
- * \r
- */\r
-public class PdfEncoder extends ImageEncoder {\r
-\r
-  private boolean isLandscape;\r
-  private PDFCreator pdf;\r
-  private String comment;\r
-\r
-  public PdfEncoder() {\r
-    // for Class.forName  \r
-  }\r
-\r
-  @Override\r
-  protected void setParams(Map<String, Object> params) {\r
-       isLandscape = (quality > 1);\r
-    comment = "Jmol " + (String) params.get("comment");\r
-  }\r
-\r
-  @Override\r
-  protected void generate() throws Exception {\r
-    pdf = new PDFCreator();\r
-    int pageWidth = 8 * 72;\r
-    int pageHeight = 11 * 72;\r
-    pdf.setOutputStream(out);\r
-    pdf.newDocument(pageWidth, pageHeight, isLandscape); // A4 or Letter\r
-    addMyImage(pageWidth, pageHeight);\r
-    Map<String, String> ht = new Hashtable<String, String>();\r
-    if (comment != null)\r
-      ht.put("Producer", comment);\r
-    ht.put("Author", "JMol");\r
-    ht.put("CreationDate", date);\r
-    pdf.addInfo(ht);\r
-    pdf.closeDocument();\r
-  }\r
-\r
-  \r
-  /**\r
-   * centered on the page\r
-   * \r
-   * @param pageWidth\r
-   * @param pageHeight\r
-   */\r
-  private void addMyImage(int pageWidth, int pageHeight) {\r
-    pdf.addImageResource("img1", width, height, pixels, true);\r
-    int w = (isLandscape ? pageHeight : pageWidth);\r
-    int h = (isLandscape ? pageWidth : pageHeight);\r
-    int iw = width;\r
-    int ih = height;\r
-    if (iw > 0.9 * w) {\r
-      ih = (int) (ih * 0.9 * w / iw);\r
-      iw = (int) (w * 0.9);\r
-    }\r
-    if (ih > 0.9 * h) {\r
-      iw = (int) (iw * 0.9 * h / ih);\r
-      ih = (int) (h * 0.9);\r
-    }\r
-    int x = 0;\r
-    int y = 0;\r
-    int x1 = iw;\r
-    int y1 = ih;\r
-    if (w > iw) {\r
-      x = (w - iw) / 2;\r
-      x1 = iw + x;\r
-    }\r
-    if (h > ih) {\r
-      y = (h - ih) / 2;\r
-      y1 = ih + y;\r
-    }\r
-    pdf.drawImage("img1", x, y, x1, y1, 0, 0, width, height);\r
-  }\r
-\r
-}\r
+/* $RCSfile$
+ * $Author: hansonr $
+ * $Date: 2009-06-30 18:58:33 -0500 (Tue, 30 Jun 2009) $
+ * $Revision: 11158 $
+ *
+ * Copyright (C) 2002-2005  The Jmol Development Team
+ *
+ * Contact: jmol-developers@lists.sf.net
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+package javajs.img;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import javajs.export.PDFCreator;
+
+/**
+ * A relatively primitive PDF generator that just makes a document with an image
+ * in it.
+ * 
+ */
+public class PdfEncoder extends ImageEncoder {
+
+  private boolean isLandscape;
+  private PDFCreator pdf;
+  private String comment;
+
+  public PdfEncoder() {
+    // for Class.forName  
+  }
+
+  @Override
+  protected void setParams(Map<String, Object> params) {
+       isLandscape = (quality > 1);
+    comment = "Jmol " + (String) params.get("comment");
+  }
+
+  @Override
+  protected void generate() throws Exception {
+    pdf = new PDFCreator();
+    int pageWidth = 8 * 72;
+    int pageHeight = 11 * 72;
+    pdf.setOutputStream(out);
+    pdf.newDocument(pageWidth, pageHeight, isLandscape); // A4 or Letter
+    addMyImage(pageWidth, pageHeight);
+    Map<String, String> ht = new Hashtable<String, String>();
+    if (comment != null)
+      ht.put("Producer", comment);
+    ht.put("Author", "JMol");
+    ht.put("CreationDate", date);
+    pdf.addInfo(ht);
+    pdf.closeDocument();
+  }
+
+  
+  /**
+   * centered on the page
+   * 
+   * @param pageWidth
+   * @param pageHeight
+   */
+  private void addMyImage(int pageWidth, int pageHeight) {
+    pdf.addImageResource("img1", width, height, pixels, true);
+    int w = (isLandscape ? pageHeight : pageWidth);
+    int h = (isLandscape ? pageWidth : pageHeight);
+    int iw = width;
+    int ih = height;
+    if (iw > 0.9 * w) {
+      ih = (int) (ih * 0.9 * w / iw);
+      iw = (int) (w * 0.9);
+    }
+    if (ih > 0.9 * h) {
+      iw = (int) (iw * 0.9 * h / ih);
+      ih = (int) (h * 0.9);
+    }
+    int x = 0;
+    int y = 0;
+    int x1 = iw;
+    int y1 = ih;
+    if (w > iw) {
+      x = (w - iw) / 2;
+      x1 = iw + x;
+    }
+    if (h > ih) {
+      y = (h - ih) / 2;
+      y1 = ih + y;
+    }
+    pdf.drawImage("img1", x, y, x1, y1, 0, 0, width, height);
+  }
+
+}