https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/pygments/formatters/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/pygments/formatters/__pycache__/img.cpython-310.pyc
o

���a#U�@sZdZddlZddlZddlmZddlmZmZmZm	Z	ddl
Z
zddlmZm
Z
mZdZWney9dZYnwzddlZWney[zddlZWneyXdZYnwYnwgd�Zgd	�d
dgdgd
dgd�ZdZdZdZGdd�de�ZGdd�de�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�ZdS)!z�
    pygments.formatters.img
    ~~~~~~~~~~~~~~~~~~~~~~~

    Formatter for Pixmap output.

    :copyright: Copyright 2006-2021 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 ObliquezBold Italic)�NORMAL�ITALIC�BOLD�
BOLDITALICzDejaVu Sans MonozCourier New�Menloc@�eZdZdZdS)�PilNotAvailablez,When Python imaging library is not availableN��__name__�
__module__�__qualname__�__doc__�r#r#�9/usr/lib/python3/dist-packages/pygments/formatters/img.pyr5�rc@r)�FontNotFoundz(When there are no usable fonts specifiedNrr#r#r#r$r&9r%r&c@sdeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zddd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�FontManagerz>
    Manages a set of fonts: normal, italic, bold, etc...
    �cCsr||_||_i|_d|_tj�d�r|st|_|��dStj�d�r.|s(t	|_|�
�dS|s3t|_|��dS)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,r#r#r$�__init__BszFontManager.__init__c	Csztjdd||fdgtjdd�}|��\}}|jdkr;|��}|D]}|�d�r)q!|�����d�}|r8|Sq!dSdS)Nzfc-listz%s:style=%s�file)�stdout�stderrrsFontconfig warning:�:)	�
subprocess�Popen�PIPE�communicate�
returncode�
splitlinesr1�decode�strip)	r8�name�style�procr;�_�lines�line�pathr#r#r$�_get_nix_font_pathTs�

��zFontManager._get_nix_font_pathcCs�tdD]}|�|j|�}|durt�||j�|jd<nqtd|j��dD]5}t|D]}|�|j|�}|durFt�||j�|j|<nq-|dkrT|jd|j|<q'|jd|j|<q'dS)Nr�No usable fonts named: "%s"�rrrrr)�STYLESrMr+r	�truetyper,r-r&)r8rFrLrG�	stylenamer#r#r$r7bs*�����zFontManager._create_nixcCs|�|d|�����S)N� )�getrE�lower)r8�font_maprFrGr#r#r$�_get_mac_font_pathwszFontManager._get_mac_font_pathcsi}tj�t�d�d�ddfD]�|��fdd�t���D��qtdD]}|�||j|�}|dur?t	�
||j�|jd<nq%t
d|j��d	D]6}t|D]}|�||j|�}|durit	�
||j�|j|<nqO|d
krw|jd|j|<qI|jd|j|<qIdS)N�HOMEzLibrary/Fonts/z/Library/Fonts/z/System/Library/Fonts/c3s@�|]}|���d�rtj�|�d��tj��|�fVqdS))�ttf�ttcrN)rU�endswith�osrL�splitext�join)�.0�f��font_dirr#r$�	<genexpr>~s�� 
�z*FontManager._create_mac.<locals>.<genexpr>rrNrOrr)r\rLr^�getenv�update�listdirrPrWr+r	rQr,r-r&)r8rVrFrLrGrRr#rar$r5zs8�
������zFontManager._create_macFc

CsvdD]*}|D]%}zd||od||f}t�||�\}}	|WSty+Yqwq|r9td||df��dS)N)rz (TrueType)z%s%s%srSz"Font %s (%s) not found in registryr)�_winreg�QueryValueEx�OSErrorr&)
r8�key�basename�styles�fail�suffixrG�valname�valrIr#r#r$�_lookup_win�s��
�zFontManager._lookup_wincCsJd}tjdftjdftjdftjdfg}|D]�}z{tj|�}zmzQ|�||jtdd�}t�||j	�|j
d<dD].}|�||jt|�}|rPt�||j	�|j
|<q7|dkr]|j
d|j
|<q7|j
d|j
|<q7WWt�|�WdSty�}z|}WYd}~nd}~wwWt�|�nt�|�wWqt
y�Yqw|r�|�td��)	Nz2Software\Microsoft\Windows NT\CurrentVersion\Fontsz/Software\Microsoft\Windows\CurrentVersion\FontsrTrOrrz$Can't open Windows font registry key)rg�HKEY_CURRENT_USER�HKEY_LOCAL_MACHINE�OpenKeyrqr+rPr	rQr,r-�CloseKeyr&ri)r8�lookuperror�keynames�keynamerjrLrG�errr#r#r$r3�sB�
����	zFontManager._create_wincCs|jd�d�S)z)
        Get the character size.
        r�M�r-�getsize�r8r#r#r$�
get_char_size��zFontManager.get_char_sizecCs|jd�|�S)z3
        Get the text size(width, height).
        rr{)r8�textr#r#r$�
get_text_size�rzFontManager.get_text_sizecCs8|r	|r	|jdS|r|jdS|r|jdS|jdS)z>
        Get the font based on bold and italic flags.
        rrrr)r-)r8�bold�obliquer#r#r$�get_font�s



zFontManager.get_fontN)r()F)rr r!r"r9rMr7rWr5rqr3r~r�r�r#r#r#r$r'=s

'r'c@s�eZdZdZdZgd�ZdgZdZdZdd�Z	d-d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,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	Ks�tstd��tj|fi|��d|_t|j�|_|jjdur"d|_n|jj|_t	|dgd�|j
dd�|_t|d	d
�|_
t|dd�|_t|d
d�}t|�dd�|�|_|j��\|_|_|�dd�|_|�dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_|jr�|j|j|jd|_ nd |_ g|_!t"|d!g�}|D]}z
|j!�#t$|��Wq�t%y�Yq�w|�d"|jj&�p�d#|_'g|_(dS)$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_pad�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_availablerrr9r.�dictrGrl�background_colorr�default_image_formatr�rr�r�r'rTr-r~�fontw�fonthr�r�r�rr�r�r�r�r�r�r��line_number_widthr�r�append�int�
ValueError�highlight_colorr��	drawables)r8�options�fontsize�hl_lines_strrKr#r#r$r9]sp�

�����
����
zImageFormatter.__init__rcCstd��)NzWThe -S option is meaningless for the image formatter. Use -O style=<stylename> instead.)�NotImplementedError)r8�argr#r#r$�get_style_defs�szImageFormatter.get_style_defscCs|j|jS)z+
        Get the height of a line.
        )r�r�r}r#r#r$�_get_line_height�szImageFormatter._get_line_heightcCs||��|jS)z8
        Get the Y coordinate of a line number.
        )r�r��r8�linenor#r#r$�_get_line_y�szImageFormatter._get_line_ycCs|jS)z/
        Get the width of a character.
        )r�r}r#r#r$�_get_char_width�szImageFormatter._get_char_widthcCs||j|jS)z?
        Get the X coordinate of a character position.
        )r�r�)r8�
linelengthr#r#r$�_get_char_x�rzImageFormatter._get_char_xcCs|�|�|�|�fS)zL
        Get the actual position for a character and line position.
        )r�r�)r8r�r�r#r#r$�
_get_text_pos�szImageFormatter._get_text_poscCs|j|�|�fS)zI
        Get the actual position for the start of a line number.
        )r�r�r�r#r#r$�_get_linenumber_pos�rz"ImageFormatter._get_linenumber_poscCs$|ddurd|d}|Sd}|S)zE
        Get the correct color for the token from the style.
        �colorN�#z#000r#)r8rG�fillr#r#r$�_get_text_color��
�zImageFormatter._get_text_colorcCs$|ddurd|d}|Sd}|S)zP
        Get the correct background color for the token from the style.
        �bgcolorNr�r#)r8rG�bg_colorr#r#r$�_get_text_bg_color�r�z!ImageFormatter._get_text_bg_colorcCs|j�|d|d�S)z5
        Get the correct font for the style.
        r��italic)r-r�)r8rGr#r#r$�_get_style_font�szImageFormatter._get_style_fontcCs$|�|�|j|�|d�|jfS)z.
        Get the required image size.
        r)r�r�r�)r8�
maxlinelength�	maxlinenor#r#r$�_get_image_size�s�zImageFormatter._get_image_sizecCs:|j|�|�t|��|j�|j�|j|j�|j	dd�dS)zA
        Remember a line number drawable to paint later.
        N��font�text_fg�text_bg)
�
_draw_textr��str�rjustr�r-r�r�r�r�)r8�posnor�r#r#r$�_draw_linenumber�s
�
�zImageFormatter._draw_linenumbercCs|j�|||||f�dS)zB
        Remember a single drawable tuple to paint later.
        N)r�r�)r8�posr�r�r�r�r#r#r$r��szImageFormatter._draw_textc
Csd}}}d}}|D]p\}}||jvr|j}||jvs|j|}	|�d�}|�d�}
t|
�D]K\}}|�d�}
|
rn|j|�||�|
|�|	�|�	|	�|�
|	�d�|j�|
�\}}||7}t
||�}|t|
�7}t
||�}|�d�r{d}d}|d7}q0q||_||_||_dS)z9
        Create drawables for the token content.
        r�T�
r�r�N)rl�parent�
expandtabsrC�	enumerate�rstripr�r�r�r�r�r-r��max�lenr[r��	maxcharnor�)r8�tokensourcer��charnor�r�r��ttype�valuerGrJ�irK�temp�
temp_width�
temp_hightr#r#r$�_create_drawables�sB

�




�


��
z ImageFormatter._create_drawablescCsB|jsdSt|j�D]}||j}||jdkr|�||�q
dS)z8
        Create drawables for the line numbers.
        Nr)r��ranger�r�r�r�)r8�p�nr#r#r$�_draw_line_numberss
��z!ImageFormatter._draw_line_numberscCs~|jsdS|jdurdSt�|�}|jd}|j|j|j}|jd||fg|j	d�|j
r<|j|df||fg|jd�~dS)z@
        Paint the line number background on the image.
        N���)rr�r�r)r�r�r�Draw�sizer�r�r��	rectangler�r�rK)r8�im�draw�recth�rectwr#r#r$�_paint_line_number_bg$s


�z$ImageFormatter._paint_line_number_bgcCs8|�|�|��t�d|�|j|j�|j�}|�|�t	�
|�}|jrY|j|j
|jd}|��}|jd|}|jD]}|�|d�}	|j||	f|||	|fg|jd�q=|jD]4\}
}}}
}|r�|j||d�}|j|
d|
d|
d|d|
d|dg|d�|j|
|||
d�q\|�||j���dS)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�rr�)r�r�)r�r�N)r�r�r�newr�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r��textsizer��saver��upper)r8r��outfiler�r��xr�r��
linenumber�yr�r�r�r�r��	text_sizer#r#r$�format5s0
�


�6zImageFormatter.formatN)r)rr r!r"rF�aliases�	filenames�
unicodeoutputr�r9r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r#r#r#r$r
�s2m
8


(r
c@s$eZdZdZdZdgZdgZdZdS)rz�
    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�rr r!r"rFr�r�r�r#r#r#r$rZsrc@s&eZdZdZdZddgZdgZdZdS)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*.jpgNrr#r#r#r$rh�rc@s&eZdZdZdZddgZdgZdZdS)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*.bmpNrr#r#r#r$r
vrr
) r"r\r/�pygments.formatterr�
pygments.utilrrrrr>�PILrrr	r��ImportErrorrg�winreg�__all__rPr6r2r4r�	Exceptionr&r'r
rrr
r#r#r#r$�<module>sR
�����+u

https://t.me/RX1948 - 2025