File indexing completed on 2025-01-19 03:59:51

0001 import cairosvg
0002 import io
0003 
0004 from .base import exporter
0005 from .svg import export_svg
0006 
0007 
0008 def _export_cairo(func, animation, fp, frame, dpi):
0009     intermediate = io.StringIO()
0010     export_svg(animation, intermediate, frame)
0011     intermediate.seek(0)
0012     func(file_obj=intermediate, write_to=fp, dpi=dpi)
0013 
0014 
0015 @exporter("PNG", ["png"], [], {"frame"})
0016 def export_png(animation, fp, frame=0, dpi=96):
0017     _export_cairo(cairosvg.svg2png, animation, fp, frame, dpi)
0018 
0019 
0020 @exporter("PDF", ["pdf"], [], {"frame"})
0021 def export_pdf(animation, fp, frame=0, dpi=96):
0022     _export_cairo(cairosvg.svg2pdf, animation, fp, frame, dpi)
0023 
0024 
0025 @exporter("PostScript", ["ps"], [], {"frame"})
0026 def export_ps(animation, fp, frame=0, dpi=96):
0027     _export_cairo(cairosvg.svg2ps, animation, fp, frame, dpi)