1 Clazz.declarePackage ("javajs.export");
2 Clazz.load (["javajs.util.SB"], "javajs.export.PDFObject", ["java.io.ByteArrayOutputStream", "java.util.Hashtable", "$.Map", "java.util.zip.Deflater", "$.DeflaterOutputStream"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.dictionary = null;
10 Clazz.instantialize (this, arguments);
11 }, javajs["export"], "PDFObject", javajs.util.SB);
12 Clazz.makeConstructor (c$,
14 Clazz.superConstructor (this, javajs["export"].PDFObject, []);
17 Clazz.defineMethod (c$, "getRef",
19 return this.index + " 0 R";
21 Clazz.defineMethod (c$, "getID",
23 return this.type.substring (0, 1) + this.index;
25 Clazz.defineMethod (c$, "isFont",
27 return "Font".equals (this.type);
29 Clazz.defineMethod (c$, "setStream",
33 Clazz.defineMethod (c$, "getDef",
35 return this.dictionary.get (key);
37 Clazz.defineMethod (c$, "addDef",
38 function (key, value) {
39 if (this.dictionary == null) this.dictionary = new java.util.Hashtable ();
40 this.dictionary.put (key, value);
41 if (key.equals ("Type")) this.type = (value).substring (1);
43 Clazz.defineMethod (c$, "setAsStream",
45 this.stream = this.toBytes (0, -1);
48 Clazz.defineMethod (c$, "output",
51 var s = this.index + " 0 obj\n";
52 this.write (os, s.getBytes (), 0);
54 if (this.dictionary != null) {
55 if (this.dictionary.containsKey ("Length")) {
56 if (this.stream == null) this.setAsStream ();
57 streamLen = this.stream.length;
58 var doDeflate = (streamLen > 1000);
60 var deflater = new java.util.zip.Deflater (9);
61 var outBytes = new java.io.ByteArrayOutputStream (1024);
62 var compBytes = new java.util.zip.DeflaterOutputStream (outBytes, deflater);
63 compBytes.write (this.stream, 0, streamLen);
65 this.stream = outBytes.toByteArray ();
66 this.dictionary.put ("Filter", "/FlateDecode");
67 streamLen = this.stream.length;
68 }this.dictionary.put ("Length", "" + streamLen);
69 }this.write (os, this.getDictionaryText (this.dictionary, "\n").getBytes (), 0);
70 }if (this.length () > 0) this.write (os, this.toString ().getBytes (), 0);
71 if (this.stream != null) {
72 this.write (os, "stream\r\n".getBytes (), 0);
73 this.write (os, this.stream, streamLen);
74 this.write (os, "\r\nendstream\r\n".getBytes (), 0);
75 }if (this.index > 0) this.write (os, "endobj\n".getBytes (), 0);
77 }, "java.io.OutputStream");
78 Clazz.defineMethod (c$, "write",
79 ($fz = function (os, bytes, nBytes) {
80 if (nBytes == 0) nBytes = bytes.length;
82 os.write (bytes, 0, nBytes);
83 }, $fz.isPrivate = true, $fz), "java.io.OutputStream,~A,~N");
84 Clazz.defineMethod (c$, "getDictionaryText",
85 ($fz = function (d, nl) {
86 var sb = new javajs.util.SB ();
88 if (d.containsKey ("Type")) sb.append ("/Type").appendO (d.get ("Type"));
89 for (var e, $e = d.entrySet ().iterator (); $e.hasNext () && ((e = $e.next ()) || true);) {
91 if (s.equals ("Type") || s.startsWith ("!")) continue;
93 var o = e.getValue ();
94 if (Clazz.instanceOf (o, java.util.Map)) {
95 sb.append ((this.getDictionaryText (o, "")));
98 if (!s.startsWith ("/")) sb.append (" ");
101 return (sb.length () > 3 ? sb.append (">>").append (nl).toString () : "");
102 }, $fz.isPrivate = true, $fz), "java.util.Map,~S");
103 Clazz.defineMethod (c$, "createSubdict",
104 ($fz = function (d0, dict) {
105 var d = d0.get (dict);
106 if (d == null) d0.put (dict, d = new java.util.Hashtable ());
108 }, $fz.isPrivate = true, $fz), "java.util.Map,~S");
109 Clazz.defineMethod (c$, "addResource",
110 function (type, key, value) {
111 var r = this.createSubdict (this.dictionary, "Resources");
112 if (type != null) r = this.createSubdict (r, type);