[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
This commit is contained in:
@@ -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}'
|
||||
|
||||
@@ -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):
|
||||
'<span data-oe-model="{obj._model._name}" data-oe-id="{obj.id}" '
|
||||
'data-oe-field="value" data-oe-type="monetary" '
|
||||
'data-oe-expression="obj.value">'
|
||||
u'<span class="oe_currency_value">\u20110.12</span>'
|
||||
u'<span class="oe_currency_value">-\N{ZERO WIDTH NO-BREAK SPACE}0.12</span>'
|
||||
u'\N{NO-BREAK SPACE}{symbol}</span>'.format(
|
||||
obj=obj,
|
||||
symbol=currency.symbol.encode('utf-8')
|
||||
|
||||
Reference in New Issue
Block a user