By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,994 Members | 1,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,994 IT Pros & Developers. It's quick & easy.

Obtaining glyph width in Python

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Aloha,

Charlie wrote:
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
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.