|
|
@ -80,13 +80,6 @@ var IsLittleEndianCached = { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function createScratchCanvas(width, height) { |
|
|
|
|
|
|
|
var canvas = document.createElement('canvas'); |
|
|
|
|
|
|
|
canvas.width = width; |
|
|
|
|
|
|
|
canvas.height = height; |
|
|
|
|
|
|
|
return canvas; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addContextCurrentTransform(ctx) { |
|
|
|
function addContextCurrentTransform(ctx) { |
|
|
|
// If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
|
|
|
|
// If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
|
|
|
|
if (!ctx.mozCurrentTransform) { |
|
|
|
if (!ctx.mozCurrentTransform) { |
|
|
@ -204,7 +197,8 @@ function addContextCurrentTransform(ctx) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var CachedCanvases = (function CachedCanvasesClosure() { |
|
|
|
var CachedCanvases = (function CachedCanvasesClosure() { |
|
|
|
function CachedCanvases() { |
|
|
|
function CachedCanvases(canvasFactory) { |
|
|
|
|
|
|
|
this.canvasFactory = canvasFactory; |
|
|
|
this.cache = Object.create(null); |
|
|
|
this.cache = Object.create(null); |
|
|
|
} |
|
|
|
} |
|
|
|
CachedCanvases.prototype = { |
|
|
|
CachedCanvases.prototype = { |
|
|
@ -213,12 +207,11 @@ var CachedCanvases = (function CachedCanvasesClosure() { |
|
|
|
var canvasEntry; |
|
|
|
var canvasEntry; |
|
|
|
if (this.cache[id] !== undefined) { |
|
|
|
if (this.cache[id] !== undefined) { |
|
|
|
canvasEntry = this.cache[id]; |
|
|
|
canvasEntry = this.cache[id]; |
|
|
|
canvasEntry.canvas.width = width; |
|
|
|
this.canvasFactory.reset(canvasEntry.canvas, width, height); |
|
|
|
canvasEntry.canvas.height = height; |
|
|
|
|
|
|
|
// reset canvas transform for emulated mozCurrentTransform, if needed
|
|
|
|
// reset canvas transform for emulated mozCurrentTransform, if needed
|
|
|
|
canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0); |
|
|
|
canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var canvas = createScratchCanvas(width, height); |
|
|
|
var canvas = this.canvasFactory.create(width, height); |
|
|
|
var ctx = canvas.getContext('2d'); |
|
|
|
var ctx = canvas.getContext('2d'); |
|
|
|
if (trackTransform) { |
|
|
|
if (trackTransform) { |
|
|
|
addContextCurrentTransform(ctx); |
|
|
|
addContextCurrentTransform(ctx); |
|
|
@ -230,10 +223,7 @@ var CachedCanvases = (function CachedCanvasesClosure() { |
|
|
|
clear: function () { |
|
|
|
clear: function () { |
|
|
|
for (var id in this.cache) { |
|
|
|
for (var id in this.cache) { |
|
|
|
var canvasEntry = this.cache[id]; |
|
|
|
var canvasEntry = this.cache[id]; |
|
|
|
// Zeroing the width and height causes Firefox to release graphics
|
|
|
|
this.canvasFactory.destroy(canvasEntry.canvas); |
|
|
|
// resources immediately, which can greatly reduce memory consumption.
|
|
|
|
|
|
|
|
canvasEntry.canvas.width = 0; |
|
|
|
|
|
|
|
canvasEntry.canvas.height = 0; |
|
|
|
|
|
|
|
delete this.cache[id]; |
|
|
|
delete this.cache[id]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -456,7 +446,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
// Defines the number of steps before checking the execution time
|
|
|
|
// Defines the number of steps before checking the execution time
|
|
|
|
var EXECUTION_STEPS = 10; |
|
|
|
var EXECUTION_STEPS = 10; |
|
|
|
|
|
|
|
|
|
|
|
function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) { |
|
|
|
function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, |
|
|
|
|
|
|
|
imageLayer) { |
|
|
|
this.ctx = canvasCtx; |
|
|
|
this.ctx = canvasCtx; |
|
|
|
this.current = new CanvasExtraState(); |
|
|
|
this.current = new CanvasExtraState(); |
|
|
|
this.stateStack = []; |
|
|
|
this.stateStack = []; |
|
|
@ -466,6 +457,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
this.xobjs = null; |
|
|
|
this.xobjs = null; |
|
|
|
this.commonObjs = commonObjs; |
|
|
|
this.commonObjs = commonObjs; |
|
|
|
this.objs = objs; |
|
|
|
this.objs = objs; |
|
|
|
|
|
|
|
this.canvasFactory = canvasFactory; |
|
|
|
this.imageLayer = imageLayer; |
|
|
|
this.imageLayer = imageLayer; |
|
|
|
this.groupStack = []; |
|
|
|
this.groupStack = []; |
|
|
|
this.processingType3 = null; |
|
|
|
this.processingType3 = null; |
|
|
@ -477,7 +469,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
this.smaskStack = []; |
|
|
|
this.smaskStack = []; |
|
|
|
this.smaskCounter = 0; |
|
|
|
this.smaskCounter = 0; |
|
|
|
this.tempSMask = null; |
|
|
|
this.tempSMask = null; |
|
|
|
this.cachedCanvases = new CachedCanvases(); |
|
|
|
this.cachedCanvases = new CachedCanvases(this.canvasFactory); |
|
|
|
if (canvasCtx) { |
|
|
|
if (canvasCtx) { |
|
|
|
// NOTE: if mozCurrentTransform is polyfilled, then the current state of
|
|
|
|
// NOTE: if mozCurrentTransform is polyfilled, then the current state of
|
|
|
|
// the transformation must already be set in canvasCtx._transformMatrix.
|
|
|
|
// the transformation must already be set in canvasCtx._transformMatrix.
|
|
|
@ -1448,7 +1440,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
get isFontSubpixelAAEnabled() { |
|
|
|
get isFontSubpixelAAEnabled() { |
|
|
|
// Checks if anti-aliasing is enabled when scaled text is painted.
|
|
|
|
// Checks if anti-aliasing is enabled when scaled text is painted.
|
|
|
|
// On Windows GDI scaled fonts looks bad.
|
|
|
|
// On Windows GDI scaled fonts looks bad.
|
|
|
|
var ctx = document.createElement('canvas').getContext('2d'); |
|
|
|
var ctx = this.canvasFactory.create(10, 10).getContext('2d'); |
|
|
|
ctx.scale(1.5, 1); |
|
|
|
ctx.scale(1.5, 1); |
|
|
|
ctx.fillText('I', 0, 10); |
|
|
|
ctx.fillText('I', 0, 10); |
|
|
|
var data = ctx.getImageData(0, 0, 10, 10).data; |
|
|
|
var data = ctx.getImageData(0, 0, 10, 10).data; |
|
|
@ -1694,7 +1686,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
var self = this; |
|
|
|
var self = this; |
|
|
|
var canvasGraphicsFactory = { |
|
|
|
var canvasGraphicsFactory = { |
|
|
|
createCanvasGraphics: function (ctx) { |
|
|
|
createCanvasGraphics: function (ctx) { |
|
|
|
return new CanvasGraphics(ctx, self.commonObjs, self.objs); |
|
|
|
return new CanvasGraphics(ctx, self.commonObjs, self.objs, |
|
|
|
|
|
|
|
self.canvasFactory); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, |
|
|
|
pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, |
|
|
@ -2308,5 +2301,4 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
exports.CanvasGraphics = CanvasGraphics; |
|
|
|
exports.CanvasGraphics = CanvasGraphics; |
|
|
|
exports.createScratchCanvas = createScratchCanvas; |
|
|
|
|
|
|
|
})); |
|
|
|
})); |
|
|
|