@@ -299,31 +299,28 @@ def create_hatch(self, hatch):
299
299
name = 'H%d' % len (self ._hatches )
300
300
linewidth = rcParams ['hatch.linewidth' ]
301
301
pageheight = self .height * 72
302
- self ._pswriter .write ("""\
302
+ self ._pswriter .write (f """\
303
303
<< /PatternType 1
304
304
/PaintType 2
305
305
/TilingType 2
306
- /BBox[0 0 %( sidelen)d %( sidelen)d ]
307
- /XStep %( sidelen)d
308
- /YStep %( sidelen)d
306
+ /BBox[0 0 { sidelen :d } { sidelen :d } ]
307
+ /XStep { sidelen :d }
308
+ /YStep { sidelen :d }
309
309
310
- /PaintProc {
310
+ /PaintProc {{
311
311
pop
312
- %(linewidth)f setlinewidth
313
- """ % locals ())
314
- self ._pswriter .write (
315
- self ._convert_path (Path .hatch (hatch ), Affine2D ().scale (sidelen ),
316
- simplify = False ))
317
- self ._pswriter .write ("""\
312
+ { linewidth :f} setlinewidth
313
+ { self ._convert_path (
314
+ Path .hatch (hatch ), Affine2D ().scale (sidelen ), simplify = False )}
318
315
fill
319
316
stroke
320
- } bind
317
+ }} bind
321
318
>>
322
319
matrix
323
- 0.0 %( pageheight)f translate
320
+ 0.0 { pageheight :f } translate
324
321
makepattern
325
- /%( name)s exch def
326
- """ % locals () )
322
+ /{ name } exch def
323
+ """ )
327
324
self ._hatches [hatch ] = name
328
325
return name
329
326
@@ -369,20 +366,20 @@ def draw_image(self, gc, x, y, im, transform=None):
369
366
clip .append ('%s' % id )
370
367
clip = '\n ' .join (clip )
371
368
372
- ps = """gsave
373
- %(clip)s
374
- %(x)s %(y)s translate
375
- [%(matrix)s] concat
376
- %(xscale)s %(yscale)s scale
377
- /DataString %(w)s string def
378
- %(w)s %(h)s 8 [ %(w)s 0 0 -%(h)s 0 %(h)s ]
379
- {
369
+ self ._pswriter .write (f"""\
370
+ gsave
371
+ { clip }
372
+ { x :f} { y :f} translate
373
+ [{ matrix } ] concat
374
+ { xscale :f} { yscale :f} scale
375
+ /DataString { w :d} string def
376
+ { w :d} { h :d} 8 [ { w :d} 0 0 -{ h :d} 0 { h :d} ]
377
+ {{
380
378
currentfile DataString readhexstring pop
381
- } bind %( imagecmd)s
382
- %( hexlines)s
379
+ }} bind { imagecmd }
380
+ { hexlines }
383
381
grestore
384
- """ % locals ()
385
- self ._pswriter .write (ps )
382
+ """ )
386
383
387
384
def _convert_path (self , path , transform , clip = False , simplify = None ):
388
385
if clip :
@@ -548,15 +545,13 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
548
545
r'\psfrag{%s}[bl][bl][1][%f]{\fontsize{%f}{%f}%s}' % (
549
546
thetext , angle , fontsize , fontsize * 1.25 , tex ))
550
547
551
- ps = """\
548
+ self . _pswriter . write ( f """\
552
549
gsave
553
- %( pos)s moveto
554
- (%( thetext)s )
550
+ { pos } moveto
551
+ ({ thetext } )
555
552
show
556
553
grestore
557
- """ % locals ()
558
-
559
- self ._pswriter .write (ps )
554
+ """ )
560
555
self .textcnt += 1
561
556
562
557
def draw_text (self , gc , x , y , s , prop , angle , ismath = False , mtext = None ):
@@ -607,17 +602,16 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
607
602
thisx += width * scale
608
603
609
604
thetext = "\n " .join (lines )
610
- ps = """\
605
+ self . _pswriter . write ( f """\
611
606
gsave
612
- /%( fontname)s findfont
613
- %( fontsize)s scalefont
607
+ /{ fontname } findfont
608
+ { fontsize } scalefont
614
609
setfont
615
- %(x)f %(y)f translate
616
- %( angle)f rotate
617
- %( thetext)s
610
+ { x :f } { y :f } translate
611
+ { angle :f } rotate
612
+ { thetext }
618
613
grestore
619
- """ % locals ()
620
- self ._pswriter .write (ps )
614
+ """ )
621
615
622
616
else :
623
617
font = self ._get_font_ttf (prop )
@@ -655,13 +649,13 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
655
649
thisx += glyph .linearHoriAdvance / 65536
656
650
657
651
thetext = '\n ' .join (lines )
658
- ps = """gsave
659
- %(x)f %(y)f translate
660
- %(angle)f rotate
661
- %(thetext)s
652
+ self ._pswriter .write (f"""\
653
+ gsave
654
+ { x :f} { y :f} translate
655
+ { angle :f} rotate
656
+ { thetext }
662
657
grestore
663
- """ % locals ()
664
- self ._pswriter .write (ps )
658
+ """ )
665
659
666
660
def new_gc (self ):
667
661
# docstring inherited
@@ -677,13 +671,13 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
677
671
self .merge_used_characters (used_characters )
678
672
self .set_color (* gc .get_rgb ())
679
673
thetext = pswriter .getvalue ()
680
- ps = """gsave
681
- %(x)f %(y)f translate
682
- %(angle)f rotate
683
- %(thetext)s
674
+ self ._pswriter .write (f"""\
675
+ gsave
676
+ { x :f} { y :f} translate
677
+ { angle :f} rotate
678
+ { thetext }
684
679
grestore
685
- """ % locals ()
686
- self ._pswriter .write (ps )
680
+ """ )
687
681
688
682
def draw_gouraud_triangle (self , gc , points , colors , trans ):
689
683
self .draw_gouraud_triangles (gc , points .reshape ((1 , 3 , 2 )),
@@ -720,20 +714,20 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
720
714
721
715
stream = quote_ps_string (streamarr .tostring ())
722
716
723
- self ._pswriter .write ("""
717
+ self ._pswriter .write (f """\
724
718
gsave
725
719
<< /ShadingType 4
726
720
/ColorSpace [/DeviceRGB]
727
721
/BitsPerCoordinate 32
728
722
/BitsPerComponent 8
729
723
/BitsPerFlag 8
730
724
/AntiAlias true
731
- /Decode [ %( xmin)f %( xmax)f %( ymin)f %( ymax)f 0 1 0 1 0 1 ]
732
- /DataSource (%( stream)s )
725
+ /Decode [ { xmin :f } { xmax :f } { ymin :f } { ymax :f } 0 1 0 1 0 1 ]
726
+ /DataSource ({ stream } )
733
727
>>
734
728
shfill
735
729
grestore
736
- """ % locals () )
730
+ """ )
737
731
738
732
def _draw_ps (self , ps , gc , rgbFace , fill = True , stroke = True , command = None ):
739
733
"""
0 commit comments