AW: [reportlab-users] UTF-8 and Bookmark
reportlab-users@reportlab.com
reportlab-users@reportlab.com
Tue, 22 Oct 2002 17:40:28 +0200
in other words
the revers of this nice function :-)
def utf8(code):
"Convert a given UCS character index into UTF-8"
if code < 0 or code > 0x7FFFFFFF:
raise ValueError, 'Invalid UCS character 0x%x' % code
elif code < 0x00000080:
return chr(code)
elif code < 0x00000800:
return '%c%c' % \
(0xC0 + (code >> 6),
0x80 + (code & 0x3F))
elif code < 0x00010000:
return '%c%c%c' % \
(0xE0 + (code >> 12),
0x80 + ((code >> 6) & 0x3F),
0x80 + (code & 0x3F))
elif code < 0x00200000:
return '%c%c%c%c' % \
(0xF0 + (code >> 18),
0x80 + ((code >> 12) & 0x3F),
0x80 + ((code >> 6) & 0x3F),
0x80 + (code & 0x3F))
elif code < 0x04000000:
return '%c%c%c%c%c' % \
(0xF8 + (code >> 24),
0x80 + ((code >> 18) & 0x3F),
0x80 + ((code >> 12) & 0x3F),
0x80 + ((code >> 6) & 0x3F),
0x80 + (code & 0x3F))
else:
return '%c%c%c%c%c%c' % \
(0xFC + (code >> 30),
0x80 + ((code >> 24) & 0x3F),
0x80 + ((code >> 18) & 0x3F),
0x80 + ((code >> 12) & 0x3F),
0x80 + ((code >> 6) & 0x3F),
0x80 + (code & 0x3F))
-----Ursprungliche Nachricht-----
Von: reportlab-users-admin@reportlab.com
[mailto:reportlab-users-admin@reportlab.com]Im Auftrag von
Jo-Bader@gmx.de
Gesendet: Dienstag, 22. Oktober 2002 14:50
An: reportlab-users@reportlab.com
Betreff: [reportlab-users] UTF-8 and Bookmark
when you dont live in a ascii-land you need UTF-8
strings on canvas.
But if you want to bookmark such an
entry you have do it with UCS strings.
canv.addOutlineEntry( UCS_Text, sKey, Level, closed=0)
canv.drawString( x,y, UTF8_Text )
does anybody have some code to convert UTF8 in UCS ?
regards
jo
_______________________________________________
reportlab-users mailing list
reportlab-users@reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users