mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Ensure that Mesh /Shadings have non-zero width/height (issue 17848)
This commit is contained in:
parent
55db43966e
commit
07a8836ab2
5 changed files with 51 additions and 14 deletions
|
@ -1472,26 +1472,43 @@ class PartialEvaluator {
|
||||||
// Shadings and patterns may be referenced by the same name but the resource
|
// Shadings and patterns may be referenced by the same name but the resource
|
||||||
// dictionary could be different so we can't use the name for the cache key.
|
// dictionary could be different so we can't use the name for the cache key.
|
||||||
let id = localShadingPatternCache.get(shading);
|
let id = localShadingPatternCache.get(shading);
|
||||||
if (!id) {
|
if (id) {
|
||||||
var shadingFill = Pattern.parseShading(
|
return id;
|
||||||
|
}
|
||||||
|
let patternIR;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const shadingFill = Pattern.parseShading(
|
||||||
shading,
|
shading,
|
||||||
this.xref,
|
this.xref,
|
||||||
resources,
|
resources,
|
||||||
this._pdfFunctionFactory,
|
this._pdfFunctionFactory,
|
||||||
localColorSpaceCache
|
localColorSpaceCache
|
||||||
);
|
);
|
||||||
const patternIR = shadingFill.getIR();
|
patternIR = shadingFill.getIR();
|
||||||
id = `pattern_${this.idFactory.createObjId()}`;
|
} catch (reason) {
|
||||||
if (this.parsingType3Font) {
|
if (reason instanceof AbortException) {
|
||||||
id = `${this.idFactory.getDocId()}_type3_${id}`;
|
return null;
|
||||||
}
|
}
|
||||||
localShadingPatternCache.set(shading, id);
|
if (this.options.ignoreErrors) {
|
||||||
|
warn(`parseShading - ignoring shading: "${reason}".`);
|
||||||
|
|
||||||
if (this.parsingType3Font) {
|
localShadingPatternCache.set(shading, null);
|
||||||
this.handler.send("commonobj", [id, "Pattern", patternIR]);
|
return null;
|
||||||
} else {
|
|
||||||
this.handler.send("obj", [id, this.pageIndex, "Pattern", patternIR]);
|
|
||||||
}
|
}
|
||||||
|
throw reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = `pattern_${this.idFactory.createObjId()}`;
|
||||||
|
if (this.parsingType3Font) {
|
||||||
|
id = `${this.idFactory.getDocId()}_type3_${id}`;
|
||||||
|
}
|
||||||
|
localShadingPatternCache.set(shading, id);
|
||||||
|
|
||||||
|
if (this.parsingType3Font) {
|
||||||
|
this.handler.send("commonobj", [id, "Pattern", patternIR]);
|
||||||
|
} else {
|
||||||
|
this.handler.send("obj", [id, this.pageIndex, "Pattern", patternIR]);
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -1551,14 +1568,16 @@ class PartialEvaluator {
|
||||||
);
|
);
|
||||||
} else if (typeNum === PatternType.SHADING) {
|
} else if (typeNum === PatternType.SHADING) {
|
||||||
const shading = dict.get("Shading");
|
const shading = dict.get("Shading");
|
||||||
const matrix = dict.getArray("Matrix");
|
|
||||||
const objId = this.parseShading({
|
const objId = this.parseShading({
|
||||||
shading,
|
shading,
|
||||||
resources,
|
resources,
|
||||||
localColorSpaceCache,
|
localColorSpaceCache,
|
||||||
localShadingPatternCache,
|
localShadingPatternCache,
|
||||||
});
|
});
|
||||||
operatorList.addOp(fn, ["Shading", objId, matrix]);
|
if (objId) {
|
||||||
|
const matrix = dict.getArray("Matrix");
|
||||||
|
operatorList.addOp(fn, ["Shading", objId, matrix]);
|
||||||
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
throw new FormatError(`Unknown PatternType: ${typeNum}`);
|
throw new FormatError(`Unknown PatternType: ${typeNum}`);
|
||||||
|
@ -2109,6 +2128,9 @@ class PartialEvaluator {
|
||||||
localColorSpaceCache,
|
localColorSpaceCache,
|
||||||
localShadingPatternCache,
|
localShadingPatternCache,
|
||||||
});
|
});
|
||||||
|
if (!patternId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
args = [patternId];
|
args = [patternId];
|
||||||
fn = OPS.shadingFill;
|
fn = OPS.shadingFill;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -956,13 +956,20 @@ class MeshShading extends BaseShading {
|
||||||
}
|
}
|
||||||
|
|
||||||
getIR() {
|
getIR() {
|
||||||
|
const { bounds } = this;
|
||||||
|
// Ensure that the shading has non-zero width and height, to prevent errors
|
||||||
|
// in `pattern_helper.js` (fixes issue17848.pdf).
|
||||||
|
if (bounds[2] - bounds[0] === 0 || bounds[3] - bounds[1] === 0) {
|
||||||
|
throw new FormatError(`Invalid MeshShading bounds: [${bounds}].`);
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
"Mesh",
|
"Mesh",
|
||||||
this.shadingType,
|
this.shadingType,
|
||||||
this.coords,
|
this.coords,
|
||||||
this.colors,
|
this.colors,
|
||||||
this.figures,
|
this.figures,
|
||||||
this.bounds,
|
bounds,
|
||||||
this.bbox,
|
this.bbox,
|
||||||
this.background,
|
this.background,
|
||||||
];
|
];
|
||||||
|
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -462,6 +462,7 @@
|
||||||
!issue15716.pdf
|
!issue15716.pdf
|
||||||
!bug1671312_reduced.pdf
|
!bug1671312_reduced.pdf
|
||||||
!bug1671312_ArialNarrow.pdf
|
!bug1671312_ArialNarrow.pdf
|
||||||
|
!issue17848.pdf
|
||||||
!issue6108.pdf
|
!issue6108.pdf
|
||||||
!issue6113.pdf
|
!issue6113.pdf
|
||||||
!openoffice.pdf
|
!openoffice.pdf
|
||||||
|
|
BIN
test/pdfs/issue17848.pdf
Normal file
BIN
test/pdfs/issue17848.pdf
Normal file
Binary file not shown.
|
@ -2562,6 +2562,13 @@
|
||||||
"link": false,
|
"link": false,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "issue17848",
|
||||||
|
"file": "pdfs/issue17848.pdf",
|
||||||
|
"md5": "9a5b7ee97e1e03ad506115f15f9b57af",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "personwithdog",
|
"id": "personwithdog",
|
||||||
"file": "pdfs/personwithdog.pdf",
|
"file": "pdfs/personwithdog.pdf",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue