HEX
Server: LiteSpeed
System: Linux srv146.niagahoster.com 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
User: kodi1989 (1633)
PHP: 8.1.34
Disabled: symlink,shell_exec,exec,popen,system,dl,passthru,escapeshellarg,escapeshellcmd,show_source,pcntl_exec
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/pygments/formatters/__pycache__/img.cpython-37.pyc
B

��fLZ�@sldZddlZddlZddlmZddlmZmZmZm	Z	ddl
Z
yddlmZm
Z
mZdZWnek
rtdZYnXyddlZWn:ek
r�yddlZWnek
r�dZYnXYnXdd	d
dgZdd
ddddgddgdgddgd�ZdZdZdZGdd�de�ZGdd�de�ZGdd �d �ZGd!d�de�ZGd"d	�d	e�ZGd#d
�d
e�ZGd$d�de�ZdS)%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�ZRomanZBookZNormalZRegularZMediumZObliqueZItalicZBoldzBold ObliquezBold Italic)�NORMAL�ITALIC�BOLD�
BOLDITALICzDejaVu Sans MonozCourier NewZMenloc@seZdZdZdS)�PilNotAvailablez,When Python imaging library is not availableN)�__name__�
__module__�__qualname__�__doc__�rr�H/opt/alt/python37/lib/python3.7/site-packages/pygments/formatters/img.pyr4src@seZdZdZdS)�FontNotFoundz(When there are no usable fonts specifiedN)rrrrrrrrr8src@sleZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zddd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�FontManagerz>
    Manages a set of fonts: normal, italic, bold, etc...
    �cCs�||_||_i|_d|_d|_t|d�s4tj�|�rdt	�
||j�}d|_xtD]}||j|<qNWdStj
�d�r�|szt|_|��n2tj
�d�r�|s�t|_|��n|s�t|_|��dS)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 r!�font�stylerrr�__init__As,


zFontManager.__init__c	Csztjdd||fdgtjdd�}|��\}}|jdkrv|��}x2|D]*}|�d�rTqD|�����d�}|rD|SqDWdSdS)Nzfc-listz%s:style=%s�file)�stdout�stderrrsFontconfig warning:�:)	�
subprocess�Popen�PIPE�communicate�
returncode�
splitlinesr-�decode�strip)	r4�namer6�procr9�_�lines�liner'rrr�_get_nix_font_path\s


zFontManager._get_nix_font_pathcCs�xJtdD]0}|�|j|�}|dk	r
t�||j�|jd<Pq
Wtd|j��xtdD]l}xft|D]0}|�|j|�}|dk	r`t�||j�|j|<Pq`W|dkr�|jd|j|<qR|jd|j|<qRWdS)NrzNo usable fonts named: "%s")rrrrr)r*rIr r	r)r!r"r)r4rDr'r6�	stylenamerrrr3js 

zFontManager._create_nixcCs|�|d|�����S)N� )�getrC�lower)r4�font_maprDr6rrr�_get_mac_font_pathszFontManager._get_mac_font_pathcsi}x@tj�t�d�d�ddfD]"�|��fdd�t���D��q WxLtdD]2}|�||j|�}|dk	rPt	�
||j�|jd<PqPWt
d|j��xvd	D]n}xht|D]2}|�||j|�}|dk	r�t	�
||j�|j|<Pq�W|d
kr�|jd|j|<q�|jd|j|<q�WdS)N�HOMEzLibrary/Fonts/z/Library/Fonts/z/System/Library/Fonts/c3s>|]6}|���d�rtj�|�d��tj��|�fVqdS))ZttfZttcrN)rM�endswithr&r'�splitext�join)�.0�f)�font_dirrr�	<genexpr>�sz*FontManager._create_mac.<locals>.<genexpr>rzNo usable fonts named: "%s")rrrrr)r&r'rS�getenv�update�listdirr*rOr r	r)r!r"r)r4rNrDr'r6rJr)rVrr1�s,


zFontManager._create_macFc

Cs~xxdD]T}xN|D]F}y*d||o$d||f}t�||�\}}	|Stk
rTwYqXqWqW|rvtd||df��dSdS)N)rz (TrueType)z%s%s%srKz"Font %s (%s) not found in registryr)�_winreg�QueryValueEx�OSErrorr)
r4�key�basename�stylesZfail�suffixr6Zvalname�valrFrrr�_lookup_win�s

zFontManager._lookup_wincCsDd}tjdftjdftjdftjdfg}�x|D]�}y�tj|�}z�y�|�||jtdd�}t�||j	�|j
d<xddD]\}|�||jt|�}|r�t�||j	�|j
|<qt|dkr�|j
d|j
|<qt|j
d|j
|<qtWdStk
�r�}z|}Wdd}~XYnXWdt�|�XWq0t
k
�r(Yq0Xq0W|�r8|�td��dS)	Nz2Software\Microsoft\Windows NT\CurrentVersion\Fontsz/Software\Microsoft\Windows\CurrentVersion\FontsrT)rrrrrz$Can't open Windows font registry key)r[�HKEY_CURRENT_USER�HKEY_LOCAL_MACHINE�OpenKeyrcr r*r	r)r!r"rZCloseKeyr])r4ZlookuperrorZkeynames�keynamer^r'r6�errrrrr/�s6


zFontManager._create_wincCs
|�d�S)z)
        Get the character size.
        �M)�
get_text_size)r4rrr�
get_char_size�szFontManager.get_char_sizecCs4|jd}t|d�r&|�|�dd�S|�|�SdS)z4
        Get the text size (width, height).
        r�getbbox��N)r"r%rl�getsize)r4�textr5rrrrj�s

zFontManager.get_text_sizecCs||r"|r"|jr|�d�S|jdS|r@|jr6|�d�S|jdS|r^|jrT|�d�S|jdS|jrn|�d�S|jdSdS)z>
        Get the font based on bold and italic flags.
        rrrrN)r$�	get_styler")r4�boldZobliquerrr�get_font�s






zFontManager.get_fontc	CsV|j|}xFt|D]:}y|�|�|Stk
r:Yqtk
rL|SXqW|S)z}
        Get the specified style of the font if it is a variable font.
        If not found, return the normal font.
        )r"r*Zset_variation_by_name�
ValueErrorr])r4r6r5Z
style_namerrrrq�s


zFontManager.get_styleN)r)F)rrrrr7rIr3rOr1rcr/rkrjrsrqrrrrr<s

'
rc@s�eZdZdZdZdddgZdgZdZdZdd�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.
        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
    �imgZIMG�pngz*.pngFc	Ks�tstd��tj|f|�d|_t|j�|_|jjdkr@d|_n
|jj|_t	|ddddd	g|j
d
d�|_t|dd
�|_
t|dd�|_t|dd�}t|�dd�|�|_|j��\|_|_|�dd�|_|�dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd
�|_t|dd
�|_t|d d!�|_t|d"d!�|_|j�rd|j|j|jd|_ nd#|_ g|_!t"|d$g�}x:|D]2}y|j!�#t$|��Wnt%k
�r�YnX�q�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_formatrv�jpeg�gif�bmpT)�normcase�	image_pad�
�line_padrmr!rr 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_availablerrr7r#�dictr6r`�background_colorr�default_image_formatrxrr}rrrLr"rk�fontw�fonthr�r�r�rr�r�r�r�r�r�r��line_number_widthr�r�append�intrtZhighlight_colorr��	drawables)r4�optionsZfontsizeZhl_lines_strrHrrrr7�sZ






zImageFormatter.__init__rcCstd��dS)NzWThe -S option is meaningless for the image formatter. Use -O style=<stylename> instead.)�NotImplementedError)r4�argrrr�get_style_defs�szImageFormatter.get_style_defscCs|j|jS)z+
        Get the height of a line.
        )r�r)r4rrr�_get_line_height�szImageFormatter._get_line_heightcCs||��|jS)z8
        Get the Y coordinate of a line number.
        )r�r})r4�linenorrr�_get_line_y�szImageFormatter._get_line_ycCs|jS)z/
        Get the width of a character.
        )r�)r4rrr�_get_char_width�szImageFormatter._get_char_widthcCs||j|jS)z?
        Get the X coordinate of a character position.
        )r}r�)r4�
linelengthrrr�_get_char_x�szImageFormatter._get_char_xcCs|�|�|�|�fS)zL
        Get the actual position for a character and line position.
        )r�r�)r4r�r�rrr�
_get_text_pos�szImageFormatter._get_text_poscCs|j|�|�fS)zI
        Get the actual position for the start of a line number.
        )r}r�)r4r�rrr�_get_linenumber_pos�sz"ImageFormatter._get_linenumber_poscCs"|ddk	rd|d}nd}|S)zE
        Get the correct color for the token from the style.
        �colorN�#z#000r)r4r6�fillrrr�_get_text_color�szImageFormatter._get_text_colorcCs"|ddk	rd|d}nd}|S)zP
        Get the correct background color for the token from the style.
        ZbgcolorNr�r)r4r6Zbg_colorrrr�_get_text_bg_color�sz!ImageFormatter._get_text_bg_colorcCs|j�|d|d�S)z5
        Get the correct font for the style.
        rrZitalic)r"rs)r4r6rrr�_get_style_font�szImageFormatter._get_style_fontcCs$|�|�|j|�|d�|jfS)z.
        Get the required image size.
        r)r�r}r�)r4�
maxlinelength�	maxlinenorrr�_get_image_sizeszImageFormatter._get_image_sizecCs:|j|�|�t|��|j�|j�|j|j�|j	dd�dS)zA
        Remember a line number drawable to paint later.
        N)r5�text_fg�text_bg)
�
_draw_textr��str�rjustr�r"rsr�r�r�)r4Zposnor�rrr�_draw_linenumber	s
zImageFormatter._draw_linenumbercCs|j�|||||f�dS)zB
        Remember a single drawable tuple to paint later.
        N)r�r�)r4�posrpr5r�r�rrrr�szImageFormatter._draw_textc
Csd}}}d}}x�|D]�\}}x||jkr6|j}q$W|j|}	|�d�}|�d�}
x�t|
�D]�\}}|�d�}
|
r�|j|�||�|
|�|	�|�	|	�|�
|	�d�|j�|
�\}}||7}t
||�}|t|
�7}t
||�}|�d�r`d}d}|d7}q`WqW||_||_||_dS)z9
        Create drawables for the token content.
        rrnT�
)r5r�r�r�N)r`�parent�
expandtabsrA�	enumerate�rstripr�r�r�r�r�r"rj�max�lenrQr��	maxcharnor�)r4�tokensourcer�Zcharnor�r�r�Zttype�valuer6rG�irH�tempZ
temp_widthrFrrr�_create_drawabless:








z ImageFormatter._create_drawablescCsF|js
dSx6t|j�D](}||j}||jdkr|�||�qWdS)z8
        Create drawables for the line numbers.
        Nr)r��ranger�r�r�r�)r4�p�nrrr�_draw_line_numbersDs
z!ImageFormatter._draw_line_numberscCs~|js
dS|jdkrdSt�|�}|jd}|j|j|j}|jd||fg|j	d�|j
rx|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�rH)r4�im�draw�recth�rectwrrr�_paint_line_number_bgOs



z$ImageFormatter._paint_line_number_bgcCsB|�|�|��t�d|�|j|j�|j�}|�|�t	�
|�}|jr�|j|j
|jd}|��}|jd|}x@|jD]6}|�|d�}	|j||	f|||	|fg|jd�q|Wxt|jD]j\}
}}}
}|�r|j||d�}|j|
d|
d|
d|d|
d|dg|d�|j|
|||
d�q�W|�||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.
        ZRGBr�r)r�)rpr5)r5r�N)r�r�r�newr�r�r�r�r�rr�r�r}r�r�r�r�r�r�r�r�Ztextsizerp�saverx�upper)r4r��outfiler�r��xr�r�Z
linenumber�yr�r�r5r�r�Z	text_sizerrr�format`s,


6zImageFormatter.formatN)r)rrrrrD�aliases�	filenamesZ
unicodeoutputr�r7r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr
s0m
8



(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
    Zimg_gifrzz*.gifN)rrrrrDr�r�r�rrrrr�s
c@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
    Zimg_jpgZjpgryz*.jpgN)rrrrrDr�r�r�rrrrr�s
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
    Zimg_bmpr{Zbitmapz*.bmpN)rrrrrDr�r�r�rrrrr
�s
) rr&r+Zpygments.formatterrZ
pygments.utilrrrrr<ZPILrrr	r��ImportErrorr[�winreg�__all__r*r2r.r0r�	Exceptionrrr
rrr
rrrr�<module>	sH
Uw