PIL: Breaking/Wrapping lines "automatically"

J

Jorge Godoy

Hi!


Is there something I can do in PIL to restrict a line to a certain size and
have it to break/wrap into a newline automatically? (Or by using some code, of
course...)

I'm trying to add information to barcodes and since the label space is fixed
I'd like to use all the horizontal space I can and since I'm with two or three
lines of free space I'd like to use them as well.


TIA,
--
Jorge Godoy <[email protected]>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
 
F

Fredrik Lundh

Jorge said:
Is there something I can do in PIL to restrict a line to a certain size and
have it to break/wrap into a newline automatically? (Or by using some
code, of course...)

there's no standard function for this purpose, no.

here's a somewhat rough implementation, based on a WCK demo:

http://effbot.python-hosting.com/file/stuff/sandbox/pil/textwrap.py

a somewhat better approach would be to use collect words as long as
they fit, and write each line as a single string.

</F>
 
J

Jorge Godoy

Fredrik Lundh said:
there's no standard function for this purpose, no.

here's a somewhat rough implementation, based on a WCK demo:

http://effbot.python-hosting.com/file/stuff/sandbox/pil/textwrap.py

a somewhat better approach would be to use collect words as long as
they fit, and write each line as a single string.

Then I'd have to have some means to determine the width of the char (I'm using
a TrueType font due to my need of using Unicode text) to calculate how many
words I can put on a single line...

I'll take a look at the page above.


Thanks!

--
Jorge Godoy <[email protected]>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
 
J

Jorge Godoy

Jorge Godoy said:
Then I'd have to have some means to determine the width of the char (I'm using
a TrueType font due to my need of using Unicode text) to calculate how many
words I can put on a single line...

Hmmm... It looks like your code does that! Thanks! I'll give it a try
here.

--
Jorge Godoy <[email protected]>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top