File size: 5,103 Bytes
233f6d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Clazz.declarePackage ("JSV.common");
Clazz.load (["JSV.api.JSVPdfWriter", "J.api.GenericGraphics"], "JSV.common.PDFWriter", ["java.util.Hashtable", "javajs.export.PDFCreator", "JU.CU", "JSV.common.JSVersion"], function () {
c$ = Clazz.decorateAsClass (function () {
this.g2d = null;
this.date = null;
this.pdf = null;
this.inPath = false;
this.rgb = null;
Clazz.instantialize (this, arguments);
}, JSV.common, "PDFWriter", null, [J.api.GenericGraphics, JSV.api.JSVPdfWriter]);
Clazz.prepareFields (c$, function () {
this.rgb =  Clazz.newFloatArray (3, 0);
});
Clazz.makeConstructor (c$, 
function () {
this.pdf =  new javajs["export"].PDFCreator ();
});
Clazz.overrideMethod (c$, "createPdfDocument", 
function (panel, pl, os) {
var isLandscape = pl.layout.equals ("landscape");
this.date = pl.date;
this.pdf.setOutputStream (os);
this.g2d = panel.getPanelData ().g2d;
try {
this.pdf.newDocument (pl.paperWidth, pl.paperHeight, isLandscape);
var ht =  new java.util.Hashtable ();
ht.put ("Producer", JSV.common.JSVersion.VERSION);
ht.put ("Creator", "JSpecView " + JSV.common.JSVersion.VERSION);
ht.put ("Author", "JSpecView");
if (this.date != null) ht.put ("CreationDate", this.date);
this.pdf.addInfo (ht);
panel.getPanelData ().printPdf (this, pl);
this.pdf.closeDocument ();
} catch (e) {
if (Clazz.exceptionOf (e, Exception)) {
panel.showMessage (e.toString (), "PDF Creation Error");
} else {
throw e;
}
}
}, "JSV.api.JSVPanel,JSV.common.PrintLayout,java.io.OutputStream");
Clazz.overrideMethod (c$, "canDoLineTo", 
function () {
return true;
});
Clazz.overrideMethod (c$, "doStroke", 
function (g, isBegin) {
this.inPath = isBegin;
if (!this.inPath) this.pdf.stroke ();
}, "~O,~B");
Clazz.overrideMethod (c$, "drawCircle", 
function (g, x, y, diameter) {
this.pdf.doCircle (x, y, Clazz.doubleToInt (diameter / 2.0), false);
}, "~O,~N,~N,~N");
Clazz.overrideMethod (c$, "drawLine", 
function (g, x0, y0, x1, y1) {
this.pdf.moveto (x0, y0);
this.pdf.lineto (x1, y1);
if (!this.inPath) this.pdf.stroke ();
}, "~O,~N,~N,~N,~N");
Clazz.overrideMethod (c$, "drawPolygon", 
function (g, axPoints, ayPoints, nPoints) {
this.pdf.doPolygon (axPoints, ayPoints, nPoints, false);
}, "~O,~A,~A,~N");
Clazz.overrideMethod (c$, "drawRect", 
function (g, x, y, width, height) {
this.pdf.doRect (x, y, width, height, false);
}, "~O,~N,~N,~N,~N");
Clazz.overrideMethod (c$, "drawString", 
function (g, s, x, y) {
this.pdf.drawStringRotated (s, x, y, 0);
}, "~O,~S,~N,~N");
Clazz.overrideMethod (c$, "drawStringRotated", 
function (g, s, x, y, angle) {
this.pdf.drawStringRotated (s, x, y, Clazz.doubleToInt (angle));
}, "~O,~S,~N,~N,~N");
Clazz.overrideMethod (c$, "fillBackground", 
function (g, bgcolor) {
}, "~O,javajs.api.GenericColor");
Clazz.overrideMethod (c$, "fillCircle", 
function (g, x, y, diameter) {
this.pdf.doCircle (x, y, Clazz.doubleToInt (diameter / 2.0), true);
}, "~O,~N,~N,~N");
Clazz.overrideMethod (c$, "fillPolygon", 
function (g, ayPoints, axPoints, nPoints) {
this.pdf.doPolygon (axPoints, ayPoints, nPoints, true);
}, "~O,~A,~A,~N");
Clazz.overrideMethod (c$, "fillRect", 
function (g, x, y, width, height) {
this.pdf.doRect (x, y, width, height, true);
}, "~O,~N,~N,~N,~N");
Clazz.overrideMethod (c$, "lineTo", 
function (g, x, y) {
this.pdf.lineto (x, y);
}, "~O,~N,~N");
Clazz.overrideMethod (c$, "setGraphicsColor", 
function (g, c) {
JU.CU.toRGB3f (c.getRGB (), this.rgb);
this.pdf.setColor (this.rgb, true);
this.pdf.setColor (this.rgb, false);
}, "~O,javajs.api.GenericColor");
Clazz.overrideMethod (c$, "setFont", 
function (g, font) {
var fname = "/Helvetica";
switch (font.idFontStyle) {
case 1:
fname += "-Bold";
break;
case 3:
fname += "-BoldOblique";
break;
case 2:
fname += "-Oblique";
break;
}
this.pdf.setFont (fname, font.fontSizeNominal);
return font;
}, "~O,javajs.awt.Font");
Clazz.overrideMethod (c$, "setStrokeBold", 
function (g, tf) {
this.pdf.setLineWidth (tf ? 2 : 1);
}, "~O,~B");
Clazz.overrideMethod (c$, "translateScale", 
function (g, x, y, scale) {
this.pdf.translateScale (x, y, scale);
}, "~O,~N,~N,~N");
Clazz.overrideMethod (c$, "newGrayScaleImage", 
function (g, image, width, height, buffer) {
this.pdf.addImageResource (image, width, height, buffer, false);
return image;
}, "~O,~O,~N,~N,~A");
Clazz.overrideMethod (c$, "drawGrayScaleImage", 
function (g, image, destX0, destY0, destX1, destY1, srcX0, srcY0, srcX1, srcY1) {
this.pdf.drawImage (image, destX0, destY0, destX1, destY1, srcX0, srcY0, srcX1, srcY1);
}, "~O,~O,~N,~N,~N,~N,~N,~N,~N,~N");
Clazz.overrideMethod (c$, "setWindowParameters", 
function (width, height) {
}, "~N,~N");
Clazz.defineMethod (c$, "getColor1", 
function (argb) {
return this.g2d.getColor1 (argb);
}, "~N");
Clazz.defineMethod (c$, "getColor3", 
function (red, green, blue) {
return this.g2d.getColor3 (red, green, blue);
}, "~N,~N,~N");
Clazz.defineMethod (c$, "getColor4", 
function (r, g, b, a) {
return this.g2d.getColor4 (r, g, b, a);
}, "~N,~N,~N,~N");
});