替换的工作直接交给linux完成。
-
获取中文字体文件 (本例中使用 simsun.ttc (全称: "SimSun"))
-
复制至 tiny/bin/reportlab/fonts/
这样你可以把字体文件拷贝到reportlab的目录下,
这个目录是在python的安装目录下的site-package>reportlab>font目录。
当然你将字体文件放在tiny/bin/reportlab/fonts/下也没有问题,
-
编辑 tiny/report/render/rml2pdf/trml2pdf.py, 插入以下代码:
encoding = 'UTF-8'
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
-
在同样的文件中搜索 reportlab.lib.styles.getSampleStyleSheet() 用 getZhSampleStyleSheet() 替换(共六处)
-
编辑 tiny/report/render/rml2pdf/init.py, 插入以下代码:
#add by chenzp
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
6.回到tinyerp的安装目录 。使用以下命令使所有的报表使用SimSun 字体:
sed -i 's/Times-Roman/SimSun/g' find ./addons -name "*.rml"
sed -i 's/Times-BoldItalic/SimSun/g' find ./addons -name "*.rml"
sed -i 's/Times-Bold/SimSun/g' find ./addons -name "*.rml"
sed -i 's/Times-Italic/SimSun/g' find ./addons -name "*.rml"
sed -i 's/Helvetica-BoldOblique/SimSun/g' find ./addons -name "*.rml"
sed -i 's/Helvetica-BoldOblique/SimSun/g' find ./addons -name "*.xsl"
sed -i 's/Helvetica-Bold/SimSun/g' find ./addons -name "*.rml"
sed -i 's/Helvetica-Bold/SimSun/g' find ./addons -name "*.xsl"
sed -i 's/Helvetica-Oblique/SimSun/g' find ./addons -name "*.xsl"
sed -i 's/Helvetica/SimSun/g' find ./addons -name "*.rml"
sed -i 's/Helvetica/SimSun/g' find ./addons -name "*.xsl"
sed -i 's/Courier-Bold/SimSun/g' find ./addons -name "*.rml"
sed -i 's/Courier/SimSun/g' find ./addons -name "*.xsl"
sed -i 's/Courier/SimSun/g' find ./addons -name "*.rml"
搞定!
[[i] 本帖最后由 openSourceERP 于 2008-10-13 13:58 编辑 [/i]]