473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
Mar 23 '06 #1
3 1680
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>

Mar 23 '06 #2
"Fredrik Lundh" <fr*****@pythonware.com> 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 <go***@ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
Mar 23 '06 #3
Jorge Godoy <go***@ieee.org> 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 <go***@ieee.org>

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: sparks | last post by:
As you might know that "java.lang" package are automatically imported by the java compiler so that one don't need to write the import statement of that package in the source code. Are there any...
13
by: gary | last post by:
Hi, We all know the below codes are dangerous: { int *p = new int; delete p; delete p; } And we also know the compilers do not delete p if p==NULL. So why compilers do not "p = NULL"...
1
by: Weixiao Fan | last post by:
as we know , FONT is not availble for XHTML standard . but VS.NET 2003 add it automatically. what can I do to make all the BODY , TD , FONT and so on to body ,td ? and don`t let it add <FONT>...
0
by: wurlds_wurst_coder | last post by:
A co-worker apparently checked the Show Disassembly Automatically checkbox at some point. This is really inconvenient to disassemble every dll we use everytime. How do I turn this option OFF??...
2
by: Ellis Yu | last post by:
Dear All I'm trying to create a control that inherits the combobox control. When I entered in the line "Inherits Combobox", the IDE automatically added the method Public Sub New(ByVal Container...
1
by: John Bailo | last post by:
using ( SqlCommand cmd = new SqlCommand("select * sample"), new SqlConnection( sqlDsn ) ) ) { SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable();...
2
by: NowItsWhatever | last post by:
In query DESIGN view, how do I automatically "fit" the columns in the table/field grid to the lengths of the table and field names (including any functions applied to the fields). I am not talking...
1
by: Jedufa | last post by:
following of thread: "Adding namespaces to code behind automatically" Hello, I had quite the same problem and got further in the right direction with your suggestions, thanks. Nevertheless, I...
2
by: Destiny111 | last post by:
Hi! I have a gps program which works only when the "manage gps automatically" function is checked in the PDA settings. I do not want to enable user to disable my gps coords logging by uncheck...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.