HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/pygments/formatters/__pycache__/img.cpython-38.pyc
U

G�
\EM�@srdZddlZddlZddlmZddlmZmZmZm	Z	m
Z
ddlZzddlm
Z
mZmZdZWnek
rxdZYnXzddlZWn:ek
r�zddlZWnek
r�dZYnXYnXdd	d
dgZdd
ddddgddgdgddgd�ZdZdZdZGdd�de�ZGdd�de�ZGdd�de�ZGd d�de�ZGd!d	�d	e�ZGd"d
�d
e�Z Gd#d�de�Z!dS)$z�
    pygments.formatters.img
    ~~~~~~~~~~~~~~~~~~~~~~~

    Formatter for Pixmap output.

    :copyright: Copyright 2006-2017 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�xrange)�Image�	ImageDraw�	ImageFontTF�ImageFormatter�GifImageFormatter�JpgImageFormatter�BmpImageFormatter�ZRomanZBookZNormalZRegularZMediumZObliqueZItalicZBoldzBold ObliquezBold Italic)�NORMAL�ITALIC�BOLD�
BOLDITALICzBitstream Vera Sans MonozCourier Newc@seZdZdZdS)�PilNotAvailablez,When Python imaging library is not availableN��__name__�
__module__�__qualname__�__doc__�rr�9/usr/lib/python3/dist-packages/pygments/formatters/img.pyr6src@seZdZdZdS)�FontNotFoundz(When there are no usable fonts specifiedNrrrrrr:src@s\eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zddd�Z	dd�Z
dd�Zdd�ZdS)�FontManagerz>
    Manages a set of fonts: normal, italic, bold, etc...
    �cCsn||_||_i|_d|_tj�d�r8|s.t|_|��n2tj�d�rX|sNt	|_|�
�n|sbt|_|��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"rrr�__init__Cs

zFontManager.__init__c	Csztjdd||fdgtjdd�}|��\}}|jdkrv|��}|D].}|�d�rRqB|�����d�}|rB|SqBdSdS)Nzfc-listz%s:style=%s�file)�stdout�stderrrsFontconfig warning:�:)	�
subprocess�Popen�PIPEZcommunicate�
returncode�
splitlinesr'�decode�strip)	r.�name�style�procr1�_�lines�line�pathrrr�_get_nix_font_pathUs�


zFontManager._get_nix_font_pathcCs�tdD]2}|�|j|�}|dk	rt�||j�|jd<qJqtd|j��dD]j}t|D]2}|�|j|�}|dk	rZt�||j�|j|<qNqZ|dkr�|jd|j|<qN|jd|j|<qNdS)Nr�No usable fonts named: "%s"�rrrrr)�STYLESrBr!r
�truetyper"r#r)r.r;rAr<�	stylenamerrrr-cs"�zFontManager._create_nixcCs|�|d|�����S)N� )�getr:�lower)r.�font_mapr;r<rrr�_get_mac_font_pathxszFontManager._get_mac_font_pathcsi}tj�t�d�d�ddfD]"�|��fdd�t���D��qtdD]4}|�||j|�}|dk	rJt	�
||j�|jd<q�qJt
d|j��d	D]l}t|D]4}|�||j|�}|dk	r�t	�
||j�|j|<q�q�|d
kr�|jd|j|<q�|jd|j|<q�dS)N�HOMEzLibrary/Fonts/z/Library/Fonts/z/System/Library/Fonts/c3s>|]6}|���d�rtj�|�d��tj��|�fVqdS)ZttfrN)rJ�endswith�osrA�splitext�join)�.0�f�Zfont_dirrr�	<genexpr>�s�z*FontManager._create_mac.<locals>.<genexpr>rrCrDrr)rOrArQ�getenv�update�listdirrErLr!r
rFr"r#r)r.rKr;rAr<rGrrTrr+{s6�
���zFontManager._create_macFc

Cs~dD]\}|D]R}z4d||o d||f}t�||�\}}	|WStk
r\YqYqXqq|rztd||df��dS)N)rz (TrueType)z%s%s%srHz"Font %s (%s) not found in registryr)�_winregZQueryValueEx�EnvironmentErrorr)
r.�key�basename�stylesZfail�suffixr<Zvalname�valr>rrr�_lookup_win�s
�zFontManager._lookup_wincCs�zt�tjd�}WnDtk
rVzt�tjd�}Wntk
rPtd��YnXYnXz�|�||jtdd�}t	�
||j�|jd<dD]\}|�||jt|�}|r�t	�
||j�|j|<q�|dkr�|jd|j|<q�|jd|j|<q�W5t�|�XdS)	Nz2Software\Microsoft\Windows NT\CurrentVersion\Fontsz/Software\Microsoft\Windows\CurrentVersion\Fontsz$Can't open Windows font registry keyrTrDrr)
rY�OpenKey�HKEY_LOCAL_MACHINErZrZCloseKeyr`r!rEr
rFr"r#)r.r[rAr<rrrr)�s0��zFontManager._create_wincCs|jd�d�S)z)
        Get the character size.
        r�M)r#�getsize�r.rrr�
get_char_size�szFontManager.get_char_sizecCs<|r|r|jdS|r |jdS|r.|jdS|jdSdS)z>
        Get the font based on bold and italic flags.
        rrrrN)r#)r.�boldZobliquerrr�get_font�s


zFontManager.get_fontN)r)F)
rrrrr/rBr-rLr+r`r)rfrhrrrrr>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*S),ra�	
    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: "Bitstream Vera Sans Mono" on Windows, Courier New 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
    ZimgZIMG�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�}|D]2}z|j!�#t$|��Wnt%k
�r�YnX�q�|�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_formatri�jpeg�gif�bmpT)�normcase�	image_pad�
�line_pad�r"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_availablerrr/r$�dictr<r]�background_colorr�default_image_formatrkrrprrrrIr#rf�fontw�fonthrtrurvrrwrxryr{r|r}r�line_number_widthr�r�append�int�
ValueErrorZhighlight_colorr��	drawables)r.ZoptionsZfontsizeZhl_lines_strr@rrrr/Js|�

�����
�
��zImageFormatter.__init__rcCstd��dS)NzWThe -S option is meaningless for the image formatter. Use -O style=<stylename> instead.)�NotImplementedError)r.�argrrr�get_style_defs�szImageFormatter.get_style_defscCs|j|jS)z+
        Get the height of a line.
        )r�rrrerrr�_get_line_height�szImageFormatter._get_line_heightcCs||��|jS)z8
        Get the Y coordinate of a line number.
        )r�rp�r.�linenorrr�_get_line_y�szImageFormatter._get_line_ycCs|jS)z/
        Get the width of a character.
        )r�rerrr�_get_char_width�szImageFormatter._get_char_widthcCs||j|j|jS)z?
        Get the X coordinate of a character position.
        )r�rpr�)r.�charnorrr�_get_char_x�szImageFormatter._get_char_xcCs|�|�|�|�fS)zL
        Get the actual position for a character and line position.
        )r�r�)r.r�r�rrr�
_get_text_pos�szImageFormatter._get_text_poscCs|j|�|�fS)zI
        Get the actual position for the start of a line number.
        )rpr�r�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.
        ZcolorN�#z#000r)r.r<�fillrrr�_get_text_color�szImageFormatter._get_text_colorcCs|j�|d|d�S)z5
        Get the correct font for the style.
        rgZitalic)r#rh)r.r<rrr�_get_style_font�szImageFormatter._get_style_fontcCs$|�|�|j|�|d�|jfS)z.
        Get the required image size.
        r)r�rpr�)r.�	maxcharno�	maxlinenorrr�_get_image_size�s�zImageFormatter._get_image_sizecCs8|j|�|�t|��|j�|j�|j|j�|j	d�dS)zA
        Remember a line number drawable to paint later.
        ��fontr�N)
�
_draw_textr��str�rjustrvr#rhrwrxrt)r.Zposnor�rrr�_draw_linenumber�s
��zImageFormatter._draw_linenumbercKs|j�||||f�dS)zB
        Remember a single drawable tuple to paint later.
        N)r�r�)r.�pos�textr��kwrrrr��szImageFormatter._draw_textc	Cs�d}}}|D]�\}}||jkr*|j}q|j|}|�d�}|�d�}t|�D]h\}	}
|
�d�}|r�|j|�||�||�|�|�	|�d�|t
|�7}t||�}|
�d�rPd}|d7}qPq||_
||_dS)z9
        Create drawables for the token content.
        r�T�
r�r~N)r]�parent�
expandtabsr8�	enumerate�rstripr�r�r�r��len�maxrNr�r�)r.�tokensourcer�r�r�Zttype�valuer<r?�ir@Ztemprrr�_create_drawables�s.





�

z ImageFormatter._create_drawablescCsB|js
dSt|j�D](}||j}||jdkr|�||�qdS)z8
        Create drawables for the line numbers.
        Nr)r{rr�rr}r�)r.�p�nrrr�_draw_line_numbers�s
z!ImageFormatter._draw_line_numberscCsx|js
dS|jdkrdSt�|�}|jd}|j|j|j}|jd||fg|j	d�|j
|df||fg|jd�~dS)z@
        Paint the line number background on the image.
        N���)rr�r�r)r{rtr	�Draw�sizerpr�ry�	rectanglerur@)r.�im�draw�recth�rectwrrr�_paint_line_number_bg�s


�z$ImageFormatter._paint_line_number_bgcCs�|�|�|��t�d|�|j|j�|j�}|�|�t	�
|�}|jr�|j|j
|jd}|��}|jd|}|jD]6}|�|d�}	|j||	f|||	|fg|jd�qz|jD]$\}
}}}
|j|
|fd|i|
��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.
        ZRGBr~rr�r�N)r�r�r�newr�r�r�r�r�r	r�r�rpr�ryr�r�r�r�r�r�r�Zsaverk�upper)r.r�Zoutfiler�r��xr�r�Z
linenumber�yr�r�r�r�rrr�formats*
�


�zImageFormatter.formatN)r)rrrrr;�aliases�	filenamesZ
unicodeoutputr�r/r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s.l
8

!c@s$eZdZdZdZdgZdgZdZdS)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
    Zimg_gifrmz*.gifN�rrrrr;r�r�r�rrrrr1s
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_jpgZjpgrlz*.jpgNr�rrrrr
?s
c@s&eZdZdZdZddgZdgZdZdS)rz�
    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_bmprnZbitmapz*.bmpNr�rrrrrMs
)"rrOr%Zpygments.formatterrZ
pygments.utilrrrrrr4ZPILrr	r
r��ImportErrorrY�winreg�__all__rEr,r(r*r�	Exceptionr�objectrrrr
rrrrr�<module>sL

��^