Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c26a2a9

Browse files
committed
Bugfix for PDF writing under Python 2.5. (cp1252 now has a
decoding_table rather than a decoding_map) svn path=/trunk/matplotlib/; revision=3450
1 parent 5dd147e commit c26a2a9

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

lib/matplotlib/backends/backend_pdf.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,20 @@ def cvt(length, upe=font.units_per_EM, nearest=True):
500500
# composite font, based on multi-byte characters.
501501

502502
from encodings import cp1252
503-
firstchar, lastchar = 0, 255
503+
# The "decoding_map" was changed to a "decoding_table" as of Python 2.5.
504+
if hasattr(cp1252, 'decoding_map'):
505+
def decode_char(charcode):
506+
return cp1252.decoding_map[charcode] or 0
507+
else:
508+
def decode_char(charcode):
509+
return ord(cp1252.decoding_table[charcode])
510+
504511
def get_char_width(charcode):
505-
unicode = cp1252.decoding_map[charcode] or 0
512+
unicode = decode_char(charcode)
506513
width = font.load_char(unicode, flags=LOAD_NO_SCALE).horiAdvance
507514
return cvt(width)
515+
516+
firstchar, lastchar = 0, 255
508517
widths = [ get_char_width(charcode) for charcode in range(firstchar, lastchar+1) ]
509518

510519
widthsObject = self.reserveObject('font widths')

0 commit comments

Comments
 (0)