Skip to content

Commit

Permalink
Normalize blend mode names.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandahl committed Apr 10, 2017
1 parent c5199d0 commit 4969b2a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
46 changes: 45 additions & 1 deletion src/core/evaluator.js
Expand Up @@ -217,6 +217,50 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
};

// Convert PDF blend mode names to HTML5 blend mode names.
function normalizeBlendMode(value) {
if (!isName(value)) {
return 'source-over';
}
switch (value.name) {
case 'Normal':
case 'Compatible':
return 'source-over';
case 'Multiply':
return 'multiply';
case 'Screen':
return 'screen';
case 'Overlay':
return 'overlay';
case 'Darken':
return 'darken';
case 'Lighten':
return 'lighten';
case 'ColorDodge':
return 'color-dodge';
case 'ColorBurn':
return 'color-burn';
case 'HardLight':
return 'hard-light';
case 'SoftLight':
return 'soft-light';
case 'Difference':
return 'difference';
case 'Exclusion':
return 'exclusion';
case 'Hue':
return 'hue';
case 'Saturation':
return 'saturation';
case 'Color':
return 'color';
case 'Luminosity':
return 'luminosity';
}
warn('Unsupported blend mode: ' + value.name);
return 'source-over';
}

var deferred = Promise.resolve();

var TILING_PATTERN = 1, SHADING_PATTERN = 2;
Expand Down Expand Up @@ -606,7 +650,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
});
break;
case 'BM':
gStateObj.push([key, value]);
gStateObj.push([key, normalizeBlendMode(value)]);
break;
case 'SMask':
if (isName(value, 'None')) {
Expand Down
19 changes: 3 additions & 16 deletions src/display/canvas.js
Expand Up @@ -950,20 +950,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.ctx.globalAlpha = state[1];
break;
case 'BM':
if (value && value.name && (value.name !== 'Normal')) {
var mode = value.name.replace(/([A-Z])/g,
function(c) {
return '-' + c.toLowerCase();
}
).substring(1);
this.ctx.globalCompositeOperation = mode;
if (this.ctx.globalCompositeOperation !== mode) {
warn('globalCompositeOperation "' + mode +
'" is not supported');
}
} else {
this.ctx.globalCompositeOperation = 'source-over';
}
this.ctx.globalCompositeOperation = value;
break;
case 'SMask':
if (this.current.activeSMask) {
Expand Down Expand Up @@ -1010,7 +997,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
copyCtxState(currentCtx, groupCtx);
this.ctx = groupCtx;
this.setGState([
['BM', 'Normal'],
['BM', 'source-over'],
['ca', 1],
['CA', 1]
]);
Expand Down Expand Up @@ -1885,7 +1872,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
copyCtxState(currentCtx, groupCtx);
this.ctx = groupCtx;
this.setGState([
['BM', 'Normal'],
['BM', 'source-over'],
['ca', 1],
['CA', 1]
]);
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Expand Up @@ -21,6 +21,7 @@
!issue5874.pdf
!issue5808.pdf
!issue6204.pdf
!issue6652.pdf
!issue6782.pdf
!issue6901.pdf
!issue6961.pdf
Expand Down
Binary file added test/pdfs/issue6652.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Expand Up @@ -1899,6 +1899,13 @@
"link": false,
"type": "eq"
},
{ "id": "issue6652",
"file": "pdfs/issue6652.pdf",
"md5": "1c8e2953f84623bc773eb720c87a9331",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue5801",
"file": "pdfs/issue5801.pdf",
"md5": "e9548650ad40e13e00d2a486bbc2bb1b",
Expand Down

0 comments on commit 4969b2a

Please sign in to comment.