@@ -91,10 +91,6 @@ def _nums_to_str(*args):
9191
9292@_api .deprecated ("3.6" , alternative = "Vendor the code" )
9393def quote_ps_string (s ):
94- return _quote_ps_string (s )
95-
96-
97- def _quote_ps_string (s ):
9894 """
9995 Quote dangerous characters of S for use in a PostScript string constant.
10096 """
@@ -447,17 +443,7 @@ def draw_image(self, gc, x, y, im, transform=None):
447443 h , w = im .shape [:2 ]
448444 imagecmd = "false 3 colorimage"
449445 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.
461447
462448 if transform is None :
463449 matrix = "1 0 0 1 0 0"
@@ -479,7 +465,7 @@ def draw_image(self, gc, x, y, im, transform=None):
479465{{
480466currentfile DataString readhexstring pop
481467}} bind { imagecmd }
482- { hexlines }
468+ { hexdata }
483469grestore
484470""" )
485471
@@ -737,13 +723,13 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
737723 xmin , ymin = points_min
738724 xmax , ymax = points_max
739725
740- streamarr = np .empty (
726+ data = np .empty (
741727 shape [0 ] * shape [1 ],
742728 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.
747733
748734 self ._pswriter .write (f"""\
749735 gsave
@@ -754,7 +740,9 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
754740 /BitsPerFlag 8
755741 /AntiAlias true
756742 /Decode [ { xmin :g} { xmax :g} { ymin :g} { ymax :g} 0 1 0 1 0 1 ]
757- /DataSource ({ stream } )
743+ /DataSource <
744+ { hexdata }
745+ >
758746>>
759747shfill
760748grestore
0 commit comments