@@ -91,10 +91,6 @@ def _nums_to_str(*args):
91
91
92
92
@_api .deprecated ("3.6" , alternative = "Vendor the code" )
93
93
def quote_ps_string (s ):
94
- return _quote_ps_string (s )
95
-
96
-
97
- def _quote_ps_string (s ):
98
94
"""
99
95
Quote dangerous characters of S for use in a PostScript string constant.
100
96
"""
@@ -447,17 +443,7 @@ def draw_image(self, gc, x, y, im, transform=None):
447
443
h , w = im .shape [:2 ]
448
444
imagecmd = "false 3 colorimage"
449
445
data = im [::- 1 , :, :3 ] # Vertically flipped rgb values.
450
- # data.tobytes().hex() has no spaces, so can be linewrapped by simply
451
- # splitting data every nchars. It's equivalent to textwrap.fill only
452
- # much faster.
453
- nchars = 128
454
- data = data .tobytes ().hex ()
455
- hexlines = "\n " .join (
456
- [
457
- data [n * nchars :(n + 1 ) * nchars ]
458
- for n in range (math .ceil (len (data ) / nchars ))
459
- ]
460
- )
446
+ hexdata = data .tobytes ().hex ("\n " , - 64 ) # Linewrap to 128 chars.
461
447
462
448
if transform is None :
463
449
matrix = "1 0 0 1 0 0"
@@ -479,7 +465,7 @@ def draw_image(self, gc, x, y, im, transform=None):
479
465
{{
480
466
currentfile DataString readhexstring pop
481
467
}} bind { imagecmd }
482
- { hexlines }
468
+ { hexdata }
483
469
grestore
484
470
""" )
485
471
@@ -737,13 +723,13 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
737
723
xmin , ymin = points_min
738
724
xmax , ymax = points_max
739
725
740
- streamarr = np .empty (
726
+ data = np .empty (
741
727
shape [0 ] * shape [1 ],
742
728
dtype = [('flags' , 'u1' ), ('points' , '2>u4' ), ('colors' , '3u1' )])
743
- streamarr ['flags' ] = 0
744
- streamarr ['points' ] = (flat_points - points_min ) * factor
745
- streamarr ['colors' ] = flat_colors [:, :3 ] * 255.0
746
- stream = _quote_ps_string ( streamarr .tobytes ())
729
+ data ['flags' ] = 0
730
+ data ['points' ] = (flat_points - points_min ) * factor
731
+ data ['colors' ] = flat_colors [:, :3 ] * 255.0
732
+ hexdata = data .tobytes (). hex ( " \n " , - 64 ) # Linewrap to 128 chars.
747
733
748
734
self ._pswriter .write (f"""\
749
735
gsave
@@ -754,7 +740,9 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
754
740
/BitsPerFlag 8
755
741
/AntiAlias true
756
742
/Decode [ { xmin :g} { xmax :g} { ymin :g} { ymax :g} 0 1 0 1 0 1 ]
757
- /DataSource ({ stream } )
743
+ /DataSource <
744
+ { hexdata }
745
+ >
758
746
>>
759
747
shfill
760
748
grestore
0 commit comments