Lino Website

Problem reports

Test 77 failed

Tuesday, 19. September 2006 21:48.

I noticed that test 77 fails.

Traceback (most recent call last):
  File "...\tests\77.py", line 62, in test01
    self.doit(d)
  File "...\tests\77.py", line 36, in doit
    d.readfile(opj(dataPath,"5.prn"),encoding="cp850")
  File "...\src\lino\textprinter\textprinter.py", line 195, in readfile
    self.writeln(line)
  File "...\src\lino\textprinter\textprinter.py", line 253, in writeln
    self.writechars(line)
  File "...\src\lino\textprinter\textprinter.py", line 271, in writechars
    self.write(text)
  File "...\src\lino\textprinter\winprn.py", line 536, in write
    self.dc.TextOut(int(self.x),-int(self.y),self.line)
  File "c:\Python23\lib\encodings\cp1252.py", line 18, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-69: character maps to <undefined>

This indicates imho that TextOut() does not always choose the right encoding when it gets a Unicode string. Here it obviously uses sys.getdefaultencoding(), which is cp1252 on my machine. It is normal that cp1252 cannot encode box characters. But I didn't ask for cp1252. The font returned when asking for win32con.OEM_CHARSET uses the default console codepage, which is cp850 on my machine.

How can I find out the default console codepage of a Windwos machine? How can I find out the encoding of a font?

I fixed it for now by encoding Unicode strings using sys.stdout.encoding in Win32Printer.write(), but I'm not sure this works in every case.

Copyright 2001-2007 Luc Saffre.
http://lino.saffre-rumma.ee
Generated 2007-06-07 16:22:50