1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #8266 from brendandahl/issue6652

Normalize blend mode names.
This commit is contained in:
Jonas Jenwald 2017-04-11 08:54:42 +02:00 committed by GitHub
commit 10e5f766a2
5 changed files with 134 additions and 17 deletions

View file

@ -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;
@ -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')) {

View file

@ -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) {
@ -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]
]);
@ -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]
]);