2525system_fonts = []
2626for f in font_manager .findSystemFonts ():
2727 try :
28- system_fonts .append (FT2Font (f ).family_name )
28+ system_fonts .append (FT2Font (str ( f ).family_name ) )
2929 except RuntimeError :
30- pass
30+ pass # some fonts on osx are known to fail, print?
31+ except :
32+ pass # unknown error, skip this font
3133
3234# get chosen TeX system from rc
3335def get_texcommand ():
@@ -659,23 +661,23 @@ def print_pgf(self, filename, *args, **kwargs):
659661 w , h = self .figure .get_figwidth (), self .figure .get_figheight ()
660662
661663 # start a pgfpicture environment and set a bounding box
662- fh = codecs .open (filename , "wt " , encoding = "utf-8" )
663- fh .write (header_text )
664- fh .write (header_info_preamble )
665- fh .write ("\n " )
666- writeln (fh , r"\begingroup" )
667- writeln (fh , r"\makeatletter" )
668- writeln (fh , r"\begin{pgfpicture}" )
669- writeln (fh , r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}" % (w ,h ))
670- writeln (fh , r"\pgfusepath{use as bounding box}" )
671-
672- renderer = RendererPgf (self .figure , fh )
673- self .figure .draw (renderer )
674-
675- # end the pgfpicture environment
676- writeln (fh , r"\end{pgfpicture}" )
677- writeln (fh , r"\makeatother" )
678- writeln (fh , r"\endgroup" )
664+ with codecs .open (filename , "w " , encoding = "utf-8" ) as fh :
665+ fh .write (header_text )
666+ fh .write (header_info_preamble )
667+ fh .write ("\n " )
668+ writeln (fh , r"\begingroup" )
669+ writeln (fh , r"\makeatletter" )
670+ writeln (fh , r"\begin{pgfpicture}" )
671+ writeln (fh , r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}" % (w ,h ))
672+ writeln (fh , r"\pgfusepath{use as bounding box}" )
673+
674+ renderer = RendererPgf (self .figure , fh )
675+ self .figure .draw (renderer )
676+
677+ # end the pgfpicture environment
678+ writeln (fh , r"\end{pgfpicture}" )
679+ writeln (fh , r"\makeatother" )
680+ writeln (fh , r"\endgroup" )
679681
680682 def print_pdf (self , filename , * args , ** kwargs ):
681683 """
@@ -704,7 +706,7 @@ def print_pdf(self, filename, *args, **kwargs):
704706\centering
705707\input{figure.pgf}
706708\end{document}""" % (w , h , latex_preamble , latex_fontspec )
707- with codecs .open ("figure.tex" , "wt " , "utf-8" ) as fh :
709+ with codecs .open ("figure.tex" , "w " , "utf-8" ) as fh :
708710 fh .write (latexcode )
709711
710712 texcommand = get_texcommand ()
@@ -716,7 +718,10 @@ def print_pdf(self, filename, *args, **kwargs):
716718 shutil .copyfile ("figure.pdf" , target )
717719 finally :
718720 os .chdir (cwd )
719- shutil .rmtree (tmpdir )
721+ try :
722+ shutil .rmtree (tmpdir )
723+ except :
724+ sys .stderr .write ("could not delete tmp directory %s\n " % tmpdir )
720725
721726 def print_png (self , filename , * args , ** kwargs ):
722727 """
@@ -735,7 +740,10 @@ def print_png(self, filename, *args, **kwargs):
735740 shutil .copyfile ("figure.png" , target )
736741 finally :
737742 os .chdir (cwd )
738- shutil .rmtree (tmpdir )
743+ try :
744+ shutil .rmtree (tmpdir )
745+ except :
746+ sys .stderr .write ("could not delete tmp directory %s\n " % tmpdir )
739747
740748 def _render_texts_pgf (self , fh ):
741749 # TODO: currently unused code path
0 commit comments