Merge pull request #7873 from timvandermeij/mediabox-cropbox-indirect

Document: handle indirect objects in `MediaBox` and `CropBox` entries
This commit is contained in:
Tim van der Meij 2016-12-08 23:59:45 +01:00 committed by GitHub
commit 47f03b619f
4 changed files with 109 additions and 15 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,12 +133,21 @@ var Page = (function PageClosure() {
},
get mediaBox() {
var obj = this.getInheritedPageProp('MediaBox');
var mediaBox = this.getInheritedPageProp('MediaBox', true);
// Reset invalid media box to letter size.
if (!isArray(obj) || obj.length !== 4) {
obj = LETTER_SIZE_MEDIABOX;
if (!isArray(mediaBox) || mediaBox.length !== 4) {
return shadow(this, 'mediaBox', LETTER_SIZE_MEDIABOX);
}
return shadow(this, 'mediaBox', obj);
return shadow(this, 'mediaBox', mediaBox);
},
get cropBox() {
var cropBox = this.getInheritedPageProp('CropBox', true);
// Reset invalid crop box to media box.
if (!isArray(cropBox) || cropBox.length !== 4) {
return shadow(this, 'cropBox', this.mediaBox);
}
return shadow(this, 'cropBox', cropBox);
},
get userUnit() {
@ -149,21 +159,16 @@ var Page = (function PageClosure() {
},
get view() {
var mediaBox = this.mediaBox;
var cropBox = this.getInheritedPageProp('CropBox');
if (!isArray(cropBox) || cropBox.length !== 4) {
return shadow(this, 'view', mediaBox);
}
// From the spec, 6th ed., p.963:
// "The crop, bleed, trim, and art boxes should not ordinarily
// extend beyond the boundaries of the media box. If they do, they are
// effectively reduced to their intersection with the media box."
cropBox = Util.intersect(cropBox, mediaBox);
if (!cropBox) {
var mediaBox = this.mediaBox, cropBox = this.cropBox;
if (mediaBox === cropBox) {
return shadow(this, 'view', mediaBox);
}
return shadow(this, 'view', cropBox);
var intersection = Util.intersect(cropBox, mediaBox);
return shadow(this, 'view', intersection || mediaBox);
},
get rotate() {

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",