Re: Built-in versus embedded fonts

Marius Gedminas <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Message-ID <20150622081622.GD6906@platonas>
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
signature.asc (application/pgp-signature, 173 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iD8DBQFVh8RWkVdEXeem148RAttEAJ0QFjd+2zDNtQur7UG/9rP3qVRTTQCfa/j9
aaqUEOD4zXy/afTeYDIxMnA=
=SDyB
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.