
    $fU                        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-2023 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__     ^/var/www/html/fontify/venv/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/img.pyr   r   5   s    6r%   r   c                       e Zd ZdZy)FontNotFoundz(When there are no usable fonts specifiedNr   r$   r%   r&   r(   r(   9   s    2r%   r(   c                   P    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y)FontManagerz>
    Manages a set of fonts: normal, italic, bold, etc...
    c                 j   || _         || _        i | _        d | _        t        j
                  j                  d      r|st        | _         | j                          y t        j
                  j                  d      r|st        | _         | j                          y |st        | _         | j                          y )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.   r/   s      r&   __init__zFontManager.__init__B   s    ""
<<""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
splitlinesr4   decodestrip)	r;   namestyleprocr?   _lineslinepaths	            r&   _get_nix_font_pathzFontManager._get_nix_font_pathT   s    T5,I6 R'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                  z        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: "%s"r   r   r   r   r   )STYLESrQ   r.   r
   truetyper/   r0   r(   )r;   rJ   rP   rK   	stylenames        r&   r:   zFontManager._create_nixb   s
   8$ 	/D**4>>4@D'0'9'9$'O

8$		/ <#~~ . / /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 )getrI   lower)r;   font_maprJ   rK   s       r&   _get_mac_font_pathzFontManager._get_mac_font_pathw   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                  z        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   | ]s  }|j                         j                  d       rRt        j                  j	                  |      d   j                         t        j                  j                  |      f u yw))ttfttcr   N)r[   endswithosrP   splitextjoin).0ffont_dirs     r&   	<genexpr>z*FontManager._create_mac.<locals>.<genexpr>~   s^      7779%%n5 !!!$Q'--/h1JK7s   A9A<r   rS   rT   r   r   )rd   rP   rf   getenvupdatelistdirrU   r]   r.   r
   rV   r/   r0   r(   )r;   r\   rJ   rP   rK   rW   ri   s         @r&   r8   zFontManager._create_macz   sl   bii&79IJ*,DF 	7HOO 7H-7 7	7 8$ 	/D**8T^^TJD'0'9'9$'O

8$		/ <#~~ . / /5 
	=E#E] 	=	..xS#(1(:(:4(PDJJu%		= L((,

6(:DJJu%(,

8(<DJJu%
	=r%   c                     dD ]7  }|D ]0  }	 ||xr d|z   |}t        j                  ||      \  }}	|c c S  9 |rt        d|d|d   d      y # t        $ r Y Xw xY w)N)r   z (TrueType)rY   zFont z (r   z) not found in registry)_winregQueryValueExOSErrorr(   )
r;   keybasenamestylesfailsuffixrK   valnamevalrM   s
             r&   _lookup_winzFontManager._lookup_win   s    ) 	F *2E4Gc%i4GPG$11#w?FCJ		 "$,fQi$9 : :  s   )A	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   TrT   r   r   z$Can't open Windows font registry key)ro   HKEY_CURRENT_USERHKEY_LOCAL_MACHINEOpenKeyry   r.   rU   r
   rV   r/   r0   CloseKeyr(   rq   )r;   lookuperrorkeynameskeynamerr   rP   rK   errs           r&   r6   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r;   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      )r0   hasattrr   getsize)r;   textfonts      r&   r   zFontManager.get_text_size   sA     zz(#4#<<%a**<<%%r%   c                     |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   )r0   )r;   boldobliques      r&   get_fontzFontManager.get_font   sK     G::l++::f%%::h''::h''r%   N)   )F)r    r!   r"   r#   r<   rQ   r:   r]   r8   ry   r6   r   r   r   r$   r%   r&   r*   r*   =   s<    $=*B=:%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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.

        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   r/   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<   r1   dictrK   rt   background_colorr   default_image_formatr   r   r   r   r*   rZ   r0   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_strrO   s        r&   r<   zImageFormatter.__init__a  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)r;   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   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     zz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     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   )r;   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$   )r;   rK   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$   )r;   rK   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)r0   r   )r;   rK   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   )r;   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r   text_fgtext_bg)

_draw_textr   strrjustr   r0   r   r   r   r   )r;   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   )r;   posr   r   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)rt   parent
expandtabsrG   	enumeraterstripr   r   r   r   r   r0   r   maxlenrc   r   	maxcharnor   )r;   tokensourcer   charnor   r   r   ttypevaluerK   rN   irO   temp
temp_widthrM   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   )r;   pns      r&   _draw_line_numbersz!ImageFormatter._draw_line_numbers  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   rO   )r;   imdrawrecthrectws        r&   _paint_line_number_bgz$ImageFormatter._paint_line_number_bg(  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 ]a  \  }
}}}}|rB|j+                  ||      }|j%                  |
d   |
d   |
d   |d   z   |
d   |d   z   g|       |j-                  |
|||       c |j/                  || j0                  j3                                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  )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    	{+!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 MMu4M@	AAA10Es1vPYZ[P\G\]dklIIc5t'I:		;
 	**0023r%   N)r   )r    r!   r"   r#   rJ   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      s    jZ 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#   rJ   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   l  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   z  s%     DhG	I r%   r   ) r#   rd   r2   pip._vendor.pygments.formatterr   pip._vendor.pygments.utilr   r   r   r   rB   PILr   r	   r
   r   ImportErrorro   winreg__all__rU   r9   r5   r7   r   	Exceptionr(   r*   r   r   r   r   r$   r%   r&   <module>r.     s   
 
 4  //M  Gh'(!=1	
 + %  7k 739 3k( k(\m4Y m4f! !" "! !E  M
    sF   B B% B"!B"%C +B0/C 0B:7C 9B::C ?C 