[reportlab-users] CJK fonts

Robin Becker robin at reportlab.com
Tue Jun 21 05:32:51 EDT 2011


> So I think I'm using TTF fonts, I have no clue that T1 fonts would even work for

> Chinese because of the glyph limit... but in my text editor and browser, they or

> Windows do appropriate font substitutions, and the Chinese, since it is UTF-8,

> "just works".

Unless you are specifically declaring and registering a font it will not be used
in reportlab unless it is one of the standard 14. So for example this is from a
Japanese based test and uses msmincho.ttc

> from reportlab.pdfbase.ttfonts import TTFont

> try:

> msmincho = TTFont('MS Mincho','msmincho.ttc',subfontIndex=0,asciiReadable=0)

> fn = ' file=msmincho.ttc subfont 0'

> except:

> try:

> msmincho = TTFont('MS Mincho','msmincho.ttf',asciiReadable=0)

> fn = 'file=msmincho.ttf'

> except:

> #Ubuntu - works on Lucid Lynx if xpdf-japanese installed

> try:

> msmincho = TTFont('MS Mincho','ttf-japanese-mincho.ttf')

> fn = 'file=msmincho.ttf'

> except:

> msmincho = None

> if msmincho is None:

> c.setFont('Helvetica', 12)

> c.drawString(100,600, 'Cannot find msmincho.ttf or msmincho.ttc')

> else:

> pdfmetrics.registerFont(msmincho)

> c.setFont('MS Mincho', 30)

The same could be done for some of the MS fonts eg pmingliu.ttf or simsun.ttf,
but I am certainly no expert here.


> Being rather ignorant of Windows font APIs (I attempted to research Windows font

> APIs some time back, discovered there were at least 4 different font APIs

> available, couldn't figure out which were the new ones, or the recommended ones,

> and never did figure out any of them, since I didn't know which one to study), I

> wouldn't know either why it "just works" in the text editor and browser, and why

> it couldn't "just work" in reportlab... even if the embedded subset font would

> happen to contain characters from a substituted font, because that is what is

> available on the machine that is creating the PDF.


I don't believe we are using any specific API to obtain/find fonts.

> Is there any good reference material for Windows font APIs? I'm not even sure

> what Chinese font is in use on my computer to be substituted in for the

> characters that are not in Times-New-Roman, nor how to determine that, as a

> first step to specifying it for use in reportlab. Whatever it is, it must come

> with Windows.


I know that there is an Asian font pack for Acrobat reader (but that allows the
meta information to be rendered properly). In addition you can always add asian
language support from the windows OS, but which fonts that provides I don't
actually know.

> Is there any good reference material for how to solve my problem above using

> reportlab? I could probably figure out and code a solution, if I knew where to

> start...


Ask here, others have certainly faced and overcome these problems
Robin Becker

More information about the reportlab-users mailing list