|
|
@ -158,19 +158,24 @@ function addContextCurrentTransform(ctx) { |
|
|
|
var CachedCanvases = (function CachedCanvasesClosure() { |
|
|
|
var CachedCanvases = (function CachedCanvasesClosure() { |
|
|
|
var cache = {}; |
|
|
|
var cache = {}; |
|
|
|
return { |
|
|
|
return { |
|
|
|
getCanvas: function CachedCanvases_getCanvas(id, width, height) { |
|
|
|
getCanvas: function CachedCanvases_getCanvas(id, width, height, |
|
|
|
var canvas; |
|
|
|
trackTransform) { |
|
|
|
|
|
|
|
var canvasEntry; |
|
|
|
if (id in cache) { |
|
|
|
if (id in cache) { |
|
|
|
canvas = cache[id]; |
|
|
|
canvasEntry = cache[id]; |
|
|
|
canvas.width = width; |
|
|
|
canvasEntry.canvas.width = width; |
|
|
|
canvas.height = height; |
|
|
|
canvasEntry.canvas.height = height; |
|
|
|
// reset canvas transform for emulated mozCurrentTransform, if needed
|
|
|
|
// reset canvas transform for emulated mozCurrentTransform, if needed
|
|
|
|
canvas.getContext('2d').setTransform(1, 0, 0, 1, 0, 0); |
|
|
|
canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
canvas = createScratchCanvas(width, height); |
|
|
|
var canvas = createScratchCanvas(width, height); |
|
|
|
cache[id] = canvas; |
|
|
|
var ctx = canvas.getContext('2d'); |
|
|
|
|
|
|
|
if (trackTransform) { |
|
|
|
|
|
|
|
addContextCurrentTransform(ctx); |
|
|
|
} |
|
|
|
} |
|
|
|
return canvas; |
|
|
|
cache[id] = canvasEntry = {canvas: canvas, context: ctx}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return canvasEntry; |
|
|
|
}, |
|
|
|
}, |
|
|
|
clear: function () { |
|
|
|
clear: function () { |
|
|
|
cache = {}; |
|
|
|
cache = {}; |
|
|
@ -399,6 +404,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
// spec 8.7.2 NOTE 1.
|
|
|
|
// spec 8.7.2 NOTE 1.
|
|
|
|
this.baseTransform = null; |
|
|
|
this.baseTransform = null; |
|
|
|
this.baseTransformStack = []; |
|
|
|
this.baseTransformStack = []; |
|
|
|
|
|
|
|
this.groupLevel = 0; |
|
|
|
if (canvasCtx) { |
|
|
|
if (canvasCtx) { |
|
|
|
addContextCurrentTransform(canvasCtx); |
|
|
|
addContextCurrentTransform(canvasCtx); |
|
|
|
} |
|
|
|
} |
|
|
@ -745,7 +751,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
// for patterns, we transform to pattern space, calculate
|
|
|
|
// for patterns, we transform to pattern space, calculate
|
|
|
|
// the pattern, call stroke, and restore to user space
|
|
|
|
// the pattern, call stroke, and restore to user space
|
|
|
|
ctx.save(); |
|
|
|
ctx.save(); |
|
|
|
ctx.strokeStyle = strokeColor.getPattern(ctx); |
|
|
|
ctx.strokeStyle = strokeColor.getPattern(ctx, this); |
|
|
|
ctx.stroke(); |
|
|
|
ctx.stroke(); |
|
|
|
ctx.restore(); |
|
|
|
ctx.restore(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -769,7 +775,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
if (fillColor && fillColor.hasOwnProperty('type') && |
|
|
|
if (fillColor && fillColor.hasOwnProperty('type') && |
|
|
|
fillColor.type === 'Pattern') { |
|
|
|
fillColor.type === 'Pattern') { |
|
|
|
ctx.save(); |
|
|
|
ctx.save(); |
|
|
|
ctx.fillStyle = fillColor.getPattern(ctx); |
|
|
|
ctx.fillStyle = fillColor.getPattern(ctx, this); |
|
|
|
needRestore = true; |
|
|
|
needRestore = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1393,7 +1399,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
|
|
|
|
|
|
|
|
this.save(); |
|
|
|
this.save(); |
|
|
|
var pattern = Pattern.shadingFromIR(patternIR); |
|
|
|
var pattern = Pattern.shadingFromIR(patternIR); |
|
|
|
ctx.fillStyle = pattern.getPattern(ctx); |
|
|
|
ctx.fillStyle = pattern.getPattern(ctx, this); |
|
|
|
|
|
|
|
|
|
|
|
var inv = ctx.mozCurrentTransformInverse; |
|
|
|
var inv = ctx.mozCurrentTransformInverse; |
|
|
|
if (inv) { |
|
|
|
if (inv) { |
|
|
@ -1505,9 +1511,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
var drawnWidth = Math.max(Math.ceil(bounds[2] - bounds[0]), 1); |
|
|
|
var drawnWidth = Math.max(Math.ceil(bounds[2] - bounds[0]), 1); |
|
|
|
var drawnHeight = Math.max(Math.ceil(bounds[3] - bounds[1]), 1); |
|
|
|
var drawnHeight = Math.max(Math.ceil(bounds[3] - bounds[1]), 1); |
|
|
|
|
|
|
|
|
|
|
|
var scratchCanvas = createScratchCanvas(drawnWidth, drawnHeight); |
|
|
|
var scratchCanvas = CachedCanvases.getCanvas( |
|
|
|
var groupCtx = scratchCanvas.getContext('2d'); |
|
|
|
'groupAt' + this.groupLevel, drawnWidth, drawnHeight, true); |
|
|
|
addContextCurrentTransform(groupCtx); |
|
|
|
var groupCtx = scratchCanvas.context; |
|
|
|
// Since we created a new canvas that is just the size of the bounding box
|
|
|
|
// Since we created a new canvas that is just the size of the bounding box
|
|
|
|
// we have to translate the group ctx.
|
|
|
|
// we have to translate the group ctx.
|
|
|
|
var offsetX = bounds[0]; |
|
|
|
var offsetX = bounds[0]; |
|
|
@ -1519,7 +1525,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
// location.
|
|
|
|
// location.
|
|
|
|
currentCtx.setTransform(1, 0, 0, 1, 0, 0); |
|
|
|
currentCtx.setTransform(1, 0, 0, 1, 0, 0); |
|
|
|
currentCtx.translate(offsetX, offsetY); |
|
|
|
currentCtx.translate(offsetX, offsetY); |
|
|
|
|
|
|
|
|
|
|
|
// The transparency group inherits all off the current graphics state
|
|
|
|
// The transparency group inherits all off the current graphics state
|
|
|
|
// except the blend mode, soft mask, and alpha constants.
|
|
|
|
// except the blend mode, soft mask, and alpha constants.
|
|
|
|
copyCtxState(currentCtx, groupCtx); |
|
|
|
copyCtxState(currentCtx, groupCtx); |
|
|
@ -1531,9 +1536,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
['CA', 1] |
|
|
|
['CA', 1] |
|
|
|
]); |
|
|
|
]); |
|
|
|
this.groupStack.push(currentCtx); |
|
|
|
this.groupStack.push(currentCtx); |
|
|
|
|
|
|
|
this.groupLevel++; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
endGroup: function CanvasGraphics_endGroup(group) { |
|
|
|
endGroup: function CanvasGraphics_endGroup(group) { |
|
|
|
|
|
|
|
this.groupLevel--; |
|
|
|
var groupCtx = this.ctx; |
|
|
|
var groupCtx = this.ctx; |
|
|
|
this.ctx = this.groupStack.pop(); |
|
|
|
this.ctx = this.groupStack.pop(); |
|
|
|
// Turn off image smoothing to avoid sub pixel interpolation which can
|
|
|
|
// Turn off image smoothing to avoid sub pixel interpolation which can
|
|
|
@ -1626,7 +1633,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); |
|
|
|
var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); |
|
|
|
var maskCtx = maskCanvas.getContext('2d'); |
|
|
|
var maskCtx = maskCanvas.context; |
|
|
|
maskCtx.save(); |
|
|
|
maskCtx.save(); |
|
|
|
|
|
|
|
|
|
|
|
putBinaryImageData(maskCtx, img); |
|
|
|
putBinaryImageData(maskCtx, img); |
|
|
@ -1636,12 +1643,12 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
var fillColor = this.current.fillColor; |
|
|
|
var fillColor = this.current.fillColor; |
|
|
|
maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') && |
|
|
|
maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') && |
|
|
|
fillColor.type === 'Pattern') ? |
|
|
|
fillColor.type === 'Pattern') ? |
|
|
|
fillColor.getPattern(maskCtx) : fillColor; |
|
|
|
fillColor.getPattern(maskCtx, this) : fillColor; |
|
|
|
maskCtx.fillRect(0, 0, width, height); |
|
|
|
maskCtx.fillRect(0, 0, width, height); |
|
|
|
|
|
|
|
|
|
|
|
maskCtx.restore(); |
|
|
|
maskCtx.restore(); |
|
|
|
|
|
|
|
|
|
|
|
this.paintInlineImageXObject(maskCanvas); |
|
|
|
this.paintInlineImageXObject(maskCanvas.canvas); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
paintImageMaskXObjectGroup: |
|
|
|
paintImageMaskXObjectGroup: |
|
|
@ -1653,7 +1660,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
var width = image.width, height = image.height; |
|
|
|
var width = image.width, height = image.height; |
|
|
|
|
|
|
|
|
|
|
|
var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); |
|
|
|
var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); |
|
|
|
var maskCtx = maskCanvas.getContext('2d'); |
|
|
|
var maskCtx = maskCanvas.context; |
|
|
|
maskCtx.save(); |
|
|
|
maskCtx.save(); |
|
|
|
|
|
|
|
|
|
|
|
putBinaryImageData(maskCtx, image); |
|
|
|
putBinaryImageData(maskCtx, image); |
|
|
@ -1663,7 +1670,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
var fillColor = this.current.fillColor; |
|
|
|
var fillColor = this.current.fillColor; |
|
|
|
maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') && |
|
|
|
maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') && |
|
|
|
fillColor.type === 'Pattern') ? |
|
|
|
fillColor.type === 'Pattern') ? |
|
|
|
fillColor.getPattern(maskCtx) : fillColor; |
|
|
|
fillColor.getPattern(maskCtx, this) : fillColor; |
|
|
|
maskCtx.fillRect(0, 0, width, height); |
|
|
|
maskCtx.fillRect(0, 0, width, height); |
|
|
|
|
|
|
|
|
|
|
|
maskCtx.restore(); |
|
|
|
maskCtx.restore(); |
|
|
@ -1671,7 +1678,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
ctx.save(); |
|
|
|
ctx.save(); |
|
|
|
ctx.transform.apply(ctx, image.transform); |
|
|
|
ctx.transform.apply(ctx, image.transform); |
|
|
|
ctx.scale(1, -1); |
|
|
|
ctx.scale(1, -1); |
|
|
|
ctx.drawImage(maskCanvas, 0, 0, width, height, |
|
|
|
ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, |
|
|
|
0, -1, 1, 1); |
|
|
|
0, -1, 1, 1); |
|
|
|
ctx.restore(); |
|
|
|
ctx.restore(); |
|
|
|
} |
|
|
|
} |
|
|
@ -1706,9 +1713,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
imgToPaint = imgData; |
|
|
|
imgToPaint = imgData; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height); |
|
|
|
var tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height); |
|
|
|
var tmpCtx = tmpCanvas.getContext('2d'); |
|
|
|
var tmpCtx = tmpCanvas.context; |
|
|
|
putBinaryImageData(tmpCtx, imgData); |
|
|
|
putBinaryImageData(tmpCtx, imgData); |
|
|
|
imgToPaint = tmpCanvas; |
|
|
|
imgToPaint = tmpCanvas.canvas; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var paintWidth = width, paintHeight = height; |
|
|
|
var paintWidth = width, paintHeight = height; |
|
|
@ -1729,11 +1736,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
var tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, |
|
|
|
var tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, |
|
|
|
newWidth, newHeight); |
|
|
|
newWidth, newHeight); |
|
|
|
tmpCtx = tmpCanvas.getContext('2d'); |
|
|
|
tmpCtx = tmpCanvas.context; |
|
|
|
tmpCtx.clearRect(0, 0, newWidth, newHeight); |
|
|
|
tmpCtx.clearRect(0, 0, newWidth, newHeight); |
|
|
|
tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, |
|
|
|
tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, |
|
|
|
0, 0, newWidth, newHeight); |
|
|
|
0, 0, newWidth, newHeight); |
|
|
|
imgToPaint = tmpCanvas; |
|
|
|
imgToPaint = tmpCanvas.canvas; |
|
|
|
paintWidth = newWidth; |
|
|
|
paintWidth = newWidth; |
|
|
|
paintHeight = newHeight; |
|
|
|
paintHeight = newHeight; |
|
|
|
tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1'; |
|
|
|
tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1'; |
|
|
@ -1761,7 +1768,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
var h = imgData.height; |
|
|
|
var h = imgData.height; |
|
|
|
|
|
|
|
|
|
|
|
var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h); |
|
|
|
var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h); |
|
|
|
var tmpCtx = tmpCanvas.getContext('2d'); |
|
|
|
var tmpCtx = tmpCanvas.context; |
|
|
|
putBinaryImageData(tmpCtx, imgData); |
|
|
|
putBinaryImageData(tmpCtx, imgData); |
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0, ii = map.length; i < ii; i++) { |
|
|
|
for (var i = 0, ii = map.length; i < ii; i++) { |
|
|
@ -1769,7 +1776,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
ctx.save(); |
|
|
|
ctx.save(); |
|
|
|
ctx.transform.apply(ctx, entry.transform); |
|
|
|
ctx.transform.apply(ctx, entry.transform); |
|
|
|
ctx.scale(1, -1); |
|
|
|
ctx.scale(1, -1); |
|
|
|
ctx.drawImage(tmpCanvas, entry.x, entry.y, entry.w, entry.h, |
|
|
|
ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, |
|
|
|
0, -1, 1, 1); |
|
|
|
0, -1, 1, 1); |
|
|
|
if (this.imageLayer) { |
|
|
|
if (this.imageLayer) { |
|
|
|
var position = this.getCanvasPosition(entry.x, entry.y); |
|
|
|
var position = this.getCanvasPosition(entry.x, entry.y); |
|
|
|