44A PDF matplotlib backend
55Author: Jouni K Seppänen <[email protected] > 66"""
7- from __future__ import (absolute_import , division , print_function ,
8- unicode_literals )
9-
10- import six
11- from six import unichr
127
138import codecs
149import collections
@@ -160,11 +155,11 @@ def pdfRepr(obj):
160155 return [b'false' , b'true' ][obj ]
161156
162157 # Integers are written as such.
163- elif isinstance (obj , (six . integer_types , np .integer )):
158+ elif isinstance (obj , (int , np .integer )):
164159 return ("%d" % obj ).encode ('ascii' )
165160
166161 # Unicode strings are encoded in UTF-16BE with byte-order mark.
167- elif isinstance (obj , six . text_type ):
162+ elif isinstance (obj , str ):
168163 try :
169164 # But maybe it's really ASCII?
170165 s = obj .encode ('ASCII' )
@@ -269,7 +264,7 @@ def __repr__(self):
269264 return "<Name %s>" % self .name
270265
271266 def __str__ (self ):
272- return '/' + six . text_type (self .name )
267+ return '/' + str (self .name )
273268
274269 def __eq__ (self , other ):
275270 return isinstance (other , Name ) and self .name == other .name
@@ -325,7 +320,7 @@ def pdfRepr(self):
325320 grestore = b'Q' , textpos = b'Td' , selectfont = b'Tf' , textmatrix = b'Tm' ,
326321 show = b'Tj' , showkern = b'TJ' , setlinewidth = b'w' , clip = b'W' , shading = b'sh' )
327322
328- Op = Bunch (** {name : Operator (value ) for name , value in six . iteritems ( _pdfops )})
323+ Op = Bunch (** {name : Operator (value ) for name , value in _pdfops . items ( )})
329324
330325
331326def _paint_path (fill , stroke ):
@@ -576,14 +571,14 @@ def finalize(self):
576571 self .writeFonts ()
577572 self .writeObject (
578573 self .alphaStateObject ,
579- {val [0 ]: val [1 ] for val in six . itervalues ( self .alphaStates )})
574+ {val [0 ]: val [1 ] for val in self .alphaStates . values ( )})
580575 self .writeHatches ()
581576 self .writeGouraudTriangles ()
582577 xobjects = {
583- name : ob for image , name , ob in six . itervalues ( self ._images )}
584- for tup in six . itervalues ( self .markers ):
578+ name : ob for image , name , ob in self ._images . values ( )}
579+ for tup in self .markers . values ( ):
585580 xobjects [tup [0 ]] = tup [1 ]
586- for name , value in six . iteritems ( self .multi_byte_charprocs ):
581+ for name , value in self .multi_byte_charprocs . items ( ):
587582 xobjects [name ] = value
588583 for name , path , trans , ob , join , cap , padding , filled , stroked \
589584 in self .paths :
@@ -639,7 +634,7 @@ def fontName(self, fontprop):
639634 as the filename of the font.
640635 """
641636
642- if isinstance (fontprop , six . string_types ):
637+ if isinstance (fontprop , str ):
643638 filename = fontprop
644639 elif rcParams ['pdf.use14corefonts' ]:
645640 filename = findfont (
@@ -1078,7 +1073,7 @@ def embedTTFType42(font, characters, descriptor):
10781073 flags = LOAD_NO_SCALE | LOAD_NO_HINTING )
10791074 widths .append ((ccode , cvt (glyph .horiAdvance )))
10801075 if ccode < 65536 :
1081- cid_to_gid_map [ccode ] = unichr (gind )
1076+ cid_to_gid_map [ccode ] = chr (gind )
10821077 max_ccode = max (ccode , max_ccode )
10831078 widths .sort ()
10841079 cid_to_gid_map = cid_to_gid_map [:max_ccode + 1 ]
@@ -1232,7 +1227,7 @@ def hatchPattern(self, hatch_style):
12321227 def writeHatches (self ):
12331228 hatchDict = dict ()
12341229 sidelen = 72.0
1235- for hatch_style , name in six . iteritems ( self .hatchPatterns ):
1230+ for hatch_style , name in self .hatchPatterns . items ( ):
12361231 ob = self .reserveObject ('hatch pattern' )
12371232 hatchDict [name ] = ob
12381233 res = {'Procsets' :
@@ -1410,7 +1405,7 @@ def _writeImg(self, data, height, width, grayscale, id, smask=None):
14101405 self .endStream ()
14111406
14121407 def writeImages (self ):
1413- for img , name , ob in six . itervalues ( self ._images ):
1408+ for img , name , ob in self ._images . values ( ):
14141409 height , width , data , adata = self ._unpack (img )
14151410 if adata is not None :
14161411 smaskObject = self .reserveObject ("smask" )
@@ -1451,7 +1446,7 @@ def markerObject(self, path, trans, fill, stroke, lw, joinstyle,
14511446
14521447 def writeMarkers (self ):
14531448 for ((pathops , fill , stroke , joinstyle , capstyle ),
1454- (name , ob , bbox , lw )) in six . iteritems ( self .markers ):
1449+ (name , ob , bbox , lw )) in self .markers . items ( ):
14551450 bbox = bbox .padded (lw * 0.5 )
14561451 self .beginStream (
14571452 ob .id , None ,
@@ -1557,7 +1552,7 @@ def writeInfoDict(self):
15571552 """Write out the info dictionary, checking it for good form"""
15581553
15591554 def is_string_like (x ):
1560- return isinstance (x , six . string_types )
1555+ return isinstance (x , str )
15611556
15621557 def is_date (x ):
15631558 return isinstance (x , datetime )
@@ -1643,7 +1638,7 @@ def check_gc(self, gc, fillcolor=None):
16431638 def track_characters (self , font , s ):
16441639 """Keeps track of which characters are required from
16451640 each font."""
1646- if isinstance (font , six . string_types ):
1641+ if isinstance (font , str ):
16471642 fname = font
16481643 else :
16491644 fname = font .fname
@@ -1653,7 +1648,7 @@ def track_characters(self, font, s):
16531648 used_characters [1 ].update ([ord (x ) for x in s ])
16541649
16551650 def merge_used_characters (self , other ):
1656- for stat_key , (realpath , charset ) in six . iteritems ( other ):
1651+ for stat_key , (realpath , charset ) in other . items ( ):
16571652 used_characters = self .file .used_characters .setdefault (
16581653 stat_key , (realpath , set ()))
16591654 used_characters [1 ].update (charset )
@@ -1881,7 +1876,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
18811876 self .file .output (self .file .fontName (fontname ), fontsize ,
18821877 Op .selectfont )
18831878 prev_font = fontname , fontsize
1884- self .file .output (self .encode_string (unichr (num ), fonttype ),
1879+ self .file .output (self .encode_string (chr (num ), fonttype ),
18851880 Op .show )
18861881 self .file .output (Op .end_text )
18871882
@@ -1935,10 +1930,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
19351930 pdfname = self .file .dviFontName (dvifont )
19361931 seq += [['font' , pdfname , dvifont .size ]]
19371932 oldfont = dvifont
1938- # We need to convert the glyph numbers to bytes, and the easiest
1939- # way to do this on both Python 2 and 3 is .encode('latin-1')
1940- seq += [['text' , x1 , y1 ,
1941- [six .unichr (glyph ).encode ('latin-1' )], x1 + width ]]
1933+ seq += [['text' , x1 , y1 , [bytes ([glyph ])], x1 + width ]]
19421934
19431935 # Find consecutive text strings with constant y coordinate and
19441936 # combine into a sequence of strings and kerns, or just one
@@ -2046,7 +2038,7 @@ def check_simple_method(s):
20462038 if fonttype == 3 and not isinstance (s , bytes ) and len (s ) != 0 :
20472039 # Break the string into chunks where each chunk is either
20482040 # a string of chars <= 255, or a single character > 255.
2049- s = six . text_type (s )
2041+ s = str (s )
20502042 for c in s :
20512043 if ord (c ) <= 255 :
20522044 char_type = 1
0 commit comments