HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/pygments/formatters/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/pygments/formatters/__pycache__/img.cpython-312.pyc
�

|�eLZ���dZddlZddlZddlmZddlmZmZmZm	Z	ddl
Z
	ddlmZm
Z
mZdZ	ddlZgd�Zgd	�d
dgdgd
dgd�ZdZdZdZGd�de�ZGd�de�ZGd�d�ZGd�de�ZGd�de�ZGd�de�ZGd�d e�Zy#e$rdZY�swxYw#e$r	ddlZn
#e$rdZYnwxYwY��wxYw)!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 ObliquezBold Italic)�NORMAL�ITALIC�BOLD�
BOLDITALICzDejaVu Sans MonozCourier New�Menloc��eZdZdZy)�PilNotAvailablez,When Python imaging library is not availableN��__name__�
__module__�__qualname__�__doc__���9/usr/lib/python3/dist-packages/pygments/formatters/img.pyrr4s��6r%rc��eZdZdZy)�FontNotFoundz(When there are no usable fonts specifiedNrr$r%r&r(r(8s��2r%r(c�V�eZdZdZdd�Zd�Zd�Zd�Zd�Zdd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�FontManagerz>
    Manages a set of fonts: normal, italic, bold, etc...
    c�R�||_||_i|_d|_d|_t|d�stjj|�rBtj||j�}d|_tD]}||j|<�ytjjd�r|st|_|j!�ytjjd�r|st"|_|j%�y|st&|_|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__zFontManager.__init__As���"���"�����
���
���
��9�f�%������	�)B��%�%�i����@�D� �D�M��
)��$(��
�
�5�!�
)�
��<�<�"�"�5�)��!6�������
�\�\�
$�
$�X�
.��!6��������!6������r%c�^�tjd|�d|��dgtjd��}|j�\}}|jdk(r]|j�}|D]G}|j
d�r�|j�j�jd�}|s�E|cSyy)Nzfc-listz:style=�file)�stdout�stderrrsFontconfig warning:�:)	�
subprocess�Popen�PIPE�communicate�
returncode�
splitlinesr<�decode�strip)	rC�namerE�procrI�_�lines�liner6s	         r&�_get_nix_font_pathzFontManager._get_nix_font_path\s�������T�5�,I�6� R�'1���t�E���$�$�&�	����?�?�a���%�%�'�E��
 ���?�?�#9�:���{�{�}�*�*�,�2�2�3�7����K�
 �� r%c�*�tdD]O}|j|j|�}|��"tj||j
�|jd<ntd|jz��dD]�}t|D]O}|j|j|�}|��"tj||j
�|j|<�]|dk(r|jd|j|<��|jd|j|<��y)Nr�No usable fonts named: "%s"�rrrrr)r9rYr/r
r8r0r1r()rCrTr6rE�	stylenames     r&rBzFontManager._create_nixjs
���8�$�	/�D��*�*�4�>�>�4�@�D���'0�'9�'9�$����'O��
�
�8�$��		/��<�#�~�~� .�/�
/�5�
	=�E�#�E�]�	
=�	��.�.�t�~�~�y�I���#�(1�(:�(:�4����(P�D�J�J�u�%��		
=��L�(�(,�
�
�6�(:�D�J�J�u�%�(,�
�
�8�(<�D�J�J�u�%�
	=r%c�h�|j|dz|zj�j��S)N� )�getrS�lower)rC�font_maprTrEs    r&�_get_mac_font_pathzFontManager._get_mac_font_paths,���|�|�T�C�Z�%�/�6�6�8�>�>�@�A�Ar%c���i}tjjtjd�d�ddfD]/�|j	�fd�tj
��D���1tdD]P}|j||j|�}|��#tj||j�|jd<ntd|jz��dD]�}t|D]P}|j||j|�}|��#tj||j�|j|<�^|d	k(r|jd
|j|<��|jd|j|<��y)N�HOMEzLibrary/Fonts/z/Library/Fonts/z/System/Library/Fonts/c3��K�|]s}|j�jd�rRtjj	|�dj�tjj�|�f���uy�w))�ttf�ttcrN)ra�endswithr5r6�splitext�join)�.0�f�font_dirs  �r&�	<genexpr>z*FontManager._create_mac.<locals>.<genexpr>�s^�����7���7�7�9�%�%�n�5����!�!�!�$�Q�'�-�-�/������h��1J�K�7�s�A9A<rr[r\rr)r5r6rk�getenv�update�listdirr9rcr/r
r8r0r1r()rCrbrTr6rEr]rns      @r&r@zFontManager._create_mac�sl����������b�i�i��&7�9I�J�*�,D�F�	7�H��O�O�7����H�-�7�
7�	7��8�$�	/�D��*�*�8�T�^�^�T�J�D���'0�'9�'9�$����'O��
�
�8�$��		/��<�#�~�~� .�/�
/�5�
	=�E�#�E�]�	
=�	��.�.�x�����S���#�(1�(:�(:�4����(P�D�J�J�u�%��		
=��L�(�(,�
�
�6�(:�D�J�J�u�%�(,�
�
�8�(<�D�J�J�u�%�
	=r%c���dD]7}|D]0}	|�|xrd|z�|��}tj||�\}}	|ccS�9|rtd|�d|d�d���y#t$rY�XwxYw)N)rz (TrueType)r_zFont z (rz) not found in registry)�_winreg�QueryValueEx�OSErrorr()
rC�key�basename�styles�fail�suffixrE�valname�valrVs
          r&�_lookup_winzFontManager._lookup_win�s���)�	�F��
���*2�E�4G�c�%�i�4G��P�G�$�1�1�#�w�?�F�C���J�	
�	��"�$,�f�Q�i�$9�:�:���
����s�)A�	A!� A!c��d}tjdftjdftjdftjdfg}|D�]}	tj|�}	|j	||j
tdd�}tj||j�|jd<dD]�}|j	||j
t|�}|r.tj||j�|j|<�W|dk(r|jd|j|<�y|jd|j|<��	tj|�y|r|�td��#t$r}|}Yd}~nd}~wwxYw	tj|�n#tj|�wxYw��v#t$rY���wxYw)	Nz2Software\Microsoft\Windows NT\CurrentVersion\Fontsz/Software\Microsoft\Windows\CurrentVersion\FontsrTr\rrz$Can't open Windows font registry key)rt�HKEY_CURRENT_USER�HKEY_LOCAL_MACHINE�OpenKeyr~r/r9r
r8r0r1�CloseKeyr(rv)rC�lookuperror�keynames�keynamerwr6rE�errs        r&r>zFontManager._create_win�s������/�/�1f�g��/�/�1c�d��0�0�2g�h��0�0�2d�e�h�� �	H�G�
��o�o�w�/��*��+�+�C������AQ�SW�X�D�+4�+=�+=�d�D�N�N�+S�D�J�J�x�(�!A�I��#�/�/��T�^�^�V�E�]�S���09�0B�0B�4����0X�D�J�J�u�-�$��4�48�J�J�v�4F��
�
�5� 1�48�J�J�x�4H��
�
�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�
Gc�$�|jd�S)z)
        Get the character size.
        �M)�
get_text_size�rCs r&�
get_char_sizezFontManager.get_char_size�s���!�!�#�&�&r%c��|jd}t|d�r|j|�ddS|j|�S)z4
        Get the text size (width, height).
        r�getbbox��)r1r4r��getsize)rC�textrDs   r&r�zFontManager.get_text_size�sA���z�z�(�#���4��#��<�<��%�a��*�*��<�<��%�%r%c�r�|r.|r,|jr|jd�S|jdS|r,|jr|jd�S|jdS|r,|jr|jd�S|jdS|jr|jd�S|jdS)z>
        Get the font based on bold and italic flags.
        rrrr)r3�	get_styler1)rC�bold�obliques   r&�get_fontzFontManager.get_font�s����G��}�}��~�~�l�3�3��:�:�l�+�+�
��}�}��~�~�f�-�-��:�:�f�%�%�
��}�}��~�~�h�/�/��:�:�h�'�'��}�}��~�~�h�/�/��:�:�h�'�'r%c��|j|}t|D]}	|j|�|cS|S#t$rY�'t$r|cYcSwxYw)z}
        Get the specified style of the font if it is a variable font.
        If not found, return the normal font.
        )r1r9�set_variation_by_name�
ValueErrorrv)rCrErD�
style_names    r&r�zFontManager.get_style�se��
�z�z�%� �� ��-�	�J�
��*�*�:�6���	�����
���
���
�s�5�	A�
A�AN)�)F)r r!r"r#rFrYrBrcr@r~r>r�r�r�r�r$r%r&r*r*<sA����6�=�*B�=�:
�%H�N'�&�(�2r%r*c��eZdZdZdZgd�ZdgZdZdZd�Z	dd�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)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.
        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�tstd��tj|fi|��d|_t|j�|_|jj�d|_n|jj|_t|dgd�|jd��|_t|d	d
�|_
t|dd�|_t|d
d�}t|j!dd�|�|_|j"j%�\|_|_|j!dd�|_|j!dd�|_t|dd�|_t1|dd�|_t1|dd�|_t|dd�|_t1|dd�|_t1|dd�|_t|dd�|_t|dd�|_|j8r/|j&|j.z|j6dzz|_ nd |_ g|_!tE|d!g�}|D]'}	|jBjGtI|���)|j!d"|jjL�xsd#|_'g|_(y#tJ$rY�lwxYw)$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�r0r�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_availablerrrFr2�dictrEry�background_colorr�default_image_formatr�rr�r�r*r`r1r��fontw�fonthr�r�r�rr�r�r�r�r�r�r��line_number_widthr�r�append�intr��highlight_colorr��	drawables)rC�options�fontsize�hl_lines_strrXs     r&rFzImageFormatter.__init__�sy���!�G�I�
I����4�+�7�+� ��
��4�:�:�&����:�:�&�&�.�$*�D�!�$(�J�J�$?�$?�D�!�*��^�%B��%�%��6���%�W�k�2�>���#�G�Z��;��
��w��R�8�� ����[�"�!=�x�H��
�!%���!9�!9�!;���
�D�J�%�k�k�*:�F�C���%�k�k�*:�F�C���!,�W�-@�!�"E��� ,�W�-?��!H���".�w�/C�U�#L���*�7�4E�q�I���(��.�$�G���%1�'�2I�4�&Q��"� +�G�5G�� K���!,�W�6I�1�!M������&*�j�j�4�3I�3I�&I�&*�&:�&:�Q�&>�'?�D�"�&'�D�"���
�#�G�Z��<�� �	�D�
��
�
�$�$�S��Y�/�	�
 ���J�$(�J�J�$>�$>�@�J�CI�	
�
�����	�
��
�s�6$J�	J�Jc��td��)NzWThe -S option is meaningless for the image formatter. Use -O style=<stylename> instead.)�NotImplementedError)rC�args  r&�get_style_defszImageFormatter.get_style_defs�s��!�#Q�R�	Rr%c�4�|j|jzS)z+
        Get the height of a line.
        )r�r�r�s r&�_get_line_heightzImageFormatter._get_line_height�s���z�z�D�M�M�)�)r%c�B�||j�z|jzS)z8
        Get the Y coordinate of a line number.
        )r�r��rC�linenos  r&�_get_line_yzImageFormatter._get_line_y�s!����-�-�/�/�$�.�.�@�@r%c��|jS)z/
        Get the width of a character.
        )r�r�s r&�_get_char_widthzImageFormatter._get_char_width�s���z�z�r%c�:�||jz|jzS)z?
        Get the X coordinate of a character position.
        )r�r�)rC�
linelengths  r&�_get_char_xzImageFormatter._get_char_x�s���D�N�N�*�T�-C�-C�C�Cr%c�F�|j|�|j|�fS)zL
        Get the actual position for a character and line position.
        )r�r�)rCr�r�s   r&�
_get_text_poszImageFormatter._get_text_pos�s%�����
�+�T�-=�-=�f�-E�E�Er%c�<�|j|j|�fS)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|dz}|Sd}|S)zE
        Get the correct color for the token from the style.
        �color�#z#000r$)rCrE�fills   r&�_get_text_colorzImageFormatter._get_text_color�s/����>�%���w��'�D����D��r%c�(�|d�
d|dz}|Sd}|S)zP
        Get the correct background color for the token from the style.
        �bgcolorNr�r$)rCrE�bg_colors   r&�_get_text_bg_colorz!ImageFormatter._get_text_bg_color�s1�����'��U�9�-�-�H����H��r%c�F�|jj|d|d�S)z5
        Get the correct font for the style.
        r��italic)r1r�)rCrEs  r&�_get_style_fontzImageFormatter._get_style_font�s#���z�z�"�"�5��=�%��/�B�Br%c��|j|�|jz|j|dz�|jzfS)z.
        Get the required image size.
        r)r�r�r�)rC�
maxlinelength�	maxlinenos   r&�_get_image_sizezImageFormatter._get_image_sizesB��� � ��/�$�.�.�@�� � ��Q��/�$�.�.�@�B�	Br%c��|j|j|�t|�j|j�|j
j
|j|j�|jd��y)zA
        Remember a line number drawable to paint later.
        N�rD�text_fg�text_bg)
�
_draw_textr��str�rjustr�r1r�r�r�r�)rC�posnor�s   r&�_draw_linenumberzImageFormatter._draw_linenumber	sj��	
����$�$�U�+���K���d�4�4�5����$�$�T�%:�%:�%)�%<�%<�>��'�'��
	�	
r%c�D�|jj|||||f�y)zB
        Remember a single drawable tuple to paint later.
        N)r�r�)rC�posr�rDr�r�s      r&r�zImageFormatter._draw_texts!��	
�����s�D�$���A�Br%c���dx}x}}dx}}|D�]=\}}||jvr|j}||jvr�|j|}	|jd�}|jd�}
t	|
�D]�\}}|jd�}
|
r�|j
|j||�|
|j|	�|j|	�|j|	���|jj|
�\}}||z
}t||�}|t|
�z
}t||�}|jd�s��d}d}|dz
}����@||_||_||_y)z9
        Create drawables for the token content.
        rr�T�
r�r�N)ry�parent�
expandtabsrQ�	enumerate�rstripr�r�r�r�r�r1r��max�lenrir��	maxcharnor�)rC�tokensourcer��charnor�r�r��ttype�valuerErW�irX�temp�
temp_widthrVs                r&�_create_drawablesz ImageFormatter._create_drawabless{��'(�'��'��)�%&�&�
�
�'�	 �L�E�5��t�{�{�*������t�{�{�*��K�K��&�E��$�$�Q�'�E��$�$�T�*�E�$�U�+�
 ���4��{�{�4�(����O�O��*�*�:�v�>��#�3�3�E�:�"&�"6�"6�u�"=�"&�"9�"9�%�"@�$��%)�J�J�$<�$<�T�$B�M�J���*�,�J�$'�
�z�$B�M��c�$�i�'�F� #�I�v� 6�I��=�=��&�!"�J��F��a�K�F�'
 �	 �<+���"�����r%c��|jsyt|j�D]6}||jz}||jzdk(s�%|j||��8y)z8
        Create drawables for the line numbers.
        Nr)r��ranger�r�r�r�)rC�p�ns   r&�_draw_line_numbersz!ImageFormatter._draw_line_numbersDs[��� � ���t�~�~�&�	,�A��D�*�*�*�A��D�)�)�)�a�/��%�%�a��+�	,r%c�n�|jsy|j�ytj|�}|jd}|j
|jz|jz
}|jd||fg|j��|jr#|j|df||fg|j��~y)z@
        Paint the line number background on the image.
        N���)rr�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_bgOs���� � �����&���~�~�b�!������������!7�!7�7�$�:N�:N�N���������/� �/�/�	�	1��%�%��I�I��q�z�E�5�>�2��9L�9L�I�M�r%c	��|j|�|j�tjd|j	|j
|j�|j�}|j|�tj|�}|jr�|j|jz|jz
dz}|j�}|j d|z
}|jD]?}|j#|dz
�}	|j%||	f||z|	|zfg|j&���A|j(D]a\}
}}}
}|rB|j+||��}|j%|
d|
d|
d|dz|
d|dzg|��|j-|
|||
���c|j/||j0j3��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�rr
)r�rD)rDr�N)rr
r�newr�r�r�r�rr	rr�r�r�r�r�rr�rr�r��textsizer��saver��upper)rCr��outfilerr�xrr�
linenumber�yr�rrDr�r��	text_sizes                r&�formatzImageFormatter.format`s���	
���{�+����!�
�Y�Y��� � ��!3�!3�T�^�^�D��!�!�
��
	
�"�"�2�&��~�~�b�!���=�=�����!7�!7�7�$�:N�:N�N�QR�R�A��)�)�+�E��G�G�A�J��N�E�"�m�m�
3�
��$�$�Z�!�^�4������A���U��A��I�(>�?�$(�M�M��3�
3�37�.�.�	;�.�C���g�w�� �M�M�u�4�M�@�	�����A���A���A���1��0E�s�1�v�PY�Z[�P\�G\�]�dk��l��I�I�c�5�t�'�I�:�		;�
	�����*�*�0�0�2�3r%N)r)r r!r"r#rT�aliases�	filenames�
unicodeoutputr�rFr�r�r�r�r�r�r�r�r�r�r�r�r�rr
rr!r$r%r&rrs���l�^�D�#�G��	�I��M� ��6�pR�*�A��D�F�:���C�B�
�C�& �P	,��"4r%rc�$�eZdZdZdZdgZdgZdZy)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#rTr"r#r�r$r%r&rr�s"����D��g�G��	�I� �r%rc�&�eZdZdZdZddgZdgZdZy)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��f�o�G��	�I�!�r%r
c�&�eZdZdZdZddgZdgZdZy)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
    �img_bmpr��bitmapz*.bmpNr'r$r%r&rr�s%����D��h��G��	�I� �r%r) r#r5r:�pygments.formatterr�
pygments.utilrrrrrL�PILrr	r
r��ImportErrorrt�winreg�__all__r9rAr=r?r�	Exceptionr(r*rrr
rr$r%r&�<module>r5s���
�
�(�����/�/��M��� ��G��h�'��(�!�=�1�	
��+��%����7�k�7�3�9�3�Q�Q�ho4�Y�o4�j!��!�"��"�!��!��U���M���
��� ���������sF�B�B%�B"�!B"�%C�+B0�/C�0B:�7C�9B:�:C�?C