
    :Qgv              
          d Z ddlZddl dZdZdZdZdZd	Ze	Z
e	Z G d
 de      Zd Zd Zej                   dk(  r eee
 ee      e      Zn eee
 ee      e      Zd Zd ZeZd Zd Zd Zd Zej                   dk(  rz e       ZesTddlZej@                  jC                  djE                  d e# ejH                  ejJ                        dz        df            Zes e&d      e'jQ                  e      Z[y	 e)jQ                  d      Z[y# e*$ r> ddlZej@                  jC                  d      Zes e&d      e)jQ                  e      ZY [yw xY w)zT
ghostscript._gsprint - A low-level interface to the Ghostscript C-API using ctypes
    N)*iiz-Hartmut Goebel <h.goebel@crazy-compilers.com>zDCopyright 2010-2018 by Hartmut Goebel <h.goebel@crazy-compilers.com>z-GNU General Public License version 3 (GPL v3)z0.6c                       e Zd Zd Zy)GhostscriptErrorc                     || _         y N)code)selfecodes     ]/var/www/html/answerous/venv/lib/python3.12/site-packages/camelot/ext/ghostscript/_gsprint.py__init__zGhostscriptError.__init__9   s	    	    N)__name__
__module____qualname__r    r   r   r   r   8   s    r   r   c                  |    d} t               }t        j                  t        |      |       }|dk7  rt	        |      |S )zcCreate a new instance of Ghostscript

    This instance is passed to most other API functions.
    Nr   )gs_main_instancelibgsgsapi_new_instancepointerr   )display_callbackinstancercs      r   new_instancer   =   sA     !H		!	!'("35E	FB	Qwr""Or   c                 ,    t         j                  |       S )zDestroy an instance of Ghostscript

    Before you call this, Ghostscript must have finished.
    If Ghostscript has been initialised, you must call exit()
    before delete_instance()
    )r   gsapi_delete_instance)r   s    r   delete_instancer   K   s     &&x00r   win32c                 $      fd}t        |      S )zWrap a filehandle into a C function to be used as `stdin` callback
    for ``set_stdio``. The filehandle has to support the readline() method.
    c                     	 j                  |      }|sd}|S t        |      }t        |t        |      |       |S #  d}Y |S xY w)Nr   )readlinelenmemmovec_char_p)r   destcountdatainfps       r   _wrapz_wrap_stdin.<locals>._wrap`   sZ    		5=='D   D	htne4	E s	   = Ac_stdstream_call_t)r)   r*   s   ` r   _wrap_stdinr-   [   s    
 e$$r   c                 $      fd}t        |      S )zWrap a filehandle into a C function to be used as `stdout` or
    `stderr` callback for ``set_stdio``. The filehandle has to support the
    write() and flush() methods.
    c                 P    j                  |d |        j                          |S r   )writeflush)r   strr'   outfps      r   r*   z_wrap_stdout.<locals>._wrapv   s#    CK r   r+   )r3   r*   s   ` r   _wrap_stdoutr4   p   s    
 e$$r   c                 j    t         j                  | |||      }|dt        t        fvrt	        |      |S )a  Set the callback functions for stdio.

    ``stdin``, ``stdout`` and ``stderr`` have to be ``ctypes``
    callback functions matching the ``_gsprint.c_stdstream_call_t``
    prototype. You may want to use _wrap_* to wrap file handles.

    Note 1: This function only changes stdio of the Postscript
    interpreter, not that of the devices.

    Note 2: Make sure you keep references to C function objects
    as long as they are used from C code. Otherwise they may be
    garbage collected, crashing your program when a callback is made.

    The ``stdin`` callback function should return the number of
    characters read, `0` for EOF, or `-1` for error. The `stdout` and
    `stderr` callback functions should return the number of characters
    written.

    You may pass ``None`` for any of stdin, stdout or stderr , in which
    case the system stdin, stdout resp. stderr will be used.
    r   )r   gsapi_set_stdioe_Quite_Infor   )r   stdinstdoutstderrr   s        r   	set_stdior<      s9    , 
		x	?B	!VV$$r""Ir   c                     t         t        |      z  } || }t        j                  | t        |      |      }|dt        t
        fvrt        |      |S )a  Initialise the interpreter

    1. If quit or EOF occur during init_with_args(), the return value
       will be e_Quit. This is not an error. You must call exit() and
       must not call any other functions.

    2. If usage info should be displayed, the return value will be
       e_Info which is not an error. Do not call exit().

    3. Under normal conditions this returns 0. You would then call one
       or more run_*() functions and then finish with exit()
    r   )r%   r#   r   gsapi_init_with_argsr7   r8   r   )r   argvArgArrayc_argvr   s        r   init_with_argsrB      sR     #d)#Ht_F		#	#Hc$i	@B	!VV$$r""Ir   c                 P    t         j                  |       }|dk7  rt        |      |S )zExit the interpreter

    This must be called on shutdown if init_with_args() has been
    called, and just before delete_instance()
    r   )r   
gsapi_exitr   )r   r   s     r   exitrE      s+     
		(	#B	Qwr""Ir   c                     	 dd l } ddl m}m}m}m}m}m} ddl	m
} dd l}g }	dD ]  }
	  ||d|
z        }t        d ||      d         D ]]  } |||      }	  |||      } ||d      d   } ||       |j                  j                  |      r|	j                   ||      |f       _  ||        |	r|	j#                          |	d   d   S y # t        $ r ddlm}m}m}m}m}m} Y w xY w# t         $ r Y w xY w# t         $ r Y w xY w)Nr   )OpenKeyCloseKeyEnumKeyQueryValueExQueryInfoKeyHKEY_LOCAL_MACHINE)LooseVersion)zAFPL GhostscriptzAladdin GhostscriptzGNU GhostscriptzGPL GhostscriptzSoftware\%sGS_DLLr!   )winregrG   rH   rI   rJ   rK   rL   ImportError_winregdistutils.versionrM   osrangepathexistsappendWindowsErrorsort)rO   rG   rH   rI   rJ   rK   rL   rM   rS   dllskey_namek1numversionk2dll_paths                   r   __win32_finddllra      s5   
	
 	
 /D 	+^h-FGBQR 0 34 	!"c* W-B+B9!<HRLww~~h/\'%:H$EF	 RL%* 		Bx|g  	
	
 	
 	
	
T $   		sG   C -C<AC-'
C<C*)C*-	C96C<8C99C<<	DD gsdll   z.dllz.Please make sure that Ghostscript is installedzlibgs.sogs)+__doc__sysctypesr8   r7   
__author____copyright____license____version__c_void_pr   r   	Exceptionr   r   r   platformWINFUNCTYPEc_intPOINTERc_charr,   	CFUNCTYPEr-   r4   _wrap_stderrr<   rB   rE   ra   r   ctypes.utilutilfind_libraryjoinr2   sizeofc_voidpRuntimeErrorwindllLoadLibrarycdllOSErrorr   r   r   <module>r      s  .   
 
<
V=  
y 
1 <<7$U,<gfouU"5*:GFOUS%*% 8*	6r <<7E((GGWc-&--"?!"CDfMN
 KLLu%E 	(  ,   (((.OPP  '(s   =D ?EE