[reportlab-users] Using bold and italic with a generic TTF
Tim Roberts
timr at probo.com
Mon Mar 12 13:28:40 EDT 2007
Lorenzo Mancini wrote:
> I'm using Reportlab 1.20 to generate PDF files. Since I have to include
> Korean and Turkish text, I'm using the Arial Unicode TTF.
>
> Everything works fine, until I try to use the <b> and <i> tags to obtain
> bold or italic glyphs. The tags are processed, but seem to be ignored: I
> always get regular text.
>
> After some experiments with registerFont/addMapping, it came to my mind
> that maybe the Arial Unicode font has only "regular" glyphs, and not the
> "italic" and "bold" ones.
>
This is correct.
> So, when I use registerFont/addMapping on a font that has only "regular"
> glyphs, Reportlab doesn't do any magic to convert them to bold and
> italic, it merely uses those regular glyphs even when the processed xml
> calls for bold and italic.
>
> (...correct?)
>
Correct. It NEVER does any magic. ReportLab keeps a table internally
that tells it "for the Arial font, the bold version is in arialbd.ttf,
the italic version is in ariali.ttf, and the bold italic version is in
arialbi.ttf". That table can be extended.
> That seemed to make sense, until I noticed that using that same font
> within OpenOffice, I can actually export to PDF with bold and italic
> characters from it (I've tried with Turkish and Korean text too, obviously).
>
It would be interesting to look at the PostScript, to see what
OpenOffice generates.
> Actually, I can export to PDF with bold and italic from *any* TTF. This
> can lead to one of the following:
>
> 1) Every TTF has the italic and bold variants of all its glyphs (???),
> but Reportlab 1.20 doesn't know how to extract/use them.
>
No. A bold font is an entirely separate .TTF file from the roman font.
> 2) OpenOffice uses the italic and bold TTF variants of a family when
> available (e.g. Arial family is composed by four TTFs, one for each
> style - regular, bold, italic, bold italic); if only regular style
> glyphs are available, it modifies the glyphs to make them look like bold
> and italic.
>
For GDI devices, Windows itself does this. If a bold version is not
available, it creates one by drawing the string twice, one or two pixels
apart. It uses a similar scheme for italics.
Assuming OpenOffice uses the Windows PostScript driver to do this, I
don't know what algorithm the driver uses.
> As I see it, the second scenario is much more realistic than the first,
> but I'd be glad to be corrected. If the second scenario is the right
> one: is a trick similar to OO's in the works for Reportlab, to obtain
> bold and italic glyphs even if the currently used TTF only has regular ones?
>
It is important to remember that ReportLab doesn't actually do any
rendering. ReportLab is generating instructions in the PostScript
computer language. Somewhere, there will be a PostScript interpreter
(usually in the printer) that interprets the PostScript and produces
output. There is very little that ReportLab can do about this, unless
we can reverse engineer something from the OpenOffice output.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the reportlab-users
mailing list