
     dU                        d Z ddlZddlZddlmZ ddlmZmZmZm	Z	 ddl
Z
	 ddlmZmZmZ dZn# e$ r dZY nw xY w	 ddlZn# e$ r 	 ddlZn# e$ r dZY nw xY wY nw xY wg dZg d	d
dgdgddgdZdZdZdZ G d de          Z G d de          Z G d d          Z G d de          Z G d de          Z G d de          Z G d d e          ZdS )!z
    pygments.formatters.img
    ~~~~~~~~~~~~~~~~~~~~~~~

    Formatter for Pixmap output.

    :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    N)	Formatter)get_bool_optget_int_optget_list_optget_choice_opt)Image	ImageDraw	ImageFontTF)ImageFormatterGifImageFormatterJpgImageFormatterBmpImageFormatter) RomanBookNormalRegularMediumObliqueItalicBoldzBold ObliquezBold Italic)NORMALITALICBOLD
BOLDITALICzDejaVu Sans MonozCourier NewMenloc                       e Zd ZdZdS )PilNotAvailablez,When Python imaging library is not availableN__name__
__module____qualname____doc__     lC:\Users\ChattiNader\Documents\MyHotelMatch\api\dev\Lib\site-packages\pip/_vendor/pygments/formatters/img.pyr   r   5   s        6666r%   r   c                       e Zd ZdZdS )FontNotFoundz(When there are no usable fonts specifiedNr   r$   r%   r&   r(   r(   9   s        2222r%   r(   c                   R    e Zd ZdZddZd Zd Zd Zd Zdd	Z	d
 Z
d Zd Zd ZdS )FontManagerz>
    Manages a set of fonts: normal, italic, bold, etc...
       c                    || _         || _        i | _        d | _        t          j                            d          r$|st          | _         |                                  d S t          j                            d          r$|st          | _         | 
                                 d S |st          | _         |                                  d S )Nwindarwin)	font_name	font_sizefontsencodingsysplatform
startswithDEFAULT_FONT_NAME_WIN_create_winDEFAULT_FONT_NAME_MAC_create_macDEFAULT_FONT_NAME_NIX_create_nix)selfr/   r0   s      r&   __init__zFontManager.__init__B   s    ""
<""5)) 	 7!6\$$X.. 	 7!6 7!6r%   c                 |   t          j        d|d|dgt           j        d           }|                                \  }}|j        dk    rp|                                }|D ]W}|                    d          r|                                                                                    d          }|r|c S Xd S d S )Nzfc-listz:style=file)stdoutstderrr   s   Fontconfig warning::)	
subprocessPopenPIPEcommunicate
returncode
splitlinesr5   decodestrip)	r<   namestyleprocr@   _lineslinepaths	            r&   _get_nix_font_pathzFontManager._get_nix_font_pathT   s    TTT55,I6 R'1tE E E$$&&	?a%%''E    ??#9:: {{}}**,,22377  KKK 4  r%   c                    t           d         D ]C}|                     | j        |          }|$t          j        || j                  | j        d<    nDt          d| j        z            dD ]}t           |         D ]C}|                     | j        |          }|$t          j        || j                  | j        |<    n2D|dk    r| j        d         | j        |<   o| j        d         | j        |<   d S )Nr   No usable fonts named: "%s"r   r   r   r   r   )STYLESrR   r/   r
   truetyper0   r1   r(   )r<   rK   rQ   rL   	stylenames        r&   r;   zFontManager._create_nixb   s   8$ 	/ 	/D**4>4@@D'0'9$'O'O
8$   <#~ . / / /5 
	= 
	=E#E] 	= 	=	..t~yII#(1(:4(P(PDJu%E $ L(((,
6(:DJu%%(,
8(<DJu%
	= 
	=r%   c                     |                     |dz   |z                                                                             S )N )getrJ   lower)r<   font_maprK   rL   s       r&   _get_mac_font_pathzFontManager._get_mac_font_pathw   s5    ||TCZ%/6688>>@@AAAr%   c                    i }t           j                            t          j        d          d          ddfD ]5|                    fdt          j                  D                        6t          d         D ]D}|                     || j        |          }|$t          j
        || j                  | j        d<    nEt          d| j        z            dD ]}t          |         D ]D}|                     || j        |          }|$t          j
        || j                  | j        |<    n2E|d	k    r| j        d
         | j        |<   p| j        d         | j        |<   d S )NHOMEzLibrary/Fonts/z/Library/Fonts/z/System/Library/Fonts/c              3     K   | ]}|                                                     d           )t          j                            |          d                                          t          j                            |          fV  dS ))ttfttcr   N)r\   endswithosrQ   splitextjoin).0ffont_dirs     r&   	<genexpr>z*FontManager._create_mac.<locals>.<genexpr>~   s       7 77799%%n557!!!$$Q'--//h1J1JK7 7 7 7 7 7r%   r   rT   rU   r   r   )re   rQ   rg   getenvupdatelistdirrV   r^   r/   r
   rW   r0   r1   r(   )r<   r]   rK   rQ   rL   rX   rj   s         @r&   r9   zFontManager._create_macz   s   bi&7&79IJJ*,DF 	7 	7HOO 7 7 7 7H--7 7 7 7 7 7 7
 8$ 	/ 	/D**8T^TJJD'0'9$'O'O
8$   <#~ . / / /5 
	= 
	=E#E] 	= 	=	..xSS#(1(:4(P(PDJu%E $ L(((,
6(:DJu%%(,
8(<DJu%
	= 
	=r%   Fc                     dD ]B}|D ]=}	 ||od|z   |}t          j        ||          \  }}	|c c S # t          $ r Y :w xY wC|rt          d|d|d         d          d S )N)r   z (TrueType)rZ   zFont z (r   z) not found in registry)_winregQueryValueExOSErrorr(   )
r<   keybasenamestylesfailsuffixrL   valnamevalrN   s
             r&   _lookup_winzFontManager._lookup_win   s    ) 	 	F  *2(E4Gc%i4GPG$1#w??FCJJJJJ   H  :"l$,HHfQiii$9 : : :4s   &5
AAc                 @   d }t           j        dft           j        dft           j        dft           j        dfg}|D ]P}	 t          j        | }	 |                     || j        t          d         d          }t          j        || j	                  | j
        d<   dD ]}|                     || j        t          |                   }|r#t          j        || j	                  | j
        |<   N|dk    r| j
        d         | j
        |<   j| j
        d         | j
        |<   	 t          j        |            d S # t          $ r}|}Y d }~nd }~ww xY w	 t          j        |           n# t          j        |           w xY wA# t          $ r Y Nw xY w|r|t          d          )	Nz2Software\Microsoft\Windows NT\CurrentVersion\Fontsz/Software\Microsoft\Windows\CurrentVersion\Fontsr   TrU   r   r   z$Can't open Windows font registry key)rp   HKEY_CURRENT_USERHKEY_LOCAL_MACHINEOpenKeyrz   r/   rV   r
   rW   r0   r1   CloseKeyr(   rr   )r<   lookuperrorkeynameskeynamers   rQ   rL   errs           r&   r7   zFontManager._create_win   s   /1fg/1cd02gh02deh   	H 	HGow/*++CAQSWXXD+4+=dDN+S+SDJx(!A I I#//T^VE]SS I090B40X0XDJu--$4448Jv4F
5 1 148Jx4H
5 1 1 $S)))))) $ & & &"%KKKKKK&$S))))G$S)))))     "!!FGGGsN   E<CD2E<2
E<E>E!EE!E<!E77E<<
F
	F
c                 ,    |                      d          S )z)
        Get the character size.
        M)get_text_sizer<   s    r&   get_char_sizezFontManager.get_char_size   s     !!#&&&r%   c                     | j         d         }t          |d          r|                    |          dd         S |                    |          S )z4
        Get the text size (width, height).
        r   getbbox      )r1   hasattrr   getsize)r<   textfonts      r&   r   zFontManager.get_text_size   sO     z(#4## 	&<<%%ac**<<%%%r%   c                 z    |r|r| j         d         S |r| j         d         S |r| j         d         S | j         d         S )z>
        Get the font based on bold and italic flags.
        r   r   r   r   )r1   )r<   boldobliques      r&   get_fontzFontManager.get_font   sW      	(G 	(:l++ 	(:f%% 	(:h'':h''r%   N)r+   )F)r    r!   r"   r#   r=   rR   r;   r^   r9   rz   r7   r   r   r   r$   r%   r&   r*   r*   =   s            $  = = =*B B B= = =:   %H %H %HN' ' '& & &( ( ( ( (r%   r*   c                       e Zd ZdZdZg dZdgZdZdZd Z	d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S )r   a	  
    Create a PNG image from source code. This uses the Python Imaging Library to
    generate a pixmap from the source code.

    .. versionadded:: 0.10

    Additional options accepted:

    `image_format`
        An image format to output to that is recognised by PIL, these include:

        * "PNG" (default)
        * "JPEG"
        * "BMP"
        * "GIF"

    `line_pad`
        The extra spacing (in pixels) between each line of text.

        Default: 2

    `font_name`
        The font name to be used as the base font from which others, such as
        bold and italic fonts will be generated.  This really should be a
        monospace font to look sane.

        Default: "Courier New" on Windows, "Menlo" on Mac OS, and
                 "DejaVu Sans Mono" on \*nix

    `font_size`
        The font size in points to be used.

        Default: 14

    `image_pad`
        The padding, in pixels to be used at each edge of the resulting image.

        Default: 10

    `line_numbers`
        Whether line numbers should be shown: True/False

        Default: True

    `line_number_start`
        The line number of the first line.

        Default: 1

    `line_number_step`
        The step used when printing line numbers.

        Default: 1

    `line_number_bg`
        The background colour (in "#123456" format) of the line number bar, or
        None to use the style background color.

        Default: "#eed"

    `line_number_fg`
        The text color of the line numbers (in "#123456"-like format).

        Default: "#886"

    `line_number_chars`
        The number of columns of line numbers allowable in the line number
        margin.

        Default: 2

    `line_number_bold`
        Whether line numbers will be bold: True/False

        Default: False

    `line_number_italic`
        Whether line numbers will be italicized: True/False

        Default: False

    `line_number_separator`
        Whether a line will be drawn between the line number area and the
        source code area: True/False

        Default: True

    `line_number_pad`
        The horizontal padding (in pixels) between the line number margin, and
        the source code area.

        Default: 6

    `hl_lines`
        Specify a list of lines to be highlighted.

        .. versionadded:: 1.2

        Default: empty list

    `hl_color`
        Specify the color for highlighting lines.

        .. versionadded:: 1.2

        Default: highlight color of the selected style
    img)r   IMGpngz*.pngFr   c                 f   t           st          d          t          j        | fi | d| _        t          | j                  | _        | j        j        d| _        n| j        j        | _        t          |dg d| j
        d          | _        t          |d	d
          | _        t          |dd          | _        t          |dd          }t          |                    dd          |          | _        | j                                        \  | _        | _        |                    dd          | _        |                    dd          | _        t          |dd          | _        t1          |dd          | _        t1          |dd          | _        t          |dd          | _        t1          |dd          | _        t1          |dd          | _        t          |dd          | _        t          |dd          | _        | j        r | j        | j        z  | j        dz  z   | _         nd | _         g | _!        tE          |d!g           }|D ]:}	 | j!        #                    tI          |                     +# tJ          $ r Y 7w xY w|                    d"| j        j&                  pd#| _'        g | _(        dS )$zE
        See the class docstring for explanation of options.
        z5Python Imaging Library is required for this formatterlatin1Nz#fffimage_format)r   jpeggifbmpT)normcase	image_pad
   line_padr   r0   r+   r/   r   line_number_fgz#886line_number_bgz#eedline_number_charsline_number_boldFline_number_italicline_number_pad   line_numbersline_number_separatorline_number_step   line_number_startr   hl_lineshl_colorz#f90))pil_availabler   r   r=   r2   dictrL   ru   background_colorr   default_image_formatr   r   r   r   r*   r[   r1   r   fontwfonthr   r   r   r   r   r   r   r   r   r   r   line_number_widthr   r   appendint
ValueErrorhighlight_colorr   	drawables)r<   optionsfontsizehl_lines_strrP   s        r&   r=   zImageFormatter.__init__a  s     	I!GI I I4++7+++ 4:&&:&.$*D!!$(J$?D!*^%B%B%B%6 6 6 %Wk2>>#GZ;;wR88 ["!=!=xHH
!%!9!9!;!;
DJ%kk*:FCC%kk*:FCC!,W-@!"E "E ,W-?!H !H".w/CU#L #L*74EqII(.$GG%1'2I4&Q &Q" +G5G K K!,W6I1!M!M 	'&*j43I&I&*&:Q&>'?D"" &'D"#GZ<<  	 	D$$SYY////   J$(J$>@ @ JCI 	s   'I33
J ?J r   c                      t          d          )NzWThe -S option is meaningless for the image formatter. Use -O style=<stylename> instead.)NotImplementedError)r<   args     r&   get_style_defszImageFormatter.get_style_defs  s    ! #Q R R 	Rr%   c                      | j         | j        z   S )z+
        Get the height of a line.
        )r   r   r   s    r&   _get_line_heightzImageFormatter._get_line_height  s     zDM))r%   c                 @    ||                                  z  | j        z   S )z8
        Get the Y coordinate of a line number.
        )r   r   r<   linenos     r&   _get_line_yzImageFormatter._get_line_y  s"     --///$.@@r%   c                     | j         S )z/
        Get the width of a character.
        )r   r   s    r&   _get_char_widthzImageFormatter._get_char_width  s     zr%   c                 &    || j         z   | j        z   S )z?
        Get the X coordinate of a character position.
        )r   r   )r<   
linelengths     r&   _get_char_xzImageFormatter._get_char_x  s     DN*T-CCCr%   c                 V    |                      |          |                     |          fS )zL
        Get the actual position for a character and line position.
        )r   r   )r<   r   r   s      r&   _get_text_poszImageFormatter._get_text_pos  s+     
++T-=-=f-E-EEEr%   c                 :    | j         |                     |          fS )zI
        Get the actual position for the start of a line number.
        )r   r   r   s     r&   _get_linenumber_posz"ImageFormatter._get_linenumber_pos  s      0 0 8 899r%   c                 2    |d         d|d         z   }nd}|S )zE
        Get the correct color for the token from the style.
        colorN#z#000r$   )r<   rL   fills      r&   _get_text_colorzImageFormatter._get_text_color  s(     >%w'DDDr%   c                 2    |d         d|d         z   }nd}|S )zP
        Get the correct background color for the token from the style.
        bgcolorNr   r$   )r<   rL   bg_colors      r&   _get_text_bg_colorz!ImageFormatter._get_text_bg_color  s*     'U9--HHHr%   c                 P    | j                             |d         |d                   S )z5
        Get the correct font for the style.
        r   italic)r1   r   )r<   rL   s     r&   _get_style_fontzImageFormatter._get_style_font  s$     z""5=%/BBBr%   c                 |    |                      |          | j        z   |                     |dz             | j        z   fS )z.
        Get the required image size.
        r   )r   r   r   )r<   maxlinelength	maxlinenos      r&   _get_image_sizezImageFormatter._get_image_size  sD       //$.@  Q//$.@B 	Br%   c                     |                      |                     |          t          |                              | j                  | j                            | j        | j                  | j	        d           dS )zA
        Remember a line number drawable to paint later.
        Nr   text_fgtext_bg)

_draw_textr   strrjustr   r1   r   r   r   r   )r<   posnor   s      r&   _draw_linenumberzImageFormatter._draw_linenumber  s}     	$$U++KKd455$$T%:%)%<> >' 	 	
 	
 	
 	
 	
r%   c                 D    | j                             |||||f           dS )zB
        Remember a single drawable tuple to paint later.
        N)r   r   )r<   posr   r   r   r   s         r&   r   zImageFormatter._draw_text  s+     	sD$ABBBBBr%   c                    dx}x}}dx}}|D ][\  }}|| j         vr|j        }|| j         v| j         |         }	|                    d          }|                    d          }
t	          |
          D ]\  }}|                    d          }|r|                     |                     ||          ||                     |	          | 	                    |	          | 
                    |	                     | j                            |          \  }}||z  }t          ||          }|t          |          z  }t          ||          }|                    d          r	d}d}|dz  }]|| _        || _        || _        dS )z9
        Create drawables for the token content.
        r   r   T
r   r   N)ru   parent
expandtabsrH   	enumeraterstripr   r   r   r   r   r1   r   maxlenrd   r   	maxcharnor   )r<   tokensourcer   charnor   r   r   ttypevaluerL   rO   irP   temp
temp_widthrN   s                   r&   _create_drawablesz ImageFormatter._create_drawables  s    '('')%&&
' 	  	 LE5t{** t{**K&E $$Q''E$$T**E$U++    4{{4(( 7OO**:v>>#33E::"&"6"6u"="="&"9"9%"@"@ $    %)J$<$<T$B$BMJ*,J$'z$B$BMc$ii'F #Iv 6 6I==&&  !"JFaKF' ( +"r%   c                     | j         sdS t          | j                  D ]0}|| j        z   }|| j        z  dk    r|                     ||           1dS )z8
        Create drawables for the line numbers.
        Nr   )r   ranger   r   r   r   )r<   pns      r&   _draw_line_numbersz!ImageFormatter._draw_line_numbers  sn       	Ft~&& 	, 	,AD**AD))a//%%a+++	, 	,r%   c                 .   | j         sdS | j        dS t          j        |          }|j        d         }| j        | j        z   | j        z
  }|                    d||fg| j	                   | j
        r"|                    |df||fg| j                   ~dS )z@
        Paint the line number background on the image.
        N)r   r   r   r   )r   r   r	   Drawsizer   r   r   	rectangler   r   rP   )r<   imdrawrecthrectws        r&   _paint_line_number_bgz$ImageFormatter._paint_line_number_bg(  s       	F&F~b!!!77$:NN/ / 	 	1 	1 	1% 	NIIqzE5>29LIMMMDDr%   c           	         |                      |           |                                  t          j        d|                     | j        | j                  | j                  }|                     |           t          j
        |          }| j        r| j        | j        z   | j        z
  dz   }|                                 }|j        d         |z
  }| j        D ]B}|                     |dz
            }	|                    ||	f||z   |	|z   fg| j                   C| j        D ]\  }
}}}}|r\|                    ||          }|                    |
d         |
d         |
d         |d         z   |
d         |d         z   g|           |                    |
|||           |                    || j                                                   dS )a   
        Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
        tuples and write it into ``outfile``.

        This implementation calculates where it should draw each token on the
        pixmap, then calculates the required pixmap size and draws the items.
        RGBr   r   r  )r   r   )r   r   N)r   r  r   newr   r   r   r   r  r	   r  r   r   r   r   r   r  r   r	  r   r   textsizer   saver   upper)r<   r   outfiler
  r  xr  r  
linenumberyr   r   r   r   r   	text_sizes                   r&   formatzImageFormatter.format9  s    	{+++!!!Y  !3T^DD!
 

 	""2&&&~b!!= 	3!77$:NNQRRA))++EGAJNE"m 3 3
$$Z!^44AUAI(>?$(M  3 3 3 326. 	; 	;.Cgw m MMu4M@@	AAA10Es1vPYZ[P\G\]dklllIIc5t'I::::
*002233333r%   N)r   )r    r!   r"   r#   rK   aliases	filenamesunicodeoutputr   r=   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r$   r%   r&   r   r      sp       j jZ D###G	IM 6 6 6pR R R R* * *A A A  D D DF F F: : :    C C CB B B
 
 
C C C&  &  & P	, 	, 	,  "4 4 4 4 4r%   r   c                   &    e Zd ZdZdZdgZdgZdZdS )r   z
    Create a GIF image from source code. This uses the Python Imaging Library to
    generate a pixmap from the source code.

    .. versionadded:: 1.0
    img_gifr   z*.gifNr    r!   r"   r#   rK   r  r  r   r$   r%   r&   r   r   ^  s5          DgG	I r%   r   c                   (    e Zd ZdZdZddgZdgZdZdS )r   z
    Create a JPEG image from source code. This uses the Python Imaging Library to
    generate a pixmap from the source code.

    .. versionadded:: 1.0
    img_jpgjpgr   z*.jpgNr   r$   r%   r&   r   r   l  s7          DfoG	I!r%   r   c                   (    e Zd ZdZdZddgZdgZdZdS )r   z
    Create a bitmap image from source code. This uses the Python Imaging Library to
    generate a pixmap from the source code.

    .. versionadded:: 1.0
    img_bmpr   bitmapz*.bmpNr   r$   r%   r&   r   r   z  s8          DhG	I r%   r   ) r#   re   r3   pip._vendor.pygments.formatterr   pip._vendor.pygments.utilr   r   r   r   rC   PILr   r	   r
   r   ImportErrorrp   winreg__all__rV   r:   r6   r8   r   	Exceptionr(   r*   r   r   r   r   r$   r%   r&   <module>r.     s    
			 



 4 4 4 4 4 4               //////////MM   MMMNNNN                 GFFh'(!=1	
 
 + %  7 7 7 7 7k 7 7 73 3 3 3 39 3 3 3k( k( k( k( k( k( k( k(\m4 m4 m4 m4 m4Y m4 m4 m4f! ! ! ! ! ! ! !" " " " " " " "! ! ! ! ! ! ! ! ! !sA   / 99A AAAAAAAA