1 | (function() {
|
2 | var PDFObject, PDFOutline, PDFPage;
|
3 |
|
4 | PDFObject = require('./object');
|
5 |
|
6 | PDFPage = require('./page');
|
7 |
|
8 | PDFOutline = (function() {
|
9 | function PDFOutline(document, parent, title, dest, options1) {
|
10 | this.document = document;
|
11 | this.options = options1 != null ? options1 : {
|
12 | expanded: false
|
13 | };
|
14 | this.outlineData = {};
|
15 | if (dest !== null) {
|
16 | this.outlineData['Dest'] = [dest.dictionary, 'Fit'];
|
17 | }
|
18 | if (parent !== null) {
|
19 | this.outlineData['Parent'] = parent;
|
20 | }
|
21 | if (title !== null) {
|
22 | this.outlineData['Title'] = new String(title);
|
23 | }
|
24 | this.dictionary = this.document.ref(this.outlineData);
|
25 | this.children = [];
|
26 | }
|
27 |
|
28 | PDFOutline.prototype.addItem = function(title, options) {
|
29 | var result;
|
30 | if (options == null) {
|
31 | options = {
|
32 | expanded: false
|
33 | };
|
34 | }
|
35 | result = new PDFOutline(this.document, this.dictionary, title, this.document.page, options);
|
36 | this.children.push(result);
|
37 | return result;
|
38 | };
|
39 |
|
40 | PDFOutline.prototype.endOutline = function() {
|
41 | var child, first, i, j, last, ref, ref1;
|
42 | if (this.children.length > 0) {
|
43 | if (this.options.expanded) {
|
44 | this.outlineData.Count = this.children.length;
|
45 | }
|
46 | ref = this.children, first = ref[0], last = ref[ref.length - 1];
|
47 | this.outlineData.First = first.dictionary;
|
48 | this.outlineData.Last = last.dictionary;
|
49 | for (i = j = 0, ref1 = this.children.length; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) {
|
50 | child = this.children[i];
|
51 | if (i > 0) {
|
52 | child.outlineData.Prev = this.children[i - 1].dictionary;
|
53 | }
|
54 | if (i < this.children.length - 1) {
|
55 | child.outlineData.Next = this.children[i + 1].dictionary;
|
56 | }
|
57 | child.endOutline();
|
58 | }
|
59 | }
|
60 | return this.dictionary.end();
|
61 | };
|
62 |
|
63 | return PDFOutline;
|
64 |
|
65 | })();
|
66 |
|
67 | module.exports = PDFOutline;
|
68 |
|
69 | }).call(this);
|