Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > PIL: Breaking/Wrapping lines "automatically"

Reply
Thread Tools

PIL: Breaking/Wrapping lines "automatically"

 
 
Jorge Godoy
Guest
Posts: n/a
 
      03-23-2006

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 <(E-Mail Removed)>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      03-23-2006
Jorge Godoy wrote:
> 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/fil...il/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>



 
Reply With Quote
 
 
 
 
Jorge Godoy
Guest
Posts: n/a
 
      03-23-2006
"Fredrik Lundh" <(E-Mail Removed)> writes:

> Jorge Godoy wrote:
>> 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/fil...il/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 <(E-Mail Removed)>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
 
Reply With Quote
 
Jorge Godoy
Guest
Posts: n/a
 
      03-23-2006
Jorge Godoy <(E-Mail Removed)> writes:

> 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 <(E-Mail Removed)>

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to know two lines are a pare parallel lines lovecreatesbeauty C Programming 11 04-28-2006 03:32 AM
How to display a string in many lines, each lines have a specified length thuyptt@dsp.com.vn C++ 1 12-06-2005 07:26 AM
Asp.Net Calender, how to display 5 lines if there are only 5 lines in one month? Jack ASP .Net 9 10-12-2005 03:44 AM
Modems, Analog Lines and ... Electrical Lines? Sens Fan Happy In Ohio Computer Support 5 09-02-2004 04:15 AM
Re: how to read 10 lines from a 200 lines file and write to a new file?? Joe Wright C Programming 0 07-27-2003 08:50 PM



Advertisments