www.emsdn.com
Class Profile: Home »» Python [Python] under "Python" »»» hbb"Visually similar" Unicode to Windows-1252 conversion

hbb"Visually similar" Unicode to Windows-1252 conversion


Hi,
I'm using htmldoc (http://www.easysw.com/htmldoc/) to convert HTML files
to PDF. Unfortunately, this software does not support Unicode, so I have
to encode my strings as Windows-1252. To avoid errors, I've using the
"replace" mode s.encode('cp1252', 'replace'). This does a "strict"
conversion in that say U+2013 (En Dash) is replaced by a question mark.
What I'd really like is a "visual approximation" conversion, so U+2013
would be replaced by an ASCII minus sign.
Now, I know Windows can do this. Using the ANSI version of wxPython, if
you enter unicode characters into a text box, this conversion is done
before the non-unicode string is returned. So, how can I access that
same conversion from Python?
Any help would be much appreciated. Also, if anyone knows another forum
I could try asking in, that'd help too.
Paul
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org


No. 1# | By Developer Tags User at [2008-5-5] | size: 1010 bytes

Paul Johnston wrote:
Hi,

I'm using htmldoc (http://www.easysw.com/htmldoc/) to convert HTML files
to PDF. Unfortunately, this software does not support Unicode,

What about UTF-8?

so I have
to encode my strings as Windows-1252. To avoid errors, I've using the
"replace" mode s.encode('cp1252', 'replace'). This does a "strict"
conversion in that say U+2013 (En Dash) is replaced by a question mark.
What I'd really like is a "visual approximation" conversion, so U+2013
would be replaced by an ASCII minus sign.

Now, I know Windows can do this. Using the ANSI version of wxPython, if
you enter unicode characters into a text box, this conversion is done
before the non-unicode string is returned. So, how can I access that
same conversion from Python?

It may be being done in the control itself. wxPython just does the
equivalent to the s.encode() using the encoding returned by
wx.GetDefaultPyEncoding().



Python Hot!

Python New!


Copyright © 2008 www.emsdn.com • All rights reserved • CMS Theme by www.emsdn.com - 0.172