[reportlab-users] using non standard fonts
Alessandro Praduroux
reportlab-users@reportlab.com
Wed, 12 Feb 2003 17:46:14 +0100
Hi all,
I'm trying to import a non standard font (Type 1) and to map the font to the
variations (bold, italic, bolditalic). I can import the typeface, but when I
try to use <b>bold</b> into the paragraph I don't get any bold face.
To load the font, I have a small description file that looks like that:
plain=Comic_Sans_MS.afm,Comic_Sans_MS.pfb
bold=Comic_Sans_MS_Bold.afm,Comic_Sans_MS_Bold.pfb
and when I load the font, I do the following:
# fnt is the description file
for ln in fnt.readlines():
ln = ln.strip()
tp = ln.split("=")[0]
files = ln.split("=")[1].split(",")
afmFile = os.path.join(folder + os.sep + 'enc',files[0])
pfbFile = os.path.join(folder + os.sep + 'enc',files[1])
justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
faceName = justFace.name
if not extFace:
extFace = faceName
pdfmetrics.registerTypeFace(justFace)
justFont = pdfmetrics.Font(faceName,faceName,'WinAnsiEncoding')
pdfmetrics.registerFont(justFont)
try:
if tp == "plain":
addMapping(fontname,0,0,faceName)
if tp == "bold":
addMapping(fontname,1,0,faceName)
if tp == "italic":
addMapping(fontname,0,1,faceName)
if tp == "bolditalic":
addMapping(fontname,1,1,faceName)
except:
pass # if we can't register a font, just give up
Looking in pdfmetrics.registerTypeFace, I see the following:
if not face.name in standardFonts:
fonts.addMapping(ttname, 0, 0, face.name)
fonts.addMapping(ttname, 1, 0, face.name)
fonts.addMapping(ttname, 0, 1, face.name)
fonts.addMapping(ttname, 1, 1, face.name)
So, it seems to me that whatever I do to load my font and register the correct
mapping, the values I supply are just ignored.
Is there a smarter way to do it, or I have to play with _tt2ps_map and friends
to get the desired behaviour? (that does not seem an option to me, playing
with the internals of the lib...)