PIL: Breaking/Wrapping lines "automatically"

Discussion in 'Python' started by Jorge Godoy, Mar 23, 2006.

  1. Jorge Godoy

    Jorge Godoy Guest

    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 <>

    "Quidquid latine dictum sit, altum sonatur."
    - Qualquer coisa dita em latim soa profundo.
    - Anything said in Latin sounds smart.
     
    Jorge Godoy, Mar 23, 2006
    #1
    1. Advertising

  2. Re: Breaking/Wrapping lines "automatically"

    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/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>
     
    Fredrik Lundh, Mar 23, 2006
    #2
    1. Advertising

  3. Jorge Godoy

    Jorge Godoy Guest

    Re: Breaking/Wrapping lines "automatically"

    "Fredrik Lundh" <> 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/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 <>

    "Quidquid latine dictum sit, altum sonatur."
    - Qualquer coisa dita em latim soa profundo.
    - Anything said in Latin sounds smart.
     
    Jorge Godoy, Mar 23, 2006
    #3
  4. Jorge Godoy

    Jorge Godoy Guest

    Re: Breaking/Wrapping lines "automatically"

    Jorge Godoy <> 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 <>

    "Quidquid latine dictum sit, altum sonatur."
    - Qualquer coisa dita em latim soa profundo.
    - Anything said in Latin sounds smart.
     
    Jorge Godoy, Mar 23, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davor
    Replies:
    9
    Views:
    1,842
    Davor
    Jan 4, 2005
  2. Sam Quigley
    Replies:
    1
    Views:
    1,424
    Martin Honnen
    Jul 1, 2004
  3. Amy
    Replies:
    0
    Views:
    532
  4. fd
    Replies:
    2
    Views:
    1,238
    Mark Day
    Mar 5, 2004
  5. Sverre
    Replies:
    2
    Views:
    3,646
    Sverre
    Dec 17, 2009
Loading...

Share This Page