472,983 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

String formatting for complex writing systems

Hi guys,

I'm writing a piece of software for some Thai friend. At the end it
is supposed to print on paper some report with tables of text and
numbers. When I test it in English, the columns are aligned nicely,
but when he tests it with Thai data, the columns are all crooked.

The problem here is that in the Thai writing system some times two or
more characters together might take one single space, for example งิ
(u"\u0E07\u0E34"). This is why when I use something like u"%10s"
% ..., it just doesn't work as expected.

Is anybody aware of an alternative string format function that can
deal with this kind of writing properly?

Any suggestion is highly appreciated. Thanks!
Andy

Jun 27 '07 #1
4 1020
En Wed, 27 Jun 2007 04:20:52 -0300, Andy <fu******@gmail.comescribió:
I'm writing a piece of software for some Thai friend. At the end it
is supposed to print on paper some report with tables of text and
numbers. When I test it in English, the columns are aligned nicely,
but when he tests it with Thai data, the columns are all crooked.

The problem here is that in the Thai writing system some times two or
more characters together might take one single space, for example งิ
(u"\u0E07\u0E34"). This is why when I use something like u"%10s"
% ..., it just doesn't work as expected.

Is anybody aware of an alternative string format function that can
deal with this kind of writing properly?
The same thing happens even in English if you print using a proportional
width font, a "W" is usually wider than an "i" or "l" letter.
You could use a reporting library or program (like ReportLab, generating
PDF files), but perhaps the simplest approach is to generate an HTML page
containing a table, and display and print it using your favorite browser.

--
Gabriel Genellina
Jun 27 '07 #2
On Jun 27, 12:20*am, Andy <fukaz...@gmail.comwrote:
Hi guys,

I'm writing a piece of software for some Thai friend. *At the end it
is supposed to print on paper some report with tables of text and
numbers. *When I test it in English, the columns are aligned nicely,
but when he tests it with Thai data, the columns are all crooked.

The problem here is that in the Thai writing system some times two or
more characters together might take one single space, for example งิ
(u"\u0E07\u0E34"). *This is why when I use something like u"%10s"
% ..., it just doesn't work as expected.

Is anybody aware of an alternative string format function that can
deal with this kind of writing properly?
In general case it's impossible to write such a function for many
unicode characters without feedback from rendering library.
Assuming you use *fixed* font for English and Thai the following
function will return how many columns your text will use:

from unicodedata import category
def columns(self, s):
return sum(1 for c in s if category(c) != 'Mn')

-- Leo

Jun 27 '07 #3
On Jun 27, 3:10*am, Leo Kislov <Leo.Kis...@gmail.comwrote:
On Jun 27, 12:20*am, Andy <fukaz...@gmail.comwrote:
Hi guys,
I'm writing a piece of software for some Thai friend. *At the end it
is supposed to print on paper some report with tables of text and
numbers. *When I test it in English, the columns are aligned nicely,
but when he tests it with Thai data, the columns are all crooked.
The problem here is that in the Thai writing system some times two or
more characters together might take one single space, for example งิ
(u"\u0E07\u0E34"). *This is why when I use something like u"%10s"
% ..., it just doesn't work as expected.
Is anybody aware of an alternative string format function that can
deal with this kind of writing properly?

In general case it's impossible to write such a function for many
unicode characters without feedback from rendering library.
Assuming you use *fixed* font for English and Thai the following
function will return how many columns your text will use:

from unicodedata import category
def columns(self, s):
* * return sum(1 for c in s if category(c) != 'Mn')
That should of course be written as def columns(s). Need to learn to
proofread before posting :)

-- Leo

Jun 27 '07 #4
Thanks guys!

I've used the HTML and the unicodedata suggestions, each on a
different report. These worked nicely!

Andy

Jul 2 '07 #5

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

Similar topics

1
by: Matt Garman | last post by:
I've got some code that generates a report for the user. The report is shown with explanatory verbage. The text is relatively long, and also has some simple formatting (paragraphs, bulleted...
4
by: Dennis Myrn | last post by:
Hi. Is there a way to utilize the great primitive data type formatting routines available in .NET without working with strings? I want a byte directly rather than a string. I think it is...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
8
by: Oenone | last post by:
Is it possible to create an object which can have methods and properties, but which can also be treated as a string? I'm trying to create a wrapper around the IIS Request.Form object which...
17
by: Modica82 | last post by:
Hi All, I am very new to web services, so am struggling to understand exactly what I am doing with regards to its returns etc. I have been given the task of designing and developing a web...
7
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
13
by: Jiho Han | last post by:
Here's the issue. You have a class, Class Person { public int id; public string firstname; public string lastname; }
1
by: schoedl | last post by:
Hello, we often compose strings via a ostringstream and then create a string from it. What is the rationale of not being able to use string in place of a ostringstream, so I could write ...
11
by: coomberjones | last post by:
I have a few std::strings that I am using to store raw binary data, each of which may very well include null bytes at any point or points. I want to slap them together into a single string, so I...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

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.