It is currently Sat Feb 11, 2012 7:02 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Printing with Chinese Fonts, using base_report_unicode
PostPosted: Wed Sep 02, 2009 1:54 pm 
Offline

Joined: Mon Jul 20, 2009 2:52 pm
Posts: 26
Location: Shanghai
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 11, 2009 2:25 pm 
Offline

Joined: Thu Jun 25, 2009 6:19 am
Posts: 75
Location: Shanghai
Thanks a lot for this how-to. Some precisions from my side after struggling one afternoon to set it up:

- Those 2 TTF files you mention can be found in Windows XP c:/windows/fonts directory

- I am used not to unzip the imported modules but in case of base_report_unicode, this leads to the problem which is the module cant find the 2 chinese TTF. So I recommand the following steps:
1. download the latest version of the base_report_unicode module from bazar
2. unzip the module in addons directory. Delete zip file in addons directory
3. place the 2 windows fonts file in ../addons/base_report_unicode/fonts with name "SimSun.ttf" and "SimHei.ttf"
3. change the __init__.py as recommanded by bhikkhu
4. Do not forget to reset your rights on addons folder and restart your server.

some information in this post : http://openobject.com/forum/topic9962.html

There is a module called base_report_cn as well, including part of the information of the current post but fonts mapping is not as complete as this one.

Eric


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP