From cb2a3afa7e010d1cd7a01c64f5c3ac58b6fd76d2 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 27 Jul 2018 12:48:48 +0200 Subject: [PATCH] [FIX] base: use -U+FEFF instead of U+2011 in -num In af64780a2 an improvement was done so a numerical fields like '-500' was not breaked up over two lines after the hyphen. But it seems in a very particular case of printing PDF in a given combination of condition: - printing over wkhtmltopdf which itself uses an old version of webkit - particular font (issue happen with Arial but not "Segoe UI") - particular version of windows (windows server 2012, not on windows 10) the - character at the front of a monetary, float or integer field would be displayed as | erroneously. The problem is probably that the font system in the old webkit with given windows will not find the code point in the given font, and doesn't fallback correctly. This commit replace using the "NON-BREAKING HYPHEN (U+2011)" by using the "ZERO WIDTH NO-BREAK SPACE (U+FEFF)" which is an invisible character with no width that prevent splitting at its location. As a note, an alternative to this character is "WORD JOINER (U+2060)" that may be preferred, but it presents exactly the same issue (with -|500 instead of -{WORD JOINER}500) in the same environment. mentioned in https://www.odoo.com/forum/1/question/118653 opw-1867842 fixes #17093 fixes #25840 closes #26019 --- openerp/addons/base/ir/ir_qweb.py | 8 ++++---- openerp/addons/test_converter/tests/test_html.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openerp/addons/base/ir/ir_qweb.py b/openerp/addons/base/ir/ir_qweb.py index 5af09a6b9e1..8045497e429 100644 --- a/openerp/addons/base/ir/ir_qweb.py +++ b/openerp/addons/base/ir/ir_qweb.py @@ -686,7 +686,7 @@ class IntegerConverter(osv.AbstractModel): context = {} lang_code = context.get('lang') or 'en_US' - return self.pool['res.lang'].format(cr, uid, [lang_code], '%d', value, grouping=True).replace(r'-', u'\u2011') + return self.pool['res.lang'].format(cr, uid, [lang_code], '%d', value, grouping=True).replace(r'-', u'-\N{ZERO WIDTH NO-BREAK SPACE}') class FloatConverter(osv.AbstractModel): _name = 'ir.qweb.field.float' @@ -704,7 +704,7 @@ class FloatConverter(osv.AbstractModel): lang_code = context.get('lang') or 'en_US' lang = self.pool['res.lang'] - formatted = lang.format(cr, uid, [lang_code], fmt.format(precision=precision), value, grouping=True).replace(r'-', u'\u2011') + formatted = lang.format(cr, uid, [lang_code], fmt.format(precision=precision), value, grouping=True).replace(r'-', u'-\N{ZERO WIDTH NO-BREAK SPACE}') # %f does not strip trailing zeroes. %g does but its precision causes # it to switch to scientific notation starting at a million *and* to @@ -889,7 +889,7 @@ class MonetaryConverter(osv.AbstractModel): lang = self.pool['res.lang'] formatted_amount = lang.format(cr, uid, [lang_code], fmt, Currency.round(cr, uid, display_currency, from_amount), - grouping=True, monetary=True).replace(r' ', u'\N{NO-BREAK SPACE}').replace(r'-', u'\u2011') + grouping=True, monetary=True).replace(r' ', u'\N{NO-BREAK SPACE}').replace(r'-', u'-\N{ZERO WIDTH NO-BREAK SPACE}') pre = post = u'' if display_currency.position == 'before': @@ -1055,7 +1055,7 @@ class QwebWidgetMonetary(osv.AbstractModel): lang_code = qwebcontext.context.get('lang') or 'en_US' formatted_amount = self.pool['res.lang'].format( qwebcontext.cr, qwebcontext.uid, [lang_code], fmt, inner, grouping=True, monetary=True - ).replace(r' ', u'\N{NO-BREAK SPACE}').replace(r'-', u'\u2011') + ).replace(r' ', u'\N{NO-BREAK SPACE}').replace(r'-', u'-\N{ZERO WIDTH NO-BREAK SPACE}') pre = post = u'' if display.position == 'before': pre = u'{symbol}\N{NO-BREAK SPACE}' diff --git a/openerp/addons/test_converter/tests/test_html.py b/openerp/addons/test_converter/tests/test_html.py index 5810e24c288..dd565f1650f 100644 --- a/openerp/addons/test_converter/tests/test_html.py +++ b/openerp/addons/test_converter/tests/test_html.py @@ -68,7 +68,7 @@ class TestFloatExport(TestBasicExport): converter = self.get_converter('float') value = converter(-42.0) - self.assertEqual(value, u"\u201142.0") + self.assertEqual(value, u"-\N{ZERO WIDTH NO-BREAK SPACE}42.0") value = converter(42.0100) self.assertEqual(value, "42.01") @@ -129,7 +129,7 @@ class TestCurrencyExport(TestExport): '' - u'\u20110.12' + u'-\N{ZERO WIDTH NO-BREAK SPACE}0.12' u'\N{NO-BREAK SPACE}{symbol}'.format( obj=obj, symbol=currency.symbol.encode('utf-8')