Happy chinese new year!
In chinese new year holiday, I have test in the ubuntu 6.10, follow this step:
1. make sure python encoding is utf-8, do like this:
sudo vi /usr/lib/python2.4/sitecustomize.py
add follow:
Code:
import sys
sys.setdefaultencoding('UTF-8')
in windows, put sitecustomize.py in tinyerp bin path also work, but in ubuntu not work, need put in system path.
2. check the reportlab version, must 2.0, in ubuntu 6.10, apt-get install is reportlab2.0, so it's ok. (sudo apt-get install python-reportlab)
3. check the chinese fonts, ls /usr/share/fonts/turetype, for me, I just copy the windows fonts simsun.ttc ... to /usr/share/fonts/turetype.
open tinyerp-server/bin/report/render/rml2pdf/__init__.py, add follow:
Code:
from reportlab.lib.fonts import addMapping
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase.cidfonts import UnicodeCIDFont, findCMapFile
from reportlab.lib.fonts import addMapping
pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))
pdfmetrics.registerFont(TTFont('SimSun','simsun.ttc'))
pdfmetrics.registerFont(TTFont('SimHei','simhei.ttf'))
pdfmetrics.registerFont(TTFont('SimKai','simkai.ttf'))
pdfmetrics.registerFont(TTFont('SimFang','simfang.ttf'))
pdfmetrics.registerFont(TTFont('SimLi','simli.ttf'))
pdfmetrics.registerFont(TTFont('SimYou','simyou.ttf'))
for facename in ['SimSun','SimHei','SimKai','SimFang','SimLi','SimYou']:
addMapping(facename, 0, 0, facename) #normal
addMapping(facename, 0, 1, facename) #italic
addMapping(facename, 1, 0, facename) #bold
addMapping(facename, 1, 1, facename) #italic and bold
please change it to your fonts.
4. open tinyerp-server/bin/report/render/rml2pdf/, search encoding and change to encoding = 'UTF-8', then add follow after import os:
Code:
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle, StyleSheet1
def getZhSampleStyleSheet():
"""Returns a chinese stylesheet object"""
stylesheet = StyleSheet1()
stylesheet.add(ParagraphStyle(name='Normal',
fontName='SimSun',
fontSize=10,
leading=12)
)
stylesheet.add(ParagraphStyle(name='BodyText',
parent=stylesheet['Normal'],
spaceBefore=6)
)
stylesheet.add(ParagraphStyle(name='Italic',
parent=stylesheet['BodyText'],
fontName = 'SimSun')
)
stylesheet.add(ParagraphStyle(name='Heading1',
parent=stylesheet['Normal'],
fontName = 'SimSun',
fontSize=18,
leading=22,
spaceAfter=6),
alias='h1')
stylesheet.add(ParagraphStyle(name='Title',
parent=stylesheet['Normal'],
fontName = 'SimSun',
fontSize=18,
leading=22,
alignment=TA_CENTER,
spaceAfter=6),
alias='title')
stylesheet.add(ParagraphStyle(name='Heading2',
parent=stylesheet['Normal'],
fontName = 'SimSun',
fontSize=14,
leading=18,
spaceBefore=12,
spaceAfter=6),
alias='h2')
stylesheet.add(ParagraphStyle(name='Heading3',
parent=stylesheet['Normal'],
fontName = 'SimSun',
fontSize=12,
leading=14,
spaceBefore=12,
spaceAfter=6),
alias='h3')
stylesheet.add(ParagraphStyle(name='Bullet',
parent=stylesheet['Normal'],
firstLineIndent=0,
spaceBefore=3),
alias='bu')
stylesheet.add(ParagraphStyle(name='Definition',
parent=stylesheet['Normal'],
firstLineIndent=0,
leftIndent=36,
bulletIndent=0,
spaceBefore=6,
bulletFontName='SimSun'),
alias='df')
stylesheet.add(ParagraphStyle(name='Code',
parent=stylesheet['Normal'],
fontName='SimSun',
fontSize=8,
leading=8.8,
firstLineIndent=0,
leftIndent=36))
return stylesheet
search reportlab.lib.styles.getSampleStyleSheet() and replace to getZhSampleStyleSheet()
getZhSampleStyleSheet() just for a example, you can write your stylesheet by youself.
5. now you can test print screen, for me it's work.
6. you can change the font name in .xsl to your chinese font name, Simsun,...., make sure your editor encoding is utf-8.



[/code]