[reportlab-users] Built-in versus embedded fonts

Marius Gedminas marius at gedmin.as
Mon Jun 22 04:16:22 EDT 2015


On Sat, Jun 20, 2015 at 06:16:37PM -0700, Glenn Linderman wrote:
> As an outgrowth of the "Helvetica" reference (and I've got working code to
> avoid it now, but would like the Canvas parameter for initial_fontname in
> time, thanks), I found some code that is using "Times-Roman" (also built in)
> to determine which string is longer... The strings are _actually_ placed in
> the document using "Times New Roman" (TTF)... but...
> 
> 1) pdfmetrics.stringWidth doesn't seem to work for TTF fonts.
> 2) I couldn't find an obvious way to obtain the information for TTF fonts.
> 3) If kerning gets implemented, the stringWidth should reflect that.
> 
> I vaguely recall implementing this "proxy for reality" late one night in a
> coding frenzy... is there an easy way to obtain stringWidth for a TTF font?

This works fine with all kinds of fonts:

    canvas.stringWidth(text, font_name, font_size)

Marius Gedminas
-- 
I've been in the sun for a week.  I took the bold step of leaving my
laptop at home.  I found only 4K messages pending when I returned.
        -- Keith Packard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 173 bytes
Desc: Digital signature
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20150622/5cd6bacc/attachment.pgp>


More information about the reportlab-users mailing list