Skip to content

Commit c53b3ee

Browse files
committed
merge PR#317 from isimisi:dev
2 parents e23cb1a + cb66f23 commit c53b3ee

9 files changed

Lines changed: 4480 additions & 1573 deletions

File tree

base/display/metadata.js

Lines changed: 78 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -18,80 +18,94 @@
1818

1919
'use strict';
2020

21-
var Metadata = PDFJS.Metadata = (function MetadataClosure() {
22-
function fixMetadata(meta) {
23-
return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
24-
var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
25-
function(code, d1, d2, d3) {
26-
return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
21+
var Metadata = (PDFJS.Metadata = (function MetadataClosure() {
22+
function fixMetadata(meta) {
23+
return meta.replace(/>\\376\\377([^<]+)/g, function (all, codes) {
24+
var bytes = codes.replace(
25+
/\\([0-3])([0-7])([0-7])/g,
26+
function (code, d1, d2, d3) {
27+
return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
28+
}
29+
);
30+
var chars = '';
31+
for (var i = 0; i < bytes.length; i += 2) {
32+
var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
33+
chars +=
34+
code >= 32 &&
35+
code < 127 &&
36+
code != 60 &&
37+
code != 62 &&
38+
code != 38 &&
39+
false
40+
? String.fromCharCode(code)
41+
: '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
42+
}
43+
return '>' + chars;
2744
});
28-
var chars = '';
29-
for (var i = 0; i < bytes.length; i += 2) {
30-
var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
31-
chars += code >= 32 && code < 127 && code != 60 && code != 62 &&
32-
code != 38 && false ? String.fromCharCode(code) :
33-
'&#x' + (0x10000 + code).toString(16).substring(1) + ';';
34-
}
35-
return '>' + chars;
36-
});
37-
}
45+
}
3846

39-
function Metadata(meta) {
40-
if (typeof meta === 'string') {
41-
// Ghostscript produces invalid metadata
42-
meta = fixMetadata(meta);
47+
function Metadata(meta) {
48+
if (typeof meta === 'string') {
49+
// Ghostscript produces invalid metadata
50+
meta = fixMetadata(meta);
4351

44-
var parser = new DOMParser();
45-
meta = parser.parseFromString(meta, 'application/xml');
46-
} else if (!(meta instanceof Document)) {
47-
error('Metadata: Invalid metadata object');
48-
}
52+
var parser = new DOMParser();
53+
meta = parser.parseFromString(meta, 'application/xml');
54+
} else if (!(meta instanceof Document)) {
55+
error('Metadata: Invalid metadata object');
56+
}
4957

50-
this.metaDocument = meta;
51-
this.metadata = {};
52-
this.parse();
53-
}
58+
this.metaDocument = meta;
59+
this.metadata = {};
60+
this.parse();
61+
}
5462

55-
Metadata.prototype = {
56-
parse: function Metadata_parse() {
57-
var doc = this.metaDocument;
58-
var rdf = doc.documentElement;
63+
Metadata.prototype = {
64+
parse: function Metadata_parse() {
65+
var doc = this.metaDocument;
66+
var rdf = doc.documentElement;
5967

60-
if (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
61-
rdf = rdf.firstChild;
62-
while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf')
63-
rdf = rdf.nextSibling;
64-
}
68+
if (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
69+
// Wrapped in <xmpmeta>
70+
rdf = rdf.firstChild;
71+
while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf')
72+
rdf = rdf.nextSibling;
73+
}
6574

66-
var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
67-
if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes())
68-
return;
75+
var nodeName = rdf ? rdf.nodeName.toLowerCase() : null;
76+
if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) return;
6977

70-
var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
78+
var children = rdf.childNodes,
79+
desc,
80+
entry,
81+
name,
82+
i,
83+
ii,
84+
length,
85+
iLength;
7186

72-
for (i = 0, length = children.length; i < length; i++) {
73-
desc = children[i];
74-
if (desc.nodeName.toLowerCase() !== 'rdf:description')
75-
continue;
87+
for (i = 0, length = children.length; i < length; i++) {
88+
desc = children[i];
89+
if (desc.nodeName.toLowerCase() !== 'rdf:description') continue;
7690

77-
for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
78-
if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
79-
entry = desc.childNodes[ii];
80-
name = entry.nodeName.toLowerCase();
81-
this.metadata[name] = entry.textContent.trim();
82-
}
83-
}
84-
}
85-
},
91+
for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
92+
if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
93+
entry = desc.childNodes[ii];
94+
name = entry.nodeName.toLowerCase();
95+
this.metadata[name] = entry.textContent.trim();
96+
}
97+
}
98+
}
99+
},
86100

87-
get: function Metadata_get(name) {
88-
return this.metadata[name] || null;
89-
},
101+
get: function Metadata_get(name) {
102+
return this.metadata[name] || null;
103+
},
90104

91-
has: function Metadata_has(name) {
92-
return typeof this.metadata[name] !== 'undefined';
93-
}
94-
};
105+
has: function Metadata_has(name) {
106+
return typeof this.metadata[name] !== 'undefined';
107+
},
108+
};
95109

96-
return Metadata;
97-
})();
110+
return Metadata;
111+
})());

0 commit comments

Comments
 (0)