From d07ad5b8baa845e2dfce6b2ecafdcb24ef891970 Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 10 Jan 2020 20:35:36 +0800 Subject: [PATCH] fix: drawImageByCanvas --- src/core/helpers/hidpi.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/core/helpers/hidpi.js b/src/core/helpers/hidpi.js index 88eae7d67..0c131d104 100644 --- a/src/core/helpers/hidpi.js +++ b/src/core/helpers/hidpi.js @@ -38,6 +38,24 @@ const ratioArgs = { } const proto = CanvasRenderingContext2D.prototype + +proto.drawImageByCanvas = (function (_super) { + return function (canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh, isScale) { + if (!this.__hidpi__) { + return _super.apply(this, arguments) + } + srcx *= pixelRatio + srcy *= pixelRatio + srcw *= pixelRatio + srch *= pixelRatio + desx *= pixelRatio + desy *= pixelRatio + desw = isScale ? desw * pixelRatio : desw + desh = isScale ? desh * pixelRatio : desh + _super.call(this, canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh) + } +})(proto.drawImage) + if (pixelRatio !== 1) { forEach(ratioArgs, function (value, key) { proto[key] = (function (_super) { @@ -141,23 +159,6 @@ if (pixelRatio !== 1) { })(proto.drawImage) } -proto.drawImageByCanvas = (function (_super) { - return function (canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh, isScale) { - if (!this.__hidpi__) { - return _super.apply(this, arguments) - } - srcx *= pixelRatio - srcy *= pixelRatio - srcw *= pixelRatio - srch *= pixelRatio - desx *= pixelRatio - desy *= pixelRatio - desw = isScale ? desw * pixelRatio : desw - desh = isScale ? desh * pixelRatio : desh - _super.call(this, canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh) - } -})(proto.drawImage) - export function wrapper (canvas) { canvas.width = canvas.offsetWidth * pixelRatio canvas.height = canvas.offsetHeight * pixelRatio -- GitLab