mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Convert the DOMCanvasFactory
to an ES6 class
For consistency, also updates the `pdf2png.js` example to use the slightly less verbose `canvasAndContext` parameter name.
This commit is contained in:
parent
32baa6af7a
commit
c5f73edcd2
2 changed files with 30 additions and 31 deletions
|
@ -20,37 +20,36 @@ import {
|
|||
|
||||
var DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
|
||||
|
||||
function DOMCanvasFactory() {}
|
||||
DOMCanvasFactory.prototype = {
|
||||
create: function DOMCanvasFactory_create(width, height) {
|
||||
class DOMCanvasFactory {
|
||||
create(width, height) {
|
||||
assert(width > 0 && height > 0, 'invalid canvas size');
|
||||
var canvas = document.createElement('canvas');
|
||||
var context = canvas.getContext('2d');
|
||||
let canvas = document.createElement('canvas');
|
||||
let context = canvas.getContext('2d');
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
return {
|
||||
canvas,
|
||||
context,
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
reset: function DOMCanvasFactory_reset(canvasAndContextPair, width, height) {
|
||||
assert(canvasAndContextPair.canvas, 'canvas is not specified');
|
||||
reset(canvasAndContext, width, height) {
|
||||
assert(canvasAndContext.canvas, 'canvas is not specified');
|
||||
assert(width > 0 && height > 0, 'invalid canvas size');
|
||||
canvasAndContextPair.canvas.width = width;
|
||||
canvasAndContextPair.canvas.height = height;
|
||||
},
|
||||
canvasAndContext.canvas.width = width;
|
||||
canvasAndContext.canvas.height = height;
|
||||
}
|
||||
|
||||
destroy: function DOMCanvasFactory_destroy(canvasAndContextPair) {
|
||||
assert(canvasAndContextPair.canvas, 'canvas is not specified');
|
||||
destroy(canvasAndContext) {
|
||||
assert(canvasAndContext.canvas, 'canvas is not specified');
|
||||
// Zeroing the width and height cause Firefox to release graphics
|
||||
// resources immediately, which can greatly reduce memory consumption.
|
||||
canvasAndContextPair.canvas.width = 0;
|
||||
canvasAndContextPair.canvas.height = 0;
|
||||
canvasAndContextPair.canvas = null;
|
||||
canvasAndContextPair.context = null;
|
||||
canvasAndContext.canvas.width = 0;
|
||||
canvasAndContext.canvas.height = 0;
|
||||
canvasAndContext.canvas = null;
|
||||
canvasAndContext.context = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class DOMCMapReaderFactory {
|
||||
constructor({ baseUrl = null, isCompressed = false, }) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue