Add a parameter to Page_getInheritedPageProp to make it possible to fetch (and dereference) Arrays, and use that for the MediaBox/CropBox getters (issue 7872)

This commit is contained in:
Jonas Jenwald 2016-12-06 10:21:42 +01:00 committed by Tim van der Meij
parent caf81685cb
commit 9be3aee9c9
4 changed files with 94 additions and 4 deletions

View File

@ -91,13 +91,14 @@ var Page = (function PageClosure() {
return this.pageDict.get(key);
},
getInheritedPageProp: function Page_getInheritedPageProp(key) {
getInheritedPageProp: function Page_getInheritedPageProp(key, getArray) {
var dict = this.pageDict, valueArray = null, loopCount = 0;
var MAX_LOOP_COUNT = 100;
getArray = getArray || false;
// Always walk up the entire parent chain, to be able to find
// e.g. \Resources placed on multiple levels of the tree.
while (dict) {
var value = dict.get(key);
var value = getArray ? dict.getArray(key) : dict.get(key);
if (value) {
if (!valueArray) {
valueArray = [];
@ -132,7 +133,7 @@ var Page = (function PageClosure() {
},
get mediaBox() {
var obj = this.getInheritedPageProp('MediaBox');
var obj = this.getInheritedPageProp('MediaBox', true);
// Reset invalid media box to letter size.
if (!isArray(obj) || obj.length !== 4) {
obj = LETTER_SIZE_MEDIABOX;
@ -150,7 +151,7 @@ var Page = (function PageClosure() {
get view() {
var mediaBox = this.mediaBox;
var cropBox = this.getInheritedPageProp('CropBox');
var cropBox = this.getInheritedPageProp('CropBox', true);
if (!isArray(cropBox) || cropBox.length !== 4) {
return shadow(this, 'view', mediaBox);
}

View File

@ -43,6 +43,7 @@
!issue7665.pdf
!issue7835.pdf
!issue7855.pdf
!issue7872.pdf
!bad-PageLabels.pdf
!filled-background.pdf
!ArabicCIDTrueType.pdf

80
test/pdfs/issue7872.pdf Normal file
View File

@ -0,0 +1,80 @@
%PDF-1.7
%âãÏÓ
1 0 obj
<<
/Pages 2 0 R
/Type /Catalog
>>
endobj
2 0 obj
<<
/Kids [3 0 R]
/Count 1
/Type /Pages
>>
endobj
3 0 obj
<<
/CropBox [4 0 R 5 0 R 6 0 R 7 0 R]
/Parent 2 0 R
/MediaBox [4 0 R 5 0 R 6 0 R 7 0 R]
/Resources
<<
/Font
<<
/F1 8 0 R
>>
>>
/Contents 9 0 R
/Type /Page
>>
endobj
8 0 obj
<<
/BaseFont /Times-Roman
/Subtype /Type1
/Encoding /WinAnsiEncoding
/Type /Font
>>
endobj
9 0 obj
<<
/Length 74
>>
stream
BT
10 20 TD
/F1 12 Tf
(MediaBox and CropBox with indirect objects.) Tj
ET
endstream
endobj
4 0 obj 0
endobj
5 0 obj 0
endobj
6 0 obj 250
endobj
7 0 obj 50
endobj xref
0 10
0000000000 65535 f
0000000015 00000 n
0000000066 00000 n
0000000125 00000 n
0000000530 00000 n
0000000548 00000 n
0000000566 00000 n
0000000586 00000 n
0000000302 00000 n
0000000403 00000 n
trailer
<<
/Root 1 0 R
/Size 10
>>
startxref
604
%%EOF

View File

@ -1343,6 +1343,14 @@
"link": true,
"type": "eq"
},
{ "id": "issue7872",
"file": "pdfs/issue7872.pdf",
"md5": "81781dfecfcb7e9cd9cc7e60f8b747b7",
"rounds": 1,
"link": false,
"type": "eq",
"about": "MediaBox and CropBox with indirect objects."
},
{ "id": "issue2642",
"file": "pdfs/issue2642.pdf",
"md5": "b6679861fdce3bbab0c1fa51bb7f5077",