1#Copyright ReportLab Europe Ltd. 2000-2017
2#see license.txt for license details
3#history www.reportlab.co.uk/rl-cgi/viewcvs.cgi/rlextra/rlj/jpsupport.py
4# Temporary japanese support for ReportLab.
5"""
6The code in this module will disappear any day now and be replaced
7by classes in reportlab.pdfbase.cidfonts
8"""
9from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
10setOutDir(__name__)
11import string, os
12import codecs
13import unittest
14from reportlab.pdfbase import pdfmetrics
15from reportlab.pdfgen.canvas import Canvas
16from reportlab.lib import colors
17from reportlab.lib.codecharts import KutenRowCodeChart, hBoxText
18
19global VERBOSE
20VERBOSE = 0
21
22class CHSFontTests(unittest.TestCase):
23
24    def test0(self):
25        "A basic document drawing some strings"
26
27        # if they do not have the Japanese font files, go away quietly
28        from reportlab.pdfbase.cidfonts import UnicodeCIDFont, findCMapFile
29
30
31        pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))
32
33        c = Canvas(outputfile('test_multibyte_chs.pdf'))
34        c.setFont('Helvetica', 30)
35        c.drawString(100,700, 'Simplified Chinese Font Support')
36
37
38        c.setFont('Helvetica', 10)
39        c.drawString(100,680, 'Short sample: "China - Zhang Ziyi"  (famous actress)')
40        # the two typefaces
41
42        hBoxText(u'\u4e2d\u56fd - \u7ae0\u5b50\u6021',
43                 c,
44                 100,
45                 660,
46                 'STSong-Light',
47                 )
48
49
50        c.setFont('Helvetica',10)
51        c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber())
52        c.showPage()
53
54##        # full kuten chart in EUC
55##        c.setFont('Helvetica', 18)
56##        c.drawString(72,750, 'Characters available in GB 2312-80, EUC encoding')
57##        y = 600
58##        enc = 'GB_EUC_H'
59##        for row in range(1, 95):
60##            KutenRowCodeChart(row, 'STSong-Light',enc).drawOn(c, 72, y)
61##            y = y - 125
62##            if y < 50:
63##                c.setFont('Helvetica',10)
64##                c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber())
65##                c.showPage()
66##                y = 700
67##
68        c.save()
69        if VERBOSE:
70            print('saved '+outputfile('test_multibyte_chs.pdf'))
71
72
73def makeSuite():
74    return makeSuiteForClasses(CHSFontTests)
75
76
77#noruntests
78if __name__ == "__main__":
79    VERBOSE = 1
80    unittest.TextTestRunner().run(makeSuite())
81    printLocation()
82