PIL: Breaking/Wrapping lines "automatically"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jorge Godoy

    #1

    PIL: Breaking/Wrapping lines "automatically"


    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 <godoy@ieee.org >

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

    #2
    Re: Breaking/Wrapping lines &quot;automatic ally&quot;

    Jorge Godoy wrote:[color=blue]
    > 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...)[/color]

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

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

    Find information, resources and relevant links for python-hosting.com. This domain may be for sale.


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

    </F>



    Comment

    • Jorge Godoy

      #3
      Re: Breaking/Wrapping lines &quot;automatic ally&quot;

      "Fredrik Lundh" <fredrik@python ware.com> writes:
      [color=blue]
      > Jorge Godoy wrote:[color=green]
      >> 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...)[/color]
      >
      > 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.[/color]

      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 <godoy@ieee.org >

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

      Comment

      • Jorge Godoy

        #4
        Re: Breaking/Wrapping lines &quot;automatic ally&quot;

        Jorge Godoy <godoy@ieee.org > writes:
        [color=blue]
        > 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...[/color]

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

        --
        Jorge Godoy <godoy@ieee.org >

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

        Comment

        Working...