@@ -191,9 +191,11 @@ def cairo_convert(pdffile, pngfile, dpi):
191
191
return cairo_convert
192
192
elif "gs" in tools_available :
193
193
def gs_convert (pdffile , pngfile , dpi ):
194
- cmd = [str (gs ), '-dQUIET' , '-dSAFER' , '-dBATCH' , '-dNOPAUSE' , '-dNOPROMPT' ,
195
- '-sDEVICE=png16m' , '-dUseCIEColor' , '-dTextAlphaBits=4' ,
196
- '-dGraphicsAlphaBits=4' , '-dDOINTERPOLATE' , '-sOutputFile=%s' % pngfile ,
194
+ cmd = [str (gs ),
195
+ '-dQUIET' , '-dSAFER' , '-dBATCH' , '-dNOPAUSE' , '-dNOPROMPT' ,
196
+ '-dUseCIEColor' , '-dTextAlphaBits=4' ,
197
+ '-dGraphicsAlphaBits=4' , '-dDOINTERPOLATE' ,
198
+ '-sDEVICE=png16m' , '-sOutputFile=%s' % pngfile ,
197
199
'-r%d' % dpi , pdffile ]
198
200
check_output (cmd , stderr = subprocess .STDOUT )
199
201
return gs_convert
@@ -242,8 +244,8 @@ class LatexManager(object):
242
244
def _build_latex_header ():
243
245
latex_preamble = get_preamble ()
244
246
latex_fontspec = get_fontspec ()
245
- # Create LaTeX header with some content, else LaTeX will load some
246
- # math fonts later when we don't expect the additional output on stdout.
247
+ # Create LaTeX header with some content, else LaTeX will load some math
248
+ # fonts later when we don't expect the additional output on stdout.
247
249
# TODO: is this sufficient?
248
250
latex_header = [r"\documentclass{minimal}" ,
249
251
latex_preamble ,
@@ -300,16 +302,17 @@ def __init__(self):
300
302
cwd = self .tmpdir )
301
303
except OSError as e :
302
304
if e .errno == errno .ENOENT :
303
- raise RuntimeError ("Latex command not found. "
304
- "Install '%s' or change pgf.texsystem to the desired command."
305
- % self .texcommand
306
- )
305
+ raise RuntimeError (
306
+ "Latex command not found. Install %r or change "
307
+ "pgf.texsystem to the desired command." % self .texcommand )
307
308
else :
308
- raise RuntimeError ("Error starting process '%s'" % self .texcommand )
309
+ raise RuntimeError (
310
+ "Error starting process %r" % self .texcommand )
309
311
test_input = self .latex_header + latex_end
310
312
stdout , stderr = latex .communicate (test_input .encode ("utf-8" ))
311
313
if latex .returncode != 0 :
312
- raise LatexError ("LaTeX returned an error, probably missing font or error in preamble:\n %s" % stdout )
314
+ raise LatexError ("LaTeX returned an error, probably missing font "
315
+ "or error in preamble:\n %s" % stdout )
313
316
314
317
# open LaTeX process for real work
315
318
latex = subprocess .Popen ([str (self .texcommand ), "-halt-on-error" ],
@@ -429,7 +432,8 @@ def __init__(self, figure, fh, dummy=False):
429
432
UserWarning )
430
433
self .__dict__ ["draw_image" ] = lambda * args , ** kwargs : None
431
434
432
- def draw_markers (self , gc , marker_path , marker_trans , path , trans , rgbFace = None ):
435
+ def draw_markers (self , gc , marker_path , marker_trans , path , trans ,
436
+ rgbFace = None ):
433
437
writeln (self .fh , r"\begin{pgfscope}" )
434
438
435
439
# convert from display units to in
@@ -442,7 +446,9 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
442
446
# build marker definition
443
447
bl , tr = marker_path .get_extents (marker_trans ).get_points ()
444
448
coords = bl [0 ] * f , bl [1 ] * f , tr [0 ] * f , tr [1 ] * f
445
- writeln (self .fh , r"\pgfsys@defobject{currentmarker}{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{" % coords )
449
+ writeln (self .fh ,
450
+ r"\pgfsys@defobject{currentmarker}"
451
+ r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{" % coords )
446
452
self ._print_pgf_path (None , marker_path , marker_trans )
447
453
self ._pgf_path_draw (stroke = gc .get_linewidth () != 0.0 ,
448
454
fill = rgbFace is not None )
@@ -479,9 +485,13 @@ def draw_path(self, gc, path, transform, rgbFace=None):
479
485
writeln (self .fh , r"\pgfusepath{clip}" )
480
486
481
487
# build pattern definition
482
- writeln (self .fh , r"\pgfsys@defobject{currentpattern}{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}{" )
488
+ writeln (self .fh ,
489
+ r"\pgfsys@defobject{currentpattern}"
490
+ r"{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}{" )
483
491
writeln (self .fh , r"\begin{pgfscope}" )
484
- writeln (self .fh , r"\pgfpathrectangle{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}" )
492
+ writeln (self .fh ,
493
+ r"\pgfpathrectangle"
494
+ r"{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}" )
485
495
writeln (self .fh , r"\pgfusepath{clip}" )
486
496
scale = mpl .transforms .Affine2D ().scale (self .dpi )
487
497
self ._print_pgf_path (None , gc .get_hatch_path (), scale )
@@ -490,11 +500,13 @@ def draw_path(self, gc, path, transform, rgbFace=None):
490
500
writeln (self .fh , r"}" )
491
501
# repeat pattern, filling the bounding rect of the path
492
502
f = 1. / self .dpi
493
- (xmin , ymin ), (xmax , ymax ) = path .get_extents (transform ).get_points ()
503
+ (xmin , ymin ), (xmax , ymax ) = \
504
+ path .get_extents (transform ).get_points ()
494
505
xmin , xmax = f * xmin , f * xmax
495
506
ymin , ymax = f * ymin , f * ymax
496
507
repx , repy = int (math .ceil (xmax - xmin )), int (math .ceil (ymax - ymin ))
497
- writeln (self .fh , r"\pgfsys@transformshift{%fin}{%fin}" % (xmin , ymin ))
508
+ writeln (self .fh ,
509
+ r"\pgfsys@transformshift{%fin}{%fin}" % (xmin , ymin ))
498
510
for iy in range (repy ):
499
511
for ix in range (repx ):
500
512
writeln (self .fh , r"\pgfsys@useobject{currentpattern}{}" )
@@ -512,7 +524,10 @@ def _print_pgf_clip(self, gc):
512
524
p1 , p2 = bbox .get_points ()
513
525
w , h = p2 - p1
514
526
coords = p1 [0 ] * f , p1 [1 ] * f , w * f , h * f
515
- writeln (self .fh , r"\pgfpathrectangle{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}} " % coords )
527
+ writeln (self .fh ,
528
+ r"\pgfpathrectangle"
529
+ r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}"
530
+ % coords )
516
531
writeln (self .fh , r"\pgfusepath{clip}" )
517
532
518
533
# check for clip path
@@ -544,7 +559,9 @@ def _print_pgf_path_styles(self, gc, rgbFace):
544
559
fillopacity = rgbFace [3 ] if has_fill and len (rgbFace ) > 3 else 1.0
545
560
546
561
if has_fill :
547
- writeln (self .fh , r"\definecolor{currentfill}{rgb}{%f,%f,%f}" % tuple (rgbFace [:3 ]))
562
+ writeln (self .fh ,
563
+ r"\definecolor{currentfill}{rgb}{%f,%f,%f}"
564
+ % tuple (rgbFace [:3 ]))
548
565
writeln (self .fh , r"\pgfsetfillcolor{currentfill}" )
549
566
if has_fill and fillopacity != 1.0 :
550
567
writeln (self .fh , r"\pgfsetfillopacity{%f}" % fillopacity )
@@ -553,7 +570,9 @@ def _print_pgf_path_styles(self, gc, rgbFace):
553
570
lw = gc .get_linewidth () * mpl_pt_to_in * latex_in_to_pt
554
571
stroke_rgba = gc .get_rgb ()
555
572
writeln (self .fh , r"\pgfsetlinewidth{%fpt}" % lw )
556
- writeln (self .fh , r"\definecolor{currentstroke}{rgb}{%f,%f,%f}" % stroke_rgba [:3 ])
573
+ writeln (self .fh ,
574
+ r"\definecolor{currentstroke}{rgb}{%f,%f,%f}"
575
+ % stroke_rgba [:3 ])
557
576
writeln (self .fh , r"\pgfsetstrokecolor{currentstroke}" )
558
577
if strokeopacity != 1.0 :
559
578
writeln (self .fh , r"\pgfsetstrokeopacity{%f}" % strokeopacity )
@@ -582,22 +601,32 @@ def _print_pgf_path(self, gc, path, transform, rgbFace=None):
582
601
for points , code in path .iter_segments (transform , clip = clip ):
583
602
if code == Path .MOVETO :
584
603
x , y = tuple (points )
585
- writeln (self .fh , r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" %
604
+ writeln (self .fh ,
605
+ r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" %
586
606
(f * x , f * y ))
587
607
elif code == Path .CLOSEPOLY :
588
608
writeln (self .fh , r"\pgfpathclose" )
589
609
elif code == Path .LINETO :
590
610
x , y = tuple (points )
591
- writeln (self .fh , r"\pgfpathlineto{\pgfqpoint{%fin}{%fin}}" %
611
+ writeln (self .fh ,
612
+ r"\pgfpathlineto{\pgfqpoint{%fin}{%fin}}" %
592
613
(f * x , f * y ))
593
614
elif code == Path .CURVE3 :
594
615
cx , cy , px , py = tuple (points )
595
616
coords = cx * f , cy * f , px * f , py * f
596
- writeln (self .fh , r"\pgfpathquadraticcurveto{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}" % coords )
617
+ writeln (self .fh ,
618
+ r"\pgfpathquadraticcurveto"
619
+ r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}"
620
+ % coords )
597
621
elif code == Path .CURVE4 :
598
622
c1x , c1y , c2x , c2y , px , py = tuple (points )
599
623
coords = c1x * f , c1y * f , c2x * f , c2y * f , px * f , py * f
600
- writeln (self .fh , r"\pgfpathcurveto{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}" % coords )
624
+ writeln (self .fh ,
625
+ r"\pgfpathcurveto"
626
+ r"{\pgfqpoint{%fin}{%fin}}"
627
+ r"{\pgfqpoint{%fin}{%fin}}"
628
+ r"{\pgfqpoint{%fin}{%fin}}"
629
+ % coords )
601
630
602
631
def _pgf_path_draw (self , stroke = True , fill = False ):
603
632
actions = []
@@ -805,7 +834,9 @@ def _print_pgf_to_fh(self, fh, *args, **kwargs):
805
834
writeln (fh , r"\begingroup" )
806
835
writeln (fh , r"\makeatletter" )
807
836
writeln (fh , r"\begin{pgfpicture}" )
808
- writeln (fh , r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}" % (w , h ))
837
+ writeln (fh ,
838
+ r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}"
839
+ % (w , h ))
809
840
writeln (fh , r"\pgfusepath{use as bounding box, clip}" )
810
841
_bbox_inches_restore = kwargs .pop ("bbox_inches_restore" , None )
811
842
renderer = MixedModeRenderer (self .figure , w , h , dpi ,
@@ -872,7 +903,9 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs):
872
903
try :
873
904
check_output (cmdargs , stderr = subprocess .STDOUT , cwd = tmpdir )
874
905
except subprocess .CalledProcessError as e :
875
- raise RuntimeError ("%s was not able to process your file.\n \n Full log:\n %s" % (texcommand , e .output ))
906
+ raise RuntimeError (
907
+ "%s was not able to process your file.\n \n Full log:\n %s"
908
+ % (texcommand , e .output ))
876
909
877
910
# copy file contents to target
878
911
with open (fname_pdf , "rb" ) as fh_src :
0 commit comments