
    ,h[                        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	 ddlZ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y# e$ r dZY sw xY w# e$ r 	 ddlZn# e$ r dZY nw xY wY w xY w)!z
    pygments.formatters.img
    ~~~~~~~~~~~~~~~~~~~~~~~

    Formatter for Pixmap output.

    :copyright: Copyright 2006-2025 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y)PilNotAvailablez,When Python imaging library is not availableN__name__
__module____qualname____doc__     Y/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pygments/formatters/img.pyr   r   4   s    6r%   r   c                       e Zd ZdZy)FontNotFoundz(When there are no usable fonts specifiedNr   r$   r%   r&   r(   r(   8   s    2r%   r(   c                   V    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 Zy)FontManagerz>
    Manages a set of fonts: normal, italic, bold, etc...
    c                 R   || _         || _        i | _        d | _        d| _        t        |d      st        j                  j                  |      rBt        j                  || j                        }d| _        t        D ]  }|| j                  |<    y t        j                  j                  d      r|st        | _         | j!                          y t        j                  j                  d      r|st"        | _         | j%                          y |st&        | _         | j)                          y )NFreadTwindarwin)	font_name	font_sizefontsencodingvariablehasattrospathisfiler
   truetypeSTYLESsysplatform
startswithDEFAULT_FONT_NAME_WIN_create_winDEFAULT_FONT_NAME_MAC_create_macDEFAULT_FONT_NAME_NIX_create_nix)selfr/   r0   fontstyles        r&   __init__zFontManager.__init__A   s    ""
9f%	)B%%i@D DM )$(

5!) <<""5)!6\\$$X.!6!6r%   c                 ^   t        j                  d| d| dgt         j                  d       }|j                         \  }}|j                  dk(  r]|j                         }|D ]G  }|j                  d      r|j                         j                         j                  d      }|sE|c S  y y )Nzfc-listz:style=file)stdoutstderrr   s   Fontconfig warning::)	
subprocessPopenPIPEcommunicate
returncode
splitlinesr<   decodestrip)	rC   namerE   procrI   _linesliner6   s	            r&   _get_nix_font_pathzFontManager._get_nix_font_path\   s    tfGE7,CV L'1tE$$&	??a%%'E  ??#9:{{}**,2237K    r%   c                 ,   t         d   D ]O  }| j                  | j                  |      }|"t        j                  || j
                        | j                  d<    n t        d| j                   d      dD ]  }t         |   D ]O  }| j                  | j                  |      }|"t        j                  || j
                        | j                  |<    ] |dk(  r| j                  d   | j                  |<   | j                  d   | j                  |<    y )Nr   No usable fonts named: ""r   r   r   r   r   )r9   rY   r/   r
   r8   r0   r1   r(   )rC   rT   r6   rE   	stylenames        r&   rB   zFontManager._create_nixj   s
   8$ 	MD**4>>4@D'0'9'9$'O

8$		M !9$..9IKLL5 
	=E#E] 	=	..t~~yI#(1(:(:4(PDJJu%		= L((,

6(:DJJu%(,

8(<DJJu%
	=r%   c                 h    |j                  |dz   |z   j                         j                               S )N )getrS   lower)rC   font_maprT   rE   s       r&   _get_mac_font_pathzFontManager._get_mac_font_path~   s,    ||TCZ%/668>>@AAr%   c                    i }t         j                  j                  t        j                  d      d      ddfD ]/  |j	                  fdt        j
                        D               1 t        d   D ]P  }| j                  || j                  |      }|#t        j                  || j                        | j                  d<    n t        d| j                   d      d	D ]  }t        |   D ]P  }| j                  || j                  |      }|#t        j                  || j                        | j                  |<    ^ |d
k(  r| j                  d   | j                  |<   | j                  d   | j                  |<    y )NHOMEzLibrary/Fonts/z/Library/Fonts/z/System/Library/Fonts/c              3     K   | ]~  \  }}}|D ]s  }|j                         j                  d       rRt        j                  j	                  |      d   j                         t        j                  j                  |      f u  yw))ttfttcr   N)rb   endswithr5   r6   splitextjoin).0rV   filesffont_dirs       r&   	<genexpr>z*FontManager._create_mac.<locals>.<genexpr>   sy      7Aq%7 779%%n5 !!!$Q'--/h1JK7K7s   BBr   r[   r\   r]   r   r   )r5   r6   rl   getenvupdatewalkr9   rd   r/   r
   r8   r0   r1   r(   )rC   rc   rT   r6   rE   r^   rp   s         @r&   r@   zFontManager._create_mac   sl   bii&79IJ*,DF 	7HOO 7#%778#47 7	7 8$ 	MD**8T^^TJD'0'9'9$'O

8$		M !9$..9IKLL5 
	=E#E] 	=	..xS#(1(:(:4(PDJJu%		= L((,

6(:DJJu%(,

8(<DJJu%
	=r%   c                     dD ]B  }|D ];  }	 dj                  ||xr d|z   |      }t        j                  ||      \  }}	|c c S  D |rt	        d| d|d    d      y # t        $ r Y cw xY w)N)r   z (TrueType)z{}{}{}r`   zFont z (r   z) not found in registry)format_winregQueryValueExOSErrorr(   )
rC   keybasenamestylesfailsuffixrE   valnamevalrV   s
             r&   _lookup_winzFontManager._lookup_win   s    ) 	F &ooh8K#e)VTG$11#w?FCJ		 "U8*BvaykAX#YZZ  s   4A  	A,+A,c                    d }t         j                  dft         j                  dft         j                  dft         j                  dfg}|D ]  }	 t        j                  | }	 | j	                  || j
                  t        d   d      }t        j                  || j                        | j                  d<   dD ]  }| j	                  || j
                  t        |         }|r.t        j                  || j                        | j                  |<   W|dk(  r| j                  d   | j                  |<   y| j                  d   | j                  |<    	 t        j                  |        y  |r|t        d      # t        $ r}|}Y d }~nd }~ww xY w	 t        j                  |       n# t        j                  |       w xY wv# t        $ r Y w xY w)	Nz2Software\Microsoft\Windows NT\CurrentVersion\Fontsz/Software\Microsoft\Windows\CurrentVersion\Fontsr   Tr]   r   r   z$Can't open Windows font registry key)rw   HKEY_CURRENT_USERHKEY_LOCAL_MACHINEOpenKeyr   r/   r9   r
   r8   r0   r1   CloseKeyr(   ry   )rC   lookuperrorkeynameskeynamerz   r6   rE   errs           r&   r>   zFontManager._create_win   s   //1fg//1cd002gh002deh   	HGoow/*++CAQSWXD+4+=+=dDNN+SDJJx(!A I#//T^^VE]S090B0B40XDJJu-$448JJv4F

5 148JJx4H

5 1I  $$S)'	H: !!FGG $ &"%K&$$S)G$$S)) sO   G#C+E6G6	F?FF%FF%G%F<<G	GGc                 $    | j                  d      S )z)
        Get the character size.
        M)get_text_sizerC   s    r&   get_char_sizezFontManager.get_char_size   s     !!#&&r%   c                     | j                   d   }t        |d      r|j                  |      dd S |j                  |      S )z4
        Get the text size (width, height).
        r   getbbox      )r1   r4   r   getsize)rC   textrD   s      r&   r   zFontManager.get_text_size   sA     zz(#4#<<%a**<<%%r%   c                 r   |r.|r,| j                   r| j                  d      S | j                  d   S |r,| j                   r| j                  d      S | j                  d   S |r,| j                   r| j                  d      S | j                  d   S | j                   r| j                  d      S | j                  d   S )z>
        Get the font based on bold and italic flags.
        r   r   r   r   )r3   	get_styler1   )rC   boldobliques      r&   get_fontzFontManager.get_font   s     G}}~~l33::l++}}~~f--::f%%}}~~h//::h''}}~~h//::h''r%   c                     | j                   |   }t        |   D ]  }	 |j                  |       |c S  |S # t        $ r Y 't        $ r |cY c S w xY w)z}
        Get the specified style of the font if it is a variable font.
        If not found, return the normal font.
        )r1   r9   set_variation_by_name
ValueErrorry   )rC   rE   rD   
style_names       r&   r   zFontManager.get_style   se    
 zz%  - 	J**:6	    s   5	A 
AAN)   )F)r    r!   r"   r#   rF   rY   rB   rd   r@   r   r>   r   r   r   r   r$   r%   r&   r*   r*   <   sA    6=(B=:%HN'&(2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y)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.
        If a filename or a file-like object is specified, the user must
        provide different styles of the font.

        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                 D   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        |j!                  dd      |      | _        | j"                  j%                         \  | _        | _        |j!                  dd      | _        |j!                  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      | _        | j8                  r/| j&                  | j.                  z  | j6                  dz  z   | _         nd | _         g | _!        tE        |d!g       }|D ]'  }	 | jB                  jG                  tI        |             ) |j!                  d"| j                  jL                        xs d#| _'        g | _(        y# tJ        $ r Y lw xY w)$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   rF   r2   dictrE   r|   background_colorr   default_image_formatr   r   r   r   r*   ra   r1   r   fontwfonthr   r   r   r   r   r   r   r   r   r   r   line_number_widthr   r   appendintr   highlight_colorr   	drawables)rC   optionsfontsizehl_lines_strrX   s        r&   rF   zImageFormatter.__init__  sy    !GI I4+7+ 4::&::&&.$*D!$(JJ$?$?D!*^%B%%6 %Wk2>#GZ;wR8 ["!=xH
!%!9!9!;
DJ%kk*:FC%kk*:FC!,W-@!"E ,W-?!H".w/CU#L*74EqI(.$G%1'2I4&Q" +G5G K!,W6I1!M&*jj43I3I&I&*&:&:Q&>'?D" &'D"#GZ<  	D$$SY/	
  J$(JJ$>$>@ JCI 		  s   6$J	JJc                     t        d      )NzWThe -S option is meaningless for the image formatter. Use -O style=<stylename> instead.)NotImplementedError)rC   args     r&   get_style_defszImageFormatter.get_style_defs  s    ! #Q R 	Rr%   c                 4    | j                   | j                  z   S )z+
        Get the height of a line.
        )r   r   r   s    r&   _get_line_heightzImageFormatter._get_line_height  s     zzDMM))r%   c                 B    || j                         z  | j                  z   S )z8
        Get the Y coordinate of a line number.
        )r   r   rC   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     zzr%   c                 :    || j                   z   | j                  z   S )z?
        Get the X coordinate of a character position.
        )r   r   )rC   
linelengths     r&   _get_char_xzImageFormatter._get_char_x  s     DNN*T-C-CCCr%   c                 F    | j                  |      | j                  |      fS )zL
        Get the actual position for a character and line position.
        )r   r   )rC   r   r   s      r&   _get_text_poszImageFormatter._get_text_pos  s%     
+T-=-=f-EEEr%   c                 <    | j                   | 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99r%   c                 (    |d   
d|d   z   }|S d}|S )zE
        Get the correct color for the token from the style.
        color#z#000r$   )rC   rE   fills      r&   _get_text_colorzImageFormatter._get_text_color  s/     >%w'D  Dr%   c                 (    |d   
d|d   z   }|S d}|S )zP
        Get the correct background color for the token from the style.
        bgcolorNr   r$   )rC   rE   bg_colors      r&   _get_text_bg_colorz!ImageFormatter._get_text_bg_color  s1     'U9--H  Hr%   c                 F    | j                   j                  |d   |d         S )z5
        Get the correct font for the style.
        r   italic)r1   r   )rC   rE   s     r&   _get_style_fontzImageFormatter._get_style_font  s#     zz""5=%/BBr%   c                     | j                  |      | j                  z   | j                  |dz         | j                  z   fS )z.
        Get the required image size.
        r   )r   r   r   )rC   maxlinelength	maxlinenos      r&   _get_image_sizezImageFormatter._get_image_size   sB       /$..@  Q/$..@B 	Br%   c                    | j                  | j                  |      t        |      j                  | j                        | j
                  j                  | j                  | j                        | j                  d       y)zA
        Remember a line number drawable to paint later.
        NrD   text_fgtext_bg)

_draw_textr   strrjustr   r1   r   r   r   r   )rC   posnor   s      r&   _draw_linenumberzImageFormatter._draw_linenumber  sj     	$$U+Kd445$$T%:%:%)%<%<>'' 	 	
r%   c                 D    | j                   j                  |||||f       y)zB
        Remember a single drawable tuple to paint later.
        N)r   r   )rC   posr   rD   r   r   s         r&   r   zImageFormatter._draw_text  s!     	sD$ABr%   c                    dx}x}}dx}}|D ]=  \  }}|| j                   vr|j                  }|| j                   vr| j                   |   }	|j                  d      }|j                  d      }
t	        |
      D ]  \  }}|j                  d      }|r| j                  | j                  ||      || j                  |	      | j                  |	      | j                  |	             | j                  j                  |      \  }}||z  }t        ||      }|t        |      z  }t        ||      }|j                  d      sd}d}|dz  } @ || _        || _        || _        y)z9
        Create drawables for the token content.
        r   r   T
r   r   N)r|   parent
expandtabsrQ   	enumeraterstripr   r   r   r   r   r1   r   maxlenrj   r   	maxcharnor   )rC   tokensourcer   charnor   r   r   ttypevaluerE   rW   irX   temp
temp_widthrV   s                   r&   _create_drawablesz ImageFormatter._create_drawables  s{    '('')%&&
' 	 LE5t{{* t{{*KK&E $$Q'E$$T*E$U+  4{{4(OO**:v>#33E:"&"6"6u"="&"9"9%"@ $  %)JJ$<$<T$BMJ*,J$'z$BMc$i'F #Iv 6I==&!"JFaKF' 	 < +"r%   c                     | j                   syt        | j                        D ]6  }|| j                  z   }|| j                  z  dk(  s%| j                  ||       8 y)z8
        Create drawables for the line numbers.
        Nr   )r   ranger   r   r   r   )rC   pns      r&   _draw_line_numbersz!ImageFormatter._draw_line_numbersB  s[       t~~& 	,AD***AD)))a/%%a+	,r%   c                 n   | j                   sy| j                  yt        j                  |      }|j                  d   }| j
                  | j                  z   | j                  z
  }|j                  d||fg| j                         | j                  r#|j                  |df||fg| j                         ~y)z@
        Paint the line number background on the image.
        N)r   r   r   r   )r   r   r	   Drawsizer   r   r   	rectangler   r   rX   )rC   imdrawrecthrectws        r&   _paint_line_number_bgz$ImageFormatter._paint_line_number_bgM  s       &~~b!!7!77$:N:NN/ // 	 	1%%IIqzE5>29L9LIMr%   c           	         | j                  |       | j                          t        j                  d| j	                  | j
                  | j                        | j                        }| j                  |       t        j                  |      }| j                  r| j                  | j                  z   | j                  z
  dz   }| j                         }|j                   d   |z
  }| j                  D ]?  }| j#                  |dz
        }	|j%                  ||	f||z   |	|z   fg| j&                         A | j(                  D ]  \  }
}}}}|rct+        |d      r|j-                  ||      }n|j/                  |      dd }|j%                  |
d   |
d   |
d   |d   z   |
d   |d   z   g|       |j1                  |
|||	        |j3                  || j4                  j7                                y)
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  textsize)r   rD   r   N)rD   r   )r  r  r   newr   r   r   r   r  r	   r  r   r   r   r   r   r  r   r  r   r   r4   r  r   r   saver   upper)rC   r  outfiler  r  xr  r  
linenumberyr   r  rD   r   r   	text_sizes                   r&   rv   zImageFormatter.format^  s    	{+!YY  !3!3T^^D!!

 	""2&~~b!==!7!77$:N:NNQRRA))+EGGAJNE"mm 3
$$Z!^4AUAI(>?$(MM  33 37.. 	;.Cgw4, $5t DI $U 3AB 7IAAA10Es1vPYZ[P\G\]dklIIc5t'I:	; 	**0023r%   N)r   )r    r!   r"   r#   rT   aliases	filenamesunicodeoutputr   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  rv   r$   r%   r&   r   r     s    l^ D#G	IM 6pR*ADF:CB
C& P	,"#4r%   r   c                   $    e Zd ZdZdZdgZdgZdZy)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#   rT   r$  r%  r   r$   r%   r&   r   r     s"     DgG	I r%   r   c                   &    e Zd ZdZdZddgZdgZdZy)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     s$     DfoG	I!r%   r   c                   &    e Zd ZdZdZddgZdgZdZy)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     s%     DhG	I r%   r   ) r#   r5   r:   pygments.formatterr   pygments.utilr   r   r   r   rL   PILr   r	   r
   r   ImportErrorrw   winreg__all__r9   rA   r=   r?   r   	Exceptionr(   r*   r   r   r   r   r$   r%   r&   <module>r7     s   
 
 (  //M  Gh'(!=1	
 + %  7k 739 3O Ods4Y s4r! !" "! !Y  M
    sF   B B% B"!B"%C +B0/C 0B:7C 9B::C ?C 