
    ^h                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
JrJrJr  SSKJr  SSKJr  S	rS
r\R(                  S:X  a   SSKr " S S\5      rg! \ a    SSKr Nf = f)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                   6   \ rS rSrSr\" S5      S 5       r\" S5      S 5       r\" SS9R                  S	S
9r
\" S5      S 5       r\" \" 5       \" 5       /SS9R                  S	S
9r\" S5      S 5       r\" SS9R                  S	S
9r\" S5      S 5       rS rSrg)SVG2PDFPreprocessor"   z<
Converts all of the outputs in a notebook from SVG to PDF.
from_formatc                     g)Nzimage/svg+xml selfs    Y/home/james-whalen/.local/lib/python3.13/site-packages/nbconvert/preprocessors/svg2pdf.py_from_format_default(SVG2PDFPreprocessor._from_format_default'   s        	to_formatc                     g)Nzapplication/pdfr   r   s    r   _to_format_default&SVG2PDFPreprocessor._to_format_default+   s     r   zeThe version of inkscape being used.

        This affects how the conversion command is run.
        )helpT)configinkscape_versionc                 "   [         R                  " U R                  S/[         R                  [         R                  S9nUR	                  5       u  p#UR
                  S:w  a  Sn[        U5      eUR                  S5      R                  S5      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_default-SVG2PDFPreprocessor._inkscape_version_default6   sv    ]]K(????

 MMO	<<1@Cs##}}W%++C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                    U R                   R                  S5      S   nU R                  /n[        U5      S:  a#  UR	                  S5        UR	                  S5        OUR	                  S5        UR	                  S5        U$ )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_versionr4   s      r   _command_default$SVG2PDFPreprocessor._command_defaultT   sm    --33C8;==/}!NN?+NN78NN<=()r   z"The path to Inkscape, if necessaryr'   c                    [        S5      nUb  U$ [        R                  S:X  a\  [        R                  R                  [        5      (       a  [        $ [        R                  R                  [        5      (       a  [        $ [        R                  S:X  aY  [        R                  " S [        R                  5      n [        R                  " US5      n[        R                  " US5      S   nU$ g! [         a    Sn[        U5      S ef = f)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'   r1   s         r   _inkscape_default%SVG2PDFPreprocessor._inkscape_defaultf   s    j)$  <<8#ww~~o..&& ww~~l++##<<7"..tV5N5NOI7~~i1_`!..tR8; O	 % 75',$67s   ;1C/ /Dc                    [        5        n[        R                  R                  US5      n[	        USSS9 nUR                  U5        SSS5        [        R                  R                  US5      nXFS.n[        U R                  [        5      (       a4  U R                   Vs/ s H  oR                  [        S0 UD65      PM     n	nOU R                  R                  " U6 n	[        R                  " U	[        U	[        5      S9  [        R                  R                  U5      (       aR  [	        US	5       n[         R"                  " UR%                  5       5      R'                  S
5      sSSS5        sSSS5        $ Sn
[)        U
5      e! , (       d  f       GNE= fs  snf ! , (       d  f       O= f SSS5        g! , (       d  f       g= f)z>
Convert a single SVG figure to PDF.  Returns converted data.
z
figure.svgwutf8)encodingNz
figure.pdf)from_filenameto_filename)shellrbr#   z%Inkscape svg to pdf conversion failedr   )r   rA   rB   joinopenwrite
isinstancer4   list
format_mapr	   formatr%   callstrrC   base64encodebytesreadr,   	TypeError)r   data_formatdatatmpdirinput_filenamefoutput_filenametemplate_varssfull_cmdr1   s              r   convert_figure"SVG2PDFPreprocessor.convert_figure}   sL     !VWW\\&,?NncF;q < !ggll6<@O.<]M$,,--SWS_S_`S_aLL)H-)HIS_`  <<..>OOHJx,EF ww~~o../40A!--affh7>>wG 10- "!4 >n$/ <; a 100- "!!sN   ,F9F	AF9"#FA/F943F'	F9:F9
F	F9
F,	(F99
Gr   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r   tagr   r2   r   r   r4   r:   r'   rO   ro   __static_attributes__r   r   r   r   r   "   s     ]  [! ! 
 
cc   
4 !
4 	DF 
cc   Y  @AEETERHZ ,!%r   r   )ru   rb   rA   r%   r?   shutilr   tempfiler   	traitletsr   r   r   r   nbconvert.utils.ior	   convertfiguresr   rE   rD   r@   rF   ImportError_winregr   r   r   r   <module>r      sq     	  
  ' 3 3 - 6 L G<<7!
|%4 |%	  ! !s   A 
A)(A)