Hi everybody,
Have been struggling with reports in Chinese for some days now. Like to share with you my experiences. I chose the route suggested by Dukai
on his blog (implemented in module base_report_unicode in addons-extras) as this seemed the most convenient. Unfortunately it doesn't work immediately for Chinese (and in version 5.0.2).
First I put the fonts SimSun and SimHei in the fonts directory of the module. Then I replaced the fontmap in __init__.py of that module by:
Code:
fontmap = {
'Times-Roman': 'SimSun',
'Times-BoldItalic': 'SimSun',
'Times-Bold': 'SimSun',
'Times-Italic': 'SimSun',
'Helvetica': 'SimHei',
'Helvetica-BoldItalic': 'SimHei',
'Helvetica-Bold': 'SimHei',
'Helvetica-Italic': 'SimHei',
'Helvetica-Oblique': 'SimHei',
'Helvetica-BoldOblique': 'SimHei',
'Courier': 'SimHei',
'Courier-Bold': 'SimHei',
'Courier-BoldItalic': 'SimHei',
'Courier-Italic': 'SimHei',
'Courier-Oblique': 'SimHei',
'Courier-BoldOblique': 'SimHei',
'Helvetica-ExtraLight': 'SimHei',
'TimesCondensed-Roman': 'SimSun',
'TimesCondensed-BoldItalic': 'SimSun',
'TimesCondensed-Bold': 'SimSun',
'TimesCondensed-Italic': 'SimSun',
'HelveticaCondensed': 'SimHei',
'HelveticaCondensed-BoldItalic': 'SimHei',
'HelveticaCondensed-Bold': 'SimHei',
'HelveticaCondensed-Italic': 'SimHei',
}
Note that I added a few permutations. I know for sure that also Helvetica-Oblique is used in some of the reports.
But you also need to to solve a bug in the code that goes unnoticed if not using the Chinese fonts. The bug is here:
Code:
for old, new in fontmap.iteritems():
data = data.replace(old, new)
This replaces the old fonts by the new fonts in the rml files. The problem is that a replacement is made also with partial matches. So the 'Helvetica' in 'Helvetica-Oblique' could very well be replaced by 'Simhei' resulting in the meaningless 'Simhei-Oblique' which results in an error.
I solved this by replacing the above code with:
Code:
while len(fontmap)>0:
ck=max(fontmap)
data = data.replace(ck,fontmap.pop(ck))
This did the trick! Hope you find it useful.