JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / javajs / img / PdfEncoder.js
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;
5 this.pdf = null;
6 this.comment = null;
7 Clazz.instantialize (this, arguments);
8 }, javajs.img, "PdfEncoder", javajs.img.ImageEncoder);
9 Clazz.makeConstructor (c$, 
10 function () {
11 Clazz.superConstructor (this, javajs.img.PdfEncoder, []);
12 });
13 Clazz.overrideMethod (c$, "setParams", 
14 function (params) {
15 this.isLandscape = (this.quality > 1);
16 this.comment = "Jmol " + params.get ("comment");
17 }, "java.util.Map");
18 Clazz.overrideMethod (c$, "generate", 
19 function () {
20 this.pdf =  new javajs["export"].PDFCreator ();
21 var pageWidth = 576;
22 var pageHeight = 792;
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 ();
32 });
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);
38 var iw = this.width;
39 var ih = this.height;
40 if (iw > 0.9 * w) {
41 ih = Clazz.doubleToInt (ih * 0.9 * w / iw);
42 iw = Clazz.doubleToInt (w * 0.9);
43 }if (ih > 0.9 * h) {
44 iw = Clazz.doubleToInt (iw * 0.9 * h / ih);
45 ih = Clazz.doubleToInt (h * 0.9);
46 }var x = 0;
47 var y = 0;
48 var x1 = iw;
49 var y1 = ih;
50 if (w > iw) {
51 x = Clazz.doubleToInt ((w - iw) / 2);
52 x1 = iw + x;
53 }if (h > ih) {
54 y = Clazz.doubleToInt ((h - ih) / 2);
55 y1 = ih + y;
56 }this.pdf.drawImage ("img1", x, y, x1, y1, 0, 0, this.width, this.height);
57 }, $fz.isPrivate = true, $fz), "~N,~N");
58 });