Apply bounding box before using shading patterns.

Fixes #8092
This commit is contained in:
Brendan Dahl 2019-05-23 17:45:25 -07:00
parent 1421b2f205
commit 6fab0a0dac
5 changed files with 191 additions and 8 deletions

View File

@ -96,6 +96,12 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
var cs = dict.get('ColorSpace', 'CS'); var cs = dict.get('ColorSpace', 'CS');
cs = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); cs = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
this.cs = cs; this.cs = cs;
const bbox = dict.getArray('BBox');
if (Array.isArray(bbox) && bbox.length === 4) {
this.bbox = Util.normalizeRect(bbox);
} else {
this.bbox = null;
}
var t0 = 0.0, t1 = 1.0; var t0 = 0.0, t1 = 1.0;
if (dict.has('Domain')) { if (dict.has('Domain')) {
@ -213,7 +219,7 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
} }
} }
return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1]; return ['RadialAxial', type, this.bbox, this.colorStops, p0, p1, r0, r1];
}, },
}; };
@ -719,7 +725,12 @@ Shadings.Mesh = (function MeshClosure() {
this.matrix = matrix; this.matrix = matrix;
this.shadingType = dict.get('ShadingType'); this.shadingType = dict.get('ShadingType');
this.type = 'Pattern'; this.type = 'Pattern';
this.bbox = dict.getArray('BBox'); const bbox = dict.getArray('BBox');
if (Array.isArray(bbox) && bbox.length === 4) {
this.bbox = Util.normalizeRect(bbox);
} else {
this.bbox = null;
}
var cs = dict.get('ColorSpace', 'CS'); var cs = dict.get('ColorSpace', 'CS');
cs = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); cs = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
this.cs = cs; this.cs = cs;

View File

@ -17,17 +17,30 @@ import { FormatError, info, Util } from '../shared/util';
var ShadingIRs = {}; var ShadingIRs = {};
function applyBoundingBox(ctx, bbox) {
if (!bbox || typeof Path2D === 'undefined') {
return;
}
const width = bbox[2] - bbox[0];
const height = bbox[3] - bbox[1];
const region = new Path2D();
region.rect(bbox[0], bbox[1], width, height);
ctx.clip(region);
}
ShadingIRs.RadialAxial = { ShadingIRs.RadialAxial = {
fromIR: function RadialAxial_fromIR(raw) { fromIR: function RadialAxial_fromIR(raw) {
var type = raw[1]; var type = raw[1];
var colorStops = raw[2]; var bbox = raw[2];
var p0 = raw[3]; var colorStops = raw[3];
var p1 = raw[4]; var p0 = raw[4];
var r0 = raw[5]; var p1 = raw[5];
var r1 = raw[6]; var r0 = raw[6];
var r1 = raw[7];
return { return {
type: 'Pattern', type: 'Pattern',
getPattern: function RadialAxial_getPattern(ctx) { getPattern: function RadialAxial_getPattern(ctx) {
applyBoundingBox(ctx, bbox);
var grad; var grad;
if (type === 'axial') { if (type === 'axial') {
grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]); grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
@ -233,11 +246,12 @@ ShadingIRs.Mesh = {
var figures = raw[4]; var figures = raw[4];
var bounds = raw[5]; var bounds = raw[5];
var matrix = raw[6]; var matrix = raw[6];
// var bbox = raw[7]; var bbox = raw[7];
var background = raw[8]; var background = raw[8];
return { return {
type: 'Pattern', type: 'Pattern',
getPattern: function Mesh_getPattern(ctx, owner, shadingFill) { getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
applyBoundingBox(ctx, bbox);
var scale; var scale;
if (shadingFill) { if (shadingFill) {
scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform); scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);

View File

@ -14,6 +14,7 @@
!issue3214.pdf !issue3214.pdf
!issue4665.pdf !issue4665.pdf
!issue4684.pdf !issue4684.pdf
!issue8092.pdf
!issue5256.pdf !issue5256.pdf
!issue5801.pdf !issue5801.pdf
!issue5946.pdf !issue5946.pdf

151
test/pdfs/issue8092.pdf Normal file
View File

@ -0,0 +1,151 @@
%PDF-1.5
%Çì<C387>¢
5 0 obj
<</Length 6 0 R/Filter /FlateDecode>>
stream
xœUÌË0Ðý|Å]ê°@ q)ôHyÕ`ËËÈçÛÆ•¹ÉÌd&gf0œl~U¾((ô«m)äV©ÉÝxÆÆ!:»èi¦Š\XÆB°¢#E~ÈÁcˆç]Õ#ª¡n”î¡4Ê[Ž‹Íjªe{Oò¢ÄOÒŒÁs,ú¨m@±OF·zsþ®·v™ÌXoÊh\ßZºÁÙBÐÃæ ,²6åendstream
endobj
6 0 obj
166
endobj
4 0 obj
<</Type/Page/MediaBox [0 0 595 842]
/Rotate 0/Parent 3 0 R
/Resources<</ProcSet[/PDF /Text]
/ColorSpace 13 0 R
/ExtGState 14 0 R
/Pattern 15 0 R
/Shading 16 0 R
/Font 17 0 R
>>
/Contents 5 0 R
>>
endobj
3 0 obj
<< /Type /Pages /Kids [
4 0 R
] /Count 1
>>
endobj
1 0 obj
<</Type /Catalog /Pages 3 0 R
/Metadata 18 0 R
>>
endobj
7 0 obj
<</Type/ExtGState
/OPM 1>>endobj
8 0 obj
[/Pattern]
endobj
13 0 obj
<</R8
8 0 R>>
endobj
14 0 obj
<</R7
7 0 R>>
endobj
15 0 obj
<</R9
9 0 R>>
endobj
9 0 obj
<</PatternType 2
/Shading 10 0 R
/Matrix[1
0
0
1
0
0]>>endobj
16 0 obj
<</R10
10 0 R>>
endobj
10 0 obj
<</ShadingType 2
/ColorSpace/DeviceRGB
/BBox[72
72
540
720]
/Coords[216
216
396
576]
/Function 11 0 R
/Extend [true false]>>endobj
17 0 obj
<</R12
12 0 R>>
endobj
11 0 obj
<</FunctionType 2
/Domain[0
1]
/C0[1
0
1]
/C1[0
1
1]
/N 1>>endobj
12 0 obj
<</BaseFont/Courier-Bold/Type/Font
/Subtype/Type1>>
endobj
18 0 obj
<</Type/Metadata
/Subtype/XML/Length 1371>>stream
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
<?adobe-xap-filters esc="CRLF"?>
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP toolkit 2.9.1-13, framework 1.6'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>
<rdf:Description rdf:about='uuid:5f8db3e5-1ae5-11e4-0000-a95b86321679' xmlns:pdf='http://ns.adobe.com/pdf/1.3/' pdf:Producer='GPL Ghostscript 9.06'/>
<rdf:Description rdf:about='uuid:5f8db3e5-1ae5-11e4-0000-a95b86321679' xmlns:xmp='http://ns.adobe.com/xap/1.0/'><xmp:ModifyDate>2014-07-31T04:08:37-04:00</xmp:ModifyDate>
<xmp:CreateDate>2014-07-31T04:08:37-04:00</xmp:CreateDate>
<xmp:CreatorTool>Henry McGilton for Adobe Systems Incorporated</xmp:CreatorTool></rdf:Description>
<rdf:Description rdf:about='uuid:5f8db3e5-1ae5-11e4-0000-a95b86321679' xmlns:xapMM='http://ns.adobe.com/xap/1.0/mm/' xapMM:DocumentID='uuid:5f8db3e5-1ae5-11e4-0000-a95b86321679'/>
<rdf:Description rdf:about='uuid:5f8db3e5-1ae5-11e4-0000-a95b86321679' xmlns:dc='http://purl.org/dc/elements/1.1/' dc:format='application/pdf'><dc:title><rdf:Alt><rdf:li xml:lang='x-default'>Ash02.ps</rdf:li></rdf:Alt></dc:title></rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?>
endstream
endobj
2 0 obj
<</Producer(GPL Ghostscript 9.06)
/CreationDate(D:20140731040837-04'00')
/ModDate(D:20140731040837-04'00')
/Title(Ash02.ps)
/Creator(Henry McGilton for Adobe Systems Incorporated)>>endobj
xref
0 19
0000000000 65535 f
0000000540 00000 n
0000002627 00000 n
0000000481 00000 n
0000000270 00000 n
0000000015 00000 n
0000000251 00000 n
0000000605 00000 n
0000000646 00000 n
0000000762 00000 n
0000000864 00000 n
0000001036 00000 n
0000001111 00000 n
0000000672 00000 n
0000000702 00000 n
0000000732 00000 n
0000000832 00000 n
0000001004 00000 n
0000001179 00000 n
trailer
<< /Size 19 /Root 1 0 R /Info 2 0 R
/ID [<DBD6B1FC3282E2424AD4E053FFD653D0><DBD6B1FC3282E2424AD4E053FFD653D0>]
>>
startxref
2823
%%EOF

View File

@ -654,6 +654,12 @@
"type": "eq", "type": "eq",
"about": "Type1 font with |Ref|s in the Differences array of the Encoding dictionary." "about": "Type1 font with |Ref|s in the Differences array of the Encoding dictionary."
}, },
{ "id": "issue8092",
"file": "pdfs/issue8092.pdf",
"md5": "e4f3376b35fd132580246c3db1fbd738",
"rounds": 1,
"type": "eq"
},
{ "id": "franz_2", { "id": "franz_2",
"file": "pdfs/franz_2.pdf", "file": "pdfs/franz_2.pdf",
"md5": "9d301ed8816e879891115b5cc3c39559", "md5": "9d301ed8816e879891115b5cc3c39559",