|
|
@ -2385,57 +2385,57 @@ var RefSet = (function refSet() { |
|
|
|
return constructor; |
|
|
|
return constructor; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
function IsBool(v) { |
|
|
|
function isBool(v) { |
|
|
|
return typeof v == 'boolean'; |
|
|
|
return typeof v == 'boolean'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsInt(v) { |
|
|
|
function isInt(v) { |
|
|
|
return typeof v == 'number' && ((v | 0) == v); |
|
|
|
return typeof v == 'number' && ((v | 0) == v); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsNum(v) { |
|
|
|
function isNum(v) { |
|
|
|
return typeof v == 'number'; |
|
|
|
return typeof v == 'number'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsString(v) { |
|
|
|
function isString(v) { |
|
|
|
return typeof v == 'string'; |
|
|
|
return typeof v == 'string'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsNull(v) { |
|
|
|
function isNull(v) { |
|
|
|
return v === null; |
|
|
|
return v === null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsName(v) { |
|
|
|
function isName(v) { |
|
|
|
return v instanceof Name; |
|
|
|
return v instanceof Name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsCmd(v, cmd) { |
|
|
|
function isCmd(v, cmd) { |
|
|
|
return v instanceof Cmd && (!cmd || v.cmd == cmd); |
|
|
|
return v instanceof Cmd && (!cmd || v.cmd == cmd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsDict(v, type) { |
|
|
|
function isDict(v, type) { |
|
|
|
return v instanceof Dict && (!type || v.get('Type').name == type); |
|
|
|
return v instanceof Dict && (!type || v.get('Type').name == type); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsArray(v) { |
|
|
|
function isArray(v) { |
|
|
|
return v instanceof Array; |
|
|
|
return v instanceof Array; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsStream(v) { |
|
|
|
function isStream(v) { |
|
|
|
return typeof v == 'object' && v != null && ('getChar' in v); |
|
|
|
return typeof v == 'object' && v != null && ('getChar' in v); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsRef(v) { |
|
|
|
function isRef(v) { |
|
|
|
return v instanceof Ref; |
|
|
|
return v instanceof Ref; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function IsPDFFunction(v) { |
|
|
|
function isPDFFunction(v) { |
|
|
|
var fnDict; |
|
|
|
var fnDict; |
|
|
|
if (typeof v != 'object') |
|
|
|
if (typeof v != 'object') |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
else if (IsDict(v)) |
|
|
|
else if (isDict(v)) |
|
|
|
fnDict = v; |
|
|
|
fnDict = v; |
|
|
|
else if (IsStream(v)) |
|
|
|
else if (isStream(v)) |
|
|
|
fnDict = v.dict; |
|
|
|
fnDict = v.dict; |
|
|
|
else |
|
|
|
else |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -2444,13 +2444,13 @@ function IsPDFFunction(v) { |
|
|
|
|
|
|
|
|
|
|
|
var EOF = {}; |
|
|
|
var EOF = {}; |
|
|
|
|
|
|
|
|
|
|
|
function IsEOF(v) { |
|
|
|
function isEOF(v) { |
|
|
|
return v == EOF; |
|
|
|
return v == EOF; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var None = {}; |
|
|
|
var None = {}; |
|
|
|
|
|
|
|
|
|
|
|
function IsNone(v) { |
|
|
|
function isNone(v) { |
|
|
|
return v == None; |
|
|
|
return v == None; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2484,7 +2484,7 @@ var Lexer = (function lexer() { |
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
|
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
function ToHexDigit(ch) { |
|
|
|
function toHexDigit(ch) { |
|
|
|
if (ch >= '0' && ch <= '9') |
|
|
|
if (ch >= '0' && ch <= '9') |
|
|
|
return ch.charCodeAt(0) - 48; |
|
|
|
return ch.charCodeAt(0) - 48; |
|
|
|
ch = ch.toUpperCase(); |
|
|
|
ch = ch.toUpperCase(); |
|
|
@ -2613,10 +2613,10 @@ var Lexer = (function lexer() { |
|
|
|
stream.skip(); |
|
|
|
stream.skip(); |
|
|
|
if (ch == '#') { |
|
|
|
if (ch == '#') { |
|
|
|
ch = stream.lookChar(); |
|
|
|
ch = stream.lookChar(); |
|
|
|
var x = ToHexDigit(ch); |
|
|
|
var x = toHexDigit(ch); |
|
|
|
if (x != -1) { |
|
|
|
if (x != -1) { |
|
|
|
stream.skip(); |
|
|
|
stream.skip(); |
|
|
|
var x2 = ToHexDigit(stream.getChar()); |
|
|
|
var x2 = toHexDigit(stream.getChar()); |
|
|
|
if (x2 == -1) |
|
|
|
if (x2 == -1) |
|
|
|
error('Illegal digit in hex char in name: ' + x2); |
|
|
|
error('Illegal digit in hex char in name: ' + x2); |
|
|
|
str += String.fromCharCode((x << 4) | x2); |
|
|
|
str += String.fromCharCode((x << 4) | x2); |
|
|
@ -2647,14 +2647,14 @@ var Lexer = (function lexer() { |
|
|
|
} |
|
|
|
} |
|
|
|
if (specialChars[ch.charCodeAt(0)] != 1) { |
|
|
|
if (specialChars[ch.charCodeAt(0)] != 1) { |
|
|
|
var x, x2; |
|
|
|
var x, x2; |
|
|
|
if ((x = ToHexDigit(ch)) == -1) |
|
|
|
if ((x = toHexDigit(ch)) == -1) |
|
|
|
error('Illegal character in hex string: ' + ch); |
|
|
|
error('Illegal character in hex string: ' + ch); |
|
|
|
|
|
|
|
|
|
|
|
ch = stream.getChar(); |
|
|
|
ch = stream.getChar(); |
|
|
|
while (specialChars[ch.charCodeAt(0)] == 1) |
|
|
|
while (specialChars[ch.charCodeAt(0)] == 1) |
|
|
|
ch = stream.getChar(); |
|
|
|
ch = stream.getChar(); |
|
|
|
|
|
|
|
|
|
|
|
if ((x2 = ToHexDigit(ch)) == -1) |
|
|
|
if ((x2 = toHexDigit(ch)) == -1) |
|
|
|
error('Illegal character in hex string: ' + ch); |
|
|
|
error('Illegal character in hex string: ' + ch); |
|
|
|
|
|
|
|
|
|
|
|
str += String.fromCharCode((x << 4) | x2); |
|
|
|
str += String.fromCharCode((x << 4) | x2); |
|
|
@ -2773,7 +2773,7 @@ var Parser = (function parserParser() { |
|
|
|
this.buf2 = this.lexer.getObj(); |
|
|
|
this.buf2 = this.lexer.getObj(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
shift: function parserShift() { |
|
|
|
shift: function parserShift() { |
|
|
|
if (IsCmd(this.buf2, 'ID')) { |
|
|
|
if (isCmd(this.buf2, 'ID')) { |
|
|
|
this.buf1 = this.buf2; |
|
|
|
this.buf1 = this.buf2; |
|
|
|
this.buf2 = null; |
|
|
|
this.buf2 = null; |
|
|
|
// skip byte after ID
|
|
|
|
// skip byte after ID
|
|
|
@ -2784,50 +2784,50 @@ var Parser = (function parserParser() { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
getObj: function parserGetObj(cipherTransform) { |
|
|
|
getObj: function parserGetObj(cipherTransform) { |
|
|
|
if (IsCmd(this.buf1, 'BI')) { // inline image
|
|
|
|
if (isCmd(this.buf1, 'BI')) { // inline image
|
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
return this.makeInlineImage(cipherTransform); |
|
|
|
return this.makeInlineImage(cipherTransform); |
|
|
|
} |
|
|
|
} |
|
|
|
if (IsCmd(this.buf1, '[')) { // array
|
|
|
|
if (isCmd(this.buf1, '[')) { // array
|
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
var array = []; |
|
|
|
var array = []; |
|
|
|
while (!IsCmd(this.buf1, ']') && !IsEOF(this.buf1)) |
|
|
|
while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) |
|
|
|
array.push(this.getObj()); |
|
|
|
array.push(this.getObj()); |
|
|
|
if (IsEOF(this.buf1)) |
|
|
|
if (isEOF(this.buf1)) |
|
|
|
error('End of file inside array'); |
|
|
|
error('End of file inside array'); |
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
return array; |
|
|
|
return array; |
|
|
|
} |
|
|
|
} |
|
|
|
if (IsCmd(this.buf1, '<<')) { // dictionary or stream
|
|
|
|
if (isCmd(this.buf1, '<<')) { // dictionary or stream
|
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
var dict = new Dict(); |
|
|
|
var dict = new Dict(); |
|
|
|
while (!IsCmd(this.buf1, '>>') && !IsEOF(this.buf1)) { |
|
|
|
while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) { |
|
|
|
if (!IsName(this.buf1)) { |
|
|
|
if (!isName(this.buf1)) { |
|
|
|
error('Dictionary key must be a name object'); |
|
|
|
error('Dictionary key must be a name object'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var key = this.buf1.name; |
|
|
|
var key = this.buf1.name; |
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
if (IsEOF(this.buf1)) |
|
|
|
if (isEOF(this.buf1)) |
|
|
|
break; |
|
|
|
break; |
|
|
|
dict.set(key, this.getObj(cipherTransform)); |
|
|
|
dict.set(key, this.getObj(cipherTransform)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (IsEOF(this.buf1)) |
|
|
|
if (isEOF(this.buf1)) |
|
|
|
error('End of file inside dictionary'); |
|
|
|
error('End of file inside dictionary'); |
|
|
|
|
|
|
|
|
|
|
|
// stream objects are not allowed inside content streams or
|
|
|
|
// stream objects are not allowed inside content streams or
|
|
|
|
// object streams
|
|
|
|
// object streams
|
|
|
|
if (IsCmd(this.buf2, 'stream')) { |
|
|
|
if (isCmd(this.buf2, 'stream')) { |
|
|
|
return this.allowStreams ? |
|
|
|
return this.allowStreams ? |
|
|
|
this.makeStream(dict, cipherTransform) : dict; |
|
|
|
this.makeStream(dict, cipherTransform) : dict; |
|
|
|
} |
|
|
|
} |
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
return dict; |
|
|
|
return dict; |
|
|
|
} |
|
|
|
} |
|
|
|
if (IsInt(this.buf1)) { // indirect reference or integer
|
|
|
|
if (isInt(this.buf1)) { // indirect reference or integer
|
|
|
|
var num = this.buf1; |
|
|
|
var num = this.buf1; |
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
if (IsInt(this.buf1) && IsCmd(this.buf2, 'R')) { |
|
|
|
if (isInt(this.buf1) && isCmd(this.buf2, 'R')) { |
|
|
|
var ref = new Ref(num, this.buf1); |
|
|
|
var ref = new Ref(num, this.buf1); |
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
@ -2835,7 +2835,7 @@ var Parser = (function parserParser() { |
|
|
|
} |
|
|
|
} |
|
|
|
return num; |
|
|
|
return num; |
|
|
|
} |
|
|
|
} |
|
|
|
if (IsString(this.buf1)) { // string
|
|
|
|
if (isString(this.buf1)) { // string
|
|
|
|
var str = this.buf1; |
|
|
|
var str = this.buf1; |
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
if (cipherTransform) |
|
|
|
if (cipherTransform) |
|
|
@ -2854,13 +2854,13 @@ var Parser = (function parserParser() { |
|
|
|
|
|
|
|
|
|
|
|
// parse dictionary
|
|
|
|
// parse dictionary
|
|
|
|
var dict = new Dict(); |
|
|
|
var dict = new Dict(); |
|
|
|
while (!IsCmd(this.buf1, 'ID') && !IsEOF(this.buf1)) { |
|
|
|
while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) { |
|
|
|
if (!IsName(this.buf1)) { |
|
|
|
if (!isName(this.buf1)) { |
|
|
|
error('Dictionary key must be a name object'); |
|
|
|
error('Dictionary key must be a name object'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var key = this.buf1.name; |
|
|
|
var key = this.buf1.name; |
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
if (IsEOF(this.buf1)) |
|
|
|
if (isEOF(this.buf1)) |
|
|
|
break; |
|
|
|
break; |
|
|
|
dict.set(key, this.getObj(cipherTransform)); |
|
|
|
dict.set(key, this.getObj(cipherTransform)); |
|
|
|
} |
|
|
|
} |
|
|
@ -2901,7 +2901,7 @@ var Parser = (function parserParser() { |
|
|
|
var xref = this.xref; |
|
|
|
var xref = this.xref; |
|
|
|
if (xref) |
|
|
|
if (xref) |
|
|
|
length = xref.fetchIfRef(length); |
|
|
|
length = xref.fetchIfRef(length); |
|
|
|
if (!IsInt(length)) { |
|
|
|
if (!isInt(length)) { |
|
|
|
error('Bad ' + length + ' attribute in stream'); |
|
|
|
error('Bad ' + length + ' attribute in stream'); |
|
|
|
length = 0; |
|
|
|
length = 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -2910,7 +2910,7 @@ var Parser = (function parserParser() { |
|
|
|
stream.pos = pos + length; |
|
|
|
stream.pos = pos + length; |
|
|
|
this.shift(); // '>>'
|
|
|
|
this.shift(); // '>>'
|
|
|
|
this.shift(); // 'stream'
|
|
|
|
this.shift(); // 'stream'
|
|
|
|
if (!IsCmd(this.buf1, 'endstream')) |
|
|
|
if (!isCmd(this.buf1, 'endstream')) |
|
|
|
error('Missing endstream'); |
|
|
|
error('Missing endstream'); |
|
|
|
this.shift(); |
|
|
|
this.shift(); |
|
|
|
|
|
|
|
|
|
|
@ -2924,18 +2924,18 @@ var Parser = (function parserParser() { |
|
|
|
filter: function parserFilter(stream, dict, length) { |
|
|
|
filter: function parserFilter(stream, dict, length) { |
|
|
|
var filter = dict.get('Filter', 'F'); |
|
|
|
var filter = dict.get('Filter', 'F'); |
|
|
|
var params = dict.get('DecodeParms', 'DP'); |
|
|
|
var params = dict.get('DecodeParms', 'DP'); |
|
|
|
if (IsName(filter)) |
|
|
|
if (isName(filter)) |
|
|
|
return this.makeFilter(stream, filter.name, length, params); |
|
|
|
return this.makeFilter(stream, filter.name, length, params); |
|
|
|
if (IsArray(filter)) { |
|
|
|
if (isArray(filter)) { |
|
|
|
var filterArray = filter; |
|
|
|
var filterArray = filter; |
|
|
|
var paramsArray = params; |
|
|
|
var paramsArray = params; |
|
|
|
for (var i = 0, ii = filterArray.length; i < ii; ++i) { |
|
|
|
for (var i = 0, ii = filterArray.length; i < ii; ++i) { |
|
|
|
filter = filterArray[i]; |
|
|
|
filter = filterArray[i]; |
|
|
|
if (!IsName(filter)) |
|
|
|
if (!isName(filter)) |
|
|
|
error('Bad filter name: ' + filter); |
|
|
|
error('Bad filter name: ' + filter); |
|
|
|
else { |
|
|
|
else { |
|
|
|
params = null; |
|
|
|
params = null; |
|
|
|
if (IsArray(paramsArray) && (i in paramsArray)) |
|
|
|
if (isArray(paramsArray) && (i in paramsArray)) |
|
|
|
params = paramsArray[i]; |
|
|
|
params = paramsArray[i]; |
|
|
|
stream = this.makeFilter(stream, filter.name, length, params); |
|
|
|
stream = this.makeFilter(stream, filter.name, length, params); |
|
|
|
// after the first stream the length variable is invalid
|
|
|
|
// after the first stream the length variable is invalid
|
|
|
@ -2986,10 +2986,10 @@ var Linearization = (function linearizationLinearization() { |
|
|
|
var obj2 = this.parser.getObj(); |
|
|
|
var obj2 = this.parser.getObj(); |
|
|
|
var obj3 = this.parser.getObj(); |
|
|
|
var obj3 = this.parser.getObj(); |
|
|
|
this.linDict = this.parser.getObj(); |
|
|
|
this.linDict = this.parser.getObj(); |
|
|
|
if (IsInt(obj1) && IsInt(obj2) && IsCmd(obj3, 'obj') && |
|
|
|
if (isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && |
|
|
|
IsDict(this.linDict)) { |
|
|
|
isDict(this.linDict)) { |
|
|
|
var obj = this.linDict.get('Linearized'); |
|
|
|
var obj = this.linDict.get('Linearized'); |
|
|
|
if (!(IsNum(obj) && obj > 0)) |
|
|
|
if (!(isNum(obj) && obj > 0)) |
|
|
|
this.linDict = null; |
|
|
|
this.linDict = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -2998,8 +2998,8 @@ var Linearization = (function linearizationLinearization() { |
|
|
|
getInt: function linearizationGetInt(name) { |
|
|
|
getInt: function linearizationGetInt(name) { |
|
|
|
var linDict = this.linDict; |
|
|
|
var linDict = this.linDict; |
|
|
|
var obj; |
|
|
|
var obj; |
|
|
|
if (IsDict(linDict) && |
|
|
|
if (isDict(linDict) && |
|
|
|
IsInt(obj = linDict.get(name)) && |
|
|
|
isInt(obj = linDict.get(name)) && |
|
|
|
obj > 0) { |
|
|
|
obj > 0) { |
|
|
|
return obj; |
|
|
|
return obj; |
|
|
|
} |
|
|
|
} |
|
|
@ -3009,10 +3009,10 @@ var Linearization = (function linearizationLinearization() { |
|
|
|
getHint: function linearizationGetHint(index) { |
|
|
|
getHint: function linearizationGetHint(index) { |
|
|
|
var linDict = this.linDict; |
|
|
|
var linDict = this.linDict; |
|
|
|
var obj1, obj2; |
|
|
|
var obj1, obj2; |
|
|
|
if (IsDict(linDict) && |
|
|
|
if (isDict(linDict) && |
|
|
|
IsArray(obj1 = linDict.get('H')) && |
|
|
|
isArray(obj1 = linDict.get('H')) && |
|
|
|
obj1.length >= 2 && |
|
|
|
obj1.length >= 2 && |
|
|
|
IsInt(obj2 = obj1[index]) && |
|
|
|
isInt(obj2 = obj1[index]) && |
|
|
|
obj2 > 0) { |
|
|
|
obj2 > 0) { |
|
|
|
return obj2; |
|
|
|
return obj2; |
|
|
|
} |
|
|
|
} |
|
|
@ -3020,7 +3020,7 @@ var Linearization = (function linearizationLinearization() { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}, |
|
|
|
}, |
|
|
|
get length() { |
|
|
|
get length() { |
|
|
|
if (!IsDict(this.linDict)) |
|
|
|
if (!isDict(this.linDict)) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
return this.getInt('L'); |
|
|
|
return this.getInt('L'); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -3074,7 +3074,7 @@ var XRef = (function xRefXRef() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get the root dictionary (catalog) object
|
|
|
|
// get the root dictionary (catalog) object
|
|
|
|
if (!IsRef(this.root = trailerDict.get('Root'))) |
|
|
|
if (!isRef(this.root = trailerDict.get('Root'))) |
|
|
|
error('Invalid root reference'); |
|
|
|
error('Invalid root reference'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3082,28 +3082,28 @@ var XRef = (function xRefXRef() { |
|
|
|
readXRefTable: function readXRefTable(parser) { |
|
|
|
readXRefTable: function readXRefTable(parser) { |
|
|
|
var obj; |
|
|
|
var obj; |
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
if (IsCmd(obj = parser.getObj(), 'trailer')) |
|
|
|
if (isCmd(obj = parser.getObj(), 'trailer')) |
|
|
|
break; |
|
|
|
break; |
|
|
|
if (!IsInt(obj)) |
|
|
|
if (!isInt(obj)) |
|
|
|
error('Invalid XRef table'); |
|
|
|
error('Invalid XRef table'); |
|
|
|
var first = obj; |
|
|
|
var first = obj; |
|
|
|
if (!IsInt(obj = parser.getObj())) |
|
|
|
if (!isInt(obj = parser.getObj())) |
|
|
|
error('Invalid XRef table'); |
|
|
|
error('Invalid XRef table'); |
|
|
|
var n = obj; |
|
|
|
var n = obj; |
|
|
|
if (first < 0 || n < 0 || (first + n) != ((first + n) | 0)) |
|
|
|
if (first < 0 || n < 0 || (first + n) != ((first + n) | 0)) |
|
|
|
error('Invalid XRef table: ' + first + ', ' + n); |
|
|
|
error('Invalid XRef table: ' + first + ', ' + n); |
|
|
|
for (var i = first; i < first + n; ++i) { |
|
|
|
for (var i = first; i < first + n; ++i) { |
|
|
|
var entry = {}; |
|
|
|
var entry = {}; |
|
|
|
if (!IsInt(obj = parser.getObj())) |
|
|
|
if (!isInt(obj = parser.getObj())) |
|
|
|
error('Invalid XRef table: ' + first + ', ' + n); |
|
|
|
error('Invalid XRef table: ' + first + ', ' + n); |
|
|
|
entry.offset = obj; |
|
|
|
entry.offset = obj; |
|
|
|
if (!IsInt(obj = parser.getObj())) |
|
|
|
if (!isInt(obj = parser.getObj())) |
|
|
|
error('Invalid XRef table: ' + first + ', ' + n); |
|
|
|
error('Invalid XRef table: ' + first + ', ' + n); |
|
|
|
entry.gen = obj; |
|
|
|
entry.gen = obj; |
|
|
|
obj = parser.getObj(); |
|
|
|
obj = parser.getObj(); |
|
|
|
if (IsCmd(obj, 'n')) { |
|
|
|
if (isCmd(obj, 'n')) { |
|
|
|
entry.uncompressed = true; |
|
|
|
entry.uncompressed = true; |
|
|
|
} else if (IsCmd(obj, 'f')) { |
|
|
|
} else if (isCmd(obj, 'f')) { |
|
|
|
entry.free = true; |
|
|
|
entry.free = true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
error('Invalid XRef table: ' + first + ', ' + n); |
|
|
|
error('Invalid XRef table: ' + first + ', ' + n); |
|
|
@ -3122,15 +3122,15 @@ var XRef = (function xRefXRef() { |
|
|
|
|
|
|
|
|
|
|
|
// read the trailer dictionary
|
|
|
|
// read the trailer dictionary
|
|
|
|
var dict; |
|
|
|
var dict; |
|
|
|
if (!IsDict(dict = parser.getObj())) |
|
|
|
if (!isDict(dict = parser.getObj())) |
|
|
|
error('Invalid XRef table'); |
|
|
|
error('Invalid XRef table'); |
|
|
|
|
|
|
|
|
|
|
|
// get the 'Prev' pointer
|
|
|
|
// get the 'Prev' pointer
|
|
|
|
var prev; |
|
|
|
var prev; |
|
|
|
obj = dict.get('Prev'); |
|
|
|
obj = dict.get('Prev'); |
|
|
|
if (IsInt(obj)) { |
|
|
|
if (isInt(obj)) { |
|
|
|
prev = obj; |
|
|
|
prev = obj; |
|
|
|
} else if (IsRef(obj)) { |
|
|
|
} else if (isRef(obj)) { |
|
|
|
// certain buggy PDF generators generate "/Prev NNN 0 R" instead
|
|
|
|
// certain buggy PDF generators generate "/Prev NNN 0 R" instead
|
|
|
|
// of "/Prev NNN"
|
|
|
|
// of "/Prev NNN"
|
|
|
|
prev = obj.num; |
|
|
|
prev = obj.num; |
|
|
@ -3140,7 +3140,7 @@ var XRef = (function xRefXRef() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// check for 'XRefStm' key
|
|
|
|
// check for 'XRefStm' key
|
|
|
|
if (IsInt(obj = dict.get('XRefStm'))) { |
|
|
|
if (isInt(obj = dict.get('XRefStm'))) { |
|
|
|
var pos = obj; |
|
|
|
var pos = obj; |
|
|
|
// ignore previously loaded xref streams (possible infinite recursion)
|
|
|
|
// ignore previously loaded xref streams (possible infinite recursion)
|
|
|
|
if (!(pos in this.xrefstms)) { |
|
|
|
if (!(pos in this.xrefstms)) { |
|
|
@ -3160,13 +3160,13 @@ var XRef = (function xRefXRef() { |
|
|
|
var i, j; |
|
|
|
var i, j; |
|
|
|
while (range.length > 0) { |
|
|
|
while (range.length > 0) { |
|
|
|
var first = range[0], n = range[1]; |
|
|
|
var first = range[0], n = range[1]; |
|
|
|
if (!IsInt(first) || !IsInt(n)) |
|
|
|
if (!isInt(first) || !isInt(n)) |
|
|
|
error('Invalid XRef range fields: ' + first + ', ' + n); |
|
|
|
error('Invalid XRef range fields: ' + first + ', ' + n); |
|
|
|
var typeFieldWidth = byteWidths[0]; |
|
|
|
var typeFieldWidth = byteWidths[0]; |
|
|
|
var offsetFieldWidth = byteWidths[1]; |
|
|
|
var offsetFieldWidth = byteWidths[1]; |
|
|
|
var generationFieldWidth = byteWidths[2]; |
|
|
|
var generationFieldWidth = byteWidths[2]; |
|
|
|
if (!IsInt(typeFieldWidth) || !IsInt(offsetFieldWidth) || |
|
|
|
if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) || |
|
|
|
!IsInt(generationFieldWidth)) { |
|
|
|
!isInt(generationFieldWidth)) { |
|
|
|
error('Invalid XRef entry fields length: ' + first + ', ' + n); |
|
|
|
error('Invalid XRef entry fields length: ' + first + ', ' + n); |
|
|
|
} |
|
|
|
} |
|
|
|
for (i = 0; i < n; ++i) { |
|
|
|
for (i = 0; i < n; ++i) { |
|
|
@ -3201,7 +3201,7 @@ var XRef = (function xRefXRef() { |
|
|
|
range.splice(0, 2); |
|
|
|
range.splice(0, 2); |
|
|
|
} |
|
|
|
} |
|
|
|
var prev = streamParameters.get('Prev'); |
|
|
|
var prev = streamParameters.get('Prev'); |
|
|
|
if (IsInt(prev)) |
|
|
|
if (isInt(prev)) |
|
|
|
this.readXRef(prev); |
|
|
|
this.readXRef(prev); |
|
|
|
return streamParameters; |
|
|
|
return streamParameters; |
|
|
|
}, |
|
|
|
}, |
|
|
@ -3298,11 +3298,11 @@ var XRef = (function xRefXRef() { |
|
|
|
stream.pos = trailers[i]; |
|
|
|
stream.pos = trailers[i]; |
|
|
|
var parser = new Parser(new Lexer(stream), true); |
|
|
|
var parser = new Parser(new Lexer(stream), true); |
|
|
|
var obj = parser.getObj(); |
|
|
|
var obj = parser.getObj(); |
|
|
|
if (!IsCmd(obj, 'trailer')) |
|
|
|
if (!isCmd(obj, 'trailer')) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
// read the trailer dictionary
|
|
|
|
// read the trailer dictionary
|
|
|
|
var dict; |
|
|
|
var dict; |
|
|
|
if (!IsDict(dict = parser.getObj())) |
|
|
|
if (!isDict(dict = parser.getObj())) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
// taking the first one with 'ID'
|
|
|
|
// taking the first one with 'ID'
|
|
|
|
if (dict.has('ID')) |
|
|
|
if (dict.has('ID')) |
|
|
@ -3318,13 +3318,13 @@ var XRef = (function xRefXRef() { |
|
|
|
var parser = new Parser(new Lexer(stream), true); |
|
|
|
var parser = new Parser(new Lexer(stream), true); |
|
|
|
var obj = parser.getObj(); |
|
|
|
var obj = parser.getObj(); |
|
|
|
// parse an old-style xref table
|
|
|
|
// parse an old-style xref table
|
|
|
|
if (IsCmd(obj, 'xref')) |
|
|
|
if (isCmd(obj, 'xref')) |
|
|
|
return this.readXRefTable(parser); |
|
|
|
return this.readXRefTable(parser); |
|
|
|
// parse an xref stream
|
|
|
|
// parse an xref stream
|
|
|
|
if (IsInt(obj)) { |
|
|
|
if (isInt(obj)) { |
|
|
|
if (!IsInt(parser.getObj()) || |
|
|
|
if (!isInt(parser.getObj()) || |
|
|
|
!IsCmd(parser.getObj(), 'obj') || |
|
|
|
!isCmd(parser.getObj(), 'obj') || |
|
|
|
!IsStream(obj = parser.getObj())) { |
|
|
|
!isStream(obj = parser.getObj())) { |
|
|
|
error('Invalid XRef stream'); |
|
|
|
error('Invalid XRef stream'); |
|
|
|
} |
|
|
|
} |
|
|
|
return this.readXRefStream(obj); |
|
|
|
return this.readXRefStream(obj); |
|
|
@ -3338,7 +3338,7 @@ var XRef = (function xRefXRef() { |
|
|
|
return e; |
|
|
|
return e; |
|
|
|
}, |
|
|
|
}, |
|
|
|
fetchIfRef: function xRefFetchIfRef(obj) { |
|
|
|
fetchIfRef: function xRefFetchIfRef(obj) { |
|
|
|
if (!IsRef(obj)) |
|
|
|
if (!isRef(obj)) |
|
|
|
return obj; |
|
|
|
return obj; |
|
|
|
return this.fetch(obj); |
|
|
|
return this.fetch(obj); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -3359,12 +3359,12 @@ var XRef = (function xRefXRef() { |
|
|
|
var obj1 = parser.getObj(); |
|
|
|
var obj1 = parser.getObj(); |
|
|
|
var obj2 = parser.getObj(); |
|
|
|
var obj2 = parser.getObj(); |
|
|
|
var obj3 = parser.getObj(); |
|
|
|
var obj3 = parser.getObj(); |
|
|
|
if (!IsInt(obj1) || obj1 != num || |
|
|
|
if (!isInt(obj1) || obj1 != num || |
|
|
|
!IsInt(obj2) || obj2 != gen || |
|
|
|
!isInt(obj2) || obj2 != gen || |
|
|
|
!IsCmd(obj3)) { |
|
|
|
!isCmd(obj3)) { |
|
|
|
error('bad XRef entry'); |
|
|
|
error('bad XRef entry'); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!IsCmd(obj3, 'obj')) { |
|
|
|
if (!isCmd(obj3, 'obj')) { |
|
|
|
// some bad pdfs use "obj1234" and really mean 1234
|
|
|
|
// some bad pdfs use "obj1234" and really mean 1234
|
|
|
|
if (obj3.cmd.indexOf('obj') == 0) { |
|
|
|
if (obj3.cmd.indexOf('obj') == 0) { |
|
|
|
num = parseInt(obj3.cmd.substring(3), 10); |
|
|
|
num = parseInt(obj3.cmd.substring(3), 10); |
|
|
@ -3386,18 +3386,18 @@ var XRef = (function xRefXRef() { |
|
|
|
e = parser.getObj(); |
|
|
|
e = parser.getObj(); |
|
|
|
} |
|
|
|
} |
|
|
|
// Don't cache streams since they are mutable.
|
|
|
|
// Don't cache streams since they are mutable.
|
|
|
|
if (!IsStream(e)) |
|
|
|
if (!isStream(e)) |
|
|
|
this.cache[num] = e; |
|
|
|
this.cache[num] = e; |
|
|
|
return e; |
|
|
|
return e; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// compressed entry
|
|
|
|
// compressed entry
|
|
|
|
stream = this.fetch(new Ref(e.offset, 0)); |
|
|
|
stream = this.fetch(new Ref(e.offset, 0)); |
|
|
|
if (!IsStream(stream)) |
|
|
|
if (!isStream(stream)) |
|
|
|
error('bad ObjStm stream'); |
|
|
|
error('bad ObjStm stream'); |
|
|
|
var first = stream.parameters.get('First'); |
|
|
|
var first = stream.parameters.get('First'); |
|
|
|
var n = stream.parameters.get('N'); |
|
|
|
var n = stream.parameters.get('N'); |
|
|
|
if (!IsInt(first) || !IsInt(n)) { |
|
|
|
if (!isInt(first) || !isInt(n)) { |
|
|
|
error('invalid first and n parameters for ObjStm stream'); |
|
|
|
error('invalid first and n parameters for ObjStm stream'); |
|
|
|
} |
|
|
|
} |
|
|
|
parser = new Parser(new Lexer(stream), false); |
|
|
|
parser = new Parser(new Lexer(stream), false); |
|
|
@ -3405,12 +3405,12 @@ var XRef = (function xRefXRef() { |
|
|
|
// read the object numbers to populate cache
|
|
|
|
// read the object numbers to populate cache
|
|
|
|
for (i = 0; i < n; ++i) { |
|
|
|
for (i = 0; i < n; ++i) { |
|
|
|
num = parser.getObj(); |
|
|
|
num = parser.getObj(); |
|
|
|
if (!IsInt(num)) { |
|
|
|
if (!isInt(num)) { |
|
|
|
error('invalid object number in the ObjStm stream: ' + num); |
|
|
|
error('invalid object number in the ObjStm stream: ' + num); |
|
|
|
} |
|
|
|
} |
|
|
|
nums.push(num); |
|
|
|
nums.push(num); |
|
|
|
var offset = parser.getObj(); |
|
|
|
var offset = parser.getObj(); |
|
|
|
if (!IsInt(offset)) { |
|
|
|
if (!isInt(offset)) { |
|
|
|
error('invalid object offset in the ObjStm stream: ' + offset); |
|
|
|
error('invalid object offset in the ObjStm stream: ' + offset); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -3472,7 +3472,7 @@ var Page = (function pagePage() { |
|
|
|
get mediaBox() { |
|
|
|
get mediaBox() { |
|
|
|
var obj = this.inheritPageProp('MediaBox'); |
|
|
|
var obj = this.inheritPageProp('MediaBox'); |
|
|
|
// Reset invalid media box to letter size.
|
|
|
|
// Reset invalid media box to letter size.
|
|
|
|
if (!IsArray(obj) || obj.length !== 4) |
|
|
|
if (!isArray(obj) || obj.length !== 4) |
|
|
|
obj = [0, 0, 612, 792]; |
|
|
|
obj = [0, 0, 612, 792]; |
|
|
|
return shadow(this, 'mediaBox', obj); |
|
|
|
return shadow(this, 'mediaBox', obj); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -3484,7 +3484,7 @@ var Page = (function pagePage() { |
|
|
|
width: this.width, |
|
|
|
width: this.width, |
|
|
|
height: this.height |
|
|
|
height: this.height |
|
|
|
}; |
|
|
|
}; |
|
|
|
if (IsArray(obj) && obj.length == 4) { |
|
|
|
if (isArray(obj) && obj.length == 4) { |
|
|
|
var rotate = this.rotate; |
|
|
|
var rotate = this.rotate; |
|
|
|
if (rotate == 0 || rotate == 180) { |
|
|
|
if (rotate == 0 || rotate == 180) { |
|
|
|
view.x = obj[0]; |
|
|
|
view.x = obj[0]; |
|
|
@ -3591,7 +3591,7 @@ var Page = (function pagePage() { |
|
|
|
var xref = this.xref; |
|
|
|
var xref = this.xref; |
|
|
|
var content = xref.fetchIfRef(this.content); |
|
|
|
var content = xref.fetchIfRef(this.content); |
|
|
|
var resources = xref.fetchIfRef(this.resources); |
|
|
|
var resources = xref.fetchIfRef(this.resources); |
|
|
|
if (IsArray(content)) { |
|
|
|
if (isArray(content)) { |
|
|
|
// fetching items
|
|
|
|
// fetching items
|
|
|
|
var i, n = content.length; |
|
|
|
var i, n = content.length; |
|
|
|
for (i = 0; i < n; ++i) |
|
|
|
for (i = 0; i < n; ++i) |
|
|
@ -3606,7 +3606,7 @@ var Page = (function pagePage() { |
|
|
|
var xref = this.xref; |
|
|
|
var xref = this.xref; |
|
|
|
var resources = xref.fetchIfRef(this.resources); |
|
|
|
var resources = xref.fetchIfRef(this.resources); |
|
|
|
var mediaBox = xref.fetchIfRef(this.mediaBox); |
|
|
|
var mediaBox = xref.fetchIfRef(this.mediaBox); |
|
|
|
assertWellFormed(IsDict(resources), 'invalid page resources'); |
|
|
|
assertWellFormed(isDict(resources), 'invalid page resources'); |
|
|
|
gfx.beginDrawing({ x: mediaBox[0], y: mediaBox[1], |
|
|
|
gfx.beginDrawing({ x: mediaBox[0], y: mediaBox[1], |
|
|
|
width: this.width, |
|
|
|
width: this.width, |
|
|
|
height: this.height, |
|
|
|
height: this.height, |
|
|
@ -3635,10 +3635,10 @@ var Page = (function pagePage() { |
|
|
|
var links = []; |
|
|
|
var links = []; |
|
|
|
for (i = 0; i < n; ++i) { |
|
|
|
for (i = 0; i < n; ++i) { |
|
|
|
var annotation = xref.fetch(annotations[i]); |
|
|
|
var annotation = xref.fetch(annotations[i]); |
|
|
|
if (!IsDict(annotation)) |
|
|
|
if (!isDict(annotation)) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
var subtype = annotation.get('Subtype'); |
|
|
|
var subtype = annotation.get('Subtype'); |
|
|
|
if (!IsName(subtype) || subtype.name != 'Link') |
|
|
|
if (!isName(subtype) || subtype.name != 'Link') |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
var rect = annotation.get('Rect'); |
|
|
|
var rect = annotation.get('Rect'); |
|
|
|
var topLeftCorner = this.rotatePoint(rect[0], rect[1]); |
|
|
|
var topLeftCorner = this.rotatePoint(rect[0], rect[1]); |
|
|
@ -3664,7 +3664,7 @@ var Page = (function pagePage() { |
|
|
|
} else if (annotation.has('Dest')) { |
|
|
|
} else if (annotation.has('Dest')) { |
|
|
|
// simple destination link
|
|
|
|
// simple destination link
|
|
|
|
var dest = annotation.get('Dest'); |
|
|
|
var dest = annotation.get('Dest'); |
|
|
|
link.dest = IsName(dest) ? dest.name : dest; |
|
|
|
link.dest = isName(dest) ? dest.name : dest; |
|
|
|
} |
|
|
|
} |
|
|
|
links.push(link); |
|
|
|
links.push(link); |
|
|
|
} |
|
|
|
} |
|
|
@ -3679,16 +3679,16 @@ var Catalog = (function catalogCatalog() { |
|
|
|
function constructor(xref) { |
|
|
|
function constructor(xref) { |
|
|
|
this.xref = xref; |
|
|
|
this.xref = xref; |
|
|
|
var obj = xref.getCatalogObj(); |
|
|
|
var obj = xref.getCatalogObj(); |
|
|
|
assertWellFormed(IsDict(obj), 'catalog object is not a dictionary'); |
|
|
|
assertWellFormed(isDict(obj), 'catalog object is not a dictionary'); |
|
|
|
this.catDict = obj; |
|
|
|
this.catDict = obj; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = { |
|
|
|
constructor.prototype = { |
|
|
|
get toplevelPagesDict() { |
|
|
|
get toplevelPagesDict() { |
|
|
|
var pagesObj = this.catDict.get('Pages'); |
|
|
|
var pagesObj = this.catDict.get('Pages'); |
|
|
|
assertWellFormed(IsRef(pagesObj), 'invalid top-level pages reference'); |
|
|
|
assertWellFormed(isRef(pagesObj), 'invalid top-level pages reference'); |
|
|
|
var xrefObj = this.xref.fetch(pagesObj); |
|
|
|
var xrefObj = this.xref.fetch(pagesObj); |
|
|
|
assertWellFormed(IsDict(xrefObj), 'invalid top-level pages dictionary'); |
|
|
|
assertWellFormed(isDict(xrefObj), 'invalid top-level pages dictionary'); |
|
|
|
// shadow the prototype getter
|
|
|
|
// shadow the prototype getter
|
|
|
|
return shadow(this, 'toplevelPagesDict', xrefObj); |
|
|
|
return shadow(this, 'toplevelPagesDict', xrefObj); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -3696,10 +3696,10 @@ var Catalog = (function catalogCatalog() { |
|
|
|
var obj = this.catDict.get('Outlines'); |
|
|
|
var obj = this.catDict.get('Outlines'); |
|
|
|
var xref = this.xref; |
|
|
|
var xref = this.xref; |
|
|
|
var root = { items: [] }; |
|
|
|
var root = { items: [] }; |
|
|
|
if (IsRef(obj)) { |
|
|
|
if (isRef(obj)) { |
|
|
|
obj = xref.fetch(obj).get('First'); |
|
|
|
obj = xref.fetch(obj).get('First'); |
|
|
|
var processed = new RefSet(); |
|
|
|
var processed = new RefSet(); |
|
|
|
if (IsRef(obj)) { |
|
|
|
if (isRef(obj)) { |
|
|
|
var queue = [{obj: obj, parent: root}]; |
|
|
|
var queue = [{obj: obj, parent: root}]; |
|
|
|
// to avoid recursion keeping track of the items
|
|
|
|
// to avoid recursion keeping track of the items
|
|
|
|
// in the processed dictionary
|
|
|
|
// in the processed dictionary
|
|
|
@ -3714,7 +3714,7 @@ var Catalog = (function catalogCatalog() { |
|
|
|
dest = xref.fetchIfRef(dest).get('D'); |
|
|
|
dest = xref.fetchIfRef(dest).get('D'); |
|
|
|
else if (outlineDict.has('Dest')) { |
|
|
|
else if (outlineDict.has('Dest')) { |
|
|
|
dest = outlineDict.get('Dest'); |
|
|
|
dest = outlineDict.get('Dest'); |
|
|
|
if (IsName(dest)) |
|
|
|
if (isName(dest)) |
|
|
|
dest = dest.name; |
|
|
|
dest = dest.name; |
|
|
|
} |
|
|
|
} |
|
|
|
var title = xref.fetchIfRef(outlineDict.get('Title')); |
|
|
|
var title = xref.fetchIfRef(outlineDict.get('Title')); |
|
|
@ -3729,12 +3729,12 @@ var Catalog = (function catalogCatalog() { |
|
|
|
}; |
|
|
|
}; |
|
|
|
i.parent.items.push(outlineItem); |
|
|
|
i.parent.items.push(outlineItem); |
|
|
|
obj = outlineDict.get('First'); |
|
|
|
obj = outlineDict.get('First'); |
|
|
|
if (IsRef(obj) && !processed.has(obj)) { |
|
|
|
if (isRef(obj) && !processed.has(obj)) { |
|
|
|
queue.push({obj: obj, parent: outlineItem}); |
|
|
|
queue.push({obj: obj, parent: outlineItem}); |
|
|
|
processed.put(obj); |
|
|
|
processed.put(obj); |
|
|
|
} |
|
|
|
} |
|
|
|
obj = outlineDict.get('Next'); |
|
|
|
obj = outlineDict.get('Next'); |
|
|
|
if (IsRef(obj) && !processed.has(obj)) { |
|
|
|
if (isRef(obj) && !processed.has(obj)) { |
|
|
|
queue.push({obj: obj, parent: i.parent}); |
|
|
|
queue.push({obj: obj, parent: i.parent}); |
|
|
|
processed.put(obj); |
|
|
|
processed.put(obj); |
|
|
|
} |
|
|
|
} |
|
|
@ -3747,7 +3747,7 @@ var Catalog = (function catalogCatalog() { |
|
|
|
get numPages() { |
|
|
|
get numPages() { |
|
|
|
var obj = this.toplevelPagesDict.get('Count'); |
|
|
|
var obj = this.toplevelPagesDict.get('Count'); |
|
|
|
assertWellFormed( |
|
|
|
assertWellFormed( |
|
|
|
IsInt(obj), |
|
|
|
isInt(obj), |
|
|
|
'page count in top level pages object is not an integer' |
|
|
|
'page count in top level pages object is not an integer' |
|
|
|
); |
|
|
|
); |
|
|
|
// shadow the prototype getter
|
|
|
|
// shadow the prototype getter
|
|
|
@ -3756,18 +3756,18 @@ var Catalog = (function catalogCatalog() { |
|
|
|
traverseKids: function catalogTraverseKids(pagesDict) { |
|
|
|
traverseKids: function catalogTraverseKids(pagesDict) { |
|
|
|
var pageCache = this.pageCache; |
|
|
|
var pageCache = this.pageCache; |
|
|
|
var kids = pagesDict.get('Kids'); |
|
|
|
var kids = pagesDict.get('Kids'); |
|
|
|
assertWellFormed(IsArray(kids), |
|
|
|
assertWellFormed(isArray(kids), |
|
|
|
'page dictionary kids object is not an array'); |
|
|
|
'page dictionary kids object is not an array'); |
|
|
|
for (var i = 0; i < kids.length; ++i) { |
|
|
|
for (var i = 0; i < kids.length; ++i) { |
|
|
|
var kid = kids[i]; |
|
|
|
var kid = kids[i]; |
|
|
|
assertWellFormed(IsRef(kid), |
|
|
|
assertWellFormed(isRef(kid), |
|
|
|
'page dictionary kid is not a reference'); |
|
|
|
'page dictionary kid is not a reference'); |
|
|
|
var obj = this.xref.fetch(kid); |
|
|
|
var obj = this.xref.fetch(kid); |
|
|
|
if (IsDict(obj, 'Page') || (IsDict(obj) && !obj.has('Kids'))) { |
|
|
|
if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) { |
|
|
|
pageCache.push(new Page(this.xref, pageCache.length, obj, kid)); |
|
|
|
pageCache.push(new Page(this.xref, pageCache.length, obj, kid)); |
|
|
|
} else { // must be a child page dictionary
|
|
|
|
} else { // must be a child page dictionary
|
|
|
|
assertWellFormed( |
|
|
|
assertWellFormed( |
|
|
|
IsDict(obj), |
|
|
|
isDict(obj), |
|
|
|
'page dictionary kid reference points to wrong type of object' |
|
|
|
'page dictionary kid reference points to wrong type of object' |
|
|
|
); |
|
|
|
); |
|
|
|
this.traverseKids(obj); |
|
|
|
this.traverseKids(obj); |
|
|
@ -3777,7 +3777,7 @@ var Catalog = (function catalogCatalog() { |
|
|
|
get destinations() { |
|
|
|
get destinations() { |
|
|
|
function fetchDestination(xref, ref) { |
|
|
|
function fetchDestination(xref, ref) { |
|
|
|
var dest = xref.fetchIfRef(ref); |
|
|
|
var dest = xref.fetchIfRef(ref); |
|
|
|
return IsDict(dest) ? dest.get('D') : dest; |
|
|
|
return isDict(dest) ? dest.get('D') : dest; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var xref = this.xref; |
|
|
|
var xref = this.xref; |
|
|
@ -4362,8 +4362,8 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
var parser = new Parser(new Lexer(stream), false); |
|
|
|
var parser = new Parser(new Lexer(stream), false); |
|
|
|
var args = [], argsArray = [], fnArray = [], obj; |
|
|
|
var args = [], argsArray = [], fnArray = [], obj; |
|
|
|
|
|
|
|
|
|
|
|
while (!IsEOF(obj = parser.getObj())) { |
|
|
|
while (!isEOF(obj = parser.getObj())) { |
|
|
|
if (IsCmd(obj)) { |
|
|
|
if (isCmd(obj)) { |
|
|
|
var cmd = obj.cmd; |
|
|
|
var cmd = obj.cmd; |
|
|
|
var fn = OP_MAP[cmd]; |
|
|
|
var fn = OP_MAP[cmd]; |
|
|
|
assertWellFormed(fn, "Unknown command '" + cmd + "'"); |
|
|
|
assertWellFormed(fn, "Unknown command '" + cmd + "'"); |
|
|
@ -4373,10 +4373,10 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
// compile tiling patterns
|
|
|
|
// compile tiling patterns
|
|
|
|
var patternName = args[args.length - 1]; |
|
|
|
var patternName = args[args.length - 1]; |
|
|
|
// SCN/scn applies patterns along with normal colors
|
|
|
|
// SCN/scn applies patterns along with normal colors
|
|
|
|
if (IsName(patternName)) { |
|
|
|
if (isName(patternName)) { |
|
|
|
var pattern = xref.fetchIfRef(patterns.get(patternName.name)); |
|
|
|
var pattern = xref.fetchIfRef(patterns.get(patternName.name)); |
|
|
|
if (pattern) { |
|
|
|
if (pattern) { |
|
|
|
var dict = IsStream(pattern) ? pattern.dict : pattern; |
|
|
|
var dict = isStream(pattern) ? pattern.dict : pattern; |
|
|
|
var typeNum = dict.get('PatternType'); |
|
|
|
var typeNum = dict.get('PatternType'); |
|
|
|
if (typeNum == 1) { |
|
|
|
if (typeNum == 1) { |
|
|
|
patternName.code = this.evaluate(pattern, xref, |
|
|
|
patternName.code = this.evaluate(pattern, xref, |
|
|
@ -4391,11 +4391,11 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
var xobj = xobjs.get(name); |
|
|
|
var xobj = xobjs.get(name); |
|
|
|
if (xobj) { |
|
|
|
if (xobj) { |
|
|
|
xobj = xref.fetchIfRef(xobj); |
|
|
|
xobj = xref.fetchIfRef(xobj); |
|
|
|
assertWellFormed(IsStream(xobj), 'XObject should be a stream'); |
|
|
|
assertWellFormed(isStream(xobj), 'XObject should be a stream'); |
|
|
|
|
|
|
|
|
|
|
|
var type = xobj.dict.get('Subtype'); |
|
|
|
var type = xobj.dict.get('Subtype'); |
|
|
|
assertWellFormed( |
|
|
|
assertWellFormed( |
|
|
|
IsName(type), |
|
|
|
isName(type), |
|
|
|
'XObject should have a Name subtype' |
|
|
|
'XObject should have a Name subtype' |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -4412,7 +4412,7 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
if (fontRes) { |
|
|
|
if (fontRes) { |
|
|
|
fontRes = xref.fetchIfRef(fontRes); |
|
|
|
fontRes = xref.fetchIfRef(fontRes); |
|
|
|
var font = xref.fetchIfRef(fontRes.get(args[0].name)); |
|
|
|
var font = xref.fetchIfRef(fontRes.get(args[0].name)); |
|
|
|
assertWellFormed(IsDict(font)); |
|
|
|
assertWellFormed(isDict(font)); |
|
|
|
if (!font.translated) { |
|
|
|
if (!font.translated) { |
|
|
|
font.translated = this.translateFont(font, xref, resources); |
|
|
|
font.translated = this.translateFont(font, xref, resources); |
|
|
|
if (fonts && font.translated) { |
|
|
|
if (fonts && font.translated) { |
|
|
@ -4454,7 +4454,7 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
var start = 0, end = 0; |
|
|
|
var start = 0, end = 0; |
|
|
|
for (var i = 0; i < widths.length; i++) { |
|
|
|
for (var i = 0; i < widths.length; i++) { |
|
|
|
var code = widths[i]; |
|
|
|
var code = widths[i]; |
|
|
|
if (IsArray(code)) { |
|
|
|
if (isArray(code)) { |
|
|
|
for (var j = 0; j < code.length; j++) |
|
|
|
for (var j = 0; j < code.length; j++) |
|
|
|
glyphsWidths[start++] = code[j]; |
|
|
|
glyphsWidths[start++] = code[j]; |
|
|
|
start = 0; |
|
|
|
start = 0; |
|
|
@ -4471,7 +4471,7 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
properties.widths = glyphsWidths; |
|
|
|
properties.widths = glyphsWidths; |
|
|
|
|
|
|
|
|
|
|
|
var cidToGidMap = dict.get('CIDToGIDMap'); |
|
|
|
var cidToGidMap = dict.get('CIDToGIDMap'); |
|
|
|
if (!cidToGidMap || !IsRef(cidToGidMap)) { |
|
|
|
if (!cidToGidMap || !isRef(cidToGidMap)) { |
|
|
|
return Object.create(GlyphsUnicode); |
|
|
|
return Object.create(GlyphsUnicode); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -4493,11 +4493,11 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
var width = glyphsWidths[code]; |
|
|
|
var width = glyphsWidths[code]; |
|
|
|
encoding[code] = { |
|
|
|
encoding[code] = { |
|
|
|
unicode: glyphID, |
|
|
|
unicode: glyphID, |
|
|
|
width: IsNum(width) ? width : defaultWidth |
|
|
|
width: isNum(width) ? width : defaultWidth |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (type == 'CIDFontType0') { |
|
|
|
} else if (type == 'CIDFontType0') { |
|
|
|
if (IsName(encoding)) { |
|
|
|
if (isName(encoding)) { |
|
|
|
// Encoding is a predefined CMap
|
|
|
|
// Encoding is a predefined CMap
|
|
|
|
if (encoding.name == 'Identity-H') { |
|
|
|
if (encoding.name == 'Identity-H') { |
|
|
|
TODO('Need to create an identity cmap'); |
|
|
|
TODO('Need to create an identity cmap'); |
|
|
@ -4518,7 +4518,7 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
var baseEncoding = null; |
|
|
|
var baseEncoding = null; |
|
|
|
if (dict.has('Encoding')) { |
|
|
|
if (dict.has('Encoding')) { |
|
|
|
encoding = xref.fetchIfRef(dict.get('Encoding')); |
|
|
|
encoding = xref.fetchIfRef(dict.get('Encoding')); |
|
|
|
if (IsDict(encoding)) { |
|
|
|
if (isDict(encoding)) { |
|
|
|
var baseName = encoding.get('BaseEncoding'); |
|
|
|
var baseName = encoding.get('BaseEncoding'); |
|
|
|
if (baseName) |
|
|
|
if (baseName) |
|
|
|
baseEncoding = Encodings[baseName.name].slice(); |
|
|
|
baseEncoding = Encodings[baseName.name].slice(); |
|
|
@ -4529,13 +4529,13 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
var index = 0; |
|
|
|
var index = 0; |
|
|
|
for (var j = 0; j < diffEncoding.length; j++) { |
|
|
|
for (var j = 0; j < diffEncoding.length; j++) { |
|
|
|
var data = diffEncoding[j]; |
|
|
|
var data = diffEncoding[j]; |
|
|
|
if (IsNum(data)) |
|
|
|
if (isNum(data)) |
|
|
|
index = data; |
|
|
|
index = data; |
|
|
|
else |
|
|
|
else |
|
|
|
differences[index++] = data.name; |
|
|
|
differences[index++] = data.name; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (IsName(encoding)) { |
|
|
|
} else if (isName(encoding)) { |
|
|
|
baseEncoding = Encodings[encoding.name].slice(); |
|
|
|
baseEncoding = Encodings[encoding.name].slice(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
error('Encoding is not a Name nor a Dict'); |
|
|
|
error('Encoding is not a Name nor a Dict'); |
|
|
@ -4572,7 +4572,7 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
var width = widths[i] || widths[glyph]; |
|
|
|
var width = widths[i] || widths[glyph]; |
|
|
|
map[i] = { |
|
|
|
map[i] = { |
|
|
|
unicode: index, |
|
|
|
unicode: index, |
|
|
|
width: IsNum(width) ? width : properties.defaultWidth |
|
|
|
width: isNum(width) ? width : properties.defaultWidth |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (glyph) |
|
|
|
if (glyph) |
|
|
@ -4590,12 +4590,12 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
|
|
|
|
|
|
|
|
if (type == 'TrueType' && dict.has('ToUnicode') && differences) { |
|
|
|
if (type == 'TrueType' && dict.has('ToUnicode') && differences) { |
|
|
|
var cmapObj = dict.get('ToUnicode'); |
|
|
|
var cmapObj = dict.get('ToUnicode'); |
|
|
|
if (IsRef(cmapObj)) { |
|
|
|
if (isRef(cmapObj)) { |
|
|
|
cmapObj = xref.fetch(cmapObj); |
|
|
|
cmapObj = xref.fetch(cmapObj); |
|
|
|
} |
|
|
|
} |
|
|
|
if (IsName(cmapObj)) { |
|
|
|
if (isName(cmapObj)) { |
|
|
|
error('ToUnicode file cmap translation not implemented'); |
|
|
|
error('ToUnicode file cmap translation not implemented'); |
|
|
|
} else if (IsStream(cmapObj)) { |
|
|
|
} else if (isStream(cmapObj)) { |
|
|
|
var tokens = []; |
|
|
|
var tokens = []; |
|
|
|
var token = ''; |
|
|
|
var token = ''; |
|
|
|
var beginArrayToken = {}; |
|
|
|
var beginArrayToken = {}; |
|
|
@ -4696,7 +4696,7 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
|
|
|
|
|
|
|
|
var defaultWidth = 0; |
|
|
|
var defaultWidth = 0; |
|
|
|
var widths = Metrics[stdFontMap[name] || name]; |
|
|
|
var widths = Metrics[stdFontMap[name] || name]; |
|
|
|
if (IsNum(widths)) { |
|
|
|
if (isNum(widths)) { |
|
|
|
defaultWidth = widths; |
|
|
|
defaultWidth = widths; |
|
|
|
widths = null; |
|
|
|
widths = null; |
|
|
|
} |
|
|
|
} |
|
|
@ -4712,7 +4712,7 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
resources) { |
|
|
|
resources) { |
|
|
|
var baseDict = dict; |
|
|
|
var baseDict = dict; |
|
|
|
var type = dict.get('Subtype'); |
|
|
|
var type = dict.get('Subtype'); |
|
|
|
assertWellFormed(IsName(type), 'invalid font Subtype'); |
|
|
|
assertWellFormed(isName(type), 'invalid font Subtype'); |
|
|
|
|
|
|
|
|
|
|
|
var composite = false; |
|
|
|
var composite = false; |
|
|
|
if (type.name == 'Type0') { |
|
|
|
if (type.name == 'Type0') { |
|
|
@ -4724,13 +4724,13 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
if (!df) |
|
|
|
if (!df) |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
if (IsRef(df)) |
|
|
|
if (isRef(df)) |
|
|
|
df = xref.fetch(df); |
|
|
|
df = xref.fetch(df); |
|
|
|
|
|
|
|
|
|
|
|
dict = xref.fetch(IsRef(df) ? df : df[0]); |
|
|
|
dict = xref.fetch(isRef(df) ? df : df[0]); |
|
|
|
|
|
|
|
|
|
|
|
type = dict.get('Subtype'); |
|
|
|
type = dict.get('Subtype'); |
|
|
|
assertWellFormed(IsName(type), 'invalid font Subtype'); |
|
|
|
assertWellFormed(isName(type), 'invalid font Subtype'); |
|
|
|
composite = true; |
|
|
|
composite = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -4740,7 +4740,7 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
var descriptor = xref.fetchIfRef(dict.get('FontDescriptor')); |
|
|
|
var descriptor = xref.fetchIfRef(dict.get('FontDescriptor')); |
|
|
|
if (!descriptor) { |
|
|
|
if (!descriptor) { |
|
|
|
var baseFontName = dict.get('BaseFont'); |
|
|
|
var baseFontName = dict.get('BaseFont'); |
|
|
|
if (!IsName(baseFontName)) |
|
|
|
if (!isName(baseFontName)) |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
// Using base font name as a font name.
|
|
|
|
// Using base font name as a font name.
|
|
|
@ -4783,7 +4783,7 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Trying get the BaseFont metrics (see comment above).
|
|
|
|
// Trying get the BaseFont metrics (see comment above).
|
|
|
|
var baseFontName = dict.get('BaseFont'); |
|
|
|
var baseFontName = dict.get('BaseFont'); |
|
|
|
if (IsName(baseFontName)) { |
|
|
|
if (isName(baseFontName)) { |
|
|
|
var metricsAndMap = this.getBaseFontMetricsAndMap(baseFontName.name); |
|
|
|
var metricsAndMap = this.getBaseFontMetricsAndMap(baseFontName.name); |
|
|
|
|
|
|
|
|
|
|
|
glyphWidths = metricsAndMap.widths; |
|
|
|
glyphWidths = metricsAndMap.widths; |
|
|
@ -4793,7 +4793,7 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var fontName = xref.fetchIfRef(descriptor.get('FontName')); |
|
|
|
var fontName = xref.fetchIfRef(descriptor.get('FontName')); |
|
|
|
assertWellFormed(IsName(fontName), 'invalid font name'); |
|
|
|
assertWellFormed(isName(fontName), 'invalid font name'); |
|
|
|
|
|
|
|
|
|
|
|
var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3'); |
|
|
|
var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3'); |
|
|
|
if (fontFile) { |
|
|
|
if (fontFile) { |
|
|
@ -4804,11 +4804,11 @@ var PartialEvaluator = (function partialEvaluator() { |
|
|
|
subtype = subtype.name; |
|
|
|
subtype = subtype.name; |
|
|
|
|
|
|
|
|
|
|
|
var length1 = fontFile.dict.get('Length1'); |
|
|
|
var length1 = fontFile.dict.get('Length1'); |
|
|
|
if (!IsInt(length1)) |
|
|
|
if (!isInt(length1)) |
|
|
|
length1 = xref.fetchIfRef(length1); |
|
|
|
length1 = xref.fetchIfRef(length1); |
|
|
|
|
|
|
|
|
|
|
|
var length2 = fontFile.dict.get('Length2'); |
|
|
|
var length2 = fontFile.dict.get('Length2'); |
|
|
|
if (!IsInt(length2)) |
|
|
|
if (!isInt(length2)) |
|
|
|
length2 = xref.fetchIfRef(length2); |
|
|
|
length2 = xref.fetchIfRef(length2); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -4983,7 +4983,7 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
}, |
|
|
|
}, |
|
|
|
setGState: function canvasGraphicsSetGState(dictName) { |
|
|
|
setGState: function canvasGraphicsSetGState(dictName) { |
|
|
|
var extGState = this.xref.fetchIfRef(this.res.get('ExtGState')); |
|
|
|
var extGState = this.xref.fetchIfRef(this.res.get('ExtGState')); |
|
|
|
if (IsDict(extGState) && extGState.has(dictName.name)) { |
|
|
|
if (isDict(extGState) && extGState.has(dictName.name)) { |
|
|
|
var gsState = this.xref.fetchIfRef(extGState.get(dictName.name)); |
|
|
|
var gsState = this.xref.fetchIfRef(extGState.get(dictName.name)); |
|
|
|
var self = this; |
|
|
|
var self = this; |
|
|
|
gsState.forEach(function canvasGraphicsSetGStateForEach(key, value) { |
|
|
|
gsState.forEach(function canvasGraphicsSetGStateForEach(key, value) { |
|
|
@ -5209,13 +5209,13 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
setFont: function canvasGraphicsSetFont(fontRef, size) { |
|
|
|
setFont: function canvasGraphicsSetFont(fontRef, size) { |
|
|
|
var font; |
|
|
|
var font; |
|
|
|
// the tf command uses a name, but graphics state uses a reference
|
|
|
|
// the tf command uses a name, but graphics state uses a reference
|
|
|
|
if (IsName(fontRef)) { |
|
|
|
if (isName(fontRef)) { |
|
|
|
font = this.xref.fetchIfRef(this.res.get('Font')); |
|
|
|
font = this.xref.fetchIfRef(this.res.get('Font')); |
|
|
|
if (!IsDict(font)) |
|
|
|
if (!isDict(font)) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
font = font.get(fontRef.name); |
|
|
|
font = font.get(fontRef.name); |
|
|
|
} else if (IsRef(fontRef)) { |
|
|
|
} else if (isRef(fontRef)) { |
|
|
|
font = fontRef; |
|
|
|
font = fontRef; |
|
|
|
} |
|
|
|
} |
|
|
|
font = this.xref.fetchIfRef(font); |
|
|
|
font = this.xref.fetchIfRef(font); |
|
|
@ -5317,13 +5317,13 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
var arrLength = arr.length; |
|
|
|
var arrLength = arr.length; |
|
|
|
for (var i = 0; i < arrLength; ++i) { |
|
|
|
for (var i = 0; i < arrLength; ++i) { |
|
|
|
var e = arr[i]; |
|
|
|
var e = arr[i]; |
|
|
|
if (IsNum(e)) { |
|
|
|
if (isNum(e)) { |
|
|
|
if (ctx.$addCurrentX) { |
|
|
|
if (ctx.$addCurrentX) { |
|
|
|
ctx.$addCurrentX(-e * 0.001 * fontSize); |
|
|
|
ctx.$addCurrentX(-e * 0.001 * fontSize); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
current.x -= e * 0.001 * fontSize * textHScale; |
|
|
|
current.x -= e * 0.001 * fontSize * textHScale; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (IsString(e)) { |
|
|
|
} else if (isString(e)) { |
|
|
|
this.showText(e); |
|
|
|
this.showText(e); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
malformed('TJ array element ' + e + ' is not string or num'); |
|
|
|
malformed('TJ array element ' + e + ' is not string or num'); |
|
|
@ -5497,7 +5497,7 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
if (!xobj) |
|
|
|
if (!xobj) |
|
|
|
return; |
|
|
|
return; |
|
|
|
xobj = this.xref.fetchIfRef(xobj); |
|
|
|
xobj = this.xref.fetchIfRef(xobj); |
|
|
|
assertWellFormed(IsStream(xobj), 'XObject should be a stream'); |
|
|
|
assertWellFormed(isStream(xobj), 'XObject should be a stream'); |
|
|
|
|
|
|
|
|
|
|
|
var oc = xobj.dict.get('OC'); |
|
|
|
var oc = xobj.dict.get('OC'); |
|
|
|
if (oc) { |
|
|
|
if (oc) { |
|
|
@ -5510,7 +5510,7 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var type = xobj.dict.get('Subtype'); |
|
|
|
var type = xobj.dict.get('Subtype'); |
|
|
|
assertWellFormed(IsName(type), 'XObject should have a Name subtype'); |
|
|
|
assertWellFormed(isName(type), 'XObject should have a Name subtype'); |
|
|
|
if ('Image' == type.name) { |
|
|
|
if ('Image' == type.name) { |
|
|
|
this.paintImageXObject(obj, xobj, false); |
|
|
|
this.paintImageXObject(obj, xobj, false); |
|
|
|
} else if ('Form' == type.name) { |
|
|
|
} else if ('Form' == type.name) { |
|
|
@ -5526,11 +5526,11 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
this.save(); |
|
|
|
this.save(); |
|
|
|
|
|
|
|
|
|
|
|
var matrix = stream.dict.get('Matrix'); |
|
|
|
var matrix = stream.dict.get('Matrix'); |
|
|
|
if (matrix && IsArray(matrix) && 6 == matrix.length) |
|
|
|
if (matrix && isArray(matrix) && 6 == matrix.length) |
|
|
|
this.transform.apply(this, matrix); |
|
|
|
this.transform.apply(this, matrix); |
|
|
|
|
|
|
|
|
|
|
|
var bbox = stream.dict.get('BBox'); |
|
|
|
var bbox = stream.dict.get('BBox'); |
|
|
|
if (bbox && IsArray(bbox) && 4 == bbox.length) { |
|
|
|
if (bbox && isArray(bbox) && 4 == bbox.length) { |
|
|
|
this.rectangle.apply(this, bbox); |
|
|
|
this.rectangle.apply(this, bbox); |
|
|
|
this.clip(); |
|
|
|
this.clip(); |
|
|
|
this.endPath(); |
|
|
|
this.endPath(); |
|
|
@ -5687,9 +5687,9 @@ var ColorSpace = (function colorSpaceColorSpace() { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.parse = function colorspace_parse(cs, xref, res) { |
|
|
|
constructor.parse = function colorspace_parse(cs, xref, res) { |
|
|
|
if (IsName(cs)) { |
|
|
|
if (isName(cs)) { |
|
|
|
var colorSpaces = xref.fetchIfRef(res.get('ColorSpace')); |
|
|
|
var colorSpaces = xref.fetchIfRef(res.get('ColorSpace')); |
|
|
|
if (IsDict(colorSpaces)) { |
|
|
|
if (isDict(colorSpaces)) { |
|
|
|
var refcs = colorSpaces.get(cs.name); |
|
|
|
var refcs = colorSpaces.get(cs.name); |
|
|
|
if (refcs) |
|
|
|
if (refcs) |
|
|
|
cs = refcs; |
|
|
|
cs = refcs; |
|
|
@ -5698,7 +5698,7 @@ var ColorSpace = (function colorSpaceColorSpace() { |
|
|
|
|
|
|
|
|
|
|
|
cs = xref.fetchIfRef(cs); |
|
|
|
cs = xref.fetchIfRef(cs); |
|
|
|
|
|
|
|
|
|
|
|
if (IsName(cs)) { |
|
|
|
if (isName(cs)) { |
|
|
|
var mode = cs.name; |
|
|
|
var mode = cs.name; |
|
|
|
this.mode = mode; |
|
|
|
this.mode = mode; |
|
|
|
|
|
|
|
|
|
|
@ -5717,7 +5717,7 @@ var ColorSpace = (function colorSpaceColorSpace() { |
|
|
|
default: |
|
|
|
default: |
|
|
|
error('unrecognized colorspace ' + mode); |
|
|
|
error('unrecognized colorspace ' + mode); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (IsArray(cs)) { |
|
|
|
} else if (isArray(cs)) { |
|
|
|
var mode = cs[0].name; |
|
|
|
var mode = cs[0].name; |
|
|
|
this.mode = mode; |
|
|
|
this.mode = mode; |
|
|
|
|
|
|
|
|
|
|
@ -5835,10 +5835,10 @@ var IndexedCS = (function indexedCS() { |
|
|
|
|
|
|
|
|
|
|
|
var length = baseNumComps * highVal; |
|
|
|
var length = baseNumComps * highVal; |
|
|
|
var lookupArray = new Uint8Array(length); |
|
|
|
var lookupArray = new Uint8Array(length); |
|
|
|
if (IsStream(lookup)) { |
|
|
|
if (isStream(lookup)) { |
|
|
|
var bytes = lookup.getBytes(length); |
|
|
|
var bytes = lookup.getBytes(length); |
|
|
|
lookupArray.set(bytes); |
|
|
|
lookupArray.set(bytes); |
|
|
|
} else if (IsString(lookup)) { |
|
|
|
} else if (isString(lookup)) { |
|
|
|
for (var i = 0; i < length; ++i) |
|
|
|
for (var i = 0; i < length; ++i) |
|
|
|
lookupArray[i] = lookup.charCodeAt(i); |
|
|
|
lookupArray[i] = lookup.charCodeAt(i); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -6034,7 +6034,7 @@ var Pattern = (function patternPattern() { |
|
|
|
var length = args.length; |
|
|
|
var length = args.length; |
|
|
|
|
|
|
|
|
|
|
|
var patternName = args[length - 1]; |
|
|
|
var patternName = args[length - 1]; |
|
|
|
if (!IsName(patternName)) |
|
|
|
if (!isName(patternName)) |
|
|
|
error('Bad args to getPattern: ' + patternName); |
|
|
|
error('Bad args to getPattern: ' + patternName); |
|
|
|
|
|
|
|
|
|
|
|
var patternRes = xref.fetchIfRef(res.get('Pattern')); |
|
|
|
var patternRes = xref.fetchIfRef(res.get('Pattern')); |
|
|
@ -6042,7 +6042,7 @@ var Pattern = (function patternPattern() { |
|
|
|
error('Unable to find pattern resource'); |
|
|
|
error('Unable to find pattern resource'); |
|
|
|
|
|
|
|
|
|
|
|
var pattern = xref.fetchIfRef(patternRes.get(patternName.name)); |
|
|
|
var pattern = xref.fetchIfRef(patternRes.get(patternName.name)); |
|
|
|
var dict = IsStream(pattern) ? pattern.dict : pattern; |
|
|
|
var dict = isStream(pattern) ? pattern.dict : pattern; |
|
|
|
var typeNum = dict.get('PatternType'); |
|
|
|
var typeNum = dict.get('PatternType'); |
|
|
|
|
|
|
|
|
|
|
|
switch (typeNum) { |
|
|
|
switch (typeNum) { |
|
|
@ -6073,7 +6073,7 @@ var Pattern = (function patternPattern() { |
|
|
|
constructor.parseShading = function pattern_shading(shading, matrix, |
|
|
|
constructor.parseShading = function pattern_shading(shading, matrix, |
|
|
|
xref, res, ctx) { |
|
|
|
xref, res, ctx) { |
|
|
|
|
|
|
|
|
|
|
|
var dict = IsStream(shading) ? shading.dict : shading; |
|
|
|
var dict = isStream(shading) ? shading.dict : shading; |
|
|
|
var type = dict.get('ShadingType'); |
|
|
|
var type = dict.get('ShadingType'); |
|
|
|
|
|
|
|
|
|
|
|
switch (type) { |
|
|
|
switch (type) { |
|
|
@ -6136,9 +6136,9 @@ var RadialAxialShading = (function radialAxialShading() { |
|
|
|
|
|
|
|
|
|
|
|
var fnObj = dict.get('Function'); |
|
|
|
var fnObj = dict.get('Function'); |
|
|
|
fnObj = xref.fetchIfRef(fnObj); |
|
|
|
fnObj = xref.fetchIfRef(fnObj); |
|
|
|
if (IsArray(fnObj)) |
|
|
|
if (isArray(fnObj)) |
|
|
|
error('No support for array of functions'); |
|
|
|
error('No support for array of functions'); |
|
|
|
else if (!IsPDFFunction(fnObj)) |
|
|
|
else if (!isPDFFunction(fnObj)) |
|
|
|
error('Invalid function'); |
|
|
|
error('Invalid function'); |
|
|
|
var fn = new PDFFunction(xref, fnObj); |
|
|
|
var fn = new PDFFunction(xref, fnObj); |
|
|
|
|
|
|
|
|
|
|
@ -6285,7 +6285,7 @@ var TilingPattern = (function tilingPattern() { |
|
|
|
graphics.transform.apply(graphics, tmpScale); |
|
|
|
graphics.transform.apply(graphics, tmpScale); |
|
|
|
graphics.transform.apply(graphics, tmpTranslate); |
|
|
|
graphics.transform.apply(graphics, tmpTranslate); |
|
|
|
|
|
|
|
|
|
|
|
if (bbox && IsArray(bbox) && 4 == bbox.length) { |
|
|
|
if (bbox && isArray(bbox) && 4 == bbox.length) { |
|
|
|
graphics.rectangle.apply(graphics, bbox); |
|
|
|
graphics.rectangle.apply(graphics, bbox); |
|
|
|
graphics.clip(); |
|
|
|
graphics.clip(); |
|
|
|
graphics.endPath(); |
|
|
|
graphics.endPath(); |
|
|
@ -6678,7 +6678,7 @@ var PDFFunction = (function pdfFunction() { |
|
|
|
var c1 = dict.get('C1') || [1]; |
|
|
|
var c1 = dict.get('C1') || [1]; |
|
|
|
var n = dict.get('N'); |
|
|
|
var n = dict.get('N'); |
|
|
|
|
|
|
|
|
|
|
|
if (!IsArray(c0) || !IsArray(c1)) |
|
|
|
if (!isArray(c0) || !isArray(c1)) |
|
|
|
error('Illegal dictionary for interpolated function'); |
|
|
|
error('Illegal dictionary for interpolated function'); |
|
|
|
|
|
|
|
|
|
|
|
var length = c0.length; |
|
|
|
var length = c0.length; |
|
|
|