1 Clazz.declarePackage ("javajs.img");
2 Clazz.load (["javajs.img.ImageEncoder"], "javajs.img.PdfEncoder", ["java.util.Hashtable", "javajs.export.PDFCreator"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.isLandscape = false;
7 Clazz.instantialize (this, arguments);
8 }, javajs.img, "PdfEncoder", javajs.img.ImageEncoder);
9 Clazz.makeConstructor (c$,
11 Clazz.superConstructor (this, javajs.img.PdfEncoder, []);
13 Clazz.overrideMethod (c$, "setParams",
15 this.isLandscape = (this.quality > 1);
16 this.comment = "Jmol " + params.get ("comment");
18 Clazz.overrideMethod (c$, "generate",
20 this.pdf = new javajs["export"].PDFCreator ();
23 this.pdf.setOutputStream (this.out);
24 this.pdf.newDocument (pageWidth, pageHeight, this.isLandscape);
25 this.addMyImage (pageWidth, pageHeight);
26 var ht = new java.util.Hashtable ();
27 if (this.comment != null) ht.put ("Producer", this.comment);
28 ht.put ("Author", "JMol");
29 ht.put ("CreationDate", this.date);
30 this.pdf.addInfo (ht);
31 this.pdf.closeDocument ();
33 Clazz.defineMethod (c$, "addMyImage",
34 ($fz = function (pageWidth, pageHeight) {
35 this.pdf.addImageResource ("img1", this.width, this.height, this.pixels, true);
36 var w = (this.isLandscape ? pageHeight : pageWidth);
37 var h = (this.isLandscape ? pageWidth : pageHeight);
41 ih = Clazz.doubleToInt (ih * 0.9 * w / iw);
42 iw = Clazz.doubleToInt (w * 0.9);
44 iw = Clazz.doubleToInt (iw * 0.9 * h / ih);
45 ih = Clazz.doubleToInt (h * 0.9);
51 x = Clazz.doubleToInt ((w - iw) / 2);
54 y = Clazz.doubleToInt ((h - ih) / 2);
56 }this.pdf.drawImage ("img1", x, y, x1, y1, 0, 0, this.width, this.height);
57 }, $fz.isPrivate = true, $fz), "~N,~N");