[reportlab-users] czech characters
Ábrahám Péter
reportlab-users@reportlab.com
Sat, 29 Nov 2003 22:26:27 +0100
Milos Prudek írta:
> what is the proper way to write Czech accented characters?
>
> canvas,setfont( "Helvetica", 12 )
> canvas.writestring( X, Y, "ì¹èø¾ýáíáé" )
Hi,
I'm afraid this isn't so simple at the first sight. Look at my way to
create special Hungarian characters. The Czech ones must be similar.
More details can be found in the "Chapter 3 Fonts and encoding" section
of ReportLab's User Guide.
By
Peter
-----------------------
I've downloaded free Type1 iso-8859-2 coded fonts, (.afm, .pbf) and
copied these ones in a separate direcory called "font".
------------
import os
import string
from reportlab.pdfbase import pdfmetrics
class PDF_magyar:
def __init__(self):
own_code = pdfmetrics.Encoding("iso_8859-2", "WinAnsiEncoding")
own_code[189] = "hungarumlaut"
own_code[213] = "Ohungarumlaut"
own_code[219] = "Uhungarumlaut"
own_code[245] = "ohungarumlaut"
own_code[251] = "uhungarumlaut"
pdfmetrics.registerEncoding(own_code)
hun_font = [("ne21003l", "NimbusRomNo9LEE-Regu"), ("ne21004l",
"NimbusRomNo9LEE-Medi"), ("ne21023l", "NimbusRomNo9LEE-ReguItal"),
("ne21024l", "NimbusRomNo9LEE-MediItal")]
for i in hun_font:
afmFile = os.getcwd() + os.sep + "font" + os.sep + str(i[0])
+ ".afm"
pfbFile = os.getcwd() + os.sep + "font" + os.sep + str(i[0])
+ ".pfb"
justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
pdfmetrics.registerTypeFace(justFace)
justFont = pdfmetrics.Font(str(i[1]), str(i[1]), "iso_8859-2")
pdfmetrics.registerFont(justFont)
self.h_font_normal = "NimbusRomNo9LEE-Regu"
self.h_font_bold = "NimbusRomNo9LEE-Medi"
self.h_font_italic = "NimbusRomNo9LEE-ReguItal"
self.h_font_bold_italic = "NimbusRomNo9LEE-MediItal"
PDF_alap = PDF_magyar()
...
canvas.setFont(PDF_alap.h_font_normal, 12)
...