From 7e5b14c40f4fbb00d64bc4e71c89739187857563 Mon Sep 17 00:00:00 2001 From: Leonardo Pavan Rocha Date: Fri, 9 Jul 2021 10:33:58 +0000 Subject: [PATCH] [IMP] sign: signature wizard behavior improvements Improves overall signature wizard usage. Signature will adjust its size to best fit the canvas, but maintaining its ratio. task-2596079 closes odoo/odoo#73493 Related: odoo/enterprise#19577 Signed-off-by: Yannick Tivisse (yti) --- .../static/src/legacy/js/libs/jSignatureCustom.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/legacy/js/libs/jSignatureCustom.js b/addons/web/static/src/legacy/js/libs/jSignatureCustom.js index da4ab05be15..617965ab68e 100644 --- a/addons/web/static/src/legacy/js/libs/jSignatureCustom.js +++ b/addons/web/static/src/legacy/js/libs/jSignatureCustom.js @@ -13,7 +13,7 @@ function _renderImageOnCanvas( data, formattype, rerendercallable ) { // Odoo override: // If a signature is saved in mobile resolution, when the user tries to sign a document in desktop, the size that is shown is the mobile size, which is strange for the user. - // This modifies the library method that adds the image to the canvas, resizing the image to the canvas size. + // This modifies the library method that adds the image to the canvas, resizing the image to the canvas size, keeping the image ratio and showing it centered. var img = new Image() // this = Canvas DOM elem. Not jQuery object. Not Canvas's parent div. @@ -23,10 +23,15 @@ function _renderImageOnCanvas( data, formattype, rerendercallable ) { var ctx = c.getContext("2d"); var oldShadowColor = ctx.shadowColor; ctx.shadowColor = "transparent"; + + var ratio = ((img.width / img.height) > (c.width / c.height)) ? c.width / img.width : c.height / img.height; + ctx.drawImage( - img, 0, 0 - , c.width - , c.height + img, + (c.width / 2) - (img.width * ratio / 2), + (c.height / 2) - (img.height * ratio / 2) + , img.width * ratio + , img.height * ratio ); ctx.shadowColor = oldShadowColor; };