4
4
A PDF matplotlib backend
5
5
Author: Jouni K Seppänen <[email protected] >
6
6
"""
7
- from __future__ import (absolute_import , division , print_function ,
8
- unicode_literals )
9
-
10
- import six
11
- from six import unichr
12
7
13
8
import codecs
14
9
import collections
@@ -160,11 +155,11 @@ def pdfRepr(obj):
160
155
return [b'false' , b'true' ][obj ]
161
156
162
157
# Integers are written as such.
163
- elif isinstance (obj , (six . integer_types , np .integer )):
158
+ elif isinstance (obj , (int , np .integer )):
164
159
return ("%d" % obj ).encode ('ascii' )
165
160
166
161
# Unicode strings are encoded in UTF-16BE with byte-order mark.
167
- elif isinstance (obj , six . text_type ):
162
+ elif isinstance (obj , str ):
168
163
try :
169
164
# But maybe it's really ASCII?
170
165
s = obj .encode ('ASCII' )
@@ -269,7 +264,7 @@ def __repr__(self):
269
264
return "<Name %s>" % self .name
270
265
271
266
def __str__ (self ):
272
- return '/' + six . text_type (self .name )
267
+ return '/' + str (self .name )
273
268
274
269
def __eq__ (self , other ):
275
270
return isinstance (other , Name ) and self .name == other .name
@@ -325,7 +320,7 @@ def pdfRepr(self):
325
320
grestore = b'Q' , textpos = b'Td' , selectfont = b'Tf' , textmatrix = b'Tm' ,
326
321
show = b'Tj' , showkern = b'TJ' , setlinewidth = b'w' , clip = b'W' , shading = b'sh' )
327
322
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 ( )})
329
324
330
325
331
326
def _paint_path (fill , stroke ):
@@ -576,14 +571,14 @@ def finalize(self):
576
571
self .writeFonts ()
577
572
self .writeObject (
578
573
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 ( )})
580
575
self .writeHatches ()
581
576
self .writeGouraudTriangles ()
582
577
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 ( ):
585
580
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 ( ):
587
582
xobjects [name ] = value
588
583
for name , path , trans , ob , join , cap , padding , filled , stroked \
589
584
in self .paths :
@@ -639,7 +634,7 @@ def fontName(self, fontprop):
639
634
as the filename of the font.
640
635
"""
641
636
642
- if isinstance (fontprop , six . string_types ):
637
+ if isinstance (fontprop , str ):
643
638
filename = fontprop
644
639
elif rcParams ['pdf.use14corefonts' ]:
645
640
filename = findfont (
@@ -1078,7 +1073,7 @@ def embedTTFType42(font, characters, descriptor):
1078
1073
flags = LOAD_NO_SCALE | LOAD_NO_HINTING )
1079
1074
widths .append ((ccode , cvt (glyph .horiAdvance )))
1080
1075
if ccode < 65536 :
1081
- cid_to_gid_map [ccode ] = unichr (gind )
1076
+ cid_to_gid_map [ccode ] = chr (gind )
1082
1077
max_ccode = max (ccode , max_ccode )
1083
1078
widths .sort ()
1084
1079
cid_to_gid_map = cid_to_gid_map [:max_ccode + 1 ]
@@ -1232,7 +1227,7 @@ def hatchPattern(self, hatch_style):
1232
1227
def writeHatches (self ):
1233
1228
hatchDict = dict ()
1234
1229
sidelen = 72.0
1235
- for hatch_style , name in six . iteritems ( self .hatchPatterns ):
1230
+ for hatch_style , name in self .hatchPatterns . items ( ):
1236
1231
ob = self .reserveObject ('hatch pattern' )
1237
1232
hatchDict [name ] = ob
1238
1233
res = {'Procsets' :
@@ -1410,7 +1405,7 @@ def _writeImg(self, data, height, width, grayscale, id, smask=None):
1410
1405
self .endStream ()
1411
1406
1412
1407
def writeImages (self ):
1413
- for img , name , ob in six . itervalues ( self ._images ):
1408
+ for img , name , ob in self ._images . values ( ):
1414
1409
height , width , data , adata = self ._unpack (img )
1415
1410
if adata is not None :
1416
1411
smaskObject = self .reserveObject ("smask" )
@@ -1451,7 +1446,7 @@ def markerObject(self, path, trans, fill, stroke, lw, joinstyle,
1451
1446
1452
1447
def writeMarkers (self ):
1453
1448
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 ( ):
1455
1450
bbox = bbox .padded (lw * 0.5 )
1456
1451
self .beginStream (
1457
1452
ob .id , None ,
@@ -1557,7 +1552,7 @@ def writeInfoDict(self):
1557
1552
"""Write out the info dictionary, checking it for good form"""
1558
1553
1559
1554
def is_string_like (x ):
1560
- return isinstance (x , six . string_types )
1555
+ return isinstance (x , str )
1561
1556
1562
1557
def is_date (x ):
1563
1558
return isinstance (x , datetime )
@@ -1643,7 +1638,7 @@ def check_gc(self, gc, fillcolor=None):
1643
1638
def track_characters (self , font , s ):
1644
1639
"""Keeps track of which characters are required from
1645
1640
each font."""
1646
- if isinstance (font , six . string_types ):
1641
+ if isinstance (font , str ):
1647
1642
fname = font
1648
1643
else :
1649
1644
fname = font .fname
@@ -1653,7 +1648,7 @@ def track_characters(self, font, s):
1653
1648
used_characters [1 ].update ([ord (x ) for x in s ])
1654
1649
1655
1650
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 ( ):
1657
1652
used_characters = self .file .used_characters .setdefault (
1658
1653
stat_key , (realpath , set ()))
1659
1654
used_characters [1 ].update (charset )
@@ -1881,7 +1876,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
1881
1876
self .file .output (self .file .fontName (fontname ), fontsize ,
1882
1877
Op .selectfont )
1883
1878
prev_font = fontname , fontsize
1884
- self .file .output (self .encode_string (unichr (num ), fonttype ),
1879
+ self .file .output (self .encode_string (chr (num ), fonttype ),
1885
1880
Op .show )
1886
1881
self .file .output (Op .end_text )
1887
1882
@@ -1935,10 +1930,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
1935
1930
pdfname = self .file .dviFontName (dvifont )
1936
1931
seq += [['font' , pdfname , dvifont .size ]]
1937
1932
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 ]]
1942
1934
1943
1935
# Find consecutive text strings with constant y coordinate and
1944
1936
# combine into a sequence of strings and kerns, or just one
@@ -2046,7 +2038,7 @@ def check_simple_method(s):
2046
2038
if fonttype == 3 and not isinstance (s , bytes ) and len (s ) != 0 :
2047
2039
# Break the string into chunks where each chunk is either
2048
2040
# a string of chars <= 255, or a single character > 255.
2049
- s = six . text_type (s )
2041
+ s = str (s )
2050
2042
for c in s :
2051
2043
if ord (c ) <= 255 :
2052
2044
char_type = 1
0 commit comments