o
    	ȷeIA                  
   @   s  d Z dZdZdZdZddlT ddlZddlT d	Zd
Z	dZ
dZdZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+d Z,d!Z-d"Z.d"Z/G d#d$ d$e0Z1e2Z3e2Z4G d%d& d&e5Z6d'd( Z7d)d* Z8d+d, Z9e:e;e3e<e=e;Z>d-d. Z?d/d0 Z@e@ZAd1d2 ZBd3d4 ZCd5d6 ZDdQd8d9ZEdQd:d;ZFdQd<d=ZGd>d? ZHdQd@dAZIdQdBdCZJdDdE ZKe:e;e2e2ZLe:e;e2e2ZMe:e;e2e2ZNe:e;e2e2e;e;e;eOZPe:e;e2e2e;e;e;eOe<eQZRe:e;e2e2ZSe:e;e2e2e;e;ZTe:e;e2e2e;e;e;e;ZUe:e2e2e2eVZWe:e;e2e2e2ZXe:e;e2e2e;eYeZeZeZeZ	Z[G dFdG dGe0Z\dHdI Z]dJdK Z^ej_dLkrIe^ Z`e`sAeadMebce`Z`[^dS z	edcdNZ`W [^dS  eeyt   ddlfZejghdOZ`e`skeadPedce`Z`Y [^dS w )RzT
ghostscript._gsprint - A low-lewel interface to the Ghostscript C-API using ctypes
z-Hartmut Goebel <h.goebel@crazy-compilers.com>z?Copyright 2010 by Hartmut Goebel <h.goebel@crazy-compilers.com>z-GNU General Public License version 3 (GPL v3)z0.5dev    )*N   i           i   i         @            i   i   i   i   i    i   i   i   i   i  0 i  @ i  P i  ` i  p c                   @   s(   e Zd ZdefdefdefdefgZdS )Revisionproduct	copyrightrevisionrevisiondateN)__name__
__module____qualname__c_char_pc_long_fields_ r   r   K/var/www/ideatree/venv/lib/python3.10/site-packages/ghostscript/_gsprint.pyr   z   s    r   c                   @   s   e Zd Zdd ZdS )GhostscriptErrorc                 C   s   t | t| || _d S N)	Exception__init__
error2namecode)selfecoder   r   r   r      s   
zGhostscriptError.__init__N)r   r   r   r   r   r   r   r   r      s    r   c                  C   s.   t  } tt| t| }|rtd| | S )z
    Get version numbers and strings.

    This is safe to call at any time.
    You should call this first to make sure that the correct version
    of the Ghostscript is being used.

    Returns a Revision instance
    z7Revision structure size is incorrect, requires %s bytes)r   libgsgsapi_revisionpointersizeofArgumentError)r   rcr   r   r   r      s   
r   c                  C   s.   d} t  }tt|| }|dkrt||S )zl
    Create a new instance of Ghostscript
    
    This instance is passed to most other API functions.
    Nr   )gs_main_instancer"   gsapi_new_instancer$   r   )display_callbackinstancer'   r   r   r   new_instance   s   r,   c                 C   s
   t | S )z
    Destroy 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+   r   r   r   delete_instance   s   
r.   c                        fdd}t |S )z
    Wrap a filehandle into a C function to be used as `stdin` callback
    for ``set_stdio``. The filehandle has to support the readline() method.
    c                    sH   z  |}W n   d}Y |S |sd}|S t|}t|t|| |S )Nr   )readlinelenmemmover   )r+   destcountdatainfpr   r   _wrap   s   z_wrap_stdin.<locals>._wrapc_stdstream_call_t)r8   r9   r   r7   r   _wrap_stdin   s   r<   c                    r/   )z
    Wrap 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                    s     |d |     |S r   )writeflush)r+   strr5   outfpr   r   r9      s   z_wrap_stdout.<locals>._wrapr:   )rA   r9   r   r@   r   _wrap_stdout   s   rB   c                 C   s*   t | |||}|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.

    Please note: 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.
    r   )r"   gsapi_set_stdioe_Quite_Infor   )r+   stdinstdoutstderrr'   r   r   r   	set_stdio   s   rI   c                 C   s@   t t| }|| }t| 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   r2   r"   gsapi_init_with_argsrD   rE   r   )r+   argvArgArrayc_argvr'   r   r   r   init_with_args   s   rN   c                 C   s   t | }|dkrt||S )z
    Exit 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'   r   r   r   exit  s   
rP   Fc                 C   2   t  }t| t |t|}|dkrt||jS Nr   )c_intr"   gsapi_run_string_beginr$   r   valuer+   user_errors	exit_coder'   r   r   r   run_string_begin     rY   c                 C   sJ   t  }t| t|t t|t |t|}|tkr"|dkr"t||jS rR   )	rS   r"   gsapi_run_string_continuer   r2   r$   e_NeedInputr   rU   r+   r?   rW   rX   r'   r   r   r   run_string_continue!  s   r^   c                 C   rQ   rR   )rS   r"   gsapi_run_string_endr$   r   rU   rV   r   r   r   run_string_end*  rZ   r`   c                  O   s   t d)NzUse run_string() instead)NotImpelmentedError)argskwr   r   r   run_string_with_length2  s   rd   c                 C   sB   t  }t| t|t t|t |t|}|dkrt||jS rR   )rS   r"   gsapi_run_string_with_lengthr   r2   r$   r   rU   r]   r   r   r   
run_string6  s   rf   c                 C   s8   t  }t| t|t |t|}|dkrt||jS rR   )rS   r"   gsapi_run_filer   r$   r   rU   )r+   filenamerW   rX   r'   r   r   r   run_file@  s   ri   c                 C   s   t r   )NotImplementedError)Ir   r   r   set_visual_tracerI  s   rl   c                   @   sd   e Zd Zdefdefdefdefdefdefdefdefd	e	fd
e
fdefdefdefdefgZdS )Display_callback_ssizeversion_majorversion_minordisplay_opendisplay_preclosedisplay_closedisplay_presizedisplay_sizedisplay_syncdisplay_pagedisplay_updatedisplay_memallocdisplay_memfreedisplay_separationN)r   r   r   rS   c_display_openc_display_preclosec_display_closec_display_presizec_display_sizec_display_syncc_display_pagec_display_updatec_display_memallocc_display_memfreec_display_separationr   r   r   r   r   rm     s     rm   c                 C   s    t | |}|dkrt||S rR   )r"   gsapi_set_display_callbackr   )r+   callbackr'   r   r   r   set_display_callback  s   r   c               
   C   s   ddl m} m}m}m}m}m} ddlm} dd l	}g }dD ]S}	zH| |d|	 }
t
d||
d D ]1}||
|}z!| |
|}||dd }|| |j|rX||||f W q1 tyb   Y q1w ||
 W q tyq   Y qw |r~|  |d d S d S )Nr   )OpenKeyCloseKeyEnumKeyQueryValueExQueryInfoKeyHKEY_LOCAL_MACHINE)LooseVersion)zAFPL GhostscriptzAladdin GhostscriptzGPL GhostscriptzGNU GhostscriptzSoftware\%sGS_DLLr0   )winregr   r   r   r   r   r   distutils.versionr   osrangepathexistsappendWindowsErrorsort)r   r   r   r   r   r   r   r   dllskey_namek1numversionk2dll_pathr   r   r   __win32_finddll  s6    

r   win32z(Can not find Ghostscript DLL in registryzlibgs.sogsz(Can not find Ghostscript library (libgs))F)i__doc__
__author____copyright____licence____version__ctypessys_errorsMAX_STRING_LENGTHDISPLAY_VERSION_MAJORDISPLAY_VERSION_MINORDISPLAY_VERSION_MAJOR_V1DISPLAY_VERSION_MINOR_V1DISPLAY_COLORS_NATIVEDISPLAY_COLORS_GRAYDISPLAY_COLORS_RGBDISPLAY_COLORS_CMYKDISPLAY_COLORS_SEPARATIONDISPLAY_COLORS_MASKDISPLAY_ALPHA_NONEDISPLAY_ALPHA_FIRSTDISPLAY_ALPHA_LASTDISPLAY_UNUSED_FIRSTDISPLAY_UNUSED_LASTDISPLAY_ALPHA_MASKDISPLAY_DEPTH_1DISPLAY_DEPTH_2DISPLAY_DEPTH_4DISPLAY_DEPTH_8DISPLAY_DEPTH_12DISPLAY_DEPTH_16DISPLAY_DEPTH_MASKDISPLAY_BIGENDIANDISPLAY_LITTLEENDIANDISPLAY_ENDIAN_MASKDISPLAY_TOPFIRSTDISPLAY_BOTTOMFIRSTDISPLAY_FIRSTROW_MASKDISPLAY_NATIVE_555DISPLAY_NATIVE_565DISPLAY_555_MASKDISPLAY_ROW_ALIGN_DEFAULTDISPLAY_ROW_ALIGN_4DISPLAY_ROW_ALIGN_8DISPLAY_ROW_ALIGN_16DISPLAY_ROW_ALIGN_32DISPLAY_ROW_ALIGN_64DISPLAY_ROW_ALIGN_MASK	Structurer   c_void_pr(   r*   r   r   r   r,   r.   	CFUNCTYPErS   POINTERc_charr;   r<   rB   _wrap_stderrrI   rN   rP   rY   r^   r`   rd   rf   ri   rl   r|   r}   r~   c_uintr   c_ubyter   r   r   r   c_ulongr   r   r   c_ushortr   rm   r   r   platformr"   RuntimeErrorwindllLoadLibrarycdllOSErrorctypes.utilutilfind_libraryr   r   r   r   <module>   s   


	


		
!
	