Obtaining glyph width in Python

C

Charlie

Hi, I'm looking for a way to obtain the width of a string, either in actual
inches/centimeters, or pixels will also work. Unfortunately this seems
difficult as I'd like to keep things as close to the stock Python install as
possible, and I'm not working with Graphics or X at all. Here are the options
I've found, and why they're less than optimal for my use:

PIL = Huge for only using one function. I'm not working with any graphics.
PyFT = Everyone uses FreeType2 now, and PyFT seems dead anyhow.
PyFT2 = Does not exist.
tkinter.text() = Works with X, creates windows no matter what you do.
t1lib = Separate package, no TTF support.
t1python = Same thing as t1lib?

Ultimately, I'm looking to take a stream of text, and break it up into lines
based on page width... and I need to know how wide (and ultimately how tall,
for page breaks) the individual glyphs are so I can break properly. If there's
an easier way to do this than calculating individual glyph width, I'm open to
that too.

I was really just looking to see if there was anything out there that wasn't
too large or too obscure/dated. Maybe there's something lower level that could
be done to achieve this? Is there metadata in the font that holds this
information that could be extracted?

Thanks in advance,
-Charlie
 
A

Andreas Lobinger

Aloha,
Hi, I'm looking for a way to obtain the width of a string, either in actual
inches/centimeters, or pixels will also work. Unfortunately this seems
difficult as I'd like to keep things as close to the stock Python install as
possible, and I'm not working with Graphics or X at all.

So you need both: metrics for single characters/glyphs and con-
catenated glyphs and words.
PIL = Huge for only using one function. I'm not working with any graphics.
PyFT = Everyone uses FreeType2 now, and PyFT seems dead anyhow.
PyFT2 = Does not exist.
tkinter.text() = Works with X, creates windows no matter what you do.
t1lib = Separate package, no TTF support.
t1python = Same thing as t1lib?

For the glyph metrics and informations there is the ttx/fonttools
project on sourceforge available. Afiar fonttools only need a
Numeric installation.
Ultimately, I'm looking to take a stream of text, and break it up into lines
based on page width... and I need to know how wide (and ultimately how tall,
for page breaks) the individual glyphs are so I can break properly. If there's
an easier way to do this than calculating individual glyph width, I'm open to
that too.

It looks like a little bit that you're redeveloping TeX (in python)...
I was really just looking to see if there was anything out there that wasn't
too large or too obscure/dated. Maybe there's something lower level that could
be done to achieve this? Is there metadata in the font that holds this
information that could be extracted?

Actually there is not only meta but real data included in the font,
speaking of Type1, TrueType and OpenType scalable outline fonts.

Wishing a happy day
LOBI
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top