mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Fix #7798: Refactor scratch canvas usage.
Fixes extra canvas create calls. Fixes unnecessary call of `new DOMCanvasFactory`. Fixes undefined error of DOMCanvasFactory. Fixes failures in some of the tests. Fixes expected behaviour. Remove unused vars.
This commit is contained in:
parent
e132fa976e
commit
32817633c9
6 changed files with 64 additions and 25 deletions
|
@ -26,6 +26,7 @@
|
|||
}
|
||||
}(this, function (exports, sharedUtil) {
|
||||
|
||||
var assert = sharedUtil.assert;
|
||||
var removeNullCharacters = sharedUtil.removeNullCharacters;
|
||||
var warn = sharedUtil.warn;
|
||||
var deprecated = sharedUtil.deprecated;
|
||||
|
@ -33,6 +34,32 @@ var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
|
|||
|
||||
var DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
|
||||
|
||||
function DOMCanvasFactory() {}
|
||||
DOMCanvasFactory.prototype = {
|
||||
create: function DOMCanvasFactory_create(width, height) {
|
||||
assert(width > 0 && height > 0, 'invalid canvas size');
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
return canvas;
|
||||
},
|
||||
|
||||
reset: function DOMCanvasFactory_reset(canvas, width, height) {
|
||||
assert(canvas, 'canvas is not specified');
|
||||
assert(width > 0 && height > 0, 'invalid canvas size');
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
},
|
||||
|
||||
destroy: function DOMCanvasFactory_destroy(canvas) {
|
||||
assert(canvas, 'canvas is not specified');
|
||||
// Zeroing the width and height cause Firefox to release graphics
|
||||
// resources immediately, which can greatly reduce memory consumption.
|
||||
canvas.width = 0;
|
||||
canvas.height = 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Optimised CSS custom property getter/setter.
|
||||
* @class
|
||||
|
@ -248,4 +275,5 @@ exports.LinkTarget = LinkTarget;
|
|||
exports.hasCanvasTypedArrays = hasCanvasTypedArrays;
|
||||
exports.getDefaultSetting = getDefaultSetting;
|
||||
exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL;
|
||||
exports.DOMCanvasFactory = DOMCanvasFactory;
|
||||
}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue