@@ -191,9 +191,11 @@ def cairo_convert(pdffile, pngfile, dpi):
191191 return cairo_convert
192192 elif "gs" in tools_available :
193193 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 ,
197199 '-r%d' % dpi , pdffile ]
198200 check_output (cmd , stderr = subprocess .STDOUT )
199201 return gs_convert
@@ -242,8 +244,8 @@ class LatexManager(object):
242244 def _build_latex_header ():
243245 latex_preamble = get_preamble ()
244246 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.
247249 # TODO: is this sufficient?
248250 latex_header = [r"\documentclass{minimal}" ,
249251 latex_preamble ,
@@ -300,16 +302,17 @@ def __init__(self):
300302 cwd = self .tmpdir )
301303 except OSError as e :
302304 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 )
307308 else :
308- raise RuntimeError ("Error starting process '%s'" % self .texcommand )
309+ raise RuntimeError (
310+ "Error starting process %r" % self .texcommand )
309311 test_input = self .latex_header + latex_end
310312 stdout , stderr = latex .communicate (test_input .encode ("utf-8" ))
311313 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 )
313316
314317 # open LaTeX process for real work
315318 latex = subprocess .Popen ([str (self .texcommand ), "-halt-on-error" ],
@@ -429,7 +432,8 @@ def __init__(self, figure, fh, dummy=False):
429432 UserWarning )
430433 self .__dict__ ["draw_image" ] = lambda * args , ** kwargs : None
431434
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 ):
433437 writeln (self .fh , r"\begin{pgfscope}" )
434438
435439 # convert from display units to in
@@ -442,7 +446,9 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
442446 # build marker definition
443447 bl , tr = marker_path .get_extents (marker_trans ).get_points ()
444448 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 )
446452 self ._print_pgf_path (None , marker_path , marker_trans )
447453 self ._pgf_path_draw (stroke = gc .get_linewidth () != 0.0 ,
448454 fill = rgbFace is not None )
@@ -479,9 +485,13 @@ def draw_path(self, gc, path, transform, rgbFace=None):
479485 writeln (self .fh , r"\pgfusepath{clip}" )
480486
481487 # 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}}{" )
483491 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}}" )
485495 writeln (self .fh , r"\pgfusepath{clip}" )
486496 scale = mpl .transforms .Affine2D ().scale (self .dpi )
487497 self ._print_pgf_path (None , gc .get_hatch_path (), scale )
@@ -490,11 +500,13 @@ def draw_path(self, gc, path, transform, rgbFace=None):
490500 writeln (self .fh , r"}" )
491501 # repeat pattern, filling the bounding rect of the path
492502 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 ()
494505 xmin , xmax = f * xmin , f * xmax
495506 ymin , ymax = f * ymin , f * ymax
496507 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 ))
498510 for iy in range (repy ):
499511 for ix in range (repx ):
500512 writeln (self .fh , r"\pgfsys@useobject{currentpattern}{}" )
@@ -512,7 +524,10 @@ def _print_pgf_clip(self, gc):
512524 p1 , p2 = bbox .get_points ()
513525 w , h = p2 - p1
514526 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 )
516531 writeln (self .fh , r"\pgfusepath{clip}" )
517532
518533 # check for clip path
@@ -544,7 +559,9 @@ def _print_pgf_path_styles(self, gc, rgbFace):
544559 fillopacity = rgbFace [3 ] if has_fill and len (rgbFace ) > 3 else 1.0
545560
546561 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 ]))
548565 writeln (self .fh , r"\pgfsetfillcolor{currentfill}" )
549566 if has_fill and fillopacity != 1.0 :
550567 writeln (self .fh , r"\pgfsetfillopacity{%f}" % fillopacity )
@@ -553,7 +570,9 @@ def _print_pgf_path_styles(self, gc, rgbFace):
553570 lw = gc .get_linewidth () * mpl_pt_to_in * latex_in_to_pt
554571 stroke_rgba = gc .get_rgb ()
555572 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 ])
557576 writeln (self .fh , r"\pgfsetstrokecolor{currentstroke}" )
558577 if strokeopacity != 1.0 :
559578 writeln (self .fh , r"\pgfsetstrokeopacity{%f}" % strokeopacity )
@@ -582,22 +601,32 @@ def _print_pgf_path(self, gc, path, transform, rgbFace=None):
582601 for points , code in path .iter_segments (transform , clip = clip ):
583602 if code == Path .MOVETO :
584603 x , y = tuple (points )
585- writeln (self .fh , r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" %
604+ writeln (self .fh ,
605+ r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" %
586606 (f * x , f * y ))
587607 elif code == Path .CLOSEPOLY :
588608 writeln (self .fh , r"\pgfpathclose" )
589609 elif code == Path .LINETO :
590610 x , y = tuple (points )
591- writeln (self .fh , r"\pgfpathlineto{\pgfqpoint{%fin}{%fin}}" %
611+ writeln (self .fh ,
612+ r"\pgfpathlineto{\pgfqpoint{%fin}{%fin}}" %
592613 (f * x , f * y ))
593614 elif code == Path .CURVE3 :
594615 cx , cy , px , py = tuple (points )
595616 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 )
597621 elif code == Path .CURVE4 :
598622 c1x , c1y , c2x , c2y , px , py = tuple (points )
599623 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 )
601630
602631 def _pgf_path_draw (self , stroke = True , fill = False ):
603632 actions = []
@@ -805,7 +834,9 @@ def _print_pgf_to_fh(self, fh, *args, **kwargs):
805834 writeln (fh , r"\begingroup" )
806835 writeln (fh , r"\makeatletter" )
807836 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 ))
809840 writeln (fh , r"\pgfusepath{use as bounding box, clip}" )
810841 _bbox_inches_restore = kwargs .pop ("bbox_inches_restore" , None )
811842 renderer = MixedModeRenderer (self .figure , w , h , dpi ,
@@ -872,7 +903,9 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs):
872903 try :
873904 check_output (cmdargs , stderr = subprocess .STDOUT , cwd = tmpdir )
874905 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 ))
876909
877910 # copy file contents to target
878911 with open (fname_pdf , "rb" ) as fh_src :
0 commit comments