From dc7050ccef7b0bd2075a18e16880c1529802542e Mon Sep 17 00:00:00 2001 From: "Jacky (trj)" Date: Tue, 31 Aug 2021 11:22:05 +0000 Subject: [PATCH] [FIX] point_of_sale: html2canvas letterRendering is configurable The `letterRendering` option from the html2canvas broke the receipt's characters of some localizations/languages such as the arabic one. With this commit, we can simply override the `htmlToImgLetterRendering()` method from the `PosModel` when needed. closes odoo/odoo#75870 X-original-commit: 8b2c9bd026c0b7296c7be819a992ccac24b9b2e3 Related: odoo/enterprise#20559 Signed-off-by: pimodoo --- addons/point_of_sale/static/lib/html2canvas.js | 2 +- .../static/src/js/Screens/ReceiptScreen/ReceiptScreen.js | 2 +- addons/point_of_sale/static/src/js/models.js | 3 +++ addons/point_of_sale/static/src/js/printers.js | 4 +++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/static/lib/html2canvas.js b/addons/point_of_sale/static/lib/html2canvas.js index 4c228889b4e..035eb7a30bc 100644 --- a/addons/point_of_sale/static/lib/html2canvas.js +++ b/addons/point_of_sale/static/lib/html2canvas.js @@ -1211,7 +1211,7 @@ textNode.nodeValue = textTransform(textNode.nodeValue, getCSS(el, "textTransform")); textAlign = textAlign.replace(["-webkit-auto"],["auto"]); - textList = (!options.letterRendering && /^(left|right|justify|auto)$/.test(textAlign) && noLetterSpacing(getCSS(el, "letterSpacing"))) ? + textList = (!options.letterRendering && /^(left|right|justify|auto|center)$/.test(textAlign) && noLetterSpacing(getCSS(el, "letterSpacing"))) ? textNode.nodeValue.split(/(\b| )/) : textNode.nodeValue.split(""); diff --git a/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js b/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js index 720c65e4525..3ab04107846 100644 --- a/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js @@ -98,7 +98,7 @@ odoo.define('point_of_sale.ReceiptScreen', function (require) { return this.env.pos.proxy.printer && this.env.pos.config.iface_print_skip_screen && invoiced_finalized; } async _sendReceiptToCustomer() { - const printer = new Printer(); + const printer = new Printer(null, this.env.pos); const receiptString = this.orderReceipt.comp.el.outerHTML; const ticketImage = await printer.htmlToImg(receiptString); const order = this.currentOrder; diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 14f1b91e20c..d4fef3e320c 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1437,6 +1437,9 @@ exports.PosModel = Backbone.Model.extend({ }); product_model.loaded(this, product); }, + htmlToImgLetterRendering() { + return false; + }, }); /** diff --git a/addons/point_of_sale/static/src/js/printers.js b/addons/point_of_sale/static/src/js/printers.js index 9bc8b75886f..479de7580af 100644 --- a/addons/point_of_sale/static/src/js/printers.js +++ b/addons/point_of_sale/static/src/js/printers.js @@ -45,6 +45,7 @@ var PrinterMixin = { init: function() { this.receipt_queue = []; this.printResultGenerator = new PrintResultGenerator(); + this.htmlToImgLetterRendering = false; // Whether to render each letter seperately. Necessary if letter-spacing is used. }, /** @@ -103,7 +104,7 @@ var PrinterMixin = { $('.pos-receipt-print').empty(); resolve(self.process_canvas(canvas)); }, - letterRendering: true, + letterRendering: self.htmlToImgLetterRendering, }) }); return promise; @@ -132,6 +133,7 @@ var Printer = core.Class.extend(PrinterMixin, { init: function (url, pos) { PrinterMixin.init.call(this, arguments); this.pos = pos; + this.htmlToImgLetterRendering = pos.htmlToImgLetterRendering(); this.connection = new Session(undefined, url || 'http://localhost:8069', { use_cors: true}); },