473,881 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linguistically correct Python text rendering

I have a question about text rendering I'm hoping someone here can
answer. Is there a way of doing linguistically correct rendering of
Unicode strings in Python? In simple cases like Latin or Japanese I can
just print the string and see the correct results. However, I don't know
how to get Python to do the right thing for writing systems which
require contextual processing.

For example, let's say I create this Unicode string in Arabic:

string1 = u"\u0644\u062e\ u0645" # lam khah meem

If I print string1, I get just the characters I specified above, which
is not correct rendering behavior for Arabic. In the simple case, I
should get an output string where the order is reversed, and the codes
have been changed into their contextually correct forms: initial lam
(\ufedf), medial khah (\ufea8) and final meem (\ufee2). Optionally, I
could even ask for a single ligature combining all three of these;
Unicode even encodes this at \ufd85.

The situation is even more complicated for writing systems like
Devanagari (used in Hindi and Marathi). In this case there are rules for
ligatures (called "conjuncts" ) which are linguistically required, but
unencoded by Unicode. Technology was developed 15 years ago to deal with
this: fonts contain tables of extra information allowing access to the
correct conjunct glyphs at rendering time, even if they're unencoded.

Apple has software that deals with correctly rendering text in cases
like this (ATSUI); Microsoft does as well. IBM provides the ICU software
classes for this kind of rendering, and I believe FreeType has made a
start on dealing with AAT and OpenType fonts as well. So my question is
this: how do we get this functionality integrated into Python? I'd love
to be able to print any Unicode string and have it come out
linguistically correctly, even if I have to do a little extra formatting
(e.g. something like adding a new string-formatting conversion character
%t for typographically rich output).

Any ideas?

Dave Opstad
Jul 18 '05 #1
6 3035
> Any ideas?

Perhaps using a GUI call that hooks into Windows or MacOS would be
sufficient for you. I don't know if tkinter or wxPython can handle it,
but I would imagine that standard Windows gui calls wouldn't have a
problem. Check out the pythonwin GUI extensions:
http://www.python.org/windows/pythonwin/

- Josiah
Jul 18 '05 #2
David Opstad wrote:
my question is this: how do we get this functionality integrated into
Python? I'd love to be able to print any Unicode string and have it
come out linguistically correctly


Isn't this a function of whatever app you're running Python code inside (a
terminal or something)? E.g. could you take the output of your Python
program as a file and display it in Yudit or a Pango app?

Mike Maxwell


Jul 18 '05 #3
In article <ma************ *************** *********@pytho n.org>,
"Mike Maxwell" <ma*****@ldc.up enn.edu> wrote:
Isn't this a function of whatever app you're running Python code inside (a
terminal or something)? E.g. could you take the output of your Python
program as a file and display it in Yudit or a Pango app?


In an interactive Python session on the Mac, the terminal window can
display Asian or accented Latin with no problem, so that:
firstCJKChar = u"\u4e00"
print firstCJKChar.en code('utf-8')


gives the correct output, the Chinese character "yi". (The terminal's
defaults are for UTF-8 text display)

All I'm wondering is whether this odd asymmetry (between parts of
Unicode that display correctly with no further work and parts of Unicode
that need more active processing) is something that could be addressed
by adding more sophistication to Python's own output formatting. The
alternative is, as you suggest, to export Unicode text and open it with
another application, but I want Python to shine for all languages by
default!

Dave
Jul 18 '05 #4
David Opstad <op****@batnet. com> writes:
In article <ma************ *************** *********@pytho n.org>,
"Mike Maxwell" <ma*****@ldc.up enn.edu> wrote:
Isn't this a function of whatever app you're running Python code inside (a
terminal or something)? E.g. could you take the output of your Python
program as a file and display it in Yudit or a Pango app?
In an interactive Python session on the Mac, the terminal window can
display Asian or accented Latin with no problem, so that:
firstCJKChar = u"\u4e00"
print firstCJKChar.en code('utf-8')


gives the correct output, the Chinese character "yi". (The terminal's
defaults are for UTF-8 text display)


But it seems to be impossible to programmaticall y determine which
encoding the terminal being printed to at a given moment is using (and
the user can fiddle this at run time). If I'm wrong about this, I'd
like to know.
All I'm wondering is whether this odd asymmetry (between parts of
Unicode that display correctly with no further work and parts of Unicode
that need more active processing) is something that could be addressed
by adding more sophistication to Python's own output formatting.


I don't think so. Depends a bit what you mean by "Python's own output
formatting". Since, 2.3 Python if sys.stdout is a terminal it
attempts to determine the encoding in use via the
"locale.nl_lang info(locale.COD ESET)" approach, but whether this
actually works seems to be a bit random. It certainly isn't going to
work on Mac OS X, which AFAICT ignores locales as much as the ISO C
standard lets it get away with.

What more would you have us do?

If you're using some other means to display Unicode text, it's up to
that means to ensure it gets displayed correctly. For PyObjC, It Just
Works, I think.

Cheers,
mwh

--
Academic politics is the most vicious and bitter form of politics,
because the stakes are so low. -- Wallace Sayre
Jul 18 '05 #5
In article <m3************ @pc150.maths.br is.ac.uk>,
Michael Hudson <mw*@python.net > wrote:
But it seems to be impossible to programmaticall y determine which
encoding the terminal being printed to at a given moment is using (and
the user can fiddle this at run time). If I'm wrong about this, I'd
like to know.
The encoding issue is peripheral to my point; sorry if I wasn't clearer
in my original message. It doesn't matter what the encoding is. The main
issue is that for some writing systems (e.g. Arabic) simply outputting
the characters in a Unicode string, irrespective of encoding, will
produce garbled results.
What more would you have us do?


Well, for those writing systems whose presentation forms are included in
Unicode, how about a further processing step? So that at a minimum, if I
start with an Arabic string like "abc" I can get out an Arabic string
like "CBA" where bidi reordering has happened, and contextual
substitution has been done. Then, outputting the processed Unicode
string using stdout will work without further intervention (assuming a
font for the writing system is present, of course).

It's probably irrational of me, I admit, but I'd love to see Python
correctly render *any* Unicode string, not just the subsets requiring no
reordering or contextual processing.

Dave
Jul 18 '05 #6
David Opstad <op****@batnet. com> writes:
In article <m3************ @pc150.maths.br is.ac.uk>,
Michael Hudson <mw*@python.net > wrote:
But it seems to be impossible to programmaticall y determine which
encoding the terminal being printed to at a given moment is using (and
the user can fiddle this at run time). If I'm wrong about this, I'd
like to know.
The encoding issue is peripheral to my point; sorry if I wasn't clearer
in my original message. It doesn't matter what the encoding is. The main
issue is that for some writing systems (e.g. Arabic) simply outputting
the characters in a Unicode string, irrespective of encoding, will
produce garbled results.
What more would you have us do?


Well, for those writing systems whose presentation forms are included in
Unicode, how about a further processing step? So that at a minimum, if I
start with an Arabic string like "abc" I can get out an Arabic string
like "CBA" where bidi reordering has happened, and contextual
substitution has been done. Then, outputting the processed Unicode
string using stdout will work without further intervention (assuming a
font for the writing system is present, of course).


Ah, OK. You are now officially beyond my level of expertise :-) You
might want to talk to the i18n-sig.

This sounds very much like the sort of thing that could/should be
developed externally to Python and then perhaps folded in later, a la
CJKCodecs.
It's probably irrational of me, I admit, but I'd love to see Python
correctly render *any* Unicode string, not just the subsets requiring no
reordering or contextual processing.


I still think "render" is probably the wrong word to use here, though.

Cheers,
mwh

--
In short, just business as usual in the wacky world of floating
point <wink>. -- Tim Peters, comp.lang.pytho n
Jul 18 '05 #7

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

Similar topics

3
2636
by: John Hunter | last post by:
matplotlib is a 2D plotting library for python. You can use matplotlib interactively from a python shell or IDE, or embed it in GUI applications (WX, GTK, and Tkinter). matplotlib supports many plot types: line plots, bar charts, log plots, images, pseudocolor plots, legends, date plots, finance charts and more. What's new since matplotlib 0.50 This is the first wide release in 5 months and there has been a tremendous amount of...
40
1296
by: Shufen | last post by:
Hi all, Can someone who has use PHP before and know quite well about the language, tell me what are the stuffs that Python offers and PHP doesn't. A few examples will be nice. I know about the date format problem which PHP is having but I need more examples. Thank you for any help. Shufen
10
3705
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. Andrew dalke@dalkescientific.com
19
3228
by: dcrespo | last post by:
Hi all... Is there a way to print a PDF file directly from Python without having Acrobat installed? I know about ReportLab. It's a python module that lets you create almost any PDF document, but I still don't know if it supports printing, so I'm looking for a Python module that could do it. I want to print a PDF file just like if I were doing it from Acrobat. Daniel.
2
2921
by: david | last post by:
hi: The file can be PDF or Word format. Any help? thx
7
5189
by: Dennis Benzinger | last post by:
Hi! Does anybody know of a SVG rendering library for Python? Bye, Dennis
50
6105
by: Shadow Lynx | last post by:
Consider this simple HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Strict kills my widths!</title> </head> <body> <table style="width:400px; table-layout:fixed;">
29
16626
by: 63q2o4i02 | last post by:
Hi, I'm interested in using python to start writing a CAD program for electrical design. I just got done reading Steven Rubin's book, I've used "real" EDA tools, and I have an MSEE, so I know what I *want* at the end of this; I just have never taken on a programming task of this magnitude. I've seen that some are using python as a utility language for existing CAD environments, and I've also found some guy who's writing a 2d drafting...
29
5168
by: Michael Bulatovich | last post by:
Is there a way to use CSS to format "plain" text in an html document. By plain I mean text which is not contained by <por <h#tags. Is there no way to control how this stuff is rendered? tia
0
9776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10724
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10827
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10403
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7954
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7113
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5781
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.