
    Mh                         d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZ ddlmZ d	Zd
Zej        dk    r	 ddlZn# e$ r ddlZY nw xY w G d de          ZdS )zcModule containing a preprocessor that converts outputs in the notebook from
one format to another.
    N)which)TemporaryDirectory)ListUnicodeUniondefault)FormatSafeDict   )ConvertFiguresPreprocessorz:/Applications/Inkscape.app/Contents/Resources/bin/inkscapez2/Applications/Inkscape.app/Contents/MacOS/inkscapewin32c                      e Zd ZdZ ed          d             Z ed          d             Z ed                              d	          Z	 ed
          d             Z
 e e             e            gd                              d	          Z ed          d             Z ed                              d	          Z ed          d             Zd ZdS )SVG2PDFPreprocessorzD
    Converts all of the outputs in a notebook from SVG to PDF.
    from_formatc                     dS )Nzimage/svg+xml selfs    _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbconvert/preprocessors/svg2pdf.py_from_format_defaultz(SVG2PDFPreprocessor._from_format_default'   s        	to_formatc                     dS )Nzapplication/pdfr   r   s    r   _to_format_defaultz&SVG2PDFPreprocessor._to_format_default+   s      r   zeThe version of inkscape being used.

        This affects how the conversion command is run.
        )helpT)configinkscape_versionc                 (   t          j        | j        dgt           j        t           j                  }|                                \  }}|j        dk    rd}t          |          |                    d                              d          d         S )Nz	--version)stdoutstderrr   z,Unable to find inkscape executable --versionutf-8 r
   )	
subprocessPopeninkscapePIPEcommunicate
returncodeRuntimeErrordecodesplit)r   poutput_msgs        r   _inkscape_version_defaultz-SVG2PDFPreprocessor._inkscape_version_default6   s    ]K(??
 
 

 MMOO	<1@Cs###}}W%%++C0033r   a  
        The command to use for converting SVG to PDF

        This traitlet is a template, which will be formatted with the keys
        to_filename and from_filename.

        The conversion call must read the SVG from {from_filename},
        and write a PDF to {to_filename}.

        It could be a List (recommended) or a String. If string, it will
        be passed to a shell for execution.
        commandc                 &   | j                             d          d         }| j        g}t          |          dk     r+|                    d           |                    d           n|                    d           |                    d           |S )N.r   r
   z--without-guiz--export-pdf={to_filename}z--export-filename={to_filename}z{from_filename})r   r*   r$   intappend)r   major_versionr0   s      r   _command_defaultz$SVG2PDFPreprocessor._command_defaultT   s    -33C88;=/}!!NN?+++NN78888NN<===()))r   z"The path to Inkscape, if necessaryr$   c                    t          d          }||S t          j        dk    rVt          j                            t                    rt          S t          j                            t                    rt          S t          j        dk    rst          j	        d t          j
                  }	 t          j        |d          }t          j        |d          d         }n # t          $ r d}t          |          d w xY w|S dS )Nr$   darwinr   z)SOFTWARE\Classes\inkscape.svg\DefaultIcon r   zInkscape executable not found)r   sysplatformospathisfileINKSCAPE_APP_v1INKSCAPE_APPwinregConnectRegistryHKEY_LOCAL_MACHINEOpenKeyQueryValueExFileNotFoundError)r   inkscape_path	wr_handlerkeyr$   r.   s         r   _inkscape_defaultz%SVG2PDFPreprocessor._inkscape_defaultf   s    j))$  <8##w~~o.. '&& w~~l++ $##<7"".tV5NOOI7~i1_``!.tR88;$ 7 7 75',,$67 Ozs   *0C C8c                 h  	 t                      5 }t          j                            |d          }t	          |dd          5 }|                    |           ddd           n# 1 swxY w Y   t          j                            |d          }||d	t          | j        t                    r	fd| j        D             }n | j        j	        	 }t          j        |t          |t                    	           t          j                            |          rnt	          |d
          5 }t          j        |                                                              d          cddd           cddd           S # 1 swxY w Y   nd}t%          |          	 ddd           dS # 1 swxY w Y   dS )zN
        Convert a single SVG figure to PDF.  Returns converted data.
        z
figure.svgwutf8)encodingNz
figure.pdf)from_filenameto_filenamec           	      N    g | ]!}|                     t          d i           "S )r   )
format_mapr	   ).0stemplate_varss     r   
<listcomp>z6SVG2PDFPreprocessor.convert_figure.<locals>.<listcomp>   s3    ```aALL)H)H-)H)HII```r   )shellrbr    z%Inkscape svg to pdf conversion failed)r   r<   r=   joinopenwrite
isinstancer0   listformatr"   callstrr>   base64encodebytesreadr)   	TypeError)
r   data_formatdatatmpdirinput_filenamefoutput_filenamefull_cmdr.   rU   s
            @r   convert_figurez"SVG2PDFPreprocessor.convert_figure}   s{     !! 	%VW\\&,??NncF;;; q               !gll6<@@O.<_]]M$,-- ?````SWS_``` /4<.>OHJx,E,EFFFF w~~o.. %/400 HA!-affhh77>>wGGH H H H H H H-	% 	% 	% 	% 	% 	% 	% 	%,H H H H H H H H H >nn$H-	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%sZ   3F'A%F'%A)	)F',A)	-B=F'*9E<#F'<F 	 F'F 	F''F+.F+N)__name__
__module____qualname____doc__r   r   r   r   tagr   r/   r   r   r0   r6   r$   rJ   rl   r   r   r   r   r   "   s         W]   W[! ! ! w  
 
cc  W  
4 
4 ! 
4 e	DDFF   
cc   WY   w@AAAEETERRHWZ  ,!% !% !% !% !%r   r   )rp   ra   r<   r"   r:   shutilr   tempfiler   	traitletsr   r   r   r   nbconvert.utils.ior	   convertfiguresr   r@   r?   r;   rA   ImportError_winregr   r   r   r   <module>ry      s=     				     



       ' ' ' ' ' ' 3 3 3 3 3 3 3 3 3 3 3 3 - - - - - - 6 6 6 6 6 6 L G<7! ! ! !      !|% |% |% |% |%4 |% |% |% |% |%s   A 	AA